KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > RubySharabilityQuery


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ruby.rubyproject;
21
22 import java.io.File JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
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 /**
33  * SharabilityQueryImplementation for j2seproject with multiple sources
34  */

35 public class RubySharabilityQuery implements SharabilityQueryImplementation, PropertyChangeListener JavaDoc {
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     /**
44      * Creates new RubySharabilityQuery
45      * @param helper RakeProjectHelper
46      * @param evaluator PropertyEvaluator
47      * @param srcRoots sources
48      * @param testRoots tests
49      */

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     /**
60      * Check whether a file or directory should be shared.
61      * If it is, it ought to be committed to a VCS if the user is using one.
62      * If it is not, it is either a disposable build product, or a per-user
63      * private file which is important but should not be shared.
64      * @param file a file to check for sharability (may or may not yet exist)
65      * @return one of {@link org.netbeans.api.queries.SharabilityQuery}'s constants
66      */

67     public int getSharability(final File JavaDoc file) {
68         return ProjectManager.mutex().readAccess(new Mutex.Action<Integer JavaDoc>() {
69             public Integer JavaDoc 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 JavaDoc 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 JavaDoc[] srcProps = srcRoots.getRootProperties();
90         String JavaDoc[] testProps = testRoots.getRootProperties();
91         String JavaDoc[] props = new String JavaDoc [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 JavaDoc[] {
100                 "${" + RubyProjectProperties.DIST_DIR + "}", // NOI18N
101
"${" + RubyProjectProperties.BUILD_DIR + "}", // NOI18N
102
});
103     }
104
105 }
106
Popular Tags