Author: struberg Date: Fri Dec 28 13:14:30 2012 New Revision: 1426498 URL: http://svn.apache.org/viewvc?rev=1426498&view=rev Log: move ant task to WeaveProcessor
Added: commons/sandbox/privilizer/trunk/ant/lib/src/main/java/org/apache/commons/weaver/ant/ commons/sandbox/privilizer/trunk/ant/lib/src/main/java/org/apache/commons/weaver/ant/WeaveTask.java (with props) Removed: commons/sandbox/privilizer/trunk/ant/lib/src/main/java/org/apache/commons/weaver/privilizer/ Modified: commons/sandbox/privilizer/trunk/ant/lib/pom.xml commons/sandbox/privilizer/trunk/ant/lib/src/main/resources/org/apache/commons/privilizer/ant/antlib.xml Modified: commons/sandbox/privilizer/trunk/ant/lib/pom.xml URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/ant/lib/pom.xml?rev=1426498&r1=1426497&r2=1426498&view=diff ============================================================================== --- commons/sandbox/privilizer/trunk/ant/lib/pom.xml (original) +++ commons/sandbox/privilizer/trunk/ant/lib/pom.xml Fri Dec 28 13:14:30 2012 @@ -41,16 +41,16 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.1</version> + </dependency> + <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</artifactId> <version>1.8.4</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.2</version><!--$NO-MVN-MAN-VER$--> - </dependency> </dependencies> <build> <plugins> Added: commons/sandbox/privilizer/trunk/ant/lib/src/main/java/org/apache/commons/weaver/ant/WeaveTask.java URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/ant/lib/src/main/java/org/apache/commons/weaver/ant/WeaveTask.java?rev=1426498&view=auto ============================================================================== --- commons/sandbox/privilizer/trunk/ant/lib/src/main/java/org/apache/commons/weaver/ant/WeaveTask.java (added) +++ commons/sandbox/privilizer/trunk/ant/lib/src/main/java/org/apache/commons/weaver/ant/WeaveTask.java Fri Dec 28 13:14:30 2012 @@ -0,0 +1,106 @@ +/* + * Copyright the original author or authors. + * + * 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 org.apache.commons.weaver.ant; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.weaver.WeaveProcessor; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; + +/** + * Privileged method weaving Ant task. + */ +public class WeaveTask extends Task { + + private File target; + private Path classpath; + private String classpathref; + private Properties weaverConfig; + + + @Override + public void execute() throws BuildException { + try { + WeaveProcessor wp = WeaveProcessor.getInstance(); + wp.configure(getClassPathEntries(), target, weaverConfig); + wp.weave(); + } catch (Exception e) { + throw new BuildException(e); + } + } + + protected File getTarget() { + return target; + } + + public void setTarget(File target) { + this.target = target; + } + + protected String getClasspathref() { + return classpathref; + } + + public void setClasspathRef(String classpathref) { + this.classpathref = classpathref; + } + + protected List<String> getClassPathEntries() { + final Path p = new Path(getProject()); + final Path cp = getClasspath(); + if (cp != null) { + p.add(cp); + } + p.add(Path.systemClasspath); + + return Arrays.asList(p.list()); + } + + protected Path getClasspath() { + if (classpath == null) { + if (getClasspathref() != null) { + Path ref = new Path(getProject()); + ref.setRefid(new Reference(getProject(), getClasspathref())); + return ref; + } + } else if (StringUtils.isNotBlank(getClasspathref())) { + throw new BuildException("Only one of classpathref|classpath is permitted."); + } + return classpath; + } + + public void setClasspath(Path classpath) { + if (this.classpath != null) { + throw new BuildException("classpath already set"); + } + this.classpath = classpath; + } + + public Properties getWeaverConfig() { + return weaverConfig; + } + + public void setWeaverConfig(Properties weaverConfig) { + this.weaverConfig = weaverConfig; + } +} Propchange: commons/sandbox/privilizer/trunk/ant/lib/src/main/java/org/apache/commons/weaver/ant/WeaveTask.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/sandbox/privilizer/trunk/ant/lib/src/main/resources/org/apache/commons/privilizer/ant/antlib.xml URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/ant/lib/src/main/resources/org/apache/commons/privilizer/ant/antlib.xml?rev=1426498&r1=1426497&r2=1426498&view=diff ============================================================================== --- commons/sandbox/privilizer/trunk/ant/lib/src/main/resources/org/apache/commons/privilizer/ant/antlib.xml (original) +++ commons/sandbox/privilizer/trunk/ant/lib/src/main/resources/org/apache/commons/privilizer/ant/antlib.xml Fri Dec 28 13:14:30 2012 @@ -17,6 +17,5 @@ --> <antlib> - <taskdef name="prepare" classname="org.apache.commons.weaver.privilizer.ant.PrepareTask" /> - <taskdef name="weave" classname="org.apache.commons.weaver.privilizer.ant.WeaveTask" /> + <taskdef name="weave" classname="org.apache.commons.weaver.ant.WeaveTask" /> </antlib>