File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\maven-plugin\src\test\java\hudson\maven\MojoInfoBuilder.java.html

1 package hudson.maven;
2
3 import hudson.maven.MojoInfo;
4
5 import java.io.File;
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import org.apache.maven.plugin.MojoExecution;
10 import org.apache.maven.plugin.descriptor.MojoDescriptor;
11 import org.apache.maven.plugin.descriptor.PluginDescriptor;
12 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
13 import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
14 import org.codehaus.plexus.configuration.PlexusConfiguration;
15
16 public class MojoInfoBuilder {
17
18 private String groupId;
19 private String artifactId;
20 private String goalName;
21 private String version = "1.0";
22 private Map<String, String> configValues = new HashMap<String, String>();
23 private long startTime = System.currentTimeMillis();
24
25 public static MojoInfoBuilder mojoBuilder(String groupId, String artifactId, String goalName) {
26 return new MojoInfoBuilder(groupId, artifactId, goalName);
27 }
28
29 private MojoInfoBuilder(String groupId, String artifactId, String goalName) {
30 this.groupId = groupId;
31 this.artifactId = artifactId;
32 this.goalName = goalName;
33 }
34
35 public MojoInfoBuilder copy() {
36 MojoInfoBuilder copy = new MojoInfoBuilder(this.groupId, this.artifactId, this.goalName)
37 .version(this.version);
38 copy.configValues.putAll(this.configValues);
39 return copy;
40 }
41
42 public MojoInfoBuilder version(String version) {
43 this.version = version;
44 return this;
45 }
46
47 public MojoInfoBuilder startTime(long startTime) {
48 this.startTime = startTime;
49 return this;
50 }
51
52 public MojoInfoBuilder configValue(String key,String value) {
53 configValues.put(key, value);
54 return this;
55 }
56
57 public MojoInfo build() {
58 PluginDescriptor pluginDescriptor = new PluginDescriptor();
59 pluginDescriptor.setGroupId(groupId);
60 pluginDescriptor.setArtifactId(artifactId);
61 pluginDescriptor.setVersion(version);
62
63 MojoDescriptor mojoDescriptor = new MojoDescriptor();
64 mojoDescriptor.setPluginDescriptor(pluginDescriptor);
65 mojoDescriptor.setGoal(goalName);
66
67 MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
68
69 PlexusConfiguration configuration = new DefaultPlexusConfiguration("configuration");
70 for (Map.Entry<String, String> e : this.configValues.entrySet()) {
71 configuration.addChild(e.getKey(),e.getValue());
72 }
73
74 ExpressionEvaluator evaluator = new ExpressionEvaluator() {
75 @Override
76 public Object evaluate(String expression) {
77 return expression;
78 }
79
80 @Override
81 public File alignToBaseDirectory(File file) {
82 return file;
83 }
84 };
85
86 MojoInfo info = new MojoInfo(mojoExecution, null, configuration, evaluator, startTime);
87 return info;
88 }
89
90
91 }
92