Skip to content

Commit

Permalink
[NETBEANS-4891] Fix missing file node of generic Gradle root project
Browse files Browse the repository at this point in the history
  • Loading branch information
lkishalmi committed Oct 11, 2020
1 parent 1bfefb6 commit 82af896
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 95 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -360,6 +360,7 @@ matrix:
- hide-logs.sh ant $OPTS -f java/debugger.jpda.js test
- hide-logs.sh ant $OPTS -f java/debugger.jpda.projects test
- hide-logs.sh ant $OPTS -f java/debugger.jpda.projectsui test
- hide-logs.sh ant $OPTS -f java/gradle.java test
#- ant $OPTS -f java/debugger.jpda.truffle test
#- ant $OPTS -f java/debugger.jpda.ui test
- travis_wait hide-logs.sh ant $OPTS -f java/editor.htmlui test
Expand Down
@@ -0,0 +1,111 @@
/*
* 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.queries;

import java.beans.PropertyChangeListener;
import javax.swing.Icon;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.netbeans.modules.gradle.api.NbGradleProject;
import org.netbeans.spi.project.ProjectServiceProvider;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;

/**
*
* @author lkishalmi
*/
@ProjectServiceProvider(service = Sources.class, projectType = NbGradleProject.GRADLE_PROJECT_TYPE)
public class GenericProjectSources implements Sources {
private final Project project;

public GenericProjectSources(Project project) {
this.project = project;
}
@Override
public SourceGroup[] getSourceGroups(String type) {
return Sources.TYPE_GENERIC.equals(type)? new SourceGroup[]{new ProjectSourceGroup()} : new SourceGroup[0];
}

@Override
public void addChangeListener(ChangeListener listener) {
}

@Override
public void removeChangeListener(ChangeListener listener) {
}

private final class ProjectSourceGroup implements SourceGroup {

public ProjectSourceGroup() {
}

@Override
public FileObject getRootFolder() {
return project.getProjectDirectory();
}

@Override
public String getName() {
return ProjectUtils.getInformation(project).getName();
}

@Override
public String getDisplayName() {
return ProjectUtils.getInformation(project).getDisplayName();
}

@Override
public Icon getIcon(boolean opened) {
return null;
}

@Override
public boolean contains(FileObject file) {
FileObject rootFolder = getRootFolder();
if (file != rootFolder && !FileUtil.isParentOf(rootFolder, file)) {
return false;
}
if (file.isFolder() && file != rootFolder && ProjectManager.getDefault().isProject(file)) {
// #67450: avoid actually loading the nested project.
return false;
}
return FileOwnerQuery.getOwner(file) == project;
}

@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
}

@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
}

@Override
public String toString() {
return "ProjectSourceGroup: " + getDisplayName();
}
}

}
@@ -0,0 +1,53 @@
package org.netbeans.modules.gradle.queries;

import java.io.IOException;
import java.util.Random;
import static junit.framework.TestCase.assertFalse;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.netbeans.modules.gradle.AbstractGradleProjectTestCase;
import org.netbeans.modules.gradle.ProjectTrust;
import org.openide.filesystems.FileObject;
import org.openide.util.NbPreferences;

/*
* 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.
*/

/**
*
* @author lkishalmi
*/
public class GenericProjectSourcesTest extends AbstractGradleProjectTestCase {
public GenericProjectSourcesTest(String name) {
super(name);
}

public void testRootProjectSourceGroup() throws IOException {
int rnd = new Random().nextInt(1000000);
FileObject a = createGradleProject("projectA-" + rnd,
"", "");
Project p = ProjectManager.getDefault().findProject(a);
SourceGroup[] groups = ProjectUtils.getSources(p).getSourceGroups(Sources.TYPE_GENERIC);
assertEquals(1, groups.length);
}

}
1 change: 1 addition & 0 deletions java/gradle.java/nbproject/project.properties
Expand Up @@ -22,3 +22,4 @@ nbm.module.author=Laszlo Kishalmi

