1 19 20 package org.netbeans.modules.java.j2seproject; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import org.netbeans.junit.NbTestCase; 25 import org.netbeans.spi.project.support.ant.AntProjectHelper; 26 import org.netbeans.spi.project.support.ant.EditableProperties; 27 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.modules.SpecificationVersion; 31 32 37 public class J2SEProjectGeneratorTest extends NbTestCase { 38 39 public J2SEProjectGeneratorTest(String testName) { 40 super(testName); 41 } 42 43 private static final String [] createdFiles = { 44 "build.xml", 45 "nbproject/build-impl.xml", 46 "nbproject/project.xml", 47 "nbproject/project.properties", 48 "src", 49 "test", 50 }; 51 52 private static final String [] createdFilesExtSources = { 53 "build.xml", 54 "nbproject/build-impl.xml", 55 "nbproject/project.xml", 56 "nbproject/project.properties", 57 "nbproject/private/private.properties", 58 }; 59 60 private static final String [] createdProperties = { 61 "build.classes.dir", 62 "build.classes.excludes", 63 "build.dir", 64 "build.generated.dir", 65 "build.sysclasspath", 66 "build.test.classes.dir", 67 "build.test.results.dir", 68 "debug.classpath", 69 "debug.test.classpath", 70 "dist.dir", 71 "dist.jar", 72 "dist.javadoc.dir", 73 "jar.compress", 74 "javac.classpath", 75 "javac.compilerargs", 76 "javac.deprecation", 77 "javac.source", 78 "javac.target", 79 "javac.test.classpath", 80 "javadoc.author", 81 "javadoc.encoding", 82 "javadoc.noindex", 83 "javadoc.nonavbar", 84 "javadoc.notree", 85 "javadoc.private", 86 "javadoc.splitindex", 87 "javadoc.use", 88 "javadoc.version", 89 "javadoc.windowtitle", 90 "javadoc.additionalparam", 91 "main.class", 92 "manifest.file", 93 "meta.inf.dir", 94 "platform.active", 95 "run.classpath", 96 "run.jvmargs", 97 "run.test.classpath", 98 "src.dir", 99 "test.src.dir", 100 }; 101 102 private static final String [] createdPropertiesExtSources = { 103 "build.classes.dir", 104 "build.classes.excludes", 105 "build.dir", 106 "build.generated.dir", 107 "build.sysclasspath", 108 "build.test.classes.dir", 109 "build.test.results.dir", 110 "debug.classpath", 111 "debug.test.classpath", 112 "dist.dir", 113 "dist.jar", 114 "dist.javadoc.dir", 115 "jar.compress", 116 "javac.classpath", 117 "javac.compilerargs", 118 "javac.deprecation", 119 "javac.source", 120 "javac.target", 121 "javac.test.classpath", 122 "javadoc.author", 123 "javadoc.encoding", 124 "javadoc.noindex", 125 "javadoc.nonavbar", 126 "javadoc.notree", 127 "javadoc.private", 128 "javadoc.splitindex", 129 "javadoc.use", 130 "javadoc.version", 131 "javadoc.windowtitle", 132 "javadoc.additionalparam", 133 "main.class", 134 "manifest.file", 135 "meta.inf.dir", 136 "platform.active", 137 "run.classpath", 138 "run.jvmargs", 139 "run.test.classpath", 140 "src.dir", 141 "test.src.dir", 142 }; 143 144 public void testCreateProject() throws Exception { 145 File proj = getWorkDir(); 146 clearWorkDir(); 147 J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4")); AntProjectHelper aph = J2SEProjectGenerator.createProject(proj, "test-project", null, "manifest.mf"); 149 J2SEProjectGenerator.setDefaultSourceLevel(null); 150 assertNotNull(aph); 151 FileObject fo = aph.getProjectDirectory(); 152 for (int i=0; i<createdFiles.length; i++) { 153 assertNotNull(createdFiles[i]+" file/folder cannot be found", fo.getFileObject(createdFiles[i])); 154 } 155 EditableProperties props = aph.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 156 ArrayList l = new ArrayList (props.keySet()); 157 for (int i=0; i<createdProperties.length; i++) { 158 assertNotNull(createdProperties[i]+" property cannot be found in project.properties", props.getProperty(createdProperties[i])); 159 l.remove(createdProperties[i]); 160 } 161 assertEquals("Found unexpected property: "+l,createdProperties.length, props.keySet().size()); 162 } 163 164 public void testCreateProjectFromExtSources () throws Exception { 165 File root = getWorkDir(); 166 clearWorkDir(); 167 File proj = new File (root, "ProjectDir"); 168 proj.mkdir(); 169 File srcRoot = new File (root, "src"); 170 srcRoot.mkdir (); 171 File testRoot = new File (root, "test"); 172 testRoot.mkdir (); 173 J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4")); AntProjectHelper helper = J2SEProjectGenerator.createProject(proj, "test-project-ext-src", new File [] {srcRoot}, new File [] {testRoot}, "manifest.mf"); 175 J2SEProjectGenerator.setDefaultSourceLevel(null); assertNotNull (helper); 177 FileObject fo = FileUtil.toFileObject(proj); 178 for (int i=0; i<createdFilesExtSources.length; i++) { 179 assertNotNull(createdFilesExtSources[i]+" file/folder cannot be found", fo.getFileObject(createdFilesExtSources[i])); 180 } 181 EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 182 ArrayList l = new ArrayList (props.keySet()); 183 int extFileRefCount = 0; 184 for (int i=0; i<createdPropertiesExtSources.length; i++) { 185 String propName = createdPropertiesExtSources[i]; 186 String propValue = props.getProperty(propName); 187 assertNotNull(propName+" property cannot be found in project.properties", propValue); 188 l.remove(propName); 189 if ("manifest.file".equals (propName)) { 190 assertEquals("Invalid value of manifest.file property.", "manifest.mf", propValue); 191 } 192 else if ("src.dir".equals (propName)) { 193 PropertyEvaluator eval = helper.getStandardPropertyEvaluator(); 194 assertTrue("Value of the external source dir should be file reference",propValue.startsWith("${file.reference.")); 197 if (l.remove (propValue.subSequence(2,propValue.length()-1))) { 198 extFileRefCount++; 199 } 200 File file = helper.resolveFile(eval.evaluate(propValue)); 201 assertEquals("Invalid value of src.dir property.", srcRoot, file); 202 } 203 else if ("test.src.dir".equals(propName)) { 204 PropertyEvaluator eval = helper.getStandardPropertyEvaluator(); 205 assertTrue("Value of the external test dir should be file reference",propValue.startsWith("${file.reference.")); 208 if (l.remove (propValue.subSequence(2,propValue.length()-1))) { 209 extFileRefCount++; 210 } 211 File file = helper.resolveFile(eval.evaluate(propValue)); 212 assertEquals("Invalid value of test.src.dir property.", testRoot, file); 213 } 214 } 215 assertEquals("Found unexpected property: "+l,createdPropertiesExtSources.length, props.keySet().size() - extFileRefCount); 216 } 217 218 } 219 | Popular Tags |