7070import org .codehaus .plexus .component .configurator .expression .ExpressionEvaluationException ;
7171import org .codehaus .plexus .component .configurator .expression .ExpressionEvaluator ;
7272import org .codehaus .plexus .util .StringUtils ;
73+ import org .scijava .maven .plugin .install .AbstractCopyJarsMojo .OtherVersions ;
7374
7475/**
7576 * Downloads .jar artifacts and their dependencies into a SciJava application
9091public class InstallArtifactMojo extends AbstractCopyJarsMojo {
9192
9293 /**
93- * Path to the ImageJ.app/ directory to which artifacts are installed .
94+ * Path to the ImageJ.app/ directory to which artifacts are copied .
9495 * <p>
9596 * If it is not a directory, no .jar files are copied.
9697 * </p>
9798 */
98- @ Parameter (property = imagejDirectoryProperty )
99+ @ Deprecated
100+ @ Parameter (property = imagejDirectoryProperty , required = false )
99101 private String imagejDirectory ;
100102
103+ /**
104+ * Path to a SciJava application directory (e.g. ImageJ.app) to which
105+ * artifacts are copied.
106+ * <p>
107+ * If it is not a directory, no .jar files are copied.
108+ * </p>
109+ */
110+ @ Parameter (property = appDirectoryProperty , required = false )
111+ private String appDirectory ;
112+
101113 /**
102114 * The name of the property pointing to the subdirectory (beneath e.g.
103- * {@code jars/} or {@code plugins/}) to which the artifact should be
104- * copied.
115+ * {@code jars/} or {@code plugins/}) to which the artifact should be copied.
105116 * <p>
106117 * If no property of that name exists, no subdirectory will be used.
107118 * </p>
108119 */
109- @ Parameter ( property = imagejSubdirectoryProperty , required = false )
120+ @ Deprecated
121+ @ Parameter (property = imagejSubdirectoryProperty , required = false )
110122 private String imagejSubdirectory ;
111123
124+ /**
125+ * The name of the property pointing to the subdirectory (beneath e.g.
126+ * {@code jars/} or {@code plugins/}) to which the artifact should be copied.
127+ * <p>
128+ * If no property of that name exists, no subdirectory will be used.
129+ * </p>
130+ */
131+ @ Parameter (property = appSubdirectoryProperty , required = false )
132+ private String appSubdirectory ;
133+
112134 /**
113135 * Whether to delete other versions when copying the files.
114136 * <p>
@@ -129,7 +151,19 @@ public class InstallArtifactMojo extends AbstractCopyJarsMojo {
129151 * other versions.
130152 * </p>
131153 */
132- @ Parameter (property = imagejDeleteOtherVersionsPolicyProperty , defaultValue = "older" )
154+ @ Deprecated
155+ @ Parameter (property = imagejDeleteOtherVersionsPolicyProperty )
156+ private OtherVersions imagejDeleteOtherVersionsPolicy ;
157+
158+ /**
159+ * Whether to delete other versions when copying the files.
160+ * <p>
161+ * When copying a file and its dependencies to a SciJava application directory
162+ * and there are other versions of the same file, we can warn or delete those
163+ * other versions.
164+ * </p>
165+ */
166+ @ Parameter (property = deleteOtherVersionsPolicyProperty , defaultValue = "older" )
133167 private OtherVersions deleteOtherVersionsPolicy ;
134168
135169 /**
@@ -239,32 +273,96 @@ public class InstallArtifactMojo extends AbstractCopyJarsMojo {
239273
240274 @ Override
241275 public void execute () throws MojoExecutionException , MojoFailureException {
242- // Keep backwards compatibility to delete.other.versions
243276 ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator (session , mojoExecution );
277+
278+ // Keep backwards compatibility to delete.other.versions
244279 try {
245280 Object evaluate = evaluator .evaluate ("${" +deleteOtherVersionsProperty +"}" );
246281 if (evaluate != null ) {
247- getLog ().warn ("Property '" + deleteOtherVersionsProperty + "' is deprecated. Use '" + imagejDeleteOtherVersionsPolicyProperty +"' instead" );
282+ getLog ().warn ("Property '" + deleteOtherVersionsProperty + "' is deprecated. Use '" + deleteOtherVersionsPolicyProperty +"' instead" );
248283 deleteOtherVersionsPolicy = deleteOtherVersions ? OtherVersions .older : OtherVersions .never ;
249284 }
250285 }
251286 catch (ExpressionEvaluationException e ) {
252287 getLog ().warn (e );
253288 }
254289
255- if (imagejDirectory == null ) {
290+ // Keep backwards compatibility to imagej.app.directory
291+ try {
292+ Object evaluate = evaluator .evaluate ("${" +imagejDirectoryProperty +"}" );
293+
294+ // Use imagejDirectory if it is set (directly or via imagej.app.directory)
295+ if (imagejDirectory != null ) {
296+ if (evaluate == null ) {
297+ getLog ().warn ("Configuration property 'imagejDirectory' is deprecated. Use 'appDirectory' instead" );
298+ } else {
299+ getLog ().warn ("Property '" + imagejDirectoryProperty + "' is deprecated. Use '" + appDirectoryProperty +"' instead" );
300+ }
301+
302+ // TODO How do we want to handle cases where both are provided. Which
303+ // property should take precedence?
304+ appDirectory = imagejDirectory ;
305+ }
306+ }
307+ catch (ExpressionEvaluationException e ) {
308+ getLog ().warn (e );
309+ }
310+
311+ // Keep backwards compatibility to imagej.app.subdirectory
312+ try {
313+ Object evaluate = evaluator .evaluate ("${" +imagejSubdirectoryProperty +"}" );
314+
315+ // Use imagejSubdirectory if it is set (directly or via imagej.app.subdirectory)
316+ if (imagejSubdirectory != null ) {
317+ if (evaluate == null ) {
318+ getLog ().warn ("Configuration property 'imagejSubdirectory' is deprecated. Use 'appSubdirectory' instead" );
319+ } else {
320+ getLog ().warn ("Property '" + imagejSubdirectoryProperty + "' is deprecated. Use '" + appSubdirectoryProperty +"' instead" );
321+ }
322+
323+ // TODO How do we want to handle cases where both are provided. Which
324+ // property should take precedence?
325+ appSubdirectory = imagejSubdirectory ;
326+ }
327+ }
328+ catch (ExpressionEvaluationException e ) {
329+ getLog ().warn (e );
330+ }
331+
332+ // Keep backwards compatibility to imagej.deleteOtherVersions
333+ try {
334+ Object evaluate = evaluator .evaluate ("${" +imagejDeleteOtherVersionsPolicyProperty +"}" );
335+
336+ // Use imagejDeleteOtherVersionsPolicy if it is set (directly or via imagej.deleteOtherVersions)
337+ if (imagejDeleteOtherVersionsPolicy != null ) {
338+ if (evaluate == null ) {
339+ getLog ().warn ("Configuration property 'imagejDeleteOtherVersionsPolicy' is deprecated. Use 'deleteOtherVersionsPolicy' instead" );
340+ } else {
341+ getLog ().warn ("Property '" + imagejDeleteOtherVersionsPolicyProperty + "' is deprecated. Use '" + deleteOtherVersionsPolicyProperty +"' instead" );
342+ }
343+
344+ // TODO How do we want to handle cases where both are provided. Which
345+ // property should take precedence?
346+ deleteOtherVersionsPolicy = imagejDeleteOtherVersionsPolicy ;
347+ }
348+ }
349+ catch (ExpressionEvaluationException e ) {
350+ getLog ().warn (e );
351+ }
352+
353+ if (appDirectory == null ) {
256354 throw new MojoExecutionException (
257- "The '" +imagejDirectoryProperty +"' property is unset!" );
355+ "The '" +appDirectoryProperty +"' property is unset!" );
258356 }
259- File imagejDir = new File (imagejDirectory );
357+ File imagejDir = new File (appDirectory );
260358 if (!imagejDir .isDirectory () && !imagejDir .mkdirs ()) {
261359 throw new MojoFailureException ("Could not make directory: " +
262360 imagejDir );
263361 }
264362
265- if ( imagejSubdirectory == null )
363+ if ( appSubdirectory == null )
266364 {
267- getLog ().info ( "No property name for the " + imagejSubdirectoryProperty +
365+ getLog ().info ( "No property name for the " + appDirectoryProperty +
268366 " directory location was specified; Installing in default location" );
269367 }
270368
@@ -326,7 +424,7 @@ public boolean accept(Node node, List<Node> parents) {
326424 try {
327425 if ( isSameGAV (coordinate , result .getArtifact ()) )
328426 {
329- installArtifact ( result .getArtifact (), imagejDir , imagejSubdirectory , false , deleteOtherVersionsPolicy );
427+ installArtifact ( result .getArtifact (), imagejDir , appSubdirectory , false , deleteOtherVersionsPolicy );
330428 continue ;
331429 }
332430 if (!ignoreDependencies )
0 commit comments