diff options
author | Tor Norbye <tnorbye@google.com> | 2013-04-19 13:32:49 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-04-19 13:32:49 -0700 |
commit | b569bc6aa78f6eacf72e8b90622d300e1a9db25f (patch) | |
tree | 309048e52eab434a381cf8554436f14de6342cbf /jps | |
parent | d1a59a0799588a226d255d9b45c4825b19651554 (diff) | |
download | idea-b569bc6aa78f6eacf72e8b90622d300e1a9db25f.tar.gz |
Snapshot 0b0329a61f47b6070bb9084be8e176635a16fa5c from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I2e8857776f197bed2d768ea37c67d2e2a1e97952
Diffstat (limited to 'jps')
12 files changed, 183 insertions, 35 deletions
diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java b/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java index 1229aa565b4b..ca31a22d8bf6 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java @@ -288,12 +288,14 @@ public class JavaBuilderUtil { private static class ModulesBasedFileFilter implements Mappings.DependentFilesFilter { private final CompileContext myContext; private final Set<JpsModule> myChunkModules; + private final Set<ModuleBuildTarget> myChunkTargets; private final Map<JpsModule, Set<JpsModule>> myCache = new HashMap<JpsModule, Set<JpsModule>>(); private final BuildRootIndex myBuildRootIndex; private ModulesBasedFileFilter(CompileContext context, ModuleChunk chunk) { myContext = context; myChunkModules = chunk.getModules(); + myChunkTargets = chunk.getTargets(); myBuildRootIndex = context.getProjectDescriptor().getBuildRootIndex(); } @@ -316,9 +318,9 @@ public class JavaBuilderUtil { } @Override - public boolean belongsToCurrentChunk(File file) { + public boolean belongsToCurrentTargetChunk(File file) { final JavaSourceRootDescriptor rd = myBuildRootIndex.findJavaRootDescriptor(myContext, file); - return rd != null && myChunkModules.contains(rd.target.getModule()); + return rd != null && myChunkTargets.contains(rd.target); } } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/java/dependencyView/Mappings.java b/jps/jps-builders/src/org/jetbrains/jps/builders/java/dependencyView/Mappings.java index 03014474592b..f81f6c1cd414 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/java/dependencyView/Mappings.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/java/dependencyView/Mappings.java @@ -787,14 +787,14 @@ public class Mappings { } @Override - public boolean belongsToCurrentChunk(File file) { + public boolean belongsToCurrentTargetChunk(File file) { return true; } }; boolean accept(File file); - boolean belongsToCurrentChunk(File file); + boolean belongsToCurrentTargetChunk(File file); } private class Differential { @@ -1769,7 +1769,7 @@ public class Mappings { for (ClassRepr c : addedClasses) { if (!c.isLocal() && !c.isAnonymous() && isEmpty(c.getOuterClassName())) { final File currentlyMappedTo = myClassToSourceFile.get(c.name); - if (currentlyMappedTo != null && !FileUtil.filesEqual(currentlyMappedTo, srcFile) && currentlyMappedTo.exists() && myFilter.belongsToCurrentChunk(currentlyMappedTo)) { + if (currentlyMappedTo != null && !FileUtil.filesEqual(currentlyMappedTo, srcFile) && currentlyMappedTo.exists() && myFilter.belongsToCurrentTargetChunk(currentlyMappedTo)) { // Same classes from different source files. // Schedule for recompilation both to make possible 'duplicate sources' error evident debug("Scheduling for recompilation duplicated sources: ", currentlyMappedTo.getPath() + "; " + srcFile.getPath()); diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildRunner.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildRunner.java index 51a43222ae6e..f2650717ff50 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildRunner.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildRunner.java @@ -119,13 +119,14 @@ public class BuildRunner { public void runBuild(ProjectDescriptor pd, CanceledStatus cs, @Nullable Callbacks.ConstantAffectionResolver constantSearch, MessageHandler msgHandler, BuildType buildType) throws Exception { for (int attempt = 0; attempt < 2; attempt++) { - final CompileScope compileScope = createCompilationScope(pd, myScopes, myFilePaths); + final boolean forceClean = myForceCleanCaches && myFilePaths.isEmpty(); + final CompileScope compileScope = createCompilationScope(pd, myScopes, myFilePaths, forceClean); final IncProjectBuilder builder = new IncProjectBuilder(pd, BuilderRegistry.getInstance(), myBuilderParams, cs, constantSearch); builder.addMessageHandler(msgHandler); try { switch (buildType) { case BUILD: - builder.build(compileScope, myForceCleanCaches); + builder.build(compileScope, forceClean); break; case CLEAN: @@ -150,8 +151,8 @@ public class BuildRunner { } } - private CompileScope createCompilationScope(ProjectDescriptor pd, List<TargetTypeBuildScope> scopes, - Collection<String> paths) throws Exception { + private static CompileScope createCompilationScope(ProjectDescriptor pd, List<TargetTypeBuildScope> scopes, + Collection<String> paths, final boolean forceClean) throws Exception { Set<BuildTargetType<?>> targetTypes = new HashSet<BuildTargetType<?>>(); Set<BuildTargetType<?>> targetTypesToForceBuild = new HashSet<BuildTargetType<?>>(); Set<BuildTarget<?>> targets = new HashSet<BuildTarget<?>>(); @@ -164,7 +165,7 @@ public class BuildRunner { LOG.info("Unknown target type: " + scope.getTypeId()); continue; } - if (scope.getForceBuild() || myForceCleanCaches && paths.isEmpty()) { + if (scope.getForceBuild() || forceClean) { targetTypesToForceBuild.add(targetType); } if (scope.getAllTargets()) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScopeImpl.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScopeImpl.java index 0e9326f4acd3..e261a0e97e9f 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScopeImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileScopeImpl.java @@ -68,7 +68,7 @@ public class CompileScopeImpl extends CompileScope { @Override public boolean isBuildForced(@NotNull BuildTarget<?> target) { BuildTargetType<?> type = target.getTargetType(); - return myTypesToForceBuild.contains(type) && myFiles.get(target) == null &&(myTypes.contains(type) || myTargets.contains(target) || isAffectedByAssociatedModule(target)); + return myTypesToForceBuild.contains(type) && myFiles.isEmpty() && (myTypes.contains(type) || myTargets.contains(target) || isAffectedByAssociatedModule(target)); } @Override @@ -87,10 +87,7 @@ public class CompileScopeImpl extends CompileScope { return true; } final Set<File> files = myFiles.get(target); - if (files != null) { - return files.contains(file); - } - return myTypes.contains(target.getTargetType()) || myTargets.contains(target) || isAffectedByAssociatedModule(target); + return files != null && files.contains(file); } private boolean isAffectedByAssociatedModule(BuildTarget<?> target) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index 3595aa26927a..72425149cc34 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -507,6 +507,7 @@ public class JavaBuilder extends ModuleLevelBuilder { private static final Key<List<String>> JAVAC_OPTIONS = Key.create("_javac_options_"); private static final Key<List<String>> JAVAC_VM_OPTIONS = Key.create("_javac_vm_options_"); + private static final Key<String> USER_DEFINED_BYTECODE_TARGET = Key.create("_user_defined_bytecode_target_"); private static List<String> getCompilationVMOptions(CompileContext context) { List<String> cached = JAVAC_VM_OPTIONS.get(context); @@ -580,6 +581,13 @@ public class JavaBuilder extends ModuleLevelBuilder { } } } + + if (bytecodeTarget == null) { + // last resort and backward compatibility: + // check if user explicitly defined bytecode target in additional compiler options + bytecodeTarget = USER_DEFINED_BYTECODE_TARGET.get(context); + } + if (bytecodeTarget != null) { options.add("-target"); options.add(bytecodeTarget); @@ -684,13 +692,22 @@ public class JavaBuilder extends ModuleLevelBuilder { if (customArgs != null) { final StringTokenizer customOptsTokenizer = new StringTokenizer(customArgs, " \t\r\n"); boolean skip = false; + boolean targetOptionFound = false; while (customOptsTokenizer.hasMoreTokens()) { final String userOption = customOptsTokenizer.nextToken(); if (FILTERED_OPTIONS.contains(userOption)) { skip = true; + targetOptionFound = "-target".equals(userOption); continue; } - if (!skip) { + if (skip) { + skip = false; + if (targetOptionFound) { + targetOptionFound = false; + USER_DEFINED_BYTECODE_TARGET.set(context, userOption); + } + } + else { if (!FILTERED_SINGLE_OPTIONS.contains(userOption)) { if (userOption.startsWith("-J-")) { vmOptions.add(userOption.substring("-J".length())); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/OutputFilesSink.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/OutputFilesSink.java index 29ca799bb01c..519762b92954 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/OutputFilesSink.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/OutputFilesSink.java @@ -15,6 +15,7 @@ */ package org.jetbrains.jps.incremental.java; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.io.FileUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; @@ -39,6 +40,7 @@ import java.util.Set; * Date: 2/16/12 */ class OutputFilesSink implements OutputFileConsumer { + private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.incremental.java.OutputFilesSink"); private final CompileContext myContext; private final ModuleLevelBuilder.OutputConsumer myOutputConsumer; private final Callbacks.Backend myMappingsCallback; @@ -84,8 +86,18 @@ class OutputFilesSink implements OutputFileConsumer { if (!isTemp && outKind == JavaFileObject.Kind.CLASS && !Utils.errorsDetected(myContext)) { // register in mappings any non-temp class file - final ClassReader reader = new ClassReader(content.getBuffer(), content.getOffset(), content.getLength()); - myMappingsCallback.associate(FileUtil.toSystemIndependentName(fileObject.getFile().getPath()), sourcePath, reader); + try { + final ClassReader reader = new ClassReader(content.getBuffer(), content.getOffset(), content.getLength()); + myMappingsCallback.associate(FileUtil.toSystemIndependentName(fileObject.getFile().getPath()), sourcePath, reader); + } + catch (Throwable e) { + // need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation + final String message = "Class dependency information may be incomplete! Error parsing generated class " + fileObject.getFile().getPath(); + LOG.info(message, e); + myContext.processMessage(new CompilerMessage( + JavaBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, message + "\n" + CompilerMessage.getTextFromThrowable(e), sourcePath) + ); + } } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/messages/CompilerMessage.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/messages/CompilerMessage.java index 90580fccd3ec..01c857c2e9ef 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/messages/CompilerMessage.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/messages/CompilerMessage.java @@ -97,7 +97,7 @@ public class CompilerMessage extends BuildMessage { return getCompilerName() + ":" + getKind().name() + ":" + super.toString(); } - private static String getTextFromThrowable(Throwable internalError) { + public static String getTextFromThrowable(Throwable internalError) { StringBuilder text = new StringBuilder(); text.append("Error: "); final String msg = internalError.getMessage(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/javac/JavacMain.java b/jps/jps-builders/src/org/jetbrains/jps/javac/JavacMain.java index f4fdb98fd473..c53183c7af27 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/javac/JavacMain.java +++ b/jps/jps-builders/src/org/jetbrains/jps/javac/JavacMain.java @@ -88,6 +88,8 @@ public class JavacMain { fileManager.handleOption("-bootclasspath", Collections.singleton("").iterator()); // this will clear cached stuff fileManager.handleOption("-extdirs", Collections.singleton("").iterator()); // this will clear cached stuff + fileManager.handleOption("-endorseddirs", Collections.singleton("").iterator()); // this will clear cached stuff + final Collection<String> _options = prepareOptions(options, nowUsingJavac); try { fileManager.setOutputDirectories(outputDirToRoots); @@ -112,7 +114,7 @@ public class JavacMain { } if (!platformClasspath.isEmpty()) { try { - fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, platformClasspath); + fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, buildPlatformClasspath(platformClasspath, _options)); } catch (IOException e) { fileManager.getContext().reportMessage(Diagnostic.Kind.ERROR, e.getMessage()); @@ -143,7 +145,6 @@ public class JavacMain { }; try { - final Collection<String> _options = prepareOptions(options, nowUsingJavac); // to be on the safe side, we'll have to apply all options _before_ calling any of manager's methods // i.e. getJavaFileObjectsFromFiles() @@ -231,6 +232,89 @@ public class JavacMain { return result; } + private static Collection<File> buildPlatformClasspath(Collection<File> platformClasspath, Collection<String> options) { + final Map<PathOption, String> argsMap = new HashMap<PathOption, String>(); + for (Iterator<String> iterator = options.iterator(); iterator.hasNext(); ) { + final String arg = iterator.next(); + for (PathOption pathOption : PathOption.values()) { + if (pathOption.parse(argsMap, arg, iterator)) { + break; + } + } + } + if (argsMap.isEmpty()) { + return platformClasspath; + } + + final List<File> result = new ArrayList<File>(); + appendFiles(argsMap, PathOption.PREPEND_CP, result, false); + appendFiles(argsMap, PathOption.ENDORSED, result, true); + appendFiles(argsMap, PathOption.D_ENDORSED, result, true); + result.addAll(platformClasspath); + appendFiles(argsMap, PathOption.APPEND_CP, result, false); + appendFiles(argsMap, PathOption.EXTDIRS, result, true); + appendFiles(argsMap, PathOption.D_EXTDIRS, result, true); + return result; + } + + private static void appendFiles(Map<PathOption, String> args, PathOption option, Collection<File> container, boolean listDir) { + final String path = args.get(option); + if (path == null) { + return; + } + final StringTokenizer tokenizer = new StringTokenizer(path, File.pathSeparator, false); + while (tokenizer.hasMoreTokens()) { + final File file = new File(tokenizer.nextToken()); + if (listDir) { + final File[] files = file.listFiles(); + if (files != null) { + for (File f : files) { + final String fName = f.getName(); + if (fName.endsWith(".jar") || fName.endsWith(".zip")) { + container.add(f); + } + } + } + } + else { + container.add(file); + } + } + } + + enum PathOption { + PREPEND_CP("-Xbootclasspath/p:"), + ENDORSED("-endorseddirs"), D_ENDORSED("-Djava.endorsed.dirs="), + APPEND_CP("-Xbootclasspath/a:"), + EXTDIRS("-extdirs"), D_EXTDIRS("-Djava.ext.dirs="); + + private final String myArgName; + private final boolean myIsSuffix; + + PathOption(String name) { + myArgName = name; + myIsSuffix = name.endsWith("=") || name.endsWith(":"); + } + + public boolean parse(Map<PathOption, String> container, String arg, Iterator<String> rest) { + if (myIsSuffix) { + if (arg.startsWith(myArgName)) { + container.put(this, arg.substring(myArgName.length())); + return true; + } + } + else { + if (arg.equals(myArgName)) { + if (rest.hasNext()) { + container.put(this, rest.next()); + } + return true; + } + } + return false; + } + } + private static class ContextImpl implements JavacFileManager.Context { private final StandardJavaFileManager myStdManager; private final DiagnosticOutputConsumer myOutConsumer; diff --git a/jps/jps-builders/src/org/jetbrains/jps/javac/OptimizedFileManager17.java b/jps/jps-builders/src/org/jetbrains/jps/javac/OptimizedFileManager17.java index 2d96145a20c9..3b0c1731ba2d 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/javac/OptimizedFileManager17.java +++ b/jps/jps-builders/src/org/jetbrains/jps/javac/OptimizedFileManager17.java @@ -47,6 +47,12 @@ class OptimizedFileManager17 extends com.sun.tools.javac.file.JavacFileManager { private final Map<File, File[]> myDirectoryCache = new HashMap<File, File[]>(); public static final File[] NULL_FILE_ARRAY = new File[0]; + private static final String _OS_NAME = System.getProperty("os.name").toLowerCase(Locale.US); + private static final boolean isWindows = _OS_NAME.startsWith("windows"); + private static final boolean isOS2 = _OS_NAME.startsWith("os/2") || _OS_NAME.startsWith("os2"); + private static final boolean isMac = _OS_NAME.startsWith("mac"); + private static final boolean isFileSystemCaseSensitive = !isWindows && !isOS2 && !isMac; + public OptimizedFileManager17() throws Throwable { super(new Context(), true, null); final Field archivesField = com.sun.tools.javac.file.JavacFileManager.class.getDeclaredField("archives"); @@ -214,7 +220,7 @@ class OptimizedFileManager17 extends com.sun.tools.javac.file.JavacFileManager { private class InputFileObject extends BaseFileObject { private String name; - final File file; + private final File file; private Reference<File> absFileRef; public InputFileObject(JavacFileManager fileManager, File f) { @@ -285,20 +291,38 @@ class OptimizedFileManager17 extends com.sun.tools.javac.file.JavacFileManager { @Override protected String inferBinaryName(Iterable<? extends File> path) { - String fPath = file.getPath(); - //System.err.println("RegularFileObject " + file + " " +r.getPath()); + final String fPath = file.getPath(); for (File dir: path) { - //System.err.println("dir: " + dir); - String dPath = dir.getPath(); - if (dPath.length() == 0) - dPath = System.getProperty("user.dir"); - if (!dPath.endsWith(File.separator)) - dPath += File.separator; - if (fPath.regionMatches(true, 0, dPath, 0, dPath.length()) - && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) { - String relativeName = fPath.substring(dPath.length()); - return removeExtension(relativeName).replace(File.separatorChar, '.'); + String dirPath = dir.getPath(); + if (dirPath.length() == 0) { + dirPath = System.getProperty("user.dir"); + } + if (!fPath.regionMatches(!isFileSystemCaseSensitive, 0, dirPath, 0, dirPath.length())) { + continue; + } + final int pathLength = fPath.length(); + final boolean endsWithSeparator = dirPath.endsWith(File.separator); + if (!endsWithSeparator) { + // need to check if the next char in fPath is file separator + final int separatorIdx = dirPath.length(); + if (pathLength <= separatorIdx || fPath.charAt(separatorIdx) != File.separatorChar) { + continue; + } + } + // fPath starts with dirPath + final int startIndex = endsWithSeparator ? dirPath.length() : dirPath.length() + 1; + int endIndex = fPath.lastIndexOf('.'); + if (endIndex <= startIndex) { + endIndex = fPath.length(); + } + final int length = endIndex - startIndex; + final StringBuilder buf = new StringBuilder(length).append(fPath, startIndex, endIndex); + for (int idx = 0; idx < length; idx++) { + if (buf.charAt(idx) == File.separatorChar) { + buf.setCharAt(idx, '.'); + } } + return buf.toString(); } return null; } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/BuildResult.java b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/BuildResult.java index 4ada300cb65a..0df6ded1041b 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/BuildResult.java +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/BuildResult.java @@ -32,11 +32,13 @@ import java.util.List; */ public class BuildResult implements MessageHandler { private final List<BuildMessage> myErrorMessages; + private final List<BuildMessage> myWarnMessages; private final List<BuildMessage> myInfoMessages; private boolean myUpToDate = true; public BuildResult() { myErrorMessages = new ArrayList<BuildMessage>(); + myWarnMessages = new ArrayList<BuildMessage>(); myInfoMessages = new ArrayList<BuildMessage>(); } @@ -46,6 +48,9 @@ public class BuildResult implements MessageHandler { myErrorMessages.add(msg); myUpToDate = false; } + else if (msg.getKind() == BuildMessage.Kind.WARNING) { + myWarnMessages.add(msg); + } else { myInfoMessages.add(msg); } @@ -76,4 +81,9 @@ public class BuildResult implements MessageHandler { public List<BuildMessage> getErrorMessages() { return Collections.unmodifiableList(myErrorMessages); } + + @NotNull + public List<BuildMessage> getWarnMessages() { + return myWarnMessages; + } } diff --git a/jps/lib/optimizedFileManager.jar b/jps/lib/optimizedFileManager.jar Binary files differindex cc5355bc32a6..ce76aa5dbc8d 100644 --- a/jps/lib/optimizedFileManager.jar +++ b/jps/lib/optimizedFileManager.jar diff --git a/jps/model-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeAssocTable.java b/jps/model-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeAssocTable.java index 8f6e14b55471..2fd1fca0a9f0 100644 --- a/jps/model-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeAssocTable.java +++ b/jps/model-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeAssocTable.java @@ -21,6 +21,7 @@ import com.intellij.openapi.fileTypes.ExtensionFileNameMatcher; import com.intellij.openapi.fileTypes.FileNameMatcher; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtilRt; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.text.CaseInsensitiveStringHashingStrategy; import gnu.trove.THashMap; @@ -177,7 +178,7 @@ public class FileTypeAssocTable<T> { if (mapping.getFirst().accept(fileName)) return mapping.getSecond(); } - return myExtensionMappings.get(FileUtilRt.getExtension(fileName).toLowerCase()); + return myExtensionMappings.get(StringUtil.toLowerCase(FileUtilRt.getExtension(fileName))); } @Nullable |