1 19 20 package org.netbeans.spi.project.support.ant; 21 22 import java.io.File ; 23 import java.net.URI ; 24 import java.util.Arrays ; 25 import java.util.Collections ; 26 import org.netbeans.api.project.ProjectManager; 27 import org.netbeans.api.project.TestUtil; 28 import org.netbeans.api.project.ant.AntArtifact; 29 import org.netbeans.junit.NbTestCase; 30 import org.openide.filesystems.FileObject; 31 import org.openide.filesystems.FileUtil; 32 import org.openide.util.Lookup; 33 34 38 public class SimpleAntArtifactTest extends NbTestCase { 39 40 public SimpleAntArtifactTest(String name) { 41 super(name); 42 } 43 44 private FileObject scratch; 45 private FileObject sisterprojdir; 46 private ProjectManager pm; 47 private AntProjectHelper sisterh; 48 49 protected void setUp() throws Exception { 50 super.setUp(); 51 scratch = TestUtil.makeScratchDir(this); 52 TestUtil.setLookup(new Object [] { 53 AntBasedTestUtil.testAntBasedProjectType(), 54 }); 55 pm = ProjectManager.getDefault(); 56 sisterprojdir = FileUtil.createFolder(scratch, "proj2"); 57 sisterh = ProjectGenerator.createProject(sisterprojdir, "test"); 58 EditableProperties props = sisterh.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 59 props.setProperty("build.jar", "build/proj2.jar"); 60 props.setProperty("build.jar.absolute", getWorkDir().getAbsolutePath()+"/build/proj3.jar"); 61 sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); 62 } 63 64 protected void tearDown() throws Exception { 65 scratch = null; 66 sisterprojdir = null; 67 sisterh = null; 68 pm = null; 69 TestUtil.setLookup(Lookup.EMPTY); 70 super.tearDown(); 71 } 72 73 76 public void testSimpleAntArtifact() throws Exception { 77 AntArtifact art = sisterh.createSimpleAntArtifact("jar", "build.jar", sisterh.getStandardPropertyEvaluator(), "dojar", "clean"); 78 assertEquals("correct type", "jar", art.getType()); 79 assertEquals("correct target name", "dojar", art.getTargetName()); 80 assertEquals("correct clean target name", "clean", art.getCleanTargetName()); 81 assertEquals("correct artifact location", URI.create("build/proj2.jar"), art.getArtifactLocations()[0]); 82 assertEquals("no artifact file yet", 0, art.getArtifactFiles().length); 83 FileObject artfile = FileUtil.createData(sisterprojdir, "build/proj2.jar"); 84 assertEquals("now have an artifact file", Collections.singletonList(artfile), Arrays.asList(art.getArtifactFiles())); 85 assertEquals("correct script location", new File (FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation()); 86 assertEquals("no script file yet", null, art.getScriptFile()); 87 FileObject scriptfile = FileUtil.createData(sisterprojdir, "build.xml"); 88 assertEquals("now have a script file", scriptfile, art.getScriptFile()); 89 assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject()); 90 91 art = sisterh.createSimpleAntArtifact("jar", "build.jar.absolute", sisterh.getStandardPropertyEvaluator(), "dojar", "clean"); 92 assertEquals("correct artifact location", (new File (getWorkDir().getAbsolutePath()+"/build/proj3.jar")).toURI(), art.getArtifactLocations()[0]); 93 } 94 95 } 96 | Popular Tags |