pax_global_header00006660000000000000000000000064126533411630014516gustar00rootroot0000000000000052 comment=7a5ebfe3b7f27157f0a0c468da34aaae23d4a0de metainf-services-metainf-services-1.7/000077500000000000000000000000001265334116300200735ustar00rootroot00000000000000metainf-services-metainf-services-1.7/.gitignore000066400000000000000000000000101265334116300220520ustar00rootroot00000000000000/target/metainf-services-metainf-services-1.7/pom.xml000066400000000000000000000050251265334116300214120ustar00rootroot00000000000000 4.0.0 org.kohsuke pom 14 org.kohsuke.metainf-services metainf-services 1.7 META-INF/services generator Annotation-driven META-INF/services auto-generation http://metainf-services.kohsuke.org/ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ metainf-services-1.7 github-pages gitsite:git@github.com/kohsuke/${project.artifactId}.git Kohsuke Kawaguchi kohsuke kk@kohsuke.org maven-compiler-plugin 3.1 1.6 1.6 -proc:none org.codehaus.mojo animal-sniffer-maven-plugin 1.10 package check org.codehaus.mojo.signature java16 1.0 MIT license http://www.opensource.org/licenses/mit-license.php repo metainf-services-metainf-services-1.7/src/000077500000000000000000000000001265334116300206625ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/000077500000000000000000000000001265334116300216065ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/java/000077500000000000000000000000001265334116300225275ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/java/org/000077500000000000000000000000001265334116300233165ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/java/org/kohsuke/000077500000000000000000000000001265334116300247675ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/java/org/kohsuke/MetaInfServices.java000066400000000000000000000036201265334116300306620ustar00rootroot00000000000000/* * The MIT License * * Copyright (c) 2009-, Kohsuke Kawaguchi * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.kohsuke; import java.lang.annotation.Documented; import static java.lang.annotation.ElementType.TYPE; import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.SOURCE; import java.lang.annotation.Target; /** * Indicates that this class name should be listed into the META-INF/services/CONTRACTNAME. * *

* If the class for which this annotation is placaed only have one base class or one interface, * then the CONTRACTNAME is the fully qualified name of that type. * *

