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-2006 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.spi.project.support.ant;
043:
044: import java.io.File;
045: import org.netbeans.api.project.ProjectManager;
046: import org.netbeans.api.project.TestUtil;
047: import org.netbeans.api.queries.SharabilityQuery;
048: import org.netbeans.junit.NbTestCase;
049: import org.netbeans.spi.queries.SharabilityQueryImplementation;
050: import org.openide.filesystems.FileObject;
051: import org.openide.filesystems.FileUtil;
052:
053: /**
054: * Test functionality of SharabilityQueryImpl.
055: * @author Jesse Glick
056: */
057: public class SharabilityQueryImplTest extends NbTestCase {
058:
059: public SharabilityQueryImplTest(String name) {
060: super (name);
061: }
062:
063: /** Location of top of testing dir (contains projdir and external). */
064: private File scratchF;
065: /** Tested impl. */
066: private SharabilityQueryImplementation sqi;
067:
068: protected void setUp() throws Exception {
069: super .setUp();
070: clearWorkDir();
071: TestUtil.setLookup(new Object[] { AntBasedTestUtil
072: .testAntBasedProjectType(), });
073: FileObject scratch = TestUtil.makeScratchDir(this );
074: scratchF = FileUtil.toFile(scratch);
075: FileObject projdir = scratch.createFolder("projdir");
076: AntProjectHelper h = ProjectGenerator.createProject(projdir,
077: "test");
078: assertEquals("right project directory", projdir, h
079: .getProjectDirectory());
080: EditableProperties props = h
081: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
082: props.setProperty("build.dir", "build");
083: props.setProperty("build2.dir", "build/2");
084: props.setProperty("dist.dir", "dist");
085: props.setProperty("src.dir", "src");
086: File externalF = new File(scratchF, "external");
087: props.setProperty("src2.dir", new File(externalF, "src")
088: .getAbsolutePath());
089: props.setProperty("build3.dir", new File(externalF, "build")
090: .getAbsolutePath());
091: h
092: .putProperties(
093: AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
094: ProjectManager.getDefault().saveProject(
095: ProjectManager.getDefault().findProject(projdir));
096: sqi = h.createSharabilityQuery(
097: h.getStandardPropertyEvaluator(), new String[] {
098: "${src.dir}", "${src2.dir}" }, new String[] {
099: "${build.dir}", "${build2.dir}",
100: "${build3.dir}", "${dist.dir}" });
101: }
102:
103: private File file(String path) {
104: return new File(scratchF, path.replace('/', File.separatorChar));
105: }
106:
107: public void testBasicIncludesExcludes() throws Exception {
108: assertEquals("project directory is mixed",
109: SharabilityQuery.MIXED, sqi
110: .getSharability(file("projdir")));
111: assertEquals("build.xml is sharable",
112: SharabilityQuery.SHARABLE, sqi
113: .getSharability(file("projdir/build.xml")));
114: assertEquals("src/ is sharable", SharabilityQuery.SHARABLE, sqi
115: .getSharability(file("projdir/src")));
116: assertEquals("src/org/foo/ is sharable",
117: SharabilityQuery.SHARABLE, sqi
118: .getSharability(file("projdir/src/org/foo")));
119: assertEquals(
120: "src/org/foo/Foo.java is sharable",
121: SharabilityQuery.SHARABLE,
122: sqi
123: .getSharability(file("projdir/src/org/foo/Foo.java")));
124: assertEquals("nbproject/ is mixed", SharabilityQuery.MIXED, sqi
125: .getSharability(file("projdir/nbproject")));
126: assertEquals(
127: "nbproject/project.xml is sharable",
128: SharabilityQuery.SHARABLE,
129: sqi
130: .getSharability(file("projdir/nbproject/project.xml")));
131: assertEquals("nbproject/private/ is not sharable",
132: SharabilityQuery.NOT_SHARABLE,
133: sqi.getSharability(file("projdir/nbproject/private")));
134: assertEquals(
135: "nbproject/private/private.properties is not sharable",
136: SharabilityQuery.NOT_SHARABLE,
137: sqi
138: .getSharability(file("projdir/nbproject/private/private.properties")));
139: assertEquals("build/ is not sharable",
140: SharabilityQuery.NOT_SHARABLE, sqi
141: .getSharability(file("projdir/build")));
142: assertEquals(
143: "build/classes/org/foo/Foo.class is not sharable",
144: SharabilityQuery.NOT_SHARABLE,
145: sqi
146: .getSharability(file("projdir/build/classes/org/foo/Foo.class")));
147: assertEquals("dist/ is not sharable",
148: SharabilityQuery.NOT_SHARABLE, sqi
149: .getSharability(file("projdir/dist")));
150: }
151:
152: public void testOverlaps() throws Exception {
153: assertEquals("build/2/ is not sharable",
154: SharabilityQuery.NOT_SHARABLE, sqi
155: .getSharability(file("projdir/build/2")));
156: assertEquals("build/2/whatever is not sharable",
157: SharabilityQuery.NOT_SHARABLE,
158: sqi.getSharability(file("projdir/build/2/whatever")));
159: // overlaps in includePaths tested in basicIncludesExcludes: src is inside projdir
160: }
161:
162: public void testExternalFiles() throws Exception {
163: assertEquals("external/src is sharable",
164: SharabilityQuery.SHARABLE, sqi
165: .getSharability(file("external/src")));
166: assertEquals(
167: "external/src/org/foo/Foo.java is sharable",
168: SharabilityQuery.SHARABLE,
169: sqi
170: .getSharability(file("external/src/org/foo/Foo.java")));
171: assertEquals("external/build is not sharable",
172: SharabilityQuery.NOT_SHARABLE, sqi
173: .getSharability(file("external/build")));
174: assertEquals(
175: "external/build/classes/org/foo/Foo.class is not sharable",
176: SharabilityQuery.NOT_SHARABLE,
177: sqi
178: .getSharability(file("external/build/classes/org/foo/Foo.class")));
179: }
180:
181: public void testUnknownFiles() throws Exception {
182: assertEquals("some other dir is unknown",
183: SharabilityQuery.UNKNOWN, sqi
184: .getSharability(file("something")));
185: assertEquals("some other file is unknown",
186: SharabilityQuery.UNKNOWN, sqi
187: .getSharability(file("something/else")));
188: assertEquals("external itself is unknown",
189: SharabilityQuery.UNKNOWN, sqi
190: .getSharability(file("external")));
191: }
192:
193: public void testDirNamesEndingInSlash() throws Exception {
194: assertEquals("project directory is mixed",
195: SharabilityQuery.MIXED, sqi
196: .getSharability(file("projdir/")));
197: assertEquals("src/ is sharable", SharabilityQuery.SHARABLE, sqi
198: .getSharability(file("projdir/src/")));
199: assertEquals("src/org/foo/ is sharable",
200: SharabilityQuery.SHARABLE, sqi
201: .getSharability(file("projdir/src/org/foo/")));
202: assertEquals("nbproject/ is mixed", SharabilityQuery.MIXED, sqi
203: .getSharability(file("projdir/nbproject/")));
204: assertEquals("nbproject/private/ is not sharable",
205: SharabilityQuery.NOT_SHARABLE,
206: sqi.getSharability(file("projdir/nbproject/private/")));
207: assertEquals("build/ is not sharable",
208: SharabilityQuery.NOT_SHARABLE, sqi
209: .getSharability(file("projdir/build/")));
210: assertEquals("dist/ is not sharable",
211: SharabilityQuery.NOT_SHARABLE, sqi
212: .getSharability(file("projdir/dist/")));
213: assertEquals("build/2/ is not sharable",
214: SharabilityQuery.NOT_SHARABLE, sqi
215: .getSharability(file("projdir/build/2/")));
216: assertEquals("some other dir is unknown",
217: SharabilityQuery.UNKNOWN, sqi
218: .getSharability(file("something/")));
219: assertEquals("external itself is unknown",
220: SharabilityQuery.UNKNOWN, sqi
221: .getSharability(file("external/")));
222: assertEquals("external/src is sharable",
223: SharabilityQuery.SHARABLE, sqi
224: .getSharability(file("external/src/")));
225: assertEquals("external/build is not sharable",
226: SharabilityQuery.NOT_SHARABLE, sqi
227: .getSharability(file("external/build/")));
228: }
229:
230: public void testSubprojectFiles() throws Exception {
231: assertEquals(
232: "nbproject/private from a subproject is sharable as far as this impl is concerned",
233: SharabilityQuery.SHARABLE,
234: sqi
235: .getSharability(file("projdir/subproj/nbproject/private")));
236: }
237:
238: // XXX testChangedProperties
239: // XXX testExternalSourceDirs
240:
241: }
|