Skip to content

Commit 5647663

Browse files
committed
Install dependencies into subdirectories
The mojos use the scijava.app.subdirectory property to determine where an artifact should be installed. This commit adds the same functionality for dependencies. If the property is not provided by a dependency, it falls back to the old case logic. This way, older versions of e.g. Bio-Formats will be supported as well.
1 parent efc7ad1 commit 5647663

File tree

9 files changed

+271
-5
lines changed

9 files changed

+271
-5
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!--
2+
#%L
3+
ImageJ software for multidimensional image processing and analysis.
4+
%%
5+
Copyright (C) 2012 - 2016 Board of Regents of the University of
6+
Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
Institute of Molecular Cell Biology and Genetics.
8+
%%
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice,
13+
this list of conditions and the following disclaimer.
14+
2. Redistributions in binary form must reproduce the above copyright notice,
15+
this list of conditions and the following disclaimer in the documentation
16+
and/or other materials provided with the distribution.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
POSSIBILITY OF SUCH DAMAGE.
29+
#L%
30+
-->
31+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
32+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33+
<modelVersion>4.0.0</modelVersion>
34+
35+
<groupId>org.apache.maven.plugin.my.unit</groupId>
36+
<artifactId>dependency</artifactId>
37+
<version>1.0.0-SNAPSHOT</version>
38+
<packaging>jar</packaging>
39+
<name>An example artifact with a dependency to be excluded via &lt;exclusions&gt;</name>
40+
41+
<properties>
42+
<scijava.app.subdirectory>jars/Something</scijava.app.subdirectory>
43+
</properties>
44+
</project>

src/it/subdir-from-dependency/dependency/src/main/resources/empty.txt

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!--
2+
#%L
3+
ImageJ software for multidimensional image processing and analysis.
4+
%%
5+
Copyright (C) 2012 - 2016 Board of Regents of the University of
6+
Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
Institute of Molecular Cell Biology and Genetics.
8+
%%
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice,
13+
this list of conditions and the following disclaimer.
14+
2. Redistributions in binary form must reproduce the above copyright notice,
15+
this list of conditions and the following disclaimer in the documentation
16+
and/or other materials provided with the distribution.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
POSSIBILITY OF SUCH DAMAGE.
29+
#L%
30+
-->
31+
32+
<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">
33+
<modelVersion>4.0.0</modelVersion>
34+
35+
<groupId>org.apache.maven.plugin.my.unit</groupId>
36+
<artifactId>exclusions</artifactId>
37+
<version>1.0.0-SNAPSHOT</version>
38+
<packaging>pom</packaging>
39+
<name>Top-level project for testing exclusions</name>
40+
41+
<properties>
42+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
43+
</properties>
44+
45+
<modules>
46+
<module>dependency</module>
47+
<module>to-copy</module>
48+
</modules>
49+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2012 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
source(new File(basedir, "../../../src/it/lib.bsh").getPath());
32+
33+
if (!plugins.exists()) plugins.mkdirs();
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--
2+
#%L
3+
ImageJ software for multidimensional image processing and analysis.
4+
%%
5+
Copyright (C) 2012 - 2016 Board of Regents of the University of
6+
Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
Institute of Molecular Cell Biology and Genetics.
8+
%%
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice,
13+
this list of conditions and the following disclaimer.
14+
2. Redistributions in binary form must reproduce the above copyright notice,
15+
this list of conditions and the following disclaimer in the documentation
16+
and/or other materials provided with the distribution.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
POSSIBILITY OF SUCH DAMAGE.
29+
#L%
30+
-->
31+
32+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
34+
<modelVersion>4.0.0</modelVersion>
35+
36+
<groupId>org.apache.maven.plugin.my.unit</groupId>
37+
<artifactId>to-copy</artifactId>
38+
<version>1.0.0-SNAPSHOT</version>
39+
<packaging>jar</packaging>
40+
<name>An example artifact to test support for &lt;exclusions&gt;</name>
41+
42+
<properties>
43+
<scijava.app.directory>${project.basedir}/../target/ImageJ.app/</scijava.app.directory>
44+
</properties>
45+
46+
<dependencies>
47+
<dependency>
48+
<groupId>${project.groupId}</groupId>
49+
<artifactId>dependency</artifactId>
50+
<version>${project.version}</version>
51+
</dependency>
52+
</dependencies>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.scijava</groupId>
58+
<artifactId>scijava-maven-plugin</artifactId>
59+
<version>${scijava-maven.version}</version>
60+
<executions>
61+
<execution>
62+
<id>copy-jars</id>
63+
<phase>install</phase>
64+
<goals>
65+
<goal>copy-jars</goal>
66+
</goals>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
</project>

src/it/subdir-from-dependency/to-copy/src/main/resources/empty.txt

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2012 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
source(new File(basedir, "../../../src/it/lib.bsh").getPath());
32+
33+
jars = new File(ijDir, "jars");
34+
dependency = new File(jars, "Something/dependency-1.0.0-SNAPSHOT.jar");
35+
assertTrue("", dependency.exists());

src/main/java/org/scijava/maven/plugin/install/CopyJarsMojo.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@
3333

