SDK:
- small synchronization cleanups in ProjectAssetManager git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10113 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
3a809e61f5
commit
02964b1c0d
@ -73,15 +73,16 @@ import org.openide.util.lookup.Lookups;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class ProjectAssetManager extends DesktopAssetManager {
|
public class ProjectAssetManager extends DesktopAssetManager {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(ProjectAssetManager.class.getName());
|
private static final Logger logger = Logger.getLogger(ProjectAssetManager.class.getName());
|
||||||
private Project project;
|
private Project project;
|
||||||
|
private URLClassLoader loader;
|
||||||
private List<String> folderNames = new LinkedList<String>();
|
private List<String> folderNames = new LinkedList<String>();
|
||||||
|
private LinkedList<FileObject> jarItems = new LinkedList<FileObject>();
|
||||||
private final List<AssetEventListener> assetEventListeners = Collections.synchronizedList(new LinkedList<AssetEventListener>());
|
private final List<AssetEventListener> assetEventListeners = Collections.synchronizedList(new LinkedList<AssetEventListener>());
|
||||||
private final List<ClassPathChangeListener> classPathListeners = Collections.synchronizedList(new LinkedList<ClassPathChangeListener>());
|
private final List<ClassPathChangeListener> classPathListeners = Collections.synchronizedList(new LinkedList<ClassPathChangeListener>());
|
||||||
private URLClassLoader loader;
|
|
||||||
private final List<ClassPath> classPaths = Collections.synchronizedList(new LinkedList<ClassPath>());
|
private final List<ClassPath> classPaths = Collections.synchronizedList(new LinkedList<ClassPath>());
|
||||||
private final List<ClassPathItem> classPathItems = Collections.synchronizedList(new LinkedList<ClassPathItem>());
|
private final List<ClassPathItem> classPathItems = Collections.synchronizedList(new LinkedList<ClassPathItem>());
|
||||||
private LinkedList<FileObject> jarItems = new LinkedList<FileObject>();
|
|
||||||
private final Mutex mutex = new Mutex();
|
private final Mutex mutex = new Mutex();
|
||||||
|
|
||||||
public ProjectAssetManager(Project prj, String folderName) {
|
public ProjectAssetManager(Project prj, String folderName) {
|
||||||
@ -137,7 +138,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|||||||
classPaths.clear();
|
classPaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void loadClassLoader() {
|
private void loadClassLoader() {
|
||||||
Sources sources = ProjectUtils.getSources(project);
|
Sources sources = ProjectUtils.getSources(project);
|
||||||
if (sources != null) {
|
if (sources != null) {
|
||||||
if (loader != null) {
|
if (loader != null) {
|
||||||
@ -215,7 +216,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private synchronized void updateClassLoader() {
|
private void updateClassLoader() {
|
||||||
ProjectManager.mutex().postWriteRequest(new Runnable() {
|
ProjectManager.mutex().postWriteRequest(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
synchronized (classPathItems) {
|
synchronized (classPathItems) {
|
||||||
@ -328,12 +329,12 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|||||||
return filesWithSuffix("j3md");
|
return filesWithSuffix("j3md");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getAssetsWithSuffix(String string){
|
public String[] getAssetsWithSuffix(String string) {
|
||||||
return filesWithSuffix(string);
|
return filesWithSuffix(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] filesWithSuffix(String string){
|
private String[] filesWithSuffix(String string) {
|
||||||
List<String> list=collectFilesWithSuffix(string);
|
List<String> list = collectFilesWithSuffix(string);
|
||||||
return list.toArray(new String[list.size()]);
|
return list.toArray(new String[list.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,24 +357,21 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classPathItems != null) {
|
synchronized (classPathItems) {
|
||||||
synchronized (classPathItems) {
|
// TODO I need to find out if classPathItems contains all jars added to a project
|
||||||
// TODO I need to find out if classPathItems contains all jars added to a project
|
Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
|
||||||
Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
|
while (classPathItemsIter.hasNext()) {
|
||||||
while (classPathItemsIter.hasNext()) {
|
ClassPathItem classPathItem = classPathItemsIter.next();
|
||||||
ClassPathItem classPathItem = classPathItemsIter.next();
|
FileObject jarFile = classPathItem.object;
|
||||||
FileObject jarFile = classPathItem.object;
|
|
||||||
|
|
||||||
Enumeration<FileObject> jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
|
Enumeration<FileObject> jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
|
||||||
while (jarEntry.hasMoreElements()) {
|
while (jarEntry.hasMoreElements()) {
|
||||||
FileObject jarEntryAsset = jarEntry.nextElement();
|
FileObject jarEntryAsset = jarEntry.nextElement();
|
||||||
if (jarEntryAsset.getExt().equalsIgnoreCase(suffix)) {
|
if (jarEntryAsset.getExt().equalsIgnoreCase(suffix)) {
|
||||||
if (!jarEntryAsset.getPath().startsWith("/")) {
|
if (!jarEntryAsset.getPath().startsWith("/")) {
|
||||||
list.add(jarEntryAsset.getPath());
|
list.add(jarEntryAsset.getPath());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -384,24 +382,22 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|||||||
public InputStream getResourceAsStream(String name) {
|
public InputStream getResourceAsStream(String name) {
|
||||||
InputStream in = null;//JmeSystem.getResourceAsStream(name);
|
InputStream in = null;//JmeSystem.getResourceAsStream(name);
|
||||||
synchronized (classPathItems) {
|
synchronized (classPathItems) {
|
||||||
if (in == null && classPathItems != null) {
|
// TODO I need to find out if classPathItems contains all jars added to a project
|
||||||
// TODO I need to find out if classPathItems contains all jars added to a project
|
Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
|
||||||
Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
|
while (classPathItemsIter.hasNext()) {
|
||||||
while (classPathItemsIter.hasNext()) {
|
ClassPathItem classPathItem = classPathItemsIter.next();
|
||||||
ClassPathItem classPathItem = classPathItemsIter.next();
|
FileObject jarFile = classPathItem.object;
|
||||||
FileObject jarFile = classPathItem.object;
|
|
||||||
|
|
||||||
Enumeration<FileObject> jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
|
Enumeration<FileObject> jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
|
||||||
while (jarEntry.hasMoreElements()) {
|
while (jarEntry.hasMoreElements()) {
|
||||||
FileObject jarEntryAsset = jarEntry.nextElement();
|
FileObject jarEntryAsset = jarEntry.nextElement();
|
||||||
if (jarEntryAsset.getPath().equalsIgnoreCase(name)) {
|
if (jarEntryAsset.getPath().equalsIgnoreCase(name)) {
|
||||||
try {
|
try {
|
||||||
in = jarEntryAsset.getInputStream();
|
in = jarEntryAsset.getInputStream();
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
Exceptions.printStackTrace(ex);
|
Exceptions.printStackTrace(ex);
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user