test-unit-sys-prop.test.netbeans.dest.dir=${netbeans.dest.dir}
test-unit-sys-prop.java.awt.headless=true
test.use.jdk.javac=true
9 changes: 4 additions & 5 deletions java/gradle.java/nbproject/project.xml
Expand Up @@ -305,11 +305,6 @@
<code-name-base>org.netbeans.libs.junit4</code-name-base>
<compile-dependency/>
</test-dependency>
<test-dependency>
<code-name-base>org.netbeans.modules.apisupport.project</code-name-base>
<compile-dependency/>
<test/>
</test-dependency>
<test-dependency>
<code-name-base>org.netbeans.modules.gradle</code-name-base>
<compile-dependency/>
Expand Down Expand Up @@ -344,6 +339,10 @@
<test/>
</test-dependency>
<test-dependency>
<code-name-base>org.openide.modules</code-name-base>
<run-dependency/>
<test/>
</test-dependency> <test-dependency>
<code-name-base>org.openide.util.ui</code-name-base>
<compile-dependency/>
<test/>
Expand Down
Expand Up @@ -44,7 +44,6 @@
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.netbeans.spi.project.ProjectServiceProvider;
Expand Down Expand Up @@ -152,10 +151,6 @@ public GradleSourcesImpl(Project proj) {

@Override
public synchronized SourceGroup[] getSourceGroups(String type) {
if (Sources.TYPE_GENERIC.equals(type)) {
return new SourceGroup[]{new GradleSourceGroup(proj.getProjectDirectory(), "ProjectRoot", //NOI18N
ProjectUtils.getInformation(proj).getDisplayName())};
}
checkChanges(false);
SourceType stype = soureType2SourceType(type);
if (stype != null) {
Expand Down

This file was deleted.

Expand Up @@ -24,7 +24,7 @@
import org.junit.Test;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.project.Project;
import org.netbeans.modules.gradle.java.AbstractGradleJavaTestCase;
import org.netbeans.modules.gradle.AbstractGradleProjectTestCase;
import org.netbeans.modules.gradle.java.api.GradleJavaProject;
import org.netbeans.spi.java.classpath.ClassPathProvider;
import org.openide.filesystems.FileObject;
Expand All @@ -34,7 +34,7 @@
*
* @author lkishalmi
*/
public class ClassPathProviderImplTest extends AbstractGradleJavaTestCase {
public class ClassPathProviderImplTest extends AbstractGradleProjectTestCase {

public ClassPathProviderImplTest(String name) {
super(name);
Expand Down
Expand Up @@ -18,20 +18,23 @@
*/
package org.netbeans.modules.gradle.java.classpath;

import java.io.IOException;
import static junit.framework.TestCase.assertEquals;
import org.netbeans.api.java.project.JavaProjectConstants;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.netbeans.modules.gradle.java.AbstractGradleJavaTestCase;
import org.netbeans.modules.gradle.AbstractGradleProjectTestCase;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;

/**
*
* @author lkishalmi
*/
public class GradleSourcesImplTest extends AbstractGradleJavaTestCase {
public class GradleSourcesImplTest extends AbstractGradleProjectTestCase {

public GradleSourcesImplTest(String name) {
super(name);
Expand All @@ -55,4 +58,12 @@ public void testGeneratedSources() throws Exception { // #187595
assertFalse(groups[1].contains(source));
}

public void testRootProjectSourceGroup() throws IOException {
FileObject d = createGradleProject(
"apply plugin: 'java'\n" +
"sourceSets { main { java { srcDirs = [ 'src', 'build/gen-src' ] }}}");
Project p = ProjectManager.getDefault().findProject(d);
SourceGroup[] groups = ProjectUtils.getSources(p).getSourceGroups(Sources.TYPE_GENERIC);
assertEquals(1, groups.length);
}
}

0 comments on commit 82af896

Please sign in to comment.