-
Notifications
You must be signed in to change notification settings - Fork 11
/
Install4jcMojoSupport.java
107 lines (88 loc) · 3.45 KB
/
Install4jcMojoSupport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (c) 2007-2012 Sonatype, Inc. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package org.sonatype.install4j.maven;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.taskdefs.ExecTask;
import org.codehaus.plexus.util.Os;
import java.io.File;
/**
* Support for install4jc-based tasks.
*
* Compatible with install4j version 5.1.2 or higher.
*
* @since 1.0
*/
public abstract class Install4jcMojoSupport
extends MojoSupport
{
/**
* Skip execution.
*/
@Parameter(property = "install4j.skip", defaultValue = "false")
protected boolean skip;
/**
* The location of the install4j installation.
*/
@Parameter(property = "install4j.home", required = true)
protected File installDir;
/**
* Fail if the installation is missing.
*/
@Parameter(property = "install4j.failIfMissing", defaultValue = "false")
protected boolean failIfMissing;
@Component
protected MavenProject project;
@Override
protected void doExecute() throws Exception {
if (skip) {
log.warn("Skipping execution");
return;
}
AntHelper ant = new AntHelper(this, project);
if (!installDir.exists()) {
maybeFailIfMissing("Invalid install directory: " + installDir);
return;
}
log.debug("install4j installation directory: " + installDir);
boolean windows = Os.isFamily(Os.FAMILY_WINDOWS);
File install4jc = new File(installDir, "bin/install4jc" + (windows ? ".exe" : ""));
if (!install4jc.exists()) {
maybeFailIfMissing("Missing install4j compiler executable: " + install4jc);
return;
}
log.debug("install4jc: " + install4jc);
// ensure the binary is executable
// FIXME: This can fail (well complain really, if we don't have perms to change the file, should check)
ant.chmod(install4jc, "u+x");
// ensure version is compatible
VersionHelper versionHelper = new VersionHelper(log);
String versionProperty = versionHelper.fetchVersion(ant, install4jc);
versionHelper.ensureVersionCompatible(ant.getProperty(versionProperty));
ExecTask task = ant.createTask(ExecTask.class);
task.setExecutable(install4jc.getAbsolutePath());
execute(ant, task);
}
protected abstract void execute(final AntHelper ant, final ExecTask task) throws Exception;
private void maybeFailIfMissing(final String message) throws MojoExecutionException {
if (failIfMissing) {
log.error(message);
throw new MojoExecutionException(message);
}
else {
log.warn(message);
}
}
}