You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ne...@apache.org on 2022/01/31 10:06:04 UTC

[netbeans] branch delivery updated: #3526: Retain traling / for non-existing directories.

This is an automated email from the ASF dual-hosted git repository.

neilcsmith pushed a commit to branch delivery
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/delivery by this push:
     new 95208b0  #3526: Retain traling / for non-existing directories.
     new 5b6a473  Merge pull request #3541 from sdedic/maven/GH3526-maven-classpath
95208b0 is described below

commit 95208b0e3a58f3107e876be99121abbc2ea66550
Author: Svata Dedic <sv...@oracle.com>
AuthorDate: Sun Jan 30 18:35:05 2022 +0100

    #3526: Retain traling / for non-existing directories.
---
 .../netbeans/modules/maven/NbMavenProjectImpl.java | 34 +++++++++++++++++++++-
 .../maven/classpath/RuntimeClassPathImpl.java      |  3 +-
 .../maven/classpath/TestRuntimeClassPathImpl.java  |  5 ++--
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java b/java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java
index a727e33..2978382 100644
--- a/java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java
+++ b/java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java
@@ -26,6 +26,7 @@ import java.lang.ref.Reference;
 import java.lang.ref.SoftReference;
 import java.lang.ref.WeakReference;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -64,6 +65,8 @@ import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.netbeans.api.annotations.common.CheckForNull;
 import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.annotations.common.NullUnknown;
 import org.netbeans.api.java.project.classpath.ProjectClassPathModifier;
 import org.netbeans.api.project.Project;
 import org.netbeans.api.queries.VisibilityQuery;
@@ -550,10 +553,39 @@ public final class NbMavenProjectImpl implements Project {
         return auxprops;
     }
 
+    /**
+     * The method will migrate to regular FileUtilities after NB13 release. The issue is that the result of 
+     * {@link FileUtilities#convertStringToUri(java.lang.String)} result depends on whether the directory 
+     * identified by the string exists or not. If it exists, the URI ends with a "/". For non-existent directories
+     * the URI lacks the trailing "/". This can break URI keys in a Map (if the directory gets created) and prevents
+     * from creating a ClassPath from such URLs (/ is checked). But FileUtilities is API and this behaviour is there for
+     * ages, so the correction should be added with a parameter.
+     */
+    public static @NullUnknown URI convertStringToUri(@NullAllowed String str, boolean slashIfNotExist) {
+        if (str != null) {
+            File fil = new File(str);
+            fil = FileUtil.normalizeFile(fil);
+            // this conversion returns URIs that end with "/" if fil is an existing directory, but returns
+            // without the slash if the directory just does not exist yet.
+            URI uri = Utilities.toURI(fil);
+            String s = uri.toString();
+            if (slashIfNotExist && !s.endsWith("/") && (fil.isDirectory() || !fil.exists())) { // NOI18N
+                try {
+                    return new URI(s + "/"); // NOI18N
+                } catch (URISyntaxException ex) {
+                    throw new IllegalArgumentException(str);
+                }
+            } else {
+                return uri;
+            }
+        }
+        return null;
+    }
+
     public URI[] getSourceRoots(boolean test) {
         List<URI> uris = new ArrayList<URI>();
         for (String root : test ? getOriginalMavenProject().getTestCompileSourceRoots() : getOriginalMavenProject().getCompileSourceRoots()) {
-            uris.add(FileUtilities.convertStringToUri(root));
+            uris.add(convertStringToUri(root, true));
         }
         for (JavaLikeRootProvider rp : getLookup().lookupAll(JavaLikeRootProvider.class)) {
             // XXX for a few purposes (listening) it is desirable to list these even before they exist, but usually it is just noise (cf. #196414 comment #2)
diff --git a/java/maven/src/org/netbeans/modules/maven/classpath/RuntimeClassPathImpl.java b/java/maven/src/org/netbeans/modules/maven/classpath/RuntimeClassPathImpl.java
index eb87786..58e7cb5 100644
--- a/java/maven/src/org/netbeans/modules/maven/classpath/RuntimeClassPathImpl.java
+++ b/java/maven/src/org/netbeans/modules/maven/classpath/RuntimeClassPathImpl.java
@@ -27,7 +27,6 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.model.Build;
 import org.apache.maven.project.MavenProject;
 import org.netbeans.modules.maven.NbMavenProjectImpl;
-import org.netbeans.modules.maven.api.FileUtilities;
 import org.openide.util.Utilities;
 
 /**
@@ -57,7 +56,7 @@ public class RuntimeClassPathImpl extends AbstractProjectClassPathImpl {
         if (build != null) {
             String outputDirectory = build.getOutputDirectory();
             if (outputDirectory != null) {
-                lst.add(FileUtilities.convertStringToUri(outputDirectory));
+                lst.add(NbMavenProjectImpl.convertStringToUri(outputDirectory, true));
             }
         }
         List<Artifact> arts = prj.getRuntimeArtifacts();
diff --git a/java/maven/src/org/netbeans/modules/maven/classpath/TestRuntimeClassPathImpl.java b/java/maven/src/org/netbeans/modules/maven/classpath/TestRuntimeClassPathImpl.java
index cb900c8..1e7a2ed 100644
--- a/java/maven/src/org/netbeans/modules/maven/classpath/TestRuntimeClassPathImpl.java
+++ b/java/maven/src/org/netbeans/modules/maven/classpath/TestRuntimeClassPathImpl.java
@@ -27,7 +27,6 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.model.Build;
 import org.apache.maven.project.MavenProject;
 import org.netbeans.modules.maven.NbMavenProjectImpl;
-import org.netbeans.modules.maven.api.FileUtilities;
 import org.openide.util.Utilities;
 
 
@@ -66,11 +65,11 @@ public class TestRuntimeClassPathImpl extends AbstractProjectClassPathImpl {
         if (build != null) {
             String testOutputDirectory = build.getTestOutputDirectory();
             if (testOutputDirectory != null) {
-                lst.add(FileUtilities.convertStringToUri(testOutputDirectory));
+                lst.add(NbMavenProjectImpl.convertStringToUri(testOutputDirectory, true));
             }
             String outputDirectory = build.getOutputDirectory();
             if (outputDirectory != null) {
-                lst.add(FileUtilities.convertStringToUri(outputDirectory));
+                lst.add(NbMavenProjectImpl.convertStringToUri(outputDirectory, true));
             }
         }
         List<Artifact> arts = prj.getTestArtifacts();

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists