1 19 20 package org.netbeans.modules.ruby.rubyproject; 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.modules.ruby.spi.project.support.rake.RakeProjectHelper; 29 import org.netbeans.modules.ruby.spi.project.support.rake.PropertyEvaluator; 30 import org.netbeans.modules.ruby.rubyproject.ui.customizer.RubyProjectProperties; 31 32 35 public class RubySharabilityQuery implements SharabilityQueryImplementation, PropertyChangeListener { 36 37 private final RakeProjectHelper helper; 38 private final PropertyEvaluator evaluator; 39 private final SourceRoots srcRoots; 40 private final SourceRoots testRoots; 41 private SharabilityQueryImplementation delegate; 42 43 50 RubySharabilityQuery (RakeProjectHelper 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 67 public int getSharability(final File file) { 68 return ProjectManager.mutex().readAccess(new Mutex.Action<Integer >() { 69 public Integer run() { 70 synchronized (RubySharabilityQuery.this) { 71 if (delegate == null) { 72 delegate = createDelegate (); 73 } 74 return delegate.getSharability(file); 75 } 76 } 77 }); 78 } 79 80 public void propertyChange(PropertyChangeEvent evt) { 81 if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) { 82 synchronized (this) { 83 this.delegate = null; 84 } 85 } 86 } 87 88 private SharabilityQueryImplementation createDelegate () { 89 String [] srcProps = srcRoots.getRootProperties(); 90 String [] testProps = testRoots.getRootProperties(); 91 String [] props = new String [srcProps.length + testProps.length]; 92 for (int i=0; i<srcProps.length; i++) { 93 props[i] = "${"+srcProps[i]+"}"; 94 } 95 for (int i=0; i<testProps.length; i++) { 96 props[srcProps.length+i] = "${"+testProps[i]+"}"; 97 } 98 return helper.createSharabilityQuery(this.evaluator, props, 99 new String [] { 100 "${" + RubyProjectProperties.DIST_DIR + "}", "${" + RubyProjectProperties.BUILD_DIR + "}", }); 103 } 104 105 } 106 | Popular Tags |