1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.gridsystems.maven.furabuild;
18
19 import java.io.File;
20 import java.util.Properties;
21
22 import org.apache.maven.plugin.MojoExecutionException;
23
24
25
26
27
28
29
30
31
32 public class TagVersionMojo extends AbstractFuraBuildMojo {
33
34
35
36
37 public void execute() throws MojoExecutionException {
38 Properties props = project.getProperties();
39 processLocation(props, location, "tag.version", defaultTag);
40 check();
41
42 if (locations != null && locations.size() > 0) {
43 for (int i = 0; i < locations.size(); i++) {
44 String s = (String)locations.get(i);
45 String[] tokens = s.split(";");
46 if (tokens.length == 3) {
47 processLocation(props, new File(tokens[0]), tokens[1], tokens[2]);
48 } else {
49 throw new MojoExecutionException("Wrong location syntax in '" + s + "'");
50 }
51 }
52 }
53 }
54
55
56
57
58
59
60
61
62
63 private void check() throws MojoExecutionException {
64 Properties props = project.getProperties();
65
66 String tagVersion = props.getProperty("tag.version.major")
67 + "." + props.getProperty("tag.version.minor");
68
69 String projectVersion = project.getVersion();
70 int pos = projectVersion.indexOf('-');
71 String version = (pos == -1) ? projectVersion : projectVersion.substring(0, pos);
72
73 if (!version.equals(tagVersion)) {
74 String v = (pos == -1) ? tagVersion : tagVersion + projectVersion.substring(pos);
75
76 throw new MojoExecutionException("Project/Tag versions incompatible. "
77 + "Change version from " + projectVersion + " to "
78 + v);
79 }
80 }
81 }