Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
b5553734
Commit
b5553734
authored
Dec 08, 2017
by
GregDThomas
Committed by
daryl herzmann
Dec 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for SNAPSHOT style versioning now Maven is a first class build tool. (#958)
parent
7e2f1fc5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
14 deletions
+56
-14
Version.java
src/java/org/jivesoftware/util/Version.java
+22
-10
VersionTest.java
src/test/java/org/jivesoftware/util/VersionTest.java
+34
-4
No files found.
src/java/org/jivesoftware/util/Version.java
View file @
b5553734
...
...
@@ -28,6 +28,7 @@ import java.util.regex.Pattern;
public
final
class
Version
implements
Comparable
<
Version
>
{
private
static
final
Pattern
PATTERN
=
Pattern
.
compile
(
"(\\d+)\\.(\\d+)\\.(\\d+)(?:\\s+(\\w+))?(?:\\s+(\\d+))?"
);
private
static
final
Pattern
SNAPSHOT_PATTERN
=
Pattern
.
compile
(
"(?i)(\\d+)\\.(\\d+)\\.(\\d+)(?:\\.(\\d+))?-SNAPSHOT"
);
/**
* The major number (ie 1.x.x).
...
...
@@ -111,16 +112,22 @@ public final class Version implements Comparable<Version> {
}
else
{
this
.
statusVersion
=
-
1
;
}
}
else
{
this
.
major
=
this
.
minor
=
this
.
micro
=
0
;
this
.
statusVersion
=
-
1
;
this
.
status
=
ReleaseStatus
.
Release
;
return
;
}
final
Matcher
snapshotMatcher
=
SNAPSHOT_PATTERN
.
matcher
(
source
);
if
(
snapshotMatcher
.
matches
())
{
major
=
Integer
.
parseInt
(
snapshotMatcher
.
group
(
1
));
minor
=
Integer
.
parseInt
(
snapshotMatcher
.
group
(
2
));
micro
=
Integer
.
parseInt
(
snapshotMatcher
.
group
(
3
));
status
=
ReleaseStatus
.
Snapshot
;
final
String
statusVersionString
=
snapshotMatcher
.
group
(
4
);
statusVersion
=
statusVersionString
==
null
?
-
1
:
Integer
.
parseInt
(
statusVersionString
);
return
;
}
}
else
{
this
.
major
=
this
.
minor
=
this
.
micro
=
0
;
this
.
statusVersion
=
-
1
;
this
.
status
=
ReleaseStatus
.
Release
;
}
this
.
major
=
this
.
minor
=
this
.
micro
=
0
;
this
.
statusVersion
=
-
1
;
this
.
status
=
ReleaseStatus
.
Release
;
}
/**
...
...
@@ -133,7 +140,12 @@ public final class Version implements Comparable<Version> {
if
(
versionString
==
null
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
major
).
append
(
'.'
).
append
(
minor
).
append
(
'.'
).
append
(
micro
);
if
(
status
!=
ReleaseStatus
.
Release
||
statusVersion
!=
-
1
)
{
if
(
status
==
ReleaseStatus
.
Snapshot
)
{
if
(
statusVersion
>=
0
)
{
sb
.
append
(
'.'
).
append
(
statusVersion
);
}
sb
.
append
(
"-SNAPSHOT"
);
}
else
if
(
status
!=
ReleaseStatus
.
Release
||
statusVersion
!=
-
1
)
{
sb
.
append
(
' '
).
append
(
status
);
if
(
statusVersion
>=
0
)
{
sb
.
append
(
' '
).
append
(
statusVersion
);
...
...
@@ -196,7 +208,7 @@ public final class Version implements Comparable<Version> {
* are indicated by type safe enum constants.
*/
public
enum
ReleaseStatus
{
Release
(
"Release"
),
Release_Candidate
(
"RC"
),
Beta
(
"Beta"
),
Alpha
(
"Alpha"
);
Release
(
"Release"
),
Release_Candidate
(
"RC"
),
Beta
(
"Beta"
),
Alpha
(
"Alpha"
)
,
Snapshot
(
"Snapshot"
)
;
private
String
status
;
...
...
src/test/java/org/jivesoftware/util/VersionTest.java
View file @
b5553734
package
org
.
jivesoftware
.
util
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
org.jivesoftware.util.Version.ReleaseStatus
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
VersionTest
{
@Test
...
...
@@ -100,4 +102,32 @@ public class VersionTest {
assertEquals
(
version1
,
version2
);
assertTrue
((
version1
.
compareTo
(
version2
)
==
0
)
==
version1
.
equals
(
version2
));
}
@Test
public
void
willVersionAThreeDigitSnapshot
()
throws
Exception
{
final
String
versionString
=
"1.2.3-SNAPSHOT"
;
Version
test
=
new
Version
(
versionString
);
assertThat
(
test
.
getMajor
(),
is
(
1
));
assertThat
(
test
.
getMinor
(),
is
(
2
));
assertThat
(
test
.
getMicro
(),
is
(
3
));
assertThat
(
test
.
getStatusVersion
(),
is
(-
1
));
assertThat
(
test
.
getStatus
(),
is
(
ReleaseStatus
.
Snapshot
));
assertThat
(
test
.
getVersionString
(),
is
(
versionString
));
}
@Test
public
void
willVersionAFourDigitSnapshot
()
throws
Exception
{
final
String
versionString
=
"1.2.3.4-snapshot"
;
Version
test
=
new
Version
(
versionString
);
assertThat
(
test
.
getMajor
(),
is
(
1
));
assertThat
(
test
.
getMinor
(),
is
(
2
));
assertThat
(
test
.
getMicro
(),
is
(
3
));
assertThat
(
test
.
getStatusVersion
(),
is
(
4
));
assertThat
(
test
.
getStatus
(),
is
(
ReleaseStatus
.
Snapshot
));
assertThat
(
test
.
getVersionString
(),
is
(
versionString
.
toUpperCase
()));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment