1 19 20 package org.netbeans.modules.web.project; 21 22 import java.io.File ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import org.openide.util.Mutex; 26 import org.netbeans.api.project.ProjectManager; 27 import org.netbeans.spi.queries.SharabilityQueryImplementation; 28 import org.netbeans.spi.project.support.ant.AntProjectHelper; 29 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 30 import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; 31 32 35 public class WebSharabilityQuery implements SharabilityQueryImplementation, PropertyChangeListener { 36 37 private final AntProjectHelper helper; 38 private final PropertyEvaluator evaluator; 39 private final SourceRoots srcRoots; 40 private final SourceRoots testRoots; 41 private SharabilityQueryImplementation delegate; 42 43 50 WebSharabilityQuery (AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots) { 51 this.helper = helper; 52 this.evaluator = evaluator; 53 this.srcRoots = srcRoots; 54 this.testRoots = testRoots; 55 this.srcRoots.addPropertyChangeListener(this); 56 this.testRoots.addPropertyChangeListener(this); 57 } 58 59 60 68 public int getSharability(final File file) { 69 Integer ret = (Integer ) ProjectManager.mutex().readAccess( new Mutex.Action() { 70 public Object run() { 71 synchronized (WebSharabilityQuery.this) { 72 if (delegate == null) { 73 delegate = createDelegate (); 74 } 75 return Integer.valueOf(delegate.getSharability (file)); 76 } 77 } 78 }); 79 return ret.intValue(); 80 } 81 82 public void propertyChange(PropertyChangeEvent evt) { 83 if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) { 84 synchronized (this) { 85 this.delegate = null; 86 } 87 } 88 } 89 90 private SharabilityQueryImplementation createDelegate () { 91 String [] srcProps = srcRoots.getRootProperties(); 92 String [] testProps = testRoots.getRootProperties(); 93 String [] props = new String [srcProps.length + testProps.length + 1]; 94 for (int i=0; i<srcProps.length; i++) { 95 props[i] = "${"+srcProps[i]+"}"; 96 } 97 for (int i=0; i<testProps.length; i++) { 98 props[srcProps.length+i] = "${"+testProps[i]+"}"; 99 } 100 props[props.length - 1] = "${" + WebProjectProperties.WEB_DOCBASE_DIR + "}"; 101 return helper.createSharabilityQuery(this.evaluator, props, 102 new String [] { 103 "${" + WebProjectProperties.DIST_DIR + "}", "${" + WebProjectProperties.BUILD_DIR + "}", }); 106 } 107 108 109 } 110 | Popular Tags |