* Otherwise, the {@link #value()} element is required to specify the contract type name. * * @author Kohsuke Kawaguchi */ @Retention(SOURCE) @Documented @Target(TYPE) public @interface MetaInfServices { Class[] value() default void.class; } metainf-services-metainf-services-1.7/src/main/java/org/kohsuke/metainf_services/000077500000000000000000000000001265334116300303155ustar00rootroot00000000000000AnnotationProcessorImpl.java000066400000000000000000000177731265334116300357540ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/java/org/kohsuke/metainf_services/* * The MIT License * * Copyright (c) 2009-, Kohsuke Kawaguchi * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.kohsuke.metainf_services; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.Filer; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.MirroredTypesException; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import javax.tools.Diagnostic.Kind; import javax.tools.FileObject; import javax.tools.StandardLocation; import org.kohsuke.MetaInfServices; /** * @author Kohsuke Kawaguchi */ @SuppressWarnings({"Since15"}) @SupportedAnnotationTypes("org.kohsuke.MetaInfServices") public class AnnotationProcessorImpl extends AbstractProcessor { @Override public SourceVersion getSupportedSourceVersion() { try { // Seems to work. Probably could use some additional error checks, but current code does not even verify that the class is assignable to an explicitly specified type! // Need to add unit tests. See stapler/stapler/core/src/test/java/org/kohsuke/stapler/jsr269/ for examples. return SourceVersion.valueOf("RELEASE_8"); } catch (IllegalArgumentException x) {} try { return SourceVersion.valueOf("RELEASE_7"); } catch (IllegalArgumentException x) {} return SourceVersion.RELEASE_6; } @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) return false; // TODO should not write anything until processingOver Map> services = new HashMap>(); Elements elements = processingEnv.getElementUtils(); // discover services from the current compilation sources for (Element e : roundEnv.getElementsAnnotatedWith(MetaInfServices.class)) { MetaInfServices a = e.getAnnotation(MetaInfServices.class); if(a==null) continue; // input is malformed, ignore if (!e.getKind().isClass() && !e.getKind().isInterface()) continue; // ditto TypeElement type = (TypeElement)e; Collection contracts = getContracts(type, a); if(contracts.isEmpty()) continue; // error should have already been reported for (TypeElement contract : contracts) { String cn = elements.getBinaryName(contract).toString(); Set v = services.get(cn); if(v==null) services.put(cn,v=new TreeSet()); v.add(elements.getBinaryName(type).toString()); } } // also load up any existing values, since this compilation may be partial Filer filer = processingEnv.getFiler(); for (Map.Entry> e : services.entrySet()) { try { String contract = e.getKey(); FileObject f = filer.getResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/services/" +contract); BufferedReader r = new BufferedReader(new InputStreamReader(f.openInputStream(), "UTF-8")); String line; while((line=r.readLine())!=null) e.getValue().add(line); r.close(); } catch (FileNotFoundException x) { // doesn't exist } catch (java.nio.file.NoSuchFileException x) { // doesn't exist } catch (IOException x) { processingEnv.getMessager().printMessage(Kind.ERROR,"Failed to load existing service definition files: "+x); } } // now write them back out for (Map.Entry> e : services.entrySet()) { try { String contract = e.getKey(); processingEnv.getMessager().printMessage(Kind.NOTE,"Writing META-INF/services/"+contract); FileObject f = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/services/" +contract); PrintWriter pw = new PrintWriter(new OutputStreamWriter(f.openOutputStream(), "UTF-8")); for (String value : e.getValue()) pw.println(value); pw.close(); } catch (IOException x) { processingEnv.getMessager().printMessage(Kind.ERROR,"Failed to write service definition files: "+x); } } return false; } private Collection getContracts(TypeElement type, MetaInfServices a) { List typeElementList = new ArrayList(); // explicitly specified? try { a.value(); throw new AssertionError(); } catch (MirroredTypesException e) { for (TypeMirror m : e.getTypeMirrors()) { if (m.getKind()== TypeKind.VOID) { // contract inferred from the signature boolean hasBaseClass = type.getSuperclass().getKind()!=TypeKind.NONE && !isObject(type.getSuperclass()); boolean hasInterfaces = !type.getInterfaces().isEmpty(); if(hasBaseClass^hasInterfaces) { if(hasBaseClass) typeElementList.add((TypeElement)((DeclaredType)type.getSuperclass()).asElement()); else typeElementList.add((TypeElement)((DeclaredType)type.getInterfaces().get(0)).asElement()); continue; } error(type, "Contract type was not specified, but it couldn't be inferred."); continue; } if (m instanceof DeclaredType) { DeclaredType dt = (DeclaredType) m; typeElementList.add((TypeElement)dt.asElement()); continue; } else { error(type, "Invalid type specified as the contract"); continue; } } } return typeElementList; } private boolean isObject(TypeMirror t) { if (t instanceof DeclaredType) { DeclaredType dt = (DeclaredType) t; return((TypeElement)dt.asElement()).getQualifiedName().toString().equals("java.lang.Object"); } return false; } private void error(Element source, String msg) { processingEnv.getMessager().printMessage(Kind.ERROR,msg,source); } } metainf-services-metainf-services-1.7/src/main/resources/000077500000000000000000000000001265334116300236205ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/resources/META-INF/000077500000000000000000000000001265334116300247605ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/resources/META-INF/services/000077500000000000000000000000001265334116300266035ustar00rootroot00000000000000javax.annotation.processing.Processor000066400000000000000000000000641265334116300360620ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/main/resources/META-INF/servicesorg.kohsuke.metainf_services.AnnotationProcessorImplmetainf-services-metainf-services-1.7/src/site/000077500000000000000000000000001265334116300216265ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/site/apt/000077500000000000000000000000001265334116300224125ustar00rootroot00000000000000metainf-services-metainf-services-1.7/src/site/apt/index.apt000066400000000000000000000035531265334116300242350ustar00rootroot00000000000000What is this? This tiny library is an annotation processor that automatically generates <<>> file from annotations that you placed on your source code, thereby eliminating the need for you to do it by yourself. Usage On classes that you'd like listed as service providers, put @MetaInfServices annotation. As long as you only have one interface or one super class, that type is assumed to be the contract. So given the example below: ----------------------------------- import org.kohsuke.MetaInfServices; @MetaInfServices public class MyProvider implements SomeContract { ... } ----------------------------------- You get the <<>> file whose content is <<>>. If you have multiple interfaces and/or base type, the library cannot infer the contract type. In such a case, specify the contract type explicitly by giving it to <<<@MetaInfServices>>> like this: ----------------------------------- import org.kohsuke.MetaInfServices; @MetaInfServices(ContractType.class) public class MyProvider extends AbstractSet implements Comparable, Serializable, Closeable { ... } ----------------------------------- When you use <<>> in JavaSE6, <<>> files are generated automatically. No additional compiler switches are necessary. This library handles incremental compilation correctly, too. Tips for Maven users <<>> is only necessary during the compilation, so specify it as an optional dependency to avoid having the jar in the runtime. This will save 6KB in the runtime footprint. ----------------------------------- org.kohsuke.metainf-services metainf-services 1.1 true ----------------------------------- metainf-services-metainf-services-1.7/src/site/site.xml000066400000000000000000000012121265334116300233100ustar00rootroot00000000000000 org.kohsuke maven-skin 1.1

${reports}