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 70fab45 [NETBEANS-2644] Gradle buildSrc projects are recognized and
displayed in the Build Scripts node
70fab45 is described below
commit 70fab45daee43bca06717ef7362ae8b1eaaefd77
Author: Laszlo Kishalmi <[email protected]>
AuthorDate: Wed Oct 7 09:52:39 2020 -0700
[NETBEANS-2644] Gradle buildSrc projects are recognized and displayed in
the Build Scripts node
---
extide/gradle/apichanges.xml | 14 +++
.../modules/gradle/BulkModelRetriever.java | 131 +++++++++++++++++++++
.../modules/gradle/NbGradleProjectFactory.java | 15 ++-
.../modules/gradle/nodes/BuildScriptsNode.java | 63 +++++-----
.../modules/gradle/nodes/SubProjectsNode.java | 34 +++---
.../org/netbeans/modules/gradle/queries/Info.java | 15 ++-
.../netbeans/modules/gradle/spi/GradleFiles.java | 32 +++--
.../modules/gradle/NbGradleProjectFactoryTest.java | 44 ++++++-
.../modules/gradle/spi/GradleFilesTest.java | 10 ++
9 files changed, 295 insertions(+), 63 deletions(-)
diff --git a/extide/gradle/apichanges.xml b/extide/gradle/apichanges.xml
index 875ee40..9fc9784 100644
--- a/extide/gradle/apichanges.xml
+++ b/extide/gradle/apichanges.xml
@@ -83,6 +83,20 @@ is the proper place.
<!-- ACTUAL CHANGES BEGIN HERE: -->
<changes>
+ <change id="gradle-buildsrc-project">
+ <api name="general"/>
+ <summary>GradleFiles SPI has the methods to deal with the buildSrc
project.</summary>
+ <version major="2" minor="4"/>
+ <date year="2020" month="10" day="7"/>
+ <author login="lkishalmi"/>
+ <compatibility binary="compatible" source="compatible"/>
+ <description>
+ <p>
+ <code><a
href="@TOP@/org/netbeans/modules/gradle/spi/GradleFiles.html#isBuildSrcProject()">GradleFiles.isBuildSrcProject()</a></code>
was
+ added to detect if a project id a buildSrc project, and a
new file Kind has been introduced <code>BUILD_SRC</code>.
+ </p>
+ </description>
+ </change>
<change id="gradle-project-connection">
<api name="general"/>
<summary>Expose Gradle ProjectConnection through Project's
Lookup.</summary>
diff --git
a/extide/gradle/src/org/netbeans/modules/gradle/BulkModelRetriever.java
b/extide/gradle/src/org/netbeans/modules/gradle/BulkModelRetriever.java
new file mode 100644
index 0000000..ddade85
--- /dev/null
+++ b/extide/gradle/src/org/netbeans/modules/gradle/BulkModelRetriever.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.gradle;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.gradle.api.Action;
+import org.gradle.tooling.BuildAction;
+import org.gradle.tooling.BuildController;
+import org.gradle.tooling.model.Model;
+
+/**
+ *
+ * @author lkishalmi
+ */
+public class BulkModelRetriever {
+
+ private static final AtomicInteger TASK_SEQUENCE = new AtomicInteger();
+
+ <T extends Model, P> Future<T> fetchModel(Class<T> modelType, Class<P>
parameterType, Action<? super P> parameterInitializer) {
+ return null;
+ }
+
+ public static class BulkActionResult {}
+ public static class ModelResult implements Serializable {
+ String id;
+ Model result;
+ Throwable exception;
+
+ public ModelResult(String id, Model result) {
+ this.id = id;
+ this.result = result;
+ }
+
+ public ModelResult(String id, Throwable exception) {
+ this.id = id;
+ this.exception = exception;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public Model getResult() {
+ return result;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ }
+
+ public static class ModelTask<T extends Model, P> implements Serializable {
+
+ String id;
+ Class<T> modelType;
+ Class<P> parameterType;
+ Action<? super P> parameterInitializer;
+
+ public ModelTask(Class<T> modelType, Class<P> parameterType, Action<?
super P> parameterInitializer) {
+ id = modelType.getName() + "-" + TASK_SEQUENCE.getAndIncrement();
+ this.modelType = modelType;
+ this.parameterType = parameterType;
+ this.parameterInitializer = parameterInitializer;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public Class<T> getModelType() {
+ return modelType;
+ }
+
+ public Class<P> getParameterType() {
+ return parameterType;
+ }
+
+ public Action<? super P> getParameterInitializer() {
+ return parameterInitializer;
+ }
+
+ }
+
+ private static class BulkModelAction implements
BuildAction<List<ModelResult>> {
+
+ List<ModelTask> modelTasks = new LinkedList<>();
+
+ public void addTask(Class modelType, Class parameterType, Action
parameterInitializer) {
+ ModelTask task = new ModelTask(modelType, parameterType,
parameterInitializer);
+ modelTasks.add(task);
+ }
+
+ @Override
+ public List<ModelResult> execute(BuildController bc) {
+ List<ModelResult> results = new LinkedList<>();
+ for (ModelTask modelTask : modelTasks) {
+ if (modelTask.parameterType != null) {
+ try {
+ Model m = (Model)bc.getModel(modelTask.modelType,
modelTask.parameterType, modelTask.getParameterInitializer());
+ results.add(new ModelResult(modelTask.getId(), m));
+ } catch (Throwable th) {
+ results.add(new ModelResult(modelTask.getId(), th));
+ }
+ }
+ }
+ return results;
+ }
+
+ }
+}
diff --git
a/extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectFactory.java
b/extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectFactory.java
index 8137835..4ac33c9 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectFactory.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectFactory.java
@@ -67,12 +67,21 @@ public final class NbGradleProjectFactory implements
ProjectFactory2 {
}
File suspect = FileUtil.toFile(dir);
GradleFiles files = new GradleFiles(suspect);
- if ((files.getSettingsScript() != null) && !files.isRootProject()) {
+ if (files.isRootProject()) return true;
+
+ if ((files.getSettingsScript() != null) && !files.isBuildSrcProject())
{
SubProjectDiskCache spCache =
SubProjectDiskCache.get(files.getRootDir());
SubProjectDiskCache.SubProjectInfo data = spCache.loadData();
- return data != null && data.getProjectPath(suspect) != null;
+ if (data != null) {
+ // Use the cached sub-project data, even if it's invalid,
+ // it may have better results, than the heuristics
+ return data.getProjectPath(suspect) != null;
+ } else {
+ // No cached info available, use heuristics.
+ return files.isProject();
+ }
} else {
- return true;
+ return false;
}
}
diff --git
a/extide/gradle/src/org/netbeans/modules/gradle/nodes/BuildScriptsNode.java
b/extide/gradle/src/org/netbeans/modules/gradle/nodes/BuildScriptsNode.java
index 614526d..d251901 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/nodes/BuildScriptsNode.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/nodes/BuildScriptsNode.java
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import org.netbeans.api.annotations.common.StaticResource;
+import org.netbeans.modules.gradle.spi.GradleFiles.Kind;
import org.netbeans.modules.gradle.spi.GradleSettings;
import org.openide.filesystems.FileChangeAdapter;
import org.openide.filesystems.FileEvent;
@@ -47,6 +48,7 @@ import org.openide.util.NbBundle.Messages;
import org.openide.util.Pair;
import org.openide.util.lookup.Lookups;
+import static org.netbeans.modules.gradle.spi.GradleFiles.Kind.*;
/**
*
* @author Laszlo Kishalmi
@@ -65,6 +67,11 @@ public final class BuildScriptsNode extends
AnnotatedAbstractNode {
setDisplayName(Bundle.LBL_Build_Scripts());
}
+ // The order in this array determines the order of the nodes under Build
Scripts
+ private final static Kind[] SCRIPTS = new Kind[] {
+ BUILD_SRC, USER_PROPERTIES, ROOT_SCRIPT, ROOT_PROPERTIES,
BUILD_SCRIPT, PROJECT_PROPERTIES
+ };
+
@Override
protected Image getIconImpl(int param) {
return getIcon(false);
@@ -116,40 +123,32 @@ public final class BuildScriptsNode extends
AnnotatedAbstractNode {
protected Node createNodeForKey(Pair<FileObject, GradleFiles.Kind>
key) {
// Do not show root script and property nodes on root project.
boolean isRoot =
project.getGradleProject().getBaseProject().isRoot();
- if (isRoot
- && ((key.second() == GradleFiles.Kind.ROOT_SCRIPT)
- || (key.second() == GradleFiles.Kind.ROOT_PROPERTIES))) {
- return null;
+ FileObject fo = key.first();
+ switch (key.second()) {
+ case ROOT_SCRIPT:
+ case ROOT_PROPERTIES:
+ return isRoot ? null : createBuildFileNode(fo,
Bundle.LBL_RootSuffix());
+ case BUILD_SCRIPT:
+ case PROJECT_PROPERTIES:
+ return createBuildFileNode(fo, isRoot ? null :
Bundle.LBL_ProjectSuffixt());
+ case USER_PROPERTIES:
+ return createBuildFileNode(fo, Bundle.LBL_UserSuffix());
+ case BUILD_SRC:
+ return SubProjectsNode.createSubProjectNode(fo);
+ default:
+ return null;
}
+ }
+
+ private static Node createBuildFileNode(FileObject fo, String
nameSuffix) {
+ Node ret = null;
try {
- Node node =
DataObject.find(key.first()).getNodeDelegate().cloneNode();
- String nameSuffix = null;
- if (key.second() != null) {
- if (key.second() == GradleFiles.Kind.USER_PROPERTIES) {
- nameSuffix = Bundle.LBL_UserSuffix();
- }
- if (!isRoot) {
- switch (key.second()) {
- case BUILD_SCRIPT:
- case PROJECT_PROPERTIES: {
- nameSuffix = Bundle.LBL_ProjectSuffixt();
- break;
- }
- case ROOT_SCRIPT:
- case ROOT_PROPERTIES: {
- nameSuffix = Bundle.LBL_RootSuffix();
- break;
- }
- }
- }
- }
+ ret = DataObject.find(fo).getNodeDelegate().cloneNode();
if (nameSuffix != null) {
- node.setDisplayName(key.first().getNameExt() + " [" +
nameSuffix + "]");
+ ret.setDisplayName(fo.getNameExt() + " [" + nameSuffix +
"]");
}
- return node;
- } catch (DataObjectNotFoundException e) {
- return null;
- }
+ } catch (DataObjectNotFoundException ex) {}
+ return ret;
}
public @Override
@@ -176,9 +175,9 @@ public final class BuildScriptsNode extends
AnnotatedAbstractNode {
@Override
protected boolean createKeys(List<Pair<FileObject, GradleFiles.Kind>>
keys) {
GradleFiles gf = project.getGradleFiles();
- for (GradleFiles.Kind kind : GradleFiles.Kind.values()) {
+ for (GradleFiles.Kind kind : SCRIPTS) {
File f = gf.getFile(kind);
- if ((f != null) && f.isFile()) {
+ if ((f != null) && f.exists()) {
keys.add(Pair.of(FileUtil.toFileObject(f), kind));
}
}
diff --git
a/extide/gradle/src/org/netbeans/modules/gradle/nodes/SubProjectsNode.java
b/extide/gradle/src/org/netbeans/modules/gradle/nodes/SubProjectsNode.java
index b50fb52..c5b458c 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/nodes/SubProjectsNode.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/nodes/SubProjectsNode.java
@@ -130,8 +130,8 @@ public class SubProjectsNode extends AbstractNode {
@Override
protected boolean createKeys(final List<String> paths) {
Map<String, File> subProjects =
project.getGradleProject().getBaseProject().getSubProjects();
- Set<String> components = new TreeSet<>();
- Set<String> projects = new TreeSet<>();
+ Set<String> components = new
TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+ Set<String> projects = new
TreeSet<>(String.CASE_INSENSITIVE_ORDER);
for (String path : subProjects.keySet()) {
if (path.startsWith(rootPath)) {
String relPath = path.substring(rootPath.length());
@@ -158,19 +158,7 @@ public class SubProjectsNode extends AbstractNode {
if (projectDir != null) {
FileObject fo = FileUtil.toFileObject(projectDir);
if (fo != null) {
- try {
- Project prj =
ProjectManager.getDefault().findProject(fo);
- if (prj != null &&
prj.getLookup().lookup(NbGradleProjectImpl.class) != null) {
- NbGradleProjectImpl proj = (NbGradleProjectImpl)
prj;
- assert
prj.getLookup().lookup(LogicalViewProvider.class) != null;
- Node original =
proj.getLookup().lookup(LogicalViewProvider.class).createLogicalView();
- ret = new ProjectFilterNode(proj, original);
- }
- } catch (IllegalArgumentException | IOException ex) {
- ErrorManager.getDefault().notify(ex);
- }
- } else {
- //TODO broken module reference.. show as such..
+ ret = createSubProjectNode(fo);
}
} else {
ret = new SubProjectsNode(project, path);
@@ -180,6 +168,22 @@ public class SubProjectsNode extends AbstractNode {
}
+ public static Node createSubProjectNode(FileObject fo) {
+ Node ret = null;
+ try {
+ Project prj = ProjectManager.getDefault().findProject(fo);
+ if (prj != null &&
prj.getLookup().lookup(NbGradleProjectImpl.class) != null) {
+ NbGradleProjectImpl proj = (NbGradleProjectImpl) prj;
+ assert prj.getLookup().lookup(LogicalViewProvider.class) !=
null;
+ Node original =
proj.getLookup().lookup(LogicalViewProvider.class).createLogicalView();
+ ret = new ProjectFilterNode(proj, original);
+ }
+ } catch (IllegalArgumentException | IOException ex) {
+ ErrorManager.getDefault().notify(ex);
+ }
+ return ret;
+ }
+
public static class ProjectFilterNode extends FilterNode {
private final NbGradleProjectImpl project;
diff --git a/extide/gradle/src/org/netbeans/modules/gradle/queries/Info.java
b/extide/gradle/src/org/netbeans/modules/gradle/queries/Info.java
index 11c3b7e..46e4e86 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/queries/Info.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/queries/Info.java
@@ -37,8 +37,11 @@ import javax.swing.SwingUtilities;
import org.netbeans.api.annotations.common.StaticResource;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectInformation;
+import org.netbeans.modules.gradle.NbGradleProjectImpl;
+import org.netbeans.modules.gradle.spi.GradleFiles;
import org.netbeans.spi.project.ProjectServiceProvider;
import org.openide.util.ImageUtilities;
+import org.openide.util.NbBundle;
import org.openide.util.WeakListeners;
/**
@@ -73,8 +76,12 @@ public final class Info implements ProjectInformation,
PropertyChangeListener {
}
@Override
+ @NbBundle.Messages({
+ "# {0} - the folder or name of the root project",
+ "LBL_BuildSrcProject=Custom Build Logic [{0}]"
+ })
public String getDisplayName() {
- final NbGradleProject nb =
project.getLookup().lookup(NbGradleProject.class);
+ final NbGradleProject nb = NbGradleProject.get(project);
if (SwingUtilities.isEventDispatchThread() &&
!nb.isGradleProjectLoaded()) {
return project.getProjectDirectory().getNameExt();
}
@@ -89,6 +96,12 @@ public final class Info implements ProjectInformation,
PropertyChangeListener {
// The current implementation of Gradle's displayName is kind of
ugly
// and cannot be configured.
//ret = prj.getDisplayName() != null ? prj.getDisplayName() :
getName();
+ if (project instanceof NbGradleProjectImpl) {
+ GradleFiles gf = ((NbGradleProjectImpl)
project).getGradleFiles();
+ if (gf.isBuildSrcProject()) {
+ return
Bundle.LBL_BuildSrcProject(gf.getRootDir().getName());
+ }
+ }
ret = getName();
}
return ret;
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 7064045..1c1a2b5 100644
--- a/extide/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java
+++ b/extide/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java
@@ -55,9 +55,11 @@ public final class GradleFiles implements Serializable {
SETTINGS_SCRIPT,
USER_PROPERTIES,
PROJECT_PROPERTIES,
- ROOT_PROPERTIES;
+ ROOT_PROPERTIES,
+ /** @since 2.4 */
+ BUILD_SRC;
- public static final Set<Kind> SCRIPTS = EnumSet.of(ROOT_SCRIPT,
BUILD_SCRIPT, SETTINGS_SCRIPT);
+ public static final Set<Kind> SCRIPTS = EnumSet.of(ROOT_SCRIPT,
BUILD_SCRIPT, SETTINGS_SCRIPT, BUILD_SRC);
public static final Set<Kind> PROPERTIES = EnumSet.of(USER_PROPERTIES,
PROJECT_PROPERTIES, ROOT_PROPERTIES);
public static final Set<Kind> PROJECT_FILES = EnumSet.of(ROOT_SCRIPT,
BUILD_SCRIPT, SETTINGS_SCRIPT, PROJECT_PROPERTIES, ROOT_PROPERTIES);
}
@@ -111,9 +113,9 @@ public final class GradleFiles implements Serializable {
if (!f1.canRead()) {
f1 = new File(projectDir, BUILD_FILE_NAME);
}
- File f2 = new File(projectDir, projectDir.getName() + ".gradle.kts");
+ File f2 = new File(projectDir, projectDir.getName() + ".gradle.kts");
//NOI18N
if (!f2.canRead()) {
- f2 = new File(projectDir, projectDir.getName() + ".gradle");
+ f2 = new File(projectDir, projectDir.getName() + ".gradle");
//NOI18N
}
settingsScript = searchPathUp(projectDir, SETTINGS_FILE_NAME_KTS);
@@ -141,7 +143,7 @@ public final class GradleFiles implements Serializable {
private void searchWrapper() {
File w = new File(rootDir, WRAPPER_PROPERTIES);
if (w.isFile()) {
- gradlew = new File(rootDir, Utilities.isWindows() ? "gradlew.bat"
: "gradlew");
+ gradlew = new File(rootDir, Utilities.isWindows() ? "gradlew.bat"
: "gradlew"); //NOI18N
wrapperProperties = w;
}
}
@@ -193,6 +195,16 @@ public final class GradleFiles implements Serializable {
return wrapperProperties != null;
}
+ /**
+ * Returns true if these files may represent a <code>buildSrc</code>
project.
+ * @return true if the project folder is under root and it is in the folder
+ * <code>buildSrc</code>
+ * @since 2.4
+ */
+ public boolean isBuildSrcProject() {
+ return "buildSrc".equals(projectDir.getName()) &&
rootDir.equals(projectDir.getParentFile());
+ }
+
public boolean isRootProject() {
return (buildScript != null) && rootDir.equals(projectDir);
}
@@ -261,6 +273,8 @@ public final class GradleFiles implements Serializable {
File guh = GradleSettings.getDefault().getGradleUserHome();
return new File(guh, GRADLE_PROPERTIES_NAME);
}
+ case BUILD_SRC:
+ return isBuildSrcProject() ? null : new File(rootDir,
"buildSrc"); //NOI18N
default:
return null;
}
@@ -299,7 +313,7 @@ public final class GradleFiles implements Serializable {
@Override
public String toString() {
- return "GradleFiles[projectDir=" + projectDir + ", rootDir=" + rootDir
+ "]";
+ return "GradleFiles[projectDir=" + projectDir + ", rootDir=" + rootDir
+ "]"; //NOI18N
}
public static class SettingsFile {
@@ -324,7 +338,7 @@ public final class GradleFiles implements Serializable {
List<String> lines = Files.readAllLines(f.toPath(),
Charset.forName("UTF-8")); //NOI18N
for (String line : lines) {
line = line.trim();
- if (!line.startsWith("//")) {
+ if (!line.startsWith("//")) { //NOI18N
String[] split = line.split("[\\s'\",\\(\\)]+");
//NOI18N
if ((split.length > 1) && "include".equals(split[0]))
{ //NOI18N
@@ -357,13 +371,13 @@ public final class GradleFiles implements Serializable {
if (firstGuess.isDirectory()) {
return firstGuess;
}
- for (String subdirName : Arrays.asList("subProjects", "modules")) {
+ for (String subdirName : Arrays.asList("subProjects", "modules"))
{ //NOI18N
File subdir = new File(rootDir, subdirName);
if (subdir.isDirectory()) {
if (new File(subdir, projectName).isDirectory()) {
return new File(subdir, projectName);
}
- String gradleStyle = projectName.replaceAll("\\p{Upper}",
"-$0").toLowerCase();
+ String gradleStyle = projectName.replaceAll("\\p{Upper}",
"-$0").toLowerCase(); //NOI18N
if (new File(subdir, gradleStyle).isDirectory()) {
return new File(subdir, gradleStyle);
}
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 af92113..00192df 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
@@ -18,12 +18,12 @@
*/
package org.netbeans.modules.gradle;
-import org.netbeans.junit.NbTestCase;
+import java.util.Random;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.LocalFileSystem;
-public class NbGradleProjectFactoryTest extends NbTestCase {
+public class NbGradleProjectFactoryTest extends AbstractGradleProjectTestCase {
private FileObject root;
public NbGradleProjectFactoryTest(String name) {
@@ -32,7 +32,7 @@ public class NbGradleProjectFactoryTest extends NbTestCase {
@Override
protected void setUp() throws Exception {
- clearWorkDir();
+ super.setUp();
LocalFileSystem fs = new LocalFileSystem();
fs.setRootDirectory(getWorkDir());
root = fs.getRoot();
@@ -43,6 +43,44 @@ public class NbGradleProjectFactoryTest extends NbTestCase {
assertFalse(NbGradleProjectFactory.isProjectCheck(null, true));
}
+ public void testNonProject() throws Exception {
+ FileObject prj = root;
+ assertFalse(NbGradleProjectFactory.isProjectCheck(prj, false));
+ }
+
+ public void testSubProject() throws Exception {
+ int rnd = new Random().nextInt(1000000);
+ FileObject a = createGradleProject("projectA-" + rnd,
+ "apply plugin: 'java'\n", "include 'projectB'\n");
+ FileObject b = createGradleProject("projectA-" + rnd + "/projectB",
+ "apply plugin: 'java'\n", null);
+ assertTrue(NbGradleProjectFactory.isProjectCheck(a, false));
+ assertTrue(NbGradleProjectFactory.isProjectCheck(b, false));
+ }
+
+ public void testNonProjectSubDir() throws Exception {
+ int rnd = new Random().nextInt(1000000);
+ FileObject a = createGradleProject("projectA-" + rnd,
+ "apply plugin: 'java'\n", "include 'projectB'\n");
+ FileObject b = createGradleProject("projectA-" + rnd + "/projectB",
+ "apply plugin: 'java'\n", null);
+ FileObject as = a.createFolder("docs");
+ FileObject bs = b.createFolder("src");
+
+ assertFalse(NbGradleProjectFactory.isProjectCheck(as, false));
+ assertFalse(NbGradleProjectFactory.isProjectCheck(bs, false));
+ }
+
+ public void testBuildSrcProject() throws Exception {
+ int rnd = new Random().nextInt(1000000);
+ FileObject a = createGradleProject("projectA-" + rnd,
+ "apply plugin: 'java'\n", null);
+ FileObject b = createGradleProject("projectA-" + rnd + "/buildSrc",
+ null, null);
+ assertTrue(NbGradleProjectFactory.isProjectCheck(a, false));
+ assertTrue(NbGradleProjectFactory.isProjectCheck(b, false));
+ }
+
public void testPomAndGradle() throws Exception {
FileObject prj = root;
FileObject pom = FileUtil.createData(prj, "pom.xml");
diff --git
a/extide/gradle/test/unit/src/org/netbeans/modules/gradle/spi/GradleFilesTest.java
b/extide/gradle/test/unit/src/org/netbeans/modules/gradle/spi/GradleFilesTest.java
index ff516ac..0fb9c56 100644
---
a/extide/gradle/test/unit/src/org/netbeans/modules/gradle/spi/GradleFilesTest.java
+++
b/extide/gradle/test/unit/src/org/netbeans/modules/gradle/spi/GradleFilesTest.java
@@ -414,6 +414,16 @@ public class GradleFilesTest {
assertTrue(gf.isRootProject());
}
+ @Test
+ public void testGetBuildSrc() throws IOException {
+ root.newFile("build.gradle");
+ root.newFile("settings.gradle");
+ File buildSrc = root.newFolder("buildSrc");
+ GradleFiles gf = new GradleFiles(buildSrc);
+ assertTrue(gf.isBuildSrcProject());
+ assertEquals(null, gf.getFile(GradleFiles.Kind.BUILD_SRC));
+ }
+
/**
* Test of getProjectFiles method, of class GradleFiles.
*/
---------------------------------------------------------------------
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