# HG changeset patch # User jjg # Date 1402264954 25200 # Node ID 655b72d7b96e9b7454cc1b30f6ac5829d00e80e4 # Parent 986d876a91216f8937b8c87f2424e071fe9e1070 7026941: 199: path options ignored when reusing filemanager across tasks Reviewed-by: jlahoda, jfranck diff -r 986d876a9121 -r 655b72d7b96e langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java --- a/langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Fri Jun 06 16:08:46 2014 -0400 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Sun Jun 08 15:02:34 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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 @@ -202,9 +202,6 @@ // - // FIXME: all these classes should be converted to use multi-catch when - // that is available in the bootstrap compiler. - protected class WrappedJavaFileManager implements JavaFileManager { protected JavaFileManager clientJavaFileManager; WrappedJavaFileManager(JavaFileManager clientJavaFileManager) { diff -r 986d876a9121 -r 655b72d7b96e langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java --- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Fri Jun 06 16:08:46 2014 -0400 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Sun Jun 08 15:02:34 2014 -0700 @@ -161,6 +161,15 @@ compilerMain.log = Log.instance(context); compilerMain.setOptions(Options.instance(context)); compilerMain.filenames = new LinkedHashSet<>(); + compilerMain.deferredFileManagerOptions = new LinkedHashMap<>(); + // The following line is conceptually wrong. It should not refer to args + // which may include inappropriate file manager options. + // (Ideally, args should not even be passed into JavacTaskImpl at all.) + // The "no filenames in args" check should have been handled by the use of + // the GrumpyHelper in JavacTool.getTask, but processArgs also has some + // additional checking, which should be factored out and called separately. + // If we fix this, then filenames and deferredFileManagerOptions in Main + // can revert to being protected or private, not public. Collection filenames = compilerMain.processArgs(CommandLine.parse(args), classNames); if (filenames != null && !filenames.isEmpty()) throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " ")); diff -r 986d876a9121 -r 655b72d7b96e langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java --- a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Fri Jun 06 16:08:46 2014 -0400 +++ b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Sun Jun 08 15:02:34 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2014, 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 @@ -158,11 +158,6 @@ symbolFileEnabled = b; } - @Override - public boolean isDefaultBootClassPath() { - return locations.isDefaultBootClassPath(); - } - public JavaFileObject getFileForInput(String name) { return getRegularFile(new File(name)); } @@ -579,15 +574,6 @@ } } - private String defaultEncodingName; - private String getDefaultEncodingName() { - if (defaultEncodingName == null) { - defaultEncodingName = - new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(); - } - return defaultEncodingName; - } - public ClassLoader getClassLoader(Location location) { nullCheck(location); Iterable path = getLocation(location); diff -r 986d876a9121 -r 655b72d7b96e langtools/src/share/classes/com/sun/tools/javac/file/Locations.java --- a/langtools/src/share/classes/com/sun/tools/javac/file/Locations.java Fri Jun 06 16:08:46 2014 -0400 +++ b/langtools/src/share/classes/com/sun/tools/javac/file/Locations.java Sun Jun 08 15:02:34 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, 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 @@ -22,12 +22,10 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package com.sun.tools.javac.file; +import java.io.File; import java.io.FileNotFoundException; -import java.util.Iterator; -import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -38,64 +36,72 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.zip.ZipFile; + +import javax.tools.JavaFileManager; import javax.tools.JavaFileManager.Location; +import javax.tools.StandardJavaFileManager; import javax.tools.StandardLocation; import com.sun.tools.javac.code.Lint; import com.sun.tools.javac.main.Option; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; -import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.StringUtils; -import javax.tools.JavaFileManager; -import javax.tools.StandardJavaFileManager; -import static javax.tools.StandardLocation.*; -import static com.sun.tools.javac.main.Option.*; +import static javax.tools.StandardLocation.CLASS_PATH; +import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; +import static javax.tools.StandardLocation.SOURCE_PATH; -/** This class converts command line arguments, environment variables - * and system properties (in File.pathSeparator-separated String form) - * into a boot class path, user class path, and source path (in - * {@code Collection} form). +import static com.sun.tools.javac.main.Option.BOOTCLASSPATH; +import static com.sun.tools.javac.main.Option.DJAVA_ENDORSED_DIRS; +import static com.sun.tools.javac.main.Option.DJAVA_EXT_DIRS; +import static com.sun.tools.javac.main.Option.ENDORSEDDIRS; +import static com.sun.tools.javac.main.Option.EXTDIRS; +import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH; +import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_APPEND; +import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_PREPEND; + +/** + * This class converts command line arguments, environment variables and system properties (in + * File.pathSeparator-separated String form) into a boot class path, user class path, and source + * path (in {@code Collection} form). * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. + *

