View Javadoc

1   /*
2    * Copyright (C) 2000 - 2008 Grid Systems, S.A.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License, version 2, as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11   * GNU General Public License for more details.
12   *
13   * You should have received a copy of the GNU General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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   * Goal for parsing the tag file.
26   *
27   * @goal tag
28   * @phase validate
29   *
30   * @author Rodrigo Ruiz
31   */
32  public class TagVersionMojo extends AbstractFuraBuildMojo {
33  
34    /**
35     * {@inheritDoc}
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     * <p>Verifies that the project version is "compatible" with the parsed tag version.</p>
57     *
58     * <p>They will be considered compatible if they share the same major and minor version
59     * numbers.</p>
60     *
61     * @throws MojoExecutionException If the project version is not compatible
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  }