001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.cnd.makeproject;
043:
044: import java.io.File;
045: import org.netbeans.api.project.ProjectManager;
046: import org.netbeans.spi.queries.SharabilityQueryImplementation;
047: import org.openide.util.Mutex;
048: import org.netbeans.spi.queries.SharabilityQueryImplementation;
049: import org.netbeans.api.queries.SharabilityQuery;
050:
051: /**
052: * SharabilityQueryImplementation for j2seproject with multiple sources
053: */
054: public class MakeSharabilityQuery implements
055: SharabilityQueryImplementation {
056: private File baseDirFile;
057: private String baseDir;
058: private int baseDirLength;
059: private boolean privateShared;
060:
061: MakeSharabilityQuery(File baseDirFile) {
062: this .baseDirFile = baseDirFile;
063: this .baseDir = baseDirFile.getPath();
064: this .baseDirLength = this .baseDir.length();
065: privateShared = false;
066: }
067:
068: /**
069: * Check whether a file or directory should be shared.
070: * If it is, it ought to be committed to a VCS if the user is using one.
071: * If it is not, it is either a disposable build product, or a per-user
072: * private file which is important but should not be shared.
073: * @param file a file to check for sharability (may or may not yet exist)
074: * @return one of {@link org.netbeans.api.queries.SharabilityQuery}'s constants
075: */
076: public int getSharability(final File file) {
077: Integer ret = (Integer) ProjectManager.mutex().readAccess(
078: new Mutex.Action() {
079: public Object run() {
080: synchronized (MakeSharabilityQuery.this ) {
081: boolean sub = file.getPath().startsWith(
082: baseDir);
083: if (!sub)
084: return new Integer(
085: SharabilityQuery.UNKNOWN);
086: if (file.getPath().equals(baseDir))
087: return new Integer(
088: SharabilityQuery.MIXED);
089: if (file.getPath().length() <= baseDirLength + 1)
090: return new Integer(
091: SharabilityQuery.UNKNOWN);
092: String subString = file.getPath()
093: .substring(baseDirLength + 1);
094: if (subString.equals("nbproject")) // NOI18N
095: return new Integer(
096: SharabilityQuery.MIXED);
097: else if (subString.equals("Makefile")) // NOI18N
098: return new Integer(
099: SharabilityQuery.SHARABLE);
100: else if (subString.equals("nbproject"
101: + File.separator
102: + "configurations.xml")) // NOI18N
103: return new Integer(
104: SharabilityQuery.SHARABLE);
105: else if (subString.equals("nbproject"
106: + File.separator + "private")) // NOI18N
107: return new Integer(
108: privateShared ? SharabilityQuery.SHARABLE
109: : SharabilityQuery.NOT_SHARABLE); // see IZ 121796, IZ 109580 and IZ 109573
110: else if (subString.equals("nbproject"
111: + File.separator
112: + "project.properties")) // NOI18N
113: return new Integer(
114: SharabilityQuery.SHARABLE);
115: else if (subString.equals("nbproject"
116: + File.separator + "project.xml")) // NOI18N
117: return new Integer(
118: SharabilityQuery.SHARABLE);
119: else if (subString.startsWith("nbproject"
120: + File.separator + "Makefile-")) // NOI18N
121: return new Integer(
122: SharabilityQuery.SHARABLE);
123: else if (subString.equals("build")) // NOI18N
124: return new Integer(
125: SharabilityQuery.NOT_SHARABLE);
126: else if (subString.equals("dist")) // NOI18N
127: return new Integer(
128: SharabilityQuery.NOT_SHARABLE);
129: return new Integer(SharabilityQuery.UNKNOWN);
130: }
131: }
132: });
133: return ret.intValue();
134: }
135:
136: public void setPrivateShared(boolean privateShared) {
137: this .privateShared = privateShared;
138: }
139:
140: public boolean getPrivateShared() {
141: return privateShared;
142: }
143: }
|