+ * This is NOT part of any supported API. If you write code that depends on this, you do so at + * your own risk. This code and its internal interfaces are subject to change or deletion without + * notice. */ public class Locations { - /** The log to use for warning output */ + /** + * The log to use for warning output + */ private Log log; - /** Collection of command-line options */ - private Options options; - - /** Handler for -Xlint options */ - private Lint lint; - - /** Access to (possibly cached) file info */ + /** + * Access to (possibly cached) file info + */ private FSInfo fsInfo; - /** Whether to warn about non-existent path elements */ + /** + * Whether to warn about non-existent path elements + */ private boolean warn; - // TODO: remove need for this - private boolean inited = false; // TODO? caching bad? - public Locations() { initHandlers(); } - public void update(Log log, Options options, Lint lint, FSInfo fsInfo) { + // could replace Lint by "boolean warn" + public void update(Log log, Lint lint, FSInfo fsInfo) { this.log = log; - this.options = options; - this.lint = lint; + warn = lint.isEnabled(Lint.LintCategory.PATH); this.fsInfo = fsInfo; } @@ -104,14 +110,14 @@ } public boolean isDefaultBootClassPath() { - BootClassPathLocationHandler h = - (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); + BootClassPathLocationHandler h + = (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); return h.isDefault(); } boolean isDefaultBootClassPathRtJar(File file) { - BootClassPathLocationHandler h = - (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); + BootClassPathLocationHandler h + = (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); return h.isDefaultRtJar(file); } @@ -127,6 +133,7 @@ /** * Split a path into its elements. Empty path elements will be ignored. + * * @param path The path to be split * @return The elements of the path */ @@ -135,12 +142,13 @@ } /** - * Split a path into its elements. If emptyPathDefault is not null, all - * empty elements in the path, including empty elements at either end of - * the path, will be replaced with the value of emptyPathDefault. + * Split a path into its elements. If emptyPathDefault is not null, all empty elements in the + * path, including empty elements at either end of the path, will be replaced with the value of + * emptyPathDefault. + * * @param path The path to be split - * @param emptyPathDefault The value to substitute for empty path elements, - * or null, to ignore empty path elements + * @param emptyPathDefault The value to substitute for empty path elements, or null, to ignore + * empty path elements * @return The elements of the path */ private static Iterable getPathEntries(String path, File emptyPathDefault) { @@ -148,33 +156,38 @@ int start = 0; while (start <= path.length()) { int sep = path.indexOf(File.pathSeparatorChar, start); - if (sep == -1) + if (sep == -1) { sep = path.length(); - if (start < sep) + } + if (start < sep) { entries.add(new File(path.substring(start, sep))); - else if (emptyPathDefault != null) + } else if (emptyPathDefault != null) { entries.add(emptyPathDefault); + } start = sep + 1; } return entries; } /** - * Utility class to help evaluate a path option. - * Duplicate entries are ignored, jar class paths can be expanded. + * Utility class to help evaluate a path option. Duplicate entries are ignored, jar class paths + * can be expanded. */ private class Path extends LinkedHashSet { + private static final long serialVersionUID = 0; private boolean expandJarClassPaths = false; - private Set canonicalValues = new HashSet<>(); + private final Set canonicalValues = new HashSet<>(); public Path expandJarClassPaths(boolean x) { expandJarClassPaths = x; return this; } - /** What to use when path element is the empty string */ + /** + * What to use when path element is the empty string + */ private File emptyPathDefault = null; public Path emptyPathDefault(File x) { @@ -182,15 +195,15 @@ return this; } - public Path() { super(); } - public Path addDirectories(String dirs, boolean warn) { boolean prev = expandJarClassPaths; expandJarClassPaths = true; try { - if (dirs != null) - for (File dir : getPathEntries(dirs)) + if (dirs != null) { + for (File dir : getPathEntries(dirs)) { addDirectory(dir, warn); + } + } return this; } finally { expandJarClassPaths = prev; @@ -203,19 +216,22 @@ private void addDirectory(File dir, boolean warn) { if (!dir.isDirectory()) { - if (warn) + if (warn) { log.warning(Lint.LintCategory.PATH, "dir.path.element.not.found", dir); + } return; } File[] files = dir.listFiles(); - if (files == null) + if (files == null) { return; + } for (File direntry : files) { - if (isArchive(direntry)) + if (isArchive(direntry)) { addFile(direntry, warn); + } } } @@ -232,8 +248,9 @@ public Path addFiles(Iterable files, boolean warn) { if (files != null) { - for (File file: files) + for (File file : files) { addFile(file, warn); + } } return this; } @@ -248,7 +265,7 @@ return; } - if (! fsInfo.exists(file)) { + if (!fsInfo.exists(file)) { /* No such file or directory exists */ if (warn) { log.warning(Lint.LintCategory.PATH, @@ -288,12 +305,13 @@ } /* Now what we have left is either a directory or a file name - conforming to archive naming convention */ + conforming to archive naming convention */ super.add(file); canonicalValues.add(canonFile); - if (expandJarClassPaths && fsInfo.isFile(file)) + if (expandJarClassPaths && fsInfo.isFile(file)) { addJarClassPath(file, warn); + } } // Adds referenced classpath elements from a jar's Class-Path @@ -302,7 +320,7 @@ // filenames, but if we do, we should redo all path-related code. private void addJarClassPath(File jarFile, boolean warn) { try { - for (File f: fsInfo.getJarClassPath(jarFile)) { + for (File f : fsInfo.getJarClassPath(jarFile)) { addFile(f, warn); } } catch (IOException e) { @@ -312,53 +330,56 @@ } /** - * Base class for handling support for the representation of Locations. - * Implementations are responsible for handling the interactions between - * the command line options for a location, and API access via setLocation. + * Base class for handling support for the representation of Locations. Implementations are + * responsible for handling the interactions between the command line options for a location, + * and API access via setLocation. + * * @see #initHandlers * @see #getHandler */ protected abstract class LocationHandler { + final Location location; final Set