From 8f81165d2098e92d839c2e225715641b3e10c3ba Mon Sep 17 00:00:00 2001 From: Kaiyao Ke Date: Wed, 20 Sep 2023 22:20:47 -0500 Subject: [PATCH 1/4] fixed order dependency in excluded group Signed-off-by: K Ke \ kaiyaok2@illinois.edu Helped-by: K Ke \ kaiyaok2@illinois.edu Signed-off-by: Kaiyao Ke --- .../org/gradle/api/tasks/util/internal/PatternSpecFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java b/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java index 4be458c83554..3ca4c537a838 100644 --- a/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java +++ b/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java @@ -34,6 +34,7 @@ import java.util.Collection; import java.util.Comparator; import java.util.EnumMap; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -99,7 +100,7 @@ private synchronized Spec getDefaultExcludeSpec(CaseSensitivity } private boolean invalidChangeOfExcludes(String[] defaultExcludes) { - return !Arrays.equals(previousDefaultExcludes, defaultExcludes); + return !(new HashSet(Arrays.asList(previousDefaultExcludes))).equals(new HashSet(Arrays.asList(defaultExcludes))); } private void failOnChangedDefaultExcludes(String[] excludesFromSettings, String[] newDefaultExcludes) { From b0c7f87ae1465311bd61d54274b6ccb97b19928a Mon Sep 17 00:00:00 2001 From: Kaiyao Ke Date: Thu, 23 Nov 2023 17:03:28 -0600 Subject: [PATCH 2/4] changed defaultExcludes and previousDefaultExcludes to HashSet Signed-off-by: Kaiyao Ke --- .../util/internal/PatternSpecFactory.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java b/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java index 3ca4c537a838..28962b617290 100644 --- a/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java +++ b/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java @@ -37,6 +37,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; /** * The basic implementation for converting {@link PatternSet}s to {@link Spec}s. @@ -47,12 +48,12 @@ @ServiceScope(Scope.Global.class) public class PatternSpecFactory implements FileSystemDefaultExcludesListener { public static final PatternSpecFactory INSTANCE = new PatternSpecFactory(); - private String[] previousDefaultExcludes; + private Set previousDefaultExcludes; private final Map> defaultExcludeSpecCache = new EnumMap<>(CaseSensitivity.class); @Override public void onDefaultExcludesChanged(List excludes) { - setDefaultExcludesFromSettings(excludes.toArray(new String[0])); + setDefaultExcludesFromSettings(new HashSet(excludes)); } public Spec createSpec(PatternSet patternSet) { @@ -89,7 +90,7 @@ public Spec createExcludeSpec(PatternSet patternSet) { } private synchronized Spec getDefaultExcludeSpec(CaseSensitivity caseSensitivity) { - String[] defaultExcludes = DirectoryScanner.getDefaultExcludes(); + Set defaultExcludes = new HashSet(Arrays.asList(DirectoryScanner.getDefaultExcludes())); if (defaultExcludeSpecCache.isEmpty()) { updateDefaultExcludeSpecCache(defaultExcludes); } else if (invalidChangeOfExcludes(defaultExcludes)) { @@ -99,27 +100,27 @@ private synchronized Spec getDefaultExcludeSpec(CaseSensitivity return defaultExcludeSpecCache.get(caseSensitivity); } - private boolean invalidChangeOfExcludes(String[] defaultExcludes) { - return !(new HashSet(Arrays.asList(previousDefaultExcludes))).equals(new HashSet(Arrays.asList(defaultExcludes))); + private boolean invalidChangeOfExcludes(Set defaultExcludes) { + return !previousDefaultExcludes.equals(defaultExcludes); } - private void failOnChangedDefaultExcludes(String[] excludesFromSettings, String[] newDefaultExcludes) { - List sortedExcludesFromSettings = Arrays.asList(excludesFromSettings); + private void failOnChangedDefaultExcludes(Set excludesFromSettings, Set newDefaultExcludes) { + List sortedExcludesFromSettings = new ArrayList(excludesFromSettings); sortedExcludesFromSettings.sort(Comparator.naturalOrder()); - List sortedNewExcludes = Arrays.asList(newDefaultExcludes); + List sortedNewExcludes = new ArrayList(newDefaultExcludes); sortedNewExcludes.sort(Comparator.naturalOrder()); throw new InvalidUserCodeException(String.format("Cannot change default excludes during the build. They were changed from %s to %s. Configure default excludes in the settings script instead.", sortedExcludesFromSettings, sortedNewExcludes)); } - public synchronized void setDefaultExcludesFromSettings(String[] excludesFromSettings) { - if (!Arrays.equals(previousDefaultExcludes, excludesFromSettings)) { + public synchronized void setDefaultExcludesFromSettings(Set excludesFromSettings) { + if (!previousDefaultExcludes.equals(excludesFromSettings)) { updateDefaultExcludeSpecCache(excludesFromSettings); } } - private void updateDefaultExcludeSpecCache(String[] defaultExcludes) { + private void updateDefaultExcludeSpecCache(Set defaultExcludes) { previousDefaultExcludes = defaultExcludes; - List patterns = Arrays.asList(defaultExcludes); + List patterns = new ArrayList(defaultExcludes); for (CaseSensitivity caseSensitivity : CaseSensitivity.values()) { defaultExcludeSpecCache.put(caseSensitivity, createSpec(patterns, false, caseSensitivity.isCaseSensitive())); } From 561ea628f02dacf4796309a11d578b2c18c110a2 Mon Sep 17 00:00:00 2001 From: Kaiyao Ke Date: Thu, 23 Nov 2023 18:34:37 -0600 Subject: [PATCH 3/4] suppressed warnings Signed-off-by: Kaiyao Ke --- .../api/tasks/util/internal/PatternSpecFactory.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java b/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java index 28962b617290..f97e90dacaac 100644 --- a/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java +++ b/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java @@ -48,12 +48,12 @@ @ServiceScope(Scope.Global.class) public class PatternSpecFactory implements FileSystemDefaultExcludesListener { public static final PatternSpecFactory INSTANCE = new PatternSpecFactory(); - private Set previousDefaultExcludes; + private Set previousDefaultExcludes = new HashSet(); private final Map> defaultExcludeSpecCache = new EnumMap<>(CaseSensitivity.class); @Override public void onDefaultExcludesChanged(List excludes) { - setDefaultExcludesFromSettings(new HashSet(excludes)); + setDefaultExcludesFromSettings(excludes.toArray(new String[0])); } public Spec createSpec(PatternSet patternSet) { @@ -89,6 +89,7 @@ public Spec createExcludeSpec(PatternSet patternSet) { } } + @SuppressWarnings("unchecked") private synchronized Spec getDefaultExcludeSpec(CaseSensitivity caseSensitivity) { Set defaultExcludes = new HashSet(Arrays.asList(DirectoryScanner.getDefaultExcludes())); if (defaultExcludeSpecCache.isEmpty()) { @@ -112,9 +113,11 @@ private void failOnChangedDefaultExcludes(Set excludesFromSettings, Set< throw new InvalidUserCodeException(String.format("Cannot change default excludes during the build. They were changed from %s to %s. Configure default excludes in the settings script instead.", sortedExcludesFromSettings, sortedNewExcludes)); } - public synchronized void setDefaultExcludesFromSettings(Set excludesFromSettings) { - if (!previousDefaultExcludes.equals(excludesFromSettings)) { - updateDefaultExcludeSpecCache(excludesFromSettings); + @SuppressWarnings("unchecked") + public synchronized void setDefaultExcludesFromSettings(String[] excludesFromSettings) { + Set excludesFromSettingsSet = new HashSet(Arrays.asList(excludesFromSettings)); + if (!previousDefaultExcludes.equals(excludesFromSettingsSet)) { + updateDefaultExcludeSpecCache(excludesFromSettingsSet); } } From c6e9e4aa886f09961a7fa8a5449b15b385ac96fb Mon Sep 17 00:00:00 2001 From: Kaiyao Ke Date: Fri, 24 Nov 2023 18:44:00 -0600 Subject: [PATCH 4/4] removed redundant casting Signed-off-by: Kaiyao Ke --- .../api/tasks/util/internal/PatternSpecFactory.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java b/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java index f97e90dacaac..08bdeca6947a 100644 --- a/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java +++ b/subprojects/core-api/src/main/java/org/gradle/api/tasks/util/internal/PatternSpecFactory.java @@ -89,9 +89,8 @@ public Spec createExcludeSpec(PatternSet patternSet) { } } - @SuppressWarnings("unchecked") private synchronized Spec getDefaultExcludeSpec(CaseSensitivity caseSensitivity) { - Set defaultExcludes = new HashSet(Arrays.asList(DirectoryScanner.getDefaultExcludes())); + Set defaultExcludes = new HashSet(Arrays.asList(DirectoryScanner.getDefaultExcludes())); if (defaultExcludeSpecCache.isEmpty()) { updateDefaultExcludeSpecCache(defaultExcludes); } else if (invalidChangeOfExcludes(defaultExcludes)) { @@ -113,9 +112,8 @@ private void failOnChangedDefaultExcludes(Set excludesFromSettings, Set< throw new InvalidUserCodeException(String.format("Cannot change default excludes during the build. They were changed from %s to %s. Configure default excludes in the settings script instead.", sortedExcludesFromSettings, sortedNewExcludes)); } - @SuppressWarnings("unchecked") public synchronized void setDefaultExcludesFromSettings(String[] excludesFromSettings) { - Set excludesFromSettingsSet = new HashSet(Arrays.asList(excludesFromSettings)); + Set excludesFromSettingsSet = new HashSet(Arrays.asList(excludesFromSettings)); if (!previousDefaultExcludes.equals(excludesFromSettingsSet)) { updateDefaultExcludeSpecCache(excludesFromSettingsSet); } @@ -123,9 +121,8 @@ public synchronized void setDefaultExcludesFromSettings(String[] excludesFromSet private void updateDefaultExcludeSpecCache(Set defaultExcludes) { previousDefaultExcludes = defaultExcludes; - List patterns = new ArrayList(defaultExcludes); for (CaseSensitivity caseSensitivity : CaseSensitivity.values()) { - defaultExcludeSpecCache.put(caseSensitivity, createSpec(patterns, false, caseSensitivity.isCaseSensitive())); + defaultExcludeSpecCache.put(caseSensitivity, createSpec(defaultExcludes, false, caseSensitivity.isCaseSensitive())); } }