32 import java.io.BufferedReader; |
32 import java.io.BufferedReader; |
33 import java.io.File; |
33 import java.io.File; |
34 import java.io.FileReader; |
34 import java.io.FileReader; |
35 import java.io.FileNotFoundException; |
35 import java.io.FileNotFoundException; |
36 import java.io.IOException; |
36 import java.io.IOException; |
|
37 import java.util.regex.Matcher; |
|
38 import java.util.regex.Pattern; |
37 |
39 |
38 public class CheckSource { |
40 public class CheckSource { |
|
41 |
|
42 public static final String SRC_HASH_REGEXP = ":((hg)|(git)):[a-z0-9]*\\+?"; |
39 |
43 |
40 CheckSource(String dataFile, boolean isOpenJDK) { |
44 CheckSource(String dataFile, boolean isOpenJDK) { |
41 // Read data files |
45 // Read data files |
42 readFile(dataFile, isOpenJDK); |
46 readFile(dataFile, isOpenJDK); |
43 } |
47 } |
44 |
48 |
45 private void readFile(String fileName, boolean isOpenJDK) { |
49 private void readFile(String fileName, boolean isOpenJDK) { |
46 String fishForSOURCE = null; |
50 String fishForSOURCE = null; |
|
51 String implementor = null; |
47 |
52 |
48 File file = new File(fileName); |
53 File file = new File(fileName); |
49 |
54 |
50 // open the stream to read in for Entries |
55 // open the stream to read in for Entries |
51 try (BufferedReader buffRead = |
56 try (BufferedReader buffRead = |
63 continue; |
68 continue; |
64 |
69 |
65 // grab SOURCE line |
70 // grab SOURCE line |
66 if (readIn.startsWith("SOURCE=")) { |
71 if (readIn.startsWith("SOURCE=")) { |
67 fishForSOURCE = readIn; |
72 fishForSOURCE = readIn; |
68 break; |
73 continue; |
|
74 } |
|
75 |
|
76 // grab IMPLEMENTOR line |
|
77 if (readIn.startsWith("IMPLEMENTOR=")) { |
|
78 implementor = readIn; |
|
79 continue; |
69 } |
80 } |
70 } |
81 } |
71 } catch (FileNotFoundException fileExcept) { |
82 } catch (FileNotFoundException fileExcept) { |
72 throw new RuntimeException("File " + fileName + |
83 throw new RuntimeException("File " + fileName + |
73 " not found reading data!", fileExcept); |
84 " not found reading data!", fileExcept); |
77 } |
88 } |
78 |
89 |
79 // was SOURCE even found? |
90 // was SOURCE even found? |
80 if (fishForSOURCE == null) { |
91 if (fishForSOURCE == null) { |
81 throw new RuntimeException("SOURCE line was not found!"); |
92 throw new RuntimeException("SOURCE line was not found!"); |
82 } else { |
93 } |
83 // OK it was found, did it have correct sources? |
94 System.out.println("The source string found: " + fishForSOURCE); |
84 System.out.println("The source string found: " + fishForSOURCE); |
|
85 |
95 |
86 // First it MUST have .: regardless of closed or openJDK |
96 // Extract the value of SOURCE= |
87 if (!fishForSOURCE.contains(".:")) { |
97 Pattern valuePattern = Pattern.compile("SOURCE=\"(.*)\""); |
88 throw new RuntimeException("The test failed, .: not found!"); |
98 Matcher valueMatcher = valuePattern.matcher(fishForSOURCE); |
89 } |
99 if (!valueMatcher.matches()) { |
90 // take out the .: source path |
100 throw new RuntimeException("SOURCE string has bad format, should be SOURCE=\"<value>\""); |
91 fishForSOURCE = fishForSOURCE.replace(".:", ""); |
101 } |
|
102 String valueString = valueMatcher.group(1); |
92 |
103 |
93 // if its closedJDK it MUST have open: |
104 // Check if implementor is Oracle |
94 if (!isOpenJDK && !fishForSOURCE.contains("open:")) { |
105 boolean isOracle = (implementor != null) && implementor.contains("Oracle Corporation"); |
95 throw new RuntimeException("The test failed, open: not found!"); |
|
96 } |
|
97 // take out the open: source path |
|
98 fishForSOURCE = fishForSOURCE.replace("open:", ""); |
|
99 |
106 |
100 // if any other source exists, that's an error |
107 String[] values = valueString.split(" "); |
101 if (fishForSOURCE.contains(":")) { |
108 |
102 throw new RuntimeException("The test failed, additional sources found!"); |
109 // First value MUST start with ".:" regardless of Oracle or OpenJDK |
|
110 String rootRegexp = "\\." + SRC_HASH_REGEXP; |
|
111 if (!values[0].matches(rootRegexp)) { |
|
112 throw new RuntimeException("The test failed, first element did not match regexp: " + rootRegexp); |
|
113 } |
|
114 |
|
115 // If it's an Oracle build, it can be either OpenJDK or OracleJDK. Other |
|
116 // builds may have any number of additional elements in any format. |
|
117 if (isOracle) { |
|
118 if (isOpenJDK) { |
|
119 if (values.length != 1) { |
|
120 throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." + |
|
121 " Should be 1 for Oracle built OpenJDK."); |
|
122 } |
|
123 } else { |
|
124 if (values.length != 2) { |
|
125 throw new RuntimeException("The test failed, wrong number of elements in SOURCE list." + |
|
126 " Should be 2 for OracleJDK."); |
|
127 } |
|
128 // Second value MUST start with "open:" for OracleJDK |
|
129 String openRegexp = "open" + SRC_HASH_REGEXP; |
|
130 if (!values[1].matches(openRegexp)) { |
|
131 throw new RuntimeException("The test failed, second element did not match regexp: " + openRegexp); |
|
132 } |
103 } |
133 } |
104 } |
134 } |
105 |
135 |
106 // Everything was fine |
136 // Everything was fine |
107 System.out.println("The test passed!"); |
137 System.out.println("The test passed!"); |