pax_global_header00006660000000000000000000000064122365140010014504gustar00rootroot0000000000000052 comment=b787aae7695bf767c0cd032a90cdda6ba0a1f825 maven-stapler-plugin-maven-stapler-plugin-1.17/000077500000000000000000000000001223651400100215565ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/.cvsignore000066400000000000000000000000311223651400100235500ustar00rootroot00000000000000target *.iws *.iml *.ipr maven-stapler-plugin-maven-stapler-plugin-1.17/.gitignore000066400000000000000000000000311223651400100235400ustar00rootroot00000000000000*.iml *.ipr *.iws target maven-stapler-plugin-maven-stapler-plugin-1.17/pom.xml000066400000000000000000000100241223651400100230700ustar00rootroot00000000000000 4.0.0 org.kohsuke.stapler maven-stapler-plugin maven-plugin 1.17 Maven Stapler plugin Maven2 plugin for developing stapler applications scm:git:git://github.com/stapler/${project.artifactId}.git scm:git:ssh://git@github.com/stapler/${project.artifactId}.git https://github.com/stapler/${project.artifactId} maven-stapler-plugin-1.17 2-clause BSD license repo http://www.opensource.org/licenses/bsd-license.php maven.jenkins-ci.org http://maven.jenkins-ci.org:8081/content/repositories/releases/ UTF-8 maven-compiler-plugin 3.1 1.6 1.6 org.codehaus.mojo animal-sniffer-maven-plugin 1.9 check org.codehaus.mojo.signature java16 1.0 org.apache.maven.plugins maven-idea-plugin 2.2.1 JDK1.6 true maven-plugin-plugin 3.2 stapler org.kohsuke.stapler stapler 1.100 org.apache.maven maven-plugin-api 2.0.1 org.apache.maven maven-project 2.0.1 org.apache.maven maven-artifact 2.0.1 dom4j dom4j 1.6.1 org.jvnet.maven-jellydoc-plugin maven-jellydoc-plugin 1.5 jaxen jaxen 1.1.4 com.google.guava guava r06 org.kohsuke.metainf-services metainf-services 1.2 maven-stapler-plugin-maven-stapler-plugin-1.17/src/000077500000000000000000000000001223651400100223455ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/000077500000000000000000000000001223651400100232715ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/000077500000000000000000000000001223651400100242125ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/000077500000000000000000000000001223651400100250015ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/000077500000000000000000000000001223651400100264525ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/stapler/000077500000000000000000000000001223651400100301245ustar00rootroot00000000000000AbstractProcessorImpl.java000066400000000000000000000025431223651400100352010ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/staplerpackage org.kohsuke.stapler; import javax.annotation.processing.AbstractProcessor; import javax.lang.model.element.Element; import javax.tools.FileObject; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; import static javax.tools.Diagnostic.Kind.*; import static javax.tools.StandardLocation.*; /** * @author Kohsuke Kawaguchi */ @SuppressWarnings({"Since15"}) abstract class AbstractProcessorImpl extends AbstractProcessor { protected void error(String msg) { processingEnv.getMessager().printMessage(ERROR, msg); } protected String getJavadoc(Element md) { return processingEnv.getElementUtils().getDocComment(md); } protected void notice(String msg, Element location) { processingEnv.getMessager().printMessage(NOTE, msg, location); } protected void writePropertyFile(Properties p, String name) throws IOException { FileObject f = createResource(name); OutputStream os = f.openOutputStream(); p.store(os,null); os.close(); } protected FileObject getResource(String name) throws IOException { return processingEnv.getFiler().getResource(CLASS_OUTPUT, "", name); } protected FileObject createResource(String name) throws IOException { return processingEnv.getFiler().createResource(CLASS_OUTPUT, "", name); } } ConstructorProcessor6.java000066400000000000000000000045661223651400100352360ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/staplerpackage org.kohsuke.stapler; import org.kohsuke.MetaInfServices; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.util.ElementScanner6; import java.io.IOException; import java.util.Properties; import java.util.Set; /** * @author Kohsuke Kawaguchi */ @SuppressWarnings({"Since15"}) @SupportedSourceVersion(SourceVersion.RELEASE_6) @SupportedAnnotationTypes("*") @MetaInfServices(Processor.class) public class ConstructorProcessor6 extends AbstractProcessorImpl { @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { ElementScanner6 scanner = new ElementScanner6() { @Override public Void visitExecutable(ExecutableElement e, Void aVoid) { if(e.getAnnotation(DataBoundConstructor.class)!=null) { write(e); } else { String javadoc = getJavadoc(e); if(javadoc!=null && javadoc.contains("@stapler-constructor")) { write(e); } } return super.visitExecutable(e, aVoid); } }; for( Element e : roundEnv.getRootElements() ) scanner.scan(e,null); return false; } private void write(ExecutableElement c) { try { StringBuilder buf = new StringBuilder(); for( VariableElement p : c.getParameters() ) { if(buf.length()>0) buf.append(','); buf.append(p.getSimpleName()); } TypeElement t = (TypeElement) c.getEnclosingElement(); String name = t.getQualifiedName().toString().replace('.', '/') + ".stapler"; notice("Generating " + name, c); Properties p = new Properties(); p.put("constructor",buf.toString()); writePropertyFile(p, name); } catch (IOException x) { error(x.toString()); } } } ExportedBeanAnnotationProcessor6.java000066400000000000000000000137021223651400100373140ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/staplerpackage org.kohsuke.stapler; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; import org.kohsuke.MetaInfServices; import org.kohsuke.stapler.export.Exported; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; 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.FileObject; 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.Collection; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.TreeSet; /** * @author Kohsuke Kawaguchi */ @SuppressWarnings({"Since15"}) @SupportedSourceVersion(SourceVersion.RELEASE_6) @SupportedAnnotationTypes("*") @MetaInfServices(Processor.class) public class ExportedBeanAnnotationProcessor6 extends AbstractProcessorImpl { @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { try { if (roundEnv.processingOver()) { return false; } // collect all exposed properties Multimap props = LinkedListMultimap.create(); for (Element exported : roundEnv.getElementsAnnotatedWith(Exported.class)) { props.put((TypeElement)exported.getEnclosingElement(), exported); } Set exposedBeanNames = scanExisting(); for (Entry> e : props.asMap().entrySet()) { exposedBeanNames.add(e.getKey().getQualifiedName().toString()); final Properties javadocs = new Properties(); for (Element md : e.getValue()) { switch (md.getKind()) { case FIELD: case METHOD: String javadoc = getJavadoc(md); if(javadoc!=null) javadocs.put(md.getSimpleName().toString(), javadoc); break; default: throw new AssertionError("Unexpected element type: "+md); } // TODO: possibly a proper method signature generation, but it's too tedious // way too tedious. //private String getSignature(MethodDeclaration m) { // final StringBuilder buf = new StringBuilder(m.getSimpleName()); // buf.append('('); // boolean first=true; // for (ParameterDeclaration p : m.getParameters()) { // if(first) first = false; // else buf.append(','); // p.getType().accept(new SimpleTypeVisitor() { // public void visitPrimitiveType(PrimitiveType pt) { // buf.append(pt.getKind().toString().toLowerCase()); // } // public void visitDeclaredType(DeclaredType dt) { // buf.append(dt.getDeclaration().getQualifiedName()); // } // // public void visitArrayType(ArrayType at) { // at.getComponentType().accept(this); // buf.append("[]"); // } // // public void visitTypeVariable(TypeVariable tv) { // // // TODO // super.visitTypeVariable(typeVariable); // } // // public void visitVoidType(VoidType voidType) { // // TODO // super.visitVoidType(voidType); // } // }); // } // buf.append(')'); // // TODO // return null; //} } String javadocFile = e.getKey().getQualifiedName().toString().replace('.', '/') + ".javadoc"; notice("Generating "+ javadocFile, e.getKey()); writePropertyFile(javadocs, javadocFile); } FileObject beans = createResource(STAPLER_BEAN_FILE); PrintWriter w = new PrintWriter(new OutputStreamWriter(beans.openOutputStream(),"UTF-8")); for (String beanName : exposedBeanNames) w.println(beanName); w.close(); } catch (IOException x) { error(x.toString()); } return false; } private Set scanExisting() throws IOException { Set exposedBeanNames = new TreeSet(); FileObject beans = getResource(STAPLER_BEAN_FILE); try { BufferedReader in = new BufferedReader(new InputStreamReader(beans.openInputStream(),"UTF-8")); String line; while((line=in.readLine())!=null) exposedBeanNames.add(line.trim()); in.close(); } catch (FileNotFoundException e) { // no existing file, which is fine } return exposedBeanNames; } private static final String STAPLER_BEAN_FILE = "META-INF/exposed.stapler-beans"; } maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/stapler/L10nProgress.java000066400000000000000000000137271223651400100332400ustar00rootroot00000000000000/* * Copyright (c) 2004-2010, Kohsuke Kawaguchi * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.kohsuke.stapler; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Represents the progress of l10n effort. * * @author ssogabe * @see http://d.hatena.ne.jp/ssogabe/20081213/1229175653 */ public class L10nProgress { /** * Locales used in the set of files parsed. */ private final Set locales = new TreeSet(); private final List messages = new ArrayList(); /** * Information per directory. */ public final class HudsonMessages { private final File dir; private final Map map = new HashMap(); public HudsonMessages(final File dir) { this.dir = dir; } public String getDirectoryName() { return dir.getName(); } private void setCnt(final String locale, final int cnt) { map.put(locale, cnt); } public int getCnt(final String locale) { final Integer cnt = map.get(locale); return cnt != null ? cnt : 0; } /** * Gets the ratio of localization against the default locale. */ public int ratio(String locale) { return (int) (((double) getCnt(locale) / getCnt("")) * 100); } /** * Dumps this object as a row in the Hatena diary format. */ public void toHatena(StringBuilder b) { b.append("|").append(getDirectoryName()).append("(").append(getCnt("")).append(") |"); for (final String locale : locales) { b.append(getCnt(locale)).append("(").append(ratio(locale)).append("%)|"); } b.append("\n"); } } /** * Gets the pseudo {@link HudsonMessages} that represents the sum of all {@link #messages}. */ public HudsonMessages getTotal() { HudsonMessages sum = new HudsonMessages(new File("total")); ArrayList localesPlusOne = new ArrayList(locales); localesPlusOne.add(""); for (String locale : localesPlusOne) { int cnt=0; for (HudsonMessages m : messages) cnt += m.getCnt(locale); sum.setCnt(locale,cnt); } return sum; } /** * Returns the number of entries in the given property file. */ private int getMessageCnt(final File file) { final Properties props = new Properties(); int cnt = 0; try { props.load(new FileInputStream(file)); cnt = props.size(); } catch (final IOException e) { e.printStackTrace(); } return cnt; } /** * Prints the result in the Hatena diary table format. */ public String toHatena() { final StringBuilder b = new StringBuilder(); // header b.append("|*Messages(#)|"); for (final String locale : locales) { b.append("*").append(locale).append("|"); } b.append("\n"); for (final HudsonMessages m : messages) m.toHatena(b); getTotal().toHatena(b); return b.toString(); } public void parse(File dir) { final HudsonMessages m = new HudsonMessages(dir); final File[] files = dir.listFiles(); for (final File f : files) { final Matcher matcher = FILENAME_PATTERN.matcher(f.getName()); if (matcher.matches()) { final String locale = matcher.group(1); if (!locale.equals("")) { locales.add(locale); } m.setCnt(locale, getMessageCnt(f)); } } messages.add(m); } public void parse(Collection dirs) { for (final File dir : dirs) parse(dir); } /** * Parse the given directory and all its descendants. */ public void parseRecursively(final File dir) { for (final File f : dir.listFiles()) { if (f.isDirectory()) { parseRecursively(f); } else if (f.isFile() && MESSAGES_FILE.equals(f.getName())) { parse(f.getParentFile()); } } } private static final String MESSAGES_FILE = "Messages.properties"; private static final Pattern FILENAME_PATTERN = Pattern.compile("^Messages_?([a-zA-Z_]*)\\.properties$"); } maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/stapler/LocalizerMojo.java000066400000000000000000000256201223651400100335450ustar00rootroot00000000000000/* * Copyright (c) 2004-2010, Kohsuke Kawaguchi * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.kohsuke.stapler; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.model.Resource; import org.xml.sax.Attributes; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.RandomAccessFile; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.regex.Pattern; import java.util.regex.Matcher; /** * Alias for stapler:l10n mojo. Left for compatibility. * * @author Kohsuke Kawaguchi * @goal i18n */ public class LocalizerMojo extends AbstractMojo { /** * The locale to generate properties for. * * @parameter expression="${locale}" * @required */ protected String locale; /** * The maven project. * * @parameter expression="${project}" * @required * @readonly */ protected MavenProject project; public void execute() throws MojoExecutionException, MojoFailureException { // create parser try { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); parser = spf.newSAXParser(); } catch (SAXException e) { throw new Error(e); // impossible } catch (ParserConfigurationException e) { throw new Error(e); // impossible } for( Resource res : (List)project.getResources() ) { File dir = new File(res.getDirectory()); processDirectory(dir); } } private void process(File file) throws MojoExecutionException { if(file.isDirectory()) processDirectory(file); else if(file.getName().endsWith(".jelly")) processJelly(file); } private void processDirectory(File dir) throws MojoExecutionException { File[] children = dir.listFiles(); if(children==null) return; for (File child : children) process(child); } private void processJelly(File file) throws MojoExecutionException { Set props = findAllProperties(file); if(props.isEmpty()) return; // nothing to generate here. String fileName = file.getName(); fileName=fileName.substring(0,fileName.length()-".jelly".length()); fileName+='_'+locale+".properties"; File resourceFile = new File(file.getParentFile(),fileName); if(resourceFile.exists()) { Properties resource; try { resource = new Properties(resourceFile); } catch (IOException e) { throw new MojoExecutionException("Failed to read "+resourceFile,e); } // find unnecessary properties = those which are present in the resource file but not in Jelly HashSet unnecessaries = new HashSet((Set) resource.keySet()); unnecessaries.removeAll(props); for (String s : unnecessaries) getLog().warn("Unused property "+s+" in "+resourceFile); // figure out missing properties props.removeAll(resource.keySet()); // add NL to the end if necessary try { // then add them to the end RandomAccessFile f = new RandomAccessFile(resourceFile,"rw"); if(f.length()>0) { // add the terminating line end if needed f.seek(f.length()-1); int ch = f.read(); if(!(ch=='\r' || ch=='\n')) f.write(System.getProperty("line.separator").getBytes()); } f.close(); } catch (IOException e) { throw new MojoExecutionException("Failed to write "+resourceFile,e); } } if(props.isEmpty()) return; // no change to make getLog().info("Updating "+resourceFile); try { // then add them to the end RandomAccessFile f = new RandomAccessFile(resourceFile,"rw"); if(f.length()>0) { // add the terminating line end if needed f.seek(f.length()-1); int ch = f.read(); if(!(ch=='\r' || ch=='\n')) f.write(System.getProperty("line.separator").getBytes()); } f.close(); PrintWriter w = new PrintWriter(new FileWriter(resourceFile,true)); for (String p : props) { w.println(escape(p)+"="); } w.close(); } catch (IOException e) { throw new MojoExecutionException("Failed to write "+resourceFile,e); } } /** * Escapes the property key in the proper format. */ private String escape(String key) { StringBuilder buf = new StringBuilder(key.length()); for( int i=0; i findAllProperties(File file) throws MojoExecutionException { getLog().debug("Parsing "+file); try { // we'd like to preserve order, but don't want duplicates final Set properties = new LinkedHashSet(); parser.parse(file,new DefaultHandler() { private final StringBuilder buf = new StringBuilder(); private Locator locator; public void setDocumentLocator(Locator locator) { this.locator = locator; } public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { findExpressions(); for( int i=0; i=0) exp=exp.substring(0,op); properties.add(exp); } else { Matcher m = RESOURCE_LITERAL_STRING.matcher(exp); while(m.find()) { String literal = m.group(); getLog().debug("Found "+literal); literal = literal.substring(2,literal.length()-1); // unquote and remove '%' // if parameters follow, remove them int op = literal.indexOf('('); if(op>=0) literal=literal.substring(0,op); properties.add(literal); } } } }); return properties; } catch (SAXException e) { throw new MojoExecutionException("Failed to parse "+file, e); } catch (IOException e) { throw new MojoExecutionException("Failed to parse "+file, e); } } SAXParser parser; // "%...." string literal that starts with '%' private static final Pattern RESOURCE_LITERAL_STRING = Pattern.compile("(\"%[^\"]+\")|('%[^']+')"); } maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/stapler/LocalizerMojo2.java000066400000000000000000000030351223651400100336230ustar00rootroot00000000000000/* * Copyright (c) 2004-2010, Kohsuke Kawaguchi * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.kohsuke.stapler; /** * Generate localized message bundles. * * @author Kohsuke Kawaguchi * @goal l10n */ public class LocalizerMojo2 extends LocalizerMojo { } LocalizerProgressMojo.java000066400000000000000000000045511223651400100352130ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/stapler/* * Copyright (c) 2004-2010, Kohsuke Kawaguchi * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.kohsuke.stapler; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import java.io.File; import java.util.Collection; /** * Prints out the progress of localization. * * @author ssogabe * @see http://d.hatena.ne.jp/ssogabe/20081213/1229175653 * @goal l10n-progress */ public class LocalizerProgressMojo extends AbstractMojo { /** * The maven project. * * @parameter expression="${project}" * @required * @readonly */ protected MavenProject project; public void execute() throws MojoExecutionException, MojoFailureException { L10nProgress r = new L10nProgress(); for( Resource root : (Collection)project.getResources() ) { r.parseRecursively(new File(root.getDirectory())); } System.out.println(r.toHatena()); } } maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/stapler/Properties.java000066400000000000000000000035431223651400100331300ustar00rootroot00000000000000/* * Copyright (c) 2004-2010, Kohsuke Kawaguchi * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.kohsuke.stapler; import java.io.File; import java.io.FileInputStream; import java.io.IOException; /** * @author Kohsuke Kawaguchi */ public class Properties extends java.util.Properties { public Properties() { super(); } /** * Loads from the file. */ public Properties(File src) throws IOException { FileInputStream in = new FileInputStream(src); try { load(in); } finally { in.close(); } } } QueryParameterAnnotationProcessor6.java000066400000000000000000000044251223651400100377040ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/staplerpackage org.kohsuke.stapler; import org.apache.commons.io.IOUtils; import org.kohsuke.MetaInfServices; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.tools.FileObject; import java.io.IOException; import java.io.OutputStream; import java.util.HashSet; import java.util.Set; /** * @author Kohsuke Kawaguchi */ @SuppressWarnings({"Since15"}) @SupportedSourceVersion(SourceVersion.RELEASE_6) @SupportedAnnotationTypes("*") @MetaInfServices(Processor.class) public class QueryParameterAnnotationProcessor6 extends AbstractProcessorImpl { @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { try { Set params = roundEnv.getElementsAnnotatedWith(QueryParameter.class); Set methods = new HashSet(); for (Element p : params) methods.add((ExecutableElement)p.getEnclosingElement()); for (ExecutableElement m : methods) { write(m); } } catch (IOException e) { error(e.getMessage()); } return false; } /** * @param m * Method whose parameter has {@link QueryParameter} */ private void write(ExecutableElement m) throws IOException { StringBuffer buf = new StringBuffer(); for( VariableElement p : m.getParameters() ) { if(buf.length()>0) buf.append(','); buf.append(p.getSimpleName()); } TypeElement t = (TypeElement)m.getEnclosingElement(); FileObject f = createResource(t.getQualifiedName().toString().replace('.', '/') + "/" + m.getSimpleName() + ".stapler"); notice("Generating " + f, m); OutputStream os = f.openOutputStream(); try { IOUtils.write(buf, os, "UTF-8"); } finally { os.close(); } } } maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/java/org/kohsuke/stapler/TaglibDocMojo.java000066400000000000000000000244371223651400100334560ustar00rootroot00000000000000/* * Copyright (c) 2004-2010, Kohsuke Kawaguchi * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.kohsuke.stapler; import com.sun.xml.txw2.TXW; import com.sun.xml.txw2.output.StreamSerializer; import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReportException; import org.codehaus.doxia.sink.Sink; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentFactory; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.jvnet.maven.jellydoc.Attribute; import org.jvnet.maven.jellydoc.JellydocMojo; import org.jvnet.maven.jellydoc.Library; import org.jvnet.maven.jellydoc.Tag; import org.jvnet.maven.jellydoc.Tags; import java.io.File; import java.io.FileFilter; import java.io.FileOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; /** * Scans Jelly tag libraries from tag files, and generate taglib.xml * compatible with maven-jellydoc-plugin * *

