Skip to content

Commit 0766c16

Browse files
committed
Gradle: Make the ProjectAssetManager work and expose the "Assets" Folder under the Project Dialog.
1 parent 0936e9c commit 0766c16

4 files changed

Lines changed: 117 additions & 18 deletions

File tree

jme3-core/src/com/jme3/gde/core/assets/AssetsLookupProvider.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@
3434
import com.jme3.gde.core.j2seproject.ProjectExtensionManager;
3535
import com.jme3.gde.core.j2seproject.actions.UpgradeProjectWizardAction;
3636
import com.jme3.gde.core.projects.SDKProjectUtils;
37+
import java.io.File;
3738
import java.io.IOException;
3839
import java.io.InputStream;
3940
import java.io.OutputStream;
41+
import java.nio.file.Path;
42+
import java.nio.file.Paths;
4043
import java.util.Properties;
4144
import java.util.logging.Level;
4245
import java.util.logging.Logger;
@@ -102,7 +105,29 @@ public Lookup createAdditionalLookup(Lookup lookup) {
102105
GradleBaseProject gradle = GradleBaseProject.get(project);
103106
if (gradle.getSubProjects().containsKey("assets")) {
104107
logger.log(Level.FINE, "Found assets subproject, extending with ProjectAssetManager");
105-
return Lookups.fixed(new ProjectAssetManager(prj, gradle.getSubProjects().get("assets").getAbsolutePath()));
108+
/* Note: The ProjectAssetManager needs the Subproject's Project,
109+
* because otherwise reading assets won't work (as assets is
110+
* not in the scope of the parent project). But it still needs
111+
* to be added to the Parent Project's Lookup
112+
*/
113+
114+
/* Complicated code to find the relative path, because the
115+
* assets subproject could be stored in a folder called "foo"
116+
* or "bar" and we still need to locate it correctly
117+
*/
118+
Path assetsPath = gradle.getSubProjects().get("assets").toPath();
119+
Path parentPath = new File(prj.getProjectDirectory().getPath()).toPath();
120+
Path relativePath = parentPath.relativize(assetsPath);
121+
try {
122+
Project assetsProj = ProjectManager.getDefault().findProject(
123+
prj.getProjectDirectory().getFileObject(relativePath.toString()));
124+
if (assetsProj != null) {
125+
return Lookups.fixed(new ProjectAssetManager(assetsProj,
126+
"")); // the String is seen relative to the project root
127+
}
128+
} catch (IOException io) {
129+
Exceptions.printStackTrace(io);
130+
}
106131
}
107132
} else {
108133
FileObject assetsProperties = prj.getProjectDirectory().getFileObject("nbproject/project.properties");

jme3-core/src/com/jme3/gde/core/assets/ProjectAssetsNodeFactory.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2010 jMonkeyEngine
2+
* Copyright (c) 2009-2020 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -37,41 +37,37 @@
3737
import org.netbeans.spi.project.ui.support.NodeFactorySupport;
3838
import org.netbeans.spi.project.ui.support.NodeList;
3939
import org.openide.loaders.DataObject;
40+
import org.openide.loaders.DataObjectNotFoundException;
4041
import org.openide.nodes.Node;
4142
import org.openide.util.Exceptions;
4243

4344
/**
44-
*
45+
* This Factory creates the visual "Project Assets" Node in the Project View
4546
* @author normenhansen
4647
*/
4748
@SuppressWarnings({"unchecked", "rawtypes"})
4849
public class ProjectAssetsNodeFactory implements NodeFactory {
49-
5050
private Project proj;
5151

52+
// return a new node for the project view if theres an assets folder
53+
@Override
5254
public NodeList createNodes(Project project) {
53-
5455
this.proj = project;
5556

56-
DataObject assetsFolder;
5757
try {
58-
//return a new node for the project view if theres an assets folder:
5958
ProjectAssetManager item = project.getLookup().lookup(ProjectAssetManager.class);
6059
if (item != null) {
61-
assetsFolder = DataObject.find(item.getAssetFolder());
62-
Node node = assetsFolder.getNodeDelegate();
63-
// return NodeFactorySupport.fixedNodeList(node);
64-
ProjectAssetsNode nd = new ProjectAssetsNode(item, proj, node);
65-
// return NodeFactorySupport.createCompositeChildren(project, item.getAssetFolderName());//fixedNodeList(nd);
60+
DataObject assetsFolder = DataObject.find(item.getAssetFolder());
61+
ProjectAssetsNode nd = new ProjectAssetsNode(item, proj, assetsFolder.getNodeDelegate());
6662
return NodeFactorySupport.fixedNodeList(nd);
6763
}
68-
} catch (Exception ex) {
64+
} catch (DataObjectNotFoundException ex) {
6965
Exceptions.printStackTrace(ex);
7066
}
7167

72-
//If our item isn't in the lookup,
73-
//then return an empty list of nodes:
68+
/* If our item isn't in the lookup, which means it is no recognized project
69+
* then return an empty list of nodes.
70+
*/
7471
return NodeFactorySupport.fixedNodeList();
75-
7672
}
7773
}

jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
/*
2-
* To change this template, choose Tools | Templates
3-
* and open the template in the editor.
2+
* Copyright (c) 2009-2020 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
431
*/
532
package com.jme3.gde.core.importantfiles;
633

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2009-2020 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.gde.core.projects;
33+
34+
import org.netbeans.api.project.Project;
35+
import org.netbeans.modules.gradle.api.GradleBaseProject;
36+
37+
/**
38+
* A collection of utility methods to guide the handling of Ant and Gradle Projects
39+
* within the SDK<br />
40+
*
41+
* @author MeFisto94
42+
*/
43+
44+
public class SDKProjectUtils {
45+
public static boolean isGradleProject(Project proj) {
46+
return proj.getClass().getSimpleName().equals("NbGradleProjectImpl") ||
47+
// because docs say this above is bad: https://bits.netbeans.org/dev/javadoc/org-netbeans-modules-projectapi/org/netbeans/api/project/Project.html
48+
GradleBaseProject.get(proj) != null;
49+
}
50+
51+
}

0 commit comments

Comments
 (0)