All Downloads are FREE. Search and download functionalities are using the official Maven repository.

protoj.util.AspectJCompileTask Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2009 Ashley Williams
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package protoj.util;

import java.io.File;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.DirSet;
import org.apache.tools.ant.types.Path;
import org.aspectj.tools.ant.taskdefs.AjcTask;

/**
 * Wrapper for the compileTask ant task.
 * 
 * @author Ashley Williams
 * 
 */
public final class AspectJCompileTask {
	private AntTarget parent;
	private boolean success;
	private AjcTask compileTask;
	private DirSet dirSet;

	public AspectJCompileTask(File sourceRoot, File destDir,
			ArgRunnable classpathConfig) {
		parent = new AntTarget("protoj-compile");
		compileTask = new AjcTask();
		parent.addTask(compileTask);
		compileTask.setTaskName("ajc");

		compileTask.setFork(true);
		compileTask.setDestdir(destDir);
		Path classpath = new Path(parent.getProject());
		classpathConfig.run(classpath);
		compileTask.setClasspath(classpath);

		Path srcPath = compileTask.createSrcdir();
		dirSet = new DirSet();
		dirSet.setDir(sourceRoot);
		srcPath.addDirset(dirSet);
	}

	/**
	 * The underlying ant task used to perform the compilation.
	 * 
	 * @return
	 */
	public AjcTask getCompileTask() {
		return compileTask;
	}

	/**
	 * The underlying ant pojo used to specify include and exlude patterns.
	 * 
	 * @return
	 */
	public DirSet getDirSet() {
		return dirSet;
	}

	public void initLogging() {
		parent.initLogging(Project.MSG_INFO);
	}

	/**
	 * Initializes cross compilation so that a version of javac can compile as
	 * if it were a different version. The parameters can be null, but it is
	 * advisable to assign the all a value. Check the documentation for the
	 * javac tool for more information.
	 * 
	 * @param target
	 * @param extdirs
	 * @param bootclasspath
	 */
	public void initCrossCompile(String target, String extdirs,
			String bootclasspath) {
		if (target != null) {
			compileTask.setTarget(target);
		}

		if (extdirs != null) {
			Path extdirsPath = new Path(compileTask.getProject());
			extdirsPath.setPath(extdirs);
			compileTask.setExtdirs(extdirsPath);
		}

		if (bootclasspath != null) {
			Path bootclasspathPath = new Path(compileTask.getProject());
			bootclasspathPath.setPath(bootclasspath);
			compileTask.setBootclasspath(bootclasspathPath);
		}
	}

	public void execute() {
		try {
			parent.execute();
			success = true;
		} catch (BuildException e) {
			success = false;
		}
	}

	public boolean isSuccess() {
		return success;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy