1 19 20 package org.netbeans.spi.project.support.ant; 21 22 import java.io.File ; 23 import org.netbeans.api.project.ProjectManager; 24 import org.netbeans.api.project.TestUtil; 25 import org.netbeans.api.queries.SharabilityQuery; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.spi.queries.SharabilityQueryImplementation; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 31 35 public class SharabilityQueryImplTest extends NbTestCase { 36 37 public SharabilityQueryImplTest(String name) { 38 super(name); 39 } 40 41 42 private File scratchF; 43 44 private SharabilityQueryImplementation sqi; 45 46 protected void setUp() throws Exception { 47 super.setUp(); 48 clearWorkDir(); 49 TestUtil.setLookup(new Object [] { 50 AntBasedTestUtil.testAntBasedProjectType(), 51 }); 52 FileObject scratch = TestUtil.makeScratchDir(this); 53 scratchF = FileUtil.toFile(scratch); 54 FileObject projdir = scratch.createFolder("projdir"); 55 AntProjectHelper h = ProjectGenerator.createProject(projdir, "test"); 56 assertEquals("right project directory", projdir, h.getProjectDirectory()); 57 EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 58 props.setProperty("build.dir", "build"); 59 props.setProperty("build2.dir", "build/2"); 60 props.setProperty("dist.dir", "dist"); 61 props.setProperty("src.dir", "src"); 62 File externalF = new File (scratchF, "external"); 63 props.setProperty("src2.dir", new File (externalF, "src").getAbsolutePath()); 64 props.setProperty("build3.dir", new File (externalF, "build").getAbsolutePath()); 65 h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); 66 ProjectManager.getDefault().saveProject(ProjectManager.getDefault().findProject(projdir)); 67 sqi = h.createSharabilityQuery(h.getStandardPropertyEvaluator(), new String [] {"${src.dir}", "${src2.dir}"}, 68 new String [] {"${build.dir}", "${build2.dir}", "${build3.dir}", "${dist.dir}"}); 69 } 70 71 private File file(String path) { 72 return new File (scratchF, path.replace('/', File.separatorChar)); 73 } 74 75 public void testBasicIncludesExcludes() throws Exception { 76 assertEquals("project directory is mixed", SharabilityQuery.MIXED, sqi.getSharability(file("projdir"))); 77 assertEquals("build.xml is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/build.xml"))); 78 assertEquals("src/ is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src"))); 79 assertEquals("src/org/foo/ is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src/org/foo"))); 80 assertEquals("src/org/foo/Foo.java is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src/org/foo/Foo.java"))); 81 assertEquals("nbproject/ is mixed", SharabilityQuery.MIXED, sqi.getSharability(file("projdir/nbproject"))); 82 assertEquals("nbproject/project.xml is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/nbproject/project.xml"))); 83 assertEquals("nbproject/private/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/nbproject/private"))); 84 assertEquals("nbproject/private/private.properties is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/nbproject/private/private.properties"))); 85 assertEquals("build/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build"))); 86 assertEquals("build/classes/org/foo/Foo.class is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/classes/org/foo/Foo.class"))); 87 assertEquals("dist/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/dist"))); 88 } 89 90 public void testOverlaps() throws Exception { 91 assertEquals("build/2/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/2"))); 92 assertEquals("build/2/whatever is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/2/whatever"))); 93 } 95 96 public void testExternalFiles() throws Exception { 97 assertEquals("external/src is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("external/src"))); 98 assertEquals("external/src/org/foo/Foo.java is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("external/src/org/foo/Foo.java"))); 99 assertEquals("external/build is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("external/build"))); 100 assertEquals("external/build/classes/org/foo/Foo.class is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("external/build/classes/org/foo/Foo.class"))); 101 } 102 103 public void testUnknownFiles() throws Exception { 104 assertEquals("some other dir is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("something"))); 105 assertEquals("some other file is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("something/else"))); 106 assertEquals("external itself is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("external"))); 107 } 108 109 public void testDirNamesEndingInSlash() throws Exception { 110 assertEquals("project directory is mixed", SharabilityQuery.MIXED, sqi.getSharability(file("projdir/"))); 111 assertEquals("src/ is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src/"))); 112 assertEquals("src/org/foo/ is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src/org/foo/"))); 113 assertEquals("nbproject/ is mixed", SharabilityQuery.MIXED, sqi.getSharability(file("projdir/nbproject/"))); 114 assertEquals("nbproject/private/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/nbproject/private/"))); 115 assertEquals("build/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/"))); 116 assertEquals("dist/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/dist/"))); 117 assertEquals("build/2/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/2/"))); 118 assertEquals("some other dir is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("something/"))); 119 assertEquals("external itself is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("external/"))); 120 assertEquals("external/src is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("external/src/"))); 121 assertEquals("external/build is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("external/build/"))); 122 } 123 124 public void testSubprojectFiles() throws Exception { 125 assertEquals("nbproject/private from a subproject is sharable as far as this impl is concerned", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/subproj/nbproject/private"))); 126 } 127 128 131 } 132 | Popular Tags |