From 286f2cefe8d5fb50bc9054386cb52527bd48784e Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Sat, 16 Dec 2023 11:23:44 +0100 Subject: [PATCH] JPS mappings for incremental compilation refactoring: support storing graph data in portable format; introduce NodeSourcePathMapper GitOrigin-RevId: 4d2cbb59b9a52da1b33303af108a7569f02b8a6b --- .../BackendCallbackToGraphDeltaAdapter.java | 11 +++- .../jps/builders/java/JavaBuilderUtil.java | 51 +++++++------- .../jps/dependency/GraphConfiguration.java | 13 ++++ .../jetbrains/jps/dependency/NodeSource.java | 5 +- .../jps/dependency/NodeSourcePathMapper.java | 16 +++++ .../jps/dependency/impl/FileSource.java | 66 ------------------- .../jps/dependency/impl/GraphImpl.java | 2 +- .../jps/dependency/impl/PathSource.java | 62 +++++++++++++++++ .../jps/dependency/impl/PathSourceMapper.java | 48 ++++++++++++++ .../java/JavaDifferentiateStrategy.java | 8 +-- .../incremental/storage/BuildDataManager.java | 19 +++++- .../builders/java/MockPackageFacadeBuilder.kt | 9 ++- .../dependency/NodeGraphPersistentTest.java | 24 +++---- 13 files changed, 214 insertions(+), 120 deletions(-) create mode 100644 jps/jps-builders/src/org/jetbrains/jps/dependency/GraphConfiguration.java create mode 100644 jps/jps-builders/src/org/jetbrains/jps/dependency/NodeSourcePathMapper.java delete mode 100644 jps/jps-builders/src/org/jetbrains/jps/dependency/impl/FileSource.java create mode 100644 jps/jps-builders/src/org/jetbrains/jps/dependency/impl/PathSource.java create mode 100644 jps/jps-builders/src/org/jetbrains/jps/dependency/impl/PathSourceMapper.java diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/java/BackendCallbackToGraphDeltaAdapter.java b/jps/jps-builders/src/org/jetbrains/jps/builders/java/BackendCallbackToGraphDeltaAdapter.java index 7a7e49f429e0..b8b17b8c13e9 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/java/BackendCallbackToGraphDeltaAdapter.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/java/BackendCallbackToGraphDeltaAdapter.java @@ -4,14 +4,13 @@ package org.jetbrains.jps.builders.java; import com.intellij.openapi.util.Pair; import com.intellij.util.SmartList; import org.jetbrains.jps.builders.java.dependencyView.Callbacks; +import org.jetbrains.jps.dependency.GraphConfiguration; import org.jetbrains.jps.dependency.Node; import org.jetbrains.jps.dependency.NodeSource; -import org.jetbrains.jps.dependency.impl.FileSource; import org.jetbrains.jps.dependency.java.*; import org.jetbrains.jps.javac.Iterators; import org.jetbrains.org.objectweb.asm.ClassReader; -import java.nio.file.Path; import java.util.*; class BackendCallbackToGraphDeltaAdapter implements Callbacks.Backend { @@ -21,6 +20,12 @@ class BackendCallbackToGraphDeltaAdapter implements Callbacks.Backend { private final Map, Collection>> myImportRefs = Collections.synchronizedMap(new HashMap<>()); private final Map> myConstantRefs = Collections.synchronizedMap(new HashMap<>()); private final List, Iterable>> myNodes = new ArrayList<>(); + private final GraphConfiguration myGraphConfig; + + BackendCallbackToGraphDeltaAdapter(GraphConfiguration graphConfig) { + myGraphConfig = graphConfig; + } + @Override public void associate(String classFileName, Collection sources, ClassReader cr, boolean isGenerated) { JvmClassNodeBuilder builder = JvmClassNodeBuilder.create(classFileName, cr, isGenerated); @@ -34,7 +39,7 @@ class BackendCallbackToGraphDeltaAdapter implements Callbacks.Backend { var node = builder.getResult(); if (!node.isPrivate()) { - myNodes.add(new Pair<>(node, Iterators.collect(Iterators.map(sources, s -> new FileSource(Path.of(s))), new SmartList<>()))); + myNodes.add(new Pair<>(node, Iterators.collect(Iterators.map(sources, myGraphConfig.getPathMapper()::toNodeSource), new SmartList<>()))); } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java b/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java index 18f65657c8d6..ebf7d186e2ff 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java @@ -18,12 +18,8 @@ import org.jetbrains.jps.builders.*; import org.jetbrains.jps.builders.java.dependencyView.Callbacks; import org.jetbrains.jps.builders.java.dependencyView.Mappings; import org.jetbrains.jps.builders.storage.BuildDataCorruptedException; -import org.jetbrains.jps.dependency.Delta; -import org.jetbrains.jps.dependency.DependencyGraph; -import org.jetbrains.jps.dependency.DifferentiateParameters; -import org.jetbrains.jps.dependency.DifferentiateResult; +import org.jetbrains.jps.dependency.*; import org.jetbrains.jps.dependency.impl.DifferentiateParametersBuilder; -import org.jetbrains.jps.dependency.impl.FileSource; import org.jetbrains.jps.incremental.*; import org.jetbrains.jps.incremental.fs.CompilationRound; import org.jetbrains.jps.incremental.messages.BuildMessage; @@ -47,7 +43,6 @@ import org.jetbrains.jps.service.JpsServiceManager; import java.io.File; import java.io.FileFilter; import java.io.IOException; -import java.nio.file.Path; import java.util.*; public final class JavaBuilderUtil { @@ -107,10 +102,11 @@ public final class JavaBuilderUtil { } public static @NotNull Callbacks.Backend getDependenciesRegistrar(CompileContext context) { - if (isDepGraphEnabled()) { + GraphConfiguration graphConfig = context.getProjectDescriptor().dataManager.getDependencyGraph(); + if (isDepGraphEnabled() && graphConfig != null) { BackendCallbackToGraphDeltaAdapter callback = GRAPH_DELTA_CALLBACK_KEY.get(context); if (callback == null) { - GRAPH_DELTA_CALLBACK_KEY.set(context, callback = new BackendCallbackToGraphDeltaAdapter()); + GRAPH_DELTA_CALLBACK_KEY.set(context, callback = new BackendCallbackToGraphDeltaAdapter(graphConfig)); } return callback; } @@ -127,7 +123,9 @@ public final class JavaBuilderUtil { public static boolean updateMappingsOnRoundCompletion( CompileContext context, DirtyFilesHolder dirtyFilesHolder, ModuleChunk chunk) throws IOException { - if(isDepGraphEnabled()) { + BuildDataManager dataManager = context.getProjectDescriptor().dataManager; + GraphConfiguration graphConfig = dataManager.getDependencyGraph(); + if(isDepGraphEnabled() && graphConfig != null) { Delta delta = null; BackendCallbackToGraphDeltaAdapter callback = GRAPH_DELTA_CALLBACK_KEY.get(context); @@ -141,10 +139,10 @@ public final class JavaBuilderUtil { // so the next compilation might compile much more files than is actually needed. Iterable inputFiles = Utils.errorsDetected(context)? Collections.emptyList() : Iterators.filter(getFilesContainer(context, FILES_TO_COMPILE_KEY), f -> !compiledWithErrors.contains(f)); - DependencyGraph graph = context.getProjectDescriptor().dataManager.getDependencyGraph(); - delta = graph.createDelta( - Iterators.map(inputFiles, f -> new FileSource(f)), - Iterators.map(getRemovedPaths(chunk, dirtyFilesHolder), p -> new FileSource(Path.of(p))) + NodeSourcePathMapper pathMapper = graphConfig.getPathMapper(); + delta = graphConfig.getGraph().createDelta( + Iterators.map(inputFiles, pathMapper::toNodeSource), + Iterators.map(getRemovedPaths(chunk, dirtyFilesHolder), pathMapper::toNodeSource) ); for (var nodeData : callback.getNodes()) { delta.associate(nodeData.getFirst(), nodeData.getSecond()); @@ -208,15 +206,17 @@ public final class JavaBuilderUtil { public static void markDirtyDependenciesForInitialRound(CompileContext context, DirtyFilesHolder dfh, ModuleChunk chunk) throws IOException { if (hasRemovedPaths(chunk, dfh)) { - if (isDepGraphEnabled()) { - Delta delta = context.getProjectDescriptor().dataManager.getDependencyGraph().createDelta( - Collections.emptyList(), - Iterators.map(getRemovedPaths(chunk, dfh), p -> new FileSource(Path.of(p))) + BuildDataManager dataManager = context.getProjectDescriptor().dataManager; + GraphConfiguration graphConfig = dataManager.getDependencyGraph(); + if (isDepGraphEnabled() && graphConfig != null) { + NodeSourcePathMapper mapper = graphConfig.getPathMapper(); + Delta delta = graphConfig.getGraph().createDelta( + Collections.emptyList(), Iterators.map(getRemovedPaths(chunk, dfh), mapper::toNodeSource) ); updateDependencyGraph(context, delta, chunk, CompilationRound.CURRENT, null); return; } - final Mappings delta = context.getProjectDescriptor().dataManager.getMappings().createDelta(); + final Mappings delta = dataManager.getMappings().createDelta(); final Set empty = Collections.emptySet(); updateMappings(context, delta, dfh, chunk, empty, empty, CompilationRound.CURRENT, null); } @@ -420,21 +420,24 @@ public final class JavaBuilderUtil { boolean additionalPassRequired = false; final boolean errorsDetected = Utils.errorsDetected(context); BuildDataManager dataManager = context.getProjectDescriptor().dataManager; - DependencyGraph graph = dataManager.getDependencyGraph(); + GraphConfiguration graphConfig = Objects.requireNonNull(dataManager.getDependencyGraph()); + DependencyGraph dependencyGraph = graphConfig.getGraph(); + NodeSourcePathMapper pathMapper = graphConfig.getPathMapper(); + final ModulesBasedFileFilter moduleBasedFilter = new ModulesBasedFileFilter(context, chunk); DifferentiateParametersBuilder params = DifferentiateParametersBuilder.create(chunk.getPresentableShortName()) .calculateAffected(context.shouldDifferentiate(chunk) && !isForcedRecompilationAllJavaModules(context)) .processConstantsIncrementally(dataManager.isProcessConstantsIncrementally()) - .withAffectionFilter(s -> moduleBasedFilter.accept(s.getPath().toFile())) - .withChunkStructureFilter(s -> moduleBasedFilter.belongsToCurrentTargetChunk(s.getPath().toFile())); + .withAffectionFilter(s -> moduleBasedFilter.accept(pathMapper.toPath(s).toFile())) + .withChunkStructureFilter(s -> moduleBasedFilter.belongsToCurrentTargetChunk(pathMapper.toPath(s).toFile())); DifferentiateParameters differentiateParams = params.get(); - DifferentiateResult diffResult = graph.differentiate(delta, differentiateParams); + DifferentiateResult diffResult = dependencyGraph.differentiate(delta, differentiateParams); final boolean compilingIncrementally = isCompileJavaIncrementally(context); if (diffResult.isIncremental()) { final Set affectedFiles = Iterators.collect( - Iterators.filter(Iterators.map(diffResult.getAffectedSources(), src -> src.getPath().toFile()), f -> skipMarkDirtyFilter == null || !skipMarkDirtyFilter.accept(f)), + Iterators.filter(Iterators.map(diffResult.getAffectedSources(), src -> pathMapper.toPath(src).toFile()), f -> skipMarkDirtyFilter == null || !skipMarkDirtyFilter.accept(f)), new HashSet<>() ); @@ -527,7 +530,7 @@ public final class JavaBuilderUtil { } if (performIntegrate) { - graph.integrate(diffResult); + dependencyGraph.integrate(diffResult); } return additionalPassRequired; diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/GraphConfiguration.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/GraphConfiguration.java new file mode 100644 index 000000000000..f2693364f8d3 --- /dev/null +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/GraphConfiguration.java @@ -0,0 +1,13 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.jps.dependency; + +import org.jetbrains.annotations.NotNull; + +public interface GraphConfiguration { + + @NotNull + NodeSourcePathMapper getPathMapper(); + + @NotNull + DependencyGraph getGraph(); +} diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/NodeSource.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/NodeSource.java index 8c575fd12ec9..dd1d1d077023 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/dependency/NodeSource.java +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/NodeSource.java @@ -1,16 +1,15 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.jps.dependency; -import java.nio.file.Path; - /** * Represents a source (normally a text file) from which one or more nodes were produced. * One source can be associated with several Nodes and a Node can be produced basing on several sources */ public interface NodeSource extends ExternalizableGraphElement { - Path getPath(); boolean equals(Object other); int hashCode(); + + String toString(); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/NodeSourcePathMapper.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/NodeSourcePathMapper.java new file mode 100644 index 000000000000..24373ce9de31 --- /dev/null +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/NodeSourcePathMapper.java @@ -0,0 +1,16 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.jps.dependency; + +import java.io.File; +import java.nio.file.Path; + +public interface NodeSourcePathMapper { + + NodeSource toNodeSource(File file); + + NodeSource toNodeSource(Path path); + + NodeSource toNodeSource(String path); + + Path toPath(NodeSource nodeSource); +} diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/FileSource.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/FileSource.java deleted file mode 100644 index f658dc698e02..000000000000 --- a/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/FileSource.java +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.jps.dependency.impl; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.dependency.GraphDataInput; -import org.jetbrains.jps.dependency.GraphDataOutput; -import org.jetbrains.jps.dependency.NodeSource; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - -public final class FileSource implements NodeSource { - - private final Path myPath; - - public FileSource(@NotNull File file) { - this(file.toPath()); - } - - public FileSource(@NotNull Path path) { - myPath = path; - } - - public FileSource(@NotNull GraphDataInput in) throws IOException { - myPath = Path.of(in.readUTF()); - } - - @Override - public void write(GraphDataOutput out) throws IOException { - out.writeUTF(myPath.toString()); - } - - @Override - public Path getPath() { - return myPath; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - final FileSource that = (FileSource)o; - - if (!myPath.equals(that.myPath)) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - return myPath.hashCode(); - } - - @Override - public String toString() { - return "NodeSource {" + myPath + "}"; - } -} diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/GraphImpl.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/GraphImpl.java index 8a05279a8698..6d28c1c3364f 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/GraphImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/GraphImpl.java @@ -25,7 +25,7 @@ abstract class GraphImpl implements Graph { addIndex(myDependencyIndex = new NodeDependenciesIndex(cFactory)); // important: if multiple implementations of NodeSource are available, change to generic graph element externalizer - Externalizer srcExternalizer = Externalizer.forGraphElement(FileSource::new); + Externalizer srcExternalizer = Externalizer.forGraphElement(PathSource::new); myNodeToSourcesMap = cFactory.createSetMultiMaplet("node-sources-map", Externalizer.forGraphElement(JvmNodeReferenceID::new), srcExternalizer); mySourceToNodesMap = cFactory.createSetMultiMaplet("source-nodes-map", srcExternalizer, Externalizer.forAnyGraphElement()); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/PathSource.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/PathSource.java new file mode 100644 index 000000000000..d835319ddc56 --- /dev/null +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/PathSource.java @@ -0,0 +1,62 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.jps.dependency.impl; + +import com.intellij.openapi.util.SystemInfoRt; +import com.intellij.openapi.util.text.StringUtilRt; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.dependency.GraphDataInput; +import org.jetbrains.jps.dependency.GraphDataOutput; +import org.jetbrains.jps.dependency.NodeSource; + +import java.io.File; +import java.io.IOException; + +public final class PathSource implements NodeSource { + + @NotNull + private final String myPath; + + public PathSource(@NotNull String path) { + myPath = File.separatorChar != '/'? path.replace(File.separatorChar, '/') : path; + } + + public PathSource(@NotNull GraphDataInput in) throws IOException { + myPath = in.readUTF(); + } + + @Override + public void write(GraphDataOutput out) throws IOException { + out.writeUTF(myPath); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final PathSource that = (PathSource)o; + + //noinspection StringEquality,SSBasedInspection + if (myPath == that.myPath) { + return true; + } + return SystemInfoRt.isFileSystemCaseSensitive? myPath.equals(that.myPath) : myPath.equalsIgnoreCase(that.myPath); + } + + @Override + public int hashCode() { + if (myPath.isEmpty()) { + return 0; + } + return SystemInfoRt.isFileSystemCaseSensitive? myPath.hashCode() : StringUtilRt.stringHashCodeInsensitive(myPath); + } + + @Override + public String toString() { + return myPath; + } +} diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/PathSourceMapper.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/PathSourceMapper.java new file mode 100644 index 000000000000..52c16e82616d --- /dev/null +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/impl/PathSourceMapper.java @@ -0,0 +1,48 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.jps.dependency.impl; + +import com.intellij.openapi.util.io.FileUtilRt; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.dependency.NodeSource; +import org.jetbrains.jps.dependency.NodeSourcePathMapper; + +import java.io.File; +import java.nio.file.Path; +import java.util.function.Function; + +public class PathSourceMapper implements NodeSourcePathMapper { + @NotNull + private final Function toFull; + @NotNull + private final Function toRelative; + + public PathSourceMapper() { + this(Function.identity(), Function.identity()); + } + + public PathSourceMapper(@NotNull Function toFull, @NotNull Function toRelative) { + this.toFull = toFull; + this.toRelative = toRelative; + } + + @Override + public NodeSource toNodeSource(File file) { + return toNodeSource(FileUtilRt.toCanonicalPath(file.getAbsolutePath(), File.separatorChar, true)); + } + + @Override + public NodeSource toNodeSource(Path path) { + return toNodeSource(FileUtilRt.toCanonicalPath(path.toString(), File.separatorChar, true)); + } + + @Override + public NodeSource toNodeSource(String path) { + return new PathSource(toRelative.apply(path)); + } + + @Override + public Path toPath(NodeSource nodeSource) { + return Path.of(toFull.apply(nodeSource.toString())); + } + +} diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/java/JavaDifferentiateStrategy.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/java/JavaDifferentiateStrategy.java index 0aef0954b5bb..0b4f4efd917c 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/dependency/java/JavaDifferentiateStrategy.java +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/java/JavaDifferentiateStrategy.java @@ -75,7 +75,7 @@ public class JavaDifferentiateStrategy extends JvmDifferentiateStrategyImpl { msg.append("Possibly duplicated classes in the same compilation chunk; Scheduling for recompilation sources: "); for (NodeSource candidate : candidates) { context.affectNodeSource(candidate); - msg.append(candidate.getPath()).append("; "); + msg.append(candidate).append("; "); } debug(msg.toString()); continue; // if duplicates are found, do not perform further checks for classes with the same short name @@ -630,7 +630,7 @@ public class JavaDifferentiateStrategy extends JvmDifferentiateStrategyImpl { }))) { if (future.isMethodVisible(outerClass, addedMethod) || future.inheritsFromLibraryClass(outerClass)) { for (NodeSource source : filter(sources, context.getParams().affectionFilter()::test)) { - debug("Affecting file due to local overriding: ", source.getPath()); + debug("Affecting file due to local overriding: ", source); context.affectNodeSource(source); } } @@ -972,7 +972,7 @@ public class JavaDifferentiateStrategy extends JvmDifferentiateStrategyImpl { for (NodeSource source : filter(context.getGraph().getSources(clsId), affectionFilter::test)) { if (forceAffect || !context.isCompiled(source) && !deletedSources.contains(source)) { context.affectNodeSource(source); - debug(affectReason, source.getPath()); + debug(affectReason, source); } } } @@ -981,7 +981,7 @@ public class JavaDifferentiateStrategy extends JvmDifferentiateStrategyImpl { debug("Affecting module ", mod.getName()); for (NodeSource source : utils.getNodeSources(mod.getReferenceID())) { context.affectNodeSource(source); - debug("Affected source ", source.getPath()); + debug("Affected source ", source); } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java index 814ec16daefd..b91b3b833522 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java @@ -22,6 +22,7 @@ import org.jetbrains.jps.dependency.*; import org.jetbrains.jps.dependency.impl.Containers; import org.jetbrains.jps.dependency.impl.DependencyGraphImpl; import org.jetbrains.jps.dependency.impl.LoggingDependencyGraph; +import org.jetbrains.jps.dependency.impl.PathSourceMapper; import org.jetbrains.jps.incremental.IncProjectBuilder; import org.jetbrains.jps.incremental.relativizer.PathRelativizerService; @@ -53,6 +54,7 @@ public final class BuildDataManager { private final Mappings myMappings; private final Object myGraphManagementLock = new Object(); private DependencyGraph myDepGraph; + private final NodeSourcePathMapper myDepGraphPathMapper; private final BuildDataPaths myDataPaths; private final BuildTargetsState myTargetsState; private final OutputToTargetRegistry myOutputToTargetRegistry; @@ -92,6 +94,7 @@ public final class BuildDataManager { myMappings.setProcessConstantsIncrementally(isProcessConstantsIncrementally()); } myVersionFile = new File(myDataPaths.getDataStorageRoot(), "version.dat"); + myDepGraphPathMapper = relativizer != null? new PathSourceMapper(relativizer::toFull, relativizer::toRelative) : new PathSourceMapper(); myRelativizer = relativizer; } @@ -137,9 +140,21 @@ public final class BuildDataManager { return myMappings; } - public DependencyGraph getDependencyGraph() { + @Nullable + public GraphConfiguration getDependencyGraph() { synchronized (myGraphManagementLock) { - return myDepGraph; + DependencyGraph depGraph = myDepGraph; + return depGraph == null? null : new GraphConfiguration() { + @Override + public @NotNull NodeSourcePathMapper getPathMapper() { + return myDepGraphPathMapper; + } + + @Override + public @NotNull DependencyGraph getGraph() { + return depGraph; + } + }; } } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/MockPackageFacadeBuilder.kt b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/MockPackageFacadeBuilder.kt index ea4098363107..6682fecc2f48 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/MockPackageFacadeBuilder.kt +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/MockPackageFacadeBuilder.kt @@ -15,7 +15,7 @@ import org.jetbrains.jps.ModuleChunk import org.jetbrains.jps.builders.DirtyFilesHolder import org.jetbrains.jps.builders.java.dependencyView.Mappings import org.jetbrains.jps.builders.storage.StorageProvider -import org.jetbrains.jps.dependency.DependencyGraph +import org.jetbrains.jps.dependency.GraphConfiguration import org.jetbrains.jps.dependency.java.JvmNodeReferenceID import org.jetbrains.jps.incremental.BuilderCategory import org.jetbrains.jps.incremental.CompileContext @@ -67,9 +67,12 @@ class MockPackageFacadeGenerator : ModuleLevelBuilder(BuilderCategory.SOURCE_PRO mappings.getClassSources(mappings.getName(qName)) } else { - val graph: DependencyGraph = context.projectDescriptor.dataManager.dependencyGraph val files = mutableListOf() - graph.getSources(JvmNodeReferenceID(qName)).forEach { files.add(it.path.toFile()) } + val graphConfig: GraphConfiguration? = context.projectDescriptor.dataManager.dependencyGraph + if (graphConfig != null) { + val mapper = graphConfig.pathMapper + graphConfig.graph.getSources(JvmNodeReferenceID(qName)).forEach { files.add(mapper.toPath(it).toFile()) } + } files } } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/dependency/NodeGraphPersistentTest.java b/jps/jps-builders/testSrc/org/jetbrains/jps/dependency/NodeGraphPersistentTest.java index aac97f163d22..a4463894c464 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/dependency/NodeGraphPersistentTest.java +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/dependency/NodeGraphPersistentTest.java @@ -7,7 +7,7 @@ import org.jetbrains.jps.dependency.diff.DiffCapable; import org.jetbrains.jps.dependency.impl.Containers; import org.jetbrains.jps.dependency.impl.DependencyGraphImpl; import org.jetbrains.jps.dependency.impl.DifferentiateParametersBuilder; -import org.jetbrains.jps.dependency.impl.FileSource; +import org.jetbrains.jps.dependency.impl.PathSource; import org.jetbrains.jps.dependency.java.JVMFlags; import org.jetbrains.jps.dependency.java.JvmClass; import org.jetbrains.jps.dependency.serializer.JvmClassTestUtil; @@ -21,10 +21,9 @@ public class NodeGraphPersistentTest extends BasePlatformTestCase { public void testPersistentNodeGraph() throws IOException { // Create and fill out the graph File tempDirectory = FileUtil.createTempDirectory("persistent", "map"); - DependencyGraphImpl graph = new DependencyGraphImpl(Containers.createPersistentContainerFactory(tempDirectory.getAbsolutePath())); - try { - FileSource aSrc = createNodeSource("A"); - FileSource bSrc = createNodeSource("B"); + try (DependencyGraphImpl graph = new DependencyGraphImpl(Containers.createPersistentContainerFactory(tempDirectory.getAbsolutePath()))) { + NodeSource aSrc = createNodeSource("A"); + NodeSource bSrc = createNodeSource("B"); // This should be executed before compiler run Delta delta = graph.createDelta(Arrays.asList(aSrc, bSrc), null); @@ -44,11 +43,10 @@ public class NodeGraphPersistentTest extends BasePlatformTestCase { JvmClass jvmClassFromGraph = graph.getNodes(nodeSourcesFromGraph.get(0), JvmClass.class).iterator().next(); JvmClass jvmClassFromGraphByDifferentSource = graph.getNodes(nodeSourcesFromGraph.get(1), JvmClass.class).iterator().next(); JvmClassTestUtil.checkJvmClassEquals(jvmClassFromGraph, jvmClassFromGraphByDifferentSource); - + JvmClassTestUtil.checkJvmClassEquals(jvmClassNode, jvmClassFromGraph); } finally { - graph.close(); FileUtil.delete(tempDirectory); } } @@ -56,10 +54,9 @@ public class NodeGraphPersistentTest extends BasePlatformTestCase { public void testIntegrateNodesWithSameID() throws IOException { // Create and fill out the graph File tempDirectory = FileUtil.createTempDirectory("persistent", "map"); - DependencyGraphImpl graph = new DependencyGraphImpl(Containers.createPersistentContainerFactory(tempDirectory.getAbsolutePath())); - try { - FileSource aSrc = createNodeSource("A"); - FileSource bSrc = createNodeSource("B"); + try (DependencyGraphImpl graph = new DependencyGraphImpl(Containers.createPersistentContainerFactory(tempDirectory.getAbsolutePath()))) { + NodeSource aSrc = createNodeSource("A"); + NodeSource bSrc = createNodeSource("B"); Delta initialDelta = graph.createDelta(Arrays.asList(aSrc, bSrc), null); JvmClass clsNodeA = new JvmClass(JVMFlags.EMPTY, "", "com.ppp.aClass", "out/modA/cls", "", "", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null, Collections.emptyList()); @@ -101,12 +98,11 @@ public class NodeGraphPersistentTest extends BasePlatformTestCase { assertTrue(nodesFromGraphAfterChange.contains(clsNodeB)); } finally { - graph.close(); FileUtil.delete(tempDirectory); } } - private static FileSource createNodeSource(String fileName) { - return new FileSource(new File("src/" + fileName + ".java")); + private static NodeSource createNodeSource(String fileName) { + return new PathSource("src/" + fileName + ".java"); } }