diff --git a/build/lib/gant/jps-sources.zip b/build/lib/gant/jps-sources.zip
index fdd201988892..985632f5cc3d 100644
Binary files a/build/lib/gant/jps-sources.zip and b/build/lib/gant/jps-sources.zip differ
diff --git a/build/lib/gant/lib/jps.jar b/build/lib/gant/lib/jps.jar
index 4a5b749b50e8..34cb9fa28de0 100644
Binary files a/build/lib/gant/lib/jps.jar and b/build/lib/gant/lib/jps.jar differ
diff --git a/build/scripts/dist.gant b/build/scripts/dist.gant
index 2921df30192a..d2099fbbb82f 100644
--- a/build/scripts/dist.gant
+++ b/build/scripts/dist.gant
@@ -67,7 +67,7 @@ def wire_build_date(String buildNumber) {
target('default': 'The default target') {
depends(compile)
layoutAll(
- buildNumber: "IC-X.SNAPSHOT",
+ buildNumber: "IC-96.SNAPSHOT",
version: "IdeaX",
system_selector: "IntelliJIdeaCE10",
jdk_req: "1.6*",
diff --git a/java/compiler/impl/compiler-impl.iml b/java/compiler/impl/compiler-impl.iml
index 4f7473c9ff2a..a65d7e10171d 100644
--- a/java/compiler/impl/compiler-impl.iml
+++ b/java/compiler/impl/compiler-impl.iml
@@ -31,6 +31,7 @@
+
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 6efb8555b579..d51610877f88 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
@@ -24,7 +24,7 @@ package com.intellij.compiler.impl;
import com.intellij.CommonBundle;
import com.intellij.analysis.AnalysisScope;
import com.intellij.compiler.*;
-import com.intellij.compiler.impl.newApi.NewCompiler;
+import com.intellij.openapi.compiler.generic.GenericCompiler;
import com.intellij.compiler.make.CacheCorruptedException;
import com.intellij.compiler.make.CacheUtils;
import com.intellij.compiler.make.DependencyCache;
@@ -725,7 +725,7 @@ public class CompileDriver {
boolean didSomething = false;
final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
- NewCompilerRunner runner = new NewCompilerRunner(context, compilerManager, forceCompile, onlyCheckStatus);
+ GenericCompilerRunner runner = new GenericCompilerRunner(context, compilerManager, forceCompile, onlyCheckStatus);
try {
didSomething |= generateSources(compilerManager, context, forceCompile, onlyCheckStatus);
@@ -747,23 +747,23 @@ public class CompileDriver {
didSomething |= invokeFileProcessingCompilers(compilerManager, context, ClassInstrumentingCompiler.class,
FILE_PROCESSING_COMPILER_ADAPTER_FACTORY, isRebuild, false, onlyCheckStatus);
- didSomething |= runner.invokeCompilers(NewCompiler.CompileOrderPlace.CLASS_INSTRUMENTING);
+ didSomething |= runner.invokeCompilers(GenericCompiler.CompileOrderPlace.CLASS_INSTRUMENTING);
// explicitly passing forceCompile = false because in scopes that is narrower than ProjectScope it is impossible
// to understand whether the class to be processed is in scope or not. Otherwise compiler may process its items even if
// there were changes in completely independent files.
didSomething |= invokeFileProcessingCompilers(compilerManager, context, ClassPostProcessingCompiler.class,
FILE_PROCESSING_COMPILER_ADAPTER_FACTORY, isRebuild, false, onlyCheckStatus);
- didSomething |= runner.invokeCompilers(NewCompiler.CompileOrderPlace.CLASS_POST_PROCESSING);
+ didSomething |= runner.invokeCompilers(GenericCompiler.CompileOrderPlace.CLASS_POST_PROCESSING);
didSomething |= invokeFileProcessingCompilers(compilerManager, context, PackagingCompiler.class,
FILE_PACKAGING_COMPILER_ADAPTER_FACTORY,
isRebuild, false, onlyCheckStatus);
- didSomething |= runner.invokeCompilers(NewCompiler.CompileOrderPlace.PACKAGING);
+ didSomething |= runner.invokeCompilers(GenericCompiler.CompileOrderPlace.PACKAGING);
didSomething |= invokeFileProcessingCompilers(compilerManager, context, Validator.class, FILE_PROCESSING_COMPILER_ADAPTER_FACTORY,
forceCompile, true, onlyCheckStatus);
- didSomething |= runner.invokeCompilers(NewCompiler.CompileOrderPlace.VALIDATING);
+ didSomething |= runner.invokeCompilers(GenericCompiler.CompileOrderPlace.VALIDATING);
}
catch (ExitException e) {
if (LOG.isDebugEnabled()) {
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompilerCacheManager.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompilerCacheManager.java
index 4afce35c12ac..a254e44418de 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/CompilerCacheManager.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompilerCacheManager.java
@@ -15,8 +15,8 @@
*/
package com.intellij.compiler.impl;
-import com.intellij.compiler.impl.newApi.NewCompiler;
-import com.intellij.compiler.impl.newApi.NewCompilerCache;
+import com.intellij.compiler.impl.generic.GenericCompilerCache;
+import com.intellij.openapi.compiler.generic.GenericCompiler;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.compiler.Compiler;
@@ -44,7 +44,7 @@ import java.util.Map;
public class CompilerCacheManager implements ProjectComponent {
private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.CompilerCacheManager");
private final Map myCompilerToCacheMap = new HashMap();
- private final Map, NewCompilerCache,?>> myNewCachesMap = new HashMap, NewCompilerCache,?>>();
+ private final Map, GenericCompilerCache,?,?>> myGenericCachesMap = new HashMap, GenericCompilerCache,?,?>>();
private final List myCacheDisposables = new ArrayList();
private final File myCachesRoot;
private final Runnable myShutdownTask = new Runnable() {
@@ -90,21 +90,23 @@ public class CompilerCacheManager implements ProjectComponent {
return dir;
}
- public synchronized NewCompilerCache getNewCompilerCache(NewCompiler compiler) throws IOException {
- NewCompilerCache, ?> cache = myNewCachesMap.get(compiler);
+ public synchronized GenericCompilerCache
+ getGenericCompilerCache(GenericCompiler compiler) throws IOException {
+ GenericCompilerCache,?,?> cache = myGenericCachesMap.get(compiler);
if (cache == null) {
- final NewCompilerCache, ?> newCache = new NewCompilerCache(compiler, NewCompilerRunner.getNewCompilerCacheDir(myProject, compiler));
- myNewCachesMap.put(compiler, newCache);
+ final GenericCompilerCache,?,?> genericCache = new GenericCompilerCache(compiler, GenericCompilerRunner
+ .getGenericCompilerCacheDir(myProject, compiler));
+ myGenericCachesMap.put(compiler, genericCache);
myCacheDisposables.add(new Disposable() {
@Override
public void dispose() {
- newCache.close();
+ genericCache.close();
}
});
- cache = newCache;
+ cache = genericCache;
}
//noinspection unchecked
- return (NewCompilerCache)cache;
+ return (GenericCompilerCache)cache;
}
public synchronized FileProcessingCompilerStateCache getFileProcessingCompilerCache(FileProcessingCompiler compiler) throws IOException {
@@ -171,7 +173,7 @@ public class CompilerCacheManager implements ProjectComponent {
}
}
myCacheDisposables.clear();
- myNewCachesMap.clear();
+ myGenericCachesMap.clear();
myCompilerToCacheMap.clear();
}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/GenericCompilerRunner.java b/java/compiler/impl/src/com/intellij/compiler/impl/GenericCompilerRunner.java
new file mode 100644
index 000000000000..8b7a773bc0b6
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/GenericCompilerRunner.java
@@ -0,0 +1,305 @@
+/*
+ * Copyright 2000-2010 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.google.common.base.Throwables;
+import com.intellij.compiler.impl.generic.GenericCompilerCache;
+import com.intellij.compiler.impl.generic.GenericCompilerPersistentData;
+import com.intellij.openapi.compiler.generic.*;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ReadAction;
+import com.intellij.openapi.application.Result;
+import com.intellij.openapi.application.RunResult;
+import com.intellij.openapi.compiler.*;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.progress.ProcessCanceledException;
+import com.intellij.openapi.project.DumbService;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Ref;
+import com.intellij.util.CommonProcessors;
+import com.intellij.util.Processor;
+import com.intellij.util.ThrowableRunnable;
+import com.intellij.util.io.KeyDescriptor;
+import gnu.trove.THashSet;
+import gnu.trove.TObjectHashingStrategy;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @author nik
+ */
+public class GenericCompilerRunner {
+ private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.GenericCompilerRunner");
+ private CompileContext myContext;
+ private final boolean myForceCompile;
+ private final boolean myOnlyCheckStatus;
+ private final GenericCompiler,?,?>[] myCompilers;
+ private final Project myProject;
+
+ public GenericCompilerRunner(CompileContext context, CompilerManager compilerManager, boolean forceCompile, boolean onlyCheckStatus) {
+ myContext = context;
+ myForceCompile = forceCompile;
+ myOnlyCheckStatus = onlyCheckStatus;
+ myCompilers = compilerManager.getCompilers(GenericCompiler.class);
+ myProject = myContext.getProject();
+ }
+
+ public boolean invokeCompilers(GenericCompiler.CompileOrderPlace place) throws CompileDriver.ExitException {
+ boolean didSomething = false;
+ try {
+ for (GenericCompiler,?,?> compiler : myCompilers) {
+ if (compiler.getOrderPlace().equals(place)) {
+ didSomething = invokeCompiler(compiler);
+ }
+ }
+ }
+ catch (IOException e) {
+ LOG.info(e);
+ myContext.requestRebuildNextTime(e.getMessage());
+ throw new CompileDriver.ExitException(CompileDriver.ExitStatus.ERRORS);
+ }
+ catch (CompileDriver.ExitException e) {
+ throw e;
+ }
+ catch (ProcessCanceledException e) {
+ throw e;
+ }
+ catch (Exception e) {
+ LOG.info(e);
+ myContext.addMessage(CompilerMessageCategory.ERROR, CompilerBundle.message("compiler.error.exception", e.getMessage()), null, -1, -1);
+ }
+ return didSomething;
+ }
+
+ private boolean invokeCompiler(GenericCompiler compiler) throws IOException, CompileDriver.ExitException {
+ return invokeCompiler(compiler, compiler.createInstance(myContext));
+ }
+
+ private , Key, SourceState, OutputState>
+ boolean invokeCompiler(GenericCompiler compiler, final GenericCompilerInstance instance) throws IOException, CompileDriver.ExitException {
+ final GenericCompilerCache cache = CompilerCacheManager.getInstance(myProject).getGenericCompilerCache(compiler);
+ GenericCompilerPersistentData
+ data = new GenericCompilerPersistentData(getGenericCompilerCacheDir(myProject, compiler), compiler.getVersion());
+ if (data.isVersionChanged()) {
+ LOG.info("Clearing cache for " + compiler.getDescription());
+ cache.wipe();
+ data.save();
+ }
+
+ final Set targetsToRemove = new HashSet(data.getAllTargets());
+ new ReadAction() {
+ protected void run(final Result result) {
+ for (T target : instance.getAllTargets()) {
+ targetsToRemove.remove(target.getId());
+ }
+ }
+ }.execute();
+
+ if (!myOnlyCheckStatus) {
+ for (final String target : targetsToRemove) {
+ final int id = data.removeId(target);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Removing obsolete target '" + target + "' (id=" + id + ")");
+ }
+
+ final List keys = new ArrayList();
+ CompilerUtil.runInContext(myContext, "Processing obsolete targets...", new ThrowableRunnable() {
+ @Override
+ public void run() throws IOException {
+ cache.processSources(id, new CommonProcessors.CollectProcessor(keys));
+ List> obsoleteSources = new ArrayList>();
+ for (Key key : keys) {
+ final GenericCompilerCache.PersistentStateData state = cache.getState(id, key);
+ obsoleteSources.add(new GenericCompilerCacheState(key, state.mySourceState, state.myOutputState));
+ }
+ instance.processObsoleteTarget(target, obsoleteSources);
+ }
+ });
+ checkForErrorsOrCanceled();
+ for (Key key : keys) {
+ cache.remove(id, key);
+ }
+ }
+ }
+
+ final List selectedTargets = new ReadAction>() {
+ protected void run(final Result> result) {
+ result.setResult(instance.getSelectedTargets());
+ }
+ }.execute().getResultObject();
+
+ boolean didSomething = false;
+ for (T target : selectedTargets) {
+ int id = data.getId(target.getId());
+ didSomething |= processTarget(target, id, compiler, instance, cache);
+ }
+
+ data.save();
+ return didSomething;
+ }
+
+ private void checkForErrorsOrCanceled() throws CompileDriver.ExitException {
+ if (myContext.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
+ throw new CompileDriver.ExitException(CompileDriver.ExitStatus.ERRORS);
+ }
+ if (myContext.getProgressIndicator().isCanceled()) {
+ throw new CompileDriver.ExitException(CompileDriver.ExitStatus.CANCELLED);
+ }
+ }
+
+ public static File getGenericCompilerCacheDir(Project project, GenericCompiler,?,?> compiler) {
+ return new File(CompilerPaths.getCacheStoreDirectory(project), compiler.getId());
+ }
+
+ private , Key, SourceState, OutputState>
+ boolean processTarget(T target, final int targetId, final GenericCompiler compiler, final GenericCompilerInstance instance,
+ final GenericCompilerCache cache) throws IOException, CompileDriver.ExitException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Processing target '" + target + "' (id=" + targetId + ")");
+ }
+ final List- items = instance.getItems(target);
+ checkForErrorsOrCanceled();
+
+ final List> toProcess = new ArrayList>();
+ final THashSet keySet = new THashSet(new SourceItemHashingStrategy(compiler));
+ final Ref exception = Ref.create(null);
+ DumbService.getInstance(myProject).waitForSmartMode();
+ final Map
- sourceStates = new HashMap
- ();
+ ApplicationManager.getApplication().runReadAction(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ for (Item item : items) {
+ final Key key = item.getKey();
+ keySet.add(key);
+ final GenericCompilerCache.PersistentStateData data = cache.getState(targetId, key);
+ SourceState sourceState = data != null ? data.mySourceState : null;
+ final OutputState outputState = data != null ? data.myOutputState : null;
+ if (myForceCompile || sourceState == null || !item.isSourceUpToDate(sourceState)
+ || outputState == null || !item.isOutputUpToDate(outputState)) {
+ sourceStates.put(item, item.computeSourceState());
+ toProcess.add(new GenericCompilerProcessingItem
- (item, sourceState, outputState));
+ }
+ }
+ }
+ catch (IOException e) {
+ exception.set(e);
+ }
+ }
+ });
+ if (!exception.isNull()) {
+ throw exception.get();
+ }
+
+ final List toRemove = new ArrayList();
+ cache.processSources(targetId, new Processor() {
+ @Override
+ public boolean process(Key key) {
+ if (!keySet.contains(key)) {
+ toRemove.add(key);
+ }
+ return true;
+ }
+ });
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(toProcess.size() + " items will be processed, " + toRemove.size() + " items will be removed");
+ }
+
+ if (toProcess.isEmpty() && toRemove.isEmpty()) {
+ return false;
+ }
+
+ if (myOnlyCheckStatus) {
+ throw new CompileDriver.ExitException(CompileDriver.ExitStatus.CANCELLED);
+ }
+
+ List> obsoleteItems = new ArrayList>();
+ for (Key key : toRemove) {
+ final GenericCompilerCache.PersistentStateData data = cache.getState(targetId, key);
+ obsoleteItems.add(new GenericCompilerCacheState(key, data.mySourceState, data.myOutputState));
+ }
+
+ final List
- processedItems = new ArrayList
- ();
+ final List filesToRefresh = new ArrayList();
+ final List dirsToRefresh = new ArrayList();
+ instance.processItems(target, toProcess, obsoleteItems, new GenericCompilerInstance.OutputConsumer
- () {
+ @Override
+ public void addFileToRefresh(@NotNull File file) {
+ filesToRefresh.add(file);
+ }
+
+ @Override
+ public void addDirectoryToRefresh(@NotNull File dir) {
+ dirsToRefresh.add(dir);
+ }
+
+ @Override
+ public void addProcessedItem(@NotNull Item sourceItem) {
+ processedItems.add(sourceItem);
+ }
+ });
+ checkForErrorsOrCanceled();
+
+ CompilerUtil.runInContext(myContext, CompilerBundle.message("progress.updating.caches"), new ThrowableRunnable() {
+ @Override
+ public void run() throws IOException {
+ for (Key key : toRemove) {
+ cache.remove(targetId, key);
+ }
+ CompilerUtil.refreshIOFiles(filesToRefresh);
+ CompilerUtil.refreshIODirectories(dirsToRefresh);
+
+ final RunResult runResult = new ReadAction() {
+ protected void run(final Result result) throws Throwable {
+ for (Item item : processedItems) {
+ SourceState sourceState = sourceStates.get(item);
+ if (sourceState == null) {
+ sourceState = item.computeSourceState();
+ }
+ cache.putState(targetId, item.getKey(), sourceState, item.computeOutputState());
+ }
+ }
+ }.executeSilently();
+ Throwables.propagateIfPossible(runResult.getThrowable(), IOException.class);
+ }
+ });
+
+ return true;
+
+ }
+
+ private class SourceItemHashingStrategy
implements TObjectHashingStrategy {
+ private KeyDescriptor myKeyDescriptor;
+
+ public SourceItemHashingStrategy(GenericCompiler compiler) {
+ myKeyDescriptor = compiler.getItemKeyDescriptor();
+ }
+
+ @Override
+ public int computeHashCode(S object) {
+ return myKeyDescriptor.getHashCode(object);
+ }
+
+ @Override
+ public boolean equals(S o1, S o2) {
+ return myKeyDescriptor.isEqual(o1, o2);
+ }
+ }
+}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/NewCompilerRunner.java b/java/compiler/impl/src/com/intellij/compiler/impl/NewCompilerRunner.java
deleted file mode 100644
index a5dc5e2ffc24..000000000000
--- a/java/compiler/impl/src/com/intellij/compiler/impl/NewCompilerRunner.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright 2000-2010 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.compiler.impl.newApi.*;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.compiler.*;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.progress.ProcessCanceledException;
-import com.intellij.openapi.project.DumbService;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.Ref;
-import com.intellij.util.CommonProcessors;
-import com.intellij.util.Processor;
-import com.intellij.util.io.KeyDescriptor;
-import gnu.trove.THashSet;
-import gnu.trove.TObjectHashingStrategy;
-import org.jetbrains.annotations.NotNull;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.*;
-
-/**
- * @author nik
- */
-public class NewCompilerRunner {
- private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.NewCompilerRunner");
- private CompileContext myContext;
- private final boolean myForceCompile;
- private final boolean myOnlyCheckStatus;
- private final NewCompiler,?>[] myCompilers;
- private final Project myProject;
-
- public NewCompilerRunner(CompileContext context, CompilerManager compilerManager, boolean forceCompile, boolean onlyCheckStatus) {
- myContext = context;
- myForceCompile = forceCompile;
- myOnlyCheckStatus = onlyCheckStatus;
- myCompilers = compilerManager.getCompilers(NewCompiler.class);
- myProject = myContext.getProject();
- }
-
- public boolean invokeCompilers(NewCompiler.CompileOrderPlace place) throws CompileDriver.ExitException {
- boolean didSomething = false;
- try {
- for (NewCompiler, ?> compiler : myCompilers) {
- if (compiler.getOrderPlace().equals(place)) {
- didSomething = invokeCompiler(compiler);
- }
- }
- }
- catch (IOException e) {
- LOG.info(e);
- myContext.requestRebuildNextTime(e.getMessage());
- throw new CompileDriver.ExitException(CompileDriver.ExitStatus.ERRORS);
- }
- catch (CompileDriver.ExitException e) {
- throw e;
- }
- catch (ProcessCanceledException e) {
- throw e;
- }
- catch (Exception e) {
- LOG.info(e);
- myContext.addMessage(CompilerMessageCategory.ERROR, CompilerBundle.message("compiler.error.exception", e.getMessage()), null, -1, -1);
- }
- return didSomething;
- }
-
- private boolean invokeCompiler(NewCompiler compiler) throws IOException, CompileDriver.ExitException {
- return invokeCompiler(compiler, compiler.createInstance(myContext));
- }
-
- private , Key, State>
- boolean invokeCompiler(NewCompiler compiler, CompilerInstance instance) throws IOException, CompileDriver.ExitException {
- NewCompilerCache cache = CompilerCacheManager.getInstance(myProject).getNewCompilerCache(compiler);
- NewCompilerPersistentData data = new NewCompilerPersistentData(getNewCompilerCacheDir(myProject, compiler), compiler.getVersion());
- if (data.isVersionChanged()) {
- LOG.info("Clearing cache for " + compiler.getDescription());
- cache.wipe();
- }
-
- Set targetsToRemove = new HashSet(data.getAllTargets());
- for (T target : instance.getAllTargets()) {
- targetsToRemove.remove(target.getId());
- }
- if (!myOnlyCheckStatus) {
- for (String target : targetsToRemove) {
- int id = data.removeId(target);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Removing obsolete target '" + target + "' (id=" + id + ")");
- }
- List keys = new ArrayList();
- cache.processSources(id, new CommonProcessors.CollectProcessor(keys));
- List> obsoleteSources = new ArrayList>();
- for (Key key : keys) {
- final State state = cache.getState(id, key);
- obsoleteSources.add(Pair.create(key, state));
- }
- instance.processObsoleteTarget(target, obsoleteSources);
- if (myContext.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
- return true;
- }
- for (Key key : keys) {
- cache.remove(id, key);
- }
- }
- }
-
- boolean didSomething = false;
- for (T target : instance.getSelectedTargets()) {
- int id = data.getId(target.getId());
- didSomething |= processTarget(target, id, compiler, instance, cache);
- }
-
- data.save();
- return didSomething;
- }
-
- public static File getNewCompilerCacheDir(Project project, NewCompiler, ?> compiler) {
- return new File(CompilerPaths.getCacheStoreDirectory(project), compiler.getId());
- }
-
- private , Key, State>
- boolean processTarget(T target, final int targetId, final NewCompiler compiler, final CompilerInstance instance,
- final NewCompilerCache cache) throws IOException, CompileDriver.ExitException {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Processing target '" + target + "' (id=" + targetId + ")");
- }
- final List- items = instance.getItems(target);
- if (myContext.getMessageCount(CompilerMessageCategory.ERROR) > 0) return true;
-
- final List> toProcess = new ArrayList>();
- final THashSet keySet = new THashSet(new SourceItemHashingStrategy(compiler));
- final Ref exception = Ref.create(null);
- DumbService.getInstance(myProject).waitForSmartMode();
- ApplicationManager.getApplication().runReadAction(new Runnable() {
- @Override
- public void run() {
- try {
- for (Item item : items) {
- final Key key = item.getKey();
- keySet.add(key);
- State output = cache.getState(targetId, key);
- if (myForceCompile || output == null || !item.isUpToDate(output)) {
- toProcess.add(Pair.create(item, output));
- }
- }
- }
- catch (IOException e) {
- exception.set(e);
- }
- }
- });
- if (!exception.isNull()) {
- throw exception.get();
- }
-
- final List toRemove = new ArrayList();
- cache.processSources(targetId, new Processor() {
- @Override
- public boolean process(Key key) {
- if (!keySet.contains(key)) {
- toRemove.add(key);
- }
- return true;
- }
- });
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(toProcess.size() + " items will be processed, " + toRemove.size() + " items will be removed");
- }
-
- if (toProcess.isEmpty() && toRemove.isEmpty()) {
- return false;
- }
-
- if (myOnlyCheckStatus) {
- throw new CompileDriver.ExitException(CompileDriver.ExitStatus.CANCELLED);
- }
-
- List> obsoleteItems = new ArrayList>();
- for (Key key : toRemove) {
- obsoleteItems.add(Pair.create(key, cache.getState(targetId, key)));
- }
-
- final List
- processedItems = new ArrayList
- ();
- final List toRefresh = new ArrayList();
- instance.processItems(target, toProcess, obsoleteItems, new CompilerInstance.OutputConsumer
- () {
- @Override
- public void addFileToRefresh(@NotNull File file) {
- toRefresh.add(file);
- }
- @Override
- public void addProcessedItem(@NotNull Item sourceItem) {
- processedItems.add(sourceItem);
- }
- });
- if (myContext.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
- return true;
- }
-
- for (Key key : toRemove) {
- cache.remove(targetId, key);
- }
- CompilerUtil.refreshIOFiles(toRefresh);
- for (Item item : processedItems) {
- cache.putOutput(targetId, item.getKey(), item.computeState());
- }
-
- return true;
-
- }
-
- private class SourceItemHashingStrategy
implements TObjectHashingStrategy {
- private KeyDescriptor myKeyDescriptor;
-
- public SourceItemHashingStrategy(NewCompiler compiler) {
- myKeyDescriptor = compiler.getItemKeyDescriptor();
- }
-
- @Override
- public int computeHashCode(S object) {
- return myKeyDescriptor.getHashCode(object);
- }
-
- @Override
- public boolean equals(S o1, S o2) {
- return myKeyDescriptor.isEqual(o1, o2);
- }
- }
-}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerCache.java b/java/compiler/impl/src/com/intellij/compiler/impl/generic/GenericCompilerCache.java
similarity index 52%
rename from java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerCache.java
rename to java/compiler/impl/src/com/intellij/compiler/impl/generic/GenericCompilerCache.java
index 0b6ea2ecc3e0..6b3f4c3fbd53 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerCache.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/generic/GenericCompilerCache.java
@@ -13,12 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.compiler.impl.newApi;
+package com.intellij.compiler.impl.generic;
+import com.intellij.openapi.compiler.generic.GenericCompiler;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.Processor;
+import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.KeyDescriptor;
import com.intellij.util.io.PersistentHashMap;
+import org.jetbrains.annotations.NotNull;
import java.io.DataInput;
import java.io.DataOutput;
@@ -28,28 +31,25 @@ import java.io.IOException;
/**
* @author nik
*/
-public class NewCompilerCache {
- private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.newApi.NewCompilerCache");
- private PersistentHashMap, State> myPersistentMap;
+public class GenericCompilerCache {
+ private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.generic.GenericCompilerCache");
+ private PersistentHashMap, PersistentStateData> myPersistentMap;
private File myCacheFile;
- private final NewCompiler myCompiler;
+ private final GenericCompiler myCompiler;
- public NewCompilerCache(NewCompiler compiler, final File compilerCacheDir) throws IOException {
+ public GenericCompilerCache(GenericCompiler compiler, final File compilerCacheDir) throws IOException {
myCompiler = compiler;
myCacheFile = new File(compilerCacheDir, "timestamps");
createMap();
}
private void createMap() throws IOException {
- myPersistentMap = new PersistentHashMap, State>(myCacheFile, new SourceItemDataDescriptor(myCompiler.getItemKeyDescriptor()),
- myCompiler.getItemStateExternalizer());
+ myPersistentMap = new PersistentHashMap, PersistentStateData>(myCacheFile, new SourceItemDataDescriptor(myCompiler.getItemKeyDescriptor()),
+ new PersistentStateDataExternalizer(myCompiler));
}
private KeyAndTargetData getKeyAndTargetData(Key key, int target) {
- KeyAndTargetData data = new KeyAndTargetData();
- data.myTarget = target;
- data.myKey = key;
- return data;
+ return new KeyAndTargetData(target, key);
}
public void wipe() throws IOException {
@@ -75,12 +75,12 @@ public class NewCompilerCache {
myPersistentMap.remove(getKeyAndTargetData(key, targetId));
}
- public State getState(int targetId, Key key) throws IOException {
+ public PersistentStateData getState(int targetId, Key key) throws IOException {
return myPersistentMap.get(getKeyAndTargetData(key, targetId));
}
public void processSources(final int targetId, final Processor processor) throws IOException {
- myPersistentMap.processKeys(new Processor>() {
+ myPersistentMap.processKeysWithExistingMapping(new Processor>() {
@Override
public boolean process(KeyAndTargetData data) {
return targetId == data.myTarget ? processor.process(data.myKey) : true;
@@ -88,16 +88,31 @@ public class NewCompilerCache {
});
}
- public void putOutput(int targetId, Key key, State outputItem) throws IOException {
- myPersistentMap.put(getKeyAndTargetData(key, targetId), outputItem);
+ public void putState(int targetId, @NotNull Key key, @NotNull SourceState sourceState, @NotNull OutputState outputState) throws IOException {
+ myPersistentMap.put(getKeyAndTargetData(key, targetId), new PersistentStateData(sourceState, outputState));
}
private static class KeyAndTargetData {
- public int myTarget;
- public Key myKey;
+ public final int myTarget;
+ public final Key myKey;
+
+ private KeyAndTargetData(int target, Key key) {
+ myTarget = target;
+ myKey = key;
+ }
}
+ public static class PersistentStateData {
+ public final SourceState mySourceState;
+ public final OutputState myOutputState;
+
+ private PersistentStateData(@NotNull SourceState sourceState, @NotNull OutputState outputState) {
+ mySourceState = sourceState;
+ myOutputState = outputState;
+ }
+ }
+
private class SourceItemDataDescriptor implements KeyDescriptor> {
private final KeyDescriptor myKeyDescriptor;
@@ -129,4 +144,27 @@ public class NewCompilerCache {
return getKeyAndTargetData(item, target);
}
}
+
+ private class PersistentStateDataExternalizer implements DataExternalizer> {
+ private DataExternalizer mySourceStateExternalizer;
+ private DataExternalizer myOutputStateExternalizer;
+
+ public PersistentStateDataExternalizer(GenericCompiler compiler) {
+ mySourceStateExternalizer = compiler.getSourceStateExternalizer();
+ myOutputStateExternalizer = compiler.getOutputStateExternalizer();
+ }
+
+ @Override
+ public void save(DataOutput out, PersistentStateData value) throws IOException {
+ mySourceStateExternalizer.save(out, value.mySourceState);
+ myOutputStateExternalizer.save(out, value.myOutputState);
+ }
+
+ @Override
+ public PersistentStateData read(DataInput in) throws IOException {
+ SourceState sourceState = mySourceStateExternalizer.read(in);
+ OutputState outputState = myOutputStateExternalizer.read(in);
+ return new PersistentStateData(sourceState, outputState);
+ }
+ }
}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerPersistentData.java b/java/compiler/impl/src/com/intellij/compiler/impl/generic/GenericCompilerPersistentData.java
similarity index 91%
rename from java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerPersistentData.java
rename to java/compiler/impl/src/com/intellij/compiler/impl/generic/GenericCompilerPersistentData.java
index 1746c334cf77..a9b12d2b3a7b 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerPersistentData.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/generic/GenericCompilerPersistentData.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.compiler.impl.newApi;
+package com.intellij.compiler.impl.generic;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.io.IOUtil;
@@ -28,16 +28,16 @@ import java.util.Set;
/**
* @author nik
*/
-public class NewCompilerPersistentData {
- private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.newApi.NewCompilerPersistentData");
- private static final int VERSION = 0;
+public class GenericCompilerPersistentData {
+ private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.generic.GenericCompilerPersistentData");
+ private static final int VERSION = 1;
private File myFile;
private Map myTarget2Id = new HashMap();
private TIntHashSet myUsedIds = new TIntHashSet();
private boolean myVersionChanged;
private final int myCompilerVersion;
- public NewCompilerPersistentData(File cacheStoreDirectory, int compilerVersion) throws IOException {
+ public GenericCompilerPersistentData(File cacheStoreDirectory, int compilerVersion) throws IOException {
myCompilerVersion = compilerVersion;
myFile = new File(cacheStoreDirectory, "info");
if (!myFile.exists()) {
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java
index 3e41738c0d3e..ce39f72ccdea 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java
@@ -176,7 +176,7 @@ public class BackendCompilerWrapper {
}
}
finally {
- if (fileToDelete != null) {
+ if (fileToDelete != null && myCompileContext.getMessageCount(CompilerMessageCategory.ERROR) == 0) {
FileUtil.asyncDelete(fileToDelete);
}
}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/BuildTarget.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/BuildTarget.java
similarity index 95%
rename from java/compiler/impl/src/com/intellij/compiler/impl/newApi/BuildTarget.java
rename to java/compiler/impl/src/com/intellij/openapi/compiler/generic/BuildTarget.java
index a53ffc1ff9c0..27f16ad9f523 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/BuildTarget.java
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/BuildTarget.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.compiler.impl.newApi;
+package com.intellij.openapi.compiler.generic;
import org.jetbrains.annotations.NotNull;
diff --git a/java/compiler/impl/src/com/intellij/openapi/compiler/generic/CompileItem.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/CompileItem.java
new file mode 100644
index 000000000000..3e5f19883a5e
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/CompileItem.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2000-2010 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.openapi.compiler.generic;
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author nik
+ */
+public abstract class CompileItem {
+ @NotNull
+ public abstract Key getKey();
+
+ public abstract boolean isSourceUpToDate(@NotNull SourceState state);
+
+ @NotNull
+ public abstract SourceState computeSourceState();
+
+
+ public abstract boolean isOutputUpToDate(@NotNull OutputState state);
+
+ @NotNull
+ public abstract OutputState computeOutputState();
+}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/VirtualFileStateExternalizer.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/DummyPersistentState.java
similarity index 52%
rename from java/compiler/impl/src/com/intellij/compiler/impl/newApi/VirtualFileStateExternalizer.java
rename to java/compiler/impl/src/com/intellij/openapi/compiler/generic/DummyPersistentState.java
index 6ca460108979..b3d66ce575fb 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/VirtualFileStateExternalizer.java
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/DummyPersistentState.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.compiler.impl.newApi;
+package com.intellij.openapi.compiler.generic;
import com.intellij.util.io.DataExternalizer;
@@ -22,23 +22,23 @@ import java.io.DataOutput;
import java.io.IOException;
/**
-* @author nik
-*/
-public abstract class VirtualFileStateExternalizer implements DataExternalizer {
- protected abstract void doSave(DataOutput out, State value) throws IOException;
+ * @author nik
+ */
+public class DummyPersistentState {
+ public static final DummyPersistentState INSTANCE = new DummyPersistentState();
+ public static final DataExternalizer EXTERNALIZER = new DummyPersistentStateExternalizer();
- protected abstract State doRead(DataInput in, long sourceTimestamp) throws IOException;
-
- @Override
- public final void save(DataOutput out, State value) throws IOException {
- out.writeLong(value.getSourceTimestamp());
- doSave(out, value);
+ private DummyPersistentState() {
}
- @Override
- public final State read(DataInput in) throws IOException {
- final long sourceTimestamp = in.readLong();
- return doRead(in, sourceTimestamp);
- }
+ private static class DummyPersistentStateExternalizer implements DataExternalizer {
+ @Override
+ public void save(DataOutput out, DummyPersistentState value) throws IOException {
+ }
+ @Override
+ public DummyPersistentState read(DataInput in) throws IOException {
+ return INSTANCE;
+ }
+ }
}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompiler.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompiler.java
similarity index 61%
rename from java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompiler.java
rename to java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompiler.java
index b82b8bf9d84c..b09c8e599626 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompiler.java
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompiler.java
@@ -13,23 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.compiler.impl.newApi;
+package com.intellij.openapi.compiler.generic;
import com.intellij.openapi.compiler.CompileContext;
+import com.intellij.openapi.compiler.CompileScope;
import com.intellij.openapi.compiler.Compiler;
import com.intellij.util.io.DataExternalizer;
+import com.intellij.util.io.EnumeratorStringDescriptor;
import com.intellij.util.io.KeyDescriptor;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
-public abstract class NewCompiler implements Compiler {
+public abstract class GenericCompiler implements Compiler {
+ protected static final KeyDescriptor STRING_KEY_DESCRIPTOR = new EnumeratorStringDescriptor();
private final String myId;
private final int myVersion;
private final CompileOrderPlace myOrderPlace;
- protected NewCompiler(@NotNull String id, int version, @NotNull CompileOrderPlace orderPlace) {
+ protected GenericCompiler(@NotNull String id, int version, @NotNull CompileOrderPlace orderPlace) {
myId = id;
myVersion = version;
myOrderPlace = orderPlace;
@@ -38,10 +41,12 @@ public abstract class NewCompiler implements Compiler {
@NotNull
public abstract KeyDescriptor getItemKeyDescriptor();
@NotNull
- public abstract DataExternalizer getItemStateExternalizer();
+ public abstract DataExternalizer getSourceStateExternalizer();
+ @NotNull
+ public abstract DataExternalizer getOutputStateExternalizer();
@NotNull
- public abstract CompilerInstance, ? extends CompileItem, Key, State> createInstance(@NotNull CompileContext context);
+ public abstract GenericCompilerInstance, ? extends CompileItem, Key, SourceState, OutputState> createInstance(@NotNull CompileContext context);
public final String getId() {
return myId;
@@ -51,6 +56,11 @@ public abstract class NewCompiler implements Compiler {
return myVersion;
}
+ @Override
+ public boolean validateConfiguration(CompileScope scope) {
+ return true;
+ }
+
public CompileOrderPlace getOrderPlace() {
return myOrderPlace;
}
diff --git a/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerCacheState.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerCacheState.java
new file mode 100644
index 000000000000..bfc44686893b
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerCacheState.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2000-2010 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.openapi.compiler.generic;
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author nik
+ */
+public class GenericCompilerCacheState {
+ private final Key myKey;
+ private final SourceState mySourceState;
+ private final OutputState myOutputState;
+
+ public GenericCompilerCacheState(@NotNull Key key, @NotNull SourceState sourceState, @NotNull OutputState outputState) {
+ myKey = key;
+ mySourceState = sourceState;
+ myOutputState = outputState;
+ }
+
+ @NotNull
+ public Key getKey() {
+ return myKey;
+ }
+
+ @NotNull
+ public SourceState getSourceState() {
+ return mySourceState;
+ }
+
+ @NotNull
+ public OutputState getOutputState() {
+ return myOutputState;
+ }
+}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompilerInstance.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerInstance.java
similarity index 69%
rename from java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompilerInstance.java
rename to java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerInstance.java
index 2e9f9cf59593..6bb9274946a2 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompilerInstance.java
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerInstance.java
@@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.compiler.impl.newApi;
+package com.intellij.openapi.compiler.generic;
import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@@ -26,10 +25,10 @@ import java.util.List;
/**
* @author nik
*/
-public abstract class CompilerInstance, Key, State> {
+public abstract class GenericCompilerInstance, Key, SourceState, OutputState> {
protected final CompileContext myContext;
- protected CompilerInstance(CompileContext context) {
+ protected GenericCompilerInstance(CompileContext context) {
myContext = context;
}
@@ -43,18 +42,20 @@ public abstract class CompilerInstance getSelectedTargets();
- public abstract void processObsoleteTarget(@NotNull String targetId, @NotNull List> obsoleteItems);
+ public abstract void processObsoleteTarget(@NotNull String targetId, @NotNull List> obsoleteItems);
@NotNull
public abstract List- getItems(@NotNull T target);
- public abstract void processItems(@NotNull T target, @NotNull List> changedItems, @NotNull List> obsoleteItems,
+ public abstract void processItems(@NotNull T target, @NotNull List> changedItems, @NotNull List> obsoleteItems,
@NotNull OutputConsumer
- consumer);
- public interface OutputConsumer
- > {
+ public interface OutputConsumer
- > {
void addFileToRefresh(@NotNull File file);
+ void addDirectoryToRefresh(@NotNull File dir);
+
void addProcessedItem(@NotNull Item sourceItem);
}
}
diff --git a/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerProcessingItem.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerProcessingItem.java
new file mode 100644
index 000000000000..e62a5b3d58cf
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/GenericCompilerProcessingItem.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2000-2010 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.openapi.compiler.generic;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author nik
+ */
+public class GenericCompilerProcessingItem
- , SourceState, OutputState> {
+ private final Item myItem;
+ private final SourceState myCachedSourceState;
+ private final OutputState myCachedOutputState;
+
+ public GenericCompilerProcessingItem(@NotNull Item item, @Nullable SourceState cachedSourceState, @Nullable OutputState cachedOutputState) {
+ myItem = item;
+ myCachedSourceState = cachedSourceState;
+ myCachedOutputState = cachedOutputState;
+ }
+
+ @NotNull
+ public Item getItem() {
+ return myItem;
+ }
+
+ @Nullable
+ public SourceState getCachedSourceState() {
+ return myCachedSourceState;
+ }
+
+ @Nullable
+ public OutputState getCachedOutputState() {
+ return myCachedOutputState;
+ }
+}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/SingleTargetCompilerInstance.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/SingleTargetCompilerInstance.java
similarity index 80%
rename from java/compiler/impl/src/com/intellij/compiler/impl/newApi/SingleTargetCompilerInstance.java
rename to java/compiler/impl/src/com/intellij/openapi/compiler/generic/SingleTargetCompilerInstance.java
index 359366e70bb4..f2e4dd3ca71e 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/SingleTargetCompilerInstance.java
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/SingleTargetCompilerInstance.java
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.compiler.impl.newApi;
+package com.intellij.openapi.compiler.generic;
import com.intellij.openapi.compiler.CompileContext;
-import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
@@ -25,7 +24,8 @@ import java.util.List;
/**
* @author nik
*/
-public abstract class SingleTargetCompilerInstance
- , S, O> extends CompilerInstance {
+public abstract class SingleTargetCompilerInstance
- , K,S, O> extends
+ GenericCompilerInstance {
protected SingleTargetCompilerInstance(CompileContext context) {
super(context);
}
@@ -43,6 +43,6 @@ public abstract class SingleTargetCompilerInstance
-
}
@Override
- public void processObsoleteTarget(@NotNull String targetId, @NotNull List> obsoleteItems) {
+ public void processObsoleteTarget(@NotNull String targetId, @NotNull List> obsoleteItems) {
}
}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/VirtualFileCompileItem.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileCompileItem.java
similarity index 68%
rename from java/compiler/impl/src/com/intellij/compiler/impl/newApi/VirtualFileCompileItem.java
rename to java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileCompileItem.java
index a2c0b7055c9f..03a14bd0d63c 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/VirtualFileCompileItem.java
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileCompileItem.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.compiler.impl.newApi;
+package com.intellij.openapi.compiler.generic;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.io.EnumeratorStringDescriptor;
@@ -23,8 +23,7 @@ import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
-public abstract class VirtualFileCompileItem extends CompileItem {
- public static final KeyDescriptor KEY_DESCRIPTOR = new EnumeratorStringDescriptor();
+public abstract class VirtualFileCompileItem extends CompileItem {
protected final VirtualFile myFile;
public VirtualFileCompileItem(@NotNull VirtualFile file) {
@@ -36,15 +35,16 @@ public abstract class VirtualFileCompileItem EXTERNALIZER = new VirtualFileStateExternalizer();
+ private final long mySourceTimestamp;
+
+ public VirtualFilePersistentState(long sourceTimestamp) {
+ mySourceTimestamp = sourceTimestamp;
+ }
+
+ public final long getSourceTimestamp() {
+ return mySourceTimestamp;
+ }
+
+ private static class VirtualFileStateExternalizer implements DataExternalizer {
+ @Override
+ public void save(DataOutput out, VirtualFilePersistentState value) throws IOException {
+ out.writeLong(value.getSourceTimestamp());
+ }
+
+ @Override
+ public VirtualFilePersistentState read(DataInput in) throws IOException {
+ return new VirtualFilePersistentState(in.readLong());
+ }
+
+ }
+}
diff --git a/java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileSetState.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileSetState.java
new file mode 100644
index 000000000000..a22e80dd77de
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileSetState.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2000-2010 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.openapi.compiler.generic;
+
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.io.DataExternalizer;
+import com.intellij.util.io.IOUtil;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author nik
+ */
+public class VirtualFileSetState {
+ public static final DataExternalizer EXTERNALIZER = new VirtualFileWithDependenciesExternalizer();
+ private Map myTimestamps = new HashMap();
+
+ public VirtualFileSetState() {
+ }
+
+ public VirtualFileSetState(Collection extends VirtualFile> files) {
+ for (VirtualFile file : files) {
+ addFile(file);
+ }
+ }
+
+ public void addFile(@NotNull VirtualFile file) {
+ myTimestamps.put(file.getUrl(), file.getTimeStamp());
+ }
+
+ public boolean isUpToDate(Set extends VirtualFile> files) {
+ if (files.size() != myTimestamps.size()) {
+ return false;
+ }
+
+ for (VirtualFile file : files) {
+ final Long timestamp = myTimestamps.get(file.getUrl());
+ if (timestamp == null || timestamp != file.getTimeStamp()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ private static class VirtualFileWithDependenciesExternalizer implements DataExternalizer {
+ private byte[] myBuffer = IOUtil.allocReadWriteUTFBuffer();
+
+ @Override
+ public void save(DataOutput out, VirtualFileSetState value) throws IOException {
+ final Map dependencies = value.myTimestamps;
+ out.writeInt(dependencies.size());
+ for (Map.Entry entry : dependencies.entrySet()) {
+ IOUtil.writeUTFFast(myBuffer, out, entry.getKey());
+ out.writeLong(entry.getValue());
+ }
+ }
+
+ @Override
+ public VirtualFileSetState read(DataInput in) throws IOException {
+ final VirtualFileSetState state = new VirtualFileSetState();
+ int size = in.readInt();
+ while (size-- > 0) {
+ final String url = IOUtil.readUTFFast(myBuffer, in);
+ final long timestamp = in.readLong();
+ state.myTimestamps.put(url, timestamp);
+ }
+ return state;
+ }
+ }
+}
diff --git a/java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileWithDependenciesState.java b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileWithDependenciesState.java
new file mode 100644
index 000000000000..9f4a815304de
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/generic/VirtualFileWithDependenciesState.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2000-2010 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.openapi.compiler.generic;
+
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.vfs.VirtualFileManager;
+import com.intellij.util.io.DataExternalizer;
+import com.intellij.util.io.IOUtil;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author nik
+ */
+public class VirtualFileWithDependenciesState {
+ public static final DataExternalizer EXTERNALIZER = new VirtualFileWithDependenciesExternalizer();
+ private long mySourceTimestamp;
+ private Map myDependencies = new HashMap();
+
+ public VirtualFileWithDependenciesState(long sourceTimestamp) {
+ mySourceTimestamp = sourceTimestamp;
+ }
+
+ public void addDependency(@NotNull VirtualFile file) {
+ myDependencies.put(file.getUrl(), file.getTimeStamp());
+ }
+
+ public boolean isUpToDate(@NotNull VirtualFile sourceFile) {
+ if (sourceFile.getTimeStamp() != mySourceTimestamp) {
+ return false;
+ }
+
+ VirtualFileManager manager = VirtualFileManager.getInstance();
+ for (Map.Entry entry : myDependencies.entrySet()) {
+ final VirtualFile file = manager.findFileByUrl(entry.getKey());
+ if (file == null || file.getTimeStamp() != entry.getValue()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ private static class VirtualFileWithDependenciesExternalizer implements DataExternalizer {
+ private byte[] myBuffer = IOUtil.allocReadWriteUTFBuffer();
+
+ @Override
+ public void save(DataOutput out, VirtualFileWithDependenciesState value) throws IOException {
+ out.writeLong(value.mySourceTimestamp);
+ final Map dependencies = value.myDependencies;
+ out.writeInt(dependencies.size());
+ for (Map.Entry entry : dependencies.entrySet()) {
+ IOUtil.writeUTFFast(myBuffer, out, entry.getKey());
+ out.writeLong(entry.getValue());
+ }
+ }
+
+ @Override
+ public VirtualFileWithDependenciesState read(DataInput in) throws IOException {
+ final VirtualFileWithDependenciesState state = new VirtualFileWithDependenciesState(in.readLong());
+ int size = in.readInt();
+ while (size-- > 0) {
+ final String url = IOUtil.readUTFFast(myBuffer, in);
+ final long timestamp = in.readLong();
+ state.myDependencies.put(url, timestamp);
+ }
+ return state;
+ }
+ }
+}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactBySourceFileFinderImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactBySourceFileFinderImpl.java
index aad584cacd02..cbff9ef68971 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactBySourceFileFinderImpl.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactBySourceFileFinderImpl.java
@@ -17,9 +17,7 @@ package com.intellij.packaging.impl.artifacts;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModuleRootModel;
-import com.intellij.openapi.roots.SourceFolder;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.openapi.util.MultiValuesMap;
import com.intellij.openapi.vfs.VirtualFile;
@@ -90,13 +88,8 @@ public class ArtifactBySourceFileFinderImpl extends ArtifactBySourceFileFinder {
final Module module = ((ModuleOutputPackagingElement)element).findModule(context);
if (module != null) {
final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module);
- for (ContentEntry contentEntry : rootModel.getContentEntries()) {
- for (SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
- final VirtualFile sourceRoot = sourceFolder.getFile();
- if (sourceRoot != null && !sourceFolder.isTestSource()) {
- result.put(sourceRoot, artifact);
- }
- }
+ for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) {
+ result.put(sourceRoot, artifact);
}
}
}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java
index da39774c3698..f9a512ffbb73 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java
@@ -19,9 +19,7 @@ import com.intellij.compiler.CompilerConfiguration;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.CompilerProjectExtension;
-import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModuleRootModel;
-import com.intellij.openapi.roots.SourceFolder;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Trinity;
@@ -365,12 +363,9 @@ public class ArtifactUtil {
final Module module = moduleElement.findModule(context);
if (module != null) {
final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module);
- for (ContentEntry entry : rootModel.getContentEntries()) {
- for (SourceFolder folder : entry.getSourceFolders()) {
- final VirtualFile sourceRoot = folder.getFile();
- if (!folder.isTestSource() && sourceRoot != null && VfsUtil.isAncestor(sourceRoot, file, true)) {
- return VfsUtil.getRelativePath(file, sourceRoot, '/');
- }
+ for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) {
+ if (VfsUtil.isAncestor(sourceRoot, file, true)) {
+ return VfsUtil.getRelativePath(file, sourceRoot, '/');
}
}
}
@@ -428,16 +423,11 @@ public class ArtifactUtil {
final Module module = ((ModuleOutputPackagingElement)element).findModule(context);
if (module != null) {
final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject());
- final ContentEntry[] contentEntries = context.getModulesProvider().getRootModel(module).getContentEntries();
- for (ContentEntry contentEntry : contentEntries) {
- for (SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
- final VirtualFile sourceRoot = sourceFolder.getFile();
- if (!sourceFolder.isTestSource() && sourceRoot != null) {
- final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path);
- if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) {
- result.add(sourceFile);
- }
- }
+ final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module);
+ for (VirtualFile sourceRoot : rootModel.getSourceRoots(false)) {
+ final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path);
+ if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) {
+ result.add(sourceFile);
}
}
}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.form b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.form
new file mode 100644
index 000000000000..16d474ec1c9f
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.form
@@ -0,0 +1,101 @@
+
+
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java
new file mode 100644
index 000000000000..5be9eb25f1a3
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2000-2010 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.packaging.impl.artifacts;
+
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.ui.TextFieldWithBrowseButton;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.packaging.elements.PackagingElementResolvingContext;
+import com.intellij.packaging.impl.elements.ManifestFileUtil;
+import com.intellij.ui.DocumentAdapter;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import javax.swing.event.DocumentEvent;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * @author nik
+ */
+public class JarArtifactFromModulesDialog extends DialogWrapper {
+ private JPanel myMainPanel;
+ private TextFieldWithBrowseButton myMainClassField;
+ private JComboBox myModuleComboBox;
+ private JLabel myMainClassLabel;
+ private TextFieldWithBrowseButton myManifestDirField;
+ private JLabel myManifestDirLabel;
+ private JRadioButton myExtractJarsRadioButton;
+ private JRadioButton myCopyJarsRadioButton;
+ private PackagingElementResolvingContext myContext;
+
+ public JarArtifactFromModulesDialog(PackagingElementResolvingContext context) {
+ super(context.getProject());
+ myContext = context;
+ setTitle("Create Jar from Modules");
+ myMainClassLabel.setLabelFor(myMainClassField.getTextField());
+ myManifestDirLabel.setLabelFor(myManifestDirField.getTextField());
+
+ final Project project = myContext.getProject();
+ ManifestFileUtil.setupMainClassField(project, myMainClassField);
+ myMainClassField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
+ @Override
+ protected void textChanged(DocumentEvent e) {
+ updateManifestDirField();
+ }
+ });
+ final ActionListener actionListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ updateManifestDirField();
+ }
+ };
+ myExtractJarsRadioButton.addActionListener(actionListener);
+ myCopyJarsRadioButton.addActionListener(actionListener);
+
+ updateManifestDirField();
+ myManifestDirField.addBrowseFolderListener(null, null, project, ManifestFileUtil.createDescriptorForManifestDirectory());
+
+ final Module[] modules = context.getModulesProvider().getModules();
+ if (modules.length > 1) {
+ myModuleComboBox.addItem(null);
+ }
+ for (Module module : modules) {
+ myModuleComboBox.addItem(module);
+ }
+ myModuleComboBox.setRenderer(new ModuleListRenderer());
+ init();
+ }
+
+ private void updateManifestDirField() {
+ final boolean enable = !myMainClassField.getText().isEmpty() || !myExtractJarsRadioButton.isSelected();
+ setManifestDirFieldEnabled(enable);
+ if (enable && myManifestDirField.getText().isEmpty()) {
+ final VirtualFile file = ManifestFileUtil.suggestManifestFileDirectory(myContext.getProject(), getSelectedModule());
+ if (file != null) {
+ myManifestDirField.setText(FileUtil.toSystemDependentName(file.getPath()));
+ }
+ }
+ }
+
+ @Nullable
+ private Module getSelectedModule() {
+ return (Module)myModuleComboBox.getSelectedItem();
+ }
+
+ @NotNull
+ public Module[] getSelectedModules() {
+ final Module module = getSelectedModule();
+ if (module != null) {
+ return new Module[]{module};
+ }
+ return myContext.getModulesProvider().getModules();
+ }
+
+ @NotNull
+ public String getDirectoryForManifest() {
+ return FileUtil.toSystemIndependentName(myManifestDirField.getText());
+ }
+
+ public boolean isExtractLibrariesToJar() {
+ return myExtractJarsRadioButton.isSelected();
+ }
+
+ public String getMainClassName() {
+ return myMainClassField.getText();
+ }
+
+ private void setManifestDirFieldEnabled(boolean enabled) {
+ myManifestDirLabel.setEnabled(enabled);
+ myManifestDirField.setEnabled(enabled);
+ }
+
+ @Override
+ protected JComponent createCenterPanel() {
+ return myMainPanel;
+ }
+
+ private static class ModuleListRenderer extends DefaultListCellRenderer {
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ if (value instanceof Module) {
+ final Module module = (Module)value;
+ setIcon(module.getModuleType().getNodeIcon(false));
+ setText(module.getName());
+ }
+ else {
+ setText("");
+ setIcon(null);
+ }
+ return component;
+ }
+ }
+}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactType.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactType.java
index 01bcd7153c86..47d0033a6e09 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactType.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactType.java
@@ -16,13 +16,17 @@
package com.intellij.packaging.impl.artifacts;
import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.packaging.artifacts.ArtifactTemplate;
import com.intellij.packaging.artifacts.ArtifactType;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.elements.PackagingElementOutputKind;
+import com.intellij.packaging.elements.PackagingElementResolvingContext;
import com.intellij.packaging.impl.elements.ArchivePackagingElement;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
+import java.util.Collections;
+import java.util.List;
/**
* @author nik
@@ -32,6 +36,10 @@ public class JarArtifactType extends ArtifactType {
super("jar", "Jar");
}
+ public static JarArtifactType getInstance() {
+ return EP_NAME.findExtension(JarArtifactType.class);
+ }
+
@NotNull
@Override
public Icon getIcon() {
@@ -48,4 +56,10 @@ public class JarArtifactType extends ArtifactType {
public CompositePackagingElement> createRootElement(@NotNull String artifactName) {
return new ArchivePackagingElement(FileUtil.sanitizeFileName(artifactName) + ".jar");
}
+
+ @NotNull
+ @Override
+ public List extends ArtifactTemplate> getNewArtifactTemplates(@NotNull PackagingElementResolvingContext context) {
+ return Collections.singletonList(new JarFromModulesTemplate(context));
+ }
}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarFromModulesTemplate.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarFromModulesTemplate.java
new file mode 100644
index 000000000000..30d6468c4ffa
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarFromModulesTemplate.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2000-2010 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.packaging.impl.artifacts;
+
+import com.intellij.CommonBundle;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.*;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.vfs.VfsUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.packaging.artifacts.ArtifactTemplate;
+import com.intellij.packaging.elements.*;
+import com.intellij.packaging.impl.elements.LibraryPackagingElement;
+import com.intellij.packaging.impl.elements.ManifestFileUtil;
+import com.intellij.util.PathUtil;
+import com.intellij.util.Processor;
+import com.intellij.util.containers.ContainerUtil;
+import gnu.trove.THashSet;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @author nik
+ */
+public class JarFromModulesTemplate extends ArtifactTemplate {
+ private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.artifacts.JarFromModulesTemplate");
+
+ private PackagingElementResolvingContext myContext;
+
+ public JarFromModulesTemplate(PackagingElementResolvingContext context) {
+ myContext = context;
+ }
+
+ @Override
+ public NewArtifactConfiguration createArtifact() {
+ JarArtifactFromModulesDialog dialog = new JarArtifactFromModulesDialog(myContext);
+ dialog.show();
+ if (!dialog.isOK()) {
+ return null;
+ }
+
+ return doCreateArtifact(dialog.getSelectedModules(), dialog.getMainClassName(), dialog.getDirectoryForManifest(),
+ dialog.isExtractLibrariesToJar());
+ }
+
+ @Nullable
+ public NewArtifactConfiguration doCreateArtifact(final Module[] modules, final String mainClassName,
+ final String directoryForManifest, final boolean extractLibrariesToJar) {
+ VirtualFile manifestFile = null;
+ final Project project = myContext.getProject();
+ if (mainClassName != null && !mainClassName.isEmpty() || !extractLibrariesToJar) {
+ final VirtualFile directory;
+ try {
+ directory = VfsUtil.createDirectoryIfMissing(directoryForManifest);
+ }
+ catch (IOException e) {
+ LOG.info(e);
+ Messages.showErrorDialog(project, "Cannot create directory '" + directoryForManifest + "': " + e.getMessage(),
+ CommonBundle.getErrorTitle());
+ return null;
+ }
+ if (directory == null) return null;
+
+ manifestFile = ManifestFileUtil.createManifestFile(directory, project);
+ if (manifestFile == null) {
+ return null;
+ }
+ ManifestFileUtil.updateManifest(manifestFile, mainClassName, null, true);
+ }
+
+ String name = modules.length == 1 ? modules[0].getName() : project.getName();
+
+ final PackagingElementFactory factory = PackagingElementFactory.getInstance();
+ final CompositePackagingElement> archive = factory.createArchive(FileUtil.sanitizeFileName(name) + ".jar");
+
+ final OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(project).orderEntries(Arrays.asList(modules));
+
+ final Set libraries = new THashSet();
+ orderEnumerator.using(myContext.getModulesProvider()).withoutSdk().productionOnly().runtimeOnly().recursively().forEach(new Processor() {
+ @Override
+ public boolean process(OrderEntry orderEntry) {
+ if (orderEntry instanceof ModuleSourceOrderEntry) {
+ archive.addOrFindChild(factory.createModuleOutput(orderEntry.getOwnerModule()));
+ }
+ else if (orderEntry instanceof LibraryOrderEntry) {
+ ContainerUtil.addIfNotNull(((LibraryOrderEntry)orderEntry).getLibrary(), libraries);
+ }
+ return true;
+ }
+ });
+
+ final JarArtifactType jarArtifactType = JarArtifactType.getInstance();
+ if (manifestFile != null && !manifestFile.equals(ManifestFileUtil.findManifestFile(archive, myContext, jarArtifactType))) {
+ archive.addFirstChild(factory.createFileCopyWithParentDirectories(manifestFile.getPath(), ManifestFileUtil.MANIFEST_DIR_NAME));
+ }
+
+ final String artifactName = name + ":jar";
+ if (extractLibrariesToJar) {
+ addExtractedLibrariesToJar(archive, factory, libraries);
+ return new NewArtifactConfiguration(archive, artifactName, jarArtifactType);
+ }
+ else {
+ final ArtifactRootElement> root = factory.createArtifactRootElement();
+ List classpath = new ArrayList();
+ root.addOrFindChild(archive);
+ addLibraries(libraries, root, archive, classpath);
+ ManifestFileUtil.updateManifest(manifestFile, mainClassName, classpath, true);
+ return new NewArtifactConfiguration(root, artifactName, PlainArtifactType.getInstance());
+ }
+ }
+
+ private void addLibraries(Set libraries, ArtifactRootElement> root, CompositePackagingElement> archive,
+ List classpath) {
+ PackagingElementFactory factory = PackagingElementFactory.getInstance();
+ for (Library library : libraries) {
+ if (LibraryPackagingElement.getKindForLibrary(library).containsDirectoriesWithClasses()) {
+ for (VirtualFile classesRoot : library.getFiles(OrderRootType.CLASSES)) {
+ if (classesRoot.isInLocalFileSystem()) {
+ archive.addOrFindChild(factory.createDirectoryCopyWithParentDirectories(classesRoot.getPath(), "/"));
+ }
+ else {
+ final PackagingElement> child = factory.createFileCopyWithParentDirectories(PathUtil.getLocalFile(classesRoot).getPath(), "/");
+ root.addOrFindChild(child);
+ classpath.addAll(ManifestFileUtil.getClasspathForElements(Collections.singletonList(child), myContext, PlainArtifactType.getInstance()));
+ }
+ }
+
+ }
+ else {
+ final List extends PackagingElement>> children = factory.createLibraryElements(library);
+ classpath.addAll(ManifestFileUtil.getClasspathForElements(children, myContext, PlainArtifactType.getInstance()));
+ root.addOrFindChildren(children);
+ }
+ }
+ }
+
+ private static void addExtractedLibrariesToJar(CompositePackagingElement> archive, PackagingElementFactory factory, Set libraries) {
+ for (Library library : libraries) {
+ if (LibraryPackagingElement.getKindForLibrary(library).containsJarFiles()) {
+ for (VirtualFile classesRoot : library.getFiles(OrderRootType.CLASSES)) {
+ if (classesRoot.isInLocalFileSystem()) {
+ archive.addOrFindChild(factory.createDirectoryCopyWithParentDirectories(classesRoot.getPath(), "/"));
+ }
+ else {
+ archive.addOrFindChild(factory.createExtractedDirectory(classesRoot));
+ }
+ }
+
+ }
+ else {
+ archive.addOrFindChildren(factory.createLibraryElements(library));
+ }
+ }
+ }
+
+ @Override
+ public String getPresentableName() {
+ return "From modules with dependencies...";
+ }
+}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PlainArtifactType.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PlainArtifactType.java
index 4cd6ab503037..b720824c04f3 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PlainArtifactType.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PlainArtifactType.java
@@ -21,7 +21,6 @@ import com.intellij.packaging.artifacts.ArtifactType;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.elements.PackagingElementOutputKind;
import com.intellij.packaging.impl.elements.ArtifactRootElementImpl;
-import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -35,7 +34,7 @@ public class PlainArtifactType extends ArtifactType {
@NonNls public static final String ID = "plain";
public static PlainArtifactType getInstance() {
- return ContainerUtil.findInstance(getAllTypes(), PlainArtifactType.class);
+ return EP_NAME.findExtension(PlainArtifactType.class);
}
public PlainArtifactType() {
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactBuildTarget.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactBuildTarget.java
index 41aeba8c8516..4a29afc1dad4 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactBuildTarget.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactBuildTarget.java
@@ -15,7 +15,7 @@
*/
package com.intellij.packaging.impl.compiler;
-import com.intellij.compiler.impl.newApi.BuildTarget;
+import com.intellij.openapi.compiler.generic.BuildTarget;
import com.intellij.packaging.artifacts.Artifact;
import org.jetbrains.annotations.NotNull;
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompilerCompileItem.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompilerCompileItem.java
index 517bef7e89d3..b4e1865f46ff 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompilerCompileItem.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompilerCompileItem.java
@@ -15,7 +15,7 @@
*/
package com.intellij.packaging.impl.compiler;
-import com.intellij.compiler.impl.newApi.VirtualFileCompileItem;
+import com.intellij.openapi.compiler.generic.VirtualFileCompileItem;
import com.intellij.compiler.impl.packagingCompiler.DestinationInfo;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
@@ -46,7 +46,7 @@ public class ArtifactCompilerCompileItem extends VirtualFileCompileItem> pairs = new SmartList>();
for (DestinationInfo destination : myDestinations) {
destination.update();
@@ -54,11 +54,11 @@ public class ArtifactCompilerCompileItem extends VirtualFileCompileItem> cachedDestinations = state.myDestinations;
if (cachedDestinations.size() != myDestinations.size()) {
return false;
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactPackagingItemExternalizer.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactPackagingItemExternalizer.java
index f1adc4c406e1..030e9484ba26 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactPackagingItemExternalizer.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactPackagingItemExternalizer.java
@@ -15,9 +15,9 @@
*/
package com.intellij.packaging.impl.compiler;
-import com.intellij.compiler.impl.newApi.VirtualFileStateExternalizer;
import com.intellij.openapi.util.Pair;
import com.intellij.util.SmartList;
+import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.IOUtil;
import java.io.DataInput;
@@ -27,12 +27,11 @@ import java.io.IOException;
/**
* @author nik
*/
-public class ArtifactPackagingItemExternalizer
- extends VirtualFileStateExternalizer {
+public class ArtifactPackagingItemExternalizer implements DataExternalizer {
private byte[] myBuffer = IOUtil.allocReadWriteUTFBuffer();
@Override
- protected void doSave(DataOutput out, ArtifactPackagingItemOutputState value) throws IOException {
+ public void save(DataOutput out, ArtifactPackagingItemOutputState value) throws IOException {
out.writeInt(value.myDestinations.size());
for (Pair pair : value.myDestinations) {
IOUtil.writeUTFFast(myBuffer, out, pair.getFirst());
@@ -41,7 +40,7 @@ public class ArtifactPackagingItemExternalizer
}
@Override
- protected ArtifactPackagingItemOutputState doRead(DataInput in, long sourceTimestamp) throws IOException {
+ public ArtifactPackagingItemOutputState read(DataInput in) throws IOException {
int size = in.readInt();
SmartList> destinations = new SmartList>();
while (size-- > 0) {
@@ -49,6 +48,6 @@ public class ArtifactPackagingItemExternalizer
long outputTimestamp = in.readLong();
destinations.add(Pair.create(path, outputTimestamp));
}
- return new ArtifactPackagingItemOutputState(sourceTimestamp, destinations);
+ return new ArtifactPackagingItemOutputState(destinations);
}
}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactPackagingItemOutputState.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactPackagingItemOutputState.java
index e93390d6bc72..29ac0ae91918 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactPackagingItemOutputState.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactPackagingItemOutputState.java
@@ -15,18 +15,16 @@
*/
package com.intellij.packaging.impl.compiler;
-import com.intellij.compiler.impl.newApi.VirtualFilePersistentState;
import com.intellij.openapi.util.Pair;
import com.intellij.util.SmartList;
/**
* @author nik
*/
-public class ArtifactPackagingItemOutputState extends VirtualFilePersistentState {
+public class ArtifactPackagingItemOutputState {
public final SmartList> myDestinations;
- public ArtifactPackagingItemOutputState(long timestamp, SmartList> destinations) {
- super(timestamp);
+ public ArtifactPackagingItemOutputState(SmartList> destinations) {
myDestinations = destinations;
}
}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsCompiler.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsCompiler.java
index b410fe456a78..d587da92afe0 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsCompiler.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsCompiler.java
@@ -15,12 +15,8 @@
*/
package com.intellij.packaging.impl.compiler;
-import com.intellij.compiler.impl.newApi.CompileItem;
-import com.intellij.compiler.impl.newApi.CompilerInstance;
-import com.intellij.compiler.impl.newApi.NewCompiler;
-import com.intellij.compiler.impl.newApi.VirtualFileCompileItem;
+import com.intellij.openapi.compiler.generic.*;
import com.intellij.openapi.compiler.CompileContext;
-import com.intellij.openapi.compiler.CompileScope;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
@@ -35,12 +31,12 @@ import java.util.Set;
/**
* @author nik
*/
-public class ArtifactsCompiler extends NewCompiler {
+public class ArtifactsCompiler extends GenericCompiler {
static final Key> WRITTEN_PATHS_KEY = Key.create("artifacts_written_paths");
static final Key> AFFECTED_ARTIFACTS = Key.create("affected_artifacts");
public ArtifactsCompiler() {
- super("artifacts_compiler", 0, NewCompiler.CompileOrderPlace.PACKAGING);
+ super("artifacts_compiler", 0, GenericCompiler.CompileOrderPlace.PACKAGING);
}
@Nullable
@@ -52,26 +48,28 @@ public class ArtifactsCompiler extends NewCompiler getItemKeyDescriptor() {
- return VirtualFileCompileItem.KEY_DESCRIPTOR;
+ return STRING_KEY_DESCRIPTOR;
}
@NotNull
@Override
- public DataExternalizer getItemStateExternalizer() {
- return ArtifactCompilerCompileItem.OUTPUT_EXTERNALIZER;
+ public DataExternalizer getSourceStateExternalizer() {
+ return VirtualFilePersistentState.EXTERNALIZER;
}
@NotNull
@Override
- public CompilerInstance, String, ArtifactPackagingItemOutputState> createInstance(
+ public DataExternalizer getOutputStateExternalizer() {
+ return new ArtifactPackagingItemExternalizer();
+ }
+
+ @NotNull
+ @Override
+ public GenericCompilerInstance, String, VirtualFilePersistentState, ArtifactPackagingItemOutputState> createInstance(
@NotNull CompileContext context) {
return new ArtifactsCompilerInstance(context);
}
- public boolean validateConfiguration(final CompileScope scope) {
- return true;
- }
-
@NotNull
public String getDescription() {
return "Artifacts Packaging Compiler";
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsCompilerInstance.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsCompilerInstance.java
index 46c1ed0bab25..acf03b898c3f 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsCompilerInstance.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsCompilerInstance.java
@@ -17,7 +17,10 @@ package com.intellij.packaging.impl.compiler;
import com.intellij.compiler.CompilerManagerImpl;
import com.intellij.compiler.impl.CompilerUtil;
-import com.intellij.compiler.impl.newApi.CompilerInstance;
+import com.intellij.openapi.compiler.generic.GenericCompilerCacheState;
+import com.intellij.openapi.compiler.generic.GenericCompilerInstance;
+import com.intellij.openapi.compiler.generic.GenericCompilerProcessingItem;
+import com.intellij.openapi.compiler.generic.VirtualFilePersistentState;
import com.intellij.compiler.impl.packagingCompiler.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
@@ -31,7 +34,7 @@ import com.intellij.openapi.deployment.DeploymentUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.progress.ProcessCanceledException;
+import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.SystemInfo;
@@ -59,8 +62,8 @@ import java.util.*;
/**
* @author nik
*/
-public class ArtifactsCompilerInstance extends CompilerInstance {
+public class ArtifactsCompilerInstance extends GenericCompilerInstance {
private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.compiler.ArtifactsCompilerInstance");
private ArtifactsProcessingItemsBuilderContext myBuilderContext;
@@ -117,8 +120,9 @@ public class ArtifactsCompilerInstance extends CompilerInstance> obsoleteItems) {
- deleteFiles(obsoleteItems, Collections.>emptyList());
+ public void processObsoleteTarget(@NotNull String targetId,
+ @NotNull List> obsoleteItems) {
+ deleteFiles(obsoleteItems, Collections.>emptyList());
}
@NotNull
@@ -160,7 +164,7 @@ public class ArtifactsCompilerInstance extends CompilerInstance> changedItems,
+ private boolean doBuild(final List> changedItems,
final Set processedItems,
final @NotNull Set writtenPaths, final Set deletedJars) {
final boolean testMode = ApplicationManager.getApplication().isUnitTestMode();
@@ -179,8 +183,8 @@ public class ArtifactsCompilerInstance extends CompilerInstance item : changedItems) {
- final ArtifactCompilerCompileItem sourceItem = item.getFirst();
+ for (final GenericCompilerProcessingItem item : changedItems) {
+ final ArtifactCompilerCompileItem sourceItem = item.getItem();
myContext.getProgressIndicator().checkCanceled();
final Ref exception = Ref.create(null);
@@ -304,9 +308,10 @@ public class ArtifactsCompilerInstance extends CompilerInstance> changedItems,
- @NotNull List> obsoleteItems,
- @NotNull final OutputConsumer consumer) {
+ public void processItems(@NotNull ArtifactBuildTarget target,
+ @NotNull final List> changedItems,
+ @NotNull List