1 19 package org.netbeans.modules.java.j2seproject.classpath; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.util.List ; 25 import java.util.ArrayList ; 26 import java.util.Collections ; 27 import java.beans.PropertyChangeListener ; 28 import java.beans.PropertyChangeSupport ; 29 import java.net.URI ; 30 import java.net.URL ; 31 import org.netbeans.spi.java.classpath.ClassPathImplementation; 32 import org.netbeans.spi.java.classpath.PathResourceImplementation; 33 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 34 import org.netbeans.modules.java.j2seproject.SourceRoots; 35 import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; 36 import org.netbeans.spi.java.classpath.FilteringPathResourceImplementation; 37 import org.netbeans.spi.java.classpath.support.PathResourceBase; 38 import org.netbeans.spi.project.support.ant.AntProjectHelper; 39 import org.netbeans.spi.project.support.ant.PathMatcher; 40 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 41 import org.openide.ErrorManager; 42 import org.openide.util.WeakListeners; 43 44 47 final class SourcePathImplementation implements ClassPathImplementation, PropertyChangeListener { 48 49 private static final String PROP_BUILD_DIR = "build.dir"; 51 private final PropertyChangeSupport support = new PropertyChangeSupport (this); 52 private List <PathResourceImplementation> resources; 53 private final SourceRoots sourceRoots; 54 private final AntProjectHelper projectHelper; 55 private final PropertyEvaluator evaluator; 56 57 62 public SourcePathImplementation(SourceRoots sourceRoots, AntProjectHelper projectHelper, PropertyEvaluator evaluator) { 63 assert sourceRoots != null && projectHelper != null && evaluator != null; 64 this.sourceRoots = sourceRoots; 65 sourceRoots.addPropertyChangeListener (this); 66 this.projectHelper = projectHelper; 67 this.evaluator = evaluator; 68 evaluator.addPropertyChangeListener (this); 69 } 70 71 public List <PathResourceImplementation> getResources() { 72 synchronized (this) { 73 if (this.resources != null) { 74 return this.resources; 75 } 76 } 77 URL [] roots = sourceRoots.getRootURLs(); 78 synchronized (this) { 79 if (this.resources == null) { 80 List <PathResourceImplementation> result = new ArrayList <PathResourceImplementation>(roots.length); 81 for (final URL root : roots) { 82 class PRI implements FilteringPathResourceImplementation, PropertyChangeListener { 83 PropertyChangeSupport pcs = new PropertyChangeSupport (this); 84 PathMatcher matcher; 85 PRI() { 86 evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator)); 87 } 88 public URL [] getRoots() { 89 return new URL [] {root}; 90 } 91 public boolean includes(URL root, String resource) { 92 if (matcher == null) { 93 matcher = new PathMatcher( 94 evaluator.getProperty(J2SEProjectProperties.INCLUDES), 95 evaluator.getProperty(J2SEProjectProperties.EXCLUDES), 96 new File (URI.create(root.toExternalForm()))); 97 } 98 return matcher.matches(resource, true); 99 } 100 public ClassPathImplementation getContent() { 101 return null; 102 } 103 public void addPropertyChangeListener(PropertyChangeListener listener) { 104 pcs.addPropertyChangeListener(listener); 105 } 106 public void removePropertyChangeListener(PropertyChangeListener listener) { 107 pcs.removePropertyChangeListener(listener); 108 } 109 public void propertyChange(PropertyChangeEvent ev) { 110 String prop = ev.getPropertyName(); 111 if (prop == null || prop.equals(J2SEProjectProperties.INCLUDES) || prop.equals(J2SEProjectProperties.EXCLUDES)) { 112 matcher = null; 113 PropertyChangeEvent ev2 = new PropertyChangeEvent (this, FilteringPathResourceImplementation.PROP_INCLUDES, null, null); 114 ev2.setPropagationId(ev); 115 pcs.firePropertyChange(ev2); 116 } 117 } 118 } 119 result.add(new PRI()); 120 } 121 if (!sourceRoots.isTest()) { 123 try { 124 String buildDir = this.evaluator.getProperty(PROP_BUILD_DIR); 125 if (buildDir != null) { 126 File f = new File (this.projectHelper.resolveFile (buildDir),"generated/wsclient"); URL url = f.toURI().toURL(); 129 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 133 result.add(ClassPathSupport.createResource(url)); 134 135 f = new File (projectHelper.resolveFile(buildDir),"generated/wsimport/client"); url = f.toURI().toURL(); 138 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 142 result.add(ClassPathSupport.createResource(url)); 143 } 144 } catch (MalformedURLException ex) { 145 ErrorManager.getDefault ().notify (ex); 146 } 147 } 148 this.resources = Collections.unmodifiableList(result); 149 } 150 return this.resources; 151 } 152 } 153 154 public void addPropertyChangeListener(PropertyChangeListener listener) { 155 support.addPropertyChangeListener (listener); 156 } 157 158 public void removePropertyChangeListener(PropertyChangeListener listener) { 159 support.removePropertyChangeListener (listener); 160 } 161 162 163 public void propertyChange(PropertyChangeEvent evt) { 164 if (SourceRoots.PROP_ROOTS.equals (evt.getPropertyName())) { 165 synchronized (this) { 166 this.resources = null; 167 } 168 this.support.firePropertyChange (PROP_RESOURCES,null,null); 169 } 170 else if (this.evaluator != null && evt.getSource() == this.evaluator && 171 (evt.getPropertyName() == null || PROP_BUILD_DIR.equals(evt.getPropertyName()))) { 172 synchronized (this) { 173 this.resources = null; 174 } 175 this.support.firePropertyChange (PROP_RESOURCES,null,null); 176 } 177 } 178 179 } 180 | Popular Tags |