Skip to content

Commit

Permalink
Synchronize all access to libertyModules
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Gooderham <[email protected]>
  • Loading branch information
turkeylurkey committed Jan 13, 2025
1 parent 75d3bf7 commit f3f8f2d
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/main/java/io/openliberty/tools/intellij/LibertyModules.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ public synchronized static LibertyModules getInstance() {
* @param module LibertyModule
*/
public LibertyModule addLibertyModule(LibertyModule module) {
if (libertyModules.containsKey(module.getBuildFile())) {
// Update existing Liberty project, projectType module, name and validContainerVersion
// Do not update the build file (key), debugMode, shellWidget or customStartParams since
// they may modify saved run configs.
LibertyModule existing = libertyModules.get(module.getBuildFile());
existing.setProject(module.getProject());
existing.setProjectType(module.getProjectType());
existing.setName(module.getName());
existing.setValidContainerVersion(module.isValidContainerVersion());
} else {
libertyModules.put(module.getBuildFile(), module);
synchronized(libertyModules) {
if (libertyModules.containsKey(module.getBuildFile())) {
// Update existing Liberty project, projectType module, name and validContainerVersion
// Do not update the build file (key), debugMode, shellWidget or customStartParams since
// they may modify saved run configs.
LibertyModule existing = libertyModules.get(module.getBuildFile());
existing.setProject(module.getProject());
existing.setProjectType(module.getProjectType());
existing.setName(module.getName());
existing.setValidContainerVersion(module.isValidContainerVersion());
} else {
libertyModules.put(module.getBuildFile(), module);
}
return libertyModules.get(module.getBuildFile());
}
return libertyModules.get(module.getBuildFile());
}

/**
Expand All @@ -67,7 +69,9 @@ public LibertyModule addLibertyModule(LibertyModule module) {
* @return LibertyModule
*/
public LibertyModule getLibertyModule(VirtualFile buildFile) {
return libertyModules.get(buildFile);
synchronized(libertyModules) {
return libertyModules.get(buildFile);
}
}

/**
Expand All @@ -77,8 +81,10 @@ public LibertyModule getLibertyModule(VirtualFile buildFile) {
* @return LibertyModule
*/
public LibertyModule getLibertyProjectFromString(String buildFile) {
VirtualFile vBuildFile = VfsUtil.findFile(Paths.get(buildFile), true);
return libertyModules.get(vBuildFile);
synchronized(libertyModules) {
VirtualFile vBuildFile = VfsUtil.findFile(Paths.get(buildFile), true);
return libertyModules.get(vBuildFile);
}
}

/**
Expand Down Expand Up @@ -127,7 +133,9 @@ public List<LibertyModule> getLibertyModules(Project project, List<String> proje
* @param libertyModule
*/
public void removeLibertyModule(LibertyModule libertyModule) {
libertyModules.remove(libertyModule.getBuildFile());
synchronized(libertyModules) {
libertyModules.remove(libertyModule.getBuildFile());
}
}

/**
Expand Down

0 comments on commit f3f8f2d

Please sign in to comment.