|
@@ -37,6 +37,7 @@ import com.jme3.asset.AssetManager;
|
|
|
import com.jme3.asset.DesktopAssetManager;
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
+import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
@@ -45,9 +46,11 @@ import java.net.URLClassLoader;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Enumeration;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import java.util.logging.Level;
|
|
|
import java.util.logging.Logger;
|
|
|
import org.netbeans.api.java.classpath.ClassPath;
|
|
@@ -57,6 +60,9 @@ 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.GradleBaseProject;
|
|
|
+import org.netbeans.modules.gradle.java.api.GradleJavaProject;
|
|
|
+import org.netbeans.modules.gradle.java.api.GradleJavaSourceSet;
|
|
|
import org.openide.DialogDisplayer;
|
|
|
import org.openide.NotifyDescriptor;
|
|
|
import org.openide.filesystems.FileAttributeEvent;
|
|
@@ -179,6 +185,46 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Gradle
|
|
|
+ FileObject rootDir = FileUtil.toFileObject(GradleBaseProject.get(project).getRootDir());
|
|
|
+ Set<File> runtimeFiles = new HashSet<>();
|
|
|
+ try {
|
|
|
+ Project rootPrj = ProjectManager.getDefault().findProject(rootDir);
|
|
|
+ GradleJavaProject rootGjp = GradleJavaProject.get(rootPrj);
|
|
|
+ for(GradleJavaSourceSet sourceSet : rootGjp.getSourceSets().values()) {
|
|
|
+ if(sourceSet.getName().equals("main")) {
|
|
|
+ runtimeFiles = sourceSet.getRuntimeClassPath();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException ex) {
|
|
|
+ Exceptions.printStackTrace(ex);
|
|
|
+ } catch (IllegalArgumentException ex) {
|
|
|
+ Exceptions.printStackTrace(ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(File file : runtimeFiles) {
|
|
|
+ // logger.info(file.getName() + " : " + file.getAbsolutePath());
|
|
|
+ FileObject fo = FileUtil.toFileObject(file);
|
|
|
+ if(fo != null && !fo.isFolder()) {
|
|
|
+ logger.info(fo.toURL().toExternalForm());
|
|
|
+ if (!fo.equals(getAssetFolder())) {
|
|
|
+ fo.addRecursiveListener(listener);
|
|
|
+ logger.log(Level.FINE, "Add classpath:{0}", fo);
|
|
|
+ classPathItems.add(new ClassPathItem(fo, listener));
|
|
|
+ urls.add(fo.toURL());
|
|
|
+ }
|
|
|
+ if (fo.toURL().toExternalForm().startsWith("jar")) {
|
|
|
+ logger.log(Level.FINE, "Add Gradle locator:{0}", fo.toURL());
|
|
|
+ jarItems.add(fo);
|
|
|
+ registerLocator(fo.toURL().toExternalForm(),
|
|
|
+ "com.jme3.asset.plugins.UrlLocator");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
|
|
|
addClassLoader(loader);
|
|
|
logger.log(Level.FINE, "Updated {0} classpath entries and {1} url locators for project {2}", new Object[]{classPathItems.size(), jarItems.size(), project.toString()});
|
|
@@ -225,7 +271,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- private void updateClassLoader() {
|
|
|
+ public void updateClassLoader() {
|
|
|
ProjectManager.mutex().postWriteRequest(new Runnable() {
|
|
|
public void run() {
|
|
|
synchronized (classPathItems) {
|
|
@@ -478,6 +524,11 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|
|
while (classPathItemsIter.hasNext()) {
|
|
|
ClassPathItem classPathItem = classPathItemsIter.next();
|
|
|
FileObject jarFile = classPathItem.object;
|
|
|
+
|
|
|
+ // Gradle projects don't know that the dependency is a Jar file
|
|
|
+ if (FileUtil.isArchiveFile(jarFile)) {
|
|
|
+ jarFile = FileUtil.getArchiveRoot(jarFile);
|
|
|
+ }
|
|
|
|
|
|
Enumeration<FileObject> jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
|
|
|
while (jarEntry.hasMoreElements()) {
|
|
@@ -488,6 +539,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
@@ -502,7 +554,14 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|
|
ClassPathItem classPathItem = classPathItemsIter.next();
|
|
|
FileObject jarFile = classPathItem.object;
|
|
|
|
|
|
- Enumeration<FileObject> jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
|
|
|
+ Enumeration<FileObject> jarEntry;
|
|
|
+ if (FileUtil.isArchiveFile(jarFile)) {
|
|
|
+ FileObject jarFileRoot = FileUtil.getArchiveRoot(jarFile);
|
|
|
+ jarEntry = (Enumeration<FileObject>) jarFileRoot.getChildren(true);
|
|
|
+ } else {
|
|
|
+ jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
|
|
|
+ }
|
|
|
+
|
|
|
while (jarEntry.hasMoreElements()) {
|
|
|
FileObject jarEntryAsset = jarEntry.nextElement();
|
|
|
if (jarEntryAsset.getPath().equalsIgnoreCase(name)) {
|