Skip to content

Commit 8fa6599

Browse files
committed
Move compatibility mode to AbstractCopyJarsMojo
1 parent 39024f1 commit 8fa6599

File tree

3 files changed

+157
-315
lines changed

3 files changed

+157
-315
lines changed

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

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@
5050
import org.apache.maven.execution.MavenSession;
5151
import org.apache.maven.model.Dependency;
5252
import org.apache.maven.plugin.AbstractMojo;
53+
import org.apache.maven.plugin.MojoExecution;
5354
import org.apache.maven.plugin.MojoExecutionException;
55+
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
56+
import org.apache.maven.plugins.annotations.Parameter;
5457
import org.apache.maven.project.MavenProject;
58+
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
59+
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
5560
import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
5661
import org.codehaus.plexus.interpolation.ObjectBasedValueSource;
5762
import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
@@ -70,6 +75,95 @@
7075
*/
7176
public abstract class AbstractCopyJarsMojo extends AbstractMojo {
7277

78+
/**
79+
* Path to the ImageJ.app/ directory to which artifacts are copied.
80+
* <p>
81+
* If it is not a directory, no .jar files are copied.
82+
* </p>
83+
*/
84+
@Deprecated
85+
@Parameter(property = imagejDirectoryProperty, required = false)
86+
String imagejDirectory;
87+
88+
/**
89+
* Path to a SciJava application directory (e.g. ImageJ.app) to which
90+
* artifacts are copied.
91+
* <p>
92+
* If it is not a directory, no .jar files are copied.
93+
* </p>
94+
*/
95+
@Parameter(property = appDirectoryProperty, required = false)
96+
String appDirectory;
97+
98+
/**
99+
* The name of the property pointing to the subdirectory (beneath e.g.
100+
* {@code jars/} or {@code plugins/}) to which the artifact should be copied.
101+
* <p>
102+
* If no property of that name exists, no subdirectory will be used.
103+
* </p>
104+
*/
105+
@Deprecated
106+
@Parameter(property = imagejSubdirectoryProperty, required = false)
107+
String imagejSubdirectory;
108+
109+
/**
110+
* The name of the property pointing to the subdirectory (beneath e.g.
111+
* {@code jars/} or {@code plugins/}) to which the artifact should be copied.
112+
* <p>
113+
* If no property of that name exists, no subdirectory will be used.
114+
* </p>
115+
*/
116+
@Parameter(property = appSubdirectoryProperty, required = false)
117+
String appSubdirectory;
118+
119+
/**
120+
* Whether to delete other versions when copying the files.
121+
* <p>
122+
* When copying a file and its dependencies to an ImageJ.app/ directory and
123+
* there are other versions of the same file, we can warn or delete those
124+
* other versions.
125+
* </p>
126+
*/
127+
@Deprecated
128+
@Parameter(property = deleteOtherVersionsProperty)
129+
boolean deleteOtherVersions;
130+
131+
/**
132+
* Whether to delete other versions when copying the files.
133+
* <p>
134+
* When copying a file and its dependencies to an ImageJ.app/ directory and
135+
* there are other versions of the same file, we can warn or delete those
136+
* other versions.
137+
* </p>
138+
*/
139+
@Deprecated
140+
@Parameter(property = imagejDeleteOtherVersionsPolicyProperty)
141+
OtherVersions imagejDeleteOtherVersionsPolicy;
142+
143+
/**
144+
* Whether to delete other versions when copying the files.
145+
* <p>
146+
* When copying a file and its dependencies to a SciJava application directory
147+
* and there are other versions of the same file, we can warn or delete those
148+
* other versions.
149+
* </p>
150+
*/
151+
@Parameter(property = deleteOtherVersionsPolicyProperty, defaultValue = "older")
152+
OtherVersions deleteOtherVersionsPolicy;
153+
154+
/**
155+
* If this option is set to <code>true</code>, only the artifact will be
156+
* copied - without its dependencies.
157+
*/
158+
@Parameter(property = ignoreDependenciesProperty, defaultValue = "false")
159+
boolean ignoreDependencies;
160+
161+
@Parameter(defaultValue = "${session}")
162+
MavenSession session;
163+
164+
@Parameter( defaultValue = "${mojoExecution}", readonly = true )
165+
MojoExecution mojoExecution;
166+
73167
public static final String imagejDirectoryProperty = "imagej.app.directory";
74168
public static final String imagejSubdirectoryProperty = "imagej.app.subdirectory";
75169
public static final String deleteOtherVersionsProperty = "delete.other.versions";
@@ -84,6 +178,65 @@ public enum OtherVersions {
84178
always, older, never
85179
}
86180

181+
/**
182+
* Handles the backward compatibility with properties previously defined by
183+
* imagej-maven-plugin.
184+
*/
185+
void handleBackwardCompatibility() {
186+
ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
187+
188+
try {
189+
// If at least one scijava.* property is set, ignore imagej.* properties
190+
if (evaluator.evaluate("${" + appDirectoryProperty + "}") == null &&
191+
evaluator.evaluate("${" + appSubdirectoryProperty + "}") == null &&
192+
evaluator.evaluate("${" + deleteOtherVersionsPolicyProperty + "}") == null)
193+
{
194+
195+
// Keep backwards compatibility to delete.other.versions
196+
if (evaluator.evaluate("${"+deleteOtherVersionsProperty+"}") != null) {
197+
getLog().warn("Property '" + deleteOtherVersionsProperty + "' is deprecated. Use '"+ deleteOtherVersionsPolicyProperty +"' instead");
198+
deleteOtherVersionsPolicy = deleteOtherVersions ? OtherVersions.older : OtherVersions.never;
199+
}
200+
201+
// Keep backwards compatibility to imagej.app.directory
202+
// Use imagejDirectory if it is set (directly or via imagej.app.directory)
203+
if (imagejDirectory != null) {
204+
if (evaluator.evaluate("${"+imagejDirectoryProperty+"}") == null) {
205+
getLog().warn("Configuration property 'imagejDirectory' is deprecated. Use 'appDirectory' instead");
206+
} else {
207+
getLog().warn("Property '" + imagejDirectoryProperty + "' is deprecated. Use '"+ appDirectoryProperty +"' instead");
208+
}
209+
appDirectory = imagejDirectory;
210+
}
211+
212+
// Keep backwards compatibility to imagej.app.subdirectory
213+
// Use imagejSubdirectory if it is set (directly or via imagej.app.subdirectory)
214+
if (imagejSubdirectory != null) {
215+
if (evaluator.evaluate("${"+imagejSubdirectoryProperty+"}") == null) {
216+
getLog().warn("Configuration property 'imagejSubdirectory' is deprecated. Use 'appSubdirectory' instead");
217+
} else {
218+
getLog().warn("Property '" + imagejSubdirectoryProperty + "' is deprecated. Use '"+ appSubdirectoryProperty +"' instead");
219+
}
220+
appSubdirectory = imagejSubdirectory;
221+
}
222+
223+
// Keep backwards compatibility to imagej.deleteOtherVersions
224+
// Use imagejDeleteOtherVersionsPolicy if it is set (directly or via imagej.deleteOtherVersions)
225+
if (imagejDeleteOtherVersionsPolicy != null) {
226+
if (evaluator.evaluate("${"+imagejDeleteOtherVersionsPolicyProperty+"}") == null) {
227+
getLog().warn("Configuration property 'imagejDeleteOtherVersionsPolicy' is deprecated. Use 'deleteOtherVersionsPolicy' instead");
228+
} else {
229+
getLog().warn("Property '" + imagejDeleteOtherVersionsPolicyProperty + "' is deprecated. Use '"+ deleteOtherVersionsPolicyProperty +"' instead");
230+
}
231+
deleteOtherVersionsPolicy = imagejDeleteOtherVersionsPolicy;
232+
}
233+
}
234+
}
235+
catch (ExpressionEvaluationException e) {
236+
getLog().warn(e);
237+
}
238+
}
239+
87240
protected boolean hasIJ1Dependency(final MavenProject project) {
88241
final List<Dependency> dependencies = project.getDependencies();
89242
for (final Dependency dependency : dependencies) {

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

Lines changed: 2 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@
3434
import java.io.File;
3535
import java.io.IOException;
3636

37-
import org.apache.maven.execution.MavenSession;
38-
import org.apache.maven.plugin.MojoExecution;
3937
import org.apache.maven.plugin.MojoExecutionException;
40-
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
4138
import org.apache.maven.plugins.annotations.Component;
4239
import org.apache.maven.plugins.annotations.Mojo;
4340
import org.apache.maven.plugins.annotations.Parameter;
@@ -50,8 +47,6 @@
5047
import org.apache.maven.shared.dependencies.DefaultDependableCoordinate;
5148
import org.apache.maven.shared.dependencies.resolve.DependencyResolver;
5249
import org.apache.maven.shared.dependencies.resolve.DependencyResolverException;
53-
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
54-
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
5550

5651
/**
5752
* Copies .jar artifacts and their dependencies into a SciJava application
@@ -71,101 +66,12 @@
7166
@Mojo(name = "copy-jars", requiresProject = true, requiresOnline = true)
7267
public class CopyJarsMojo extends AbstractCopyJarsMojo {
7368

74-
/**
75-
* Path to the ImageJ.app/ directory to which artifacts are copied.
76-
* <p>
77-
* If it is not a directory, no .jar files are copied.
78-
* </p>
79-
*/
80-
@Deprecated
81-
@Parameter(property = imagejDirectoryProperty, required = false)
82-
private String imagejDirectory;
83-
84-
/**
85-
* Path to a SciJava application directory (e.g. ImageJ.app) to which
86-
* artifacts are copied.
87-
* <p>
88-
* If it is not a directory, no .jar files are copied.
89-
* </p>
90-
*/
91-
@Parameter(property = appDirectoryProperty, required = false)
92-
private String appDirectory;
93-
94-
/**
95-
* The name of the property pointing to the subdirectory (beneath e.g.
96-
* {@code jars/} or {@code plugins/}) to which the artifact should be copied.
97-
* <p>
98-
* If no property of that name exists, no subdirectory will be used.
99-
* </p>
100-
*/
101-
@Deprecated
102-
@Parameter(property = imagejSubdirectoryProperty, required = false)
103-
private String imagejSubdirectory;
104-
105-
/**
106-
* The name of the property pointing to the subdirectory (beneath e.g.
107-
* {@code jars/} or {@code plugins/}) to which the artifact should be copied.
108-
* <p>
109-
* If no property of that name exists, no subdirectory will be used.
110-
* </p>
111-
*/
112-
@Parameter(property = appSubdirectoryProperty, required = false)
113-
private String appSubdirectory;
114-
115-
/**
116-
* Whether to delete other versions when copying the files.
117-
* <p>
118-
* When copying a file and its dependencies to an ImageJ.app/ directory and
119-
* there are other versions of the same file, we can warn or delete those
120-
* other versions.
121-
* </p>
122-
*/
123-
@Deprecated
124-
@Parameter(property = deleteOtherVersionsProperty)
125-
private boolean deleteOtherVersions;
126-
127-
/**
128-
* Whether to delete other versions when copying the files.
129-
* <p>
130-
* When copying a file and its dependencies to an ImageJ.app/ directory and
131-
* there are other versions of the same file, we can warn or delete those
132-
* other versions.
133-
* </p>
134-
*/
135-
@Deprecated
136-
@Parameter(property = imagejDeleteOtherVersionsPolicyProperty)
137-
private OtherVersions imagejDeleteOtherVersionsPolicy;
138-
139-
/**
140-
* Whether to delete other versions when copying the files.
141-
* <p>
142-
* When copying a file and its dependencies to a SciJava application directory
143-
* and there are other versions of the same file, we can warn or delete those
144-
* other versions.
145-
* </p>
146-
*/
147-
@Parameter(property = deleteOtherVersionsPolicyProperty, defaultValue = "older")
148-
private OtherVersions deleteOtherVersionsPolicy;
149-
150-
/**
151-
* If this option is set to <code>true</code>, only the artifact will be
152-
* copied - without its dependencies.
153-
*/
154-
@Parameter(property = ignoreDependenciesProperty, defaultValue = "false")
155-
private boolean ignoreDependencies;
156-
15769
/**
15870
* Project
15971
*/
16072
@Parameter(defaultValue = "${project}", required=true, readonly = true)
16173
private MavenProject project;
16274

163-
/**
164-
* Session
165-
*/
166-
@Parameter(defaultValue = "${session}")
167-
private MavenSession session;
168-
16975
/**
17076
* The dependency resolver to.
17177
*/
@@ -176,13 +82,10 @@ public class CopyJarsMojo extends AbstractCopyJarsMojo {
17682

17783
private File appDir;
17884

179-
@Parameter( defaultValue = "${mojoExecution}", readonly = true )
180-
MojoExecution mojoExecution;
181-
18285
@Override
18386
public void execute() throws MojoExecutionException {
184-
// Keep backwards compatibility
185-
handleBackwardsCompatibility();
87+
// Keep backward compatibility
88+
handleBackwardCompatibility();
18689

18790
if (appDirectory == null) {
18891
if (hasIJ1Dependency(project)) getLog().info(
@@ -241,62 +144,4 @@ public void execute() throws MojoExecutionException {
241144
"Couldn't resolve dependencies for artifact: " + e.getMessage(), e);
242145
}
243146
}
244-
245-
/**
246-
* TODO Javadoc
247-
*/
248-
private void handleBackwardsCompatibility() {
249-
ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
250-
251-
try {
252-
// If at least one scijava.* property is set, ignore imagej.* properties
253-
if (evaluator.evaluate("${" + appDirectoryProperty + "}") == null &&
254-
evaluator.evaluate("${" + appSubdirectoryProperty + "}") == null &&
255-
evaluator.evaluate("${" + deleteOtherVersionsPolicyProperty + "}") == null)
256-
{
257-
258-
// Keep backwards compatibility to delete.other.versions
259-
if (evaluator.evaluate("${"+deleteOtherVersionsProperty+"}") != null) {
260-
getLog().warn("Property '" + deleteOtherVersionsProperty + "' is deprecated. Use '"+ deleteOtherVersionsPolicyProperty +"' instead");
261-
deleteOtherVersionsPolicy = deleteOtherVersions ? OtherVersions.older : OtherVersions.never;
262-
}
263-
264-
// Keep backwards compatibility to imagej.app.directory
265-
// Use imagejDirectory if it is set (directly or via imagej.app.directory)
266-
if (imagejDirectory != null) {
267-
if (evaluator.evaluate("${"+imagejDirectoryProperty+"}") == null) {
268-
getLog().warn("Configuration property 'imagejDirectory' is deprecated. Use 'appDirectory' instead");
269-
} else {
270-
getLog().warn("Property '" + imagejDirectoryProperty + "' is deprecated. Use '"+ appDirectoryProperty +"' instead");
271-
}
272-
appDirectory = imagejDirectory;
273-
}
274-
275-
// Keep backwards compatibility to imagej.app.subdirectory
276-
// Use imagejSubdirectory if it is set (directly or via imagej.app.subdirectory)
277-
if (imagejSubdirectory != null) {
278-
if (evaluator.evaluate("${"+imagejSubdirectoryProperty+"}") == null) {
279-
getLog().warn("Configuration property 'imagejSubdirectory' is deprecated. Use 'appSubdirectory' instead");
280-
} else {
281-
getLog().warn("Property '" + imagejSubdirectoryProperty + "' is deprecated. Use '"+ appSubdirectoryProperty +"' instead");
282-
}
283-
appSubdirectory = imagejSubdirectory;
284-
}
285-
286-
// Keep backwards compatibility to imagej.deleteOtherVersions
287-
// Use imagejDeleteOtherVersionsPolicy if it is set (directly or via imagej.deleteOtherVersions)
288-
if (imagejDeleteOtherVersionsPolicy != null) {
289-
if (evaluator.evaluate("${"+imagejDeleteOtherVersionsPolicyProperty+"}") == null) {
290-
getLog().warn("Configuration property 'imagejDeleteOtherVersionsPolicy' is deprecated. Use 'deleteOtherVersionsPolicy' instead");
291-
} else {
292-
getLog().warn("Property '" + imagejDeleteOtherVersionsPolicyProperty + "' is deprecated. Use '"+ deleteOtherVersionsPolicyProperty +"' instead");
293-
}
294-
deleteOtherVersionsPolicy = imagejDeleteOtherVersionsPolicy;
295-
}
296-
}
297-
}
298-
catch (ExpressionEvaluationException e) {
299-
getLog().warn(e);
300-
}
301-
}
302147
}

0 commit comments

Comments
 (0)