Skip to content

Commit

Permalink
[NETBEANS-4900] Added back the node for settings.gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
lkishalmi committed Oct 14, 2020
1 parent 02cb755 commit 5894b30
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 20 deletions.
Expand Up @@ -69,7 +69,7 @@ public BuildScriptsNode(NbGradleProjectImpl prj) {

// 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
BUILD_SRC, USER_PROPERTIES, SETTINGS_SCRIPT, ROOT_SCRIPT, ROOT_PROPERTIES, BUILD_SCRIPT, PROJECT_PROPERTIES
};

@Override
Expand Down Expand Up @@ -133,6 +133,8 @@ protected Node createNodeForKey(Pair<FileObject, GradleFiles.Kind> key) {
return createBuildFileNode(fo, isRoot ? null : Bundle.LBL_ProjectSuffixt());
case USER_PROPERTIES:
return createBuildFileNode(fo, Bundle.LBL_UserSuffix());
case SETTINGS_SCRIPT:
return createBuildFileNode(fo, null);
case BUILD_SRC:
return SubProjectsNode.createSubProjectNode(fo);
default:
Expand Down
Expand Up @@ -53,6 +53,7 @@ public class GradleProjectNode extends AbstractNode {
public GradleProjectNode(Lookup lookup, NbGradleProjectImpl proj) {
super(NodeFactorySupport.createCompositeChildren(proj, "Projects/" + NbGradleProject.GRADLE_PROJECT_TYPE + "/Nodes"), lookup); //NOI18N
this.project = proj;
setName(proj.getProjectDirectory().getNameExt());
info = ProjectUtils.getInformation(project);
info.addPropertyChangeListener(new PropertyChangeListener() {
@Override
Expand Down
53 changes: 34 additions & 19 deletions extide/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java
Expand Up @@ -257,26 +257,41 @@ public Set<File> getProjectFiles() {
* @return
*/
public File getFile(Kind kind) {
switch (kind) {
case BUILD_SCRIPT:
return buildScript != null ? buildScript : new File(projectDir, BUILD_FILE_NAME);
case ROOT_SCRIPT:
return parentScript != null ? parentScript : new File(rootDir, BUILD_FILE_NAME);
case SETTINGS_SCRIPT:
return settingsScript != null ? settingsScript : new File(rootDir, SETTINGS_FILE_NAME);

case PROJECT_PROPERTIES:
return new File(projectDir, GRADLE_PROPERTIES_NAME);
case ROOT_PROPERTIES:
return new File(rootDir, GRADLE_PROPERTIES_NAME);
case USER_PROPERTIES: {
File guh = GradleSettings.getDefault().getGradleUserHome();
return new File(guh, GRADLE_PROPERTIES_NAME);
if (isBuildSrcProject()) {
switch (kind) {
case BUILD_SCRIPT:
return buildScript != null ? buildScript : new File(projectDir, BUILD_FILE_NAME);
case PROJECT_PROPERTIES:
return new File(projectDir, GRADLE_PROPERTIES_NAME);
case USER_PROPERTIES: {
File guh = GradleSettings.getDefault().getGradleUserHome();
return new File(guh, GRADLE_PROPERTIES_NAME);
}
default:
return null;
}
} else {
switch (kind) {
case BUILD_SCRIPT:
return buildScript != null ? buildScript : new File(projectDir, BUILD_FILE_NAME);
case ROOT_SCRIPT:
return parentScript != null ? parentScript : new File(rootDir, BUILD_FILE_NAME);
case SETTINGS_SCRIPT:
return settingsScript != null ? settingsScript : new File(rootDir, SETTINGS_FILE_NAME);

case PROJECT_PROPERTIES:
return new File(projectDir, GRADLE_PROPERTIES_NAME);
case ROOT_PROPERTIES:
return new File(rootDir, GRADLE_PROPERTIES_NAME);
case USER_PROPERTIES: {
File guh = GradleSettings.getDefault().getGradleUserHome();
return new File(guh, GRADLE_PROPERTIES_NAME);
}
case BUILD_SRC:
return new File(rootDir, "buildSrc"); //NOI18N
default:
return null;
}
case BUILD_SRC:
return isBuildSrcProject() ? null : new File(rootDir, "buildSrc"); //NOI18N
default:
return null;
}
}

Expand Down
@@ -0,0 +1,132 @@
/*
* 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.nodes;

import java.io.IOException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.gradle.AbstractGradleProjectTestCase;
import org.netbeans.modules.gradle.NbGradleProjectImpl;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.LocalFileSystem;
import org.openide.nodes.Node;

/**
*
* @author lkishalmi
*/
public class BuildScriptsNodeTest extends AbstractGradleProjectTestCase {

private FileObject root;

public BuildScriptsNodeTest(String name) {
super(name);
}

@Override
protected void setUp() throws Exception {
super.setUp();
LocalFileSystem fs = new LocalFileSystem();
fs.setRootDirectory(getWorkDir());
root = fs.getRoot();
}

@Test
public void testGradleOnRoot() throws Exception {
FileObject a = createGradleProject("projectA",
"apply plugin: 'java'\n", "");
Project prjA = ProjectManager.getDefault().findProject(a);
BuildScriptsNode node = new BuildScriptsNode((NbGradleProjectImpl)prjA);
Node build = childNodeFor(node, a.getFileObject("build.gradle"));
assertNotNull(build);
assertEquals("build.gradle", build.getDisplayName());
Node settings = childNodeFor(node, a.getFileObject("settings.gradle"));
assertNotNull(settings);
assertEquals("settings.gradle", settings.getDisplayName());
assertNull(node.getChildren().findChild("buildSrc"));
}

@Test
public void testGradleWithBuildSrc() throws Exception {
FileObject a = createGradleProject("projectA",
"apply plugin: 'java'\n", "");
FileObject b = a.createFolder("buildSrc");
Project prjA = ProjectManager.getDefault().findProject(a);
BuildScriptsNode node = new BuildScriptsNode((NbGradleProjectImpl)prjA);
Node build = childNodeFor(node, a.getFileObject("build.gradle"));
assertNotNull(build);
assertEquals("build.gradle", build.getDisplayName());
Node settings = childNodeFor(node, a.getFileObject("settings.gradle"));
assertNotNull(settings);
assertEquals("settings.gradle", settings.getDisplayName());
Node buildSrc = childNodeFor(node, b);
assertNotNull(buildSrc);
}

@Test
public void testGradleOnBuildSrc() throws Exception {
FileObject a = createGradleProject("projectA",
"apply plugin: 'java'\n", "");
FileObject b = a.createFolder("buildSrc");
Project prjA = ProjectManager.getDefault().findProject(a);
Project prjB = ProjectManager.getDefault().findProject(b);
BuildScriptsNode node = new BuildScriptsNode((NbGradleProjectImpl)prjB);
assertNull(childNodeFor(node, b));
assertNull(childNodeFor(node, a.getFileObject("build.gradle")));
assertNull(childNodeFor(node, a.getFileObject("settings.gradle")));
}

@Test
public void testGradleWithSubProject() throws Exception {
FileObject a = createGradleProject("projectA",
"", "include 'projectB'");
FileObject gprops = a.createData("gradle.properties");
FileObject b = createGradleProject("projectA/projectB",
"apply plugin: 'java'\n", null);
Project prjA = ProjectManager.getDefault().findProject(a);
Project prjB = ProjectManager.getDefault().findProject(b);
BuildScriptsNode node = new BuildScriptsNode((NbGradleProjectImpl)prjB);
Node build = node.getChildren().findChild("build");
assertNotNull(build);
assertEquals("build.gradle [root]", build.getDisplayName());
Node settings = node.getChildren().findChild("settings");
assertNotNull(settings);
assertEquals("settings.gradle", settings.getDisplayName());
Node gradle = childNodeFor(node, gprops);
assertNotNull(gradle);
assertEquals("gradle.properties [root]", gradle.getDisplayName());

}

private static Node childNodeFor(Node node, FileObject fo) {
for (Node child : node.getChildren().getNodes(true)) {
FileObject cfo = child.getLookup().lookup(FileObject.class);
if (fo.equals(cfo)) {
return child;
}
}
return null;
}
}

0 comments on commit 5894b30

Please sign in to comment.