Skip to content

Commit 47fb312

Browse files
committed
WIP: Add a mojo for dumping version property values
This mojo is intended to replace sj-version.sh from scijava-scripts.
1 parent 0aa6c09 commit 47fb312

5 files changed

Lines changed: 178 additions & 0 deletions

File tree

‎pom.xml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@
100100
<artifactId>plexus-interpolation</artifactId>
101101
<version>1.14</version>
102102
</dependency>
103+
104+
<!-- Test scope dependencies -->
105+
<dependency>
106+
<groupId>junit</groupId>
107+
<artifactId>junit</artifactId>
108+
<scope>test</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.apache.maven.plugin-testing</groupId>
112+
<artifactId>maven-plugin-testing-harness</artifactId>
113+
<version>3.1.0</version>
114+
<scope>test</scope>
115+
</dependency>
103116
</dependencies>
104117

105118
<build>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* #%L
3+
* A plugin for managing SciJava-based projects.
4+
* %%
5+
* Copyright (C) 2014 Board of Regents of the University of
6+
* Wisconsin-Madison.
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
31+
package org.scijava.maven.plugin;
32+
33+
import org.apache.maven.plugin.AbstractMojo;
34+
import org.apache.maven.plugin.MojoExecutionException;
35+
import org.apache.maven.project.MavenProject;
36+
37+
/**
38+
* Lists the project's version property values.
39+
*
40+
* @author Curtis Rueden
41+
*
42+
* @goal versions
43+
* @phase validate
44+
* @requiresProject false
45+
*/
46+
public class VersionPropertiesMojo extends AbstractMojo {
47+
48+
/**
49+
* The name of the organization whose parent POM should be processed.
50+
*
51+
* @parameter expression="${parentOrg}"
52+
* default-value="scijava"
53+
*/
54+
private String parentOrg;
55+
56+
/**
57+
* @parameter expression="${project}"
58+
* @required
59+
* @readonly
60+
*/
61+
private MavenProject currentProject;
62+
63+
@Override
64+
public void execute() throws MojoExecutionException {
65+
getLog().info("parentOrg = " + parentOrg);
66+
getLog().info("project = " + currentProject);
67+
for (final Object key : currentProject.getProperties().keySet()) {
68+
final Object value = currentProject.getProperties().get(key);
69+
getLog().info(key + " = " + value);
70+
}
71+
}
72+
73+
}

‎src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<pluginExecutionFilter>
55
<goals>
66
<goal>set-rootdir</goal>
7+
<goal>versions</goal>
78
</goals>
89
</pluginExecutionFilter>
910
<action>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* #%L
3+
* A plugin for managing SciJava-based projects.
4+
* %%
5+
* Copyright (C) 2014 Board of Regents of the University of
6+
* Wisconsin-Madison.
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
31+
package org.scijava.maven.plugin;
32+
33+
import java.io.File;
34+
35+
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
36+
import org.junit.Test;
37+
38+
/**
39+
* Tests {@link VersionPropertiesMojo}.
40+
*
41+
* @author Curtis Rueden
42+
*/
43+
public class VersionPropertiesMojoTest extends AbstractMojoTestCase {
44+
45+
@Test
46+
public void testSomething() throws Exception {
47+
final File pom =
48+
getTestFile("src/test/resources/versions/pom.xml");
49+
assertNotNull(pom);
50+
assertTrue(pom.exists());
51+
52+
final VersionPropertiesMojo myMojo =
53+
(VersionPropertiesMojo) lookupMojo("versions", pom);
54+
assertNotNull(myMojo);
55+
myMojo.execute();
56+
57+
// ...
58+
}
59+
60+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.scijava</groupId>
7+
<artifactId>pom-scijava</artifactId>
8+
<version>2.0</version>
9+
</parent>
10+
11+
<artifactId>versions-test</artifactId>
12+
<version>0.1.0-SNAPSHOT</version>
13+
14+
<name>Test VersionPropertiesMojo</name>
15+
16+
<properties>
17+
<foo.version>bar</foo.version>
18+
</properties>
19+
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<artifactId>scijava-maven-plugin</artifactId>
24+
<configuration>
25+
<parentOrg>scijava</parentOrg>
26+
</configuration>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
31+
</project>

0 commit comments

Comments
 (0)