summaryrefslogtreecommitdiff
path: root/java/compiler/impl/src/com/intellij/compiler/impl
diff options
context:
space:
mode:
Diffstat (limited to 'java/compiler/impl/src/com/intellij/compiler/impl')
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java11
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java180
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/InternedPath.java79
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/OutputPathFinder.java219
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/PackagingCompilerAdapter.java34
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java343
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseSettingsBuilder.java47
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacSettingsBuilder.java92
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/BuildInstructionBase.java72
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/DependentJarsEvaluator.java44
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/DestinationInfo.java60
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/ExplodedDestinationInfo.java33
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/FileCopyInstructionImpl.java76
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarDestinationInfo.java55
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarInfo.java77
-rw-r--r--java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarsBuilder.java283
16 files changed, 4 insertions, 1701 deletions
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
index 46584ef9c8bf..406d16574955 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
@@ -176,17 +176,6 @@ public class CompileDriver {
}
}
- private static boolean containsFileIndexScopes(CompileScope scope) {
- if (scope instanceof CompositeScope) {
- for (CompileScope childScope : ((CompositeScope)scope).getScopes()) {
- if (containsFileIndexScopes(childScope)) {
- return true;
- }
- }
- }
- return scope instanceof FileIndexCompileScope;
- }
-
private void doRebuild(CompileStatusNotification callback, CompilerMessage message, final CompileScope compileScope) {
if (validateCompilerConfiguration(compileScope)) {
startup(compileScope, true, false, callback, message);
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java
index 9b227da1dbf8..67bdb5209f39 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java
@@ -20,36 +20,24 @@
*/
package com.intellij.compiler.impl;
-import com.intellij.CommonBundle;
-import com.intellij.compiler.CompilerConfiguration;
-import com.intellij.compiler.impl.javaCompiler.ModuleChunk;
-import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.compiler.CompilerBundle;
import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.LocalFileSystem;
-import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.RefreshQueue;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.util.ThrowableRunnable;
-import com.intellij.util.containers.ContainerUtil;
-import gnu.trove.THashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
-import java.io.FileFilter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
public class CompilerUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.CompilerUtil");
@@ -62,51 +50,6 @@ public class CompilerUtil {
return path;
}
- public static void collectFiles(Collection<File> container, File rootDir, FileFilter fileFilter) {
- final File[] files = rootDir.listFiles(fileFilter);
- if (files == null) {
- return;
- }
- for (File file : files) {
- if (file.isDirectory()) {
- collectFiles(container, file, fileFilter);
- }
- else {
- container.add(file);
- }
- }
- }
-
- public static Map<Module, List<VirtualFile>> buildModuleToFilesMap(CompileContext context, VirtualFile[] files) {
- return buildModuleToFilesMap(context, Arrays.asList(files));
- }
-
-
- public static Map<Module, List<VirtualFile>> buildModuleToFilesMap(final CompileContext context, final List<VirtualFile> files) {
- //assertion: all files are different
- final Map<Module, List<VirtualFile>> map = new THashMap<Module, List<VirtualFile>>();
- ApplicationManager.getApplication().runReadAction(new Runnable() {
- public void run() {
- for (VirtualFile file : files) {
- final Module module = context.getModuleByFile(file);
-
- if (module == null) {
- continue; // looks like file invalidated
- }
-
- List<VirtualFile> moduleFiles = map.get(module);
- if (moduleFiles == null) {
- moduleFiles = new ArrayList<VirtualFile>();
- map.put(module, moduleFiles);
- }
- moduleFiles.add(file);
- }
- }
- });
- return map;
- }
-
-
/**
* must not be called inside ReadAction
* @param files
@@ -167,58 +110,6 @@ public class CompilerUtil {
}
}
- public static void addLocaleOptions(final List<String> commandLine, final boolean launcherUsed) {
- // need to specify default encoding so that javac outputs messages in 'correct' language
- //noinspection HardCodedStringLiteral
- commandLine.add((launcherUsed? "-J" : "") + "-D" + CharsetToolkit.FILE_ENCODING_PROPERTY + "=" + CharsetToolkit.getDefaultSystemCharset().name());
- // javac's VM should use the same default locale that IDEA uses in order for javac to print messages in 'correct' language
- //noinspection HardCodedStringLiteral
- final String lang = System.getProperty("user.language");
- if (lang != null) {
- //noinspection HardCodedStringLiteral
- commandLine.add((launcherUsed? "-J" : "") + "-Duser.language=" + lang);
- }
- //noinspection HardCodedStringLiteral
- final String country = System.getProperty("user.country");
- if (country != null) {
- //noinspection HardCodedStringLiteral
- commandLine.add((launcherUsed? "-J" : "") + "-Duser.country=" + country);
- }
- //noinspection HardCodedStringLiteral
- final String region = System.getProperty("user.region");
- if (region != null) {
- //noinspection HardCodedStringLiteral
- commandLine.add((launcherUsed? "-J" : "") + "-Duser.region=" + region);
- }
- }
-
- public static void addTargetCommandLineSwitch(final ModuleChunk chunk, final List<String> commandLine) {
- String optionValue = null;
- CompilerConfiguration config = null;
- final Module[] modules = chunk.getModules();
- for (Module module : modules) {
- if (config == null) {
- config = CompilerConfiguration.getInstance(module.getProject());
- }
- final String moduleTarget = config.getBytecodeTargetLevel(module);
- if (moduleTarget == null) {
- continue;
- }
- if (optionValue == null) {
- optionValue = moduleTarget;
- }
- else {
- if (moduleTarget.compareTo(optionValue) < 0) {
- optionValue = moduleTarget; // use the lower possible target among modules that form the chunk
- }
- }
- }
- if (optionValue != null) {
- commandLine.add("-target");
- commandLine.add(optionValue);
- }
- }
-
public static void addSourceCommandLineSwitch(final Sdk jdk, LanguageLevel chunkLanguageLevel, @NonNls final List<String> commandLine) {
final String versionString = jdk.getVersionString();
if (StringUtil.isEmpty(versionString)) {
@@ -312,67 +203,4 @@ public class CompilerUtil {
public static void logDuration(final String activityName, long duration) {
LOG.info(activityName + " took " + duration + " ms: " + duration /60000 + " min " +(duration %60000)/1000 + "sec");
}
-
- public static void clearOutputDirectories(final Collection<File> outputDirectories) {
- final long start = System.currentTimeMillis();
- // do not delete directories themselves, or we'll get rootsChanged() otherwise
- final Collection<File> filesToDelete = new ArrayList<File>(outputDirectories.size() * 2);
- for (File outputDirectory : outputDirectories) {
- File[] files = outputDirectory.listFiles();
- if (files != null) {
- ContainerUtil.addAll(filesToDelete, files);
- }
- }
- if (filesToDelete.size() > 0) {
- FileUtil.asyncDelete(filesToDelete);
-
- // ensure output directories exist
- for (final File file : outputDirectories) {
- file.mkdirs();
- }
- final long clearStop = System.currentTimeMillis();
-
- refreshIODirectories(outputDirectories);
-
- final long refreshStop = System.currentTimeMillis();
-
- logDuration("Clearing output dirs", clearStop - start);
- logDuration("Refreshing output directories", refreshStop - clearStop);
- }
- }
-
- public static void computeIntersectingPaths(final Project project,
- final Collection<VirtualFile> outputPaths,
- final Collection<VirtualFile> result) {
- for (Module module : ModuleManager.getInstance(project).getModules()) {
- final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
- final VirtualFile[] sourceRoots = rootManager.getSourceRoots();
- for (final VirtualFile outputPath : outputPaths) {
- for (VirtualFile sourceRoot : sourceRoots) {
- if (VfsUtilCore.isAncestor(outputPath, sourceRoot, true) || VfsUtilCore.isAncestor(sourceRoot, outputPath, false)) {
- result.add(outputPath);
- }
- }
- }
- }
- }
-
- public static boolean askUserToContinueWithNoClearing(Project project, Collection<VirtualFile> affectedOutputPaths) {
- final StringBuilder paths = new StringBuilder();
- for (final VirtualFile affectedOutputPath : affectedOutputPaths) {
- if (paths.length() > 0) {
- paths.append(",\n");
- }
- paths.append(affectedOutputPath.getPath().replace('/', File.separatorChar));
- }
- final int answer = Messages.showOkCancelDialog(project,
- CompilerBundle.message("warning.sources.under.output.paths", paths.toString()),
- CommonBundle.getErrorTitle(), Messages.getWarningIcon());
- if (answer == Messages.OK) { // ok
- return true;
- }
- else {
- return false;
- }
- }
}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/InternedPath.java b/java/compiler/impl/src/com/intellij/compiler/impl/InternedPath.java
deleted file mode 100644
index 7914dc29c2c1..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/InternedPath.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.compiler.impl;
-
-import com.intellij.util.StringBuilderSpinAllocator;
-import com.intellij.util.containers.StringInterner;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Eugene Zhuravlev
- * Date: Jun 21, 2006
- */
-public class InternedPath {
- private final @NotNull List<String> myValue;
-
- public InternedPath(StringInterner interner, String url, final char separator) {
- myValue = convert(interner, url, separator);
- }
-
- public String toString() {
- return join(myValue, '/');
- }
-
- public static List<String> convert(StringInterner interner, String value, char delim) {
- final List<String> result = new ArrayList<String>();
- int start = 0;
- final int len = value.length();
- for (int idx = 0; idx < len; idx++) {
- if (value.charAt(idx) == delim) {
- result.add(interner.intern(value.substring(start, idx)));
- start = idx + 1;
- }
- }
- if (start < value.length()) {
- result.add(interner.intern(value.substring(start)));
- }
- if (len > 0 && value.charAt(len-1) == delim) { // ends with delimiter
- result.add("");
- }
- return result;
- }
-
- public static String join(List<String> value, char separator) {
- final int size = value.size();
- if (size > 1) {
- final StringBuilder builder = StringBuilderSpinAllocator.alloc();
- try {
- builder.append(value.get(0));
- for (int idx = 1; idx < size; idx++) {
- builder.append(separator).append(value.get(idx));
- }
- return builder.toString();
- }
- finally {
- StringBuilderSpinAllocator.dispose(builder);
- }
- }
- else if (size == 1){
- return value.get(0);
- }
- return "";
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/OutputPathFinder.java b/java/compiler/impl/src/com/intellij/compiler/impl/OutputPathFinder.java
deleted file mode 100644
index 6a712d131711..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/OutputPathFinder.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.compiler.impl;
-
-import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.io.FileUtil;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Eugene Zhuravlev
- * Date: Apr 6, 2009
- */
-public class OutputPathFinder {
- private final Node myRoot = new Node("");
-
- public OutputPathFinder(Set<File> outputDirs) {
- for (File dir : outputDirs) {
- final String path = FileUtil.toSystemIndependentName(dir.getPath());
- Node node = myRoot;
- int idx = path.startsWith("/")? 1 : 0;
- int slashIndex = path.indexOf('/', idx);
-
- for (; slashIndex >= 0; slashIndex = path.indexOf('/', idx)) {
- final String name = path.substring(idx, slashIndex);
- node = node.addChild(name);
- idx = slashIndex + 1;
- }
-
- if (idx < path.length()) {
- node = node.addChild(path.substring(idx));
- }
-
- node.setData(path);
- }
- }
-
- @Nullable
- public String lookupOutputPath(File outputFile) {
- return lookupOutputPath(outputFile.getPath());
- }
-
- @Nullable
- public String lookupOutputPath(String filePath) {
- final String path = FileUtil.toSystemIndependentName(filePath);
- Node node = myRoot;
- int idx = path.startsWith("/")? 1 : 0;
-
- return findOutputPath(path, idx, node);
- }
-
- private static @Nullable String findOutputPath(final String path, int idx, Node node) {
- while (true) {
- final int slashIndex = path.indexOf('/', idx);
- final String name = slashIndex < idx? path.substring(idx) : path.substring(idx, slashIndex);
- node = node.getChild(name);
- if (node == null) {
- return null;
- }
- if (node.isOutputRoot()) {
- if (node.hasChildren() && slashIndex > idx) {
- final String candidate = findOutputPath(path, slashIndex + 1, node);
- if (candidate != null) {
- return candidate;
- }
- }
- return node.getData();
- }
- if (slashIndex < 0) {
- return null; // end of path reached
- }
- idx = slashIndex + 1;
- }
- }
-
- private static class Node {
- private final String myName;
- @Nullable
- private Object myChildren; // either a Node or a Map<String, Node> or a String or a Pair<String, Node or NodeMap>
-
- private Node(String name) {
- myName = name;
- }
-
- public String getName() {
- return myName;
- }
-
- public boolean isOutputRoot() {
- return myChildren instanceof String || myChildren instanceof Pair;
- }
-
- public boolean hasChildren() {
- return myChildren instanceof Map || myChildren instanceof Pair;
- }
-
- @Nullable
- public String getData() {
- if (myChildren instanceof String) {
- return (String)myChildren;
- }
- if (myChildren instanceof Pair) {
- //noinspection unchecked
- return (String)((Pair)myChildren).first;
- }
- return null;
- }
-
- public void setData(String path) {
- if (myChildren != null) {
- if (myChildren instanceof String) {
- myChildren = path;
- }
- else {
- myChildren = new Pair(path, myChildren instanceof Pair? ((Pair)myChildren).second : myChildren);
- }
- }
- else {
- myChildren = path;
- }
- }
-
- public Node addChild(String childName) {
- if (myChildren == null) {
- final Node node = new Node(childName);
- myChildren = node;
- return node;
- }
- if (myChildren instanceof String) {
- final Node node = new Node(childName);
- myChildren = new Pair(myChildren, node);
- return node;
- }
-
- final Map<String, Node> map;
- if (myChildren instanceof Map) {
- map = (Map<String, Node>)myChildren;
- }
- else if (myChildren instanceof Node) {
- final Node existingChild = (Node)myChildren;
- myChildren = map = new HashMap<String, Node>();
- map.put(existingChild.getName(), existingChild);
- }
- else { // myChildren is a Pair
- Object children = ((Pair)myChildren).second;
- if (children instanceof Map) {
- map = (Map<String, Node>)children;
- }
- else {
- final Node existingChild = (Node)children;
- myChildren = new Pair(((Pair)myChildren).first, map = new HashMap<String, Node>());
- map.put(existingChild.getName(), existingChild);
- }
- }
-
- Node node = map.get(childName);
- if (node == null) {
- map.put(childName, node = new Node(childName));
- }
- return node;
- }
-
- @Nullable
- public Node getChild(String childName) {
- final Object children = myChildren instanceof Pair? ((Pair)myChildren).second : myChildren;
- if (children instanceof Node) {
- final Node childNode = (Node)children;
- return childName.equals(childNode.getName())? childNode : null;
- }
- if (children instanceof Map) {
- return ((Map<String, Node>)myChildren).get(childName);
- }
- return null;
- }
- }
-
-
- public static void main(String[] args) {
- final Set<File> set = new HashSet<File>();
- set.add(new File("/a/b/c"));
- set.add(new File("a/b/d"));
- set.add(new File("a/b/e"));
- set.add(new File("/a/b/f/g"));
- set.add(new File("/a/b/f/g/zzz"));
-
- final OutputPathFinder finder = new OutputPathFinder(set);
-
- System.out.println(finder.lookupOutputPath(new File("a/b")));
- System.out.println(finder.lookupOutputPath(new File("a/b/c/dir1/dir2/File.class")));
- System.out.println(finder.lookupOutputPath(new File("a/b/d/dir1/dir2/File.class")));
- System.out.println(finder.lookupOutputPath(new File("a/b/jjjjj/dir1/dir2/File.class")));
- System.out.println(finder.lookupOutputPath(new File("a/b/e/File.class")));
- System.out.println(finder.lookupOutputPath(new File("a/b/File.class")));
-
- System.out.println(finder.lookupOutputPath(new File("/a/b/f/g/File.class")));
- System.out.println(finder.lookupOutputPath(new File("/a/b/f/g/ttt/yy/File.class")));
- System.out.println(finder.lookupOutputPath(new File("/a/b/f/g/zzz/File.class")));
- System.out.println(finder.lookupOutputPath(new File("/a/b/f/g/zzz/mmm/ttt/File.class")));
-
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/PackagingCompilerAdapter.java b/java/compiler/impl/src/com/intellij/compiler/impl/PackagingCompilerAdapter.java
deleted file mode 100644
index d2f7826a1704..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/PackagingCompilerAdapter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.compiler.impl;
-
-import com.intellij.openapi.compiler.CompileContext;
-import com.intellij.openapi.compiler.PackagingCompiler;
-import com.intellij.openapi.compiler.ValidityState;
-import org.jetbrains.annotations.Nullable;
-
-public class PackagingCompilerAdapter extends FileProcessingCompilerAdapter{
- private final PackagingCompiler myCompiler;
-
- public PackagingCompilerAdapter(CompileContext compileContext, PackagingCompiler compiler) {
- super(compileContext, compiler);
- myCompiler = compiler;
- }
-
- public void processOutdatedItem(CompileContext context, String url, @Nullable ValidityState state) {
- myCompiler.processOutdatedItem(context, url, state);
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java
deleted file mode 100644
index 513c5dad5102..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.compiler.impl.javaCompiler;
-
-import com.intellij.compiler.CompilerConfiguration;
-import com.intellij.compiler.CompilerConfigurationImpl;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.compiler.ex.CompileContextEx;
-import com.intellij.openapi.module.EffectiveLanguageLevelUtil;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.roots.JdkOrderEntry;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.roots.OrderEntry;
-import com.intellij.openapi.roots.OrderEnumerator;
-import com.intellij.openapi.util.Computable;
-import com.intellij.openapi.util.Condition;
-import com.intellij.openapi.vfs.VfsUtil;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.pom.java.LanguageLevel;
-import com.intellij.util.Chunk;
-import com.intellij.util.PathsList;
-import com.intellij.util.StringBuilderSpinAllocator;
-import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.OrderedSet;
-import gnu.trove.THashMap;
-import org.jetbrains.annotations.NotNull;
-
-import java.io.File;
-import java.util.*;
-
-/**
- * @author Eugene Zhuravlev
- * Date: Sep 29, 2004
- */
-public class ModuleChunk extends Chunk<Module> {
- private final CompileContextEx myContext;
- private final Map<Module, List<VirtualFile>> myModuleToFilesMap = new THashMap<Module, List<VirtualFile>>();
- private final Map<VirtualFile, VirtualFile> myTransformedToOriginalMap = new THashMap<VirtualFile, VirtualFile>();
- private int mySourcesFilter = ALL_SOURCES;
-
- public ModuleChunk(CompileContextEx context, Chunk<Module> chunk, Map<Module, List<VirtualFile>> moduleToFilesMap) {
- super(chunk.getNodes());
- myContext = context;
- for (final Module module : chunk.getNodes()) {
- final List<VirtualFile> files = moduleToFilesMap.get(module);
- // Important!!! Collections in the myModuleToFilesMap must be modifiable copies of the corresponding collections
- // from the moduleToFilesMap. This is needed to support SourceTransforming compilers
- myModuleToFilesMap.put(module, files == null ? Collections.<VirtualFile>emptyList() : new ArrayList<VirtualFile>(files));
- }
- }
-
- public static final int SOURCES = 0x1;
- public static final int TEST_SOURCES = 0x2;
- public static final int ALL_SOURCES = SOURCES | TEST_SOURCES;
-
- public void setSourcesFilter(int filter) {
- mySourcesFilter = filter;
- }
-
- public int getSourcesFilter() {
- return mySourcesFilter;
- }
-
- public void substituteWithTransformedVersion(Module module, int fileIndex, VirtualFile transformedFile) {
- final List<VirtualFile> moduleFiles = getFilesToCompile(module);
- final VirtualFile currentFile = moduleFiles.get(fileIndex);
- moduleFiles.set(fileIndex, transformedFile);
- VirtualFile originalFile = myTransformedToOriginalMap.remove(currentFile);
- if (originalFile == null) {
- originalFile = currentFile;
- }
- myTransformedToOriginalMap.put(transformedFile, originalFile);
- }
-
- public VirtualFile getOriginalFile(VirtualFile file) {
- final VirtualFile original = myTransformedToOriginalMap.get(file);
- return original != null? original : file;
- }
-
- @NotNull
- public List<VirtualFile> getFilesToCompile(Module forModule) {
- return myModuleToFilesMap.get(forModule);
- }
-
- @NotNull
- public List<VirtualFile> getFilesToCompile() {
- if (getModuleCount() == 0) {
- return Collections.emptyList();
- }
- final Set<Module> modules = getNodes();
-
- final List<VirtualFile> filesToCompile = new ArrayList<VirtualFile>();
- for (final Module module : modules) {
- final List<VirtualFile> moduleCompilableFiles = getFilesToCompile(module);
- if (mySourcesFilter == ALL_SOURCES) {
- filesToCompile.addAll(moduleCompilableFiles);
- }
- else {
- for (final VirtualFile file : moduleCompilableFiles) {
- VirtualFile originalFile = myTransformedToOriginalMap.get(file);
- if (originalFile == null) {
- originalFile = file;
- }
- if (mySourcesFilter == TEST_SOURCES) {
- if (myContext.isInTestSourceContent(originalFile)) {
- filesToCompile.add(file);
- }
- }
- else {
- if (!myContext.isInTestSourceContent(originalFile)) {
- filesToCompile.add(file);
- }
- }
- }
- }
- }
- return filesToCompile;
- }
-
- /**
- * @return the jdk. Assumes that the jdk is the same for all modules
- */
- public Sdk getJdk() {
- final Module module = getNodes().iterator().next();
- return ModuleRootManager.getInstance(module).getSdk();
- }
-
- public VirtualFile[] getSourceRoots() {
- return getSourceRoots(mySourcesFilter);
- }
-
- private VirtualFile[] getSourceRoots(final int sourcesFilter) {
- return ApplicationManager.getApplication().runReadAction(new Computable<VirtualFile[]>() {
- public VirtualFile[] compute() {
- return filterRoots(getAllSourceRoots(), getNodes().iterator().next().getProject(), sourcesFilter);
- }
- });
- }
-
- public VirtualFile[] getSourceRoots(final Module module) {
- if (!getNodes().contains(module)) {
- return VirtualFile.EMPTY_ARRAY;
- }
- return ApplicationManager.getApplication().runReadAction(new Computable<VirtualFile[]>() {
- public VirtualFile[] compute() {
- return filterRoots(myContext.getSourceRoots(module), module.getProject(), mySourcesFilter);
- }
- });
- }
-
- private VirtualFile[] filterRoots(VirtualFile[] roots, Project project, final int sourcesFilter) {
- final List<VirtualFile> filteredRoots = new ArrayList<VirtualFile>(roots.length);
- final CompilerConfigurationImpl compilerConfiguration = (CompilerConfigurationImpl)CompilerConfiguration.getInstance(project);
- for (final VirtualFile root : roots) {
- if (sourcesFilter != ALL_SOURCES) {
- if (myContext.isInTestSourceContent(root)) {
- if ((sourcesFilter & TEST_SOURCES) == 0) {
- continue;
- }
- }
- else {
- if ((sourcesFilter & SOURCES) == 0) {
- continue;
- }
- }
- }
- if (compilerConfiguration.isExcludedFromCompilation(root)) {
- continue;
- }
- filteredRoots.add(root);
- }
- return VfsUtil.toVirtualFileArray(filteredRoots);
- }
-
- private VirtualFile[] getAllSourceRoots() {
- final Set<Module> modules = getNodes();
- Set<VirtualFile> roots = new HashSet<VirtualFile>();
- for (final Module module : modules) {
- ContainerUtil.addAll(roots, myContext.getSourceRoots(module));
- }
- return VfsUtil.toVirtualFileArray(roots);
- }
-
- public String getCompilationClasspath() {
- final OrderedSet<VirtualFile> cpFiles = getCompilationClasspathFiles();
- return convertToStringPath(cpFiles);
-
- }
-
- public OrderedSet<VirtualFile> getCompilationClasspathFiles() {
- return getCompilationClasspathFiles(true);
- }
-
- public OrderedSet<VirtualFile> getCompilationClasspathFiles(final boolean exportedOnly) {
- final Set<Module> modules = getNodes();
-
- OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>();
- for (final Module module : modules) {
- Collections.addAll(cpFiles, orderEnumerator(module, exportedOnly, new AfterJdkOrderEntryCondition()).getClassesRoots());
- }
- return cpFiles;
- }
-
- private OrderEnumerator orderEnumerator(Module module, boolean exportedOnly, Condition<OrderEntry> condition) {
- OrderEnumerator enumerator = OrderEnumerator.orderEntries(module).compileOnly().satisfying(condition);
- if ((mySourcesFilter & TEST_SOURCES) == 0) {
- enumerator = enumerator.productionOnly();
- }
- enumerator = enumerator.recursively();
- return exportedOnly ? enumerator.exportedOnly() : enumerator;
- }
-
- public String getCompilationBootClasspath() {
- return convertToStringPath(getCompilationBootClasspathFiles());
- }
-
- public OrderedSet<VirtualFile> getCompilationBootClasspathFiles() {
- return getCompilationBootClasspathFiles(true);
- }
-
- public OrderedSet<VirtualFile> getCompilationBootClasspathFiles(final boolean exportedOnly) {
- final Set<Module> modules = getNodes();
- final OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>();
- final OrderedSet<VirtualFile> jdkFiles = new OrderedSet<VirtualFile>();
- for (final Module module : modules) {
- Collections.addAll(cpFiles, orderEnumerator(module, exportedOnly, new BeforeJdkOrderEntryCondition(module)).getClassesRoots());
- Collections.addAll(jdkFiles, OrderEnumerator.orderEntries(module).sdkOnly().getClassesRoots());
- }
- cpFiles.addAll(jdkFiles);
- return cpFiles;
- }
-
- private static String convertToStringPath(final OrderedSet<VirtualFile> cpFiles) {
- PathsList classpath = new PathsList();
- classpath.addVirtualFiles(cpFiles);
- return classpath.getPathsString();
- }
-
- //private String tryZipFor(String outputDir) {
- // final File zip = CompilerPathsEx.getZippedOutputPath(myContext.getProject(), outputDir);
- // if (zip.exists()) {
- // try {
- // myContext.commitZip(outputDir); // flush unsaved data if any
- // }
- // catch (IOException e) {
- // LOG.info(e);
- // }
- // return zip.getPath();
- // }
- // return outputDir;
- //}
-
- public int getModuleCount() {
- return getNodes().size();
- }
-
- public Module[] getModules() {
- final Set<Module> nodes = getNodes();
- return nodes.toArray(new Module[nodes.size()]);
- }
-
- public String getSourcePath() {
- return getSourcePath(mySourcesFilter);
- }
-
- public String getSourcePath(final int sourcesFilter) {
- if (getModuleCount() == 0) {
- return "";
- }
- final VirtualFile[] filteredRoots = getSourceRoots(sourcesFilter);
- final StringBuilder buffer = StringBuilderSpinAllocator.alloc();
- try {
- ApplicationManager.getApplication().runReadAction(new Runnable() {
- public void run() {
- for (VirtualFile root : filteredRoots) {
- if (buffer.length() > 0) {
- buffer.append(File.pathSeparatorChar);
- }
- buffer.append(root.getPath().replace('/', File.separatorChar));
- }
- }
- });
- return buffer.toString();
- }
- finally {
- StringBuilderSpinAllocator.dispose(buffer);
- }
- }
-
- //the check for equal language levels is done elsewhere
- public LanguageLevel getLanguageLevel() {
- return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(getNodes().iterator().next());
- }
-
- public Project getProject() {
- return myContext.getProject();
- }
-
- private static class BeforeJdkOrderEntryCondition implements Condition<OrderEntry> {
- private boolean myJdkFound;
- private final Module myOwnerModule;
-
- private BeforeJdkOrderEntryCondition(Module ownerModule) {
- myOwnerModule = ownerModule;
- }
-
- @Override
- public boolean value(OrderEntry orderEntry) {
- if (orderEntry instanceof JdkOrderEntry && myOwnerModule.equals(orderEntry.getOwnerModule())) {
- myJdkFound = true;
- }
- return !myJdkFound;
- }
- }
-
- private static class AfterJdkOrderEntryCondition implements Condition<OrderEntry> {
- private boolean myJdkFound;
-
- @Override
- public boolean value(OrderEntry orderEntry) {
- if (orderEntry instanceof JdkOrderEntry) {
- myJdkFound = true;
- return false;
- }
- return myJdkFound;
- }
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseSettingsBuilder.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseSettingsBuilder.java
deleted file mode 100644
index 7748223d0eac..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseSettingsBuilder.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2000-2012 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.compiler.impl.javaCompiler.eclipse;
-
-import com.intellij.compiler.impl.javaCompiler.javac.JavacSettingsBuilder;
-import com.intellij.openapi.module.Module;
-import com.intellij.util.Chunk;
-import org.jetbrains.jps.model.java.compiler.EclipseCompilerOptions;
-
-import java.util.Collection;
-
-/**
- * @author Eugene Zhuravlev
- * Date: 9/27/12
- */
-public class EclipseSettingsBuilder extends JavacSettingsBuilder {
- public EclipseSettingsBuilder(final EclipseCompilerOptions options) {
- super(options);
- }
-
- @Override
- public EclipseCompilerOptions getOptions() {
- return (EclipseCompilerOptions)super.getOptions();
- }
-
- @Override
- public Collection<String> getOptions(Chunk<Module> chunk) {
- final Collection<String> options = super.getOptions(chunk);
- if (getOptions().PROCEED_ON_ERROR) {
- options.add("-proceedOnError");
- }
- return options;
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacSettingsBuilder.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacSettingsBuilder.java
deleted file mode 100644
index 7be8e1da9fd4..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacSettingsBuilder.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.compiler.impl.javaCompiler.javac;
-
-import com.intellij.compiler.CompilerEncodingService;
-import com.intellij.compiler.impl.javaCompiler.ModuleChunk;
-import com.intellij.openapi.module.Module;
-import com.intellij.util.Chunk;
-import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions;
-
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.StringTokenizer;
-
-public class JavacSettingsBuilder {
- private final JpsJavaCompilerOptions myOptions;
-
- public JavacSettingsBuilder(JpsJavaCompilerOptions options) {
- myOptions = options;
- }
-
- protected JpsJavaCompilerOptions getOptions() {
- return myOptions;
- }
-
- public Collection<String> getOptions(Chunk<Module> chunk) {
- List<String> options = new ArrayList<String>();
- if (getOptions().DEBUGGING_INFO) {
- options.add("-g");
- }
- if (getOptions().DEPRECATION) {
- options.add("-deprecation");
- }
- if (getOptions().GENERATE_NO_WARNINGS) {
- options.add("-nowarn");
- }
- boolean isEncodingSet = false;
- final StringTokenizer tokenizer = new StringTokenizer(getOptions().ADDITIONAL_OPTIONS_STRING, " \t\r\n");
- while(tokenizer.hasMoreTokens()) {
- final String token = tokenizer.nextToken();
- if(!acceptUserOption(token)) {
- continue;
- }
- options.add(token);
- if ("-encoding".equals(token)) {
- isEncodingSet = true;
- }
- }
- if (!isEncodingSet && acceptEncoding()) {
- final Charset charset = CompilerEncodingService.getPreferredModuleEncoding(chunk);
- if (charset != null) {
- options.add("-encoding");
- options.add(charset.name());
- }
- }
- return options;
- }
-
- protected boolean acceptUserOption(String token) {
- return !("-g".equals(token) || "-deprecation".equals(token) || "-nowarn".equals(token));
- }
-
- protected boolean acceptEncoding() {
- return true;
- }
-
- public String getOptionsString(final ModuleChunk chunk) {
- final StringBuilder options = new StringBuilder();
- for (String option : getOptions(chunk)) {
- if (options.length() > 0) {
- options.append(" ");
- }
- options.append(option);
- }
- return options.toString();
- }
-} \ No newline at end of file
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/BuildInstructionBase.java b/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/BuildInstructionBase.java
deleted file mode 100644
index 446dd2e37b28..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/BuildInstructionBase.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @author cdr
- */
-package com.intellij.compiler.impl.packagingCompiler;
-
-import com.intellij.openapi.compiler.make.BuildInstruction;
-import com.intellij.openapi.util.UserDataHolderBase;
-import com.intellij.openapi.util.io.FileUtil;
-import gnu.trove.THashSet;
-import org.jetbrains.annotations.NonNls;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-
-public abstract class BuildInstructionBase extends UserDataHolderBase implements BuildInstruction, Cloneable {
- private final String myOutputRelativePath;
- private Collection<File> myFilesToDelete;
-
- protected BuildInstructionBase(String outputRelativePath) {
- myOutputRelativePath = outputRelativePath;
- }
-
- public String getOutputRelativePath() {
- return myOutputRelativePath;
- }
-
- public BuildInstructionBase clone() {
- return (BuildInstructionBase)super.clone();
- }
-
- public void addFileToDelete(File file) {
- if (myFilesToDelete == null) {
- myFilesToDelete = new THashSet<File>();
- }
- myFilesToDelete.add(file);
- }
-
- public void collectFilesToDelete(Collection<File> filesToDelete) {
- if (myFilesToDelete != null) {
- filesToDelete.addAll(myFilesToDelete);
- }
- myFilesToDelete = null;
- }
-
- @NonNls
- public String toString() {
- return super.toString();
- }
-
- protected File createTempFile(final String prefix, final String suffix) throws IOException {
- final File tempFile = FileUtil.createTempFile(prefix + "___", suffix);
- addFileToDelete(tempFile);
- return tempFile;
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/DependentJarsEvaluator.java b/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/DependentJarsEvaluator.java
deleted file mode 100644
index 9fa4e2c63de9..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/DependentJarsEvaluator.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.intellij.compiler.impl.packagingCompiler;
-
-import com.intellij.openapi.util.Pair;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-/**
- * @author nik
- */
-public class DependentJarsEvaluator {
- private final Set<JarInfo> myJars = new LinkedHashSet<JarInfo>();
-
- public void addJarWithDependencies(final JarInfo jarInfo) {
- if (myJars.add(jarInfo)) {
- for (JarDestinationInfo destination : jarInfo.getJarDestinations()) {
- addJarWithDependencies(destination.getJarInfo());
- }
- for (Pair<String, JarInfo> pair : jarInfo.getPackedJars()) {
- addJarWithDependencies(pair.getSecond());
- }
- }
- }
-
- public Set<JarInfo> getJars() {
- return myJars;
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/DestinationInfo.java b/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/DestinationInfo.java
deleted file mode 100644
index abda98227402..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/DestinationInfo.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.compiler.impl.packagingCompiler;
-
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.vfs.LocalFileSystem;
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * @author nik
- */
-public abstract class DestinationInfo {
- private VirtualFile myOutputFile;
- private final String myOutputPath;
- private final String myOutputFilePath;
-
- protected DestinationInfo(@NotNull final String outputPath, @Nullable final VirtualFile outputFile, @NotNull String outputFilePath) {
- myOutputFilePath = outputFilePath;
- myOutputFile = outputFile;
- myOutputPath = outputPath;
- }
-
- @NotNull
- public String getOutputPath() {
- return myOutputPath;
- }
-
- @Nullable
- public VirtualFile getOutputFile() {
- return myOutputFile;
- }
-
- @NotNull
- public String getOutputFilePath() {
- return myOutputFilePath;
- }
-
- public void update() {
- if (myOutputFile != null && !myOutputFile.isValid()) {
- myOutputFile = null;
- }
- if (myOutputFile == null) {
- myOutputFile = LocalFileSystem.getInstance().findFileByPath(myOutputFilePath);
- }
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/ExplodedDestinationInfo.java b/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/ExplodedDestinationInfo.java
deleted file mode 100644
index 33a3a8e8da11..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/ExplodedDestinationInfo.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.intellij.compiler.impl.packagingCompiler;
-
-import com.intellij.openapi.vfs.VirtualFile;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * @author nik
- */
-public class ExplodedDestinationInfo extends DestinationInfo {
- public ExplodedDestinationInfo(final String outputPath, @Nullable final VirtualFile outputFile) {
- super(outputPath, outputFile, outputPath);
- }
-
- public String toString() {
- return getOutputPath();
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/FileCopyInstructionImpl.java b/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/FileCopyInstructionImpl.java
deleted file mode 100644
index 64b58555f151..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/FileCopyInstructionImpl.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.compiler.impl.packagingCompiler;
-
-import com.intellij.openapi.compiler.make.BuildInstructionVisitor;
-import com.intellij.openapi.compiler.make.FileCopyInstruction;
-import com.intellij.openapi.util.io.FileUtil;
-
-import java.io.File;
-
-public class FileCopyInstructionImpl extends BuildInstructionBase implements FileCopyInstruction {
- private File myFile;
- private boolean myIsDirectory;
-
- public FileCopyInstructionImpl(File source, boolean isDirectory, String outputRelativePath) {
- super(outputRelativePath);
- setFile(source, isDirectory);
- }
-
- public boolean accept(BuildInstructionVisitor visitor) throws Exception {
- return visitor.visitFileCopyInstruction(this);
- }
-
- public String toString() {
- return "Copy " + getFile() + "->" + getOutputRelativePath();
- }
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof FileCopyInstruction)) return false;
-
- final FileCopyInstruction item = (FileCopyInstruction) o;
-
- if (getFile() != null ? !FileUtil.filesEqual(getFile(), item.getFile()) : item.getFile() != null) return false;
-
- if (getOutputRelativePath() != null) {
- if (!getOutputRelativePath().equals( item.getOutputRelativePath() )) return false;
- } else if ( item.getOutputRelativePath() != null ) {
- return false;
- }
-
- return true;
- }
-
- public int hashCode() {
- return (getFile() != null ? getFile().hashCode() : 0) +
- (getOutputRelativePath() != null ? getOutputRelativePath().hashCode():0);
- }
-
- public File getFile() {
- return myFile;
- }
-
- public boolean isDirectory() {
- return myIsDirectory;
- }
-
- private void setFile(File file, boolean isDirectory) {
- myFile = file;
- myIsDirectory = isDirectory;
- }
-
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarDestinationInfo.java b/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarDestinationInfo.java
deleted file mode 100644
index 5cc45c19278e..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarDestinationInfo.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.intellij.compiler.impl.packagingCompiler;
-
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.JarFileSystem;
-
-/**
- * @author nik
- */
-public class JarDestinationInfo extends DestinationInfo {
- private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.packagingCompiler.JarDestinationInfo");
- private final String myPathInJar;
- private final JarInfo myJarInfo;
-
- public JarDestinationInfo(final String pathInJar, final JarInfo jarInfo, DestinationInfo jarDestination) {
- super(appendPathInJar(jarDestination.getOutputPath(), pathInJar), jarDestination.getOutputFile(), jarDestination.getOutputFilePath());
- LOG.assertTrue(!pathInJar.startsWith(".."), pathInJar);
- myPathInJar = StringUtil.startsWithChar(pathInJar, '/') ? pathInJar : "/" + pathInJar;
- myJarInfo = jarInfo;
- }
-
- private static String appendPathInJar(String outputPath, String pathInJar) {
- LOG.assertTrue(outputPath.length() > 0 && outputPath.charAt(outputPath.length() - 1) != '/');
- LOG.assertTrue(pathInJar.length() > 0 && pathInJar.charAt(0) != '/');
- return outputPath + JarFileSystem.JAR_SEPARATOR + pathInJar;
- }
-
- public String getPathInJar() {
- return myPathInJar;
- }
-
- public JarInfo getJarInfo() {
- return myJarInfo;
- }
-
- public String toString() {
- return myPathInJar + "(" + getOutputPath() + ")";
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarInfo.java b/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarInfo.java
deleted file mode 100644
index 7626ca13469b..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarInfo.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.intellij.compiler.impl.packagingCompiler;
-
-import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.vfs.VirtualFile;
-
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
-
-/**
- * @author nik
- */
-public class JarInfo {
- private final List<Pair<String, VirtualFile>> myPackedFiles;
- private final LinkedHashSet<Pair<String, JarInfo>> myPackedJars;
- private final List<DestinationInfo> myDestinations;
-
- public JarInfo() {
- myDestinations = new ArrayList<DestinationInfo>();
- myPackedFiles = new ArrayList<Pair<String, VirtualFile>>();
- myPackedJars = new LinkedHashSet<Pair<String, JarInfo>>();
- }
-
- public void addDestination(DestinationInfo info) {
- myDestinations.add(info);
- if (info instanceof JarDestinationInfo) {
- JarDestinationInfo destinationInfo = (JarDestinationInfo)info;
- destinationInfo.getJarInfo().myPackedJars.add(Pair.create(destinationInfo.getPathInJar(), this));
- }
- }
-
- public void addContent(String pathInJar, VirtualFile sourceFile) {
- myPackedFiles.add(Pair.create(pathInJar, sourceFile));
- }
-
- public List<Pair<String, VirtualFile>> getPackedFiles() {
- return myPackedFiles;
- }
-
- public LinkedHashSet<Pair<String, JarInfo>> getPackedJars() {
- return myPackedJars;
- }
-
- public List<JarDestinationInfo> getJarDestinations() {
- final ArrayList<JarDestinationInfo> list = new ArrayList<JarDestinationInfo>();
- for (DestinationInfo destination : myDestinations) {
- if (destination instanceof JarDestinationInfo) {
- list.add((JarDestinationInfo)destination);
- }
- }
- return list;
- }
-
- public List<DestinationInfo> getAllDestinations() {
- return myDestinations;
- }
-
- public String getPresentableDestination() {
- return !myDestinations.isEmpty() ? myDestinations.get(0).getOutputPath() : "";
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarsBuilder.java b/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarsBuilder.java
deleted file mode 100644
index c543abe674cc..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/packagingCompiler/JarsBuilder.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright 2000-2014 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.intellij.compiler.impl.packagingCompiler;
-
-import com.intellij.openapi.compiler.CompileContext;
-import com.intellij.openapi.compiler.CompilerBundle;
-import com.intellij.openapi.compiler.CompilerMessageCategory;
-import com.intellij.openapi.deployment.DeploymentUtil;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.util.Couple;
-import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.io.FileUtil;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.VfsUtil;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.packaging.impl.compiler.ArtifactCompilerUtil;
-import com.intellij.util.ArrayUtil;
-import com.intellij.util.graph.CachingSemiGraph;
-import com.intellij.util.graph.DFSTBuilder;
-import com.intellij.util.graph.GraphGenerator;
-import com.intellij.util.io.ZipUtil;
-import gnu.trove.THashSet;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.*;
-import java.util.*;
-import java.util.jar.JarFile;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-/**
- * @author nik
- */
-public class JarsBuilder {
- private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.packagingCompiler.JarsBuilder");
- private final Set<JarInfo> myJarsToBuild;
- private final FileFilter myFileFilter;
- private final CompileContext myContext;
- private Map<JarInfo, File> myBuiltJars;
-
- public JarsBuilder(Set<JarInfo> jarsToBuild, FileFilter fileFilter, CompileContext context) {
- DependentJarsEvaluator evaluator = new DependentJarsEvaluator();
- for (JarInfo jarInfo : jarsToBuild) {
- evaluator.addJarWithDependencies(jarInfo);
- }
- myJarsToBuild = evaluator.getJars();
- myFileFilter = fileFilter;
- myContext = context;
- }
-
- public boolean buildJars(Set<String> writtenPaths) throws IOException {
- myContext.getProgressIndicator().setText(CompilerBundle.message("packaging.compiler.message.building.archives"));
-
- final JarInfo[] sortedJars = sortJars();
- if (sortedJars == null) {
- return false;
- }
-
- myBuiltJars = new HashMap<JarInfo, File>();
- try {
- for (JarInfo jar : sortedJars) {
- myContext.getProgressIndicator().checkCanceled();
- buildJar(jar);
- }
-
- myContext.getProgressIndicator().setText(CompilerBundle.message("packaging.compiler.message.copying.archives"));
- copyJars(writtenPaths);
- }
- finally {
- deleteTemporaryJars();
- }
-
-
- return true;
- }
-
- private void deleteTemporaryJars() {
- for (File file : myBuiltJars.values()) {
- FileUtil.delete(file);
- }
- }
-
- private void copyJars(final Set<String> writtenPaths) throws IOException {
- for (Map.Entry<JarInfo, File> entry : myBuiltJars.entrySet()) {
- File fromFile = entry.getValue();
- boolean first = true;
- for (DestinationInfo destination : entry.getKey().getAllDestinations()) {
- if (destination instanceof ExplodedDestinationInfo) {
- File toFile = new File(FileUtil.toSystemDependentName(destination.getOutputPath()));
-
- if (first) {
- first = false;
- renameFile(fromFile, toFile, writtenPaths);
- fromFile = toFile;
- }
- else {
- DeploymentUtil.getInstance().copyFile(fromFile, toFile, myContext, writtenPaths, myFileFilter);
- }
-
- }
- }
- }
- }
-
- private static void renameFile(final File fromFile, final File toFile, final Set<String> writtenPaths) throws IOException {
- FileUtil.rename(fromFile, toFile);
- writtenPaths.add(toFile.getPath());
- }
-
- @Nullable
- private JarInfo[] sortJars() {
- final DFSTBuilder<JarInfo> builder = new DFSTBuilder<JarInfo>(GraphGenerator.create(CachingSemiGraph.create(new JarsGraph())));
- if (!builder.isAcyclic()) {
- final Couple<JarInfo> dependency = builder.getCircularDependency();
- String message = CompilerBundle.message("packaging.compiler.error.cannot.build.circular.dependency.found.between.0.and.1",
- dependency.getFirst().getPresentableDestination(),
- dependency.getSecond().getPresentableDestination());
- myContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
- return null;
- }
-
- JarInfo[] jars = myJarsToBuild.toArray(new JarInfo[myJarsToBuild.size()]);
- Arrays.sort(jars, builder.comparator());
- jars = ArrayUtil.reverseArray(jars);
- return jars;
- }
-
- public Set<JarInfo> getJarsToBuild() {
- return myJarsToBuild;
- }
-
- private void buildJar(final JarInfo jar) throws IOException {
- if (jar.getPackedFiles().isEmpty() && jar.getPackedJars().isEmpty()) {
- myContext.addMessage(CompilerMessageCategory.WARNING, "Archive '" + jar.getPresentableDestination() + "' has no files so it won't be created", null, -1, -1);
- return;
- }
-
- myContext.getProgressIndicator()
- .setText(CompilerBundle.message("packaging.compiler.message.building.0", jar.getPresentableDestination()));
- File jarFile = FileUtil.createTempFile("artifactCompiler", "tmp");
- myBuiltJars.put(jar, jarFile);
-
- FileUtil.createParentDirs(jarFile);
-
- VirtualFile manifestFile = null;
- for (Pair<String, VirtualFile> pair : jar.getPackedFiles()) {
- if (pair.getFirst().equals(JarFile.MANIFEST_NAME)) {
- manifestFile = pair.getSecond();
- }
- }
- final JarOutputStream jarOutputStream = createJarOutputStream(jarFile, manifestFile);
-
- try {
- final THashSet<String> writtenPaths = new THashSet<String>();
- for (Pair<String, VirtualFile> pair : jar.getPackedFiles()) {
- if (pair.getFirst().equals(JarFile.MANIFEST_NAME)) continue;
- final VirtualFile sourceFile = pair.getSecond();
- if (sourceFile.isInLocalFileSystem()) {
- File file = VfsUtil.virtualToIoFile(sourceFile);
- addFileToJar(jarOutputStream, file, pair.getFirst(), writtenPaths);
- }
- else {
- extractFileAndAddToJar(jarOutputStream, sourceFile, pair.getFirst(), writtenPaths);
- }
- }
-
- for (Pair<String, JarInfo> nestedJar : jar.getPackedJars()) {
- File nestedJarFile = myBuiltJars.get(nestedJar.getSecond());
- if (nestedJarFile != null) {
- addFileToJar(jarOutputStream, nestedJarFile, nestedJar.getFirst(), writtenPaths);
- }
- else {
- LOG.debug("nested jar file " + nestedJar.getFirst() + " for " + jar.getPresentableDestination() + " not found");
- }
- }
- }
- finally {
- jarOutputStream.close();
- }
- }
-
- private static JarOutputStream createJarOutputStream(File jarFile, VirtualFile manifestFile) throws IOException {
- final BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(jarFile));
- final JarOutputStream jarOutputStream;
- if (manifestFile != null) {
- final InputStream manifestStream = manifestFile.getInputStream();
- try {
- jarOutputStream = new JarOutputStream(outputStream, new Manifest(manifestStream));
- }
- finally {
- manifestStream.close();
- }
- }
- else {
- jarOutputStream = new JarOutputStream(outputStream);
- }
- return jarOutputStream;
- }
-
- private void extractFileAndAddToJar(JarOutputStream jarOutputStream, VirtualFile sourceFile, String relativePath, THashSet<String> writtenPaths)
- throws IOException {
- relativePath = addParentDirectories(jarOutputStream, writtenPaths, relativePath);
- myContext.getProgressIndicator().setText2(relativePath);
- if (!writtenPaths.add(relativePath)) return;
-
- final BufferedInputStream input = ArtifactCompilerUtil.getJarEntryInputStream(sourceFile, myContext);
- if (input == null) return;
-
- ZipEntry entry = new ZipEntry(relativePath);
- entry.setTime(ArtifactCompilerUtil.getJarFile(sourceFile).lastModified());
- jarOutputStream.putNextEntry(entry);
- FileUtil.copy(input, jarOutputStream);
- jarOutputStream.closeEntry();
- }
-
- private void addFileToJar(final @NotNull JarOutputStream jarOutputStream, final @NotNull File file, @NotNull String relativePath,
- final @NotNull THashSet<String> writtenPaths) throws IOException {
- if (!file.exists()) {
- return;
- }
-
- relativePath = addParentDirectories(jarOutputStream, writtenPaths, relativePath);
- myContext.getProgressIndicator().setText2(relativePath);
- ZipUtil.addFileToZip(jarOutputStream, file, relativePath, writtenPaths, myFileFilter);
- }
-
- private static String addParentDirectories(JarOutputStream jarOutputStream, THashSet<String> writtenPaths, String relativePath) throws IOException {
- while (StringUtil.startsWithChar(relativePath, '/')) {
- relativePath = relativePath.substring(1);
- }
- int i = relativePath.indexOf('/');
- while (i != -1) {
- String prefix = relativePath.substring(0, i+1);
- if (!writtenPaths.contains(prefix) && prefix.length() > 1) {
- addEntry(jarOutputStream, prefix);
- writtenPaths.add(prefix);
- }
- i = relativePath.indexOf('/', i + 1);
- }
- return relativePath;
- }
-
- private static void addEntry(final ZipOutputStream output, @NonNls final String relativePath) throws IOException {
- ZipEntry e = new ZipEntry(relativePath);
- e.setMethod(ZipEntry.STORED);
- e.setSize(0);
- e.setCrc(0);
- output.putNextEntry(e);
- output.closeEntry();
- }
-
- private class JarsGraph implements GraphGenerator.SemiGraph<JarInfo> {
- public Collection<JarInfo> getNodes() {
- return myJarsToBuild;
- }
-
- public Iterator<JarInfo> getIn(final JarInfo n) {
- Set<JarInfo> ins = new HashSet<JarInfo>();
- for (JarDestinationInfo destination : n.getJarDestinations()) {
- ins.add(destination.getJarInfo());
- }
- return ins.iterator();
- }
- }
-}