From 70d600bc245e48548634814ba276ee01b5b1b11b Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Wed, 9 Nov 2011 00:39:33 +0000 Subject: [PATCH] - add project classpath items to ProjectAssetManager as UrlLocators git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8609 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../gde/core/assets/ProjectAssetManager.java | 60 ++++++++++++------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java b/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java index 2a6232474..c2fd3dd1b 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java @@ -68,6 +68,7 @@ public class ProjectAssetManager extends DesktopAssetManager { private List folderNames = new LinkedList(); private List assetEventListeners = new LinkedList(); private URLClassLoader loader; + private LinkedList classPathItems = new LinkedList(); public ProjectAssetManager(Project prj, String folderName) { super(true); @@ -82,9 +83,39 @@ public class ProjectAssetManager extends DesktopAssetManager { 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() { + 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); if (sources != null) { if (loader != null) { @@ -95,11 +126,16 @@ public class ProjectAssetManager extends DesktopAssetManager { for (SourceGroup sourceGroup : groups) { ClassPath path = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.EXECUTE); if (path != null) { - System.out.println("Classpath: " + path); try { FileObject[] roots = path.getRoots(); 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) { 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() { setAssetEventListener(new AssetEventListener() {