1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.plugin.buildmetadata;
17
18 import java.util.Date;
19 import java.util.Properties;
20
21 import org.apache.maven.plugin.MojoExecutionException;
22 import org.apache.maven.plugin.MojoFailureException;
23 import org.codehaus.plexus.util.StringUtils;
24
25 import de.smartics.maven.plugin.buildmetadata.common.Constant;
26 import de.smartics.maven.plugin.buildmetadata.io.BuildPropertiesFileHelper;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public final class BuildPointMojo extends AbstractBuildMojo
47 {
48
49
50
51
52
53
54
55
56
57
58
59 public static final String TMP_BUILD_END = "build.tmp.timestamp";
60
61
62
63
64
65
66
67
68
69
70
71
72
73 private String name;
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 public void execute() throws MojoExecutionException, MojoFailureException
93 {
94 super.execute();
95
96 if (propertiesOutputFile.exists())
97 {
98 final Properties buildMetaDataProperties = new Properties();
99 final BuildPropertiesFileHelper helper =
100 new BuildPropertiesFileHelper(getLog(), propertiesOutputFile);
101 helper.readBuildPropertiesFile(buildMetaDataProperties);
102
103 provideBuildPointInfo(buildMetaDataProperties, helper);
104 provideBuildMetaData(buildMetaDataProperties, null, providers, true);
105
106 helper.writePropertiesFile(buildMetaDataProperties);
107 updateMavenEnvironment(buildMetaDataProperties, helper);
108 }
109 else
110 {
111 getLog()
112 .info(
113 "Skipping build point '" + name + "' since no "
114 + propertiesOutputFile.getName()
115 + " with build meta data found.");
116 }
117 }
118
119 private void provideBuildPointInfo(final Properties buildMetaDataProperties,
120 final BuildPropertiesFileHelper helper)
121 {
122 final Date start = session.getStartTime();
123 final Date end = new Date();
124 final long duration = end.getTime() - start.getTime();
125 final String durationPropertyName = createDurationPropertyName();
126 final String durationString = String.valueOf(duration);
127 buildMetaDataProperties.setProperty(durationPropertyName, durationString);
128 setTimeDifference(helper, buildMetaDataProperties, end, durationString,
129 durationPropertyName);
130 }
131
132 private void setTimeDifference(final BuildPropertiesFileHelper helper,
133 final Properties buildMetaDataProperties, final Date currentEnd,
134 final String durationString, final String durationPropertyName)
135 {
136 final Properties projectProperties = helper.getProjectProperties(project);
137 final String previousDurationEnd =
138 projectProperties.getProperty(TMP_BUILD_END);
139 final String diffPropertyName = durationPropertyName + ".diff";
140 if (StringUtils.isNotBlank(previousDurationEnd))
141 {
142 final long previousTimestamp = Long.parseLong(previousDurationEnd);
143 final long difference = currentEnd.getTime() - previousTimestamp;
144 buildMetaDataProperties.setProperty(diffPropertyName,
145 String.valueOf(difference));
146 }
147 else
148 {
149 buildMetaDataProperties.setProperty(diffPropertyName, durationString);
150 }
151
152 projectProperties.setProperty(TMP_BUILD_END,
153 String.valueOf(currentEnd.getTime()));
154 }
155
156 private String createDurationPropertyName()
157 {
158 if (StringUtils.isNotBlank(name))
159 {
160 return Constant.PROP_NAME_BUILD_DURATION + '.' + name;
161 }
162 return Constant.PROP_NAME_BUILD_DURATION;
163 }
164
165
166
167 }