r735 - in trunk: . src/main/java/org/nuiton/helper/plugin src/main/java/org/nuiton/plugin
Author: tchemit Date: 2010-06-29 12:49:29 +0200 (Tue, 29 Jun 2010) New Revision: 735 Url: http://nuiton.org/repositories/revision/maven-helper-plugin/735 Log: Evolution #722: Introduce PluginWithEncoding Added: trunk/src/main/java/org/nuiton/plugin/PluginWithEncoding.java Modified: trunk/pom.xml trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java trunk/src/main/java/org/nuiton/plugin/PluginHelper.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-06-27 06:49:24 UTC (rev 734) +++ trunk/pom.xml 2010-06-29 10:49:29 UTC (rev 735) @@ -34,7 +34,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom4redmine</artifactId> - <version>2.2.1</version> + <version>2.2.2-SNAPSHOT</version> </parent> <artifactId>maven-helper-plugin</artifactId> Modified: trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2010-06-27 06:49:24 UTC (rev 734) +++ trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2010-06-29 10:49:29 UTC (rev 735) @@ -33,6 +33,7 @@ import org.apache.maven.project.MavenProject; import org.nuiton.plugin.AbstractPlugin; import org.nuiton.plugin.PluginHelper; +import org.nuiton.plugin.PluginWithEncoding; import java.io.File; import java.io.IOException; @@ -49,7 +50,7 @@ * @requiresProject true * @since 1.1.0 */ -public class CollectFilesMojo extends AbstractPlugin { +public class CollectFilesMojo extends AbstractPlugin implements PluginWithEncoding { /** * The projects in the reactor. @@ -58,7 +59,7 @@ * @readonly * @since 1.2.4 */ - protected List reactorProjects; + protected List<?> reactorProjects; /** * Fallback maven project (for maven 2). @@ -78,7 +79,7 @@ * @readonly * @since 1.0.0 */ - protected List attachedArtifacts; + protected List<?> attachedArtifacts; /** * The local repository. @@ -359,6 +360,7 @@ /** * Read a file containing on each line the path of a file. * + * @param input the file where to pick files (one file per line). * @return the list of files read from the given file * @throws IOException if any pb while reading file */ @@ -491,24 +493,6 @@ return result; } -// -// protected MavenProject getExecutionRootProject(MavenProject project) { -// -// if (project.isExecutionRoot()) { -// -// getLog().info("Project is root execution : " + project); -// return project; -// } -// -// if (project.getParent() == null) { -// -// getLog().info("Could not find executionRoot for " + project); -// return null; -// } -// -// MavenProject result = getExecutionRootProject(project.getParent()); -// return result; -// } protected void addFile(File f, String msg, @@ -566,5 +550,15 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } + + @Override + public String getEncoding() { + return encoding; + } + + @Override + public void setEncoding(String encoding) { + this.encoding = encoding; + } } Modified: trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2010-06-27 06:49:24 UTC (rev 734) +++ trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2010-06-29 10:49:29 UTC (rev 735) @@ -37,6 +37,7 @@ import org.nuiton.io.mail.ProjectJavamailMailSender; import org.nuiton.plugin.AbstractPlugin; import org.nuiton.plugin.PluginHelper; +import org.nuiton.plugin.PluginWithEncoding; import java.io.File; import java.util.List; @@ -50,7 +51,7 @@ * @requiresProject true * @since 1.0.3 */ -public class SendEmailMojo extends AbstractPlugin { +public class SendEmailMojo extends AbstractPlugin implements PluginWithEncoding{ /** * Dependance du projet. @@ -304,7 +305,6 @@ "Invalid mail sender: name and email is mandatory (" + mailSender + ")."); } - } @Override @@ -399,7 +399,7 @@ ProjectJavamailMailSender mailer = new ProjectJavamailMailSender(); ConsoleLogger logger = new ConsoleLogger(Logger.LEVEL_INFO, "base"); - if (getLog().isDebugEnabled()) { + if (isVerbose()) { logger.setThreshold(Logger.LEVEL_DEBUG); } mailer.enableLogging(logger); @@ -432,4 +432,14 @@ protected boolean isExecutionRoot() { return project.isExecutionRoot(); } + + @Override + public String getEncoding() { + return encoding; + } + + @Override + public void setEncoding(String encoding) { + this.encoding = encoding; + } } Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2010-06-27 06:49:24 UTC (rev 734) +++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2010-06-29 10:49:29 UTC (rev 735) @@ -81,8 +81,7 @@ protected abstract void doAction() throws Exception; @Override - public final void execute() throws MojoExecutionException, - MojoFailureException { + public final void execute() throws MojoExecutionException, MojoFailureException { try { if (getLog().isDebugEnabled()) { @@ -103,8 +102,14 @@ try { + checkEncoding(); + init(); + } catch (MojoFailureException e) { + throw e; + } catch (MojoExecutionException e) { + throw e; } catch (Exception e) { throw new MojoExecutionException( "could not init goal " + getClass().getSimpleName() + @@ -127,6 +132,10 @@ doAction(); + } catch (MojoFailureException e) { + throw e; + } catch (MojoExecutionException e) { + throw e; } catch (Exception e) { throw new MojoExecutionException( "could not execute goal " + getClass().getSimpleName() + @@ -795,7 +804,7 @@ * the resources */ protected URL getTemplate(File f) throws IOException { - URL r = null; + URL r; if (f.exists()) { r = f.toURI().toURL(); } else { @@ -829,7 +838,7 @@ } } - protected MavenProject getRootProject(MavenProject project, List reactors) { + protected MavenProject getRootProject(MavenProject project, List<?> reactors) { if (project.isExecutionRoot() || reactors.size() == 1 || reactors.get(0).equals(project)) { getLog().debug("project " + project + " is root execution :)"); @@ -841,4 +850,30 @@ getLog().debug("first project in reactor : " + root); return root; } + + /** + * Method to be invoked in init phase to check sanity of {@link PluginWithEncoding#getEncoding()}. + * <p/> + * If no encoding was filled, then use the default for system + * (via {@code file.encoding} environement property). + * <p/> + * <b>Note:</b> If mojo is not implementing {@link PluginWithEncoding}, + * nothing is done. + * + * @since 1.26 + */ + protected void checkEncoding() { + + if (PluginWithEncoding.class.isAssignableFrom(getClass())) { + PluginHelper.checkEncoding((PluginWithEncoding) this); + } + } + + /** + * @return {@code true} if project is not a pom, {@code false} otherwise. + * @since 1.2.6 + */ + protected boolean hasClassPath() { + return rejectPackaging(Packaging.pom); + } } Modified: trunk/src/main/java/org/nuiton/plugin/PluginHelper.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2010-06-27 06:49:24 UTC (rev 734) +++ trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2010-06-29 10:49:29 UTC (rev 735) @@ -30,13 +30,30 @@ import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.StringUtils; -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.text.MessageFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -639,4 +656,26 @@ "could not obtain url " + url, ex); } } + + /** + * Method to be invoked in init phase to check sanity of {@link PluginWithEncoding#getEncoding()}. + * <p/> + * If no encoding was filled, then use the default for system + * (via {@code file.encoding} environement property). + * <p/> + * <b>Note:</b> If mojo is not implementing {@link PluginWithEncoding}, + * nothing is done. + * + * @param mojo the mojo to check. + * @since 1.2.6 + */ + public static void checkEncoding(PluginWithEncoding mojo) { + + if (StringUtils.isEmpty(mojo.getEncoding())) { + mojo.getLog().warn( + "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + + ", i.e. build is platform dependent!"); + } + mojo.setEncoding(ReaderFactory.FILE_ENCODING); + } } Added: trunk/src/main/java/org/nuiton/plugin/PluginWithEncoding.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/PluginWithEncoding.java (rev 0) +++ trunk/src/main/java/org/nuiton/plugin/PluginWithEncoding.java 2010-06-29 10:49:29 UTC (rev 735) @@ -0,0 +1,52 @@ +/* + * #%L + * Maven helper plugin + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.plugin; + +/** + * A common contract to be implements by our mojo and reports which needs encoding. + * <p/> + * Just expose a getter-setter {@link #getEncoding()} and {@link #setEncoding(String)}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public interface PluginWithEncoding extends Plugin { + + + /** + * Gets the encoding to be used to read and write io resources. + * + * @return the encoding used. + */ + String getEncoding(); + + /** + * Sets the encoding to use in mojo. + * + * @param encoding the new encoding to use in mojo + */ + void setEncoding(String encoding); +} \ No newline at end of file Property changes on: trunk/src/main/java/org/nuiton/plugin/PluginWithEncoding.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL
participants (1)
-
tchemit@users.nuiton.org