- add project classpath items to ProjectAssetManager as UrlLocators

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8609 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent 01e7ae48b4
commit 70d600bc24
  1. 60
      sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java

@ -68,6 +68,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
private List<String> folderNames = new LinkedList<String>(); private List<String> folderNames = new LinkedList<String>();
private List<AssetEventListener> assetEventListeners = new LinkedList<AssetEventListener>(); private List<AssetEventListener> assetEventListeners = new LinkedList<AssetEventListener>();
private URLClassLoader loader; private URLClassLoader loader;
private LinkedList<FileObject> classPathItems = new LinkedList<FileObject>();
public ProjectAssetManager(Project prj, String folderName) { public ProjectAssetManager(Project prj, String folderName) {
super(true); super(true);
@ -82,9 +83,39 @@ public class ProjectAssetManager extends DesktopAssetManager {
updateClassLoader(); updateClassLoader();
} }
}); });
prepAssetEventListeners();
}
public ProjectAssetManager(FileObject path) {
super(true);
if (path == null) {
this.project = new DummyProject(this);
} else {
this.project = new DummyProject(this, path);
}
String string = project.getProjectDirectory().getPath();
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Add locator: {0}", string);
registerLocator(string, "com.jme3.asset.plugins.FileLocator");
for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) {
di.prepareManager(this);
}
prepAssetEventListeners();
}
public ProjectAssetManager() {
this(null);
} }
public void updateClassLoader() { public void updateClassLoader() {
for (FileObject fileObject : classPathItems) {
try {
unregisterLocator(fileObject.getURL().toExternalForm(),
com.jme3.asset.plugins.UrlLocator.class);
} catch (FileStateInvalidException ex) {
Exceptions.printStackTrace(ex);
}
}
classPathItems.clear();
Sources sources = project.getLookup().lookup(Sources.class); Sources sources = project.getLookup().lookup(Sources.class);
if (sources != null) { if (sources != null) {
if (loader != null) { if (loader != null) {
@ -95,11 +126,16 @@ public class ProjectAssetManager extends DesktopAssetManager {
for (SourceGroup sourceGroup : groups) { for (SourceGroup sourceGroup : groups) {
ClassPath path = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.EXECUTE); ClassPath path = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.EXECUTE);
if (path != null) { if (path != null) {
System.out.println("Classpath: " + path);
try { try {
FileObject[] roots = path.getRoots(); FileObject[] roots = path.getRoots();
for (FileObject fileObject : roots) { for (FileObject fileObject : roots) {
urls.add(fileObject.getURL()); if(fileObject.getURL().toExternalForm().startsWith("jar")){
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Add classpath locator:{0}", fileObject.getURL());
urls.add(fileObject.getURL());
classPathItems.add(fileObject);
registerLocator(fileObject.getURL().toExternalForm(),
"com.jme3.asset.plugins.UrlLocator");
}
} }
} catch (FileStateInvalidException ex) { } catch (FileStateInvalidException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
@ -111,26 +147,6 @@ public class ProjectAssetManager extends DesktopAssetManager {
} }
} }
public ProjectAssetManager(FileObject path) {
super(true);
if (path == null) {
this.project = new DummyProject(this);
} else {
this.project = new DummyProject(this, path);
}
String string = project.getProjectDirectory().getPath();
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Add locator: {0}", string);
registerLocator(string, "com.jme3.asset.plugins.FileLocator");
for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) {
di.prepareManager(this);
}
prepAssetEventListeners();
}
public ProjectAssetManager() {
this(null);
}
private void prepAssetEventListeners() { private void prepAssetEventListeners() {
setAssetEventListener(new AssetEventListener() { setAssetEventListener(new AssetEventListener() {

Loading…
Cancel
Save