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 java.net.URI;
046: import java.util.Arrays;
047: import java.util.Collections;
048: import org.netbeans.api.project.ProjectManager;
049: import org.netbeans.api.project.TestUtil;
050: import org.netbeans.api.project.ant.AntArtifact;
051: import org.netbeans.junit.NbTestCase;
052: import org.openide.filesystems.FileObject;
053: import org.openide.filesystems.FileUtil;
054: import org.openide.util.Lookup;
055:
056: /**
057: * Test functionality of SimpleAntArtifact.
058: * @author Jesse Glick
059: */
060: public class SimpleAntArtifactTest extends NbTestCase {
061:
062: public SimpleAntArtifactTest(String name) {
063: super (name);
064: }
065:
066: private FileObject scratch;
067: private FileObject sisterprojdir;
068: private ProjectManager pm;
069: private AntProjectHelper sisterh;
070:
071: protected void setUp() throws Exception {
072: super .setUp();
073: scratch = TestUtil.makeScratchDir(this );
074: TestUtil.setLookup(new Object[] { AntBasedTestUtil
075: .testAntBasedProjectType(), });
076: pm = ProjectManager.getDefault();
077: sisterprojdir = FileUtil.createFolder(scratch, "proj2");
078: sisterh = ProjectGenerator.createProject(sisterprojdir, "test");
079: EditableProperties props = sisterh
080: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
081: props.setProperty("build.jar", "build/proj2.jar");
082: props.setProperty("build.jar.absolute", getWorkDir()
083: .getAbsolutePath()
084: + "/build/proj3.jar");
085: sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,
086: props);
087: }
088:
089: protected void tearDown() throws Exception {
090: scratch = null;
091: sisterprojdir = null;
092: sisterh = null;
093: pm = null;
094: TestUtil.setLookup(Lookup.EMPTY);
095: super .tearDown();
096: }
097:
098: /**
099: * Check that {@link SimpleAntArtifact} works as documented.
100: */
101: public void testSimpleAntArtifact() throws Exception {
102: AntArtifact art = sisterh.createSimpleAntArtifact("jar",
103: "build.jar", sisterh.getStandardPropertyEvaluator(),
104: "dojar", "clean");
105: assertEquals("correct type", "jar", art.getType());
106: assertEquals("correct target name", "dojar", art
107: .getTargetName());
108: assertEquals("correct clean target name", "clean", art
109: .getCleanTargetName());
110: assertEquals("correct artifact location", URI
111: .create("build/proj2.jar"),
112: art.getArtifactLocations()[0]);
113: assertEquals("no artifact file yet", 0,
114: art.getArtifactFiles().length);
115: FileObject artfile = FileUtil.createData(sisterprojdir,
116: "build/proj2.jar");
117: assertEquals("now have an artifact file", Collections
118: .singletonList(artfile), Arrays.asList(art
119: .getArtifactFiles()));
120: assertEquals("correct script location", new File(FileUtil
121: .toFile(sisterprojdir), "build.xml"), art
122: .getScriptLocation());
123: assertEquals("no script file yet", null, art.getScriptFile());
124: FileObject scriptfile = FileUtil.createData(sisterprojdir,
125: "build.xml");
126: assertEquals("now have a script file", scriptfile, art
127: .getScriptFile());
128: assertEquals("correct project", pm.findProject(sisterprojdir),
129: art.getProject());
130:
131: art = sisterh.createSimpleAntArtifact("jar",
132: "build.jar.absolute", sisterh
133: .getStandardPropertyEvaluator(), "dojar",
134: "clean");
135: assertEquals("correct artifact location", (new File(
136: getWorkDir().getAbsolutePath() + "/build/proj3.jar"))
137: .toURI(), art.getArtifactLocations()[0]);
138: }
139:
140: }
|