I do worry that the example Java1.5 code looks just like STL C++. We also need to compare factorypath with classpath behaviour. But we can demo that you can add new factories git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277860 13f79535-47bb-0310-9956-ffa450edef68master
@@ -30,8 +30,11 @@ | |||
<property name="bootstrap.jar" value="ant-bootstrap.jar"/> | |||
<property name="ant.package" value="org/apache/tools/ant"/> | |||
<property name="optional.package" value="${ant.package}/taskdefs/optional"/> | |||
<property name="optional.type.package" value="${ant.package}/types/optional"/> | |||
<property name="taskdefs.package" value="${ant.package}/taskdefs"/> | |||
<property name="optional.package" value="${taskdefs.package}/optional"/> | |||
<property name="optional.condition.package" value="${optional.package}/condition"/> | |||
<property name="type.package" value="${ant.package}/types"/> | |||
<property name="optional.type.package" value="${type.package}/optional"/> | |||
<property name="apache.resolver.type.package" value="${ant.package}/types/resolver"/> | |||
<property name="util.package" value="${ant.package}/util"/> | |||
<property name="regexp.package" value="${util.package}/regexp"/> | |||
@@ -154,7 +157,8 @@ | |||
<selector id="needs.jdk1.5+"> | |||
<or> | |||
<filename name="${ant.package}/taskdefs/optional/condition/IsPingable*"/> | |||
<filename name="${optional.condition.package}/IsPingable*"/> | |||
<filename name="${taskdefs.package}/AptTest*"/> | |||
</or> | |||
</selector> | |||
@@ -162,7 +166,7 @@ | |||
but not all of them --> | |||
<selector id="not.in.kaffe"> | |||
<or> | |||
<filename name="${ant.package}/taskdefs/optional/condition/IsPingable*"/> | |||
<filename name="${optional.condition.package}/IsPingable*"/> | |||
</or> | |||
</selector> | |||
@@ -185,7 +189,7 @@ | |||
<filename name="${optional.package}/sitraka/**"/> | |||
<filename name="${optional.package}/metamata/MMetrics*"/> | |||
<filename name="${optional.package}/XsltTest*"/> | |||
<filename name="${ant.package}/types/XMLCatalogBuildFileTest*"/> | |||
<filename name="${type.package}/XMLCatalogBuildFileTest*"/> | |||
</or> | |||
</selector> | |||
@@ -1507,7 +1511,7 @@ | |||
<include name="**/*Test*"/> | |||
<!-- abstract classes, not testcases --> | |||
<exclude name="${ant.package}/taskdefs/TaskdefsTest.java"/> | |||
<exclude name="${taskdefs.package}/TaskdefsTest.java"/> | |||
<exclude name="${ant.package}/BuildFileTest.java"/> | |||
<exclude name="${regexp.package}/RegexpMatcherTest.java"/> | |||
<exclude name="${regexp.package}/RegexpTest.java"/> | |||
@@ -1517,10 +1521,10 @@ | |||
<!-- helper classes, not testcases --> | |||
<exclude name="org/example/**"/> | |||
<exclude name="${ant.package}/taskdefs/TaskdefTest*Task.java"/> | |||
<exclude name="${taskdefs.package}/TaskdefTest*Task.java"/> | |||
<!-- interactive tests --> | |||
<exclude name="${ant.package}/taskdefs/TestProcess.java"/> | |||
<exclude name="${taskdefs.package}/TestProcess.java"/> | |||
<exclude name="${optional.package}/splash/SplashScreenTest.java"/> | |||
<!-- only run these tests if their required libraries are | |||
@@ -1580,7 +1584,7 @@ | |||
unless="trax.impl.present"/> | |||
<exclude name="${optional.package}/junit/JUnitReportTest.java" | |||
unless="run.junitreport"/> | |||
<exclude name="${ant.package}/taskdefs/StyleTest.java" | |||
<exclude name="${taskdefs.package}/StyleTest.java" | |||
unless="trax.impl.present"/> | |||
<!-- needs BSF to work --> | |||
@@ -1610,9 +1614,9 @@ | |||
IllegalAccessExceptions otherwise. --> | |||
<exclude name="${ant.package}/DirectoryScannerTest.java" | |||
unless="tests.and.ant.share.classloader"/> | |||
<exclude name="${ant.package}/taskdefs/SQLExecTest.java" | |||
<exclude name="${taskdefs.package}/SQLExecTest.java" | |||
unless="tests.and.ant.share.classloader"/> | |||
<exclude name="${ant.package}/taskdefs/cvslib/ChangeLogWriterTest.java" | |||
<exclude name="${taskdefs.package}/cvslib/ChangeLogWriterTest.java" | |||
unless="tests.and.ant.share.classloader"/> | |||
<exclude name="${optional.package}/sos/SOSTest.java" | |||
unless="tests.and.ant.share.classloader"/> | |||
@@ -1622,15 +1626,15 @@ | |||
unless="tests.and.ant.share.classloader"/> | |||
<exclude name="${optional.package}/metamata/MAuditParserTest.java" | |||
unless="tests.and.ant.share.classloader"/> | |||
<exclude name="${ant.package}/taskdefs/ProcessDestroyerTest.java" | |||
<exclude name="${taskdefs.package}/ProcessDestroyerTest.java" | |||
unless="tests.and.ant.share.classloader"/> | |||
<exclude name="${ant.package}/taskdefs/ProtectedJarMethodsTest.java" | |||
<exclude name="${taskdefs.package}/ProtectedJarMethodsTest.java" | |||
unless="tests.and.ant.share.classloader"/> | |||
<!-- can only run if cvs is installed on your machine | |||
enable by setting the property have.cvs | |||
--> | |||
<exclude name="${ant.package}/taskdefs/AbstractCvsTaskTest.java" | |||
<exclude name="${taskdefs.package}/AbstractCvsTaskTest.java" | |||
unless="have.cvs"/> | |||
<!-- needs a local ftp server and the entry of a user/password combination --> | |||
@@ -0,0 +1,107 @@ | |||
<?xml version="1.0"?> | |||
<project basedir="."> | |||
<!-- apt tests --> | |||
<property name="build.dir" location="aptbuild/classes" /> | |||
<property name="classes.dir" location="${build.dir}/classes" /> | |||
<property name="classes2.dir" location="${build.dir}/classes2" /> | |||
<property name="preprocess.dir" location="${build.dir}/source" /> | |||
<property name="src" location="apt" /> | |||
<property name="AptExample.class" location="${classes.dir}/AptExample.class" /> | |||
<macrodef name="assertCompiled"> | |||
<attribute name="file" /> | |||
<sequential > | |||
<fail message="not found: @{file}"> | |||
<condition> | |||
<not> | |||
<available file="@{file}" /> | |||
</not> | |||
</condition> | |||
</fail> | |||
</sequential> | |||
</macrodef> | |||
<presetdef name="assertAptExampleCompiled"> | |||
<assertCompiled file="${AptExample.class}"/> | |||
</presetdef> | |||
<target name="clean"> | |||
<delete dir="${build.dir}"/> | |||
</target> | |||
<target name="init"> | |||
<mkdir dir="${classes.dir}"/> | |||
<mkdir dir="${classes2.dir}"/> | |||
<mkdir dir="${preprocess.dir}"/> | |||
</target> | |||
<target name="testApt" depends="init"> | |||
<apt srcdir="${src}" | |||
destdir="${classes.dir}" | |||
debug="on" | |||
compile="true" | |||
preprocessdir="${preprocess.dir}"> | |||
</apt> | |||
<assertAptExampleCompiled /> | |||
</target> | |||
<target name="testAptFork" depends="init"> | |||
<apt srcdir="${src}" | |||
destdir="${classes.dir}" | |||
debug="on" | |||
compile="true" | |||
fork="true" | |||
preprocessdir="${preprocess.dir}"> | |||
</apt> | |||
<assertAptExampleCompiled /> | |||
</target> | |||
<target name="testListAnnotationTypes" depends="init"> | |||
<apt srcdir="${src}" | |||
destdir="${classes.dir}" | |||
debug="on" | |||
compile="true" | |||
preprocessdir="${preprocess.dir}"> | |||
<compilerarg value="-XListAnnotationTypes" /> | |||
<compilerarg value="-Xlint:deprecation" /> | |||
</apt> | |||
<assertAptExampleCompiled /> | |||
</target> | |||
<!-- use the factory we compiled. To avoid trouble | |||
we deliver into a version in a new classpath, otherwise | |||
the dependency logic will not run Apt--> | |||
<target name="testAptNewFactory" depends="testApt"> | |||
<apt srcdir="${src}" | |||
destdir="${classes2.dir}" | |||
debug="on" | |||
compile="true" | |||
factory="DistributedAnnotationFactory" | |||
preprocessdir="${preprocess.dir}"> | |||
<factorypath path="${classes.dir}" /> | |||
<option name="build.dir" value="${build.dir}" /> | |||
</apt> | |||
<assertAptExampleCompiled /> | |||
</target> | |||
<target name="testAptNewFactoryFork" depends="testApt"> | |||
<apt srcdir="${src}" | |||
destdir="${classes2.dir}" | |||
debug="on" | |||
compile="true" | |||
factory="DistributedAnnotationFactory" | |||
preprocessdir="${preprocess.dir}"> | |||
<factorypath path="${classes.dir}" /> | |||
<option name="build.dir" value="${build.dir}" /> | |||
</apt> | |||
<assertAptExampleCompiled /> | |||
</target> | |||
</project> |
@@ -0,0 +1,24 @@ | |||
/* | |||
* Copyright 2005 The Apache Software Foundation | |||
* | |||
* 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. | |||
* | |||
*/ | |||
/** | |||
*/ | |||
@Distributed( | |||
protocol="CORBA", | |||
distribution=Distributed.DistributionTypes.FEDERATED | |||
) | |||
public class AptExample { | |||
} |
@@ -0,0 +1,38 @@ | |||
/* | |||
* Copyright 2005 The Apache Software Foundation | |||
* | |||
* 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. | |||
* | |||
*/ | |||
import java.lang.annotation.Annotation; | |||
import java.lang.annotation.Target; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.Documented; | |||
import java.lang.annotation.ElementType; | |||
import java.lang.annotation.RetentionPolicy; | |||
/** | |||
*/ | |||
@Documented | |||
@Retention(value = RetentionPolicy.RUNTIME) | |||
@Target(value = ElementType.TYPE) | |||
public @interface Distributed { | |||
public DistributionTypes distribution() default DistributionTypes.LOCAL; | |||
public String protocol() default "RMI"; | |||
public enum DistributionTypes { SINGLETON, LOCAL, FAULT_TOLERANT, FEDERATED, MOBILE}; | |||
} |
@@ -0,0 +1,49 @@ | |||
/* | |||
* Copyright 2005 The Apache Software Foundation | |||
* | |||
* 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. | |||
* | |||
*/ | |||
import com.sun.mirror.apt.AnnotationProcessorFactory; | |||
import com.sun.mirror.apt.AnnotationProcessor; | |||
import com.sun.mirror.apt.AnnotationProcessorEnvironment; | |||
import java.util.Collection; | |||
import java.util.Set; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
/** | |||
* This was the first piece of Java1.5 code in the source tree. | |||
* @since 20050-03-09T21:29:25Z | |||
*/ | |||
public class DistributedAnnotationFactory implements AnnotationProcessorFactory { | |||
private static final Collection<String> supportedAnnotations | |||
= Collections.unmodifiableCollection(Arrays.asList("*")); | |||
public Collection<String> supportedOptions() { | |||
return Collections.emptySet(); | |||
} | |||
public Collection<String> supportedAnnotationTypes() { | |||
return supportedAnnotations; | |||
} | |||
public AnnotationProcessor getProcessorFor( | |||
Set<com.sun.mirror.declaration.AnnotationTypeDeclaration> annotationTypeDeclarations, | |||
AnnotationProcessorEnvironment env) { | |||
return new DistributedAnnotationProcessor(env); | |||
} | |||
} |
@@ -0,0 +1,64 @@ | |||
/* | |||
* Copyright 2005 The Apache Software Foundation | |||
* | |||
* 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. | |||
* | |||
*/ | |||
//found in tools.jar, not the JRE runtime. | |||
import com.sun.mirror.apt.AnnotationProcessor; | |||
import com.sun.mirror.apt.AnnotationProcessorEnvironment; | |||
import com.sun.mirror.declaration.TypeDeclaration; | |||
import com.sun.mirror.declaration.ClassDeclaration; | |||
import com.sun.mirror.util.SimpleDeclarationVisitor; | |||
import static com.sun.mirror.util.DeclarationVisitors.*; | |||
import java.util.Map; | |||
/** | |||
* Annotation processor outputs stuff | |||
*/ | |||
public class DistributedAnnotationProcessor implements AnnotationProcessor { | |||
public AnnotationProcessorEnvironment env; | |||
public DistributedAnnotationProcessor(AnnotationProcessorEnvironment env) { | |||
this.env = env; | |||
} | |||
public void echo(String text) { | |||
env.getMessager().printNotice(text); | |||
} | |||
public void process() { | |||
echo("DistributedAnnotationProcessor-is-go"); | |||
Map<String, String> options=env.getOptions(); | |||
for(String key:options.keySet()) { | |||
echo("Option ["+key+"] = "+options.get(key)); | |||
} | |||
//work time | |||
for (TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations()) { | |||
typeDecl.accept(getDeclarationScanner(new ClassVisitor(), | |||
NO_OP)); | |||
} | |||
} | |||
private class ClassVisitor extends SimpleDeclarationVisitor { | |||
public void visitClassDeclaration(ClassDeclaration d) { | |||
echo("visiting "+ d.getQualifiedName()); | |||
} | |||
} | |||
} |
@@ -81,6 +81,17 @@ public abstract class BuildFileTest extends TestCase { | |||
realLog.indexOf(substring) >= 0); | |||
} | |||
/** | |||
* Assert that the given substring is in the output messages | |||
* @since Ant1.7 | |||
*/ | |||
protected void assertOutputContaining(String substring) { | |||
String realOutput = getOutput(); | |||
assertTrue("expecting output to contain \"" + substring + "\" output was \"" | |||
+ realOutput + "\"", | |||
realOutput.indexOf(substring) >= 0); | |||
} | |||
/** | |||
* Assert that the given message has been logged with a priority | |||
* <= INFO when running the given target. | |||
@@ -0,0 +1,71 @@ | |||
/* | |||
* Copyright 2005 The Apache Software Foundation | |||
* | |||
* 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.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
/** | |||
*/ | |||
public class AptTest extends BuildFileTest { | |||
public AptTest(String name) { | |||
super(name); | |||
} | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/apt.xml"); | |||
} | |||
/** | |||
* Tears down the fixture, for example, close a network connection. This | |||
* method is called after a test is executed. | |||
*/ | |||
protected void tearDown() throws Exception { | |||
executeTarget("clean"); | |||
} | |||
public void testApt() { | |||
executeTarget("testApt"); | |||
} | |||
public void testAptFork() { | |||
executeTarget("testAptFork"); | |||
} | |||
public void testListAnnotationTypes() { | |||
executeTarget("testListAnnotationTypes"); | |||
assertLogContaining("Set of annotations found:"); | |||
assertLogContaining("Distributed"); | |||
} | |||
public void testAptNewFactory() { | |||
executeTarget("testAptNewFactory"); | |||
assertProcessed(); | |||
} | |||
public void testAptNewFactoryFork() { | |||
executeTarget("testAptNewFactoryFork"); | |||
assertProcessed(); | |||
} | |||
private void assertProcessed() { | |||
assertLogContaining("DistributedAnnotationProcessor-is-go"); | |||
assertLogContaining("[-Abuild.dir="); | |||
assertLogContaining("visiting DistributedAnnotationFactory"); | |||
} | |||
} | |||