mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external artifact builder: refactoring
This commit is contained in:
+2
-2
@@ -85,10 +85,10 @@ public class ArtifactSourceFilesState extends CompositeStorageOwner {
|
||||
myDeletedFiles.clear();
|
||||
getOrCreateInstructions().processRoots(new ArtifactRootProcessor() {
|
||||
@Override
|
||||
public boolean process(ArtifactSourceRoot root, int rootIndex, Collection<DestinationInfo> destinations) throws IOException {
|
||||
public boolean process(ArtifactSourceRoot root, DestinationInfo destinations) throws IOException {
|
||||
final File rootFile = root.getRootFile();
|
||||
if (rootFile.exists()) {
|
||||
processRecursively(rootFile, rootIndex, dataManager, root.getFilter(), currentPaths);
|
||||
processRecursively(rootFile, root.getRootIndex(), dataManager, root.getFilter(), currentPaths);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+8
-10
@@ -130,23 +130,21 @@ public class IncArtifactBuilder extends ProjectLevelBuilder {
|
||||
final Set<JarInfo> changedJars = new THashSet<JarInfo>();
|
||||
instructions.processRoots(new ArtifactRootProcessor() {
|
||||
@Override
|
||||
public boolean process(ArtifactSourceRoot root, int rootIndex, Collection<DestinationInfo> destinations) throws IOException {
|
||||
public boolean process(ArtifactSourceRoot root, DestinationInfo destination) throws IOException {
|
||||
if (context.getCancelStatus().isCanceled()) return false;
|
||||
|
||||
final Set<String> sourcePaths = filesToProcess.get(rootIndex);
|
||||
final Set<String> sourcePaths = filesToProcess.get(root.getRootIndex());
|
||||
if (sourcePaths == null) return true;
|
||||
|
||||
for (String sourcePath : sourcePaths) {
|
||||
if (!root.containsFile(sourcePath, pd.dataManager)) continue;//todo[nik] this seems to be unnecessary
|
||||
|
||||
for (DestinationInfo destination : destinations) {
|
||||
if (destination instanceof ExplodedDestinationInfo) {
|
||||
root.copyFromRoot(sourcePath, rootIndex, destination.getOutputPath(), context, srcOutMapping, outSrcMapping);
|
||||
}
|
||||
else if (outSrcMapping.getState(destination.getOutputFilePath()) == null) {
|
||||
outSrcMapping.update(destination.getOutputFilePath(), Collections.<ArtifactOutputToSourceMapping.SourcePathAndRootIndex>emptyList());
|
||||
changedJars.add(((JarDestinationInfo)destination).getJarInfo());
|
||||
}
|
||||
if (destination instanceof ExplodedDestinationInfo) {
|
||||
root.copyFromRoot(sourcePath, root.getRootIndex(), destination.getOutputPath(), context, srcOutMapping, outSrcMapping);
|
||||
}
|
||||
else if (outSrcMapping.getState(destination.getOutputFilePath()) == null) {
|
||||
outSrcMapping.update(destination.getOutputFilePath(), Collections.<ArtifactOutputToSourceMapping.SourcePathAndRootIndex>emptyList());
|
||||
changedJars.add(((JarDestinationInfo)destination).getJarInfo());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -164,8 +164,7 @@ public class JarsBuilder {
|
||||
final String relativePath = pair.getFirst();
|
||||
if (pair.getSecond() instanceof ArtifactSourceRoot) {
|
||||
final ArtifactSourceRoot root = (ArtifactSourceRoot)pair.getSecond();
|
||||
final int rootIndex = myInstructions.getRootIndex(root);
|
||||
LOG.assertTrue(rootIndex != -1, root + " not found in instructions");
|
||||
final int rootIndex = root.getRootIndex();
|
||||
final ArtifactBuilderLogger logger = myContext.getLoggingManager().getArtifactBuilderLogger();
|
||||
if (root instanceof FileBasedArtifactSourceRoot) {
|
||||
addFileToJar(jarOutputStream, jarFile, root.getRootFile(), root.getFilter(), relativePath, targetJarPath, writtenPaths,
|
||||
|
||||
+2
-2
@@ -45,14 +45,14 @@ public abstract class ArtifactCompilerInstructionCreatorBase implements Artifact
|
||||
public void addDirectoryCopyInstructions(@NotNull File directory, @Nullable SourceFileFilter filter) {
|
||||
final boolean copyExcluded = myInstructionsBuilder.getRootsIndex().isExcluded(directory);
|
||||
SourceFileFilter fileFilter = new SourceFileFilterImpl(filter, myInstructionsBuilder.getRootsIndex(), myInstructionsBuilder.getIgnoredFilePatterns(), copyExcluded);
|
||||
addDirectoryCopyInstructions(new FileBasedArtifactSourceRoot(directory, fileFilter));
|
||||
addDirectoryCopyInstructions(myInstructionsBuilder.createFileBasedRoot(directory, fileFilter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtractDirectoryInstruction(@NotNull File jarFile, @NotNull String pathInJar) {
|
||||
final SourceFileFilterImpl filter = new SourceFileFilterImpl(null, myInstructionsBuilder.getRootsIndex(),
|
||||
myInstructionsBuilder.getIgnoredFilePatterns(), false);
|
||||
addDirectoryCopyInstructions(new JarBasedArtifactSourceRoot(jarFile, pathInJar, filter));
|
||||
addDirectoryCopyInstructions(myInstructionsBuilder.createJarBasedRoot(jarFile, pathInJar, filter));
|
||||
}
|
||||
|
||||
protected abstract void addDirectoryCopyInstructions(ArtifactSourceRoot root);
|
||||
|
||||
-8
@@ -1,8 +1,5 @@
|
||||
package org.jetbrains.jps.incremental.artifacts.instructions;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -10,9 +7,4 @@ import java.io.IOException;
|
||||
*/
|
||||
public interface ArtifactInstructionsBuilder {
|
||||
void processRoots(ArtifactRootProcessor processor) throws IOException;
|
||||
|
||||
@Nullable
|
||||
JarInfo getJarInfo(String outputPath);
|
||||
|
||||
int getRootIndex(@NotNull ArtifactSourceRoot root);
|
||||
}
|
||||
|
||||
+20
-29
@@ -1,17 +1,16 @@
|
||||
package org.jetbrains.jps.incremental.artifacts.instructions;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.LinkedMultiMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.IgnoredFilePatterns;
|
||||
import org.jetbrains.jps.incremental.ModuleRootsIndex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -19,15 +18,16 @@ import java.util.Map;
|
||||
*/
|
||||
public class ArtifactInstructionsBuilderImpl implements ArtifactInstructionsBuilder {
|
||||
private final Map<String, JarInfo> myJarByPath;
|
||||
private final MultiMap<ArtifactSourceRoot, DestinationInfo> myInstructions;
|
||||
private final List<Pair<ArtifactSourceRoot, DestinationInfo>> myInstructions;
|
||||
private final ModuleRootsIndex myRootsIndex;
|
||||
private final IgnoredFilePatterns myIgnoredFilePatterns;
|
||||
private int myRootIndex;
|
||||
|
||||
public ArtifactInstructionsBuilderImpl(ModuleRootsIndex rootsIndex, IgnoredFilePatterns patterns) {
|
||||
myRootsIndex = rootsIndex;
|
||||
myIgnoredFilePatterns = patterns;
|
||||
myJarByPath = new HashMap<String, JarInfo>();
|
||||
myInstructions = new LinkedMultiMap<ArtifactSourceRoot, DestinationInfo>();
|
||||
myInstructions = new ArrayList<Pair<ArtifactSourceRoot, DestinationInfo>>();
|
||||
}
|
||||
|
||||
public IgnoredFilePatterns getIgnoredFilePatterns() {
|
||||
@@ -40,7 +40,7 @@ public class ArtifactInstructionsBuilderImpl implements ArtifactInstructionsBuil
|
||||
return false;
|
||||
}
|
||||
|
||||
myInstructions.putValue(root, destinationInfo);
|
||||
myInstructions.add(Pair.create(root, destinationInfo));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,32 +56,23 @@ public class ArtifactInstructionsBuilderImpl implements ArtifactInstructionsBuil
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JarInfo getJarInfo(String outputPath) {
|
||||
return myJarByPath.get(outputPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRootIndex(@NotNull ArtifactSourceRoot root) {
|
||||
int i = 0;
|
||||
for (Map.Entry<ArtifactSourceRoot, Collection<DestinationInfo>> entry : myInstructions.entrySet()) {
|
||||
if (entry.getKey().equals(root)) {
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processRoots(ArtifactRootProcessor processor) throws IOException {
|
||||
int i = 0;
|
||||
for (Map.Entry<ArtifactSourceRoot, Collection<DestinationInfo>> entry : myInstructions.entrySet()) {
|
||||
if (!processor.process(entry.getKey(), i, entry.getValue())) {
|
||||
for (Pair<ArtifactSourceRoot, DestinationInfo> pair : myInstructions) {
|
||||
if (!processor.process(pair.getFirst(), pair.getSecond())) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public FileBasedArtifactSourceRoot createFileBasedRoot(@NotNull File file,
|
||||
@NotNull SourceFileFilter filter) {
|
||||
return new FileBasedArtifactSourceRoot(file, filter, myRootIndex++);
|
||||
}
|
||||
|
||||
public JarBasedArtifactSourceRoot createJarBasedRoot(@NotNull File jarFile,
|
||||
@NotNull String pathInJar,
|
||||
@NotNull SourceFileFilter filter) {
|
||||
return new JarBasedArtifactSourceRoot(jarFile, pathInJar, filter, myRootIndex++);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,5 +7,5 @@ import java.util.Collection;
|
||||
* @author nik
|
||||
*/
|
||||
public interface ArtifactRootProcessor {
|
||||
boolean process(ArtifactSourceRoot root, int rootIndex, Collection<DestinationInfo> destinations) throws IOException;
|
||||
boolean process(ArtifactSourceRoot root, DestinationInfo destinations) throws IOException;
|
||||
}
|
||||
|
||||
+7
-1
@@ -14,9 +14,11 @@ import java.io.IOException;
|
||||
*/
|
||||
public abstract class ArtifactSourceRoot {
|
||||
private final SourceFileFilter myFilter;
|
||||
private final int myRootIndex;
|
||||
|
||||
protected ArtifactSourceRoot(@NotNull SourceFileFilter filter) {
|
||||
protected ArtifactSourceRoot(@NotNull SourceFileFilter filter, int index) {
|
||||
myFilter = filter;
|
||||
myRootIndex = index;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -44,4 +46,8 @@ public abstract class ArtifactSourceRoot {
|
||||
public int hashCode() {
|
||||
return myFilter.hashCode();
|
||||
}
|
||||
|
||||
public int getRootIndex() {
|
||||
return myRootIndex;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class CopyToDirectoryInstructionCreator extends ArtifactCompilerInstructi
|
||||
}
|
||||
|
||||
public void addFileCopyInstruction(@NotNull File file, @NotNull String outputFileName) {
|
||||
myInstructionsBuilder.addDestination(new FileBasedArtifactSourceRoot(file, SourceFileFilter.ALL), new ExplodedDestinationInfo(myOutputPath + "/" + outputFileName));
|
||||
myInstructionsBuilder.addDestination(myInstructionsBuilder.createFileBasedRoot(file, SourceFileFilter.ALL), new ExplodedDestinationInfo(myOutputPath + "/" + outputFileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@ import java.util.Collections;
|
||||
public class FileBasedArtifactSourceRoot extends ArtifactSourceRoot {
|
||||
private final File myFile;
|
||||
|
||||
public FileBasedArtifactSourceRoot(@NotNull File file, @NotNull SourceFileFilter filter) {
|
||||
super(filter);
|
||||
public FileBasedArtifactSourceRoot(@NotNull File file, @NotNull SourceFileFilter filter, int index) {
|
||||
super(filter, index);
|
||||
myFile = file;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ public class JarBasedArtifactSourceRoot extends ArtifactSourceRoot {
|
||||
private final File myJarFile;
|
||||
private final String myPathInJar;
|
||||
|
||||
public JarBasedArtifactSourceRoot(@NotNull File jarFile, @NotNull String pathInJar, @NotNull SourceFileFilter filter) {
|
||||
super(filter);
|
||||
public JarBasedArtifactSourceRoot(@NotNull File jarFile, @NotNull String pathInJar, @NotNull SourceFileFilter filter, int index) {
|
||||
super(filter, index);
|
||||
myJarFile = jarFile;
|
||||
myPathInJar = pathInJar;
|
||||
}
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.jps.incremental.artifacts.instructions;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
@@ -42,7 +41,7 @@ public class PackIntoArchiveInstructionCreator extends ArtifactCompilerInstructi
|
||||
}
|
||||
|
||||
public void addFileCopyInstruction(@NotNull File file, @NotNull String outputFileName) {
|
||||
addCopyInstruction(childPathInJar(outputFileName), new FileBasedArtifactSourceRoot(file, SourceFileFilter.ALL));
|
||||
addCopyInstruction(childPathInJar(outputFileName), myInstructionsBuilder.createFileBasedRoot(file, SourceFileFilter.ALL));
|
||||
}
|
||||
|
||||
private void addCopyInstruction(String pathInJar, final ArtifactSourceRoot root) {
|
||||
|
||||
Reference in New Issue
Block a user