* For productive debugging of this mojo, run "mvn site:run" with debugger. * Every request will trigger a whole rendering, and you can do hot-swap of * byte code for changes. * * @author Kohsuke Kawaguchi * @goal jelly-taglibdoc * @phase generate-sources * @requiresDependencyResolution compile */ public class TaglibDocMojo extends AbstractMojo implements MavenReport { /** * The Maven Project Object * * @parameter expression="${project}" * @required * @readonly */ protected MavenProject project; /** * The plugin dependencies. * * @parameter expression="${plugin.artifacts}" * @required * @readonly */ private List pluginArtifacts; /** * Version of this plugin. * * @parameter expression="${plugin.version}" * @required * @readonly */ private String pluginVersion; /** * Regular expression for taglib URIs. If specified, * only those taglibs that match these patterns will be generated into * documentation. * * @parameter expression="${patterns}" */ private String[] patterns = new String[]{".*"}; /** * Factory for creating artifact objects * * @component */ private ArtifactFactory factory; /** * Used for resolving artifacts * * @component */ private ArtifactResolver resolver; /** * The local repository where the artifacts are located. * * @parameter expression="${localRepository}" */ private ArtifactRepository localRepository; /** * @component */ private MavenProjectHelper helper; private JellydocMojo jellydoc; public void execute() throws MojoExecutionException, MojoFailureException { writeTaglibXml(); getJellydocMojo().generateSchema(); } private JellydocMojo getJellydocMojo() { if(jellydoc==null) { jellydoc = new JellydocMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { TaglibDocMojo.this.execute(); } }; jellydoc.factory = factory; jellydoc.helper = helper; jellydoc.localRepository = localRepository; jellydoc.project = project; jellydoc.resolver = resolver; } return jellydoc; } private void writeTaglibXml() throws MojoExecutionException { try { File taglibsXml = new File(project.getBasedir(), "target/taglib.xml"); taglibsXml.getParentFile().mkdirs(); Tags tags = TXW.create(Tags.class,new StreamSerializer(new FileOutputStream(taglibsXml))); for(Resource res : (List)project.getResources()) scanTagLibs(new File(res.getDirectory()),"",tags); tags.commit(); } catch (IOException e) { throw new MojoExecutionException("Failed to generate taglibs.xml",e); } } /** * Recurisely search for taglibs and call {@link #parseTagLib(File, String, Library)}. */ private void scanTagLibs(File dir, String uri, Tags tags) throws IOException { if(new File(dir,"taglib").exists()) { boolean match = patterns.length==0; for (String p : patterns) { if(Pattern.matches(p,uri)) { match = true; break; } } if(match) parseTagLib(dir,uri,tags.library()); } // scan subdirs File[] subdirs = dir.listFiles(new FileFilter() { public boolean accept(File f) { return f.isDirectory(); } }); if(subdirs==null) return; for (File subdir : subdirs) scanTagLibs(subdir,uri+'/'+subdir.getName(), tags); } private void parseTagLib(File dir, String uri, Library lib) throws IOException { getLog().info("Processing "+dir); List markerFile = FileUtils.readLines(new File(dir, "taglib")); if(markerFile.size()==0) markerFile.add(uri); // write the attributes lib.name(markerFile.get(0).toString()); lib.prefix(uri.substring(uri.lastIndexOf('/')+1)).uri(uri); // doc lib.doc()._pcdata(join(markerFile)); File[] tagFiles = dir.listFiles(new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(".jelly"); } }); if(tagFiles==null) return; for (File tagFile : tagFiles) parseTagFile(tagFile,lib.tag()); } /** * Parses a given tag file and writes to {@link Tag}. */ private void parseTagFile(File tagFile, Tag tag) throws IOException { try { String name = tagFile.getName(); name = name.substring(0,name.length()-6); // cut off ".jelly" tag.name(name); DocumentFactory f = new DocumentFactory(); f.setXPathNamespaceURIs(NAMESPACE_MAP); Document jelly = new SAXReader(f).read(tagFile); Element doc = (Element) jelly.selectSingleNode(".//s:documentation"); // does this tag have a body? if(jelly.selectSingleNode("//d:invokeBody")==null) tag.noContent(true); if(doc==null) { tag.doc(""); } else { tag.doc(doc.getText()); for(Element attr : (List)doc.selectNodes("s:attribute")) { Attribute aw = tag.attribute(); for (org.dom4j.Attribute a : (List)attr.attributes()) aw._attribute(a.getName(),a.getValue()); aw.doc(attr.getText()); } } } catch (DocumentException e) { IOException x = new IOException("Failed to parse " + tagFile); x.initCause(e); throw x; } } private String join(List list) { StringBuilder buf = new StringBuilder(); for (Object item : list) { if(buf.length()>0) buf.append('\n'); buf.append(item); } return buf.toString(); } // // MavenReport implementation // public void generate(Sink sink, Locale locale) throws MavenReportException { getJellydocMojo().generate(sink,locale); } public String getOutputName() { return getJellydocMojo().getOutputName(); } public String getName(Locale locale) { return getJellydocMojo().getName(locale); } public String getCategoryName() { return getJellydocMojo().getCategoryName(); } public String getDescription(Locale locale) { return getJellydocMojo().getDescription(locale); } public void setReportOutputDirectory(File outputDirectory) { getJellydocMojo().setReportOutputDirectory(outputDirectory); } public File getReportOutputDirectory() { return getJellydocMojo().getReportOutputDirectory(); } public boolean isExternalReport() { return getJellydocMojo().isExternalReport(); } public boolean canGenerateReport() { return getJellydocMojo().canGenerateReport(); } private static final Map NAMESPACE_MAP = new HashMap(); static { NAMESPACE_MAP.put("s", "jelly:stapler"); NAMESPACE_MAP.put("d", "jelly:define"); } } maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/resources/000077500000000000000000000000001223651400100253035ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/resources/META-INF/000077500000000000000000000000001223651400100264435ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/resources/META-INF/plexus/000077500000000000000000000000001223651400100277635ustar00rootroot00000000000000maven-stapler-plugin-maven-stapler-plugin-1.17/src/main/resources/META-INF/plexus/components.xml000066400000000000000000000074331223651400100327010ustar00rootroot00000000000000 org.apache.maven.lifecycle.mapping.LifecycleMapping stapler-jar org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping default org.apache.maven.plugins:maven-resources-plugin:resources org.apache.maven.plugins:maven-compiler-plugin:compile org.apache.maven.plugins:maven-resources-plugin:testResources org.kohsuke.stapler:maven-stapler-plugin:apt-test-compile org.apache.maven.plugins:maven-surefire-plugin:test org.apache.maven.plugins:maven-jar-plugin:jar org.apache.maven.plugins:maven-install-plugin:install org.apache.maven.plugins:maven-deploy-plugin:deploy org.apache.maven.lifecycle.mapping.LifecycleMapping stapler-war org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping default org.apache.maven.plugins:maven-resources-plugin:resources org.apache.maven.plugins:maven-compiler-plugin:compile org.apache.maven.plugins:maven-resources-plugin:testResources org.kohsuke.stapler:maven-stapler-plugin:apt-test-compile org.apache.maven.plugins:maven-surefire-plugin:test org.apache.maven.plugins:maven-war-plugin:war org.apache.maven.plugins:maven-install-plugin:install org.apache.maven.plugins:maven-deploy-plugin:deploy org.apache.maven.artifact.handler.ArtifactHandler stapler-jar org.apache.maven.artifact.handler.DefaultArtifactHandler jar stapler-jar stapler-jar java true org.apache.maven.artifact.handler.ArtifactHandler stapler-war org.apache.maven.artifact.handler.DefaultArtifactHandler war stapler-war stapler-war java false