1 19 package org.netbeans.modules.web.project; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import org.openide.filesystems.FileObject; 24 import org.netbeans.api.queries.FileBuiltQuery; 25 import org.netbeans.spi.queries.FileBuiltQueryImplementation; 26 import org.netbeans.spi.project.support.ant.AntProjectHelper; 27 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 28 import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; 29 30 public class WebFileBuiltQuery implements FileBuiltQueryImplementation, PropertyChangeListener { 31 32 private FileBuiltQueryImplementation delegate; 33 private final AntProjectHelper helper; 34 private final PropertyEvaluator evaluator; 35 private final SourceRoots sourceRoots; 36 private final SourceRoots testRoots; 37 38 WebFileBuiltQuery (AntProjectHelper helper, PropertyEvaluator evaluator, 39 SourceRoots sourceRoots, SourceRoots testRoots) { 40 this.helper = helper; 41 this.evaluator = evaluator; 42 this.sourceRoots = sourceRoots; 43 this.testRoots = testRoots; 44 } 45 46 public synchronized FileBuiltQuery.Status getStatus(FileObject file) { 47 if (this.delegate == null) { 48 this.delegate = createDelegate (); 49 } 50 return this.delegate.getStatus (file); 51 } 52 53 private FileBuiltQueryImplementation createDelegate () { 54 String [] srcRoots = this.sourceRoots.getRootProperties(); 55 String [] tstRoots = this.testRoots.getRootProperties(); 56 String [] from = new String [srcRoots.length + tstRoots.length]; 57 String [] to = new String [srcRoots.length + tstRoots.length]; 58 for (int i=0; i< srcRoots.length; i++) { 59 from[i] = "${" + srcRoots[i] + "}/*.java"; to[i] = "${" + WebProjectProperties.BUILD_CLASSES_DIR + "}/*.class"; } 62 for (int i=0; i<tstRoots.length; i++) { 63 from[srcRoots.length+i] = "${" + tstRoots[i] + "}/*.java"; to[srcRoots.length+i] = "${" + WebProjectProperties.BUILD_TEST_CLASSES_DIR + "}/*.class"; } 66 return helper.createGlobFileBuiltQuery(evaluator, from, to); 67 } 68 69 public void propertyChange(PropertyChangeEvent evt) { 70 if (SourceRoots.PROP_ROOT_PROPERTIES.equals (evt.getPropertyName())) { 71 synchronized(this) { 72 this.delegate = null; 73 } 75 } 76 } 77 } 78 | Popular Tags |