Lines 23-28
Link Here
|
23 |
import java.io.UnsupportedEncodingException; |
23 |
import java.io.UnsupportedEncodingException; |
24 |
import java.lang.reflect.Field; |
24 |
import java.lang.reflect.Field; |
25 |
import java.text.MessageFormat; |
25 |
import java.text.MessageFormat; |
|
|
26 |
import java.util.ArrayList; |
26 |
import java.util.Arrays; |
27 |
import java.util.Arrays; |
27 |
import java.util.Collections; |
28 |
import java.util.Collections; |
28 |
import java.util.Enumeration; |
29 |
import java.util.Enumeration; |
Lines 45-50
Link Here
|
45 |
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; |
46 |
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; |
46 |
import org.eclipse.jdt.internal.compiler.IProblemFactory; |
47 |
import org.eclipse.jdt.internal.compiler.IProblemFactory; |
47 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
48 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
|
|
49 |
import org.eclipse.jdt.internal.compiler.env.AccessRule; |
50 |
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; |
48 |
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; |
51 |
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; |
49 |
import org.eclipse.jdt.internal.compiler.env.INameEnvironment; |
52 |
import org.eclipse.jdt.internal.compiler.env.INameEnvironment; |
50 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
53 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
Lines 311-317
Link Here
|
311 |
String.valueOf(time), |
314 |
String.valueOf(time), |
312 |
String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) })); |
315 |
String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) })); |
313 |
} |
316 |
} |
314 |
public void logClasspath(String[] classpaths) { |
317 |
public void logClasspath(FileSystem.Classpath[] classpaths) { |
315 |
if (classpaths == null) return; |
318 |
if (classpaths == null) return; |
316 |
if (this.isXml) { |
319 |
if (this.isXml) { |
317 |
final int length = classpaths.length; |
320 |
final int length = classpaths.length; |
Lines 320-326
Link Here
|
320 |
this.printTag(CLASSPATHS, null, true, false); |
323 |
this.printTag(CLASSPATHS, null, true, false); |
321 |
for (int i = 0; i < length; i++) { |
324 |
for (int i = 0; i < length; i++) { |
322 |
this.parameters.clear(); |
325 |
this.parameters.clear(); |
323 |
String classpath = classpaths[i]; |
326 |
String classpath = classpaths[i].normalizedPath(); |
324 |
parameters.put(PATH, classpath); |
327 |
parameters.put(PATH, classpath); |
325 |
File f = new File(classpath); |
328 |
File f = new File(classpath); |
326 |
String id = null; |
329 |
String id = null; |
Lines 925-931
Link Here
|
925 |
public final static String bundleName = |
928 |
public final static String bundleName = |
926 |
"org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$ |
929 |
"org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$ |
927 |
|
930 |
|
928 |
public String[] classpaths; |
931 |
ArrayList checkedClasspaths; |
929 |
public String destinationPath; |
932 |
public String destinationPath; |
930 |
public String[] encodings; |
933 |
public String[] encodings; |
931 |
public Logger logger; |
934 |
public Logger logger; |
Lines 1185-1194
Link Here
|
1185 |
final int InsideBootClasspath = 128; |
1188 |
final int InsideBootClasspath = 128; |
1186 |
final int InsideMaxProblems = 256; |
1189 |
final int InsideMaxProblems = 256; |
1187 |
final int Default = 0; |
1190 |
final int Default = 0; |
1188 |
String[] bootclasspaths = null; |
|
|
1189 |
int DEFAULT_SIZE_CLASSPATH = 4; |
1191 |
int DEFAULT_SIZE_CLASSPATH = 4; |
1190 |
int pathCount = 0; |
1192 |
ArrayList bootclasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH); |
1191 |
int bootclasspathCount = 0; |
1193 |
checkedClasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH); |
|
|
1194 |
String currentClasspathName = null; |
1195 |
ArrayList currentRuleSpecs = new ArrayList(DEFAULT_SIZE_CLASSPATH); |
1192 |
int index = -1, filesCount = 0, argCount = argv.length; |
1196 |
int index = -1, filesCount = 0, argCount = argv.length; |
1193 |
int mode = Default; |
1197 |
int mode = Default; |
1194 |
this.repetitions = 0; |
1198 |
this.repetitions = 0; |
Lines 1264-1270
Link Here
|
1264 |
currentArg = newCommandLineArgs[index]; |
1268 |
currentArg = newCommandLineArgs[index]; |
1265 |
|
1269 |
|
1266 |
customEncoding = null; |
1270 |
customEncoding = null; |
1267 |
if (currentArg.endsWith("]")) { //$NON-NLS-1$ |
1271 |
if (currentArg.endsWith("]") && !(mode == InsideBootClasspath || mode == InsideClasspath) ) { //$NON-NLS-1$ |
1268 |
// look for encoding specification |
1272 |
// look for encoding specification |
1269 |
int encodingStart = currentArg.indexOf('[') + 1; |
1273 |
int encodingStart = currentArg.indexOf('[') + 1; |
1270 |
int encodingEnd = currentArg.length() - 1; |
1274 |
int encodingEnd = currentArg.length() - 1; |
Lines 1376-1392
Link Here
|
1376 |
} |
1380 |
} |
1377 |
if (currentArg.equals("-classpath") //$NON-NLS-1$ |
1381 |
if (currentArg.equals("-classpath") //$NON-NLS-1$ |
1378 |
|| currentArg.equals("-cp")) { //$NON-NLS-1$ //$NON-NLS-2$ |
1382 |
|| currentArg.equals("-cp")) { //$NON-NLS-1$ //$NON-NLS-2$ |
1379 |
if (pathCount == 0) { |
|
|
1380 |
this.classpaths = new String[DEFAULT_SIZE_CLASSPATH]; |
1381 |
} |
1382 |
mode = InsideClasspath; |
1383 |
mode = InsideClasspath; |
1383 |
continue; |
1384 |
continue; |
1384 |
} |
1385 |
} |
1385 |
if (currentArg.equals("-bootclasspath")) {//$NON-NLS-1$ |
1386 |
if (currentArg.equals("-bootclasspath")) {//$NON-NLS-1$ |
1386 |
if (bootclasspathCount > 0) |
1387 |
if (bootclasspaths.size() > 0) |
1387 |
throw new InvalidInputException( |
1388 |
throw new InvalidInputException( |
1388 |
Main.bind("configure.duplicateBootClasspath", currentArg)); //$NON-NLS-1$ |
1389 |
Main.bind("configure.duplicateBootClasspath", currentArg)); //$NON-NLS-1$ |
1389 |
bootclasspaths = new String[DEFAULT_SIZE_CLASSPATH]; |
|
|
1390 |
mode = InsideBootClasspath; |
1390 |
mode = InsideBootClasspath; |
1391 |
continue; |
1391 |
continue; |
1392 |
} |
1392 |
} |
Lines 1921-1960
Link Here
|
1921 |
mode = Default; |
1921 |
mode = Default; |
1922 |
continue; |
1922 |
continue; |
1923 |
} |
1923 |
} |
1924 |
if (mode == InsideClasspath) { |
1924 |
if (mode == InsideClasspath || mode == InsideBootClasspath) { |
1925 |
StringTokenizer tokenizer = new StringTokenizer(currentArg, File.pathSeparator); |
1925 |
StringTokenizer tokenizer = new StringTokenizer(currentArg, |
|
|
1926 |
File.pathSeparator + "[]", true); //$NON-NLS-1$ |
1927 |
// state machine |
1928 |
final int start = 0; |
1929 |
final int readyToClose = 1; |
1930 |
// 'path' 'path1[rule];path2' |
1931 |
final int readyToCloseEndingWithRules = 2; |
1932 |
// 'path[rule]' 'path1;path2[rule]' |
1933 |
final int readyToCloseOrOtherEntry = 3; |
1934 |
// 'path[rule];' 'path;' 'path1;path2;' |
1935 |
final int rulesNeedAnotherRule = 4; |
1936 |
// 'path[rule1;' |
1937 |
final int rulesStart = 5; |
1938 |
// 'path[' 'path1;path2[' |
1939 |
final int rulesReadyToClose = 6; |
1940 |
// 'path[rule' 'path[rule1;rule2' |
1941 |
final int error = 99; |
1942 |
int state = start; |
1943 |
String token = null; |
1926 |
while (tokenizer.hasMoreTokens()) { |
1944 |
while (tokenizer.hasMoreTokens()) { |
1927 |
int length; |
1945 |
token = tokenizer.nextToken(); |
1928 |
if ((length = this.classpaths.length) <= pathCount) { |
1946 |
if (token.equals(File.pathSeparator)) { |
1929 |
System.arraycopy( |
1947 |
switch (state) { |
1930 |
this.classpaths, |
1948 |
case readyToClose: |
1931 |
0, |
1949 |
case readyToCloseEndingWithRules: |
1932 |
(this.classpaths = new String[length * 2]), |
1950 |
case readyToCloseOrOtherEntry: |
1933 |
0, |
1951 |
state = readyToCloseOrOtherEntry; |
1934 |
length); |
1952 |
break; |
|
|
1953 |
case rulesReadyToClose: |
1954 |
state = rulesNeedAnotherRule; |
1955 |
break; |
1956 |
default: |
1957 |
state = error; |
1958 |
} |
1959 |
} else if (token.equals("[")) { //$NON-NLS-1$ |
1960 |
switch (state) { |
1961 |
case readyToClose: |
1962 |
state = rulesStart; |
1963 |
break; |
1964 |
default: |
1965 |
state = error; |
1966 |
} |
1967 |
} else if (token.equals("]")) { //$NON-NLS-1$ |
1968 |
switch (state) { |
1969 |
case rulesReadyToClose: |
1970 |
state = readyToCloseEndingWithRules; |
1971 |
break; |
1972 |
default: |
1973 |
state = error; |
1974 |
} |
1975 |
|
1976 |
} else // regular word |
1977 |
{ |
1978 |
switch (state) { |
1979 |
case start: |
1980 |
case readyToCloseOrOtherEntry: |
1981 |
state = readyToClose; |
1982 |
currentClasspathName = token; |
1983 |
break; |
1984 |
case rulesNeedAnotherRule: |
1985 |
case rulesStart: |
1986 |
state = rulesReadyToClose; |
1987 |
currentRuleSpecs.add(token); |
1988 |
break; |
1989 |
default: |
1990 |
state = error; |
1991 |
} |
1935 |
} |
1992 |
} |
1936 |
this.classpaths[pathCount++] = tokenizer.nextToken(); |
|
|
1937 |
} |
1993 |
} |
1938 |
mode = Default; |
1994 |
if (state == readyToClose |
1939 |
continue; |
1995 |
|| state == readyToCloseEndingWithRules |
1940 |
} |
1996 |
|| state == readyToCloseOrOtherEntry) { |
1941 |
if (mode == InsideBootClasspath) { |
1997 |
AccessRule[] accessRules = new AccessRule[currentRuleSpecs |
1942 |
StringTokenizer tokenizer = new StringTokenizer(currentArg, File.pathSeparator); |
1998 |
.size()]; |
1943 |
while (tokenizer.hasMoreTokens()) { |
1999 |
boolean rulesOK = true; |
1944 |
int length; |
2000 |
Iterator i = currentRuleSpecs.iterator(); |
1945 |
if ((length = bootclasspaths.length) <= bootclasspathCount) { |
2001 |
int j = 0; |
1946 |
System.arraycopy( |
2002 |
while (i.hasNext()) { |
1947 |
bootclasspaths, |
2003 |
String ruleSpec = (String) i.next(); |
1948 |
0, |
2004 |
char key = ruleSpec.charAt(0); |
1949 |
(bootclasspaths = new String[length * 2]), |
2005 |
String pattern = ruleSpec.substring(1); |
1950 |
0, |
2006 |
if (pattern.length() > 0) { |
1951 |
length); |
2007 |
switch (key) { |
|
|
2008 |
case '+': |
2009 |
accessRules[j++] = new AccessRule(pattern |
2010 |
.toCharArray(), -1); |
2011 |
break; |
2012 |
case '~': |
2013 |
accessRules[j++] = new AccessRule(pattern |
2014 |
.toCharArray(), |
2015 |
IProblem.DiscouragedReference); |
2016 |
break; |
2017 |
case '-': |
2018 |
accessRules[j++] = new AccessRule(pattern |
2019 |
.toCharArray(), |
2020 |
IProblem.ForbiddenReference); |
2021 |
break; |
2022 |
default: |
2023 |
rulesOK = false; |
2024 |
} |
2025 |
} else { |
2026 |
rulesOK = false; |
2027 |
} |
2028 |
} |
2029 |
if (rulesOK) { |
2030 |
AccessRuleSet accessRuleSet = new AccessRuleSet( |
2031 |
accessRules, "{0}"); //$NON-NLS-1$ |
2032 |
FileSystem.Classpath currentClasspath = FileSystem |
2033 |
.getClasspath(currentClasspathName, |
2034 |
customEncoding, 0, accessRuleSet); |
2035 |
if (currentClasspath != null) { |
2036 |
if (mode == InsideClasspath) { |
2037 |
this.checkedClasspaths.add(currentClasspath); |
2038 |
} else { // inside bootclasspath |
2039 |
bootclasspaths.add(currentClasspath); |
2040 |
} |
2041 |
} else { |
2042 |
this.logger.logIncorrectClasspath(currentArg); |
2043 |
// we go on anyway |
2044 |
} |
2045 |
} else { |
2046 |
this.logger.logIncorrectClasspath(currentArg); |
2047 |
// we go on anyway |
1952 |
} |
2048 |
} |
1953 |
bootclasspaths[bootclasspathCount++] = tokenizer.nextToken(); |
2049 |
} else { |
|
|
2050 |
this.logger.logIncorrectClasspath(currentArg); |
2051 |
// we go on anyway |
1954 |
} |
2052 |
} |
1955 |
mode = Default; |
2053 |
mode = Default; |
1956 |
continue; |
2054 |
continue; |
1957 |
} |
2055 |
} |
1958 |
//default is input directory |
2056 |
//default is input directory |
1959 |
currentArg = currentArg.replace('/', File.separatorChar); |
2057 |
currentArg = currentArg.replace('/', File.separatorChar); |
1960 |
if (currentArg.endsWith(File.separator)) |
2058 |
if (currentArg.endsWith(File.separator)) |
Lines 2020-2041
Link Here
|
2020 |
(this.filenames = new String[filesCount]), |
2118 |
(this.filenames = new String[filesCount]), |
2021 |
0, |
2119 |
0, |
2022 |
filesCount); |
2120 |
filesCount); |
2023 |
if (pathCount == 0) { |
2121 |
if (checkedClasspaths.size() == 0) { |
2024 |
// no user classpath specified. |
2122 |
// no user classpath specified. |
2025 |
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ |
2123 |
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ |
2026 |
if ((classProp == null) || (classProp.length() == 0)) { |
2124 |
if ((classProp == null) || (classProp.length() == 0)) { |
2027 |
this.logger.logNoClasspath(); //$NON-NLS-1$ |
2125 |
this.logger.logNoClasspath(); //$NON-NLS-1$ |
2028 |
classProp = System.getProperty("user.dir"); //$NON-NLS-1$ |
|
|
2029 |
} |
2126 |
} |
2030 |
StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); |
2127 |
else { |
2031 |
this.classpaths = new String[tokenizer.countTokens() + 1]; |
2128 |
StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); |
2032 |
while (tokenizer.hasMoreTokens()) { |
2129 |
String token; |
2033 |
this.classpaths[pathCount++] = tokenizer.nextToken(); |
2130 |
while (tokenizer.hasMoreTokens()) { |
|
|
2131 |
token = tokenizer.nextToken(); |
2132 |
FileSystem.Classpath currentClasspath = FileSystem |
2133 |
.getClasspath(token, customEncoding, 0, null); |
2134 |
if (currentClasspath != null) { |
2135 |
this.checkedClasspaths.add(currentClasspath); |
2136 |
} else { |
2137 |
this.logger.logIncorrectClasspath(token); |
2138 |
// should not happen - we go on anyway |
2139 |
} |
2140 |
} |
2034 |
} |
2141 |
} |
2035 |
this.classpaths[pathCount++] = System.getProperty("user.dir");//$NON-NLS-1$ |
|
|
2036 |
} |
2142 |
} |
2037 |
|
2143 |
|
2038 |
if (bootclasspathCount == 0) { |
2144 |
if (bootclasspaths.size() == 0) { |
2039 |
/* no bootclasspath specified |
2145 |
/* no bootclasspath specified |
2040 |
* we can try to retrieve the default librairies of the VM used to run |
2146 |
* we can try to retrieve the default librairies of the VM used to run |
2041 |
* the batch compiler |
2147 |
* the batch compiler |
Lines 2060-2072
Link Here
|
2060 |
File[] directoriesToCheck = new File[] { new File(javaHomeFile, "lib"), new File(javaHomeFile, "lib/ext")};//$NON-NLS-1$//$NON-NLS-2$ |
2166 |
File[] directoriesToCheck = new File[] { new File(javaHomeFile, "lib"), new File(javaHomeFile, "lib/ext")};//$NON-NLS-1$//$NON-NLS-2$ |
2061 |
File[][] systemLibrariesJars = getLibrariesFiles(directoriesToCheck); |
2167 |
File[][] systemLibrariesJars = getLibrariesFiles(directoriesToCheck); |
2062 |
if (systemLibrariesJars != null) { |
2168 |
if (systemLibrariesJars != null) { |
2063 |
int length = getLength(systemLibrariesJars); |
|
|
2064 |
bootclasspaths = new String[length]; |
2065 |
for (int i = 0, max = systemLibrariesJars.length; i < max; i++) { |
2169 |
for (int i = 0, max = systemLibrariesJars.length; i < max; i++) { |
2066 |
File[] current = systemLibrariesJars[i]; |
2170 |
File[] current = systemLibrariesJars[i]; |
2067 |
if (current != null) { |
2171 |
if (current != null) { |
2068 |
for (int j = 0, max2 = current.length; j < max2; j++) { |
2172 |
for (int j = 0, max2 = current.length; j < max2; j++) { |
2069 |
bootclasspaths[bootclasspathCount++] = current[j].getAbsolutePath(); |
2173 |
FileSystem.Classpath classpath = |
|
|
2174 |
FileSystem.getClasspath( |
2175 |
current[j].getAbsolutePath(), |
2176 |
null, 0, null); |
2177 |
if (classpath != null) { |
2178 |
bootclasspaths.add(classpath); |
2179 |
} |
2070 |
} |
2180 |
} |
2071 |
} |
2181 |
} |
2072 |
} |
2182 |
} |
Lines 2084-2123
Link Here
|
2084 |
this.showProgress = false; |
2194 |
this.showProgress = false; |
2085 |
} |
2195 |
} |
2086 |
|
2196 |
|
2087 |
if (this.classpaths == null) { |
|
|
2088 |
this.classpaths = new String[0]; |
2089 |
} |
2090 |
/* |
2197 |
/* |
2091 |
* We put the bootclasspath at the beginning of the classpath entries |
2198 |
* We put the bootclasspath at the beginning of the classpath entries |
2092 |
*/ |
2199 |
*/ |
2093 |
String[] newclasspaths = null; |
2200 |
bootclasspaths.addAll(this.checkedClasspaths); |
2094 |
if ((pathCount + bootclasspathCount) != this.classpaths.length) { |
2201 |
this.checkedClasspaths = bootclasspaths; |
2095 |
newclasspaths = new String[pathCount + bootclasspathCount]; |
2202 |
this.checkedClasspaths.trimToSize(); |
2096 |
} else { |
|
|
2097 |
newclasspaths = this.classpaths; |
2098 |
} |
2099 |
System.arraycopy( |
2100 |
this.classpaths, |
2101 |
0, |
2102 |
newclasspaths, |
2103 |
bootclasspathCount, |
2104 |
pathCount); |
2105 |
|
2106 |
if (bootclasspathCount != 0) { |
2107 |
System.arraycopy( |
2108 |
bootclasspaths, |
2109 |
0, |
2110 |
newclasspaths, |
2111 |
0, |
2112 |
bootclasspathCount); |
2113 |
} |
2114 |
this.classpaths = newclasspaths; |
2115 |
for (int i = 0, max = this.classpaths.length; i < max; i++) { |
2116 |
File file = new File(this.classpaths[i]); |
2117 |
if (!file.exists()) { // signal missing classpath entry file |
2118 |
this.logger.logIncorrectClasspath(this.classpaths[i]); //$NON-NLS-1$ |
2119 |
} |
2120 |
} |
2121 |
if (this.destinationPath == null) { |
2203 |
if (this.destinationPath == null) { |
2122 |
this.generatePackagesStructure = false; |
2204 |
this.generatePackagesStructure = false; |
2123 |
} else if ("none".equals(this.destinationPath)) { //$NON-NLS-1$ |
2205 |
} else if ("none".equals(this.destinationPath)) { //$NON-NLS-1$ |
Lines 2198-2204
Link Here
|
2198 |
} |
2280 |
} |
2199 |
this.logger.logCommandLineArguments(newCommandLineArgs); |
2281 |
this.logger.logCommandLineArguments(newCommandLineArgs); |
2200 |
this.logger.logOptions(this.options); |
2282 |
this.logger.logOptions(this.options); |
2201 |
this.logger.logClasspath(this.classpaths); |
2283 |
this.logger.logClasspath((FileSystem.Classpath[])this.checkedClasspaths.toArray(new FileSystem.Classpath[0])); |
2202 |
if (this.repetitions == 0) { |
2284 |
if (this.repetitions == 0) { |
2203 |
this.repetitions = 1; |
2285 |
this.repetitions = 1; |
2204 |
} |
2286 |
} |
Lines 2319-2336
Link Here
|
2319 |
return result; |
2401 |
return result; |
2320 |
} |
2402 |
} |
2321 |
|
2403 |
|
2322 |
private int getLength(File[][] libraries) { |
|
|
2323 |
int sum = 0; |
2324 |
if (libraries != null) { |
2325 |
for (int i = 0, max = libraries.length; i < max; i++) { |
2326 |
final File[] currentFiles = libraries[i]; |
2327 |
if (currentFiles != null) { |
2328 |
sum+= currentFiles.length; |
2329 |
} |
2330 |
} |
2331 |
} |
2332 |
return sum; |
2333 |
} |
2334 |
/* |
2404 |
/* |
2335 |
* Low-level API performing the actual compilation |
2405 |
* Low-level API performing the actual compilation |
2336 |
*/ |
2406 |
*/ |
Lines 2351-2357
Link Here
|
2351 |
String defaultEncoding = (String) this.options.get(CompilerOptions.OPTION_Encoding); |
2421 |
String defaultEncoding = (String) this.options.get(CompilerOptions.OPTION_Encoding); |
2352 |
if ("".equals(defaultEncoding)) //$NON-NLS-1$ |
2422 |
if ("".equals(defaultEncoding)) //$NON-NLS-1$ |
2353 |
defaultEncoding = null; //$NON-NLS-1$ |
2423 |
defaultEncoding = null; //$NON-NLS-1$ |
2354 |
return new FileSystem(this.classpaths, this.filenames, defaultEncoding); |
2424 |
return new FileSystem( |
|
|
2425 |
(FileSystem.Classpath[])this.checkedClasspaths.toArray( |
2426 |
new FileSystem.Classpath[0]), |
2427 |
this.filenames); |
2355 |
} |
2428 |
} |
2356 |
/* |
2429 |
/* |
2357 |
* Low-level API performing the actual compilation |
2430 |
* Low-level API performing the actual compilation |