01: //////////////////////////////////////////////////////////////////////////////
02: //Clirr: compares two versions of a java library for binary compatibility
03: //Copyright (C) 2004 Lars Kühne
04: //
05: //This library is free software; you can redistribute it and/or
06: //modify it under the terms of the GNU Lesser General Public
07: //License as published by the Free Software Foundation; either
08: //version 2.1 of the License, or (at your option) any later version.
09: //
10: //This library is distributed in the hope that it will be useful,
11: //but WITHOUT ANY WARRANTY; without even the implied warranty of
12: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: //Lesser General Public License for more details.
14: //
15: //You should have received a copy of the GNU Lesser General Public
16: //License along with this library; if not, write to the Free Software
17: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: //////////////////////////////////////////////////////////////////////////////
19:
20: package net.sf.clirr.maven;
21:
22: import java.io.File;
23: import java.util.List;
24:
25: import org.apache.maven.jelly.MavenJellyContext;
26: import org.apache.maven.project.Version;
27: import org.apache.maven.util.HttpUtils;
28:
29: /**
30: * Utility class to manipulate POM version information.
31: *
32: * @author Vincent Massol
33: */
34: public class ClirrUtils {
35: /**
36: * @return the latest released version, which means the latest version
37: * listed in the POM <version> elements with a
38: * <code>tag</code> different from <code>HEAD</code>. Returns
39: * null if no latest released version is found
40: * @param versions the list of {@link Version} objects from the POM
41: */
42: public static String getLatestVersion(List versions) {
43: String result = null;
44:
45: if (!versions.isEmpty()) {
46: int pos = versions.size();
47: while (pos > 0) {
48: Version latestVersion = (Version) versions.get(pos - 1);
49:
50: // Is it a released version?
51: if (!latestVersion.getTag().equalsIgnoreCase("HEAD")) {
52: result = latestVersion.getId();
53: break;
54: } else {
55: pos = pos - 1;
56: }
57: }
58: }
59:
60: return result;
61: }
62:
63: /**
64: * TODO: Add support for proxies
65: */
66: public static void getBaselineJar(MavenJellyContext context)
67: throws Exception {
68: String targetFileName = (String) context
69: .getVariable("clirr.baseline.destination");
70: File targetFile = new File(targetFileName);
71: HttpUtils.getFile((String) context
72: .getVariable("clirr.baseline.url"), targetFile, false,
73: true, null, null, null, null);
74: }
75:
76: }
|