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 926-931
Link Here
|
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 |
public String[] classpaths; |
|
|
932 |
// WORK suppress (if not used) |
933 |
FileSystem.Classpath[] checkedClasspaths; |
934 |
// WORK consider the use of an ArrayList instead |
929 |
public String destinationPath; |
935 |
public String destinationPath; |
930 |
public String[] encodings; |
936 |
public String[] encodings; |
931 |
public Logger logger; |
937 |
public Logger logger; |
Lines 1185-1193
Link Here
|
1185 |
final int InsideBootClasspath = 128; |
1191 |
final int InsideBootClasspath = 128; |
1186 |
final int InsideMaxProblems = 256; |
1192 |
final int InsideMaxProblems = 256; |
1187 |
final int Default = 0; |
1193 |
final int Default = 0; |
1188 |
String[] bootclasspaths = null; |
1194 |
FileSystem.Classpath[] bootclasspaths = null; |
1189 |
int DEFAULT_SIZE_CLASSPATH = 4; |
1195 |
int DEFAULT_SIZE_CLASSPATH = 4; |
1190 |
int pathCount = 0; |
1196 |
int pathCount = 0; |
|
|
1197 |
int checkedClasspathsCount = 0; |
1198 |
// FileSystem.Classpath currentClasspath = null; |
1199 |
String currentClasspathName = null; |
1200 |
ArrayList currentRuleSpecs = new ArrayList(DEFAULT_SIZE_CLASSPATH); |
1191 |
int bootclasspathCount = 0; |
1201 |
int bootclasspathCount = 0; |
1192 |
int index = -1, filesCount = 0, argCount = argv.length; |
1202 |
int index = -1, filesCount = 0, argCount = argv.length; |
1193 |
int mode = Default; |
1203 |
int mode = Default; |
Lines 1264-1270
Link Here
|
1264 |
currentArg = newCommandLineArgs[index]; |
1274 |
currentArg = newCommandLineArgs[index]; |
1265 |
|
1275 |
|
1266 |
customEncoding = null; |
1276 |
customEncoding = null; |
1267 |
if (currentArg.endsWith("]")) { //$NON-NLS-1$ |
1277 |
if (currentArg.endsWith("]") && !(mode == InsideBootClasspath || mode == InsideClasspath) ) { //$NON-NLS-1$ |
1268 |
// look for encoding specification |
1278 |
// look for encoding specification |
1269 |
int encodingStart = currentArg.indexOf('[') + 1; |
1279 |
int encodingStart = currentArg.indexOf('[') + 1; |
1270 |
int encodingEnd = currentArg.length() - 1; |
1280 |
int encodingEnd = currentArg.length() - 1; |
Lines 1378-1383
Link Here
|
1378 |
|| currentArg.equals("-cp")) { //$NON-NLS-1$ //$NON-NLS-2$ |
1388 |
|| currentArg.equals("-cp")) { //$NON-NLS-1$ //$NON-NLS-2$ |
1379 |
if (pathCount == 0) { |
1389 |
if (pathCount == 0) { |
1380 |
this.classpaths = new String[DEFAULT_SIZE_CLASSPATH]; |
1390 |
this.classpaths = new String[DEFAULT_SIZE_CLASSPATH]; |
|
|
1391 |
this.checkedClasspaths = new FileSystem.Classpath[DEFAULT_SIZE_CLASSPATH]; |
1381 |
} |
1392 |
} |
1382 |
mode = InsideClasspath; |
1393 |
mode = InsideClasspath; |
1383 |
continue; |
1394 |
continue; |
Lines 1386-1392
Link Here
|
1386 |
if (bootclasspathCount > 0) |
1397 |
if (bootclasspathCount > 0) |
1387 |
throw new InvalidInputException( |
1398 |
throw new InvalidInputException( |
1388 |
Main.bind("configure.duplicateBootClasspath", currentArg)); //$NON-NLS-1$ |
1399 |
Main.bind("configure.duplicateBootClasspath", currentArg)); //$NON-NLS-1$ |
1389 |
bootclasspaths = new String[DEFAULT_SIZE_CLASSPATH]; |
1400 |
bootclasspaths = new FileSystem.Classpath[DEFAULT_SIZE_CLASSPATH]; |
1390 |
mode = InsideBootClasspath; |
1401 |
mode = InsideBootClasspath; |
1391 |
continue; |
1402 |
continue; |
1392 |
} |
1403 |
} |
Lines 1921-1960
Link Here
|
1921 |
mode = Default; |
1932 |
mode = Default; |
1922 |
continue; |
1933 |
continue; |
1923 |
} |
1934 |
} |
1924 |
if (mode == InsideClasspath) { |
1935 |
if (mode == InsideClasspath || mode == InsideBootClasspath) { |
1925 |
StringTokenizer tokenizer = new StringTokenizer(currentArg, File.pathSeparator); |
1936 |
StringTokenizer tokenizer = new StringTokenizer(currentArg, |
|
|
1937 |
File.pathSeparator + "[]", true); //$NON-NLS-1$ |
1938 |
// state machine |
1939 |
final int start = 0; |
1940 |
final int readyToClose = 1; |
1941 |
// 'path' 'path1[rule];path2' |
1942 |
final int readyToCloseEndingWithRules = 2; |
1943 |
// 'path[rule]' 'path1;path2[rule]' |
1944 |
final int needAnotherEntry = 3; |
1945 |
// 'path[rule];' 'path;' 'path1;path2;' |
1946 |
final int rulesNeedAnotherRule = 4; |
1947 |
// 'path[rule1;' |
1948 |
final int rulesStart = 5; |
1949 |
// 'path[' 'path1;path2[' |
1950 |
final int rulesReadyToClose = 6; |
1951 |
// 'path[rule' 'path[rule1;rule2' |
1952 |
final int error = 99; |
1953 |
int state = start; |
1954 |
String token = null; |
1926 |
while (tokenizer.hasMoreTokens()) { |
1955 |
while (tokenizer.hasMoreTokens()) { |
1927 |
int length; |
1956 |
token = tokenizer.nextToken(); |
1928 |
if ((length = this.classpaths.length) <= pathCount) { |
1957 |
if (token.equals(File.pathSeparator)) { |
1929 |
System.arraycopy( |
1958 |
switch (state) { |
1930 |
this.classpaths, |
1959 |
case readyToClose: |
1931 |
0, |
1960 |
case readyToCloseEndingWithRules: |
1932 |
(this.classpaths = new String[length * 2]), |
1961 |
state = needAnotherEntry; |
1933 |
0, |
1962 |
break; |
1934 |
length); |
1963 |
case rulesReadyToClose: |
|
|
1964 |
state = rulesNeedAnotherRule; |
1965 |
break; |
1966 |
default: |
1967 |
state = error; |
1968 |
} |
1969 |
} else if (token.equals("[")) { //$NON-NLS-1$ |
1970 |
switch (state) { |
1971 |
case readyToClose: |
1972 |
state = rulesStart; |
1973 |
break; |
1974 |
default: |
1975 |
state = error; |
1976 |
} |
1977 |
} else if (token.equals("]")) { //$NON-NLS-1$ |
1978 |
switch (state) { |
1979 |
case rulesReadyToClose: |
1980 |
state = readyToCloseEndingWithRules; |
1981 |
break; |
1982 |
default: |
1983 |
state = error; |
1984 |
} |
1985 |
|
1986 |
} else // regular word |
1987 |
{ |
1988 |
switch (state) { |
1989 |
case start: |
1990 |
case needAnotherEntry: |
1991 |
state = readyToClose; |
1992 |
if (mode == InsideClasspath) { |
1993 |
int length; |
1994 |
if ((length = this.classpaths.length) <= pathCount) { |
1995 |
System |
1996 |
.arraycopy( |
1997 |
this.classpaths, |
1998 |
0, |
1999 |
(this.classpaths = new String[length * 2]), |
2000 |
0, length); |
2001 |
} |
2002 |
this.classpaths[pathCount++] = token; |
2003 |
currentClasspathName = token; |
2004 |
} else { // inside bootclasspath |
2005 |
currentClasspathName = token; |
2006 |
} |
2007 |
break; |
2008 |
case rulesNeedAnotherRule: |
2009 |
case rulesStart: |
2010 |
state = rulesReadyToClose; |
2011 |
currentRuleSpecs.add(token); |
2012 |
break; |
2013 |
default: |
2014 |
state = error; |
2015 |
} |
1935 |
} |
2016 |
} |
1936 |
this.classpaths[pathCount++] = tokenizer.nextToken(); |
|
|
1937 |
} |
2017 |
} |
1938 |
mode = Default; |
2018 |
if (state == readyToClose |
1939 |
continue; |
2019 |
|| state == readyToCloseEndingWithRules) { |
1940 |
} |
2020 |
AccessRule[] accessRules = new AccessRule[currentRuleSpecs |
1941 |
if (mode == InsideBootClasspath) { |
2021 |
.size()]; |
1942 |
StringTokenizer tokenizer = new StringTokenizer(currentArg, File.pathSeparator); |
2022 |
boolean rulesOK = true; |
1943 |
while (tokenizer.hasMoreTokens()) { |
2023 |
Iterator i = currentRuleSpecs.iterator(); |
1944 |
int length; |
2024 |
int j = 0; |
1945 |
if ((length = bootclasspaths.length) <= bootclasspathCount) { |
2025 |
while (i.hasNext()) { |
1946 |
System.arraycopy( |
2026 |
String ruleSpec = (String) i.next(); |
1947 |
bootclasspaths, |
2027 |
char key = ruleSpec.charAt(0); |
1948 |
0, |
2028 |
String pattern = ruleSpec.substring(1); |
1949 |
(bootclasspaths = new String[length * 2]), |
2029 |
if (pattern.length() > 0) { |
1950 |
0, |
2030 |
switch (key) { |
1951 |
length); |
2031 |
case '+': |
|
|
2032 |
accessRules[j++] = new AccessRule(pattern |
2033 |
.toCharArray(), -1); |
2034 |
break; |
2035 |
case '~': |
2036 |
accessRules[j++] = new AccessRule(pattern |
2037 |
.toCharArray(), |
2038 |
IProblem.DiscouragedReference); |
2039 |
break; |
2040 |
case '-': |
2041 |
accessRules[j++] = new AccessRule(pattern |
2042 |
.toCharArray(), |
2043 |
IProblem.ForbiddenReference); |
2044 |
break; |
2045 |
default: |
2046 |
rulesOK = false; |
2047 |
} |
2048 |
} else { |
2049 |
rulesOK = false; |
2050 |
} |
2051 |
} |
2052 |
if (rulesOK) { |
2053 |
AccessRuleSet accessRuleSet = new AccessRuleSet( |
2054 |
accessRules, "{0}"); //$NON-NLS-1$ |
2055 |
FileSystem.Classpath currentClasspath = FileSystem |
2056 |
.getClasspath(currentClasspathName, |
2057 |
customEncoding, 0, accessRuleSet); |
2058 |
if (currentClasspath != null) { |
2059 |
int length; |
2060 |
if (mode == InsideClasspath) { |
2061 |
if ((length = this.checkedClasspaths.length) <= checkedClasspathsCount) { |
2062 |
System |
2063 |
.arraycopy( |
2064 |
this.checkedClasspaths, |
2065 |
0, |
2066 |
(this.checkedClasspaths = new FileSystem.Classpath[length * 2]), |
2067 |
0, length); |
2068 |
} |
2069 |
this.checkedClasspaths[checkedClasspathsCount++] = currentClasspath; |
2070 |
} else { // inside bootclasspath |
2071 |
if ((length = bootclasspaths.length) <= bootclasspathCount) { |
2072 |
System |
2073 |
.arraycopy( |
2074 |
bootclasspaths, |
2075 |
0, |
2076 |
(bootclasspaths = new FileSystem.Classpath[length * 2]), |
2077 |
0, length); |
2078 |
} |
2079 |
bootclasspaths[bootclasspathCount++] = currentClasspath; |
2080 |
} |
2081 |
} else { |
2082 |
this.logger.logIncorrectClasspath(currentArg); |
2083 |
// WORK refine diagnostic |
2084 |
} |
2085 |
} else { |
2086 |
this.logger.logIncorrectClasspath(currentArg); |
2087 |
// we go on anyway |
1952 |
} |
2088 |
} |
1953 |
bootclasspaths[bootclasspathCount++] = tokenizer.nextToken(); |
2089 |
|
|
|
2090 |
} else { |
2091 |
this.logger.logIncorrectClasspath(currentArg); |
2092 |
// we go on anyway |
1954 |
} |
2093 |
} |
1955 |
mode = Default; |
2094 |
mode = Default; |
1956 |
continue; |
2095 |
continue; |
1957 |
} |
2096 |
} |
1958 |
//default is input directory |
2097 |
//default is input directory |
1959 |
currentArg = currentArg.replace('/', File.separatorChar); |
2098 |
currentArg = currentArg.replace('/', File.separatorChar); |
1960 |
if (currentArg.endsWith(File.separator)) |
2099 |
if (currentArg.endsWith(File.separator)) |
Lines 2025-2036
Link Here
|
2025 |
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ |
2164 |
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ |
2026 |
if ((classProp == null) || (classProp.length() == 0)) { |
2165 |
if ((classProp == null) || (classProp.length() == 0)) { |
2027 |
this.logger.logNoClasspath(); //$NON-NLS-1$ |
2166 |
this.logger.logNoClasspath(); //$NON-NLS-1$ |
2028 |
classProp = System.getProperty("user.dir"); //$NON-NLS-1$ |
2167 |
this.classpaths = new String[1]; |
2029 |
} |
2168 |
} |
2030 |
StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); |
2169 |
else { |
2031 |
this.classpaths = new String[tokenizer.countTokens() + 1]; |
2170 |
StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); |
2032 |
while (tokenizer.hasMoreTokens()) { |
2171 |
String token; |
2033 |
this.classpaths[pathCount++] = tokenizer.nextToken(); |
2172 |
this.classpaths = new String[tokenizer.countTokens() + 1]; |
|
|
2173 |
this.checkedClasspaths = new FileSystem.Classpath[this.classpaths.length]; |
2174 |
while (tokenizer.hasMoreTokens()) { |
2175 |
token = tokenizer.nextToken(); |
2176 |
this.classpaths[pathCount++] = token; |
2177 |
FileSystem.Classpath currentClasspath = FileSystem |
2178 |
.getClasspath(token, customEncoding, 0, null); |
2179 |
if (currentClasspath != null) { |
2180 |
this.checkedClasspaths[checkedClasspathsCount++] = currentClasspath; |
2181 |
} else { |
2182 |
this.logger.logIncorrectClasspath(token); |
2183 |
// should not happen - we go on anyway |
2184 |
} |
2185 |
} |
2034 |
} |
2186 |
} |
2035 |
this.classpaths[pathCount++] = System.getProperty("user.dir");//$NON-NLS-1$ |
2187 |
this.classpaths[pathCount++] = System.getProperty("user.dir");//$NON-NLS-1$ |
2036 |
} |
2188 |
} |
Lines 2061-2072
Link Here
|
2061 |
File[][] systemLibrariesJars = getLibrariesFiles(directoriesToCheck); |
2213 |
File[][] systemLibrariesJars = getLibrariesFiles(directoriesToCheck); |
2062 |
if (systemLibrariesJars != null) { |
2214 |
if (systemLibrariesJars != null) { |
2063 |
int length = getLength(systemLibrariesJars); |
2215 |
int length = getLength(systemLibrariesJars); |
2064 |
bootclasspaths = new String[length]; |
2216 |
bootclasspaths = new FileSystem.Classpath[length]; |
2065 |
for (int i = 0, max = systemLibrariesJars.length; i < max; i++) { |
2217 |
for (int i = 0, max = systemLibrariesJars.length; i < max; i++) { |
2066 |
File[] current = systemLibrariesJars[i]; |
2218 |
File[] current = systemLibrariesJars[i]; |
2067 |
if (current != null) { |
2219 |
if (current != null) { |
2068 |
for (int j = 0, max2 = current.length; j < max2; j++) { |
2220 |
for (int j = 0, max2 = current.length; j < max2; j++) { |
2069 |
bootclasspaths[bootclasspathCount++] = current[j].getAbsolutePath(); |
2221 |
if ((bootclasspaths[bootclasspathCount] = FileSystem |
|
|
2222 |
.getClasspath(current[j] |
2223 |
.getAbsolutePath(), |
2224 |
null, 0, null)) != null) { |
2225 |
bootclasspathCount++; |
2226 |
} |
2070 |
} |
2227 |
} |
2071 |
} |
2228 |
} |
2072 |
} |
2229 |
} |
Lines 2102-2123
Link Here
|
2102 |
newclasspaths, |
2259 |
newclasspaths, |
2103 |
bootclasspathCount, |
2260 |
bootclasspathCount, |
2104 |
pathCount); |
2261 |
pathCount); |
2105 |
|
2262 |
FileSystem.Classpath [] trimmedClasspaths = new FileSystem.Classpath[bootclasspathCount |
2106 |
if (bootclasspathCount != 0) { |
2263 |
+ checkedClasspathsCount]; |
2107 |
System.arraycopy( |
2264 |
System.arraycopy( |
2108 |
bootclasspaths, |
2265 |
this.checkedClasspaths, |
2109 |
0, |
|
|
2110 |
newclasspaths, |
2111 |
0, |
2266 |
0, |
2112 |
bootclasspathCount); |
2267 |
trimmedClasspaths, |
|
|
2268 |
bootclasspathCount, |
2269 |
checkedClasspathsCount); |
2270 |
for (int i = 0; i < bootclasspathCount;i++){ |
2271 |
trimmedClasspaths[i] = bootclasspaths[i]; |
2272 |
newclasspaths[i] = bootclasspaths[i].normalizedPath(); |
2113 |
} |
2273 |
} |
2114 |
this.classpaths = newclasspaths; |
2274 |
this.classpaths = newclasspaths; |
2115 |
for (int i = 0, max = this.classpaths.length; i < max; i++) { |
2275 |
this.checkedClasspaths = trimmedClasspaths; |
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) { |
2276 |
if (this.destinationPath == null) { |
2122 |
this.generatePackagesStructure = false; |
2277 |
this.generatePackagesStructure = false; |
2123 |
} else if ("none".equals(this.destinationPath)) { //$NON-NLS-1$ |
2278 |
} else if ("none".equals(this.destinationPath)) { //$NON-NLS-1$ |
Lines 2351-2357
Link Here
|
2351 |
String defaultEncoding = (String) this.options.get(CompilerOptions.OPTION_Encoding); |
2506 |
String defaultEncoding = (String) this.options.get(CompilerOptions.OPTION_Encoding); |
2352 |
if ("".equals(defaultEncoding)) //$NON-NLS-1$ |
2507 |
if ("".equals(defaultEncoding)) //$NON-NLS-1$ |
2353 |
defaultEncoding = null; //$NON-NLS-1$ |
2508 |
defaultEncoding = null; //$NON-NLS-1$ |
2354 |
return new FileSystem(this.classpaths, this.filenames, defaultEncoding); |
2509 |
return new FileSystem(this.checkedClasspaths, this.filenames); |
2355 |
} |
2510 |
} |
2356 |
/* |
2511 |
/* |
2357 |
* Low-level API performing the actual compilation |
2512 |
* Low-level API performing the actual compilation |