You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mk...@apache.org on 2010/03/09 17:17:00 UTC

svn commit: r920955 - in /maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation: ./ src/ src/main/ src/main/java/ src/main/java/com/ src/main/java/com/mycompany/ src/main/java/com/mycompany/jdk16annotation/ src/main/resources/ src/main/reso...

Author: mkleint
Date: Tue Mar  9 16:16:59 2010
New Revision: 920955

URL: http://svn.apache.org/viewvc?rev=920955&view=rev
Log:
add integration test for jdk 1.6 annotation parameters.

Added:
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/   (with props)
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/invoker.properties
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/pom.xml
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/App.java
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProvider.java
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProviderProcessor.java
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/resources/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/resources/META-INF/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/resources/META-INF/services/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/com/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/com/mycompany/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/com/mycompany/jdk16annotation/
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/com/mycompany/jdk16annotation/AppTest.java
    maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/verify.bsh

Propchange: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Mar  9 16:16:59 2010
@@ -0,0 +1 @@
+target

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/invoker.properties?rev=920955&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/invoker.properties (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/invoker.properties Tue Mar  9 16:16:59 2010
@@ -0,0 +1,3 @@
+# build project if Jdk is 1.6+, only then annotations get processed.
+invoker.java.version = 1.6+
+

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/pom.xml?rev=920955&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/pom.xml (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/pom.xml Tue Mar  9 16:16:59 2010
@@ -0,0 +1,41 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.mycompany</groupId>
+  <artifactId>jdk16-annotation</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0</version>
+  <name>jdk16-annotation</name>
+  <url>http://maven.apache.org</url>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.2-SNAPSHOT</version>
+                <executions>
+                    <execution>
+                        <id>default-compile</id>
+                        <configuration>
+                            <proc>none</proc>
+                        </configuration>
+                    </execution>
+                </executions>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
+

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/App.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/App.java?rev=920955&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/App.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/App.java Tue Mar  9 16:16:59 2010
@@ -0,0 +1,13 @@
+package com.mycompany.jdk16annotation;
+
+/**
+ * Hello world!
+ *
+ */
+public class App 
+{
+    public static void main( String[] args )
+    {
+        System.out.println( "Hello World!" );
+    }
+}

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProvider.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProvider.java?rev=920955&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProvider.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProvider.java Tue Mar  9 16:16:59 2010
@@ -0,0 +1,16 @@
+package com.mycompany.jdk16annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+
+@Retention(RetentionPolicy.SOURCE)
+@Target(ElementType.TYPE)
+public @interface ServiceProvider {
+    Class<?> service();
+    int position() default Integer.MAX_VALUE;
+    String path() default "";
+}

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProviderProcessor.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProviderProcessor.java?rev=920955&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProviderProcessor.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/java/com/mycompany/jdk16annotation/ServiceProviderProcessor.java Tue Mar  9 16:16:59 2010
@@ -0,0 +1,71 @@
+package com.mycompany.jdk16annotation;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+
+import javax.tools.Diagnostic.Kind;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+public class ServiceProviderProcessor extends AbstractProcessor {
+
+    public @Override Set<String> getSupportedAnnotationTypes() {
+        return new HashSet<String>(Arrays.asList(
+            ServiceProvider.class.getCanonicalName()
+        ));
+    }
+
+    /** public for ServiceLoader */
+    public ServiceProviderProcessor() {}
+
+    @Override
+    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+        if (roundEnv.errorRaised()) {
+            return false;
+        }
+        if (roundEnv.processingOver()) {
+            writeServices();
+            return true;
+        } else {
+            return true;
+        }
+
+    }
+
+    private void writeServices() {
+        try {
+            FileObject out = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/one",new Element[0]);
+            OutputStream os = out.openOutputStream();
+            OutputStream os2 = processingEnv.getFiler().createSourceFile("org.Milos", new Element[0]).openOutputStream();
+            OutputStreamWriter osr = new OutputStreamWriter(os2);
+            try {
+                PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
+                w.write("test");
+                w.flush();
+                String clazz = "package org;\n class Milos {}";
+                osr.write(clazz.toCharArray());
+                osr.flush();
+            } finally {
+                osr.close();
+                os.close();
+            }
+
+
+        } catch (IOException x) {
+            processingEnv.getMessager().printMessage(Kind.ERROR, "Failed to write to one: " + x.toString());
+        }
+    }
+
+}

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor?rev=920955&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor Tue Mar  9 16:16:59 2010
@@ -0,0 +1 @@
+com.mycompany.jdk16annotation.ServiceProviderProcessor

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/com/mycompany/jdk16annotation/AppTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/com/mycompany/jdk16annotation/AppTest.java?rev=920955&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/com/mycompany/jdk16annotation/AppTest.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/src/test/java/com/mycompany/jdk16annotation/AppTest.java Tue Mar  9 16:16:59 2010
@@ -0,0 +1,39 @@
+package com.mycompany.jdk16annotation;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+@ServiceProvider(service=App.class, path="xxx", position=1)
+public class AppTest 
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public AppTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( AppTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        assertTrue( true );
+    }
+}

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/verify.bsh?rev=920955&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/verify.bsh (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/jdk16-annotation/verify.bsh Tue Mar  9 16:16:59 2010
@@ -0,0 +1,27 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+try
+{
+    File res = new File( basedir, "target/test-classes/META-INF/one" );
+    if ( !res.isFile() )
+    {
+        System.out.println( "generated resource not existent: " + res );
+        return false;
+    }
+    File java = new File( basedir, "target/generated-sources/test-annotations/org/Milos.java" );
+    if ( !java.isFile() )
+    {
+        System.out.println( "generated java file not existent: " + java );
+        return false;
+    }
+
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;