1
|
package eu.dnetlib.maven.plugin.properties;
|
2
|
|
3
|
import java.io.File;
|
4
|
import java.util.ArrayList;
|
5
|
import java.util.List;
|
6
|
|
7
|
import org.apache.commons.lang.ArrayUtils;
|
8
|
import org.apache.commons.lang.StringUtils;
|
9
|
import org.apache.maven.plugin.AbstractMojo;
|
10
|
import org.apache.maven.plugin.MojoExecutionException;
|
11
|
import org.apache.maven.plugin.MojoFailureException;
|
12
|
|
13
|
/**
|
14
|
* Generates oozie properties which were not provided from commandline.
|
15
|
* @author mhorst
|
16
|
*
|
17
|
* @goal generate-properties
|
18
|
*/
|
19
|
public class GenerateOoziePropertiesMojo extends AbstractMojo {
|
20
|
|
21
|
public static final String PROPERTY_NAME_WF_SOURCE_DIR = "workflow.source.dir";
|
22
|
public static final String PROPERTY_NAME_SANDBOX_NAME = "sandboxName";
|
23
|
|
24
|
private final String[] limiters = {"iis", "dnetlib", "eu", "dhp"};
|
25
|
|
26
|
@Override
|
27
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
28
|
if (System.getProperties().containsKey(PROPERTY_NAME_WF_SOURCE_DIR) &&
|
29
|
!System.getProperties().containsKey(PROPERTY_NAME_SANDBOX_NAME)) {
|
30
|
String generatedSandboxName = generateSandboxName(System.getProperties().getProperty(
|
31
|
PROPERTY_NAME_WF_SOURCE_DIR));
|
32
|
if (generatedSandboxName!=null) {
|
33
|
System.getProperties().setProperty(PROPERTY_NAME_SANDBOX_NAME,
|
34
|
generatedSandboxName);
|
35
|
} else {
|
36
|
System.out.println("unable to generate sandbox name from path: " +
|
37
|
System.getProperties().getProperty(PROPERTY_NAME_WF_SOURCE_DIR));
|
38
|
}
|
39
|
}
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Generates sandbox name from workflow source directory.
|
44
|
* @param wfSourceDir
|
45
|
* @return generated sandbox name
|
46
|
*/
|
47
|
private String generateSandboxName(String wfSourceDir) {
|
48
|
// utilize all dir names until finding one of the limiters
|
49
|
List<String> sandboxNameParts = new ArrayList<String>();
|
50
|
String[] tokens = StringUtils.split(wfSourceDir, File.separatorChar);
|
51
|
ArrayUtils.reverse(tokens);
|
52
|
if (tokens.length>0) {
|
53
|
for (String token : tokens) {
|
54
|
for (String limiter : limiters) {
|
55
|
if (limiter.equals(token)) {
|
56
|
return sandboxNameParts.size()>0?
|
57
|
StringUtils.join(sandboxNameParts.toArray()):null;
|
58
|
}
|
59
|
}
|
60
|
if (sandboxNameParts.size()>0) {
|
61
|
sandboxNameParts.add(0, File.separator);
|
62
|
}
|
63
|
sandboxNameParts.add(0, token);
|
64
|
}
|
65
|
return StringUtils.join(sandboxNameParts.toArray());
|
66
|
} else {
|
67
|
return null;
|
68
|
}
|
69
|
}
|
70
|
|
71
|
}
|