--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wes Isberg initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.internal.build;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.aspectj.internal.tools.build.Messager;
+import org.aspectj.internal.tools.build.Module;
+import org.aspectj.internal.tools.build.Modules;
+import org.aspectj.internal.tools.build.Result;
+import org.aspectj.internal.tools.build.Result.Kind;
+
+public class BuildClasspathTest extends TestCase {
+
+ public void testKindsGet() {
+ Kind kind = Result.kind(Result.NORMAL, Result.ASSEMBLE);
+ same(kind, "RELEASE_ALL");
+ kind = Result.kind(Result.NORMAL, !Result.ASSEMBLE);
+ same(kind, "RELEASE");
+ kind = Result.kind(!Result.NORMAL, Result.ASSEMBLE);
+ same(kind, "TEST_ALL");
+ kind = Result.kind(!Result.NORMAL, !Result.ASSEMBLE);
+ same(kind, "TEST");
+ }
+ private void same(Kind kind, String name) {
+ if (!name.equals(kind.toString())) {
+ fail("expected \"" + name + "\" got \"" + kind + "\"");
+ }
+ }
+ public void testClasspath() {
+ Messager handler = new Messager();
+ File baseDir = new File("..");
+ File jarDir = new File("../aj-build/jars");
+ Modules modules = new Modules(baseDir, jarDir, handler);
+ Module module = modules.getModule("ajbrowser");
+ Kind kind = Result.kind(Result.NORMAL, !Result.ASSEMBLE);
+ Result result = module.getResult(kind);
+ print(result);
+ }
+ public void testBuildClasspath() {
+ Messager handler = new Messager();
+ File baseDir = new File("..");
+ File jarDir = new File("../aj-build/jars");
+ Modules modules = new Modules(baseDir, jarDir, handler);
+ Module module = modules.getModule("build");
+ Kind kind = Result.kind(Result.NORMAL, !Result.ASSEMBLE);
+ Result result = module.getResult(kind);
+ print(result);
+ }
+ private void print(Result result) {
+ System.out.println(result + " libjars" + result.getLibJars());
+ System.out.println(result + " required" + result.getRequired());
+ }
+}
package org.aspectj.internal.build;
-import org.apache.tools.ant.*;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.tools.ant.BuildException;
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 org.aspectj.internal.tools.ant.taskdefs.Checklics;
-import org.aspectj.internal.tools.build.*;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import junit.framework.TestCase;
+import org.aspectj.internal.tools.build.Util;
/**
* Test our integrated taskdef build.
private static boolean printInfoMessages = false;
private static boolean printedMessage;
+
+ // to just build one module verbosely
+ private static final String[] DEBUGS
+ = {};
+
// skip those requiring ajdoc, which requires tools.jar
// also skip those requiring java5 unless manually set up
private static final String[] SKIPS
- = {"aspectjtools", "ajdoc", "aspectj5rt"};
+ //= {};
+ = {"aspectjtools", "ajdoc", "aspectj5rt", "run-all-junit-tests"};
+
private static final String SKIP_MESSAGE =
"BuildModuleTest: Define \"run.build.tests\" as a system "
+ "property to run tests to build ";
private static final String BUILD_CONFIG;
+ private static final boolean useEclipseCompiles;
static {
+ boolean useEclipse = false;
String config = null;
try {
config = System.getProperty("build.config");
+ useEclipse = ((null != config)
+ && (-1 != config.indexOf("useEclipseCompiles")));
} catch (Throwable t) {
// ignore
}
+ useEclipseCompiles = useEclipse;
BUILD_CONFIG = config;
if (printInfoMessages) {
System.out.println("BuildModuleTest build.config: " + config);
}
}
-
+
ArrayList tempFiles = new ArrayList();
private File jarDir;
boolean building; // must be enabled for tests to run
protected void tearDown() throws Exception {
super.tearDown();
+ if (debugging()) {
+ return;
+ }
for (Iterator iter = tempFiles.iterator(); iter.hasNext();) {
File file = (File) iter.next();
if (!Util.delete(file)) {
}
}
- public void testBuild() {
+ public void testAllJunitTests() {
+ checkBuild("run-all-junit-tests");
+ }
+
+ public void testBuild() {
checkBuild("build",
Checklics.class.getName(),
new String[0], // help message
}
public void testAspectj5rt() {
- checkBuild("aspectj5rt",
- "org.aspectj.lang.annotation.Main",
- new String[] {}); // compiler version
+ checkBuild("aspectj5rt");
}
-
+
public void testAjbrowser() {
checkBuild("ajbrowser",
"org.aspectj.tools.ajbrowser.Main",
new String[] {"-noExit", "-version"}); // compiler version
}
+ public void testTestingUtils() {
+ checkBuild("testing-util");
+ }
public void testAjdt() {
checkBuild("org.aspectj.ajdt.core",
"org.aspectj.tools.ajc.Main",
new String[] { "-noExit", "-version" });
+ }//
+ public void testTesting() {
+ checkBuild("testing",
+ "org.aspectj.testing.util.LangUtilTest",
+ new String[] {"ignored"});
}
public void testTestingDrivers() {
checkBuild("testing-drivers",
"org.aspectj.testing.drivers.Harness",
new String[] {"-help"});
}
+ public void testWeaver() {
+ checkBuild("weaver");
+ }
// ajdoc relies on tools.jar
public void testAspectjtools() {
checkBuildProduct(productDir, baseDir, distDir, jarDir);
}
-
void checkBuildProduct(File productDir, File baseDir, File distDir, File jarDir) {
if (!shouldBuild(productDir.getPath())) {
return;
File getAntJar() {
return new File("../lib/ant/lib/ant.jar");
}
+ File getJUnitJar() {
+ return new File("../lib/junit/junit.jar");
+ }
File getJarDir() {
if (null == jarDir) {
void checkBuild(String module,
String classname,
String[] args) {
- checkBuild(module, classname, args, false);
+ checkBuild(module, classname, args, true);
}
boolean shouldBuild(String target) {
+ if (null == target) {
+ return false;
+ }
if (!building && !printedMessage) {
System.err.println(SKIP_MESSAGE + target + " (this is the only warning)");
printedMessage = true;
}
- for (int i = 0; i < SKIPS.length; i++) {
- if (SKIPS[i].equals(target)) {
- if (printInfoMessages) {
- System.err.println(target + " skipped build test [" + getClass().getName() + ".shouldBuild(..)]");
+ if (debugging()) {
+ for (int i = 0; i < DEBUGS.length; i++) {
+ if (target.equals(DEBUGS[i])) {
+ return true;
+ }
+ }
+ return false;
+ } else {
+ for (int i = 0; i < SKIPS.length; i++) {
+ if (SKIPS[i].equals(target)) {
+ if (printInfoMessages) {
+ System.err.println(target + " skipped build test [" + getClass().getName() + ".shouldBuild(..)]");
+ }
+ return false;
}
- return false;
}
}
return building;
}
+ private static boolean debugging() {
+ return ((null != DEBUGS) && (0 < DEBUGS.length));
+ }
+ private static String name(String module, boolean trimTesting, boolean assemble) {
+ return module + (trimTesting?"":"-test") + (assemble?"-all":"");
+ }
+ private static void deleteJar(File jar) {
+ if (jar.exists()) {
+ jar.delete();
+ }
+ if (jar.exists()) {
+ try {
+ Thread.sleep(5000);
+ } catch (Throwable t) {
+ }
+ }
+ if (jar.exists()) {
+ assertTrue("cannot delete " + jar, jar.delete());
+ }
+ }
void checkBuild(String module,
String classname,
String[] args,
}
assertTrue(null != module);
checkJavac();
-
- // run without assembly
- BuildModule task = getTask(module);
- File jar = new File(getJarDir(), module + ".jar");
- task.setAssembleall(false);
- task.execute();
- assertTrue("cannot read " + jar, jar.canRead());
- assertTrue("cannot delete " + jar, jar.delete());
+ File jar;
+ jar = doTask(module, true, false);
+ deleteJar(jar);
+ jar = doTask(module, true, true);
+ deleteJar(jar);
+ jar = doTask(module, false, false);
+ deleteJar(jar);
+ jar = doTask(module, false, true);
- // run with assembly
- task = getTask(module);
- task.setAssembleall(true);
- task.execute();
- jar = new File(getJarDir(), module + "-all.jar");
- assertTrue("cannot read " + jar, jar.canRead());
// verify if possible
- if (null == classname) {
- return;
- }
-
- Java java = new Java();
- Project project = task.getProject();
- java.setProject(project);
- java.setFailonerror(true);
- Path cp = new Path(project);
- cp.append(new Path(project, jar.getAbsolutePath()));
- if (addAnt) {
- cp.append(new Path(project, getAntJar().getAbsolutePath()));
- }
- java.setClasspath(cp);
- java.setClassname(classname);
- if (null != args) {
- for (int i = 0; i < args.length; i++) {
- Argument arg = java.createArg();
- arg.setValue(args[i]);
+ if (null != classname) {
+ Java java = new Java();
+ Project project = new Project();
+ java.setProject(project);
+ java.setFailonerror(true);
+ Path cp = new Path(project);
+ assertTrue(jar.canRead());
+ cp.append(new Path(project, jar.getAbsolutePath()));
+ if (addAnt) {
+ cp.append(new Path(project, getAntJar().getAbsolutePath()));
+ cp.append(new Path(project, getJUnitJar().getAbsolutePath()));
+ }
+ java.setClasspath(cp);
+ java.setClassname(classname);
+ if (null != args) {
+ for (int i = 0; i < args.length; i++) {
+ Argument arg = java.createArg();
+ arg.setValue(args[i]);
+ }
+ }
+ try {
+ java.execute();
+ } catch (BuildException e) {
+ e.printStackTrace(System.err);
+ assertTrue("BuildException running " + classname, false);
}
}
- try {
- java.execute();
- } catch (BuildException e) {
- e.printStackTrace(System.err);
- assertTrue("BuildException running " + classname, false);
+
+ }
+
+ File doTask(String module, boolean trimTesting, boolean assembleAll) {
+ BuildModule task = getTask(module);
+ String name = name(module, trimTesting, assembleAll);
+ File jar = new File(getJarDir(), name+ ".jar");
+ task.setAssembleall(assembleAll);
+ task.setTrimtesting(trimTesting);
+ task.execute();
+ if (!jar.canRead()) {
+ File[] files = getJarDir().listFiles();
+ fail("cannot read " + jar + " in " + Arrays.asList(files));
}
+ return jar;
}
void checkJavac() {