Package: MavenVersionNumberConverter

MavenVersionNumberConverter

nameinstructionbranchcomplexitylinemethod
MavenVersionNumberConverter()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
convertToOsgi(String)
M: 0 C: 35
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.bundlor.maven.plugin.internal;
13:
14: import java.util.regex.Matcher;
15: import java.util.regex.Pattern;
16:
17: public final class MavenVersionNumberConverter {
18:
19: private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)(\\.\\d+)?(\\.\\d+)?([\\.-]{1}.*)?");
20:
21: public String convertToOsgi(String mavenVersionNumber) {
22: VersionBuilder versionBuilder = new VersionBuilder();
23:
24: Matcher matcher = VERSION_PATTERN.matcher(mavenVersionNumber);
25: matcher.find();
26: versionBuilder.setMajor(matcher.group(1));
27: versionBuilder.setMinor(matcher.group(2));
28: versionBuilder.setMicro(matcher.group(3));
29: versionBuilder.setQualifier(matcher.group(4));
30:
31: return versionBuilder.getVersionString();
32: }
33:
34: private static class VersionBuilder {
35:
36: private volatile String major = "0";
37:
38: private volatile String minor = "0";
39:
40: private volatile String micro = "0";
41:
42: private volatile String qualifier = null;
43:
44: public void setMajor(String major) {
45: if (major != null) {
46: this.major = major;
47: }
48: }
49:
50: public void setMinor(String minor) {
51: if (minor != null) {
52: this.minor = trim(minor);
53: }
54: }
55:
56: public void setMicro(String micro) {
57: if (micro != null) {
58: this.micro = trim(micro);
59: }
60: }
61:
62: public void setQualifier(String qualifier) {
63: if (qualifier != null) {
64: this.qualifier = trim(qualifier).replaceAll("\\.", "_");
65: }
66: }
67:
68: public String getVersionString() {
69: if (qualifier == null) {
70: return String.format("%s.%s.%s", major, minor, micro);
71: }
72: return String.format("%s.%s.%s.%s", major, minor, micro, qualifier);
73: }
74:
75: private String trim(String s) {
76: return s.substring(1);
77: }
78: }
79: }