mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
close already created storages if exception occurred on initialization
GitOrigin-RevId: 73583d785452ba36f2180c80f726534fdbcbadf2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9fc76882e9
commit
71b175792f
@@ -44,7 +44,6 @@ public class Mappings {
|
||||
private static final String IMPORT_WILDCARD_SUFFIX = ".*";
|
||||
|
||||
private final boolean myIsDelta;
|
||||
private final boolean myDeltaIsTransient;
|
||||
private boolean myIsDifferentiated = false;
|
||||
private boolean myIsRebuild = false;
|
||||
|
||||
@@ -94,7 +93,6 @@ public class Mappings {
|
||||
myChangedFiles = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
|
||||
myDeletedClasses = new HashSet<>(DEFAULT_SET_CAPACITY, DEFAULT_SET_LOAD_FACTOR);
|
||||
myAddedClasses = new HashSet<>(DEFAULT_SET_CAPACITY, DEFAULT_SET_LOAD_FACTOR);
|
||||
myDeltaIsTransient = base.myDeltaIsTransient;
|
||||
myRootDir = new File(FileUtil.toSystemIndependentName(base.myRootDir.getAbsolutePath()) + File.separatorChar + "myDelta");
|
||||
myContext = base.myContext;
|
||||
myInitName = myContext.get("<init>");
|
||||
@@ -105,14 +103,13 @@ public class Mappings {
|
||||
createImplementation();
|
||||
}
|
||||
|
||||
public Mappings(final File rootDir, PathRelativizerService relativizer, final boolean transientDelta) throws IOException {
|
||||
public Mappings(final File rootDir, PathRelativizerService relativizer) throws IOException {
|
||||
myLock = new Object();
|
||||
myIsDelta = false;
|
||||
myChangedClasses = null;
|
||||
myChangedFiles = null;
|
||||
myDeletedClasses = null;
|
||||
myAddedClasses = null;
|
||||
myDeltaIsTransient = transientDelta;
|
||||
myRootDir = rootDir;
|
||||
myRelativizer = relativizer;
|
||||
createImplementation();
|
||||
@@ -122,51 +119,62 @@ public class Mappings {
|
||||
}
|
||||
|
||||
private void createImplementation() throws IOException {
|
||||
if (!myIsDelta) {
|
||||
myContext = new DependencyContext(myRootDir, myRelativizer);
|
||||
myDebugS = myContext.getLogger(LOG);
|
||||
}
|
||||
|
||||
myRemovedSuperClasses = myIsDelta ? new IntIntTransientMultiMaplet() : null;
|
||||
myAddedSuperClasses = myIsDelta ? new IntIntTransientMultiMaplet() : null;
|
||||
|
||||
final CollectionFactory<String> fileCollectionFactory = new CollectionFactory<String>() {
|
||||
@Override
|
||||
public Collection<String> create() {
|
||||
return new THashSet<>(FileUtil.PATH_HASHING_STRATEGY); // todo: do we really need set and not a list here?
|
||||
try {
|
||||
if (!myIsDelta) {
|
||||
myContext = new DependencyContext(myRootDir, myRelativizer);
|
||||
myDebugS = myContext.getLogger(LOG);
|
||||
}
|
||||
};
|
||||
if (myIsDelta && myDeltaIsTransient) {
|
||||
myClassToSubclasses = new IntIntTransientMultiMaplet();
|
||||
myClassToClassDependency = new IntIntTransientMultiMaplet();
|
||||
myShortClassNameIndex = null;
|
||||
myRelativeSourceFilePathToClasses = new ObjectObjectTransientMultiMaplet<>(FileUtil.PATH_HASHING_STRATEGY, () -> new THashSet<>(5, DEFAULT_SET_LOAD_FACTOR));
|
||||
myClassToRelativeSourceFilePath = new IntObjectTransientMultiMaplet<>(fileCollectionFactory);
|
||||
}
|
||||
else {
|
||||
if (myIsDelta) {
|
||||
myRootDir.mkdirs();
|
||||
}
|
||||
myClassToSubclasses = new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_SUBCLASSES),
|
||||
EnumeratorIntegerDescriptor.INSTANCE);
|
||||
myClassToClassDependency = new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_CLASS),
|
||||
EnumeratorIntegerDescriptor.INSTANCE);
|
||||
myShortClassNameIndex = myIsDelta? null : new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, SHORT_NAMES),
|
||||
EnumeratorIntegerDescriptor.INSTANCE);
|
||||
myRelativeSourceFilePathToClasses = new ObjectObjectPersistentMultiMaplet<String, ClassFileRepr>(
|
||||
DependencyContext.getTableFile(myRootDir, SOURCE_TO_CLASS), PathStringDescriptor.INSTANCE, new ClassFileReprExternalizer(myContext),
|
||||
() -> new THashSet<>(5, DEFAULT_SET_LOAD_FACTOR)
|
||||
) {
|
||||
@NotNull
|
||||
|
||||
myRemovedSuperClasses = myIsDelta ? new IntIntTransientMultiMaplet() : null;
|
||||
myAddedSuperClasses = myIsDelta ? new IntIntTransientMultiMaplet() : null;
|
||||
|
||||
final CollectionFactory<String> fileCollectionFactory = new CollectionFactory<String>() {
|
||||
@Override
|
||||
protected String debugString(String path) {
|
||||
// on case-insensitive file systems save paths in normalized (lowercase) format in order to make tests run deterministically
|
||||
return SystemInfo.isFileSystemCaseSensitive ? path : path.toLowerCase(Locale.US);
|
||||
public Collection<String> create() {
|
||||
return new THashSet<>(FileUtil.PATH_HASHING_STRATEGY); // todo: do we really need set and not a list here?
|
||||
}
|
||||
};
|
||||
myClassToRelativeSourceFilePath = new IntObjectPersistentMultiMaplet<>(
|
||||
DependencyContext.getTableFile(myRootDir, CLASS_TO_SOURCE), EnumeratorIntegerDescriptor.INSTANCE, PathStringDescriptor.INSTANCE, fileCollectionFactory
|
||||
);
|
||||
if (myIsDelta) {
|
||||
myClassToSubclasses = new IntIntTransientMultiMaplet();
|
||||
myClassToClassDependency = new IntIntTransientMultiMaplet();
|
||||
myShortClassNameIndex = null;
|
||||
myRelativeSourceFilePathToClasses = new ObjectObjectTransientMultiMaplet<>(FileUtil.PATH_HASHING_STRATEGY, () -> new THashSet<>(5, DEFAULT_SET_LOAD_FACTOR));
|
||||
myClassToRelativeSourceFilePath = new IntObjectTransientMultiMaplet<>(fileCollectionFactory);
|
||||
}
|
||||
else {
|
||||
if (myIsDelta) {
|
||||
myRootDir.mkdirs();
|
||||
}
|
||||
myClassToSubclasses = new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_SUBCLASSES),
|
||||
EnumeratorIntegerDescriptor.INSTANCE);
|
||||
myClassToClassDependency = new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_CLASS),
|
||||
EnumeratorIntegerDescriptor.INSTANCE);
|
||||
myShortClassNameIndex = myIsDelta? null : new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, SHORT_NAMES),
|
||||
EnumeratorIntegerDescriptor.INSTANCE);
|
||||
myRelativeSourceFilePathToClasses = new ObjectObjectPersistentMultiMaplet<String, ClassFileRepr>(
|
||||
DependencyContext.getTableFile(myRootDir, SOURCE_TO_CLASS), PathStringDescriptor.INSTANCE, new ClassFileReprExternalizer(myContext),
|
||||
() -> new THashSet<>(5, DEFAULT_SET_LOAD_FACTOR)
|
||||
) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String debugString(String path) {
|
||||
// on case-insensitive file systems save paths in normalized (lowercase) format in order to make tests run deterministically
|
||||
return SystemInfo.isFileSystemCaseSensitive ? path : path.toLowerCase(Locale.US);
|
||||
}
|
||||
};
|
||||
myClassToRelativeSourceFilePath = new IntObjectPersistentMultiMaplet<>(
|
||||
DependencyContext.getTableFile(myRootDir, CLASS_TO_SOURCE), EnumeratorIntegerDescriptor.INSTANCE, PathStringDescriptor.INSTANCE, fileCollectionFactory
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
try {
|
||||
// ensure already initialized maps are properly closed
|
||||
close();
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2956,26 +2964,39 @@ public class Mappings {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
BuildDataCorruptedException error = null;
|
||||
synchronized (myLock) {
|
||||
myClassToSubclasses.close();
|
||||
myClassToClassDependency.close();
|
||||
myRelativeSourceFilePathToClasses.close();
|
||||
myClassToRelativeSourceFilePath.close();
|
||||
for (CloseableMaplet maplet : Arrays.asList(myClassToSubclasses, myClassToClassDependency, myRelativeSourceFilePathToClasses, myClassToRelativeSourceFilePath, myShortClassNameIndex)) {
|
||||
if (maplet != null) {
|
||||
try {
|
||||
maplet.close();
|
||||
}
|
||||
catch (BuildDataCorruptedException ex) {
|
||||
if (error == null) {
|
||||
error = ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!myIsDelta) {
|
||||
myShortClassNameIndex.close();
|
||||
// only close if you own the context
|
||||
final DependencyContext context = myContext;
|
||||
if (context != null) {
|
||||
context.close();
|
||||
try {
|
||||
context.close();
|
||||
}
|
||||
catch (BuildDataCorruptedException ex) {
|
||||
if (error == null) {
|
||||
error = ex;
|
||||
}
|
||||
}
|
||||
myContext = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!myDeltaIsTransient) {
|
||||
FileUtil.delete(myRootDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,10 @@ import org.jetbrains.jps.incremental.fs.BuildFSState;
|
||||
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
||||
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||
import org.jetbrains.jps.incremental.relativizer.PathRelativizerService;
|
||||
import org.jetbrains.jps.incremental.storage.*;
|
||||
import org.jetbrains.jps.incremental.storage.BuildDataManager;
|
||||
import org.jetbrains.jps.incremental.storage.BuildTargetsState;
|
||||
import org.jetbrains.jps.incremental.storage.ProjectTimestamps;
|
||||
import org.jetbrains.jps.incremental.storage.StampsStorage;
|
||||
import org.jetbrains.jps.indices.ModuleExcludeIndex;
|
||||
import org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl;
|
||||
import org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl;
|
||||
@@ -56,7 +59,6 @@ public class BuildRunner {
|
||||
private static final Logger LOG = Logger.getInstance(BuildRunner.class);
|
||||
public static final boolean PARALLEL_BUILD_ENABLED = Boolean.parseBoolean(System.getProperty(GlobalOptions.COMPILE_PARALLEL_OPTION, "false"));
|
||||
public static final boolean PARALLEL_BUILD_AUTOMAKE_ENABLED = PARALLEL_BUILD_ENABLED && Boolean.parseBoolean(System.getProperty(GlobalOptions.ALLOW_PARALLEL_AUTOMAKE_OPTION, "true"));
|
||||
private static final boolean STORE_TEMP_CACHES_IN_MEMORY = true;
|
||||
private final JpsModelLoader myModelLoader;
|
||||
private List<String> myFilePaths = Collections.emptyList();
|
||||
private Map<String, String> myBuilderParams = Collections.emptyMap();
|
||||
@@ -90,7 +92,7 @@ public class BuildRunner {
|
||||
BuildDataManager dataManager = null;
|
||||
try {
|
||||
projectStamps = new ProjectTimestamps(dataStorageRoot, targetsState, relativizer);
|
||||
dataManager = new BuildDataManager(dataPaths, targetsState, relativizer, STORE_TEMP_CACHES_IN_MEMORY);
|
||||
dataManager = new BuildDataManager(dataPaths, targetsState, relativizer);
|
||||
if (dataManager.versionDiffers()) {
|
||||
myForceCleanCaches = true;
|
||||
msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Dependency data format has changed, project rebuild required"));
|
||||
@@ -109,7 +111,7 @@ public class BuildRunner {
|
||||
FileUtil.delete(dataStorageRoot);
|
||||
targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
|
||||
projectStamps = new ProjectTimestamps(dataStorageRoot, targetsState, relativizer);
|
||||
dataManager = new BuildDataManager(dataPaths, targetsState, relativizer, STORE_TEMP_CACHES_IN_MEMORY);
|
||||
dataManager = new BuildDataManager(dataPaths, targetsState, relativizer);
|
||||
// second attempt succeeded
|
||||
msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Project rebuild forced: " + e.getMessage()));
|
||||
}
|
||||
|
||||
@@ -114,15 +114,12 @@ public class BuildDataManager implements StorageOwner {
|
||||
}
|
||||
};
|
||||
|
||||
public BuildDataManager(BuildDataPaths dataPaths,
|
||||
BuildTargetsState targetsState,
|
||||
PathRelativizerService relativizer,
|
||||
boolean useMemoryTempCaches) throws IOException {
|
||||
public BuildDataManager(BuildDataPaths dataPaths, BuildTargetsState targetsState, PathRelativizerService relativizer) throws IOException {
|
||||
myDataPaths = dataPaths;
|
||||
myTargetsState = targetsState;
|
||||
mySrcToFormMap = new OneToManyPathsMapping(new File(getSourceToFormsRoot(), "data"), relativizer);
|
||||
myOutputToTargetRegistry = new OutputToTargetRegistry(new File(getOutputToSourceRegistryRoot(), "data"), relativizer);
|
||||
myMappings = new Mappings(getMappingsRoot(myDataPaths.getDataStorageRoot()), relativizer, useMemoryTempCaches);
|
||||
myMappings = new Mappings(getMappingsRoot(myDataPaths.getDataStorageRoot()), relativizer);
|
||||
myVersionFile = new File(myDataPaths.getDataStorageRoot(), "version.dat");
|
||||
myRelativizer = relativizer;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class StorageDumper {
|
||||
final File parent = new File(oath == null ? "" : oath);
|
||||
final File dataStorageRoot = new File(dataPath, "mappings");
|
||||
|
||||
final Mappings mappings = new Mappings(dataStorageRoot, new PathRelativizerService(), true);
|
||||
final Mappings mappings = new Mappings(dataStorageRoot, new PathRelativizerService());
|
||||
try {
|
||||
//final File outputPath = new File(parent, "snapshot-" + new SimpleDateFormat("dd-MM-yy(hh-mm-ss)").format(new Date()) + ".log");
|
||||
//FileUtil.createIfDoesntExist(outputPath);
|
||||
|
||||
@@ -26,10 +26,9 @@ import org.jetbrains.jps.incremental.FSOperations;
|
||||
import org.jetbrains.jps.incremental.IncProjectBuilder;
|
||||
import org.jetbrains.jps.incremental.RebuildRequestedException;
|
||||
import org.jetbrains.jps.incremental.fs.BuildFSState;
|
||||
import org.jetbrains.jps.incremental.storage.BuildDataManager;
|
||||
import org.jetbrains.jps.incremental.storage.BuildTargetSourcesState;
|
||||
import org.jetbrains.jps.incremental.storage.BuildTargetsState;
|
||||
import org.jetbrains.jps.incremental.relativizer.PathRelativizerService;
|
||||
import org.jetbrains.jps.incremental.storage.BuildDataManager;
|
||||
import org.jetbrains.jps.incremental.storage.BuildTargetsState;
|
||||
import org.jetbrains.jps.incremental.storage.ProjectTimestamps;
|
||||
import org.jetbrains.jps.indices.ModuleExcludeIndex;
|
||||
import org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl;
|
||||
@@ -210,7 +209,7 @@ public abstract class JpsBuildTestCase extends UsefulTestCase {
|
||||
BuildTargetsState targetsState = new BuildTargetsState(dataPaths, myModel, buildRootIndex);
|
||||
PathRelativizerService relativizer = new PathRelativizerService(myModel.getProject(), dataPaths.getDataStorageRoot());
|
||||
ProjectTimestamps timestamps = new ProjectTimestamps(myDataStorageRoot, targetsState, relativizer);
|
||||
BuildDataManager dataManager = new BuildDataManager(dataPaths, targetsState, relativizer, true);
|
||||
BuildDataManager dataManager = new BuildDataManager(dataPaths, targetsState, relativizer);
|
||||
return new ProjectDescriptor(myModel, new BuildFSState(true), timestamps, dataManager, buildLoggingManager, index, targetsState,
|
||||
targetIndex, buildRootIndex, ignoredFileIndex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user