3434
import java.io.File;
3535
import java.io.IOException;
36+
import java.util.Properties;
3637

3738
import org.apache.maven.plugin.MojoExecutionException;
3839
import org.apache.maven.plugins.annotations.Component;
3940
import org.apache.maven.plugins.annotations.Mojo;
4041
import org.apache.maven.plugins.annotations.Parameter;
4142
import org.apache.maven.project.DefaultProjectBuildingRequest;
4243
import org.apache.maven.project.MavenProject;
44+
import org.apache.maven.project.ProjectBuilder;
45+
import org.apache.maven.project.ProjectBuildingException;
4346
import org.apache.maven.project.ProjectBuildingRequest;
47+
import org.apache.maven.project.ProjectBuildingResult;
4448
import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
4549
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
4650
import org.apache.maven.shared.artifact.resolve.ArtifactResult;
@@ -82,6 +86,9 @@ public class CopyJarsMojo extends AbstractCopyJarsMojo {
8286

8387
private File appDir;
8488

89+
@Component
90+
private ProjectBuilder mavenProjectBuilder;
91+
8592
@Override
8693
public void execute() throws MojoExecutionException {
8794
// Keep backward compatibility
@@ -130,13 +137,23 @@ public void execute() throws MojoExecutionException {
130137
continue;
131138
}
132139
// Resolution of the subdirectory for dependencies is handled in installArtifact
133-
if (!ignoreDependencies)
134-
installArtifact(result.getArtifact(), appDir, false, deleteOtherVersionsPolicy);
140+
if (!ignoreDependencies) {
141+
ProjectBuildingResult build = mavenProjectBuilder.build(result.getArtifact(), session.getProjectBuildingRequest());
142+
Properties properties = build.getProject().getProperties();
143+
String subdir = (String) properties.get( appSubdirectoryProperty );
144+
145+
installArtifact(result.getArtifact(), appDir, subdir, false, deleteOtherVersionsPolicy);
146+
}
135147
}
136148
catch (IOException e) {
137149
throw new MojoExecutionException("Couldn't download artifact " +
138150
result.getArtifact() + ": " + e.getMessage(), e);
139151
}
152+
catch ( ProjectBuildingException e )
153+
{
154+
throw new MojoExecutionException( "Couldn't determine " +
155+
appSubdirectoryProperty + " for " + result.getArtifact(), e );
156+
}
140157
}
141158
}
142159
catch (DependencyResolverException e) {

src/main/java/org/scijava/maven/plugin/install/InstallArtifactMojo.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Arrays;
3838
import java.util.List;
3939
import java.util.Map;
40+
import java.util.Properties;
4041
import java.util.regex.Matcher;
4142
import java.util.regex.Pattern;
4243

@@ -52,7 +53,10 @@
5253
import org.apache.maven.plugins.annotations.Mojo;
5354
import org.apache.maven.plugins.annotations.Parameter;
5455
import org.apache.maven.project.DefaultProjectBuildingRequest;
56+
import org.apache.maven.project.ProjectBuilder;
57+
import org.apache.maven.project.ProjectBuildingException;
5558
import org.apache.maven.project.ProjectBuildingRequest;
59+
import org.apache.maven.project.ProjectBuildingResult;
5660
import org.apache.maven.shared.artifact.filter.resolve.AbstractFilter;
5761
import org.apache.maven.shared.artifact.filter.resolve.AndFilter;
5862
import org.apache.maven.shared.artifact.filter.resolve.Node;
@@ -173,6 +177,9 @@ public class InstallArtifactMojo extends AbstractCopyJarsMojo {
173177
*/
174178
private DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();
175179

180+
@Component
181+
private ProjectBuilder mavenProjectBuilder;
182+
176183
@Override
177184
public void execute() throws MojoExecutionException, MojoFailureException {
178185
// Keep backward compatibility
@@ -255,14 +262,23 @@ public boolean accept(Node node, List<Node> parents) {
255262
installArtifact( result.getArtifact(), appDir, appSubdirectory, false, deleteOtherVersionsPolicy );
256263
continue;
257264
}
258-
if (!ignoreDependencies)
259-
installArtifact(result.getArtifact(), appDir, false,
260-
deleteOtherVersionsPolicy);
265+
if (!ignoreDependencies) {
266+
ProjectBuildingResult build = mavenProjectBuilder.build(result.getArtifact(), session.getProjectBuildingRequest());
267+
Properties properties = build.getProject().getProperties();
268+
String subdir = (String) properties.get( appSubdirectoryProperty );
269+
270+
installArtifact(result.getArtifact(), appDir, subdir, false, deleteOtherVersionsPolicy);
271+
}
261272
}
262273
catch (IOException e) {
263274
throw new MojoExecutionException("Couldn't download artifact " +
264275
artifact + ": " + e.getMessage(), e);
265276
}
277+
catch ( ProjectBuildingException e )
278+
{
279+
throw new MojoExecutionException( "Couldn't determine " +
280+
appSubdirectoryProperty + " for " + result.getArtifact(), e );
281+
}
266282
}
267283
}
268284
catch (DependencyResolverException e) {

0 commit comments

Comments
 (0)