From: Andy Clement
Date: Fri, 1 Feb 2019 20:59:56 +0000 (-0800)
Subject: mavenizing build - done
X-Git-Tag: V1_9_3RC1~38
X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=45a255c029a4ea6e67d18b43593b36fd53d146db;p=aspectj.git
mavenizing build - done
---
diff --git a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AJInstaller.java b/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AJInstaller.java
deleted file mode 100644
index 6bc2fc09b..000000000
--- a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AJInstaller.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/* *******************************************************************
- * 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 Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-
-//XXX INCLUDES CODE FROM ANT -- UNDER APACHE LICENSE
-package org.aspectj.internal.tools.ant.taskdefs;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringBufferInputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.zip.CRC32;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.Copy;
-import org.apache.tools.ant.taskdefs.Delete;
-import org.apache.tools.ant.taskdefs.Expand;
-import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.apache.tools.ant.types.FileSet;
-import org.apache.tools.ant.types.PatternSet;
-
-public class AJInstaller extends MatchingTask {
- static final String INCLUDE_CLASSES = "$installer$/org/aspectj/*.class";
- static final String MAIN_CLASS = "$installer$.org.aspectj.Main";
- static final String CONTENTS_FILE = "$installer$/org/aspectj/resources/contents.txt";
- private String htmlSrc;
-
- public void setHtmlSrc(String v) { htmlSrc = v; }
-
- private String resourcesSrc;
-
- public void setResourcesSrc(String v) { resourcesSrc = v; }
-
- private String mainclass;
-
- public void setMainclass(String v) { mainclass = v; }
-
- private File installerClassJar;
-
- public void setInstallerclassjar(String v) {
- installerClassJar = project.resolveFile(v);
- }
-
- protected List contentsNames = new ArrayList();
-
- protected long contentsBytes = 0;
-
- protected void addToContents(File file, String vPath) {
- contentsNames.add(vPath);
- contentsBytes += file.length();
- }
-
- String[] getFiles(File baseDir) {
- DirectoryScanner ds = new DirectoryScanner();
- setBasedir(baseDir.getAbsolutePath());
- ds.setBasedir(baseDir);
- //ds.setIncludes(new String [] {pattern});
- ds.scan();
- return ds.getIncludedFiles();
- }
-
- protected Copy getCopyTask() {
- Copy cd = (Copy)project.createTask("copy");
- if (null == cd) {
- log("project.createTask(\"copy\") failed - direct", Project.MSG_VERBOSE);
- cd = new Copy();
- cd.setProject(getProject());
- }
- return cd;
- }
- protected void finishZipOutputStream(ZipOutputStream zOut) throws IOException, BuildException {
- writeContents(zOut);
- writeManifest(zOut);
- File tempDir = setupTempDir();
- String tmp = tempDir.getAbsolutePath();
-
- // installer class files
- Expand expand = new Expand();
- expand.setProject(getProject());
- expand.setSrc(installerClassJar);
- expand.setDest(new File(tmp));
- PatternSet patterns = new PatternSet();
- patterns.setIncludes(INCLUDE_CLASSES);
- expand.addPatternset(patterns);
- expand.execute();
-
- // move the correct resource files into the jar
- Copy cd = getCopyTask();
- fileset = new FileSet();
- fileset.setDir(new File(resourcesSrc));
- fileset.setIncludes("*");
- fileset.setExcludes("contents.txt,properties.txt");
- cd.addFileset(fileset);
- cd.setTodir(new File(tmp+"/$installer$/org/aspectj/resources"));
- cd.execute();
- project.getGlobalFilterSet().addFilter("installer.main.class", this.mainclass);
- Copy cf = getCopyTask();
- fileset = new FileSet();
- fileset.setDir(new File(resourcesSrc));
- fileset.setIncludes("properties.txt");
- cf.setFiltering(true);
- cf.addFileset(fileset);
- cf.setTodir(new File(tmp+"/$installer$/org/aspectj/resources"));
- cf.execute();
- // move the correct resource files into the jar
- cd = getCopyTask();
- fileset = new FileSet();
- fileset.setDir(new File(htmlSrc));
- fileset.setIncludes("*");
- cd.addFileset(fileset);
- cd.setTodir(new File(tmp+"/$installer$/org/aspectj/resources"));
- cd.execute();
- // now move these files into the jar
- setBasedir(tmp);
- writeFiles(zOut, getFiles(tempDir));
- // and delete the tmp dir
- Delete dt = (Delete)project.createTask("delete");
- if (null == dt) {
- dt = new Delete();
- dt.setProject(getProject());
- }
- dt.setDir(tempDir);
- dt.execute();
- tempDir = null;
- }
-
- static final char NEWLINE = '\n';
-
- protected void writeContents(ZipOutputStream zOut) throws IOException {
- // write to a StringBuffer
- StringBuffer buf = new StringBuffer();
- buf.append(contentsBytes);
- buf.append(NEWLINE);
- for (Iterator i = contentsNames.iterator(); i.hasNext(); ) {
- String name = (String)i.next();
- buf.append(name);
- buf.append(NEWLINE);
- }
- zipFile(new StringBufferInputStream(buf.toString()), zOut, CONTENTS_FILE, System.currentTimeMillis());
- }
-
- protected void writeManifest(ZipOutputStream zOut) throws IOException {
- // write to a StringBuffer
- StringBuffer buf = new StringBuffer();
- buf.append("Manifest-Version: 1.0");
- buf.append(NEWLINE);
- buf.append("Main-Class: " + MAIN_CLASS);
- buf.append(NEWLINE);
- zipFile(new StringBufferInputStream(buf.toString()), zOut, "META-INF/MANIFEST.MF", System.currentTimeMillis());
- }
-
- //XXX cut-and-paste from Zip super-class (under apache license)
- private File zipFile;
- private File baseDir;
- private boolean doCompress = true;
- protected String archiveType = "zip";
-
- /**
- * This is the name/location of where to
- * create the .zip file.
- */
- public void setZipfile(String zipFilename) {
- zipFile = project.resolveFile(zipFilename);
- }
-
- /**
- * This is the base directory to look in for
- * things to zip.
- */
- public void setBasedir(String baseDirname) {
- baseDir = project.resolveFile(baseDirname);
- }
-
- /**
- * Sets whether we want to compress the files or only store them.
- */
- public void setCompress(String compress) {
- doCompress = Project.toBoolean(compress);
- }
-
- protected void initZipOutputStream(ZipOutputStream zOut)
- throws IOException, BuildException
- {
- }
-
- protected void zipDir(File dir, ZipOutputStream zOut, String vPath)
- throws IOException
- {
- }
-
- protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath,
- long lastModified)
- throws IOException
- {
- ZipEntry ze = new ZipEntry(vPath);
- ze.setTime(lastModified);
-
- /*
- * XXX ZipOutputStream.putEntry expects the ZipEntry to know its
- * size and the CRC sum before you start writing the data when using
- * STORED mode.
- *
- * This forces us to process the data twice.
- *
- * I couldn't find any documentation on this, just found out by try
- * and error.
- */
- if (!doCompress) {
- long size = 0;
- CRC32 cal = new CRC32();
- if (!in.markSupported()) {
- // Store data into a byte[]
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- byte[] buffer = new byte[8 * 1024];
- int count = 0;
- do {
- size += count;
- cal.update(buffer, 0, count);
- bos.write(buffer, 0, count);
- count = in.read(buffer, 0, buffer.length);
- } while (count != -1);
- in = new ByteArrayInputStream(bos.toByteArray());
- } else {
- in.mark(Integer.MAX_VALUE);
- byte[] buffer = new byte[8 * 1024];
- int count = 0;
- do {
- size += count;
- cal.update(buffer, 0, count);
- count = in.read(buffer, 0, buffer.length);
- } while (count != -1);
- in.reset();
- }
- ze.setSize(size);
- ze.setCrc(cal.getValue());
- }
- zOut.putNextEntry(ze);
- byte[] buffer = new byte[8 * 1024];
- int count = 0;
- do {
- zOut.write(buffer, 0, count);
- count = in.read(buffer, 0, buffer.length);
- } while (count != -1);
- }
-
- protected void zipFile(File file, ZipOutputStream zOut, String vPath)
- throws IOException
- {
- if ( !vPath.startsWith("$installer$") ) {
- addToContents(file, vPath);
- }
- FileInputStream fIn = new FileInputStream(file);
- try {
- zipFile(fIn, zOut, vPath, file.lastModified());
- } finally {
- fIn.close();
- }
- }
- private File setupTempDir() throws BuildException {
- File tmpDirF = null;
- File tmpDir = null;
- try {
- tmpDirF = File.createTempFile("tgz", ".di");
- tmpDir = new File(tmpDirF.getParentFile(), "AJInstaller");
- tmpDirF.delete();
- } catch (IOException e) {
- // retrying below
- }
- if (null == tmpDir || !tmpDir.mkdirs()) {
- tmpDir = new File("AJInstaller.finishZipOutputStream.tmp");
- if (!tmpDir.mkdirs()) {
- throw new BuildException("unable to make temp dir");
- }
- }
- return tmpDir;
- }
-
- public void execute() throws BuildException {
- if (installerClassJar == null) {
- throw new BuildException("installerClassJar attribute must be set!");
- }
- if (!installerClassJar.canRead()
- || !installerClassJar.getPath().endsWith(".jar")) {
- throw new BuildException("not readable jar:" + installerClassJar);
- }
-// if (installerClassDir == null) {
-// throw new BuildException("installerClassDir attribute must be set!");
-// }
-// if (!installerClassDir.exists()) {
-// throw new BuildException("no such directory: installerClassDir=" + installerClassDir);
-// }
- if (baseDir == null) {
- throw new BuildException("basedir attribute must be set!");
- }
- if (!baseDir.exists()) {
- throw new BuildException("basedir does not exist!");
- }
- DirectoryScanner ds = super.getDirectoryScanner(baseDir);
- String[] files = ds.getIncludedFiles();
- String[] dirs = ds.getIncludedDirectories();
- log("Building installer: "+ zipFile.getAbsolutePath());
- ZipOutputStream zOut = null;
- try {
- zOut = new ZipOutputStream(new FileOutputStream(zipFile));
- if (doCompress) {
- zOut.setMethod(ZipOutputStream.DEFLATED);
- } else {
- zOut.setMethod(ZipOutputStream.STORED);
- }
- initZipOutputStream(zOut);
- writeDirs(zOut, dirs);
- writeFiles(zOut, files);
- finishZipOutputStream(zOut); // deletes temp dir
- } catch (IOException ioe) {
- String msg = "Problem creating " + archiveType + " " + ioe.getMessage();
- throw new BuildException(msg, ioe, location);
- } finally {
- if (zOut != null) {
- try {
- // close up
- zOut.close();
- }
- catch (IOException e) {}
- }
- }
- }
-
- protected void writeDirs(ZipOutputStream zOut, String[] dirs) throws IOException {
- for (int i = 0; i < dirs.length; i++) {
- File f = new File(baseDir,dirs[i]);
- String name = dirs[i].replace(File.separatorChar,'/')+"/";
- zipDir(f, zOut, name);
- }
- }
-
- protected void writeFiles(ZipOutputStream zOut, String[] files) throws IOException {
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir,files[i]);
- String name = files[i].replace(File.separatorChar,'/');
- zipFile(f, zOut, name);
- }
- }
-
-}
diff --git a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AJPush.java b/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AJPush.java
deleted file mode 100644
index 26ab7ce5f..000000000
--- a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AJPush.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/* *******************************************************************
- * 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 Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-
-package org.aspectj.internal.tools.ant.taskdefs;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.text.DecimalFormat;
-import java.util.Properties;
-
-import org.apache.tools.ant.taskdefs.Mkdir;
-
-public class AJPush extends ConditionalTask {
- private File src;
-
- public void setSrc(String v) { src = project.resolveFile(v); }
-
- private String key;
-
- public void setKey(String v) { key = v; }
-
- File releaseDir = null;
- File downloadDir = null;
- boolean waiting = false;
-
- public void execute() throws org.apache.tools.ant.BuildException {
- //File releaseDir = src.getParentFile();
- // todo: dependency on ant script variable name aj.release.dir
- releaseDir = project.resolveFile(project.getProperty("aj.release.dir"));
- // todo: dependency on ant script variable name download.dir
- downloadDir = project.resolveFile(project.getProperty("download.dir"));
- // For testing make sure these directories are made
- Mkdir mkdir = (Mkdir) project.createTask("mkdir");
- mkdir.setDir(releaseDir);
- mkdir.execute();
- mkdir = (Mkdir) project.createTask("mkdir");
- mkdir.setDir(downloadDir);
- mkdir.execute();
- log("Pushing from " + releaseDir + " to " + downloadDir);
- // add info to release.txt
- try {
- File releaseFile = new File(releaseDir, "release.txt");
- File downloadFile = new File(downloadDir, "release.txt");
- if (!releaseFile.canRead()) {
- releaseFile.createNewFile();
- }
- addReleaseInfo(src, releaseFile);
- // copy to staging web server
- project.copyFile(src, new File(downloadDir, src.getName()));
- project.copyFile(releaseFile, downloadFile);
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
-
- void addReleaseInfo(File file, File propFile) throws IOException {
- Properties props = new Properties();
- if (propFile.canRead()) {
- props.load(new FileInputStream(propFile));
- }
- file.createNewFile(); // create new only if necessary
- long bytes = file.length();
- DecimalFormat df = new DecimalFormat();
- df.setGroupingSize(3);
- String bytesString = df.format(bytes);
- props.put("release." + key + ".size.bytes", bytesString);
- props.put("release." + key + ".date", project.getProperty("build.date"));
- props.put("release." + key + ".filename", file.getName());
- props.put("release.date", project.getProperty("build.date"));
- props.put("release.version", project.getProperty("build.version.short"));
- props.put("release.versionName", project.getProperty("build.version.long"));
- String userName = System.getProperty("user.name");
- if (userName != null) {
- props.put("release." + key + ".username", userName);
- }
- props.store(new FileOutputStream(propFile), null);
- }
-
-}
diff --git a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AntBuilder.java b/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AntBuilder.java
deleted file mode 100644
index d65c50501..000000000
--- a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/AntBuilder.java
+++ /dev/null
@@ -1,833 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * 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://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-package org.aspectj.internal.tools.ant.taskdefs;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Target;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.Copy;
-import org.apache.tools.ant.taskdefs.Javac;
-import org.apache.tools.ant.taskdefs.Zip;
-import org.apache.tools.ant.types.FileSet;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.ZipFileSet;
-import org.aspectj.internal.tools.build.BuildSpec;
-import org.aspectj.internal.tools.build.Builder;
-import org.aspectj.internal.tools.build.Messager;
-import org.aspectj.internal.tools.build.Module;
-import org.aspectj.internal.tools.build.Result;
-import org.aspectj.internal.tools.build.Util;
-
-/**
- * Implement Builder in Ant.
- */
-public class AntBuilder extends Builder {
- private static final boolean FORCE_FORK_FOR_LIBRARIES = false;
-
- /**
- * Factory for a Builder.
- *
- * @param config the String configuration, where only substrings "verbose" and "useEclipseCompiles" are significant
- * @param project the owning Project for all tasks (not null)
- * @param tempDir the File path to a temporary dir for side effects (may be null)
- * @return a Builder for this project and configuration
- */
- public static Builder getBuilder(String config, Project project, File tempDir) {
- boolean useEclipseCompiles = false;
- boolean verbose = false;
- if (null != config) {
- if (-1 != config.indexOf("useEclipseCompiles")) {
- useEclipseCompiles = true;
- }
- if (-1 != config.indexOf("verbose")) {
- verbose = true;
- }
- }
- // Messager handler = new Messager(); // debugging
- Messager handler = new ProjectMessager(project);
- Builder result = new ProductBuilder(project, tempDir, useEclipseCompiles, handler);
- if (verbose) {
- result.setVerbose(true);
- }
- return result;
- }
-
- private static String resultToTargetName(Result result) {
- return result.getName();
- }
-
- /**
- * Ensure targets exist for this module and all antecedants, so topoSort can work.
- */
- private static void makeTargetsForResult(final Result result, final Hashtable targets) {
- final String resultTargetName = resultToTargetName(result);
- Target target = targets.get(resultTargetName);
- if (null == target) {
- // first add the target
- target = new Target();
- target.setName(resultTargetName);
-
- Result[] reqs = result.getRequired();
- StringBuffer depends = new StringBuffer();
- boolean first = true;
- for (int i = 0; i < reqs.length; i++) {
- Result reqResult = reqs[i];
- if (!first) {
- depends.append(",");
- } else {
- first = false;
- }
- depends.append(resultToTargetName(reqResult));
- }
- if (0 < depends.length()) {
- target.setDepends(depends.toString());
- }
- targets.put(resultTargetName, target);
-
- // then recursively add any required results
- for (int i = 0; i < reqs.length; i++) {
- Result reqResult = reqs[i];
- makeTargetsForResult(reqResult, targets);
- }
- }
- }
-
- private final Project project;
-
- protected AntBuilder(Project project, File tempDir, boolean useEclipseCompiles, Messager handler) {
- super(tempDir, useEclipseCompiles, handler);
- this.project = project;
- Util.iaxIfNull(project, "project");
- }
-
- /**
- * Initialize task with project and "ajbuild-" + name as name. (Using bm- prefix distinguishes these tasks from tasks found in
- * the build script.)
- *
- * @param task the Task to initialize - not null
- * @param name the String name suffix for the task
- * @return true unless some error
- */
- protected boolean setupTask(Task task, String name) {
- task.setProject(project);
- task.setTaskName("ajbuild-" + name);
- return true;
- }
-
- /**
- * Copy file, optionally filtering. (Filters set in project.)
- *
- * @param fromFile the readable File source to copy
- * @param toFile the writable File destination file
- * @param boolean filter if true, enable filtering
- * @see org.aspectj.internal.tools.build.Builder#copyFile(File, File, boolean)
- */
- @Override
- protected boolean copyFile(File fromFile, File toFile, boolean filter) {
- Copy copy = makeCopyTask(filter);
- copy.setFile(fromFile);
- copy.setTofile(toFile);
- executeTask(copy);
- return true;
- }
-
- /**
- * (Filters set in project.)
- *
- * @see org.aspectj.internal.tools.ant.taskdefs.Builder#copyFiles(File, File, String, String, boolean)
- */
- @Override
- protected boolean copyFiles(File fromDir, File toDir, String includes, String excludes, boolean filter) {
- Copy copy = makeCopyTask(filter);
- copy.setTodir(toDir);
- FileSet fileset = new FileSet();
- fileset.setDir(fromDir);
- if (null != includes) {
- fileset.setIncludes(includes);
- }
- if (null != excludes) {
- fileset.setExcludes(excludes);
- }
- copy.addFileset(fileset);
- executeTask(copy);
-
- return false;
- }
-
- protected void copyFileset(File toDir, FileSet fileSet, boolean filter) {
- Copy copy = makeCopyTask(filter);
- copy.addFileset(fileSet);
- copy.setTodir(toDir);
- executeTask(copy);
- }
-
- /**
- * @param filter if FILTER_ON, use filters
- */
- protected Copy makeCopyTask(boolean filter) {
- Copy copy = new Copy();
- setupTask(copy, "copy");
- if (FILTER_ON == filter) {
- copy.setFiltering(true);
- }
- return copy;
- }
-
- protected void dumpMinFile(Result result, File classesDir, List errors) {
- String name = result.getName() + "-empty";
- File minFile = new File(classesDir, name);
- FileWriter fw = null;
- try {
- fw = new FileWriter(minFile);
- fw.write(name);
- } catch (IOException e) {
- errors.add("IOException writing " + name + " to " + minFile + ": " + Util.renderException(e));
- } finally {
- Util.close(fw);
- }
-
- }
-
- @Override
- protected boolean compile(Result result, File classesDir, boolean useExistingClasses, List errors) {
- if (!classesDir.exists() && !classesDir.mkdirs()) {
- errors.add("compile - unable to create " + classesDir);
- return false;
- }
- if (useExistingClasses) {
- return true;
- }
- // -- source paths
- Path path = new Path(project);
- boolean hasSourceDirectories = false;
- boolean isJava5Compile = false;
- boolean isJava8Compile = false;
- for (File file: result.getSrcDirs()) {
- path.createPathElement().setLocation(file);
- if (!isJava5Compile
- && (Util.Constants.JAVA5_SRC.equals(file.getName()) ||
- Util.Constants.JAVA5_TESTSRC.equals(file.getName()) ||
- new File(file.getParent(), ".isJava5").exists())) {
- isJava5Compile = true;
- }
- if (new File(file.getParent(),".isJava8").exists()) {
- isJava8Compile = true;
- }
- if (!hasSourceDirectories) {
- hasSourceDirectories = true;
- }
- }
- if (!hasSourceDirectories) {
- return true; // nothing to compile - ok
- }
- // XXX test whether build.compiler property takes effect automatically
- // I suspect it requires the proper adapter setup.
- Javac javac = new Javac();
- setupTask(javac, "javac");
- javac.setIncludeantruntime(false);
- javac.setDestdir(classesDir);
- javac.setSrcdir(path);
- javac.setVerbose(verbose);
- path = null;
-
- // -- classpath
- Path classpath = new Path(project);
- boolean hasLibraries = setupClasspath(result, classpath);
- if (hasLibraries && FORCE_FORK_FOR_LIBRARIES) {
- javac.setFork(true); // otherwise never releases library jars
- // can we build under 1.4, but fork javac 1.5 compile?
- }
- // also fork if using 1.5?
-
- // -- set output directory
- classpath.createPathElement().setLocation(classesDir);
- javac.setClasspath(classpath);
-
- // misc
- javac.setDebug(true);
- if (isJava8Compile) {
- javac.setSource("1.8");
- javac.setTarget("1.8");
- } else if (isJava5Compile) {
- // *cough*
- javac.setSource("1.6");
- javac.setTarget("1.6");
- } else {
- javac.setTarget("1.1"); // 1.1 class files - Javac in 1.4 uses 1.4
- javac.setSource("1.3");
- }
- // compile
- boolean passed = false;
- BuildException failure = null;
- try {
- passed = executeTask(AspectJSupport.wrapIfNeeded(result, javac));
- } catch (BuildException e) {
- failure = e;
- } catch (Error e) {
- failure = new BuildException(e);
- } catch (RuntimeException e) {
- failure = new BuildException(e);
- } finally {
- if (!passed) {
- String args = "" + Arrays.asList(javac.getCurrentCompilerArgs());
- if ("[]".equals(args)) {
- args = "{" + result.toLongString() + "}";
- }
- String m = "BuildException compiling " + result.toLongString() + args
- + (null == failure ? "" : ": " + Util.renderException(failure));
- // debuglog System.err.println(m);
- errors.add(m);
- }
- javac.init(); // be nice to let go of classpath libraries...
- }
- return passed;
- }
-
- public boolean setupClasspath(Result result, Path classpath) { // XXX fix test access
- boolean hasLibraries = false;
- // required libraries
- for (Iterator iter = result.getLibJars().iterator(); iter.hasNext();) {
- File file = (File) iter.next();
- classpath.createPathElement().setLocation(file);
- if (!hasLibraries) {
- hasLibraries = true;
- }
- }
- // Westodo Kind kind = result.getKind();
- Result[] reqs = result.getRequired();
- // required modules and their exported libraries
- for (int i = 0; i < reqs.length; i++) {
- Result requiredResult = reqs[i];
- classpath.createPathElement().setLocation(requiredResult.getOutputFile());
- if (!hasLibraries) {
- hasLibraries = true;
- }
- // also put on classpath libraries exported from required module
- // XXX exported modules not supported
- for (Iterator iterator = requiredResult.getExportedLibJars().iterator(); iterator.hasNext();) {
- classpath.createPathElement().setLocation((File) iterator.next());
- }
- }
- return hasLibraries;
- }
-
- /**
- * Merge classes directory and any merge jars into module jar with any specified manifest file. META-INF directories are
- * excluded.
- */
- @Override
- protected boolean assemble(Result result, File classesDir, List errors) {
- if (!buildingEnabled) {
- return false;
- }
- if (!result.outOfDate()) {
- return true;
- }
-
- // ---- zip result up
- Zip zip = new Zip();
- setupTask(zip, "zip");
- zip.setDestFile(result.getOutputFile());
- ZipFileSet zipfileset = null;
-
- // -- merge any resources in any of the src directories
- for (Iterator iter = result.getSrcDirs().iterator(); iter.hasNext();) {
- File srcDir = (File) iter.next();
- zipfileset = new ZipFileSet();
- zipfileset.setProject(project);
- zipfileset.setDir(srcDir);
- zipfileset.setIncludes(RESOURCE_PATTERN);
- zip.addZipfileset(zipfileset);
- }
-
- final Module module = result.getModule();
-
- File metaInfDir = new File(classesDir, "META-INF");
- Util.deleteContents(metaInfDir);
-
- // -- manifest
- File manifest = new File(module.moduleDir, module.name + ".mf.txt"); // XXXFileLiteral
- if (Util.canReadFile(manifest)) {
- if (Util.canReadDir(metaInfDir) || metaInfDir.mkdirs()) {
- // Jar spec requires a MANIFEST.MF not a manifest.mf
- copyFile(manifest, new File(metaInfDir, "MANIFEST.MF"), FILTER_ON); // XXXFileLiteral
- } else {
- errors.add("have manifest, but unable to create " + metaInfDir);
- return false;
- }
- }
-
- zipfileset = new ZipFileSet();
- zipfileset.setProject(project);
- zipfileset.setDir(classesDir);
- zipfileset.setIncludes("**/*");
- zip.addZipfileset(zipfileset);
- File[] contents = classesDir.listFiles();
- if ((null == contents) || (0 == contents.length)) {
- // *something* to zip up
- dumpMinFile(result, classesDir, errors);
- }
-
- try {
- handler.log("assemble " + module + " in " + result.getOutputFile());
- return executeTask(zip)
- // zip returns true when it doesn't create zipfile
- // because there are no entries to add, so verify done
- && Util.canReadFile(result.getOutputFile());
- } catch (BuildException e) {
- errors.add("BuildException zipping " + module + ": " + e.getMessage());
- return false;
- } finally {
- result.clearOutOfDate();
- }
- }
-
- /**
- * @see org.aspectj.internal.tools.build.Builder#buildAntecedants(Module)
- */
- @Override
- protected Result[] getAntecedantResults(Result moduleResult) {
- Hashtable targets = new Hashtable();
- makeTargetsForResult(moduleResult, targets);
- String targetName = resultToTargetName(moduleResult);
- // bug: doc says topoSort returns String, but returns Target
- Collection result = project.topoSort(targetName, targets);
- // fyi, we don't rely on topoSort to detect cycles - see buildAll
- int size = result.size();
- if (0 == result.size()) {
- return new Result[0];
- }
- ArrayList toReturn = new ArrayList();
- for (Iterator iter = result.iterator(); iter.hasNext();) {
- Target target = iter.next();
- String name = target.getName();
- if (null == name) {
- throw new Error("null name?");
- } else {
- toReturn.add(name);
- }
- }
- // topoSort always returns target name
- if ((1 == size) && targetName.equals(toReturn.get(0)) && !moduleResult.outOfDate()) {
- return new Result[0];
- }
- return Result.getResults(toReturn.toArray(new String[0]));
- }
-
- /**
- * Generate Module.assembledJar with merge of itself and all antecedants
- */
- @Override
- protected boolean assembleAll(Result result, Messager handler) {
- if (!buildingEnabled) {
- return false;
- }
- if (!result.outOfDate()) {
- return true;
- }
-
- Util.iaxIfNull(result, "result");
- Util.iaxIfNull(handler, "handler");
- if (!result.getKind().isAssembly()) {
- throw new IllegalStateException("not assembly: " + result);
- }
-
- // ---- zip result up
- Zip zip = new Zip();
- setupTask(zip, "zip");
- zip.setDestFile(result.getOutputFile());
- ZipFileSet zipfileset = null;
- final Module module = result.getModule();
- List known = result.findJarRequirements();
- removeLibraryFilesToSkip(module, known);
- // -- merge any antecedents, less any manifest
- for (File jarFile: known) {
- zipfileset = new ZipFileSet();
- zipfileset.setProject(project);
- zipfileset.setSrc(jarFile);
- zipfileset.setIncludes("**/*");
- String name = jarFile.getName();
- name = name.substring(0, name.length() - 4); // ".jar".length()
- // required includes self - exclude manifest from others
- if (!module.name.equals(name)) {
- zipfileset.setExcludes("META-INF/MANIFEST.MF"); // XXXFileLiteral
- zipfileset.setExcludes("META-INF/manifest.mf");
- zipfileset.setExcludes("meta-inf/manifest.mf");
- zipfileset.setExcludes("meta-inf/MANIFEST.MF");
- }
- zip.addZipfileset(zipfileset);
- }
-
- try {
- handler.log("assembling all " + module + " in " + result.getOutputFile());
- if (verbose) {
- handler.log("knownAntecedants: " + known);
- }
- return executeTask(zip);
- } catch (BuildException e) {
- handler.logException("BuildException zipping " + module, e);
- return false;
- } finally {
- result.clearOutOfDate();
- }
- }
-
- /**
- * @see org.aspectj.internal.tools.ant.taskdefs.Builder#buildInstaller(BuildSpec, String)
- */
- @Override
- protected boolean buildInstaller(BuildSpec buildSpec, String targDirPath) {
- return false;
- }
-
- /** task.execute() and any advice */
- protected boolean executeTask(Task task) {
- if (!buildingEnabled) {
- return false;
- }
- task.execute();
- return true;
- }
-
- /**
- * Support for compiling basic AspectJ projects. Projects may only compile all (and only) their source directories; aspectpath,
- * inpath, etc. are not supported. To load the compiler, this assumes the user has either defined a project property
- * "aspectj.home" or that there exists {module-dir}/lib/aspectj/lib/aspectj[tools|rt].jar
.
- */
- static class AspectJSupport {
- static final String AJCTASK = "org.aspectj.tools.ant.taskdefs.AjcTask";
- static final String ASPECTJRT_JAR_VARIABLE = "ASPECTJRT_LIB";
- static final String LIBASPECTJ_RPATH = "/lib/aspectj";
- static final Map nameToAspectjrtjar = new HashMap();
- static final String NONE = "NONE";
-
- /**
- * If this module should be compiled with AspectJ, return a task to do so.
- *
- * @param module the Module to compile
- * @param javac the Javac compile commands
- * @return javac or a Task to compile with AspectJ if needed
- */
- static Task wrapIfNeeded(Result result, Javac javac) {
- final Project project = javac.getProject();
- Path runtimeJar = null;
- final Module module = result.getModule();
- if (runtimeJarOnClasspath(result)) {
- // yes aspectjrt.jar on classpath
- } else if (result.getClasspathVariables().contains(ASPECTJRT_JAR_VARIABLE)) {
- // yes, in variables - find aspectjrt.jar to add to classpath
- runtimeJar = getAspectJLib(project, module, "aspectjrt.jar");
- } else {
- // no
- // System.out.println("javac " + result + " " + javac.getClasspath());
- return javac;
- }
- // System.out.println("aspectj " + result + " " + javac.getClasspath());
- Path aspectjtoolsJar = getAspectJLib(project, module, "aspectjtools.jar");
- return aspectJTask(javac, aspectjtoolsJar, runtimeJar);
- }
-
- /** @return true if aspectjrt.jar is on classpath */
- private static boolean runtimeJarOnClasspath(Result result) {
- for (File file: result.getLibJars()) {
- if ("aspectjrt.jar".equals(file.getName())) {
- return true;
- }
- }
- return false;
- }
-
- static Path getAspectJLib(Project project, Module module, String name) {
- Path result = null;
- String[] libDirNames = { "aspectj.home", "ASPECTJ_HOME", LIBASPECTJ_RPATH };
- String[] libDirs = new String[libDirNames.length];
- for (int i = 0; i < libDirNames.length; i++) {
- if (LIBASPECTJ_RPATH == libDirNames[i]) {
- libDirs[i] = module.getFullPath(LIBASPECTJ_RPATH);
- } else {
- libDirs[i] = project.getProperty(libDirNames[i]);
- }
- if (null != libDirs[i]) {
- libDirs[i] = Util.path(libDirs[i], "lib");
- result = new Path(project, Util.path(libDirs[i], name));
- String path = result.toString();
- if (new File(path).canRead()) {
- return result;
- }
- }
- }
- String m = "unable to find " + name + " in " + Arrays.asList(libDirs);
- throw new BuildException(m);
- }
-
- /**
- * Wrap AspectJ compiler as Task. Only works for javac-like source compilation of everything under srcDir. Written
- * reflectively to compile in the build module, which can't depend on the whole tree.
- *
- * @param javac the Javac specification
- * @param toolsJar the Path to the aspectjtools.jar
- * @param runtimeJar the Path to the aspectjrt.jar
- * @return javac or another Task invoking the AspectJ compiler
- */
- @SuppressWarnings("unchecked")
- static Task aspectJTask(Javac javac, Path toolsJar, Path runtimeJar) {
- Object task = null;
- String url = null;
- try {
- url = "file:" + toolsJar.toString().replace('\\', '/');
- URL[] cp = new URL[] { new URL(url) };
- ClassLoader parent = Task.class.getClassLoader();
- ClassLoader loader = new URLClassLoader(cp, parent);
- Class c = loader.loadClass(AJCTASK);
- task = c.newInstance();
- // Westodo Project project = javac.getProject();
- Method m = c.getMethod("setupAjc", new Class[] { Javac.class });
- m.invoke(task, new Object[] { javac });
- m = c.getMethod("setFork", new Class[] { boolean.class });
- m.invoke(task, new Object[] { Boolean.TRUE });
- m = c.getMethod("setForkclasspath", new Class[] { Path.class });
- m.invoke(task, new Object[] { toolsJar });
- m = c.getMethod("setSourceRoots", new Class[] { Path.class });
- m.invoke(task, new Object[] { javac.getSrcdir() });
- if (null != runtimeJar) {
- m = c.getMethod("setClasspath", new Class[] { Path.class });
- m.invoke(task, new Object[] { runtimeJar });
- }
- } catch (BuildException e) {
- throw e;
- } catch (Throwable t) {
- StringBuffer sb = new StringBuffer();
- sb.append("classpath=");
- sb.append(url);
- throw new BuildException(sb.toString(), t);
- }
- return (Task) task;
- }
-
- private AspectJSupport() {
- throw new Error("no instances");
- }
- }
-}
-
-// finally caught by failing to comply with proper ant initialization
-// /**
-// * Build a module that has a build script.
-// * @param buildSpec the module to build
-// * @param buildScript the script file
-// * @throws BuildException if build fails
-// */
-// private void buildByScript(BuildSpec buildSpec, File buildScript)
-// throws BuildException {
-// Ant ant = new Ant();
-// ant.setProject(getProject());
-// ant.setAntfile(buildScript.getAbsolutePath());
-// ant.setDescription("building module " + buildSpec.module);
-// ant.setDir(buildScript.getParentFile());
-// ant.setInheritAll(true);
-// ant.setInheritRefs(false);
-// ant.setLocation(getLocation());
-// ant.setOwningTarget(getOwningTarget());
-// // by convention, for build.xml, use module name to publish
-// ant.setTarget(buildSpec.module);
-// ant.setTaskName("ant");
-// loadAntProperties(ant, buildSpec);
-// ant.execute();
-// }
-//
-// /** override definitions */
-// private void loadAntProperties(Ant ant, BuildSpec buildSpec) {
-// Property property = ant.createProperty();
-// property.setName(BuildSpec.baseDir_NAME);
-// property.setFile(buildSpec.baseDir);
-// property = ant.createProperty();
-// property.setName(buildSpec.distDir_NAME);
-// property.setFile(buildSpec.distDir);
-// property = ant.createProperty();
-// property.setName(BuildSpec.tempDir_NAME);
-// property.setFile(buildSpec.tempDir);
-// property = ant.createProperty();
-// property.setName(BuildSpec.jarDir_NAME);
-// property.setFile(buildSpec.jarDir);
-// property = ant.createProperty();
-// property.setName(BuildSpec.stagingDir_NAME);
-// property.setFile(buildSpec.stagingDir);
-// }
-
-/**
- * Segregate product-building API's from module-building APIs for clarity. These are called by the superclass if the BuildSpec
- * warrants. XXX extremely brittle/arbitrary assumptions.
- *
- * @see BuildModule for assumptions
- */
-class ProductBuilder extends AntBuilder {
-
- private static String getProductInstallResourcesSrc(BuildSpec buildSpec) {
- final String resourcesName = "installer-resources"; // XXXFileLiteral
- File dir = buildSpec.productDir.getParentFile();
- if (null == dir) {
- return Util.path(new String[] { "..", "..", resourcesName });
- }
- dir = dir.getParentFile();
- if (null == dir) {
- return Util.path("..", resourcesName);
- } else {
- dir = new File(dir, resourcesName);
- return dir.getPath();
- }
- }
-
- private static String getProductInstallerFileName(BuildSpec buildSpec) { // XXXFileLiteral
- return "aspectj-" + buildSpec.productDir.getName() + "-" + Util.shortVersion(buildSpec.version) + ".jar";
- }
-
- /**
- * Calculate name of main, typically InitialCap, and hence installer class.
- *
- * @return $$installer$$.org.aspectj." + ProductName + "Installer"
- */
-
- private static String getProductInstallerMainClass(BuildSpec buildSpec) {
- String productName = buildSpec.productDir.getName();
- String initial = productName.substring(0, 1).toUpperCase();
- productName = initial + productName.substring(1);
- return "$installer$.org.aspectj." + productName + "Installer"; // XXXNameLiteral
- }
-
- /** @see Builder.getBuilder(String, Project, File) */
- ProductBuilder(Project project, File tempDir, boolean useEclipseCompiles, Messager handler) {
- super(project, tempDir, useEclipseCompiles, handler);
- }
-
- /**
- * Delegate for super.buildProduct(..) template method.
- */
- @Override
- protected boolean copyBinaries(BuildSpec buildSpec, File distDir, File targDir, String excludes) {
- Copy copy = makeCopyTask(false);
- copy.setTodir(targDir);
- FileSet fileset = new FileSet();
- fileset.setDir(distDir);
- fileset.setIncludes(Builder.BINARY_SOURCE_PATTERN);
- if (null != excludes) {
- fileset.setExcludes(excludes);
- }
- copy.addFileset(fileset);
- return executeTask(copy);
- }
-
- /**
- * Delegate for super.buildProduct(..) template method.
- */
- @Override
- protected boolean copyNonBinaries(BuildSpec buildSpec, File distDir, File targDir) {
- // filter-copy everything but the binaries
- Copy copy = makeCopyTask(true);
- copy.setTodir(targDir);
- Util.iaxIfNotCanReadDir(distDir, "product dist directory");
- FileSet fileset = new FileSet();
- fileset.setDir(distDir);
- fileset.setExcludes(Builder.BINARY_SOURCE_PATTERN);
- copy.addFileset(fileset);
- return executeTask(copy);
- }
-
- @Override
- protected boolean buildInstaller(BuildSpec buildSpec, String targDirPath) {
- if (buildSpec.verbose) {
- handler.log("creating installer for " + buildSpec);
- }
- AJInstaller installer = new AJInstaller();
- setupTask(installer, "installer");
- installer.setBasedir(targDirPath);
- // installer.setCompress();
- File installSrcDir = new File(buildSpec.productDir, "install"); // XXXFileLiteral
- Util.iaxIfNotCanReadDir(installSrcDir, "installSrcDir");
- installer.setHtmlSrc(installSrcDir.getPath());
- String resourcePath = getProductInstallResourcesSrc(buildSpec);
- File resourceSrcDir = new File(resourcePath);
- Util.iaxIfNotCanReadDir(resourceSrcDir, "resourceSrcDir");
- installer.setResourcesSrc(resourcePath);
- String name = getProductInstallerFileName(buildSpec);
- File outFile = new File(buildSpec.jarDir, name);
- installer.setZipfile(outFile.getPath());
- installer.setMainclass(getProductInstallerMainClass(buildSpec));
- installer.setInstallerclassjar(getBuildJar(buildSpec));
- return executeTask(installer);
-
- // -- test installer XXX
- // create text setup file
- // run installer with setup file
- // cleanup installed product
- }
-
- private String getBuildJar(BuildSpec buildSpec) {
- return buildSpec.baseDir.getPath() + "/lib/build/build.jar"; // XXX
- }
-
- // private Module moduleForReplaceFile(File replaceFile, Modules modules) {
- // String jarName = moduleAliasFor(replaceFile.getName().toLowerCase());
- // if (jarName.endsWith(".jar") || jarName.endsWith(".zip")) { // XXXFileLiteral
- // jarName = jarName.substring(0, jarName.length()-4);
- // } else {
- // throw new IllegalArgumentException("can only replace .[jar|zip]");
- // }
- // boolean assembleAll = jarName.endsWith("-all");
- // String name = (!assembleAll ? jarName : jarName.substring(0, jarName.length()-4));
- // return modules.getModule(name);
- // }
- //
-}
-
-class ProjectMessager extends Messager {
- private final Project project;
-
- public ProjectMessager(Project project) {
- Util.iaxIfNull(project, "project");
- this.project = project;
- }
-
- @Override
- public boolean log(String s) {
- project.log(s);
- return true;
- }
-
- @Override
- public boolean error(String s) {
- project.log(s, Project.MSG_ERR);
- return true;
- }
-
- @Override
- public boolean logException(String context, Throwable thrown) {
- project.log(context + Util.renderException(thrown), Project.MSG_ERR);
- return true;
- }
-
-}
\ No newline at end of file
diff --git a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/BuildModule.java b/build/src/main/java./aspectj/internal/tools/ant/taskdefs/BuildModule.java
deleted file mode 100644
index 6ac6b5ba6..000000000
--- a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/BuildModule.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/* *******************************************************************
- * 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 Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-
-
-package org.aspectj.internal.tools.ant.taskdefs;
-
-import java.io.File;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Location;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.Path;
-import org.aspectj.internal.tools.build.BuildSpec;
-import org.aspectj.internal.tools.build.Builder;
-
-/**
- * Ant interface to build a product or module, including any required modules.
- * @see Builder
- */
-public class BuildModule extends Task { // quickie hack...
-
- public static void main(String[] args) {
- TestBuildModule.main(args);
- }
-
- private static File pathToFile(Path path) {
- if (null != path) {
- String[] list = path.list();
- if ((null == list) || (1 != list.length)) {
- throw new IllegalArgumentException("expected exactly 1 element");
- }
- return new File(list[0]);
- }
- return null;
- }
- BuildSpec buildSpec;
-
- public BuildModule() {
- buildSpec = new BuildSpec();
- setTaskName("ajbuild");
- }
-
- public void setModuledir(Path moduleDir) {
- buildSpec.moduleDir = pathToFile(moduleDir);
- }
-
- public void setModule(String module) { // XXX handle multiple modules, same builder
- buildSpec.module = module;
- }
-
- public void setVersion(String version) {
- buildSpec.version = version;
- }
- public void setBasedir(Path baseDir) {
- buildSpec.baseDir = pathToFile(baseDir);
- }
-
- public void setJardir(Path jarDir) {
- buildSpec.jarDir = pathToFile(jarDir);
- }
-
- public void setTrimtesting(boolean trimTesting) {
- buildSpec.trimTesting = trimTesting;
- }
-
- public void setAssembleall(boolean assembleAll) {
- buildSpec.assembleAll = assembleAll;
- }
-
- public void setRebuild(boolean rebuild) {
- buildSpec.rebuild = rebuild;
- }
-
- public void setFailonerror(boolean failonerror) {
- buildSpec.failonerror = failonerror;
- }
-
- public void setCreateinstaller(boolean create) {
- buildSpec.createInstaller = create;
- }
-
- public void setVerbose(boolean verbose) {
- buildSpec.verbose = verbose;
- }
-
- public void setBuildConfig(String buildConfig) {
- buildSpec.buildConfig = buildConfig;
- }
-
- // --------------------------------------------------------- product build
-
- public void setProductdir(Path productDir) {
- buildSpec.productDir = pathToFile(productDir);
- }
-
- public void setTempdir(Path tempDir) {
- buildSpec.tempDir = pathToFile(tempDir);
- }
-
- public void setDistdir(Path distdir) {
- buildSpec.distDir = pathToFile(distdir);
- }
-
- public void execute() throws BuildException {
- final BuildSpec buildSpec = this.buildSpec;
- this.buildSpec = new BuildSpec();
- build(buildSpec);
- }
-
- private void build(BuildSpec buildSpec) throws BuildException {
- final boolean failonerror = buildSpec.failonerror;
- Builder builder = null;
- try {
- // try using script first if not a product
- boolean built = false;
- if ((null == buildSpec.productDir) && (null != buildSpec.moduleDir)) {
- File buildScript = new File(buildSpec.moduleDir, "build.xml"); // XXXFileLiteral
- if (buildScript.canRead()) {
- built = buildByScript(buildSpec, buildScript);
- if (!built) {
- log("unable to build "
- + buildSpec
- + " using script: "
- + buildScript.getAbsolutePath());
- }
- }
- }
- if (!built) {
- builder = AntBuilder.getBuilder(
- buildSpec.buildConfig,
- getProject(),
- buildSpec.tempDir);
- if (!builder.build(buildSpec) && failonerror) {
- Location loc = getLocation();
- throw new BuildException("error building " + buildSpec, loc);
- }
- }
- } catch (BuildException e) {
- throw e;
- } catch (Throwable t) {
- Location loc = getLocation();
- throw new BuildException("error building " + buildSpec, t, loc);
- } finally {
- if (null != builder) {
- builder.cleanup();
- }
- }
- }
-
- boolean buildByScript(BuildSpec buildSpec, File buildScript)
- throws BuildException {
- return false;
- }
-}
-
\ No newline at end of file
diff --git a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/Checklics.java b/build/src/main/java./aspectj/internal/tools/ant/taskdefs/Checklics.java
deleted file mode 100644
index 904ba4656..000000000
--- a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/Checklics.java
+++ /dev/null
@@ -1,676 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * 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://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-
-package org.aspectj.internal.tools.ant.taskdefs;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.Reference;
-
-/**
- * Check that included .java files contain license and copyright strings for MPL 1.0 (default), Apache, or CPL. Use list="true" to
- * get a list of known license variants {license}-{copyrightHolder} todo reimplement with regexp and jdiff FileLine utilities
- */
-public class Checklics extends MatchingTask {
- /*
- * This does not enforce that copyrights are correct/current, only that they exist. E.g., the default behavior requires MPL but
- * permits either Xerox or PARC copyright holders and any valid year.
- */
- public static final String MPL_TAG = "mpl";
- public static final String APACHE_TAG = "apache";
- public static final String CPL_IBM_PARC_TAG = "cpl-ibm|parc";
- public static final String CPL_IBM_TAG = "cpl-ibm";
- public static final String MPL_XEROX_PARC_TAG = "mpl-parc|xerox";
- public static final String MPL_ONLY_TAG = "mpl-only";
- public static final String MPL_PARC_TAG = "mpl-parc";
- public static final String PARC_COPYRIGHT_TAG = "parc-copy";
- public static final String CPL_IBM_PARC_XEROX_TAG = "cpl-ibm|parc|xerox";
- public static final String CPL_IBM_PARC_XEROX_OTHERS_TAG = "cpl-ibm|parc|xerox|others";
- public static final String EPL_CPL_IBM_PARC_XEROX_OTHERS_TAG = "epl-cpl-ibm|parc|xerox|vmware|others";
- public static final String DEFAULT = EPL_CPL_IBM_PARC_XEROX_OTHERS_TAG;
-
- static final Map LICENSES; // unmodifiable Map
-
- static {
- final String CONTRIBUTORS = "Contributors";
- final String XEROX = "Xerox";
- final String PARC = "Palo Alto Research Center";
- final String APACHE = "The Apache Software Foundation";
- final String IBM = "IBM";
- final String VMWARE = "VMware";
- final String IBM_LONG = "International Business Machines";
- final String LIC_APL = "Apache Software Foundation (http://www.apache.org/)";
- final String LIC_MPL = "http://aspectj.org/MPL/";
- final String LIC_CPL = "Eclipse Public License";
- final String LIC_ECPL = " Public License";
- License APL = new License(APACHE_TAG, LIC_APL, APACHE);
- License MPL = new License(MPL_TAG, LIC_MPL, XEROX);
- License MPL_XEROX_PARC = new License(DEFAULT, LIC_MPL, XEROX, PARC);
- License CPL_IBM_PARC = new License(CPL_IBM_PARC_TAG, LIC_CPL, new String[] { IBM_LONG, IBM, PARC });
- License CPL_IBM_PARC_XEROX = new License(CPL_IBM_PARC_XEROX_TAG, LIC_CPL, new String[] { IBM_LONG, IBM, PARC, XEROX });
-
- License CPL_IBM_PARC_XEROX_OTHERS = new License(CPL_IBM_PARC_XEROX_OTHERS_TAG, LIC_CPL, new String[] { IBM_LONG, IBM, PARC,
- XEROX, CONTRIBUTORS });
- License EPL_CPL_IBM_PARC_XEROX_OTHERS = new License(EPL_CPL_IBM_PARC_XEROX_OTHERS_TAG, LIC_ECPL, new String[] { IBM_LONG,
- IBM, PARC, XEROX, VMWARE, CONTRIBUTORS });
- License CPL_IBM = new License(CPL_IBM_TAG, LIC_CPL, IBM, IBM_LONG);
- License MPL_ONLY = new License(MPL_ONLY_TAG, LIC_MPL);
- License MPL_PARC = new License(MPL_PARC_TAG, LIC_MPL, PARC);
- License PARC_COPYRIGHT = new License(PARC_COPYRIGHT_TAG, null, PARC);
- LICENSES = new Hashtable();
- LICENSES.put(APL.tag, APL);
- LICENSES.put(MPL.tag, MPL);
- LICENSES.put(MPL_PARC.tag, MPL_PARC);
- LICENSES.put(MPL_XEROX_PARC.tag, MPL_XEROX_PARC);
- LICENSES.put(CPL_IBM_PARC.tag, CPL_IBM_PARC);
- LICENSES.put(MPL_ONLY.tag, MPL_ONLY);
- LICENSES.put(CPL_IBM.tag, CPL_IBM);
- LICENSES.put(PARC_COPYRIGHT.tag, PARC_COPYRIGHT);
- LICENSES.put(CPL_IBM_PARC_XEROX.tag, CPL_IBM_PARC_XEROX);
- LICENSES.put(CPL_IBM_PARC_XEROX_OTHERS.tag, CPL_IBM_PARC_XEROX_OTHERS);
- LICENSES.put(EPL_CPL_IBM_PARC_XEROX_OTHERS.tag, EPL_CPL_IBM_PARC_XEROX_OTHERS);
- }
-
- /** @param args String[] { < sourcepath > {, < licenseTag > } } */
- public static void main(String[] args) {
- switch (args.length) {
- case 1:
- runDirect(args[0], null, false);
- break;
- case 2:
- runDirect(args[0], args[1], false);
- break;
- default:
- String options = "{replace-headers|get-years|list|{licenseTag}}";
- System.err.println("java {me} sourcepath " + options);
- break;
- }
- }
-
- /**
- * Run the license check directly
- *
- * @param sourcepaths String[] of paths to source directories
- * @param license the String tag for the license, if any
- * @param failonerror boolean flag to pass to Checklics
- * @throws IllegalArgumentException if sourcepaths is empty
- * @return total number of failed licenses
- */
- public static int runDirect(String sourcepath, String license, boolean failonerror) {
- if ((null == sourcepath) || (1 > sourcepath.length())) {
- throw new IllegalArgumentException("bad sourcepath: " + sourcepath);
- }
- Checklics me = new Checklics();
- Project p = new Project();
- p.setName("direct interface to Checklics");
- p.setBasedir(".");
- me.setProject(p);
- me.setFailOnError(failonerror);
- me.setSourcepath(new Path(p, sourcepath));
- if (null != license) {
- if ("replace-headers".equals(license)) {
- me.setReplaceheaders(true);
- } else if ("get-years".equals(license)) {
- me.setGetYears(true);
- } else if ("list".equals(license)) {
- me.setList(true);
- } else {
- me.setLicense(license);
- }
- }
- me.execute();
- return me.failed;
- }
-
- private Path sourcepath;
- private License license;
- private boolean list;
- private String streamTag;
- private boolean failOnError;
- private boolean getYears;
- private boolean replaceHeaders;
- private int failed;
- private int passed;
-
- private boolean printDirectories;
-
- /** @param list if true, don't run but list known license tags */
- public void setList(boolean list) {
- this.list = list;
- }
-
- public void setPrintDirectories(boolean print) {
- printDirectories = print;
- }
-
- /**
- * When failOnError is true, if any file failed, throw BuildException listing number of files that file failed to pass license
- * check
- *
- * @param fail if true, report errors by throwing BuildException
- */
- public void setFailOnError(boolean fail) {
- this.failOnError = fail;
- }
-
- /** @param tl mpl | apache | cpl */
- public void setLicense(String tl) {
- License input = LICENSES.get(tl);
- if (null == input) {
- throw new BuildException("no license known for " + tl);
- }
- license = input;
- }
-
- public void setSourcepath(Path path) {
- if (sourcepath == null) {
- sourcepath = path;
- } else {
- sourcepath.append(path);
- }
- }
-
- public Path createSourcepath() {
- return sourcepath == null ? (sourcepath = new Path(project)) : sourcepath.createPath();
- }
-
- public void setSourcepathRef(Reference id) {
- createSourcepath().setRefid(id);
- }
-
- /** @param out "out" or "err" */
- public void setOutputStream(String out) {
- this.streamTag = out;
- }
-
- public void setReplaceheaders(boolean replaceHeaders) {
- this.replaceHeaders = replaceHeaders;
- }
-
- public void setGetYears(boolean getYears) {
- this.getYears = getYears;
- }
-
- /** list known licenses or check source tree */
- @Override
- public void execute() throws BuildException {
- if (list) {
- list();
- } else if (replaceHeaders) {
- replaceHeaders();
- } else if (getYears) {
- getYears();
- } else {
- checkLicenses();
- }
- }
-
- private PrintStream getOut() {
- return ("err".equals(streamTag) ? System.err : System.out);
- }
-
- interface FileVisitor {
- void visit(File file);
- }
-
- /** visit all .java files in all directories... */
- private void visitAll(FileVisitor visitor) {
- // List filelist = new ArrayList();
- String[] dirs = sourcepath.list();
- for (int i = 0; i < dirs.length; i++) {
- File dir = project.resolveFile(dirs[i]);
- String[] files = getDirectoryScanner(dir).getIncludedFiles();
- for (int j = 0; j < files.length; j++) {
- File file = new File(dir, files[j]);
- String path = file.getPath();
- if (path.endsWith(".java")) {
- visitor.visit(file);
- }
- }
- }
- }
-
- private void replaceHeaders() {
- class YearVisitor implements FileVisitor {
- @Override
- public void visit(File file) {
- HeaderInfo info = Header.checkFile(file);
- if (!Header.replaceHeader(file, info)) {
- throw new BuildException("failed to replace header for " + file + " using " + info);
- }
- }
- }
- visitAll(new YearVisitor());
- }
-
- private void getYears() {
- final PrintStream out = getOut();
- class YearVisitor implements FileVisitor {
- @Override
- public void visit(File file) {
- HeaderInfo info = Header.checkFile(file);
- out.println(info.toString());
- }
- }
- visitAll(new YearVisitor());
- }
-
- private void checkLicenses() throws BuildException {
- if (null == license) {
- setLicense(DEFAULT);
- }
- final License license = this.license; // being paranoid...
- if (null == license) {
- throw new BuildException("no license");
- }
- final PrintStream out = getOut();
-
- class Visitor implements FileVisitor {
- int failed = 0;
- int passed = 0;
-
- @Override
- public void visit(File file) {
- if (license.checkFile(file)) {
- passed++;
- } else {
- failed++;
- String path = file.getPath();
- if (!license.foundLicense()) {
- out.println(license.tag + " LICENSE FAIL: " + path);
- }
- if (!license.foundCopyright()) {
- out.println(license.tag + " COPYRIGHT FAIL: " + path);
- }
- }
- }
- }
- Visitor visitor = new Visitor();
- visitAll(visitor);
- this.failed = visitor.failed;
- this.passed = visitor.passed;
- if (0 < visitor.failed) {
- getOut().println("Total passed: " + visitor.passed + (visitor.failed == 0 ? "" : " failed: " + visitor.failed));
- if (failOnError) {
- throw new BuildException(failed + " files failed license check");
- }
- }
- }
-
- private void list() {
- Iterator enu = LICENSES.keySet().iterator();
- StringBuffer sb = new StringBuffer();
- sb.append("known license keys:");
- boolean first = true;
- while (enu.hasNext()) {
- sb.append((first ? " " : ", ") + enu.next());
- if (first) {
- first = false;
- }
- }
- getOut().println(sb.toString());
- }
-
- /**
- * Encapsulate license and copyright specifications to check files use hokey string matching.
- */
- public static class License {
- /** acceptable years for copyright prefix to company - append " " */
- static final String[] YEARS = // remove older after license xfer?
- new String[] { "2002 ", "2003 ", "2004 ", "2005", "2006", "2007", "2008",
- "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2001 ", "2000 ",
- "1999 " };
- public final String tag;
- public final String license;
- private final String[] copyright;
- private boolean gotLicense;
- private boolean gotCopyright;
-
- License(String tag, String license) {
- this(tag, license, (String[]) null);
- }
-
- License(String tag, String license, String copyright) {
- this(tag, license, new String[] { copyright });
- }
-
- License(String tag, String license, String copyright, String altCopyright) {
- this(tag, license, new String[] { copyright, altCopyright });
- }
-
- License(String tag, String license, String[] copyright) {
- this.tag = tag;
- if ((null == tag) || (0 == tag.length())) {
- throw new IllegalArgumentException("null tag");
- }
- this.license = license;
- this.copyright = copyright;
- }
-
- public final boolean gotValidFile() {
- return foundLicense() && foundCopyright();
- }
-
- /** @return true if no license sought or if some license found */
- public final boolean foundLicense() {
- return ((null == license) || gotLicense);
- }
-
- /** @return true if no copyright sought or if some copyright found */
- public final boolean foundCopyright() {
- return ((null == copyright) || gotCopyright);
- }
-
- public boolean checkFile(final File file) {
- clear();
- // boolean result = false;
- BufferedReader input = null;
- int lineNum = 0;
- try {
- input = new BufferedReader(new FileReader(file));
- String line;
- while (!gotValidFile() && (line = input.readLine()) != null) {
- lineNum++;
- checkLine(line);
- }
- } catch (IOException e) {
- System.err.println("reading line " + lineNum + " of " + file);
- e.printStackTrace(System.err);
- } finally {
- if (null != input) {
- try {
- input.close();
- } catch (IOException e) {
- } // ignore
- }
- }
- return gotValidFile();
- }
-
- @Override
- public String toString() {
- return tag;
- }
-
- private void checkLine(String line) {
- if ((null == line) || (0 == line.length())) {
- return;
- }
- if (!gotLicense && (null != license) && (-1 != line.indexOf(license))) {
- gotLicense = true;
- }
- if (!gotCopyright && (null != copyright)) {
- int loc;
- for (int j = 0; !gotCopyright && (j < YEARS.length); j++) {
- if (-1 != (loc = line.indexOf(YEARS[j]))) {
- loc += YEARS[j].length();
- String afterLoc = line.substring(loc).trim();
- for (int i = 0; !gotCopyright && (i < copyright.length); i++) {
- if (0 == afterLoc.indexOf(copyright[i])) {
- gotCopyright = true;
- }
- }
- }
- }
- }
- }
-
- private void clear() {
- if (gotLicense) {
- gotLicense = false;
- }
- if (gotCopyright) {
- gotCopyright = false;
- }
- }
- } // class License
-}
-
-class HeaderInfo {
- /** File for which this is the info */
- public final File file;
-
- /** unmodifiable List of String years */
- public final List years;
-
- /** last line of license */
- public final int lastLine;
-
- /** last line of license */
- public final boolean hasLicense;
-
- public HeaderInfo(File file, int lastLine, List years, boolean hasLicense) {
- this.lastLine = lastLine;
- this.file = file;
- this.hasLicense = hasLicense;
- List newYears = new ArrayList();
- newYears.addAll(years);
- Collections.sort(newYears);
- this.years = Collections.unmodifiableList(newYears);
- if ((null == file) || !file.canWrite()) {
- throw new IllegalArgumentException("bad file: " + this);
- }
- if (!hasLicense) {
- if ((0 > lastLine) || (65 < lastLine)) {
- throw new IllegalArgumentException("bad last line: " + this);
- }
- } else {
- if ((null == years) || (1 > years.size())) {
- throw new IllegalArgumentException("no years: " + this);
- }
- if ((20 > lastLine) || (65 < lastLine)) {
- throw new IllegalArgumentException("bad last line: " + this);
- }
- }
- }
-
- @Override
- public String toString() {
- return file.getPath() + ":" + lastLine + " " + years;
- }
-
- public void writeHeader(PrintWriter writer) {
- if (!hasLicense) {
- writer.println(TOP);
- writer.println(PARC_ONLY);
- writeRest(writer);
- } else {
- final int size = years.size();
- if (1 > size) {
- throw new Error("no years found in " + toString());
- }
- String first = (String) years.get(0);
- String last = (String) years.get(size - 1);
- boolean lastIs2002 = "2002".equals(last);
- String xlast = last;
- if (lastIs2002) { // 2002 was PARC
- xlast = (String) (size > 1 ? years.get(size - 2) : null);
- // 1999-2002 Xerox implies 1999-2001 Xerox
- if (first.equals(xlast) && !"2001".equals(xlast)) {
- xlast = "2001";
- }
- }
- String xyears = first + "-" + xlast;
- if (first.equals(last)) {
- xyears = first;
- }
-
- writer.println(TOP);
- if (!lastIs2002) { // Xerox only
- writer.println(XEROX_PREFIX + xyears + XEROX_SUFFIX + ". ");
- } else if (size == 1) { // PARC only
- writer.println(PARC_ONLY);
- } else { // XEROX plus PARC
- writer.println(XEROX_PREFIX + xyears + XEROX_SUFFIX + ", ");
- writer.println(PARC);
- }
- writeRest(writer);
- }
- }
-
- void writeRest(PrintWriter writer) {
- writer.println(" * All rights reserved. ");
- writer.println(" * This program and the accompanying materials are made available ");
- writer.println(" * under the terms of the Eclipse Public License v1.0 ");
- writer.println(" * which accompanies this distribution and is available at ");
- writer.println(" * http://www.eclipse.org/legal/epl-v10.html ");
- writer.println(" * ");
- writer.println(" * Contributors: ");
- writer.println(" * Xerox/PARC initial implementation ");
- writer.println(" * ******************************************************************/");
- writer.println("");
- }
-
- public static final String TOP = "/* *******************************************************************";
- public static final String PARC = " * 2002 Palo Alto Research Center, Incorporated (PARC).";
- public static final String PARC_ONLY = " * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).";
- public static final String XEROX_PREFIX = " * Copyright (c) ";
- public static final String XEROX_SUFFIX = " Xerox Corporation";
- /*
- * /* ******************************************************************* Copyright (c) 1998-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 Eclipse Public License v1.0 which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Xerox/PARC initial implementation ******************************************************************
- */
-}
-
-/**
- * header search/replace using hokey string matching
- */
-class Header {
-
- /** replace the header in file */
- public static boolean replaceHeader(File file, HeaderInfo info) {
- // ArrayList years = new ArrayList();
- // int endLine = 0;
- BufferedReader input = null;
- PrintWriter output = null;
- FileWriter outWriter = null;
- int lineNum = 0;
- boolean result = false;
- final File inFile = new File(file.getPath() + ".tmp");
- try {
- File outFile = new File(file.getPath());
- if (!file.renameTo(inFile) || !inFile.canRead()) {
- throw new Error("unable to rename " + file + " to " + inFile);
- }
- outWriter = new FileWriter(outFile);
- input = new BufferedReader(new FileReader(inFile));
- output = new PrintWriter(outWriter, true);
- info.writeHeader(output);
- String line;
- while (null != (line = input.readLine())) {
- lineNum++;
- if (lineNum > info.lastLine) {
- output.println(line);
- }
- }
- } catch (IOException e) {
- System.err.println("writing line " + lineNum + " of " + file);
- e.printStackTrace(System.err);
- result = false;
- } finally {
- if (null != input) {
- try {
- input.close();
- } catch (IOException e) {
- result = false;
- }
- }
- if (null != outWriter) {
- try {
- outWriter.close();
- } catch (IOException e) {
- result = false;
- }
- }
- result = inFile.delete();
- }
- return result;
- }
-
- public static HeaderInfo checkFile(final File file) {
- ArrayList years = new ArrayList();
- int endLine = 0;
- BufferedReader input = null;
- int lineNum = 0;
- try {
- input = new BufferedReader(new FileReader(file));
- String line;
- while (null != (line = input.readLine())) {
- lineNum++;
- String ll = line.trim();
- if (ll.startsWith("package ") || ll.startsWith("import ")) {
- break; // ignore default package w/o imports
- }
- if (checkLine(line, years)) {
- endLine = lineNum;
- break;
- }
- }
- } catch (IOException e) {
- System.err.println("reading line " + lineNum + " of " + file);
- e.printStackTrace(System.err);
- } finally {
- if (null != input) {
- try {
- input.close();
- } catch (IOException e) {
- } // ignore
- }
- }
- return new HeaderInfo(file, endLine, years, endLine > 0);
- }
-
- /**
- * Add any years found (as String) to years, and return true at the first end-of-comment
- *
- * @return true if this line has end-of-comment
- */
- private static boolean checkLine(String line, ArrayList years) {
- if ((null == line) || (0 == line.length())) {
- return false;
- }
- int loc;
- int start = 0;
-
- while ((-1 != (loc = line.indexOf("199", start)) || (-1 != (loc = line.indexOf("200", start))))) {
- char c = line.charAt(loc + 3);
- if ((c <= '9') && (c >= '0')) {
- years.add(line.substring(loc, loc + 4));
- }
- start = loc + 4;
- }
-
- return (-1 != line.indexOf("*/"));
- }
-
-} // class Header
-
diff --git a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/ConditionalTask.java b/build/src/main/java./aspectj/internal/tools/ant/taskdefs/ConditionalTask.java
deleted file mode 100644
index fdff0d7c1..000000000
--- a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/ConditionalTask.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/* *******************************************************************
- * 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 Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-
-package org.aspectj.internal.tools.ant.taskdefs;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-
-public abstract class ConditionalTask extends Task {
-
- public final static String TRUE = "true";
-
- private List ifs;
- protected List ifs() {
- return ifs != null ? ifs : (ifs = new Vector());
- }
-
- public If createIf() {
- If i = new If();
- ifs().add(i);
- return i;
- }
-
- public If createIf(String name, String equals, boolean strict) {
- If i = createIf();
- i.setName(name);
- i.setEquals(equals);
- i.setStrict(strict);
- return i;
- }
-
- public If createIf(String name, String equals) {
- return createIf(name, equals, false);
- }
-
- public If createIf(String name) {
- return createIf(name, TRUE, false);
- }
-
- public If createIf(String name, boolean strict) {
- return createIf(name, TRUE, strict);
- }
-
- public void setIfs(String ifs) {
- StringTokenizer tok = new StringTokenizer(ifs, ",;: ", false);
- while (tok.hasMoreTokens()) {
- String next = tok.nextToken();
- int iequals = next.lastIndexOf("=");
- String equals;
- String name;
- boolean strict;
- If i = createIf();
- if (iequals != -1) {
- name = next.substring(0, iequals);
- equals = next.substring(iequals + 1);
- strict = true;
- } else {
- name = next.substring(0);
- equals = TRUE;
- strict = false;
- }
- i.setName(name);
- i.setEquals(equals);
- i.setStrict(strict);
- }
- }
-
- public void setIf(String ifStr) {
- setIfs(ifStr);
- }
-
- public class If {
- public If() {
- this(null, null);
- }
- public If(String name) {
- this(name, TRUE);
- }
- public If(String name, String equals) {
- setName(name);
- setEquals(equals);
- }
- private String name;
- public void setName(String name) {
- this.name = name;
- }
- public String getName() {
- return name;
- }
- private String equals;
- public void setEquals(String equals) {
- this.equals = equals;
- }
- public String getEquals() {
- return equals;
- }
- private boolean strict = false;
- public void setStrict(boolean strict) {
- this.strict = strict;
- }
- public boolean isStrict() {
- return strict;
- }
- public boolean isOk(String prop) {
- return isOk(prop, isStrict());
- }
- //XXX Need a better boolean parser
- public boolean isOk(String prop, boolean isStrict) {
- if (isStrict) {
- return prop != null && prop.equals(getEquals());
- } else {
- if (isOk(prop, true)) {
- return true;
- }
- if (prop == null || isFalse(getEquals())) {
- return true;
- }
- if ( (isTrue(getEquals()) && isTrue(prop)) ||
- (isFalse(getEquals()) && isFalse(prop)) ) {
- return true;
- }
- return false;
- }
- }
- private boolean isFalse(String prop) {
- return isOneOf(prop, falses) || isOneOf(prop, complement(trues));
- }
- private boolean isTrue(String prop) {
- return isOneOf(prop, trues) || isOneOf(prop, complement(falses));
- }
- private boolean isOneOf(String prop, String[] strings) {
- for (int i = 0; i < strings.length; i++) {
- if (strings[i].equals(prop)) {
- return true;
- }
- }
- return false;
- }
- private String[] complement(String[] strings) {
- for (int i = 0; i < strings.length; i++) {
- strings[i] = "!" + strings[i];
- }
- return strings;
- }
- }
-
- final static String[] falses = { "false", "no" };
- final static String[] trues = { "true", "yes" };
-
- protected boolean checkIfs() {
- return getFalses().size() == 0;
- }
-
- protected List getFalses() {
- Iterator iter = ifs().iterator();
- List result = new Vector();
- while (iter.hasNext()) {
- If next = (If) iter.next();
- String name = next.getName();
- String prop = project.getProperty(name);
- if (prop == null) {
- prop = project.getUserProperty(name);
- }
- if (!next.isOk(prop)) {
- result.add(name);
- }
- }
- return result;
- }
-
- public abstract void execute() throws BuildException;
-}
diff --git a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/CopyAndInlineStylesheet.java b/build/src/main/java./aspectj/internal/tools/ant/taskdefs/CopyAndInlineStylesheet.java
deleted file mode 100644
index 664616c07..000000000
--- a/build/src/main/java./aspectj/internal/tools/ant/taskdefs/CopyAndInlineStylesheet.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/* *******************************************************************
- * 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 Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-
-package org.aspectj.internal.tools.ant.taskdefs;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintStream;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.Mkdir;
-
-public class CopyAndInlineStylesheet extends Task {
-
- private File file;
- public void setFile(String file) {
- this.file = project.resolveFile(file);
- }
-
- private File todir;
- public void setTodir(String todir) {
- this.todir = project.resolveFile(todir);
- }
-
-
- public void execute() throws BuildException {
- try {
- if (todir == null) {
- throw new BuildException("must set 'todir' attribute");
- }
- if (file == null) {
- throw new BuildException("must set 'file' attribute");
- }
- log("copying html from" + file + " to " + todir.getAbsolutePath());
-
- File toFile = new File(todir, file.getName());
-
- Mkdir mkdir = (Mkdir) project.createTask("mkdir");
- mkdir.setDir(todir);
- mkdir.execute();
-
- BufferedReader in = new BufferedReader(new FileReader(file));
- PrintStream out = new PrintStream(new FileOutputStream(toFile));
-
- outer:
- while (true) {
- String line = in.readLine();
- if (line == null) break;
- if (isStyleSheet(line)) {
- doStyleSheet(line, out, file);
- while (true) {
- String line2 = in.readLine();
- if (line2 == null) break outer;
- out.println(line2);
- }
- } else {
- out.println(line);
- }
- }
-
- in.close();
- out.close();
- } catch (IOException e) {
- throw new BuildException(e.getMessage());
- }
- }
-
- private static void doStyleSheet(String line, PrintStream out, File file) throws IOException {
- int srcIndex = line.indexOf("href");
- int startQuotIndex = line.indexOf('"', srcIndex);
- int endQuotIndex = line.indexOf('"', startQuotIndex + 1);
-
- String stylesheetLocation = line.substring(startQuotIndex + 1, endQuotIndex);
-
- File styleSheetFile = new File(file.getParent(), stylesheetLocation);
-
- out.println("");
- }
-
-
- private static boolean isStyleSheet(String line) throws IOException {
- line = line.toLowerCase();
- int len = line.length();
- int i = 0;
-
- while (true) {
- if (i == len) return false;
- if (! Character.isWhitespace(line.charAt(i))) break;
- }
-
- return line.startsWith(" This task can take the following arguments:
- *
- *
- * - srcdir
- * - destdir
- * - include
- * - exclude
- *
- *
- * Of these arguments, only sourcedir is required.
- *
- * When this task executes, it will scan the srcdir based on the
- * include and exclude properties.
- */
-
-public class StripNonBodyHtml extends MatchingTask {
-
- private File srcDir;
- private File destDir = null;
-
- public void setSrcdir(File srcDir) {
- this.srcDir = srcDir;
- }
-
- public void setDestdir(File destDir) {
- this.destDir = destDir;
- }
-
- public void execute() throws BuildException {
- if (srcDir == null) {
- throw new BuildException("srcdir attribute must be set!");
- }
- if (!srcDir.exists()) {
- throw new BuildException("srcdir does not exist!");
- }
- if (!srcDir.isDirectory()) {
- throw new BuildException("srcdir is not a directory!");
- }
- if (destDir != null) {
- if (!destDir.exists()) {
- throw new BuildException("destdir does not exist!");
- }
- if (!destDir.isDirectory()) {
- throw new BuildException("destdir is not a directory!");
- }
- }
-
- DirectoryScanner ds = super.getDirectoryScanner(srcDir);
- String[] files = ds.getIncludedFiles();
-
- log("stripping " + files.length + " files");
- int stripped = 0;
- for (int i = 0, len = files.length; i < len; i++) {
- if (processFile(files[i])) {
- stripped++;
- } else {
- log(files[i] + " not stripped");
- }
- }
- log(stripped + " files successfully stripped");
- }
-
- boolean processFile(String filename) throws BuildException {
- File srcFile = new File(srcDir, filename);
- File destFile;
- if (destDir == null) {
- destFile = srcFile;
- } else {
- destFile = new File(destDir, filename);
- destFile.getParentFile().mkdirs();
- }
- try {
- return strip(srcFile, destFile);
- } catch (IOException e) {
- throw new BuildException(e);
- }
- }
-
- private boolean strip(File f, File g) throws IOException {
- BufferedInputStream in =
- new BufferedInputStream(new FileInputStream(f));
- String s = readToString(in);
- in.close();
- return writeBodyTo(s, g);
- }
-
- private ByteArrayOutputStream temp = new ByteArrayOutputStream();
- private byte[] buf = new byte[2048];
-
- private String readToString(InputStream in) throws IOException {
- ByteArrayOutputStream temp = this.temp;
- byte[] buf = this.buf;
- String s = "";
- try {
- while (true) {
- int i = in.read(buf, 0, 2048);
- if (i == -1) break;
- temp.write(buf, 0, i);
-
- }
- s = temp.toString();
- } finally {
- temp.reset();
- }
- return s;
- }
-
- private boolean writeBodyTo(String s, File f) throws IOException {
- int start;//, end;
- try {
- start = findStart(s);
- findEnd(s, start);
- } catch (ParseException e) {
- return false; // if we get confused, just don't write the file.
- }
- s = processBody(s,f);
- BufferedOutputStream out =
- new BufferedOutputStream(new FileOutputStream(f));
-
- out.write(s.getBytes());
- out.close();
- return true;
- }
-
- /**
- * Process body. This implemenation strips text
- * between <!-- start strip -->
- * and <!-- end strip -->
- * inclusive.
- */
- private String processBody(String body, File file) {
- if (null == body) return body;
- final String START = "";
- final String END = "";
- return stripTags(body, file.toString(), START, END);
- }
-
- /**
- * Strip 0..n substrings in input: "s/${START}.*${END}//g"
- * @param input the String to strip
- * @param source the name of the source for logging purposes
- * @param start the starting tag (case sensitive)
- * @param end the ending tag (case sensitive)
- */
- String stripTags(String input, final String SOURCE,
- final String START, final String END) {
- if (null == input) return input;
- StringBuffer buffer = new StringBuffer(input.length());
- String result = input;
- int curLoc = 0;
- while (true) {
- int startLoc = input.indexOf(START, curLoc);
- if (-1 == startLoc) {
- buffer.append(input.substring(curLoc));
- result = buffer.toString();
- break; // <------------ valid exit
- } else {
- int endLoc = input.indexOf(END, startLoc);
- if (-1 == endLoc) {
- log(SOURCE + " stripTags - no end tag - startLoc=" + startLoc);
- break; // <------------ invalid exit
- } else if (endLoc < startLoc) {
- log(SOURCE + " stripTags - impossible: startLoc="
- + startLoc + " > endLoc=" + endLoc);
- break; // <------------ invalid exit
- } else {
- buffer.append(input.substring(curLoc, startLoc));
- curLoc = endLoc + END.length();
- }
- }
- }
- return result;
- }
-
- private int findStart(String s) throws ParseException {
- int len = s.length();
- int start = 0;
- while (true) {
- start = s.indexOf("= len) throw barf();
- char ch = s.charAt(start);
- if (ch == '>') return start + 1;
- if (Character.isWhitespace(ch)) {
- start = s.indexOf('>', start);
- if (start == -1) return -1;
- return start + 1;
- }
- }
- }
-
- private int findEnd(String s, int start) throws ParseException {
- int end;
- end = s.indexOf("", start);
- if (end == -1) {
- end = s.indexOf("