This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new dd6be41a3f Gradle hide empty generated folders (#4525)
dd6be41a3f is described below
commit dd6be41a3f8bd48ccdf812838407300409286d6b
Author: Laszlo Kishalmi <[email protected]>
AuthorDate: Sat Sep 3 16:04:50 2022 -0700
Gradle hide empty generated folders (#4525)
* Fix Gradle resourche watchers not attached on project open
* Hide empty generated source dirs
* Move the SourceGroup filtering to the UI
---
.../modules/gradle/api/NbGradleProject.java | 52 +++++++++++++---------
.../execute/GradleDistributionProviderImpl.java | 2 +-
.../java/classpath/ClassPathProviderImpl.java | 2 +-
.../gradle/java/classpath/GradleSourcesImpl.java | 1 -
.../gradle/java/nodes/SourcesNodeFactory.java | 28 +++++++++++-
5 files changed, 59 insertions(+), 26 deletions(-)
diff --git
a/extide/gradle/src/org/netbeans/modules/gradle/api/NbGradleProject.java
b/extide/gradle/src/org/netbeans/modules/gradle/api/NbGradleProject.java
index fc592b5e5d..08314942ae 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/api/NbGradleProject.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/api/NbGradleProject.java
@@ -31,6 +31,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
+import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.swing.Icon;
import javax.swing.ImageIcon;
@@ -58,6 +59,8 @@ import org.openide.util.Utilities;
*/
public final class NbGradleProject {
+ static final Logger LOG =
Logger.getLogger(NbGradleProject.class.getName());
+
/**
* As loading a Gradle project information into the memory could be a time
* consuming task each the Gradle Plugin uses heuristics and offline
@@ -170,7 +173,7 @@ public final class NbGradleProject {
@Override
public void activate(NbGradleProject watcher) {
- watcher.attachResourceWatchers();
+ watcher.attachResourceWatchers(true);
}
@Override
@@ -268,34 +271,41 @@ public final class NbGradleProject {
private void doFireReload() {
detachResourceWatchers();
support.firePropertyChange(PROP_PROJECT_INFO, null, null);
- attachResourceWatchers();
+ attachResourceWatchers(false);
}
private void detachResourceWatchers() {
- for (File resource : resources) {
- try {
- FileUtil.removeFileChangeListener(FCHSL, resource);
- } catch (IllegalArgumentException ex) {
- assert false : "Something is wrong with the resource handling";
+ synchronized (resources) {
+ for (File resource : resources) {
+ try {
+ FileUtil.removeFileChangeListener(FCHSL, resource);
+ } catch (IllegalArgumentException ex) {
+ assert false : "Something is wrong with the resource
handling";
+ }
}
+ resources.clear();
}
- resources.clear();
}
- private void attachResourceWatchers() {
+ private void attachResourceWatchers(boolean elevateQuality) {
//Never listen on resource changes when only FALLBACK quality is needed
- if (project.getAimedQuality() == Quality.FALLBACK) return;
-
- Collection<? extends WatchedResourceProvider> all
- = project.getLookup().lookupAll(WatchedResourceProvider.class);
- for (WatchedResourceProvider pvd : all) {
- resources.addAll(pvd.getWatchedResources());
- }
- for (File resource : resources) {
- try {
- FileUtil.addFileChangeListener(FCHSL, resource);
- } catch (IllegalArgumentException ex) {
- assert false : "Something is wrong with the resource handling";
+ if ((project.getAimedQuality() == Quality.FALLBACK) &&
!elevateQuality) return;
+ synchronized (resources) {
+ if (!resources.isEmpty()) {
+ LOG.warning("Gradle ResourceWatcher Leak: " + resources);
//NOI18N
+ resources.clear();
+ }
+ Collection<? extends WatchedResourceProvider> all
+ =
project.getLookup().lookupAll(WatchedResourceProvider.class);
+ for (WatchedResourceProvider pvd : all) {
+ resources.addAll(pvd.getWatchedResources());
+ }
+ for (File resource : resources) {
+ try {
+ FileUtil.addFileChangeListener(FCHSL, resource);
+ } catch (IllegalArgumentException ex) {
+ assert false : "Something is wrong with the resource
handling";
+ }
}
}
}
diff --git
a/extide/gradle/src/org/netbeans/modules/gradle/execute/GradleDistributionProviderImpl.java
b/extide/gradle/src/org/netbeans/modules/gradle/execute/GradleDistributionProviderImpl.java
index 351241d8cc..ef04429cf1 100644
---
a/extide/gradle/src/org/netbeans/modules/gradle/execute/GradleDistributionProviderImpl.java
+++
b/extide/gradle/src/org/netbeans/modules/gradle/execute/GradleDistributionProviderImpl.java
@@ -80,7 +80,7 @@ public class GradleDistributionProviderImpl implements
GradleDistributionProvide
public GradleDistributionProviderImpl(Project project) {
this.project = (NbGradleProjectImpl) project;
pcl = (evt) -> {
- if
(NbGradleProject.PROP_RESOURCES.endsWith(evt.getPropertyName())) {
+ if (NbGradleProject.PROP_RESOURCES.equals(evt.getPropertyName())) {
URI uri = (URI) evt.getNewValue();
if ((uri != null) && (uri.getPath() != null) &&
uri.getPath().endsWith(GradleFiles.WRAPPER_PROPERTIES)) {
URI newDistURI = getWrapperDistributionURI();
diff --git
a/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/ClassPathProviderImpl.java
b/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/ClassPathProviderImpl.java
index 70fbc148fe..d09039ff2e 100644
---
a/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/ClassPathProviderImpl.java
+++
b/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/ClassPathProviderImpl.java
@@ -85,7 +85,7 @@ public final class ClassPathProviderImpl extends
ProjectOpenedHook implements Cl
if
(NbGradleProject.PROP_PROJECT_INFO.equals(evt.getPropertyName())) {
updateGroups();
}
- if
(NbGradleProject.PROP_RESOURCES.endsWith(evt.getPropertyName())) {
+ if (NbGradleProject.PROP_RESOURCES.equals(evt.getPropertyName())) {
URI uri = (URI) evt.getNewValue();
updateResources(uri);
}
diff --git
a/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/GradleSourcesImpl.java
b/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/GradleSourcesImpl.java
index c5508e2358..9c590e2660 100644
---
a/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/GradleSourcesImpl.java
+++
b/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/GradleSourcesImpl.java
@@ -42,7 +42,6 @@ import java.util.Set;
import javax.swing.Icon;
import javax.swing.event.ChangeListener;
import org.netbeans.api.java.project.JavaProjectConstants;
-import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.SourceGroup;
diff --git
a/java/gradle.java/src/org/netbeans/modules/gradle/java/nodes/SourcesNodeFactory.java
b/java/gradle.java/src/org/netbeans/modules/gradle/java/nodes/SourcesNodeFactory.java
index 5e5ac20f1b..bb1ec19d92 100644
---
a/java/gradle.java/src/org/netbeans/modules/gradle/java/nodes/SourcesNodeFactory.java
+++
b/java/gradle.java/src/org/netbeans/modules/gradle/java/nodes/SourcesNodeFactory.java
@@ -20,11 +20,14 @@
package org.netbeans.modules.gradle.java.nodes;
import java.awt.Image;
+import java.beans.PropertyChangeListener;
+import java.net.URI;
import java.nio.file.Path;
import java.util.ArrayList;
import org.netbeans.modules.gradle.api.NbGradleProject;
import org.netbeans.modules.gradle.spi.nodes.AbstractGradleNodeList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
@@ -49,6 +52,7 @@ import org.openide.nodes.Node;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
+import org.openide.util.WeakListeners;
/**
*
@@ -58,7 +62,8 @@ import org.openide.util.RequestProcessor;
public final class SourcesNodeFactory implements NodeFactory {
private static final String WARNING_BADGE =
"org/netbeans/modules/gradle/resources/warning-badge.png"; //NOI18N
-
+
+
@Override
public NodeList<?> createNodes(Project project) {
return new NList(project);
@@ -67,8 +72,21 @@ public final class SourcesNodeFactory implements NodeFactory
{
private static class NList extends AbstractGradleNodeList<SourceGroup>
implements ChangeListener {
private static final RequestProcessor RP = new
RequestProcessor(SourcesNodeFactory.NList.class);
private final Project project;
+
+ private List<SourceGroup> generatedGroups = Collections.emptyList();
+ private final PropertyChangeListener pcl = (evt) -> {
+ if (NbGradleProject.PROP_RESOURCES.equals(evt.getPropertyName())) {
+ String path = ((URI) evt.getNewValue()).getPath();
+ for (SourceGroup group : generatedGroups) {
+ if
(path.startsWith(group.getRootFolder().toURI().getPath())) {
+ RP.post(this::fireChange);
+ }
+ }
+ }
+ };
private NList(Project prj) {
project = prj;
+ NbGradleProject.addPropertyChangeListener(project,
WeakListeners.propertyChange(pcl, this));
}
@Override
@@ -79,7 +97,9 @@ public final class SourcesNodeFactory implements NodeFactory {
ret.addAll(Arrays.asList(srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)));
ret.addAll(Arrays.asList(srcs.getSourceGroups(GradleSourcesImpl.SOURCE_TYPE_KOTLIN)));
ret.addAll(Arrays.asList(srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES)));
-
ret.addAll(Arrays.asList(srcs.getSourceGroups(GradleSourcesImpl.SOURCE_TYPE_GENERATED)));
+ List<SourceGroup> generated =
Arrays.asList(srcs.getSourceGroups(GradleSourcesImpl.SOURCE_TYPE_GENERATED));
+ ret.addAll(generated);
+ generatedGroups = generated;
ret.sort(Comparator.comparing(SourceGroup::getName));
return ret;
}
@@ -97,6 +117,10 @@ public final class SourcesNodeFactory implements
NodeFactory {
Logger.getLogger(SourcesNodeFactory.class.getName()).log(Level.INFO, "Cannot
find a project owner for folder {0}", group.getRootFolder()); //NOI18N
return null;
}
+ // Do not display empty Generated SourceGroups
+ if (generatedGroups.contains(group) && (group.getRootFolder() !=
null) && group.getRootFolder().getChildren().length == 0) {
+ return null;
+ }
String name = group.getName();
Node ret;
switch(name) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists