mirror of
https://github.com/Alfresco/alfresco-sdk.git
synced 2025-08-07 17:49:34 +00:00
-- added testing with maven-plugin-test-harness
git-svn-id: http://maven-alfresco-archetypes.googlecode.com/svn/trunk@157 04253f4f-3451-0410-a141-5562f1e59037
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.sourcesense.maven</groupId>
|
||||
<artifactId>maven-nosnapshot-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
<version>0.0.4-SNAPSHOT</version>
|
||||
<name>maven-nosnapshot-plugin Maven Mojo</name>
|
||||
<name>Custom version manipulator Maven Plugin. It's non invasive and puts modified versions in configurable pom properties</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<scm>
|
||||
<developerConnection>scm:svn:https://maven-alfresco-archetypes.googlecode.com/svn/trunk/plugins/maven-nosnapshot-plugin</developerConnection>
|
||||
@@ -27,9 +28,22 @@
|
||||
<artifactId>maven-project</artifactId>
|
||||
<version>2.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>maven-plugin-testing-harness</artifactId>
|
||||
<version>1.0-beta-1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
|
@@ -1,65 +0,0 @@
|
||||
package com.sourcesense.maven;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Goal which pushes a stripped version number in the maven project properties (any -SNAPSHOT suffix is removed)
|
||||
*
|
||||
* @goal strip
|
||||
* @phase initialize
|
||||
*
|
||||
*/
|
||||
public class NoSnapshotVersionMojo
|
||||
extends AbstractMojo
|
||||
{
|
||||
/**
|
||||
* Current version of the project
|
||||
* @parameter expression="${project.version}"
|
||||
* @required
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* The Maven project
|
||||
* @parameter expression="${project}"
|
||||
* @required
|
||||
*/
|
||||
private MavenProject project;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
int indexOfDash = version.indexOf("-");
|
||||
|
||||
String noSnapshotVersion = version;
|
||||
if(Pattern.matches("[a-zA-Z]", version))
|
||||
{
|
||||
noSnapshotVersion = version.substring(0, indexOfDash);
|
||||
}
|
||||
getLog().info(
|
||||
MessageFormat.format( "Storing noSnapshotVersion: {0} ", new Object[] {
|
||||
noSnapshotVersion} ) );
|
||||
project.getProperties().put("noSnapshotVersion", noSnapshotVersion);
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
package com.sourcesense.maven;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Goal which pushes a stripped version number in the maven project properties,
|
||||
* removing the suffix after the configured separator into the project variable
|
||||
* noSnapshotVersion
|
||||
*
|
||||
* @goal strip
|
||||
* @phase initialize
|
||||
*
|
||||
*/
|
||||
public class StripMojo extends AbstractMojo {
|
||||
private static final String RESULT_PROPERTY_NAME = "noSnapshotVersion";
|
||||
|
||||
/**
|
||||
* Current version of the project
|
||||
*
|
||||
* @parameter expression="${project.version}" default-value="3.0.0-SNAPSHOT"
|
||||
* @required
|
||||
*/
|
||||
private String version;
|
||||
|
||||
public MavenProject getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Maven project
|
||||
*
|
||||
* @parameter expression="${project}"
|
||||
* @required
|
||||
*/
|
||||
private MavenProject project;
|
||||
|
||||
/**
|
||||
* The separator used to identify and strip the suffix
|
||||
*
|
||||
* @parameter expression="${separator}" default-value="-"
|
||||
* @required
|
||||
*/
|
||||
private String separator;
|
||||
|
||||
/**
|
||||
* The Maven Projec property the stripped version is pushed into
|
||||
*
|
||||
* @parameter expression="${propertyName}" default-value="noSnapshotVersion"
|
||||
* @required
|
||||
*/
|
||||
private String propertyName;
|
||||
|
||||
|
||||
public void execute() throws MojoExecutionException {
|
||||
int separatorIndex = version.indexOf(separator);
|
||||
String noSnapshotVersion = version;
|
||||
if (separatorIndex > -1) {
|
||||
noSnapshotVersion = version.substring(0, separatorIndex);
|
||||
}
|
||||
getLog().info(
|
||||
MessageFormat.format("Storing " + propertyName
|
||||
+ ": {0} ", new Object[] { noSnapshotVersion }));
|
||||
project.getProperties().put(propertyName, noSnapshotVersion);
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setPropertyName(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public void setSeparator(String separator) {
|
||||
this.separator = separator;
|
||||
}
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
package com.sourcesense.maven.plugins.test;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import com.sourcesense.maven.StripMojo;
|
||||
|
||||
public class StripTest extends org.apache.maven.plugin.testing.AbstractMojoTestCase {
|
||||
|
||||
File testPom;
|
||||
MavenProject project = new MavenProject();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
// required for mojo lookups to work
|
||||
super.setUp();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* tests the proper discovery and configuration of the mojo
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testMojoDefaultEnvironment() throws Exception {
|
||||
testPom = new File( getBasedir(), "target/test-classes/snapshot-pom.xml" );
|
||||
StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
|
||||
assertNotNull( mojo );
|
||||
|
||||
}
|
||||
|
||||
public void testSnapshotVersion() throws Exception {
|
||||
testPom = new File( getBasedir(), "target/test-classes/snapshot-pom.xml" );
|
||||
StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
|
||||
setVariableValueToObject(mojo, "version", "3.0.0-SNAPSHOT");
|
||||
setVariableValueToObject(mojo, "project", project);
|
||||
try {
|
||||
mojo.execute();
|
||||
} catch (MojoExecutionException e) {
|
||||
fail("Mojo execution exception" + e);
|
||||
}
|
||||
assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
|
||||
mojo.getPropertyName()));
|
||||
}
|
||||
|
||||
public void testReleaseCandidateVersion() throws Exception {
|
||||
testPom = new File( getBasedir(), "target/test-classes/relcandidate-pom.xml" );
|
||||
StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
|
||||
setVariableValueToObject(mojo, "version", "3.0.0-RC1");
|
||||
setVariableValueToObject(mojo, "project", project);
|
||||
try {
|
||||
mojo.execute();
|
||||
} catch (MojoExecutionException e) {
|
||||
fail("Mojo execution exception" + e);
|
||||
}
|
||||
assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
|
||||
mojo.getPropertyName()));
|
||||
}
|
||||
|
||||
public void testIdempotent() throws Exception {
|
||||
testPom = new File( getBasedir(), "target/test-classes/snapshot-pom.xml" );
|
||||
StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
|
||||
setVariableValueToObject(mojo, "version", "3.0.0");
|
||||
setVariableValueToObject(mojo, "project", project);
|
||||
try {
|
||||
mojo.execute();
|
||||
} catch (MojoExecutionException e) {
|
||||
fail("Mojo execution exception" + e);
|
||||
}
|
||||
assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
|
||||
mojo.getPropertyName()));
|
||||
}
|
||||
|
||||
public void testUnderscore() throws Exception {
|
||||
testPom = new File( getBasedir(), "target/test-classes/underscore-pom.xml" );
|
||||
StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
|
||||
setVariableValueToObject(mojo, "version", "3.0.0_RC1");
|
||||
setVariableValueToObject(mojo, "project", project);
|
||||
try {
|
||||
mojo.execute();
|
||||
} catch (MojoExecutionException e) {
|
||||
fail("Mojo execution exception" + e);
|
||||
}
|
||||
assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
|
||||
mojo.getPropertyName()));
|
||||
}
|
||||
|
||||
public void testCustomPropName() throws Exception {
|
||||
testPom = new File( getBasedir(), "target/test-classes/customprop-pom.xml" );
|
||||
StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
|
||||
setVariableValueToObject(mojo, "version", "3.0.0-RC1");
|
||||
setVariableValueToObject(mojo, "project", project);
|
||||
try {
|
||||
mojo.execute();
|
||||
} catch (MojoExecutionException e) {
|
||||
fail("Mojo execution exception" + e);
|
||||
}
|
||||
assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
|
||||
"foobar"));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
<project>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-nosnapshot-plugin
|
||||
</artifactId>
|
||||
<configuration>
|
||||
<separator>-</separator>
|
||||
<propertyName>foobar</propertyName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
<project>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-nosnapshot-plugin
|
||||
</artifactId>
|
||||
<configuration>
|
||||
<separator>-</separator>
|
||||
<propertyName>noSnapshotVersion</propertyName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
<project>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-nosnapshot-plugin
|
||||
</artifactId>
|
||||
<configuration>
|
||||
<separator>-</separator>
|
||||
<propertyName>noSnapshotVersion</propertyName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,15 @@
|
||||
<project>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-nosnapshot-plugin</artifactId>
|
||||
<configuration>
|
||||
<separator>-</separator>
|
||||
<propertyName>noSnapshotVersion</propertyName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
<project>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-nosnapshot-plugin
|
||||
</artifactId>
|
||||
<configuration>
|
||||
<separator>_</separator>
|
||||
<propertyName>noSnapshotVersion</propertyName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
</properties>
|
||||
</project>
|
Reference in New Issue
Block a user