1 19 20 package org.netbeans.modules.web.project.classpath; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.io.File ; 24 import java.net.MalformedURLException ; 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.beans.PropertyChangeListener ; 29 import java.beans.PropertyChangeSupport ; 30 import java.net.URL ; 31 import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; 32 import org.netbeans.spi.java.classpath.ClassPathImplementation; 33 import org.netbeans.spi.java.classpath.PathResourceImplementation; 34 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 35 import org.netbeans.modules.web.project.SourceRoots; 36 import org.netbeans.spi.project.support.ant.AntProjectHelper; 37 import org.openide.ErrorManager; 38 39 42 final class SourcePathImplementation implements ClassPathImplementation, PropertyChangeListener { 43 44 private PropertyChangeSupport support = new PropertyChangeSupport (this); 45 private List resources; 46 private SourceRoots sourceRoots; 47 private AntProjectHelper projectHelper; 48 49 53 public SourcePathImplementation(SourceRoots sourceRoots) { 54 assert sourceRoots != null; 55 this.sourceRoots = sourceRoots; 56 this.sourceRoots.addPropertyChangeListener (this); 57 } 58 59 64 public SourcePathImplementation(SourceRoots sourceRoots, AntProjectHelper projectHelper) { 65 assert sourceRoots != null; 66 this.sourceRoots = sourceRoots; 67 this.sourceRoots.addPropertyChangeListener (this); 68 this.projectHelper=projectHelper; 69 } 70 71 public List getResources() { 72 synchronized (this) { 73 if (this.resources != null) { 74 return this.resources; 75 } 76 } 77 URL [] roots = this.sourceRoots.getRootURLs(); 78 String buildDir = projectHelper.getStandardPropertyEvaluator().getProperty(WebProjectProperties.BUILD_DIR); 79 synchronized (this) { 80 if (this.resources == null) { 81 List result = new ArrayList (roots.length); 82 for (int i = 0; i < roots.length; i++) { 83 PathResourceImplementation res = ClassPathSupport.createResource(roots[i]); 84 result.add (res); 85 } 86 if (projectHelper!=null) { 88 try { 89 if (buildDir!=null) { 90 File f = new File (projectHelper.resolveFile(buildDir),"generated/wsclient"); URL url = f.toURI().toURL(); 93 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 97 result.add(ClassPathSupport.createResource(url)); 98 f = new File (projectHelper.resolveFile(buildDir),"generated/wsimport/client"); url = f.toURI().toURL(); 101 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 105 result.add(ClassPathSupport.createResource(url)); 106 f = new File (projectHelper.resolveFile(buildDir),"generated/wsimport/service"); url = f.toURI().toURL(); 109 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 113 result.add(ClassPathSupport.createResource(url)); 114 } 115 } catch (MalformedURLException ex) { 116 ErrorManager.getDefault ().notify (ex); 117 } 118 } 119 this.resources = Collections.unmodifiableList(result); 120 } 121 } 122 return this.resources; 123 } 124 125 public void addPropertyChangeListener(PropertyChangeListener listener) { 126 support.addPropertyChangeListener (listener); 127 } 128 129 public void removePropertyChangeListener(PropertyChangeListener listener) { 130 support.removePropertyChangeListener (listener); 131 } 132 133 134 public void propertyChange(PropertyChangeEvent evt) { 135 if (SourceRoots.PROP_ROOTS.equals (evt.getPropertyName())) { 136 synchronized (this) { 137 this.resources = null; 138 } 139 this.support.firePropertyChange (PROP_RESOURCES,null,null); 140 } 141 } 142 143 } 144 | Popular Tags |