This is an automated email from the ASF dual-hosted git repository. sdedic 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 47eeba854b Support projects without build.gradle new 8b4df5dc82 Merge pull request #4594 from sdedic/gradle/no-build-gradle 47eeba854b is described below commit 47eeba854b894a1e84ba8a400f1d4f7f3491ee56 Author: Svata Dedic <svatopluk.de...@oracle.com> AuthorDate: Wed Sep 7 11:03:28 2022 +0200 Support projects without build.gradle --- .../modules/gradle/NbGradleProjectFactory.java | 7 +++++- .../netbeans/modules/gradle/spi/GradleFiles.java | 2 +- .../modules/gradle/NbGradleProjectFactoryTest.java | 25 +++++++++++++++++++++- .../modules/maven/NbMavenProjectFactory.java | 5 ++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectFactory.java b/extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectFactory.java index 628e3f8fa1..6663416b5b 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectFactory.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectFactory.java @@ -43,7 +43,12 @@ public final class NbGradleProjectFactory implements ProjectFactory2 { @Override public ProjectManager.Result isProject2(FileObject dir) { - return isProject(dir) ? new ProjectManager.Result(NbGradleProject.getIcon()) : null; + if (!isProject(dir)) { + return null; + } + // project display name can be only safely determined if the project is loaded + return isProject(dir) ? new ProjectManager.Result( + null, NbGradleProject.GRADLE_PROJECT_TYPE, NbGradleProject.getIcon()) : null; } @Override diff --git a/extide/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java b/extide/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java index 565251092e..eca56b7bdb 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java @@ -220,7 +220,7 @@ public final class GradleFiles implements Serializable { } public boolean isRootProject() { - return (buildScript != null) && rootDir.equals(projectDir); + return isProject() && rootDir.equals(projectDir); } public boolean isSubProject() { diff --git a/extide/gradle/test/unit/src/org/netbeans/modules/gradle/NbGradleProjectFactoryTest.java b/extide/gradle/test/unit/src/org/netbeans/modules/gradle/NbGradleProjectFactoryTest.java index 4041f77fb1..c2ea1e5261 100644 --- a/extide/gradle/test/unit/src/org/netbeans/modules/gradle/NbGradleProjectFactoryTest.java +++ b/extide/gradle/test/unit/src/org/netbeans/modules/gradle/NbGradleProjectFactoryTest.java @@ -21,6 +21,7 @@ package org.netbeans.modules.gradle; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.Random; +import org.netbeans.modules.gradle.api.NbGradleProject; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.LocalFileSystem; @@ -129,9 +130,31 @@ public class NbGradleProjectFactoryTest extends AbstractGradleProjectTestCase { } FileObject app = FileUtil.createFolder(parentPrj, "app"); FileObject gradle = FileUtil.createData(app, "build.gradle"); - + assertProjectsRecognized(parentPrj, app); + } + + private void assertProjectsRecognized(FileObject parentPrj, FileObject app) { assertTrue("Parent Gradle recognized", NbGradleProjectFactory.isProjectCheck(parentPrj, false)); assertTrue("Child Gradle recognized", NbGradleProjectFactory.isProjectCheck(app, false)); + NbGradleProjectFactory factoryInstance = new NbGradleProjectFactory(); + assertEquals("Gradle project type of main project", NbGradleProject.GRADLE_PROJECT_TYPE, factoryInstance.isProject2(parentPrj).getProjectType()); + assertEquals("Gradle project type of subproject", NbGradleProject.GRADLE_PROJECT_TYPE, factoryInstance.isProject2(app).getProjectType()); + } + + /** + * Checks that project with just settings.gradle and no build.gradle is recognized as a project. + */ + public void testNoBuildFileProject() throws Exception { + FileObject parentPrj = root; + FileObject settings = FileUtil.createData(parentPrj, "settings.gradle"); + try (OutputStream os = settings.getOutputStream()) { + os.write(("\n" + + "rootProject.name = 'example'\n" + + "include('app')\n" + ).getBytes(StandardCharsets.UTF_8)); + } + FileObject app = FileUtil.createFolder(parentPrj, "app"); + assertProjectsRecognized(parentPrj, app); } } diff --git a/java/maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java b/java/maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java index 3346cae10d..69f1f942ec 100644 --- a/java/maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java +++ b/java/maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; +import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.spi.project.ProjectFactory; import org.netbeans.spi.project.ProjectFactory2; import org.netbeans.spi.project.ProjectState; @@ -77,7 +78,9 @@ public class NbMavenProjectFactory implements ProjectFactory2 { public @Override ProjectManager.Result isProject2(FileObject projectDirectory) { if (isProject(projectDirectory)) { - return new ProjectManager.Result(ImageUtilities.loadImageIcon("org/netbeans/modules/maven/resources/Maven2Icon.gif", true)); //NOI18N + return new ProjectManager.Result( + null, NbMavenProject.TYPE, + ImageUtilities.loadImageIcon("org/netbeans/modules/maven/resources/Maven2Icon.gif", true)); //NOI18N } return null; } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists