Skip to content

Commit

Permalink
#510 Opening multiple projects in a new window makes IDEA plug-in unr…
Browse files Browse the repository at this point in the history
…esponsive
  • Loading branch information
hsz committed Jan 11, 2018
1 parent 524c6f8 commit 2bf3686
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change Log
----------

### Unreleased

**Fixed bugs:**

- Opening multiple projects in a new window makes IDEA plug-in unresponsive [\#510](https://github.com/hsz/idea-gitignore/issues/510)


### [v2.3.2](https://github.com/hsz/idea-gitignore/tree/v2.3.2) (2017-11-17)

[Full Changelog](https://github.com/hsz/idea-gitignore/compare/v2.3.0...v2.3.2)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ Usage
Changelog
---------

### Unreleased

**Fixed bugs:**

- Opening multiple projects in a new window makes IDEA plug-in unresponsive [\#510](https://github.com/hsz/idea-gitignore/issues/510)


### [v2.3.2](https://github.com/hsz/idea-gitignore/tree/v2.3.2) (2017-11-17)

[Full Changelog](https://github.com/hsz/idea-gitignore/compare/v2.3.0...v2.3.2)
Expand Down
5 changes: 1 addition & 4 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@
<i>Fixed bugs:</i>
<ul>
<li>IDE Fatal Error: Accessing 'IgnoreFilesIndex' during processing 'FilenameIndex' (<a href="https://github.com/hsz/idea-gitignore/issues/480">480</a>)</li>
<li>ConcurrentModificationException in IgnoreSettings.notifyOnChange (<a href="https://github.com/hsz/idea-gitignore/issues/480">480</a>)</li>
<li>Missing/Wrong Key IGNORE.UNUSED_ENTRY in colour scheme (<a href="https://github.com/hsz/idea-gitignore/issues/494">494</a>)</li>
<li>It's prohibited to access index during event dispatching (<a href="https://github.com/hsz/idea-gitignore/issues/493">493</a>)</li>
<li>Opening multiple projects in a new window makes IDEA plug-in unresponsive (<a href="https://github.com/hsz/idea-gitignore/issues/510">510</a>)</li>
</ul>
<a href="https://github.com/hsz/idea-gitignore/blob/master/CHANGELOG.md"><b>Full Changelog History</b></a>
Expand Down
5 changes: 1 addition & 4 deletions resources/messages/IgnoreBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ notification.update.title=<b>.ignore</b> plugin updated to v{0}
notification.update.content=<br/>\
If you find my plugin helpful, <b><a href="https://www.paypal.me/hsz">Donate with PayPal</a></b><br/><br/>\
Fixes:<br/>\
- IDE Fatal Error: Accessing 'IgnoreFilesIndex' during processing 'FilenameIndex' (#480)<br/>\
- ConcurrentModificationException in IgnoreSettings.notifyOnChange (#480)<br/>\
- Missing/Wrong Key IGNORE.UNUSED_ENTRY in colour scheme (#494)<br/>\
- It's prohibited to access index during event dispatching (#493)<br/>\
- Opening multiple projects in a new window makes IDEA plug-in unresponsive (#510)<br/>\
<br/>\
If you find my plugin helpful, donate me using <br/><b><a href="https://www.paypal.me/hsz">Donate with PayPal</a></b>
29 changes: 25 additions & 4 deletions src/mobi/hsz/idea/gitignore/util/Glob.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher;
Expand All @@ -48,10 +49,10 @@
*/
public class Glob {
/** Cache map that holds processed regex statements to the glob rules. */
private static final WeakHashMap<String, String> GLOBS_CACHE = new WeakHashMap<String, String>();
private static final ConcurrentMap<String, String> GLOBS_CACHE = ContainerUtil.newConcurrentMap();

/** Cache map that holds compiled regex. */
private static final WeakHashMap<String, Pattern> PATTERNS_CACHE = new WeakHashMap<String, Pattern>();
private static final ConcurrentMap<String, WeakPattern> PATTERNS_CACHE = ContainerUtil.newConcurrentMap();

/** Private constructor to prevent creating {@link Glob} instance. */
private Glob() {
Expand Down Expand Up @@ -195,9 +196,9 @@ public static Pattern createPattern(@NotNull String rule,
final String regex = syntax.equals(IgnoreBundle.Syntax.GLOB) ? createRegex(rule, acceptChildren) : rule;
try {
if (!PATTERNS_CACHE.containsKey(regex)) {
PATTERNS_CACHE.put(regex, Pattern.compile(regex));
PATTERNS_CACHE.put(regex, new WeakPattern(Pattern.compile(regex)));
}
return PATTERNS_CACHE.get(regex);
return PATTERNS_CACHE.get(regex).get();
} catch (PatternSyntaxException e) {
return null;
}
Expand Down Expand Up @@ -390,4 +391,24 @@ public static void clearCache() {
GLOBS_CACHE.clear();
PATTERNS_CACHE.clear();
}

/** Weak reference to {@link Pattern}. */
private static final class WeakPattern extends WeakReference<Pattern> {
private int myHashCode;

WeakPattern(@NotNull Pattern referent) {
super(referent);
myHashCode = System.identityHashCode(referent);
}

@Override
public boolean equals(Object o) {
return this == o || (o instanceof WeakPattern && ((WeakPattern) o).get() == get());
}

@Override
public int hashCode() {
return myHashCode;
}
}
}

0 comments on commit 2bf3686

Please sign in to comment.