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.api.project.ant;
043:
044: import java.io.File;
045: import org.netbeans.api.project.Project;
046: import org.netbeans.api.project.ProjectManager;
047: import org.netbeans.api.project.TestUtil;
048: import org.netbeans.junit.NbTestCase;
049: import org.netbeans.spi.project.support.ant.AntBasedTestUtil;
050: import org.netbeans.spi.project.support.ant.AntProjectHelper;
051: import org.netbeans.spi.project.support.ant.EditableProperties;
052: import org.netbeans.spi.project.support.ant.ProjectGenerator;
053: import org.openide.filesystems.FileObject;
054: import org.openide.filesystems.FileUtil;
055: import org.openide.util.test.MockLookup;
056:
057: /* XXX tests needed:
058: * - testFindArtifactFromNonexistentFile
059: * like testFindArtifactFromFile but file does not yet exist on disk
060: * - testFindArtifactByTarget
061: * - testFindArtifactsByType
062: */
063:
064: /**
065: * Test functionality of AntArtifactQuery, StandardAntArtifactQueryImpl, etc.
066: * @author Jesse Glick
067: */
068: public class AntArtifactQueryTest extends NbTestCase {
069:
070: public AntArtifactQueryTest(String name) {
071: super (name);
072: }
073:
074: private FileObject scratch;
075: private FileObject projdir;
076: private FileObject sisterprojdir;
077: private FileObject dummyprojdir;
078: private ProjectManager pm;
079:
080: protected @Override
081: void setUp() throws Exception {
082: super .setUp();
083: MockLookup.setInstances(AntBasedTestUtil
084: .testAntBasedProjectType(), TestUtil
085: .testProjectFactory());
086: scratch = TestUtil.makeScratchDir(this );
087: projdir = scratch.createFolder("proj");
088: ProjectGenerator.createProject(projdir, "test");
089: pm = ProjectManager.getDefault();
090: sisterprojdir = FileUtil.createFolder(scratch, "proj2");
091: AntProjectHelper sisterh = ProjectGenerator.createProject(
092: sisterprojdir, "test");
093: EditableProperties props = sisterh
094: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
095: props.setProperty("build.jar", "dist/proj2.jar");
096: props.setProperty("build.javadoc", "build/javadoc");
097: sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,
098: props);
099: dummyprojdir = scratch.createFolder("dummy");
100: dummyprojdir.createFolder("testproject");
101: }
102:
103: protected @Override
104: void tearDown() throws Exception {
105: scratch = null;
106: projdir = null;
107: sisterprojdir = null;
108: pm = null;
109: super .tearDown();
110: }
111:
112: public void testFindArtifactFromFile() throws Exception {
113: FileObject proj2JarFO = FileUtil.createData(sisterprojdir,
114: "dist/proj2.jar");
115: File proj2Jar = FileUtil.toFile(proj2JarFO);
116: assertNotNull("have dist/proj2.jar on disk", proj2Jar);
117: AntArtifact art = AntArtifactQuery
118: .findArtifactFromFile(proj2Jar);
119: assertNotNull("found an artifact matching " + proj2Jar, art);
120: assertEquals("correct project", pm.findProject(sisterprojdir),
121: art.getProject());
122: assertEquals("correct artifact file", proj2JarFO, art
123: .getArtifactFiles()[0]);
124: assertEquals("correct target name", "dojar", art
125: .getTargetName());
126: assertEquals("correct clean target name", "clean", art
127: .getCleanTargetName());
128: assertEquals("correct type", "jar", art.getType());
129: assertEquals("correct script location", new File(FileUtil
130: .toFile(sisterprojdir), "build.xml"), art
131: .getScriptLocation());
132: }
133:
134: public void testFindArtifactsByType() throws Exception {
135: Project p = pm.findProject(projdir);
136: assertNotNull("have a project in " + projdir, p);
137: AntArtifact[] arts = AntArtifactQuery.findArtifactsByType(p,
138: "jar");
139: assertEquals("one JAR artifact", 1, arts.length);
140: assertEquals("correct project", p, arts[0].getProject());
141: assertEquals("correct target name", "dojar", arts[0]
142: .getTargetName());
143: p = pm.findProject(dummyprojdir);
144: assertNotNull("have a dummy project in " + dummyprojdir, p);
145: arts = AntArtifactQuery.findArtifactsByType(p, "jar");
146: assertEquals("no JAR artifacts", 0, arts.length);
147: }
148:
149: }
|