1 19 20 package org.netbeans.api.project.ant; 21 22 import java.io.File ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.api.project.TestUtil; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.spi.project.support.ant.AntBasedTestUtil; 28 import org.netbeans.spi.project.support.ant.AntProjectHelper; 29 import org.netbeans.spi.project.support.ant.EditableProperties; 30 import org.netbeans.spi.project.support.ant.ProjectGenerator; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.util.Lookup; 34 35 41 42 46 public class AntArtifactQueryTest extends NbTestCase { 47 48 public AntArtifactQueryTest(String name) { 49 super(name); 50 } 51 52 private FileObject scratch; 53 private FileObject projdir; 54 private FileObject sisterprojdir; 55 private FileObject dummyprojdir; 56 private ProjectManager pm; 57 58 protected void setUp() throws Exception { 59 super.setUp(); 60 TestUtil.setLookup(new Object [] { 61 AntBasedTestUtil.testAntBasedProjectType(), 62 TestUtil.testProjectFactory(), 63 }); 64 scratch = TestUtil.makeScratchDir(this); 65 projdir = scratch.createFolder("proj"); 66 ProjectGenerator.createProject(projdir, "test"); 67 pm = ProjectManager.getDefault(); 68 sisterprojdir = FileUtil.createFolder(scratch, "proj2"); 69 AntProjectHelper sisterh = ProjectGenerator.createProject(sisterprojdir, "test"); 70 EditableProperties props = sisterh.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 71 props.setProperty("build.jar", "dist/proj2.jar"); 72 props.setProperty("build.javadoc", "build/javadoc"); 73 sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); 74 dummyprojdir = scratch.createFolder("dummy"); 75 dummyprojdir.createFolder("testproject"); 76 } 77 78 protected void tearDown() throws Exception { 79 scratch = null; 80 projdir = null; 81 sisterprojdir = null; 82 pm = null; 83 TestUtil.setLookup(Lookup.EMPTY); 84 super.tearDown(); 85 } 86 87 public void testFindArtifactFromFile() throws Exception { 88 FileObject proj2JarFO = FileUtil.createData(sisterprojdir, "dist/proj2.jar"); 89 File proj2Jar = FileUtil.toFile(proj2JarFO); 90 assertNotNull("have dist/proj2.jar on disk", proj2Jar); 91 AntArtifact art = AntArtifactQuery.findArtifactFromFile(proj2Jar); 92 assertNotNull("found an artifact matching " + proj2Jar, art); 93 assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject()); 94 assertEquals("correct artifact file", proj2JarFO, art.getArtifactFiles()[0]); 95 assertEquals("correct target name", "dojar", art.getTargetName()); 96 assertEquals("correct clean target name", "clean", art.getCleanTargetName()); 97 assertEquals("correct type", "jar", art.getType()); 98 assertEquals("correct script location", new File (FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation()); 99 } 100 101 public void testFindArtifactsByType() throws Exception { 102 Project p = pm.findProject(projdir); 103 assertNotNull("have a project in " + projdir, p); 104 AntArtifact[] arts = AntArtifactQuery.findArtifactsByType(p, "jar"); 105 assertEquals("one JAR artifact", 1, arts.length); 106 assertEquals("correct project", p, arts[0].getProject()); 107 assertEquals("correct target name", "dojar", arts[0].getTargetName()); 108 p = pm.findProject(dummyprojdir); 109 assertNotNull("have a dummy project in " + dummyprojdir, p); 110 arts = AntArtifactQuery.findArtifactsByType(p, "jar"); 111 assertEquals("no JAR artifacts", 0, arts.length); 112 } 113 114 } 115 | Popular Tags |