This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository maven-helper-plugin. See http://git.nuiton.org/maven-helper-plugin.git commit 940d9a622f756b46d2e4cf65b985609c57db50f2 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 25 12:34:11 2015 +0200 use Maven 3.0 Api (refs #3702) + introduce Test Api module (refs #3703) --- helper-maven-plugin-api/pom.xml | 112 +----- .../java/org/nuiton/plugin/AbstractMojoTest.java | 387 --------------------- .../test/java/org/nuiton/plugin/TestHelper.java | 121 ------- helper-maven-plugin-test-api/LICENSE.txt | 165 +++++++++ helper-maven-plugin-test-api/README.txt | 0 helper-maven-plugin-test-api/changelog.txt | 0 .../pom.xml | 130 ++----- .../src/license/THIRD-PARTY.properties | 32 ++ .../main/java/org/nuiton/plugin/MojoTestRule.java | 222 ++++++++++++ .../main/java/org/nuiton/plugin/TestHelper.java | 117 +++++++ .../src/site/apt/index.apt | 17 + .../src/site/apt/mojo-testFramework.apt | 22 +- helper-maven-plugin-test-api/src/site/site.xml | 31 ++ helper-maven-plugin/pom.xml | 27 +- .../nuiton/helper/plugin/SendEmailMojoTest.java | 79 +++-- .../plugin/TransformProjectVersionMojoTest.java | 58 +-- .../src/test/resources/log4j.properties | 32 ++ pom.xml | 48 ++- 18 files changed, 784 insertions(+), 816 deletions(-) diff --git a/helper-maven-plugin-api/pom.xml b/helper-maven-plugin-api/pom.xml index 49482e6..e6544b6 100644 --- a/helper-maven-plugin-api/pom.xml +++ b/helper-maven-plugin-api/pom.xml @@ -69,75 +69,41 @@ <!-- provided dependencies --> - <dependency> + <!--dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-container-default</artifactId> + </dependency--> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> - <version>${mavenVersion}</version> + <artifactId>maven-compat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-model</artifactId> - <version>${mavenVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-artifact</artifactId> - <version>${mavenVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> - <version>${mavenVersion}</version> <scope>provided</scope> </dependency> - <!-- tests dependencies --> - - <dependency> - <groupId>org.apache.maven.plugin-testing</groupId> - <artifactId>maven-plugin-testing-harness</artifactId> - <scope>test</scope> - <exclusions> - - <exclusion> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-archiver</artifactId> - </exclusion> - - <exclusion> - <groupId>org.apache.maven.wagon</groupId> - <artifactId>wagon-http-lightweight</artifactId> - </exclusion> - - <exclusion> - <groupId>org.apache.maven.wagon</groupId> - <artifactId>wagon-file</artifactId> - </exclusion> - - <exclusion> - <groupId>org.apache.maven.wagon</groupId> - <artifactId>wagon-ssh</artifactId> - </exclusion> - - <exclusion> - <groupId>org.apache.maven.reporting</groupId> - <artifactId>maven-reporting-api</artifactId> - </exclusion> - - </exclusions> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -166,21 +132,6 @@ </testResource> </testResources> - <plugins> - - <plugin> - <artifactId>maven-jar-plugin</artifactId> - <executions> - <execution> - <id>attach-test</id> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> <profiles> @@ -234,52 +185,6 @@ </reporting> </profile> - <!-- to deploy snapshot or release without anything else --> - <profile> - <id>release-profile</id> - <activation> - <property> - <name>performRelease</name> - <value>true</value> - </property> - </activation> - - <build> - <plugins> - - <!-- always compute source jar --> - <plugin> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <id>attach-sources</id> - <goals> - <goal>jar</goal> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - - <!-- always compute javadoc jar --> - <plugin> - <artifactId>maven-javadoc-plugin</artifactId> - <executions> - <execution> - <id>attach-javadocs</id> - <goals> - <goal>jar</goal> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - </build> - - </profile> - <!-- prepare the assembly at release time --> <profile> <id>release-assembly-profile</id> @@ -320,7 +225,6 @@ </profile> - </profiles> </project> diff --git a/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/AbstractMojoTest.java b/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/AbstractMojoTest.java deleted file mode 100644 index a528633..0000000 --- a/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/AbstractMojoTest.java +++ /dev/null @@ -1,387 +0,0 @@ -package org.nuiton.plugin; - -/* - * #%L - * Helper Maven Plugin :: API - * %% - * Copyright (C) 2009 - 2012 Codelutin, Tony Chemit - * %% - * 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% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.project.DefaultProjectBuilderConfiguration; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; -import org.apache.maven.project.ProjectBuilderConfiguration; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runner.Description; - -import java.beans.Introspector; -import java.io.File; -import java.io.IOException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Base test class for a mojo. - * <p/> - * <b>Note:</b> replace the previous class {@code org.nuiton.util.BasePluginTestCase}. - * <p/> - * Inside each test method, we can use the following objects : - * <p/> - * <ul> <li>{@link #getTestDir()} : location of mojo resources (where the pom - * file for example)</li> <li>{@link #getPomFile()} : location of the pom - * file</li> <li>{@link #getMojo()} : the instanciated and ready to execute - * mojo</li> </ul> - * <p/> - * To change the behaviour of initialization of mojo, you can override the - * following methods : <ul> <li>{@link #getBasedir()} </li> <li>{@link - * #getTestBasedir()} </li> <li>{@link #getTestDir(String, String)}</li> - * <li>{@link #getPomFile(File, String, String)}</li> <li>{@link - * #createMojo(File, String)}</li> <li>{@link #setUpMojo(Plugin, File)}</li> - * </ul> - * - * @param <P> type of goal to test - * @author tchemit <chemit@codelutin.com> - * @since 1.0.3 - */ -public abstract class AbstractMojoTest<P extends Plugin> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(AbstractMojoTest.class); - - /** the basedir of the project */ - protected static File basedir; - - /** the basedir of all tests (by convention {@code getBasedir()/target/test-classes}). */ - protected static File testBasedir; - - /** - * Your test rule which offers methodName, testDir, pomFile and mojo inside - * test methods. - */ - @Rule - public MojoTestRule name = new MojoTestRule(); - - public File getBasedir() { - if (basedir == null) { - basedir = TestHelper.getBasedir(); - if (log.isDebugEnabled()) { - log.debug("basedir = " + basedir); - } - } - return basedir; - } - - public File getTestBasedir() { - if (testBasedir == null) { - testBasedir = TestHelper.getFile(getBasedir(), - "target", - "test-classes" - ); - if (log.isDebugEnabled()) { - log.debug("testBasedir = " + testBasedir); - } - } - return testBasedir; - } - - public String getRelativePathFromBasedir(File f) { - return TestHelper.getRelativePath(getBasedir(), f); - } - - public String getRelativePathFromTestBasedir(File f) { - return TestHelper.getRelativePath(getTestBasedir(), f); - } - - /** - * Obtain the name of the goal according to the methodName. - * <p/> - * By convention, we should consider that a test class use always the same - * goal's name. - * - * @param methodName the name of the next test to execute. - * @return the name of the goal to test for the given method test name. - */ - protected abstract String getGoalName(String methodName); - - /** - * Obtain the location of the directory where to find resources for the next - * test. - * <p/> - * By convention, will be the package named by the test class name from the - * {@link #getTestBasedir()}. - * - * @param methodName the method of the next test to execute - * @param goalName the common goal name to use - * @return the directory where to find resources for the test - */ - protected File getTestDir(String methodName, String goalName) { - - //TC-20091101 use a decipatilize simple name to avoid conflict of - // package with existing class name. - String rep = getClass().getPackage().getName() + "." + - Introspector.decapitalize(getClass().getSimpleName()); - String[] paths = rep.split("\\."); - File testDir = TestHelper.getFile(getTestBasedir(), paths); - if (isVerbose()) { - log.info("test dir = " + getRelativePathFromBasedir(testDir)); - } else if (log.isDebugEnabled()) { - log.debug("test dir = " + getRelativePathFromBasedir(testDir)); - } - - return testDir; - } - - /** - * Obtain the location of the pom file to use for next mojo test. - * <p/> - * By default, the pom file is the file with name {@code methodName+".xml"} - * in the {@code testDir}. - * - * @param testDir the location of resources for the next test (is the - * result of the method {@link #getTestDir(String, - * String)}. - * @param methodName the name of the next test - * @param goalName the name of the common goal - * @return the location of the pom file for the next mojo test. - */ - protected File getPomFile(File testDir, String methodName, String goalName) { - File pom = new File(testDir, methodName + ".xml"); - - if (isVerbose()) { - log.info("pom file = " + getRelativePathFromBasedir(pom)); - } else if (log.isDebugEnabled()) { - log.debug("pom file = " + getRelativePathFromBasedir(pom)); - } - - return pom; - } - - /** - * Create the mojo base on the given {@code pomFile} for the given {@code - * goalName}. - * - * @param pomFile the location of the pom file - * @param goalName the name of the goal to lookup - * @return the instanciated mojo - * @throws Exception if any problem while creating the mojo - */ - @SuppressWarnings("unchecked") - protected P createMojo(File pomFile, String goalName) throws Exception { - Mojo lookupMojo = TestHelper.lookupMojo(goalName, pomFile); - P result = (P) lookupMojo; - return result; - } - - /** - * Initialize the given mojo. - * - * @param mojo the instanciate mojo - * @param pomFile the pom file used to instanciate the mojo - * @throws Exception if any pb - */ - protected void setUpMojo(P mojo, File pomFile) throws Exception { - - MavenProject project = mojo.getProject(); - if (project == null) { - - log.debug("init maven project"); - MavenProjectBuilder projectBuilder = (MavenProjectBuilder) - TestHelper.getDelegateMojoTest().getContainer().lookup( - MavenProjectBuilder.ROLE - ); - ProjectBuilderConfiguration projectBuilderConfiguration = - new DefaultProjectBuilderConfiguration(); - project = projectBuilder.build(pomFile, projectBuilderConfiguration); - -// project = new MavenProject(); - - mojo.setProject(project); - } - - mojo.getProject().setFile(pomFile); - } - - protected P getMojo() { - return name.getMojo(); - } - - protected String getMethodName() { - return name.getMethodName(); - } - - protected File getPomFile() { - return name.getPomFile(); - } - - protected File getTestDir() { - return name.getTestDir(); - } - - protected boolean isVerbose() { - return TestHelper.isVerbose(); - } - - protected void clearMojo(P mojo) { - - // by default do nothing - } - - /** - * Checks on the given {@code file} that : - * <ul> - * <li>file exists</li> - * <li>the given {@code pattern} exists {@code required = true} - * (or not {@code required = false}) in the content of the file.</li> - * </ul> - * - * @param file the file to test - * @param pattern the pattern to search - * @param encoding encoding of the file to read - * @param required flag to says if pattern should (or not) be found in - * file's content - * @throws IOException if could not read file - */ - public void checkExistsPattern(File file, - String pattern, - String encoding, - boolean required) throws IOException { - - // checks file exists - assertTrue("File '" + file + "' does not exist, but should...", - file.exists() - ); - - //obtain file content as a string - String content = PluginHelper.readAsString(file, encoding); - - checkPattern(file, content, pattern, required); - } - - public void checkPattern(File file, - String content, - String pattern, - boolean required) throws IOException { - - String errorMessage = required ? "could not find the pattern : " : - "should not have found pattern :"; - - // checks pattern found (or not) in file's content - assertEquals(errorMessage + pattern + " in '" + file + "'", - required, - content.contains(pattern) - ); - } - - /** - * To offer inside each test method (annotated by a {@link Test}) the - * following properties : - * <p/> - * <ul> <li>{@link #testDir} : location where to find resources for the - * test</li> <li>{@link #pomFile} : location of the pom file to use to build - * the mojo</li> <li>{@link #mojo} : the instanciated and initialized - * mojo</li> </ul> - */ - public class MojoTestRule extends TestName { - - /** location of the pom to use */ - private File pomFile; - - /** the mojo to used in the test method (based on the {@link #pomFile}). */ - private P mojo; - - /** the directory where the resources of the test are */ - private File testDir; - - public MojoTestRule() { - if (log.isDebugEnabled()) { - log.debug("NEW MojoTest instance for " + getTestClass()); - } - } - - @Override - public void starting(Description method) { - super.starting(method); - - if (isVerbose()) { - log.info("=============================================================================================="); - } - String methodName = name.getMethodName(); - - log.info("NEW Mojo test starting : " + getTestClass().getName() + - "#" + methodName); - - String goalName = getGoalName(methodName); - - testDir = getTest().getTestDir(methodName, goalName); - - pomFile = getTest().getPomFile(testDir, methodName, goalName); - - try { - Assert.assertTrue("could not find pom " + - pomFile.getAbsoluteFile(), pomFile.exists()); - - mojo = createMojo(pomFile, goalName); - - getTest().setUpMojo(mojo, pomFile); - - } catch (Exception ex) { - throw new IllegalStateException( - "could not init test " + getClass() + " - " + - methodName + " for reason " + ex.getMessage(), ex); - } - } - - @Override - public void finished(Description method) { - super.finished(method); - if (mojo != null) { - clearMojo(mojo); - } - pomFile = null; - mojo = null; - testDir = null; - } - - public P getMojo() { - return mojo; - } - - public File getPomFile() { - return pomFile; - } - - public File getTestDir() { - return testDir; - } - - public AbstractMojoTest<P> getTest() { - return AbstractMojoTest.this; - } - - public Class<?> getTestClass() { - return getTest().getClass(); - } - } -} diff --git a/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/TestHelper.java b/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/TestHelper.java deleted file mode 100644 index 7e7d482..0000000 --- a/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/TestHelper.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.nuiton.plugin; - -/* - * #%L - * Helper Maven Plugin :: API - * %% - * Copyright (C) 2009 - 2012 Codelutin, Tony Chemit - * %% - * 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% - */ - -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.PlexusTestCase; -import org.junit.Assert; -import org.junit.Ignore; - -import java.io.File; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 1.0.3 - */ -public abstract class TestHelper extends PluginHelper { - - protected static boolean verbose; - protected static File basedir; - protected static DelegateMojoTestCase delegateMojoTest; - - /** - * @return the basedir for all tests - * @see PlexusTestCase#getBasedir() - */ - public static File getBasedir() { - if (basedir == null) { - String path = PlexusTestCase.getBasedir(); - basedir = new File(path); - if (verbose) { - System.out.println("basedir = " + basedir.getAbsolutePath()); - } - } - return basedir; - } - - public static void setBasedir(File basedir) { - TestHelper.basedir = basedir; - } - - public static boolean isVerbose() { - return verbose; - } - - public static void setVerbose(boolean verbose) { - TestHelper.verbose = verbose; - } - - public static File getTestDir(Class<?> type, String prefix) { - File f = new File(getBasedir(), prefix); - String rep = type.getName(); - String[] paths = rep.split("\\."); - File testDir = getFile(f, paths); - return testDir; - } - - public static Mojo lookupMojo(String goalName, File pomFile) throws Exception { - Mojo lookupMojo = getDelegateMojoTest().lookupMojo(goalName, pomFile); - Assert.assertNotNull(lookupMojo); - return lookupMojo; - - } - - public static DelegateMojoTestCase getDelegateMojoTest() throws Exception { - if (delegateMojoTest == null) { - delegateMojoTest = new DelegateMojoTestCase(); - TestHelper.delegateMojoTest.setUp(); - } - return delegateMojoTest; - } - - public static void setDelegateMojoTest(DelegateMojoTestCase delegateMojoTest) { - TestHelper.delegateMojoTest = delegateMojoTest; - } - - @Ignore - public static class DelegateMojoTestCase extends AbstractMojoTestCase { - - @Override - public Mojo lookupMojo(String goal, File pom) throws Exception { - return super.lookupMojo(goal, pom); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - } - - @Override - public PlexusContainer getContainer() { - return super.getContainer(); - } - } -} diff --git a/helper-maven-plugin-test-api/LICENSE.txt b/helper-maven-plugin-test-api/LICENSE.txt new file mode 100644 index 0000000..cca7fc2 --- /dev/null +++ b/helper-maven-plugin-test-api/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/helper-maven-plugin-test-api/README.txt b/helper-maven-plugin-test-api/README.txt new file mode 100644 index 0000000..e69de29 diff --git a/helper-maven-plugin-test-api/changelog.txt b/helper-maven-plugin-test-api/changelog.txt new file mode 100644 index 0000000..e69de29 diff --git a/helper-maven-plugin-api/pom.xml b/helper-maven-plugin-test-api/pom.xml similarity index 71% copy from helper-maven-plugin-api/pom.xml copy to helper-maven-plugin-test-api/pom.xml index 49482e6..e6228e2 100644 --- a/helper-maven-plugin-api/pom.xml +++ b/helper-maven-plugin-test-api/pom.xml @@ -30,9 +30,9 @@ <version>2.2-SNAPSHOT</version> </parent> - <artifactId>helper-maven-plugin-api</artifactId> - <name>Helper Maven Plugin :: API</name> - <description>Simple maven mojo api for our projects</description> + <artifactId>helper-maven-plugin-test-api</artifactId> + <name>Helper Maven Plugin :: Test Api</name> + <description>Simple maven mojo test api for our projects</description> <properties> @@ -48,57 +48,62 @@ <!-- compile dependencies --> <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> + <groupId>${project.groupId}</groupId> + <artifactId>helper-maven-plugin-api</artifactId> + <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-dependency-tree</artifactId> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> </dependency> - <dependency> - <groupId>velocity</groupId> - <artifactId>velocity</artifactId> - </dependency> + <!-- provided dependencies --> <dependency> <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-utils</artifactId> + <artifactId>plexus-container-default</artifactId> </dependency> - <!-- provided dependencies --> - <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-container-default</artifactId> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> - <version>${mavenVersion}</version> + <artifactId>maven-compat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-model</artifactId> - <version>${mavenVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-artifact</artifactId> - <version>${mavenVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> - <version>${mavenVersion}</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-api</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-aether-provider</artifactId> <scope>provided</scope> </dependency> @@ -107,7 +112,7 @@ <dependency> <groupId>org.apache.maven.plugin-testing</groupId> <artifactId>maven-plugin-testing-harness</artifactId> - <scope>test</scope> + <scope>compile</scope> <exclusions> <exclusion> @@ -141,46 +146,13 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> + <scope>compile</scope> </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <scope>test</scope> - </dependency> - - </dependencies> <build> - <testResources> - <testResource> - <directory>${project.basedir}/src/test/resources</directory> - <includes> - <include>**/*</include> - </includes> - <excludes> - <exclude>**/*~</exclude> - </excludes> - </testResource> - </testResources> - - <plugins> - - <plugin> - <artifactId>maven-jar-plugin</artifactId> - <executions> - <execution> - <id>attach-test</id> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> <profiles> @@ -234,52 +206,6 @@ </reporting> </profile> - <!-- to deploy snapshot or release without anything else --> - <profile> - <id>release-profile</id> - <activation> - <property> - <name>performRelease</name> - <value>true</value> - </property> - </activation> - - <build> - <plugins> - - <!-- always compute source jar --> - <plugin> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <id>attach-sources</id> - <goals> - <goal>jar</goal> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - - <!-- always compute javadoc jar --> - <plugin> - <artifactId>maven-javadoc-plugin</artifactId> - <executions> - <execution> - <id>attach-javadocs</id> - <goals> - <goal>jar</goal> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - </build> - - </profile> - <!-- prepare the assembly at release time --> <profile> <id>release-assembly-profile</id> diff --git a/helper-maven-plugin-test-api/src/license/THIRD-PARTY.properties b/helper-maven-plugin-test-api/src/license/THIRD-PARTY.properties new file mode 100644 index 0000000..2e0940b --- /dev/null +++ b/helper-maven-plugin-test-api/src/license/THIRD-PARTY.properties @@ -0,0 +1,32 @@ +# Generated by org.codehaus.mojo.license.AddThirdPartyMojo +#------------------------------------------------------------------------------- +# Already used licenses in project : +# - Apache License +# - BSD License +# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +# - Common Public License Version 1.0 +# - Eclipse Public License, Version 1.0 +# - Indiana University Extreme! Lab Software License, vesion 1.1.1 +# - Lesser General Public License (LPGL) +# - Lesser General Public License (LPGL) v 2.1 +# - MIT License +# - New BSD License +# - Public Domain +# - The Apache Software License, Version 2.0 +# - http://classworlds.codehaus.org/license.html +#------------------------------------------------------------------------------- +# Please fill the missing licenses for dependencies : +# +# +#Sun Oct 26 13:40:44 CET 2014 +classworlds--classworlds--1.1-alpha-2=http\://classworlds.codehaus.org/license.html +commons-codec--commons-codec--1.2=The Apache Software License, Version 2.0 +commons-collections--commons-collections--3.1=The Apache Software License, Version 2.0 +nekohtml--xercesMinimal--1.9.6.2=The Apache Software License, Version 2.0 +org.codehaus.plexus--plexus-container-default--1.0-alpha-9-stable-1=The Apache Software License, Version 2.0 +org.codehaus.plexus--plexus-interactivity-api--1.0-alpha-4=The Apache Software License, Version 2.0 +org.slf4j--jcl-over-slf4j--1.5.6=The Apache Software License, Version 2.0 +org.slf4j--slf4j-api--1.5.6=The Apache Software License, Version 2.0 +org.slf4j--slf4j-jdk14--1.5.6=The Apache Software License, Version 2.0 +org.slf4j--slf4j-nop--1.5.3=The Apache Software License, Version 2.0 +oro--oro--2.0.8=The Apache Software License, Version 2.0 diff --git a/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/MojoTestRule.java b/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/MojoTestRule.java new file mode 100644 index 0000000..a014b09 --- /dev/null +++ b/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/MojoTestRule.java @@ -0,0 +1,222 @@ +package org.nuiton.plugin; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.maven.plugin.testing.MojoRule; +import org.apache.maven.project.DefaultProjectBuildingRequest; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuilder; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.project.ProjectBuildingResult; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.beans.Introspector; +import java.io.File; + +/** + * To offer inside each test method (annotated by a {@link Test}) the + * following properties : + * <p/> + * <ul> <li>{@link #testDirectory} : location where to find resources for the + * test</li> <li>{@link #pomFile} : location of the pom file to use to build + * the mojo</li> <li>{@link #mojo} : the instanciated and initialized + * mojo</li> </ul> + */ +public abstract class MojoTestRule<P extends Plugin> extends MojoRule { + + /** Logger. */ + private static final Log log = LogFactory.getLog(MojoTestRule.class); + + /** + * Directory where the resources for the current test. + */ + private File testDirectory; + + /** + * Method name of the current test. + */ + private String testMethodName; + + /** + * Pom file of the current test. + */ + private File pomFile; + + /** + * Mojo to used in the current test method. + */ + private P mojo; + + /** + * Class of the test. + */ + private final Class<?> testClass; + + protected MojoTestRule(Class<?> testClass) { + this.testClass = testClass; + } + + protected abstract String getGoalName(String methodName); + + @Override + public Statement apply(final Statement base, Description description) { + + testMethodName = description.getMethodName(); + + return super.apply(base, description); + + } + + @SuppressWarnings("unchecked") + protected P createMojo(File pomFile, String goalName) throws Exception { + P result = (P) lookupMojo(goalName, pomFile); + return result; + } + + /** + * Initialize the given mojo. + * + * @param mojo the instanciate mojo + * @param pomFile the pom file used to instanciate the mojo + * @throws Exception if any pb + */ + protected void setUpMojo(P mojo, File pomFile) throws Exception { + + MavenProject project = mojo.getProject(); + if (project == null) { + + log.debug("init maven project"); + ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); + ProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest(); + projectBuildingRequest.setRepositorySession(new DefaultRepositorySystemSession()); + ProjectBuildingResult projectBuildingResult = projectBuilder.build(pomFile, projectBuildingRequest); + project = projectBuildingResult.getProject(); + + mojo.setProject(project); + } + + mojo.getProject().setFile(pomFile); + + } + + protected void tearDownMojo(P mojo) { + + // by default nothing to clear + + } + + @Override + protected void before() throws Throwable { + + if (TestHelper.isVerbose()) { + log.info("=============================================================================================="); + } + + log.info("Starting test: " + testClass.getName() + "#" + testMethodName); + + String goalName = getGoalName(testMethodName); + + testDirectory = getTestDir(testMethodName, goalName); + + pomFile = getPomFile(testDirectory, testMethodName, goalName); + + try { + + Assert.assertTrue("could not find pom " + pomFile.getAbsoluteFile(), pomFile.exists()); + + mojo = createMojo(pomFile, goalName); + + setUpMojo(mojo, pomFile); + + } catch (Exception ex) { + + throw new IllegalStateException("could not init test " + testClass + "#" + testMethodName, ex); + + } + + } + + @Override + protected void after() { + + if (mojo != null) { + tearDownMojo(mojo); + } + pomFile = null; + mojo = null; + testDirectory = null; + + } + + public P getMojo() { + return mojo; + } + + public File getPomFile() { + return pomFile; + } + + public File getTestDirectory() { + return testDirectory; + } + + /** + * Obtain the location of the directory where to find resources for the next test. + * + * By convention, will be the package named by the test class name from the + * {@link TestHelper#getTestBasedir()}. + * + * @param methodName the method of the next test to execute + * @param goalName the common goal name to use + * @return the directory where to find resources for the test + */ + protected File getTestDir(String methodName, String goalName) { + + //TC-20091101 use a decipatilize simple name to avoid conflict of package with existing class name. + String rep = getClass().getPackage().getName() + "." + Introspector.decapitalize(testClass.getSimpleName()); + String[] paths = rep.split("\\."); + File directory = TestHelper.getFile(TestHelper.getTestBasedir(), paths); + if (TestHelper.isVerbose()) { + log.info("test dir = " + getRelativePathFromBasedir(directory)); + } else if (log.isDebugEnabled()) { + log.debug("test dir = " + getRelativePathFromBasedir(directory)); + } + + return directory; + } + + /** + * Obtain the location of the pom file to use for next mojo test. + * <p/> + * By default, the pom file is the file with name {@code methodName+".xml"} + * in the {@code testDir}. + * + * @param testDir the location of resources for the next test (is the + * result of the method {@link #getTestDir(String, + * String)}. + * @param methodName the name of the next test + * @param goalName the name of the common goal + * @return the location of the pom file for the next mojo test. + */ + protected File getPomFile(File testDir, String methodName, String goalName) { + + File pom = new File(testDir, methodName + ".xml"); + + if (TestHelper.isVerbose()) { + log.info("pom file = " + getRelativePathFromBasedir(pom)); + } else if (log.isDebugEnabled()) { + log.debug("pom file = " + getRelativePathFromBasedir(pom)); + } + + return pom; + } + + public String getRelativePathFromBasedir(File f) { + return TestHelper.getRelativePath(TestHelper.getBasedir(), f); + } + +} diff --git a/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/TestHelper.java b/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/TestHelper.java new file mode 100644 index 0000000..8151a50 --- /dev/null +++ b/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/TestHelper.java @@ -0,0 +1,117 @@ +package org.nuiton.plugin; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codehaus.plexus.PlexusTestCase; +import org.junit.Assert; + +import java.io.File; +import java.io.IOException; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 1.0.3 + */ +public abstract class TestHelper extends PluginHelper { + + /** Logger. */ + private static final Log log = LogFactory.getLog(TestHelper.class); + + protected static boolean verbose; + + protected static File basedir; + + protected static File testBasedir; + + public static File getTestBasedir() { + if (testBasedir == null) { + testBasedir = TestHelper.getFile(getBasedir(), "target", "test-classes"); + if (log.isDebugEnabled()) { + log.debug("testBasedir = " + testBasedir); + } + } + return testBasedir; + } + + /** + * @return the basedir for all tests + * @see PlexusTestCase#getBasedir() + */ + public static File getBasedir() { + if (basedir == null) { + String path = PlexusTestCase.getBasedir(); + basedir = new File(path); + if (verbose) { + System.out.println("basedir = " + basedir.getAbsolutePath()); + } + } + return basedir; + } + + public static void setBasedir(File basedir) { + TestHelper.basedir = basedir; + } + + public static boolean isVerbose() { + return verbose; + } + + public static void setVerbose(boolean verbose) { + TestHelper.verbose = verbose; + } + + public static File getTestDir(Class<?> type, String prefix) { + File f = new File(getBasedir(), prefix); + String rep = type.getName(); + String[] paths = rep.split("\\."); + File testDir = PluginHelper.getFile(f, paths); + return testDir; + } + + /** + * Checks on the given {@code file} that : + * <ul> + * <li>file exists</li> + * <li>the given {@code pattern} exists {@code required = true} + * (or not {@code required = false}) in the content of the file.</li> + * </ul> + * + * @param file the file to test + * @param pattern the pattern to search + * @param encoding encoding of the file to read + * @param required flag to says if pattern should (or not) be found in + * file's content + * @throws IOException if could not read file + */ + public static void checkExistsPattern(File file, + String pattern, + String encoding, + boolean required) throws IOException { + + // checks file exists + Assert.assertTrue("File '" + file + "' does not exist, but should...", + file.exists() + ); + + //obtain file content as a string + String content = PluginHelper.readAsString(file, encoding); + + checkPattern(file, content, pattern, required); + } + + public static void checkPattern(File file, + String content, + String pattern, + boolean required) throws IOException { + + String errorMessage = required ? "could not find the pattern : " : + "should not have found pattern :"; + + // checks pattern found (or not) in file's content + Assert.assertEquals(errorMessage + pattern + " in '" + file + "'", + required, + content.contains(pattern) + ); + } + +} diff --git a/helper-maven-plugin-test-api/src/site/apt/index.apt b/helper-maven-plugin-test-api/src/site/apt/index.apt new file mode 100644 index 0000000..cdb688d --- /dev/null +++ b/helper-maven-plugin-test-api/src/site/apt/index.apt @@ -0,0 +1,17 @@ + +---- +Introduction +---- +---- +2012-11-10 +---- + +Maven helper Plugin Test API + + This modules offers a test toolkit : usefull classes to make new tests (see {Test toolkit overview}) + +Test toolkit overview + + see the {{{./mojo-testFramework.html}Mojo test framework}} page. + + see {{{./testapidocs/index.html}test-javadoc}}. diff --git a/helper-maven-plugin-api/src/site/apt/mojo-testFramework.apt b/helper-maven-plugin-test-api/src/site/apt/mojo-testFramework.apt similarity index 86% rename from helper-maven-plugin-api/src/site/apt/mojo-testFramework.apt rename to helper-maven-plugin-test-api/src/site/apt/mojo-testFramework.apt index d4303e2..32757d7 100644 --- a/helper-maven-plugin-api/src/site/apt/mojo-testFramework.apt +++ b/helper-maven-plugin-test-api/src/site/apt/mojo-testFramework.apt @@ -1,24 +1,4 @@ -~~~ -~~ #%L -~~ Helper Maven Plugin :: API -~~ %% -~~ Copyright (C) 2009 - 2012 Codelutin, Tony Chemit -~~ %% -~~ 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% -~~~ + ---- Mojo Test framework ---- diff --git a/helper-maven-plugin-test-api/src/site/site.xml b/helper-maven-plugin-test-api/src/site/site.xml new file mode 100644 index 0000000..8a24ae9 --- /dev/null +++ b/helper-maven-plugin-test-api/src/site/site.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<project name="${project.name}" xmlns="http://maven.apache.org/DECORATION/1.4.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 http://maven.apache.org/xsd/decoration-1.4.0.xsd"> + + <bannerLeft> + <name>${project.name}</name> + <href>index.html</href> + </bannerLeft> + + <body> + + <breadcrumbs> + <item name="${project.name}" href="index.html"/> + </breadcrumbs> + + <menu ref="parent"/> + + <menu name="User"> + <item name="Introduction" href="index.html"/> + </menu> + + <menu name="Developer"> + <item name="Mojo test framework" href="mojo-testFramework.html"/> + </menu> + + <menu ref="reports"/> + + </body> +</project> diff --git a/helper-maven-plugin/pom.xml b/helper-maven-plugin/pom.xml index e31004c..011c93c 100644 --- a/helper-maven-plugin/pom.xml +++ b/helper-maven-plugin/pom.xml @@ -72,17 +72,16 @@ <artifactId>plexus-sec-dispatcher</artifactId> </dependency> - <dependency> + <!--dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-container-default</artifactId> - </dependency> + </dependency--> <dependency> <groupId>plexus</groupId> <artifactId>plexus-mail-sender-api</artifactId> </dependency> - <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> @@ -102,52 +101,60 @@ <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> + <artifactId>maven-core</artifactId> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-model</artifactId> + <artifactId>maven-compat</artifactId> + </dependency> + + <dependency> + <groupId>org.eclipse.sisu</groupId> + <artifactId>org.eclipse.sisu.plexus</artifactId> + <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-settings</artifactId> + <artifactId>maven-model</artifactId> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-artifact</artifactId> + <artifactId>maven-settings</artifactId> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-artifact-manager</artifactId> + <artifactId>maven-artifact</artifactId> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> + <scope>compile</scope> </dependency> <!-- tests dependencies --> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>helper-maven-plugin-api</artifactId> + <artifactId>helper-maven-plugin-test-api</artifactId> <version>${project.version}</version> - <classifier>tests</classifier> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.maven.plugin-testing</groupId> <artifactId>maven-plugin-testing-harness</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> + <scope>test</scope> </dependency> <dependency> diff --git a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java index 5e46d8b..ead8638 100644 --- a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java +++ b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java @@ -26,70 +26,79 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; import org.junit.Assume; +import org.junit.Rule; import org.junit.Test; import org.nuiton.helper.io.mail.MailSender; -import org.nuiton.plugin.AbstractMojoTest; +import org.nuiton.plugin.MojoTestRule; import java.io.File; -import java.util.Arrays; +import java.util.Collections; /** * @author tchemit <chemit@codelutin.com> * @since 1.0.0 */ -public class SendEmailMojoTest extends AbstractMojoTest<SendEmailMojo> { +public class SendEmailMojoTest { /** Logger. */ private static final Log log = LogFactory.getLog(SendEmailMojoTest.class); - protected boolean canContinue; + @Rule + public MojoTestRule<SendEmailMojo> rule = new MojoTestRule<SendEmailMojo>(SendEmailMojoTest.class) { - @Override - protected String getGoalName(String methodName) { - return "send-email"; - } + @Override + protected String getGoalName(String methodName) { + return "send-email"; + } - @Override - protected void setUpMojo(SendEmailMojo mojo, File pomFile) throws Exception { - super.setUpMojo(mojo, pomFile); + @Override + protected void setUpMojo(SendEmailMojo mojo, File pomFile) throws Exception { - // add a mailSender here - MailSender sender = new MailSender(); - sender.setName("Nuiton Release Notification"); - sender.setEmail("test@noway.fr"); - mojo.setMailSender(sender); + super.setUpMojo(mojo, pomFile); - // add a destination - mojo.setToAddresses(Arrays.asList("chemit@codelutin.com")); + // add a mailSender here + MailSender sender = new MailSender(); + sender.setName("Nuiton Release Notification"); + sender.setEmail("test@noway.fr"); + mojo.setMailSender(sender); - try { - mojo.init(); - canContinue = true; - } catch (Exception e) { - canContinue = false; - } -// canContinue = mojo.init(); - if (canContinue) { - if (mojo.isVerbose()) { - log.info("setup done for " + mojo.getProject().getFile().getName()); + // add a destination + mojo.setToAddresses(Collections.singletonList("chemit@codelutin.com")); + + try { + mojo.init(); + canContinue = true; + } catch (Exception e) { + canContinue = false; + } + + if (canContinue) { + if (mojo.isVerbose()) { + log.info("setup done for " + mojo.getProject().getFile().getName()); + } + } else { + log.error("setup was not successfull, will skip this test [" + getClass() + "]"); } - } else { - log.error("setup was not successfull, will skip this test [" + getClass() + "]"); + } - } + + }; + + protected boolean canContinue; @Test public void sendEmail() throws Exception { Assume.assumeTrue(canContinue); - Assert.assertNotNull(getMojo()); - getMojo().doAction(); + Assert.assertNotNull(rule.getMojo()); + rule.getMojo().doAction(); } @Test public void skipSendEmail() throws Exception { Assume.assumeTrue(canContinue); - Assert.assertNotNull(getMojo()); - getMojo().execute(); + Assert.assertNotNull(rule.getMojo()); + rule.getMojo().execute(); } + } diff --git a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/TransformProjectVersionMojoTest.java b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/TransformProjectVersionMojoTest.java index 3c3498f..2b9362e 100644 --- a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/TransformProjectVersionMojoTest.java +++ b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/TransformProjectVersionMojoTest.java @@ -25,8 +25,9 @@ package org.nuiton.helper.plugin; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.plugin.AbstractMojoTest; +import org.nuiton.plugin.MojoTestRule; import java.io.File; import java.util.Properties; @@ -35,42 +36,47 @@ import java.util.Properties; * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class TransformProjectVersionMojoTest extends AbstractMojoTest<TransformProjectVersionMojo> { +public class TransformProjectVersionMojoTest { /** Logger. */ - private static final Log log = - LogFactory.getLog(TransformProjectVersionMojoTest.class); + private static final Log log = LogFactory.getLog(TransformProjectVersionMojoTest.class); protected boolean canContinue; - @Override - protected String getGoalName(String methodName) { - return "transform-project-version"; - } + @Rule + public MojoTestRule<TransformProjectVersionMojo> rule = new MojoTestRule<TransformProjectVersionMojo>(TransformProjectVersionMojoTest.class) { + + @Override + protected String getGoalName(String methodName) { + return "transform-project-version"; + } - @Override - protected void setUpMojo(TransformProjectVersionMojo mojo, File pomFile) throws Exception { - super.setUpMojo(mojo, pomFile); + @Override + protected void setUpMojo(TransformProjectVersionMojo mojo, File pomFile) throws Exception { - try { - mojo.init(); - canContinue = true; - } catch (Exception e) { + super.setUpMojo(mojo, pomFile); - canContinue = false; + try { + mojo.init(); + canContinue = true; + } catch (Exception e) { - if (log.isDebugEnabled()) { - log.debug("Could not init mojo ", e); + canContinue = false; + + if (log.isDebugEnabled()) { + log.debug("Could not init mojo ", e); + } } + } - } + }; @Test public void simple() throws Exception { Assert.assertTrue(canContinue); - Assert.assertNotNull(getMojo()); - getMojo().doAction(); + Assert.assertNotNull(rule.getMojo()); + rule.getMojo().doAction(); assertNewVersion("newVersion", "1.0-rev-1"); } @@ -79,8 +85,8 @@ public class TransformProjectVersionMojoTest extends AbstractMojoTest<TransformP public void keepSnapshot() throws Exception { Assert.assertTrue(canContinue); - Assert.assertNotNull(getMojo()); - getMojo().doAction(); + Assert.assertNotNull(rule.getMojo()); + rule.getMojo().doAction(); assertNewVersion("newVersion", "2.0-rev-2-SNAPSHOT"); } @@ -89,8 +95,8 @@ public class TransformProjectVersionMojoTest extends AbstractMojoTest<TransformP public void removeSnapshot() throws Exception { Assert.assertTrue(canContinue); - Assert.assertNotNull(getMojo()); - getMojo().doAction(); + Assert.assertNotNull(rule.getMojo()); + rule.getMojo().doAction(); assertNewVersion("newVersion", "2.0-rev-2"); } @@ -116,7 +122,7 @@ public class TransformProjectVersionMojoTest extends AbstractMojoTest<TransformP protected void assertNewVersion(String versionKey, String expectedNewVersion) { - Properties properties = getMojo().getProject().getProperties(); + Properties properties = rule.getMojo().getProject().getProperties(); Object newVersion = properties.get(versionKey); Assert.assertNotNull(newVersion); Assert.assertEquals(expectedNewVersion, newVersion); diff --git a/helper-maven-plugin/src/test/resources/log4j.properties b/helper-maven-plugin/src/test/resources/log4j.properties new file mode 100644 index 0000000..e366d88 --- /dev/null +++ b/helper-maven-plugin/src/test/resources/log4j.properties @@ -0,0 +1,32 @@ +### +# #%L +# Helper Maven Plugin :: API +# %% +# Copyright (C) 2009 - 2012 Codelutin, Tony Chemit +# %% +# 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% +### +# Global logging configuration +log4j.rootLogger=ERROR, stdout +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%p] (%F:%L) %M - %m%n +#log4j.appender.stdout.layout.ConversionPattern=[%p] [%t] (%F:%L) %M - %m%n + +# package level +log4j.logger.org.nuiton=INFO + diff --git a/pom.xml b/pom.xml index 0c4a9f3..bd10b94 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>nuitonpom</artifactId> - <version>1.5</version> + <version>2.1</version> </parent> <artifactId>helper-maven-plugin-parent</artifactId> @@ -42,6 +42,7 @@ <modules> <module>helper-maven-plugin-api</module> + <module>helper-maven-plugin-test-api</module> <module>helper-maven-plugin</module> </modules> @@ -97,7 +98,15 @@ <!-- documentation is in apt --> <siteSourcesType>apt</siteSourcesType> - <mavenVersion>2.2.1</mavenVersion> + <mavenVersion>3.3.3</mavenVersion> + + <javaVersion>1.7</javaVersion> + <!--TODO remove this when idea won't ask to change jdk level at each pom modification--> + <maven.compiler.source>${javaVersion}</maven.compiler.source> + <!--TODO remove this when idea won't ask to change jdk level at each pom modification--> + <maven.compiler.target>${javaVersion}</maven.compiler.target> + <signatureArtifactId>java17</signatureArtifactId> + <signatureVersion>1.0</signatureVersion> </properties> @@ -113,19 +122,19 @@ <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> - <version>3.3.2</version> + <version>3.4</version> </dependency> <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-dependency-tree</artifactId> - <version>2.1</version> + <version>2.2</version> </dependency> <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> - <version>3.0.14</version> + <version>3.0.22</version> </dependency> <dependency> @@ -157,7 +166,7 @@ <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> + <artifactId>maven-core</artifactId> <version>${mavenVersion}</version> <scope>provided</scope> </dependency> @@ -185,7 +194,7 @@ <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-artifact-manager</artifactId> + <artifactId>maven-compat</artifactId> <version>${mavenVersion}</version> <scope>provided</scope> </dependency> @@ -197,6 +206,26 @@ <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-aether-provider</artifactId> + <version>${mavenVersion}</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-api</artifactId> + <version>1.0.2.v20150114</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.eclipse.sisu</groupId> + <artifactId>org.eclipse.sisu.plexus</artifactId> + <version>0.3.0</version> + </dependency> + <!-- dependencies to mojo annotations --> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> @@ -223,8 +252,7 @@ <dependency> <groupId>org.apache.maven.plugin-testing</groupId> <artifactId>maven-plugin-testing-harness</artifactId> - <version>1.3</version> - <!--<version>2.1</version>--> + <version>3.3.0</version> <scope>test</scope> </dependency> @@ -237,7 +265,7 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.11</version> + <version>4.12</version> <scope>test</scope> </dependency> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.