pax_global_header00006660000000000000000000000064117230115110014502gustar00rootroot0000000000000052 comment=f5a70129e549c80f1adebaffa46c3454f8e067b6 kohsuke-metainf-services-cab3195/000077500000000000000000000000001172301151100170265ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/.gitignore000066400000000000000000000000101172301151100210050ustar00rootroot00000000000000/target/kohsuke-metainf-services-cab3195/pom.xml000066400000000000000000000064221172301151100203470ustar00rootroot00000000000000 4.0.0 org.kohsuke.metainf-services metainf-services 1.4 META-INF/services generator Annotation-driven META-INF/services auto-generation http://metainf-srvices.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/ sonatype-nexus-snapshots Sonatype Nexus Snapshots https://oss.sonatype.org/content/repositories/snapshots/ sonatype-nexus-staging Nexus Release Repository https://oss.sonatype.org/service/local/staging/deploy/maven2/ github-pages gitsite:git@github.com/kohsuke/${project.artifactId}.git Kohsuke Kawaguchi kohsuke kk@kohsuke.org maven-compiler-plugin 1.5 1.5 -proc:none maven-release-plugin release org.apache.maven.scm maven-scm-provider-gitexe 1.3 org.apache.maven.scm maven-scm-manager-plexus 1.3 org.kathrynhuxtable.maven.wagon wagon-gitsite 0.3.1 MIT license http://www.opensource.org/licenses/mit-license.php repo release maven-gpg-plugin sign-artifacts verify sign kohsuke-metainf-services-cab3195/src/000077500000000000000000000000001172301151100176155ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/main/000077500000000000000000000000001172301151100205415ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/main/java/000077500000000000000000000000001172301151100214625ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/main/java/org/000077500000000000000000000000001172301151100222515ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/main/java/org/kohsuke/000077500000000000000000000000001172301151100237225ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/main/java/org/kohsuke/MetaInfServices.java000066400000000000000000000036131172301151100276170ustar00rootroot00000000000000/* * 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; } kohsuke-metainf-services-cab3195/src/main/java/org/kohsuke/metainf_services/000077500000000000000000000000001172301151100272505ustar00rootroot00000000000000AnnotationProcessorImpl.java000066400000000000000000000155121172301151100346740ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/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 org.kohsuke.MetaInfServices; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.Filer; import javax.annotation.processing.RoundEnvironment; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.MirroredTypeException; 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 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.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.TreeSet; /** * @author Kohsuke Kawaguchi */ @SuppressWarnings({"Since15"}) public class AnnotationProcessorImpl extends AbstractProcessor { @Override public Set getSupportedAnnotationTypes() { return Collections.singleton(MetaInfServices.class.getName()); } @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) return false; 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; TypeElement contract = getContract(type, a); if(contract==null) continue; // error should have already been reported 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 (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 TypeElement getContract(TypeElement type, MetaInfServices a) { // explicitly specified? try { a.value(); throw new AssertionError(); } catch (MirroredTypeException e) { TypeMirror m = e.getTypeMirror(); 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) return (TypeElement)((DeclaredType)type.getSuperclass()).asElement(); return (TypeElement)((DeclaredType)type.getInterfaces().get(0)).asElement(); } error(type, "Contract type was not specified, but it couldn't be inferred."); return null; } if (m instanceof DeclaredType) { DeclaredType dt = (DeclaredType) m; return (TypeElement)dt.asElement(); } else { error(type, "Invalid type specified as the contract"); return null; } } } 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); } } kohsuke-metainf-services-cab3195/src/main/resources/000077500000000000000000000000001172301151100225535ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/main/resources/META-INF/000077500000000000000000000000001172301151100237135ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/main/resources/META-INF/services/000077500000000000000000000000001172301151100255365ustar00rootroot00000000000000javax.annotation.processing.Processor000066400000000000000000000000641172301151100350150ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/main/resources/META-INF/servicesorg.kohsuke.metainf_services.AnnotationProcessorImplkohsuke-metainf-services-cab3195/src/site/000077500000000000000000000000001172301151100205615ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/site/apt/000077500000000000000000000000001172301151100213455ustar00rootroot00000000000000kohsuke-metainf-services-cab3195/src/site/apt/index.apt000066400000000000000000000035531172301151100231700ustar00rootroot00000000000000What 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 ----------------------------------- kohsuke-metainf-services-cab3195/src/site/site.xml000066400000000000000000000012121172301151100222430ustar00rootroot00000000000000 org.kohsuke maven-skin 1.1

${reports}