You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2021/11/02 19:11:43 UTC

[GitHub] [netbeans] matthiasblaesing commented on a change in pull request #3285: [NETBEANS-6163] Try to find Java root in generated sources.

matthiasblaesing commented on a change in pull request #3285:
URL: https://github.com/apache/netbeans/pull/3285#discussion_r741390841



##########
File path: java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java
##########
@@ -639,6 +640,24 @@ public MavenEmbedder getEmbedder() {
         return uris.toArray(new URI[uris.size()]);
     }
 
+    private static File findJavaRoot(File root, boolean test) {
+        String javaFolder = test ? "test" + File.separator + "java" : "main" + File.separator + "java"; // NOI18N
+        File newRoot = new File(root, javaFolder);
+        if (newRoot.isDirectory()) {
+            return newRoot;
+        }
+        File[] listFiles = root.listFiles();
+        if (listFiles != null) {
+            for (File f : listFiles) {
+                newRoot = new File(f, javaFolder);
+                if (newRoot.isDirectory()) {
+                    return newRoot;
+                }
+            }
+        }

Review comment:
       This will break, if an existing plugin (maven-compiler (annotations), jaxb, ...) generates sources in the package `test.java` or `main.java`. I don't think, that that is impossible. You could analyze java files there for the package declaration, but that sounds like overkill.
   
   IMHO it would be better if the plugin would be fixed to use the conventional directory: `target/generated-sources/<PLUGIN>`. At least `maven-compiler-plugin`  and `jaxb2-maven-plugin` both use that and the existing code in the netbeans code is an indicator, that the original authors came to the same conclusion.

##########
File path: java/maven/test/unit/src/org/netbeans/modules/maven/classpath/MavenSourcesImplTest.java
##########
@@ -115,6 +115,26 @@ public void testGeneratedSources() throws Exception { // #187595
         assertEquals(gtsrc, grps[1].getRootFolder());
     }
 
+    public void testGeneratedSources2() throws Exception { // #187595
+        TestFileUtils.writeFile(d,
+                "pom.xml",
+                "<project xmlns='http://maven.apache.org/POM/4.0.0'>" +
+                "<modelVersion>4.0.0</modelVersion>" +
+                "<groupId>grp</groupId>" +
+                "<artifactId>art</artifactId>" +
+                "<packaging>jar</packaging>" +
+                "<version>0</version>" +
+                "</project>");
+        FileObject gsrc = FileUtil.createFolder(d, "target/generated-sources/name/src/main/java/com");
+        gsrc.createData("Whatever.class");

Review comment:
       `Whatever.java` - this is generated sources :-) - the same is true for line 131.

##########
File path: java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java
##########
@@ -639,6 +640,24 @@ public MavenEmbedder getEmbedder() {
         return uris.toArray(new URI[uris.size()]);
     }
 
+    private static File findJavaRoot(File root, boolean test) {
+        String javaFolder = test ? "test" + File.separator + "java" : "main" + File.separator + "java"; // NOI18N
+        File newRoot = new File(root, javaFolder);
+        if (newRoot.isDirectory()) {
+            return newRoot;
+        }

Review comment:
       This will recognize `target/generated-sources/test/java` and `target/generated-sources/test/java` - did someone seriously place files there?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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

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