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 5a2ad9e [NETBEANS-3600] Added Gradle wrapper distribution change
detection.
5a2ad9e is described below
commit 5a2ad9e3fc45ff05ffcb82ca179f2804e337bcb9
Author: Laszlo Kishalmi <[email protected]>
AuthorDate: Sun Sep 13 07:23:15 2020 -0700
[NETBEANS-3600] Added Gradle wrapper distribution change detection.
---
.../modules/gradle/GradleProjectCache.java | 7 +--
.../api/execute/GradleDistributionManager.java | 38 +++++++++++----
.../execute/GradleDistributionProviderImpl.java | 55 ++++++++++++++++++++--
3 files changed, 85 insertions(+), 15 deletions(-)
diff --git
a/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectCache.java
b/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectCache.java
index b02ba62..db8a44c 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectCache.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/GradleProjectCache.java
@@ -96,7 +96,7 @@ public final class GradleProjectCache {
private static final Map<File, Set<File>> SUB_PROJECT_DIR_CACHE = new
ConcurrentHashMap<>();
// Increase this number if new info is gathered from the projects.
- private static final int COMPATIBLE_CACHE_VERSION = 13;
+ private static final int COMPATIBLE_CACHE_VERSION = 14;
private GradleProjectCache() {
}
@@ -446,8 +446,9 @@ public final class GradleProjectCache {
assert gp.getQuality().betterThan(FALLBACK) : "Never attempt to cache
FALLBACK projects."; //NOi18N
//TODO: Make it possible to handle external file set as cache.
GradleFiles gf = new GradleFiles(gp.getBaseProject().getProjectDir(),
true);
-
- ProjectCacheEntry entry = new ProjectCacheEntry(new
StoredProjectInfo(data), gp, gf.getProjectFiles());
+ Set<File> cacheInvalidators = new HashSet<>(gf.getProjectFiles());
+ if (gf.hasWrapper()) cacheInvalidators.add(gf.getWrapperProperties());
+ ProjectCacheEntry entry = new ProjectCacheEntry(new
StoredProjectInfo(data), gp, cacheInvalidators);
File cacheFile = new File(getCacheDir(gp), INFO_CACHE_FILE_NAME);
if (!cacheFile.exists()) {
cacheFile.getParentFile().mkdirs();
diff --git
a/extide/gradle/src/org/netbeans/modules/gradle/api/execute/GradleDistributionManager.java
b/extide/gradle/src/org/netbeans/modules/gradle/api/execute/GradleDistributionManager.java
index c72190b..55ca548 100644
---
a/extide/gradle/src/org/netbeans/modules/gradle/api/execute/GradleDistributionManager.java
+++
b/extide/gradle/src/org/netbeans/modules/gradle/api/execute/GradleDistributionManager.java
@@ -58,6 +58,7 @@ import org.json.simple.parser.ParseException;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.netbeans.modules.gradle.api.NbGradleProject;
+import org.netbeans.modules.gradle.spi.GradleFiles;
import org.openide.awt.Notification;
import org.openide.awt.NotificationDisplayer;
import org.openide.util.Exceptions;
@@ -201,7 +202,31 @@ public final class GradleDistributionManager {
* the Gradle distribution cannot be determined form it.
*/
public GradleDistribution distributionFromWrapper(File gradleProjectRoot)
throws IOException, URISyntaxException {
- File wrapperProps = new File(gradleProjectRoot,
"gradle/wrapper/gradle-wrapper.properties"); //NOI18N
+ URI uri = getWrapperDistributionURI(gradleProjectRoot);
+ Matcher m = DIST_VERSION_PATTERN.matcher(uri.getPath());
+ if (m.matches()) {
+ String version = m.group(1);
+ return new GradleDistribution(distributionBaseDir(uri, version),
uri, version);
+ } else {
+ throw new URISyntaxException(uri.getPath(), "Cannot get the Gradle
distribution version from the URI"); //NOI18N
+ }
+ }
+
+ /**
+ * Retrieves a normalized URI for the Gradle Wrapper distribution for the
+ * given root project directory.
+ *
+ * @param rootDir the root project directory
+ * @return the normalized URI of the Gradle wrapper distribution.
+ * @throws IOException if there is no
<code>gradle-wrapper.properties</code>
+ * or it cannot be read.
+ * @throws URISyntaxException if the <code>distributionUrl</code> is
missing
+ * or cannot be resolved to a valid URI.
+ */
+ public static URI getWrapperDistributionURI(File rootDir) throws
IOException, URISyntaxException {
+ URI ret;
+
+ File wrapperProps = new File(rootDir, GradleFiles.WRAPPER_PROPERTIES);
if (wrapperProps.isFile() && wrapperProps.canRead()) {
Properties wrapper = new Properties();
try (FileInputStream is = new FileInputStream(wrapperProps)) {
@@ -211,13 +236,9 @@ public final class GradleDistributionManager {
}
String distUrlProp = wrapper.getProperty("distributionUrl");
//NOI18N
if (distUrlProp != null) {
- URI uri = new URI(distUrlProp);
- Matcher m = DIST_VERSION_PATTERN.matcher(distUrlProp);
- if (m.matches()) {
- String version = m.group(1);
- return new GradleDistribution(distributionBaseDir(uri,
version), uri, version);
- } else {
- throw new URISyntaxException(distUrlProp, "Cannot get the
Gradle distribution version from the URI"); //NOI18N
+ ret = new URI(distUrlProp);
+ if (ret.getScheme() == null) {
+ ret =
wrapperProps.getParentFile().toPath().resolve(distUrlProp).normalize().toUri();
}
} else {
throw new URISyntaxException("", "No distributionUrl property
found in: " + wrapperProps.getAbsolutePath()); //NOI18N
@@ -225,6 +246,7 @@ public final class GradleDistributionManager {
} else {
throw new FileNotFoundException("Gradle Wrapper properties not
found at: " + wrapperProps.getAbsolutePath()); //NOI18N
}
+ return ret;
}
/**
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 12f9cae..8bd243c 100644
---
a/extide/gradle/src/org/netbeans/modules/gradle/execute/GradleDistributionProviderImpl.java
+++
b/extide/gradle/src/org/netbeans/modules/gradle/execute/GradleDistributionProviderImpl.java
@@ -18,33 +18,42 @@
*/
package org.netbeans.modules.gradle.execute;
+import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import javax.swing.event.ChangeListener;
+import org.gradle.internal.impldep.com.google.common.base.Objects;
import org.netbeans.api.project.Project;
import org.netbeans.modules.gradle.api.GradleBaseProject;
import org.netbeans.modules.gradle.api.NbGradleProject;
import org.netbeans.modules.gradle.api.execute.GradleDistributionManager;
import
org.netbeans.modules.gradle.api.execute.GradleDistributionManager.GradleDistribution;
+import org.netbeans.modules.gradle.spi.GradleFiles;
import org.netbeans.modules.gradle.spi.GradleSettings;
import org.netbeans.modules.gradle.spi.execute.GradleDistributionProvider;
import org.netbeans.spi.project.ProjectServiceProvider;
import org.openide.util.ChangeSupport;
import static org.netbeans.modules.gradle.spi.GradleSettings.*;
+import org.netbeans.modules.gradle.spi.WatchedResourceProvider;
+import org.openide.util.WeakListeners;
/**
*
* @author lkishalmi
*/
-@ProjectServiceProvider(service = GradleDistributionProvider.class,
projectType = NbGradleProject.GRADLE_PROJECT_TYPE)
-public class GradleDistributionProviderImpl implements
GradleDistributionProvider {
+@ProjectServiceProvider(service = {GradleDistributionProvider.class,
WatchedResourceProvider.class}, projectType =
NbGradleProject.GRADLE_PROJECT_TYPE)
+public class GradleDistributionProviderImpl implements
GradleDistributionProvider, WatchedResourceProvider {
private final static Logger LOGGER =
Logger.getLogger(GradleDistributionProviderImpl.class.getName());
@@ -59,16 +68,31 @@ public class GradleDistributionProviderImpl implements
GradleDistributionProvide
private final ChangeSupport support = new ChangeSupport(this);
private final PreferenceChangeListener listener = (PreferenceChangeEvent
evt) -> {
if (AFFECTING_PROPS.contains(evt.getKey())) {
- dist = null;
- support.fireChange();
+ distributionChanged();
}
};
final Project project;
private GradleDistribution dist;
+ private PropertyChangeListener pcl;
+ private URI distributionURI;
public GradleDistributionProviderImpl(Project project) {
this.project = project;
+ pcl = (evt) -> {
+ if
(NbGradleProject.PROP_RESOURCES.endsWith(evt.getPropertyName())) {
+ URI uri = (URI) evt.getNewValue();
+ if ((uri != null) && (uri.getPath() != null) &&
uri.getPath().endsWith(GradleFiles.WRAPPER_PROPERTIES)) {
+ URI newDistURI = getWrapperDistributionURI();
+ if (GradleSettings.getDefault().isWrapperPreferred() && !
Objects.equal(distributionURI, newDistURI)) {
+ distributionURI = newDistURI;
+ distributionChanged();
+ }
+ }
+ }
+ };
+ distributionURI = getWrapperDistributionURI();
+ NbGradleProject.addPropertyChangeListener(project,
WeakListeners.propertyChange(pcl, project));
}
@Override
@@ -103,6 +127,23 @@ public class GradleDistributionProviderImpl implements
GradleDistributionProvide
return dist;
}
+ private void distributionChanged() {
+ dist = null;
+ support.fireChange();
+ NbGradleProject.fireGradleProjectReload(project);
+ }
+
+ private URI getWrapperDistributionURI() {
+ URI ret = null;
+ try {
+ GradleBaseProject gbp = GradleBaseProject.get(project);
+ if (gbp != null) {
+ ret =
GradleDistributionManager.getWrapperDistributionURI(gbp.getRootDir());
+ }
+ } catch (IOException | URISyntaxException ex) {}
+ return ret;
+ }
+
@Override
public void addChangeListener(ChangeListener l) {
if (!support.hasListeners()) {
@@ -119,4 +160,10 @@ public class GradleDistributionProviderImpl implements
GradleDistributionProvide
}
}
+ @Override
+ public Set<File> getWatchedResources() {
+ GradleBaseProject gbp = GradleBaseProject.get(project);
+ return gbp != null ? Collections.singleton(new File(gbp.getRootDir(),
GradleFiles.WRAPPER_PROPERTIES)) : Collections.emptySet();
+ }
+
}
---------------------------------------------------------------------
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