Skip to content

Commit f9cd2db

Browse files
authored
Merge pull request #162 from xdev-software/develop
Release
2 parents 4f28d38 + a8ea0a7 commit f9cd2db

File tree

9 files changed

+64
-39
lines changed

9 files changed

+64
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.3.1
2+
* Fix IDE hang when projects with different "Process files asynchronously" are open #160
3+
14
## 1.3.0
25
* Make it possible to run processors asynchronously #130
36
* This way the UI should be more responsive when processing a lot of files

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'idea'
44
id 'checkstyle'
55
id 'pmd'
6-
id 'org.jetbrains.intellij.platform' version '2.0.1'
6+
id 'org.jetbrains.intellij.platform' version '2.1.0'
77
id 'org.sonarqube' version '5.1.0.4882'
88
}
99

@@ -58,7 +58,7 @@ dependencies {
5858
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
5959
pmd "net.sourceforge.pmd:pmd-ant:${pmdVersion}",
6060
"net.sourceforge.pmd:pmd-java:${pmdVersion}"
61-
testImplementation platform('org.junit:junit-bom:5.11.0'),
61+
testImplementation platform('org.junit:junit-bom:5.11.1'),
6262
'org.junit.jupiter:junit-jupiter',
6363
'org.junit.jupiter:junit-jupiter-engine',
6464
'org.assertj:assertj-core:3.26.3'

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/software/xdev/saveactions/core/component/Engine.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,25 @@ public void processPsiFilesIfNecessary(
7979
}
8080
if(!this.storage.isEnabled(this.activation))
8181
{
82-
LOGGER.info(String.format("Action \"%s\" not enabled on %s", this.activation.getText(), this.project));
82+
LOGGER.info(String.format(
83+
"Action \"%s\" not enabled on %s",
84+
this.activation.getText(),
85+
this.project.getName()));
8386
return;
8487
}
8588

8689
indicator.setIndeterminate(true);
8790
final Set<PsiFile> psiFilesEligible = this.getEligiblePsiFiles(indicator, async);
8891
if(psiFilesEligible.isEmpty())
8992
{
90-
LOGGER.info("No files are eligible");
93+
LOGGER.info("No files are eligible - " + this.project.getName());
9194
return;
9295
}
9396

9497
final List<SaveCommand> processorsEligible = this.getEligibleProcessors(indicator, psiFilesEligible);
9598
if(processorsEligible.isEmpty())
9699
{
97-
LOGGER.info("No processors are eligible");
100+
LOGGER.info("No processors are eligible - " + this.project.getName());
98101
return;
99102
}
100103

@@ -105,7 +108,7 @@ public void processPsiFilesIfNecessary(
105108

106109
private Set<PsiFile> getEligiblePsiFiles(final @NotNull ProgressIndicator indicator, final boolean async)
107110
{
108-
LOGGER.info(String.format("Processing %s files %s mode %s", this.project, this.psiFiles, this.mode));
111+
LOGGER.info(String.format("Processing %s files %s mode %s", this.project.getName(), this.psiFiles, this.mode));
109112
indicator.checkCanceled();
110113
indicator.setText2("Collecting files to process");
111114

@@ -124,7 +127,7 @@ private Set<PsiFile> getEligiblePsiFiles(final @NotNull ProgressIndicator indica
124127
final @NotNull ProgressIndicator indicator,
125128
final Set<PsiFile> psiFilesEligible)
126129
{
127-
LOGGER.info(String.format("Start processors (%d)", this.processors.size()));
130+
LOGGER.info(String.format("Start processors (%d) - %s", this.processors.size(), this.project.getName()));
128131
indicator.checkCanceled();
129132
indicator.setText2("Collecting processors");
130133

@@ -142,7 +145,7 @@ private void flushPsiFiles(
142145
final boolean async,
143146
final Set<PsiFile> psiFilesEligible)
144147
{
145-
LOGGER.info(String.format("Flushing files (%d)", psiFilesEligible.size()));
148+
LOGGER.info(String.format("Flushing files (%d) - %s", psiFilesEligible.size(), this.project.getName()));
146149
indicator.checkCanceled();
147150
indicator.setText2("Flushing files");
148151

@@ -176,7 +179,11 @@ private void execute(
176179
final AtomicInteger executedCount = new AtomicInteger();
177180
final List<SimpleEntry<Action, Result<ResultCode>>> results = saveCommands.stream()
178181
.map(command -> {
179-
LOGGER.info(String.format("Execute command %s on %d files", command, psiFilesEligible.size()));
182+
LOGGER.info(String.format(
183+
"Execute command %s on %d files - %s",
184+
command,
185+
psiFilesEligible.size(),
186+
this.project.getName()));
180187

181188
indicator.checkCanceled();
182189
indicator.setText2("Executing '" + command.getAction().getText() + "'");
@@ -189,9 +196,12 @@ private void execute(
189196
return entry;
190197
})
191198
.toList();
192-
LOGGER.info(String.format("Exit engine with results %s", results.stream()
193-
.map(entry -> entry.getKey() + ":" + entry.getValue())
194-
.toList()));
199+
LOGGER.info(String.format(
200+
"Exit engine with results %s - %s",
201+
results.stream()
202+
.map(entry -> entry.getKey() + ":" + entry.getValue())
203+
.toList(),
204+
this.project.getName()));
195205
}
196206

197207
private boolean isPsiFileEligible(final Project project, final PsiFile psiFile)
@@ -211,7 +221,7 @@ private boolean isProjectValid(final Project project)
211221
final boolean valid = project.isInitialized() && !project.isDisposed();
212222
if(!valid)
213223
{
214-
LOGGER.info("Project invalid. Either not initialized or disposed.");
224+
LOGGER.info(String.format("Project %s invalid. Either not initialized or disposed", project.getName()));
215225
}
216226
return valid;
217227
}
@@ -260,7 +270,7 @@ private boolean isPsiFileFresh(final PsiFile psiFile)
260270
final boolean isFresh = psiFile.getModificationStamp() != 0;
261271
if(!isFresh)
262272
{
263-
LOGGER.info(String.format("File %s is not fresh.", psiFile));
273+
LOGGER.info(String.format("File %s is not fresh", psiFile));
264274
}
265275
return isFresh;
266276
}
@@ -270,7 +280,7 @@ private boolean isPsiFileValid(final PsiFile psiFile)
270280
final boolean valid = psiFile.isValid();
271281
if(!valid)
272282
{
273-
LOGGER.info(String.format("File %s is not valid.", psiFile));
283+
LOGGER.info(String.format("File %s is not valid", psiFile));
274284
}
275285
return valid;
276286
}
@@ -280,7 +290,7 @@ private boolean hasPsiFileText(final PsiFile psiFile)
280290
final boolean valid = psiFile.getTextRange() != null;
281291
if(!valid)
282292
{
283-
LOGGER.info(String.format("File %s has no text.", psiFile));
293+
LOGGER.info(String.format("File %s has no text", psiFile));
284294
}
285295
return valid;
286296
}

src/main/java/software/xdev/saveactions/core/service/impl/AbstractSaveActionsService.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package software.xdev.saveactions.core.service.impl;
22

33
import static java.util.function.Function.identity;
4-
import static java.util.stream.Collectors.toList;
54
import static java.util.stream.Collectors.toMap;
65
import static software.xdev.saveactions.model.StorageFactory.JAVA;
76

87
import java.util.ArrayList;
98
import java.util.Arrays;
9+
import java.util.Collections;
1010
import java.util.List;
1111
import java.util.Map;
1212
import java.util.Objects;
1313
import java.util.Optional;
1414
import java.util.Set;
15+
import java.util.WeakHashMap;
1516
import java.util.concurrent.locks.ReentrantLock;
1617
import java.util.stream.Stream;
1718

@@ -59,7 +60,8 @@ abstract class AbstractSaveActionsService implements SaveActionsService
5960
private final boolean javaAvailable;
6061
private final boolean compilingAvailable;
6162

62-
private final ReentrantLock guardedProcessPsiFilesLock = new ReentrantLock();
63+
private final Map<Project, ReentrantLock> guardedProcessPsiFilesLocks =
64+
Collections.synchronizedMap(new WeakHashMap<>());
6365

6466
protected AbstractSaveActionsService(final StorageFactory storageFactory)
6567
{
@@ -100,20 +102,31 @@ public void guardedProcessPsiFiles(
100102
@Override
101103
public void run(@NotNull final ProgressIndicator indicator)
102104
{
103-
AbstractSaveActionsService.this.processPsiFilesIfNecessaryWithLock(engine, indicator);
105+
AbstractSaveActionsService.this.processPsiFilesIfNecessaryWithLock(project, engine, indicator);
104106
}
105107
}.queue();
106108
return;
107109
}
108110

109-
this.processPsiFilesIfNecessaryWithLock(engine, null);
111+
this.processPsiFilesIfNecessaryWithLock(project, engine, null);
110112
}
111113

112-
private void processPsiFilesIfNecessaryWithLock(final Engine engine, final ProgressIndicator indicator)
114+
private void processPsiFilesIfNecessaryWithLock(
115+
final Project project,
116+
final Engine engine,
117+
final ProgressIndicator indicator)
113118
{
114-
LOGGER.trace("Getting lock");
115-
this.guardedProcessPsiFilesLock.lock();
116-
LOGGER.trace("Got lock");
119+
if(LOGGER.isTraceEnabled())
120+
{
121+
LOGGER.trace("Getting lock - " + project.getName());
122+
}
123+
final ReentrantLock lock =
124+
this.guardedProcessPsiFilesLocks.computeIfAbsent(project, ignored -> new ReentrantLock());
125+
lock.lock();
126+
if(LOGGER.isTraceEnabled())
127+
{
128+
LOGGER.trace("Got lock - " + project.getName());
129+
}
117130
try
118131
{
119132
engine.processPsiFilesIfNecessary(
@@ -122,8 +135,11 @@ private void processPsiFilesIfNecessaryWithLock(final Engine engine, final Progr
122135
}
123136
finally
124137
{
125-
this.guardedProcessPsiFilesLock.unlock();
126-
LOGGER.trace("Released lock");
138+
lock.unlock();
139+
if(LOGGER.isTraceEnabled())
140+
{
141+
LOGGER.trace("Released lock - " + project.getName());
142+
}
127143
}
128144
}
129145

@@ -151,8 +167,8 @@ public List<QuickList> getQuickLists(final Project project)
151167
.map(Integer::valueOf)
152168
.map(quickListsIds::get)
153169
.filter(Objects::nonNull)
154-
.collect(toList()))
155-
.orElse(new ArrayList<>());
170+
.toList())
171+
.orElseGet(List::of);
156172
}
157173

