/* * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Test for combinations of using javac command-line options and fileManager setLocation * calls to affect the locations available in the fileManager. * * Using a single Java compiler and file manager, for each of the standard locations, * a series of operations is performed, using either compiler options or setLocation * calls. Each operation includes a compilation, and then a check for the value of * the standard location available in the file manager. * * The operations generate and use unique files to minimize the possibility of false * positive results.
*/ publicclass TestSearchPaths {
publicstaticvoid main(String... args) throws Exception {
TestSearchPaths t = new TestSearchPaths();
t.run();
}
// future-proof: guard against new StandardLocations being added if (!tested.equals(EnumSet.allOf(StandardLocation.class))) { // FIXME: need to update for JDK 9 locations // error("not all standard locations have been tested");
out.println("not yet tested: " + EnumSet.complementOf(tested));
}
case 2: // the default values for -extdirs and -endorseddirs come after the bootclasspath; // so to check -Xbootclasspath/a: we specify empty values for those options.
options = getOptions("-d", classes.getPath(), "-source", "8", "-target", "8", "-Xbootclasspath/a:" + testClasses, "-extdirs", "", "-endorseddirs", "");
mode = Mode.ENDS_WITH;
match = Arrays.asList(testClasses); break;
case 3:
options = getOptions("-d", classes.getPath(), "-Xbootclasspath:" + defaultPathString);
mode = Mode.EQUALS;
match = defaultPath;
reference = ""; break;
case 4:
fileManager.setLocation(PLATFORM_CLASS_PATH, null);
jar = new File(testJars, "j" + i + ".jar");
writeJar(jar, testClasses, "C" + i + ".class");
options = getOptions("-d", classes.getPath(), "-source", "8", "-target", "8", "-endorseddirs", testJars.getPath());
mode = Mode.CONTAINS;
match = Arrays.asList(jar); break;
case 5:
fileManager.setLocation(PLATFORM_CLASS_PATH, null);
jar = new File(testJars, "j" + i + ".jar");
writeJar(jar, testClasses, "C" + i + ".class");
options = getOptions("-d", classes.getPath(), "-source", "8", "-target", "8", "-Djava.endorsed.dirs=" + testJars.getPath());
mode = Mode.CONTAINS;
match = Arrays.asList(jar); break;
case 6:
fileManager.setLocation(PLATFORM_CLASS_PATH, null);
jar = new File(testJars, "j" + i + ".jar");
writeJar(jar, testClasses, "C" + i + ".class");
options = getOptions("-d", classes.getPath(), "-source", "8", "-target", "8", "-extdirs", testJars.getPath());
mode = Mode.CONTAINS;
match = Arrays.asList(jar); break;
case 7:
fileManager.setLocation(PLATFORM_CLASS_PATH, null);
jar = new File(testJars, "j" + i + ".jar");
writeJar(jar, testClasses, "C" + i + ".class");
options = getOptions("-d", classes.getPath(), "-source", "8", "-target", "8", "-Djava.ext.dirs=" + testJars.getPath());
mode = Mode.CONTAINS;
match = Arrays.asList(jar); break;
case 8:
setLocation(PLATFORM_CLASS_PATH, defaultPath);
options = getOptions("-d", classes.getPath());
mode = Mode.EQUALS;
match = defaultPath;
reference = ""; break;
void checkFile(StandardLocation l, String path) { if (!l.isOutputLocation()) {
error("Not an output location: " + l); return;
}
List<File> files = getLocation(l); if (files == null) {
error("location is unset: " + l); return;
}
if (files.size() != 1)
error("unexpected number of entries on " + l + ": " + files.size());
File f = new File(files.get(0), path); if (!f.exists())
error("file not found: " + f);
}
void checkPath(StandardLocation l, Mode m, File expect) {
checkPath(l, m, Arrays.asList(expect));
}
void checkPath(StandardLocation l, Mode m, List<File> expect) {
List<File> files = getLocation(l); if (files == null) {
error("location is unset: " + l); return;
}
switch (m) { case EQUALS: if (!Objects.equals(files, expect)) {
error("location does not match the expected files: " + l);
out.println("found: " + files);
out.println("expect: " + expect);
} break;
case CONTAINS: int containsIndex = Collections.indexOfSubList(files, expect); if (containsIndex == -1) {
error("location does not contain the expected files: " + l);
out.println("found: " + files);
out.println("expect: " + expect);
} break;
case STARTS_WITH: int startsIndex = Collections.indexOfSubList(files, expect); if (startsIndex != 0) {
error("location does not start with the expected files: " + l);
out.println("found: " + files);
out.println("expect: " + expect);
} break;
case ENDS_WITH: int endsIndex = Collections.lastIndexOfSubList(files, expect); if (endsIndex != files.size() - expect.size()) {
error("location does not end with the expected files: " + l);
out.println("found: " + files);
out.println("expect: " + expect);
} break;
}
}
List<File> getLocation(StandardLocation l) {
Iterable<? extends File> iter = fileManager.getLocation(l); if (iter == null) returnnull;
List<File> files = new ArrayList<>(); for (File f: iter)
files.add(f); return files;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.