From 1d0c520e415465aa581aa501eb84a00371979da4 Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 9 Aug 2010 15:08:06 +0400 Subject: [PATCH] new compiler api: persistent state splitted to source and output state --- java/compiler/impl/compiler-impl.iml | 1 + .../compiler/impl/CompilerCacheManager.java | 11 +-- .../compiler/impl/NewCompilerRunner.java | 67 ++++++++++++------- .../compiler/impl/newApi/CompileItem.java | 12 +++- .../impl/newApi/CompilerInstance.java | 9 ++- .../compiler/impl/newApi/NewCompiler.java | 8 ++- .../impl/newApi/NewCompilerCache.java | 66 +++++++++++++----- .../impl/newApi/NewCompilerItemState.java | 43 ++++++++++++ .../newApi/NewCompilerPersistentData.java | 2 +- .../newApi/SingleTargetCompilerInstance.java | 5 +- .../impl/newApi/VirtualFileCompileItem.java | 15 +++-- .../newApi/VirtualFileStateExternalizer.java | 14 ++-- .../compiler/ArtifactCompilerCompileItem.java | 6 +- .../ArtifactPackagingItemExternalizer.java | 11 ++- .../ArtifactPackagingItemOutputState.java | 6 +- .../impl/compiler/ArtifactsCompiler.java | 19 +++--- .../compiler/ArtifactsCompilerInstance.java | 40 ++++++----- 17 files changed, 221 insertions(+), 114 deletions(-) create mode 100644 java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerItemState.java 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/CompilerCacheManager.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompilerCacheManager.java index 4afce35c12ac..b93583556588 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompilerCacheManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompilerCacheManager.java @@ -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, NewCompilerCache> myNewCachesMap = new HashMap, NewCompilerCache>(); private final List myCacheDisposables = new ArrayList(); private final File myCachesRoot; private final Runnable myShutdownTask = new Runnable() { @@ -90,10 +90,11 @@ public class CompilerCacheManager implements ProjectComponent { return dir; } - public synchronized NewCompilerCache getNewCompilerCache(NewCompiler compiler) throws IOException { - NewCompilerCache cache = myNewCachesMap.get(compiler); + public synchronized NewCompilerCache + getNewCompilerCache(NewCompiler compiler) throws IOException { + NewCompilerCache cache = myNewCachesMap.get(compiler); if (cache == null) { - final NewCompilerCache newCache = new NewCompilerCache(compiler, NewCompilerRunner.getNewCompilerCacheDir(myProject, compiler)); + final NewCompilerCache newCache = new NewCompilerCache(compiler, NewCompilerRunner.getNewCompilerCacheDir(myProject, compiler)); myNewCachesMap.put(compiler, newCache); myCacheDisposables.add(new Disposable() { @Override @@ -104,7 +105,7 @@ public class CompilerCacheManager implements ProjectComponent { cache = newCache; } //noinspection unchecked - return (NewCompilerCache)cache; + return (NewCompilerCache)cache; } public synchronized FileProcessingCompilerStateCache getFileProcessingCompilerCache(FileProcessingCompiler compiler) throws IOException { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/NewCompilerRunner.java b/java/compiler/impl/src/com/intellij/compiler/impl/NewCompilerRunner.java index a5dc5e2ffc24..1b7e3438d5ea 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/NewCompilerRunner.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/NewCompilerRunner.java @@ -15,14 +15,17 @@ */ package com.intellij.compiler.impl; +import com.google.common.base.Throwables; import com.intellij.compiler.impl.newApi.*; 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.Pair; import com.intellij.openapi.util.Ref; import com.intellij.util.CommonProcessors; import com.intellij.util.Processor; @@ -43,7 +46,7 @@ public class NewCompilerRunner { private CompileContext myContext; private final boolean myForceCompile; private final boolean myOnlyCheckStatus; - private final NewCompiler[] myCompilers; + private final NewCompiler[] myCompilers; private final Project myProject; public NewCompilerRunner(CompileContext context, CompilerManager compilerManager, boolean forceCompile, boolean onlyCheckStatus) { @@ -57,7 +60,7 @@ public class NewCompilerRunner { public boolean invokeCompilers(NewCompiler.CompileOrderPlace place) throws CompileDriver.ExitException { boolean didSomething = false; try { - for (NewCompiler compiler : myCompilers) { + for (NewCompiler compiler : myCompilers) { if (compiler.getOrderPlace().equals(place)) { didSomething = invokeCompiler(compiler); } @@ -81,13 +84,13 @@ public class NewCompilerRunner { return didSomething; } - private boolean invokeCompiler(NewCompiler compiler) throws IOException, CompileDriver.ExitException { + 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); + private , Key, SourceState, OutputState> + 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()); @@ -106,10 +109,10 @@ public class NewCompilerRunner { } List keys = new ArrayList(); cache.processSources(id, new CommonProcessors.CollectProcessor(keys)); - List> obsoleteSources = new ArrayList>(); + List> obsoleteSources = new ArrayList>(); for (Key key : keys) { - final State state = cache.getState(id, key); - obsoleteSources.add(Pair.create(key, state)); + final NewCompilerCache.PersistentStateData state = cache.getState(id, key); + obsoleteSources.add(new NewCompilerItemState(key, state.mySourceState, state.myOutputState)); } instance.processObsoleteTarget(target, obsoleteSources); if (myContext.getMessageCount(CompilerMessageCategory.ERROR) > 0) { @@ -131,23 +134,24 @@ public class NewCompilerRunner { return didSomething; } - public static File getNewCompilerCacheDir(Project project, NewCompiler compiler) { + 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 { + private , Key, SourceState, OutputState> + 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 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() { @@ -155,9 +159,13 @@ public class NewCompilerRunner { 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)); + final NewCompilerCache.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 NewCompilerItemState(item, sourceState, outputState)); } } } @@ -193,9 +201,10 @@ public class NewCompilerRunner { throw new CompileDriver.ExitException(CompileDriver.ExitStatus.CANCELLED); } - List> obsoleteItems = new ArrayList>(); + List> obsoleteItems = new ArrayList>(); for (Key key : toRemove) { - obsoleteItems.add(Pair.create(key, cache.getState(targetId, key))); + final NewCompilerCache.PersistentStateData data = cache.getState(targetId, key); + obsoleteItems.add(new NewCompilerItemState(key, data.mySourceState, data.myOutputState)); } final List processedItems = new ArrayList(); @@ -218,9 +227,19 @@ public class NewCompilerRunner { cache.remove(targetId, key); } CompilerUtil.refreshIOFiles(toRefresh); - for (Item item : processedItems) { - cache.putOutput(targetId, item.getKey(), item.computeState()); - } + + 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; @@ -229,7 +248,7 @@ public class NewCompilerRunner { private class SourceItemHashingStrategy implements TObjectHashingStrategy { private KeyDescriptor myKeyDescriptor; - public SourceItemHashingStrategy(NewCompiler compiler) { + public SourceItemHashingStrategy(NewCompiler compiler) { myKeyDescriptor = compiler.getItemKeyDescriptor(); } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompileItem.java b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompileItem.java index fb941ca3e4b2..df5eb2fbfc14 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompileItem.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompileItem.java @@ -20,12 +20,18 @@ import org.jetbrains.annotations.NotNull; /** * @author nik */ -public abstract class CompileItem { +public abstract class CompileItem { @NotNull public abstract Key getKey(); - public abstract boolean isUpToDate(@NotNull State state); + public abstract boolean isSourceUpToDate(@NotNull SourceState state); @NotNull - public abstract State computeState(); + 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/CompilerInstance.java b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompilerInstance.java index 2e9f9cf59593..f5a9df2d41f0 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompilerInstance.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/CompilerInstance.java @@ -17,7 +17,6 @@ package com.intellij.compiler.impl.newApi; 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,7 +25,7 @@ import java.util.List; /** * @author nik */ -public abstract class CompilerInstance, Key, State> { +public abstract class CompilerInstance, Key, SourceState, OutputState> { protected final CompileContext myContext; protected CompilerInstance(CompileContext context) { @@ -43,16 +42,16 @@ 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 addProcessedItem(@NotNull Item sourceItem); diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompiler.java index b82b8bf9d84c..11c770a62461 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompiler.java @@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull; /** * @author nik */ -public abstract class NewCompiler implements Compiler { +public abstract class NewCompiler implements Compiler { private final String myId; private final int myVersion; private final CompileOrderPlace myOrderPlace; @@ -38,10 +38,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, Key, State> createInstance(@NotNull CompileContext context); + public abstract CompilerInstance, Key, SourceState, OutputState> createInstance(@NotNull CompileContext context); public final String getId() { return myId; diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerCache.java b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerCache.java index 0b6ea2ecc3e0..6982e084a52b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerCache.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerCache.java @@ -17,6 +17,7 @@ package com.intellij.compiler.impl.newApi; 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; @@ -28,28 +29,25 @@ import java.io.IOException; /** * @author nik */ -public class NewCompilerCache { +public class NewCompilerCache { private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.newApi.NewCompilerCache"); - private PersistentHashMap, State> myPersistentMap; + private PersistentHashMap, PersistentStateData> myPersistentMap; private File myCacheFile; - private final NewCompiler myCompiler; + private final NewCompiler myCompiler; - public NewCompilerCache(NewCompiler compiler, final File compilerCacheDir) throws IOException { + public NewCompilerCache(NewCompiler 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,7 +73,7 @@ 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)); } @@ -88,16 +86,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, Key key, SourceState sourceState, 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(SourceState sourceState, OutputState outputState) { + mySourceState = sourceState; + myOutputState = outputState; + } + } + private class SourceItemDataDescriptor implements KeyDescriptor> { private final KeyDescriptor myKeyDescriptor; @@ -129,4 +142,27 @@ public class NewCompilerCache { return getKeyAndTargetData(item, target); } } + + private class PersistentStateDataExternalizer implements DataExternalizer> { + private DataExternalizer mySourceStateExternalizer; + private DataExternalizer myOutputStateExternalizer; + + public PersistentStateDataExternalizer(NewCompiler 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/NewCompilerItemState.java b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerItemState.java new file mode 100644 index 000000000000..4dd7084fec76 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerItemState.java @@ -0,0 +1,43 @@ +/* + * 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.newApi; + +/** + * @author nik + */ +public class NewCompilerItemState { + private final Item myItem; + private final SourceState mySourceState; + private final OutputState myOutputState; + + public NewCompilerItemState(Item item, SourceState sourceState, OutputState outputState) { + myItem = item; + mySourceState = sourceState; + myOutputState = outputState; + } + + public Item getItem() { + return myItem; + } + + public SourceState getSourceState() { + return mySourceState; + } + + public OutputState getOutputState() { + return myOutputState; + } +} diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerPersistentData.java b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerPersistentData.java index 1746c334cf77..703a206c7d1f 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerPersistentData.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/NewCompilerPersistentData.java @@ -30,7 +30,7 @@ import java.util.Set; */ public class NewCompilerPersistentData { private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.newApi.NewCompilerPersistentData"); - private static final int VERSION = 0; + private static final int VERSION = 1; private File myFile; private Map myTarget2Id = new HashMap(); private TIntHashSet myUsedIds = new TIntHashSet(); diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/SingleTargetCompilerInstance.java b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/SingleTargetCompilerInstance.java index 359366e70bb4..4e5b5fb51dd6 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/SingleTargetCompilerInstance.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/SingleTargetCompilerInstance.java @@ -16,7 +16,6 @@ package com.intellij.compiler.impl.newApi; import com.intellij.openapi.compiler.CompileContext; -import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -25,7 +24,7 @@ import java.util.List; /** * @author nik */ -public abstract class SingleTargetCompilerInstance, S, O> extends CompilerInstance { +public abstract class SingleTargetCompilerInstance, K,S, O> extends CompilerInstance { protected SingleTargetCompilerInstance(CompileContext context) { super(context); } @@ -43,6 +42,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/compiler/impl/newApi/VirtualFileCompileItem.java index a2c0b7055c9f..9131318960e6 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/newApi/VirtualFileCompileItem.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/newApi/VirtualFileCompileItem.java @@ -23,7 +23,7 @@ import org.jetbrains.annotations.NotNull; /** * @author nik */ -public abstract class VirtualFileCompileItem extends CompileItem { +public abstract class VirtualFileCompileItem extends CompileItem { public static final KeyDescriptor KEY_DESCRIPTOR = new EnumeratorStringDescriptor(); protected final VirtualFile myFile; @@ -36,15 +36,16 @@ public abstract class VirtualFileCompileItem implements DataExternalizer { - protected abstract void doSave(DataOutput out, State value) throws IOException; - - protected abstract State doRead(DataInput in, long sourceTimestamp) throws IOException; +public class VirtualFileStateExternalizer implements DataExternalizer { + public static VirtualFileStateExternalizer INSTANCE = new VirtualFileStateExternalizer(); @Override - public final void save(DataOutput out, State value) throws IOException { + public void save(DataOutput out, VirtualFilePersistentState value) throws IOException { out.writeLong(value.getSourceTimestamp()); - doSave(out, value); } @Override - public final State read(DataInput in) throws IOException { - final long sourceTimestamp = in.readLong(); - return doRead(in, sourceTimestamp); + public VirtualFilePersistentState read(DataInput in) throws IOException { + return new VirtualFilePersistentState(in.readLong()); } } 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..05113499af2a 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 @@ -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..b8cdb63fdb6b 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,10 +15,7 @@ */ 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.compiler.impl.newApi.*; import com.intellij.openapi.compiler.CompileContext; import com.intellij.openapi.compiler.CompileScope; import com.intellij.openapi.compiler.CompilerManager; @@ -35,7 +32,7 @@ import java.util.Set; /** * @author nik */ -public class ArtifactsCompiler extends NewCompiler { +public class ArtifactsCompiler extends NewCompiler { static final Key> WRITTEN_PATHS_KEY = Key.create("artifacts_written_paths"); static final Key> AFFECTED_ARTIFACTS = Key.create("affected_artifacts"); @@ -57,13 +54,19 @@ public class ArtifactsCompiler extends NewCompiler getItemStateExternalizer() { - return ArtifactCompilerCompileItem.OUTPUT_EXTERNALIZER; + public DataExternalizer getSourceStateExternalizer() { + return VirtualFileStateExternalizer.INSTANCE; } @NotNull @Override - public CompilerInstance, String, ArtifactPackagingItemOutputState> createInstance( + public DataExternalizer getOutputStateExternalizer() { + return new ArtifactPackagingItemExternalizer(); + } + + @NotNull + @Override + public CompilerInstance, String, VirtualFilePersistentState, ArtifactPackagingItemOutputState> createInstance( @NotNull CompileContext context) { return new ArtifactsCompilerInstance(context); } 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..5f995f90048b 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 @@ -18,6 +18,8 @@ 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.compiler.impl.newApi.NewCompilerItemState; +import com.intellij.compiler.impl.newApi.VirtualFilePersistentState; import com.intellij.compiler.impl.packagingCompiler.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; @@ -31,7 +33,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; @@ -60,7 +62,7 @@ import java.util.*; * @author nik */ public class ArtifactsCompilerInstance extends CompilerInstance { + String, VirtualFilePersistentState, ArtifactPackagingItemOutputState> { private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.compiler.ArtifactsCompilerInstance"); private ArtifactsProcessingItemsBuilderContext myBuilderContext; @@ -117,8 +119,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 +163,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 +182,8 @@ public class ArtifactsCompilerInstance extends CompilerInstance item : changedItems) { - final ArtifactCompilerCompileItem sourceItem = item.getFirst(); + for (final NewCompilerItemState item : changedItems) { + final ArtifactCompilerCompileItem sourceItem = item.getItem(); myContext.getProgressIndicator().checkCanceled(); final Ref exception = Ref.create(null); @@ -304,9 +307,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> obsoleteItems, + @NotNull OutputConsumer consumer) { final THashSet deletedJars = deleteFiles(obsoleteItems, changedItems); @@ -333,8 +337,8 @@ public class ArtifactsCompilerInstance extends CompilerInstance deleteFiles(List> obsoleteItems, - List> changedItems) { + private THashSet deleteFiles(List> obsoleteItems, + List> changedItems) { myContext.getProgressIndicator().setText(CompilerBundle.message("packaging.compiler.message.deleting.outdated.files")); final boolean testMode = ApplicationManager.getApplication().isUnitTestMode(); @@ -345,21 +349,21 @@ public class ArtifactsCompilerInstance extends CompilerInstance pathToDelete = new THashSet(); - for (Pair item : changedItems) { - final ArtifactPackagingItemOutputState cached = item.getSecond(); + for (NewCompilerItemState item : changedItems) { + final ArtifactPackagingItemOutputState cached = item.getOutputState(); if (cached != null) { for (Pair destination : cached.myDestinations) { pathToDelete.add(destination.getFirst()); } } } - for (Pair item : changedItems) { - for (DestinationInfo destination : item.getFirst().getDestinations()) { + for (NewCompilerItemState item : changedItems) { + for (DestinationInfo destination : item.getItem().getDestinations()) { pathToDelete.remove(destination.getOutputPath()); } } - for (Pair item : obsoleteItems) { - for (Pair destination : item.getSecond().myDestinations) { + for (NewCompilerItemState item : obsoleteItems) { + for (Pair destination : item.getOutputState().myDestinations) { pathToDelete.add(destination.getFirst()); } }