diff options
author | wisberg <wisberg> | 2002-12-16 17:09:36 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 17:09:36 +0000 |
commit | c3300283ecc397d26ad9dfe31d1710ec45db2af0 (patch) | |
tree | e9acb7f3d33c1499975cec9ef3cc7ea151078344 /build/testsrc | |
parent | 3cde920c3f7eb8241bf569007e25225d80b43c0f (diff) | |
download | aspectj-c3300283ecc397d26ad9dfe31d1710ec45db2af0.tar.gz aspectj-c3300283ecc397d26ad9dfe31d1710ec45db2af0.zip |
initial version
Diffstat (limited to 'build/testsrc')
-rw-r--r-- | build/testsrc/BuildModuleTests.java | 143 | ||||
-rw-r--r-- | build/testsrc/org/aspectj/internal/build/BuildModuleTest.java | 179 |
2 files changed, 322 insertions, 0 deletions
diff --git a/build/testsrc/BuildModuleTests.java b/build/testsrc/BuildModuleTests.java new file mode 100644 index 000000000..651b061a6 --- /dev/null +++ b/build/testsrc/BuildModuleTests.java @@ -0,0 +1,143 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +// default package + +import org.aspectj.internal.tools.ant.taskdefs.Checklics; +import org.aspectj.internal.build.BuildModuleTest; + +import java.io.File; + +import junit.framework.*; + +public class BuildModuleTests extends TestCase { + + /** if true, then replace old headers with new first */ + private static final boolean replacing = false; // XXX never to enable again... + + /** if any replace failed, halt all */ + private static boolean replaceFailed = false; + + private static final String BASE_DIR = "../"; + private static final String[] JDT_SOURCE_DIRS = new String[] + {"antadapter", "batch", "codeassist", "compiler", "dom", "eval", "formatter", + "model", "search" }; + + public static Test suite() { + TestSuite suite = new TestSuite("Build module tests"); + suite.addTestSuite(BuildModuleTests.class); + suite.addTestSuite(BuildModuleTest.class); + return suite; + } + + /** @return String tag of license if not default */ + public static String getLicense(String module) { + if ("org.eclipse.jdt.core".equals(module)) { + return Checklics.CPL_IBM_PARC_TAG; + } + return null; + } + + public BuildModuleTests(String name) { super(name); } + + public void testLicense_ajbrowser() { + checkLicense("ajbrowser"); + } + public void testLicense_ajde() { + checkLicense("ajde"); + } + public void testLicense_asm() { + checkLicense("asm"); + } + public void testLicense_bcweaver() { + String module = "bcweaver"; + checkSourceDirectory("../" + module + "/src", module); + checkSourceDirectory("../" + module + "/testsrc/org", module); + } + public void testLicense_bridge() { + checkLicense("bridge"); + } + public void testLicense_build() { + checkLicense("build"); + } + public void testLicense_jbuilder() { + checkLicense("jbuilder"); + } + public void testLicense_netbeans() { + checkLicense("netbeans"); + } + public void testLicense_org_aspectj_ajdt_core() { + checkLicense("org.aspectj.ajdt.core"); + } + public void testLicense_org_eclipse_jdt_core() { + final String mod = "org.eclipse.jdt.core"; + final String pre = BASE_DIR + mod + "/"; + for (int i = 0; i < JDT_SOURCE_DIRS.length; i++) { + checkSourceDirectory(pre + JDT_SOURCE_DIRS[i], mod); + } + } + + public void testLicense_runtime() { + checkLicense("runtime"); + } + public void testLicense_taskdefs() { + checkLicense("taskdefs"); + } + public void testLicense_testing() { + checkLicense("testing"); + } + public void testLicense_testing_drivers() { + checkLicense("testing-drivers"); + } + public void testLicense_testing_client() { + checkLicense("testing-client"); + } + public void testLicense_testing_util() { + checkLicense("testing-util"); + } + public void testLicense_util() { + checkLicense("util"); + } + + void checkLicense(String module) { + checkSourceDirectory("../" + module + "/src", module); + checkSourceDirectory("../" + module + "/testsrc", module); + } + + void checkSourceDirectory(String path, String module) { + File moduleDir = new File(path); + final String label = "source dir " + moduleDir + " (module " + module + ")"; + assertTrue(label, (moduleDir.exists() && moduleDir.isDirectory())); + String license = getLicense(module); + if (replacing) { + if (replacing) { + throw new Error("replacing done - code left for other replaces"); + } + assertTrue("aborting - replace failed", !replaceFailed); + // do the replace + int fails = Checklics.runDirect(moduleDir.getPath(), "replace-headers"); + replaceFailed = (0 != fails); + assertTrue(!replaceFailed); + license = Checklics.CPL_IBM_PARC_XEROX_TAG; + } + int fails = Checklics.runDirect(moduleDir.getPath(), license); + if (0 != fails) { + if (replacing) { + replaceFailed = true; + } + assertTrue(label + " fails", false); + } + } + +} diff --git a/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java b/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java new file mode 100644 index 000000000..6bee0a63f --- /dev/null +++ b/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java @@ -0,0 +1,179 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.internal.build; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Java; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Commandline.Argument; +import org.aspectj.internal.tools.ant.taskdefs.BuildModule; + +import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; + +import junit.framework.TestCase; +/** + * + */ +public class BuildModuleTest extends TestCase { + + private static final String SKIP_MESSAGE = + "Define \"run.build.tests\" as a system property to run tests to build "; + private static boolean delete(File file) { // XXX Util + if ((null == file) || !file.exists()) { + return true; + } + if (file.isFile()) { + return file.delete(); + } else { + File[] files = file.listFiles(); + boolean result = true; + for (int i = 0; i < files.length; i++) { + if (!BuildModuleTest.delete(files[i]) + && result) { + result = false; + } + } + return (file.delete() && result); + } + } + + ArrayList tempFiles = new ArrayList(); + boolean building; // must be enabled for tests to run + + public BuildModuleTest(String name) { + super(name); + building = (null != System.getProperty("run.build.tests")); + } + + protected void tearDown() throws Exception { + super.tearDown(); + for (Iterator iter = tempFiles.iterator(); iter.hasNext();) { + File file = (File) iter.next(); + if (!BuildModuleTest.delete(file)) { + System.err.println("warning: BuildModuleTest unable to delete " + file); + } + } + } + + public void testBuild() { + checkBuild("build", null, null); + } + public void testAsm() { + checkBuild("asm", null, null); + } + + public void testRuntime() { + checkBuild("runtime", null, null); + } + + public void testAjbrowser() { + checkBuild("ajbrowser", null, null); + } + + public void testAjdt() { + checkBuild("org.aspectj.ajdt.core", "org.aspectj.tools.ajc.Main", + new String[] { "-version" }); + } + + public void testAspectjtools() { + if (!building) { + System.err.println(SKIP_MESSAGE + "aspectjtools"); + return; + } + File baseDir = new File(".."); + File tempBuildDir = new File(baseDir, "aj-build"); + File distDir = new File(tempBuildDir, "dist"); + File jarDir = new File(tempBuildDir, "jars"); + assertTrue(distDir.canWrite() || distDir.mkdirs()); + File productDir = new File(baseDir.getPath() + "/build/products/tools"); + assertTrue(""+productDir, productDir.canRead()); + checkBuildProduct(productDir, baseDir, distDir, jarDir); + } + + void checkBuildProduct(File productDir, File baseDir, File distDir, File jarDir) { + if (!building) { + System.err.println(SKIP_MESSAGE + "product " + productDir); + return; + } + assertTrue(null != productDir); + assertTrue(productDir.canRead()); + + checkJavac(); + + BuildModule task = new BuildModule(); + Project project = new Project(); + task.setProject(project); + assertTrue(jarDir.canWrite() || jarDir.mkdirs()); + // XXX restore tempFiles.add(jarDir); + task.setJardir(new Path(project, jarDir.getAbsolutePath())); + task.setProductdir(new Path(project, productDir.getAbsolutePath())); + task.setBasedir(new Path(project, baseDir.getAbsolutePath())); + task.setDistdir(new Path(project, distDir.getAbsolutePath())); + task.setFailonerror(true); + //task.setVerbose(true); + task.setCreateinstaller(true); + task.execute(); + // now run installer and do product tests? + } + + void checkBuild(String module, String classname, String[] args) { + if (!building) { + System.err.println(SKIP_MESSAGE + "module " + module); + return; + } + assertTrue(null != module); + checkJavac(); + + BuildModule task = new BuildModule(); + Project project = new Project(); + task.setProject(project); + File jarDir = new File("tempJarDir"); + assertTrue(jarDir.canWrite() || jarDir.mkdirs()); + tempFiles.add(jarDir); + task.setModuledir(new Path(project, "../" + module)); + task.setJardir(new Path(project, jarDir.getAbsolutePath())); + task.setFailonerror(true); + task.execute(); + + if (null == classname) { + return; + } + + Java java = new Java(); + java.setProject(project); + File jar = new File(jarDir, module + ".jar"); + java.setClasspath(new Path(project, jar.getAbsolutePath())); + java.setClassname(classname); + for (int i = 0; i < args.length; i++) { + Argument arg = java.createArg(); + arg.setValue(args[i]); + } + java.execute(); + } + + void checkJavac() { + boolean result = false; + try { + result = (null != Class.forName("sun.tools.javac.Main")); + } catch (Throwable t) { + // ignore + } + if (! result) { + assertTrue("add tools.jar to the classpath for Ant's use of javac", false); + } + } + +} |