1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.mojo.properties;
17
18 import java.util.Enumeration;
19 import java.util.Properties;
20
21 import org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.MojoFailureException;
24
25
26
27
28
29
30
31
32
33 public class SetSystemPropertiesMojo extends AbstractMojo {
34
35
36
37
38
39
40
41
42 private Properties properties;
43
44
45
46
47
48
49 @Override
50 public void execute() throws MojoExecutionException, MojoFailureException {
51 if (properties.isEmpty()) {
52 getLog().debug("No system properties found");
53
54 return;
55 }
56
57 getLog().debug("Setting system properties:");
58
59 for (Enumeration<?> propertyNames = properties.propertyNames(); propertyNames.hasMoreElements();) {
60 String propertyName = propertyNames.nextElement().toString();
61 String propertyValue = properties.getProperty(propertyName);
62
63 getLog().debug("- " + propertyName + " = " + propertyValue);
64
65 System.setProperty(propertyName, propertyValue);
66 }
67
68 int count = properties.size();
69
70 getLog().info("Set " + count + " system " + (count > 1 ? "properties" : "property"));
71 }
72 }