Revision 955

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/installer/lib/api/Version.java
56 56
	public boolean check(String op, Version other);
57 57

  
58 58
	public String fullFormat();
59
	
60
	/**
61
	 * Return the version formated as string with the format specified as fmt.
62
	 * It replace in fmt:
63
	 * - %M by the major number of the version
64
	 * - %m by the minor number of the version
65
	 * - %r by the revision number of the version
66
	 * - %c by the classifier of the version
67
	 * - %b by the build number of the version
68
	 * 
69
	 * @param fmt, string used as format
70
	 * @return the version formated as string 
71
	 */
72
	public String format(String fmt);
59 73

  
60 74
	/**
61 75
	 * @deprecated don't use, set only in parse 
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/DefaultVersion.java
167 167

  
168 168
	public String toString() {
169 169
		if (this.classifier == null) {
170
			return MessageFormat.format("{0}.{1}.{2}-{3,number,####}", 
170
			return MessageFormat.format("{0}.{1}.{2}-{4,number,####}", 
171 171
				new Object[] {
172 172
					new Integer(this.major), 
173 173
					new Integer(this.minor), 
......
257 257
		this.build = build;
258 258
		return this;
259 259
	}
260
	
261
	public String format(String fmt) {
262
		String s = fmt;
263
		s = s.replace("%M", String.valueOf(this.major));
264
		s = s.replace("%m", String.valueOf(this.minor));
265
		s = s.replace("%r", String.valueOf(this.rev));
266
		s = s.replace("%c", this.classifier);
267
		s = s.replace("%b", String.valueOf(this.build));
268
		return s;
269
	}
260 270
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/test/java/packageutils/DefaultVersionTest.java
1
package packageutils;
2

  
3
import junit.framework.TestCase;
4

  
5
import org.gvsig.tools.packageutils.impl.DefaultVersion;
6

  
7
public class DefaultVersionTest extends TestCase {
8

  
9
	public void testFormat() {
10
		DefaultVersion v = new DefaultVersion();
11
		v.parse("1.2.3-SNAPSHOT-4");
12
		String s = v.format("%M.%m.%r-%c-%b");
13
		assertEquals("1.2.3-SNAPSHOT-4", s);
14
	}
15
}
0 16

  

Also available in: Unified diff