Skip to content

Commit

Permalink
If there is a sibling folder named "webapp" of a source folder, it wi…
Browse files Browse the repository at this point in the history
…ll be listed in the project view.
  • Loading branch information
kelemen committed Sep 22, 2012
1 parent 388b17c commit a82168c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/org/netbeans/gradle/project/CollectionUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.netbeans.gradle.project;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public final class CollectionUtils {
public static <E> List<E> copyNullSafeList(List<? extends E> list) {
public static <E> List<E> copyNullSafeList(Collection<? extends E> list) {
if (list == null) throw new NullPointerException("list");

List<E> result = Collections.unmodifiableList(new ArrayList<E>(list));
Expand Down
23 changes: 22 additions & 1 deletion src/org/netbeans/gradle/project/model/GradleModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static NbGradleModel createEmptyModel(FileObject projectDir) throws IOExc

NbGradleModule mainModule = new NbGradleModule(properties,
Collections.<NbSourceType, NbSourceGroup>emptyMap(),
Collections.<File>emptyList(),
Collections.<NbDependencyType, NbDependencyGroup>emptyMap(),
Collections.<NbGradleModule>emptyList());

Expand Down Expand Up @@ -314,6 +315,25 @@ private static List<IdeaModule> getChildModules(IdeaModule mainModule) {
return result;
}

private static List<File> lookupListedDirs(Map<NbSourceType, NbSourceGroup> sources) {
List<File> result = new LinkedList<File>();

NbSourceGroup sourceGroups = sources.get(NbSourceType.SOURCE);
if (sourceGroups != null) {
for (File sourceRoot: sourceGroups.getPaths()) {
File parent = sourceRoot.getParentFile();
if (parent != null) {
File webapp = new File(parent, "webapp");
if (webapp.isDirectory()) {
result.add(webapp);
}
}
}
}

return result;
}

private static NbGradleModule tryParseModule(IdeaModule module,
Map<String, NbGradleModule> parsedModules) {
String uniqueName = module.getGradleProject().getPath();
Expand Down Expand Up @@ -364,7 +384,8 @@ private static NbGradleModule tryParseModule(IdeaModule module,
createDefaultOutput(moduleDir),
taskNames);

NbGradleModule result = new NbGradleModule(properties, sources, dependencies, children);
List<File> listedDirs = lookupListedDirs(sources);
NbGradleModule result = new NbGradleModule(properties, sources, listedDirs, dependencies, children);
parsedModules.put(uniqueName, result);
return result;
}
Expand Down
15 changes: 10 additions & 5 deletions src/org/netbeans/gradle/project/model/NbGradleModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,32 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import org.netbeans.gradle.project.CollectionUtils;

public final class NbGradleModule {
private final Properties properties;
private final Map<NbSourceType, NbSourceGroup> sources;
private final Map<NbDependencyType, NbDependencyGroup> dependencies;
private final List<NbGradleModule> children;
private final List<File> listedDirs;

public NbGradleModule(
Properties properties,
Map<NbSourceType, NbSourceGroup> sources,
List<File> listedDirs,
Map<NbDependencyType, NbDependencyGroup> dependencies,
Collection<NbGradleModule> children) {

if (properties == null) throw new NullPointerException("properties");
if (dependencies == null) throw new NullPointerException("dependencies");
if (listedDirs == null) throw new NullPointerException("listedDirs");
if (children == null) throw new NullPointerException("children");

this.properties = properties;
this.sources = asImmutable(NbSourceType.class, sources);
this.listedDirs = CollectionUtils.copyNullSafeList(listedDirs);
this.dependencies = asImmutable(NbDependencyType.class, dependencies);
this.children = Collections.unmodifiableList(new ArrayList<NbGradleModule>(children));

for (NbGradleModule child: this.children) {
if (child == null) throw new NullPointerException("child");
}
this.children = CollectionUtils.copyNullSafeList(children);
}

private static <K extends Enum<K>, V> Map<K, V> asImmutable(
Expand Down Expand Up @@ -80,6 +81,10 @@ public Map<NbSourceType, NbSourceGroup> getSources() {
return sources;
}

public List<File> getListedDirs() {
return listedDirs;
}

public NbDependencyGroup getDependencies(NbDependencyType dependencyType) {
NbDependencyGroup result = dependencies.get(dependencyType);
return result != null ? result : NbDependencyGroup.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.netbeans.gradle.project.view;

import java.awt.Image;
import java.io.File;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Logger;
Expand All @@ -18,6 +19,7 @@
import org.netbeans.gradle.project.model.NbGradleModule;
import org.netbeans.spi.java.project.support.ui.PackageView;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
Expand Down Expand Up @@ -212,8 +214,24 @@ private void addSources(List<SingleNodeFactory> toPopulate) {
addSourceGroups(sources.getSourceGroups(GradleProjectConstants.TEST_RESOURCES), toPopulate);
}

private void addListedDirs(List<SingleNodeFactory> toPopulate) {
for (File listedDir: project.getCurrentModel().getMainModule().getListedDirs()) {
FileObject listedDirObj = FileUtil.toFileObject(listedDir);
if (listedDirObj != null) {
final DataFolder listedFolder = DataFolder.findFolder(listedDirObj);
toPopulate.add(new SingleNodeFactory() {
@Override
public Node createNode() {
return listedFolder.getNodeDelegate().cloneNode();
}
});
}
}
}

private void readKeys(List<SingleNodeFactory> toPopulate) throws DataObjectNotFoundException {
addSources(toPopulate);
addListedDirs(toPopulate);

addChildren(toPopulate);

Expand Down

0 comments on commit a82168c

Please sign in to comment.