1 19 package org.netbeans.modules.ruby.railsprojects.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.URL ; 30 import org.netbeans.modules.ruby.railsprojects.SourceRoots; 31 import org.netbeans.modules.ruby.spi.project.support.rake.PropertyEvaluator; 32 import org.netbeans.modules.ruby.spi.project.support.rake.RakeProjectHelper; 33 import org.netbeans.spi.java.classpath.ClassPathImplementation; 34 import org.netbeans.spi.java.classpath.PathResourceImplementation; 35 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 36 import org.openide.ErrorManager; 37 38 41 final class SourcePathImplementation implements ClassPathImplementation, PropertyChangeListener { 42 43 private static final String PROP_BUILD_DIR = "build.dir"; 45 private final PropertyChangeSupport support = new PropertyChangeSupport (this); 46 private List <PathResourceImplementation> resources; 47 private final SourceRoots sourceRoots; 48 private final RakeProjectHelper projectHelper; 49 private final PropertyEvaluator evaluator; 50 51 55 public SourcePathImplementation(SourceRoots sourceRoots) { 56 assert sourceRoots != null; 57 this.sourceRoots = sourceRoots; 58 this.projectHelper = null; 59 this.evaluator = null; 60 sourceRoots.addPropertyChangeListener (this); 61 } 62 63 68 public SourcePathImplementation(SourceRoots sourceRoots, RakeProjectHelper projectHelper, PropertyEvaluator evaluator) { 69 assert sourceRoots != null && projectHelper != null && evaluator != null; 70 this.sourceRoots = sourceRoots; 71 sourceRoots.addPropertyChangeListener (this); 72 this.projectHelper = projectHelper; 73 this.evaluator = evaluator; 74 evaluator.addPropertyChangeListener (this); 75 } 76 77 public List <PathResourceImplementation> getResources() { 78 synchronized (this) { 79 if (this.resources != null) { 80 return this.resources; 81 } 82 } 83 URL [] roots = sourceRoots.getRootURLs(); 84 synchronized (this) { 85 if (this.resources == null) { 86 List <PathResourceImplementation> result = new ArrayList <PathResourceImplementation>(roots.length); 87 for (URL root : roots) { 88 result.add(ClassPathSupport.createResource(root)); 89 } 90 if (projectHelper!=null) { 92 try { 93 String buildDir = this.evaluator.getProperty(PROP_BUILD_DIR); 94 if (buildDir != null) { 95 File f = new File (this.projectHelper.resolveFile (buildDir),"generated/wsclient"); URL url = f.toURI().toURL(); 98 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 102 result.add(ClassPathSupport.createResource(url)); 103 104 f = new File (projectHelper.resolveFile(buildDir),"generated/wsimport/client"); url = f.toURI().toURL(); 107 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 111 result.add(ClassPathSupport.createResource(url)); 112 } 113 } catch (MalformedURLException ex) { 114 ErrorManager.getDefault ().notify (ex); 115 } 116 } 117 this.resources = Collections.unmodifiableList(result); 118 } 119 return this.resources; 120 } 121 } 122 123 public void addPropertyChangeListener(PropertyChangeListener listener) { 124 support.addPropertyChangeListener (listener); 125 } 126 127 public void removePropertyChangeListener(PropertyChangeListener listener) { 128 support.removePropertyChangeListener (listener); 129 } 130 131 132 public void propertyChange(PropertyChangeEvent evt) { 133 if (SourceRoots.PROP_ROOTS.equals (evt.getPropertyName())) { 134 synchronized (this) { 135 this.resources = null; 136 } 137 this.support.firePropertyChange (PROP_RESOURCES,null,null); 138 } 139 else if (this.evaluator != null && evt.getSource() == this.evaluator && 140 (evt.getPropertyName() == null || PROP_BUILD_DIR.equals(evt.getPropertyName()))) { 141 synchronized (this) { 142 this.resources = null; 143 } 144 this.support.firePropertyChange (PROP_RESOURCES,null,null); 145 } 146 } 147 148 } 149 | Popular Tags |