158174
protected SaveActionsService addProcessors(final Stream<Processor> processors)

src/main/java/software/xdev/saveactions/core/service/impl/SaveActionsDefaultService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
*/
2222
public final class SaveActionsDefaultService extends AbstractSaveActionsService
2323
{
24-
2524
public SaveActionsDefaultService()
2625
{
2726
super(DEFAULT);
28-
addProcessors(BuildProcessor.stream());
29-
addProcessors(GlobalProcessor.stream());
27+
this.addProcessors(BuildProcessor.stream());
28+
this.addProcessors(GlobalProcessor.stream());
3029
}
3130
}

src/main/java/software/xdev/saveactions/core/service/impl/SaveActionsJavaService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
*/
2323
public final class SaveActionsJavaService extends AbstractSaveActionsService
2424
{
25-
2625
public SaveActionsJavaService()
2726
{
2827
super(JAVA);
29-
addProcessors(BuildProcessor.stream());
30-
addProcessors(GlobalProcessor.stream());
31-
addProcessors(JavaProcessor.stream());
28+
this.addProcessors(BuildProcessor.stream());
29+
this.addProcessors(GlobalProcessor.stream());
30+
this.addProcessors(JavaProcessor.stream());
3231
}
3332
}

src/main/java/software/xdev/saveactions/processors/java/InspectionRunnable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class InspectionRunnable implements Runnable
4040
this.project = project;
4141
this.psiFiles = psiFiles;
4242
this.toolWrapper = new LocalInspectionToolWrapper(inspectionTool);
43-
LOGGER.info(String.format("Running inspection for %s", inspectionTool.getShortName()));
43+
LOGGER.info(String.format("Running inspection for %s - %s", inspectionTool.getShortName(), project.getName()));
4444
}
4545

4646
@Override

src/main/java/software/xdev/saveactions/processors/java/inspection/CustomSerializableHasSerialVersionUidFieldInspection.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ public CustomSerializableHasSerialVersionUidFieldInspection()
3636
@Override
3737
public @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String getDisplayName()
3838
{
39-
4039
return this.getClass().getSimpleName();
4140
}
4241

4342
@Override
4443
public @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String getGroupDisplayName()
4544
{
46-
4745
return "SaveActionsInternal";
4846
}
4947

0 commit comments

Comments
 (0)