Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
DEMO
spring-boot
Commits
4a8d3532
Commit
4a8d3532
authored
Mar 31, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
5b2f0ea0
751cd6e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
9 deletions
+32
-9
GitProperties.java
...ain/java/org/springframework/boot/info/GitProperties.java
+5
-1
GitPropertiesTests.java
...ava/org/springframework/boot/info/GitPropertiesTests.java
+27
-8
No files found.
spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java
View file @
4a8d3532
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -54,6 +54,10 @@ public class GitProperties extends InfoProperties {
...
@@ -54,6 +54,10 @@ public class GitProperties extends InfoProperties {
* @return the short commit id
* @return the short commit id
*/
*/
public
String
getShortCommitId
()
{
public
String
getShortCommitId
()
{
String
shortId
=
get
(
"commit.id.abbrev"
);
if
(
shortId
!=
null
)
{
return
shortId
;
}
String
id
=
getCommitId
();
String
id
=
getCommitId
();
if
(
id
==
null
)
{
if
(
id
==
null
)
{
return
null
;
return
null
;
...
...
spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java
View file @
4a8d3532
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -32,7 +32,7 @@ public class GitPropertiesTests {
...
@@ -32,7 +32,7 @@ public class GitPropertiesTests {
@Test
@Test
public
void
basicInfo
()
{
public
void
basicInfo
()
{
GitProperties
properties
=
new
GitProperties
(
GitProperties
properties
=
new
GitProperties
(
createProperties
(
"master"
,
"abcdefghijklmno"
,
"1457527123"
));
createProperties
(
"master"
,
"abcdefghijklmno"
,
"
abcdefg"
,
"
1457527123"
));
assertThat
(
properties
.
getBranch
()).
isEqualTo
(
"master"
);
assertThat
(
properties
.
getBranch
()).
isEqualTo
(
"master"
);
assertThat
(
properties
.
getCommitId
()).
isEqualTo
(
"abcdefghijklmno"
);
assertThat
(
properties
.
getCommitId
()).
isEqualTo
(
"abcdefghijklmno"
);
assertThat
(
properties
.
getShortCommitId
()).
isEqualTo
(
"abcdefg"
);
assertThat
(
properties
.
getShortCommitId
()).
isEqualTo
(
"abcdefg"
);
...
@@ -50,7 +50,7 @@ public class GitPropertiesTests {
...
@@ -50,7 +50,7 @@ public class GitPropertiesTests {
@Test
@Test
public
void
coerceEpochSecond
()
{
public
void
coerceEpochSecond
()
{
GitProperties
properties
=
new
GitProperties
(
GitProperties
properties
=
new
GitProperties
(
createProperties
(
"master"
,
"abcdefg"
,
"1457527123"
));
createProperties
(
"master"
,
"abcdefg"
,
null
,
"1457527123"
));
assertThat
(
properties
.
getCommitTime
()).
isNotNull
();
assertThat
(
properties
.
getCommitTime
()).
isNotNull
();
assertThat
(
properties
.
get
(
"commit.time"
)).
isEqualTo
(
"1457527123000"
);
assertThat
(
properties
.
get
(
"commit.time"
)).
isEqualTo
(
"1457527123000"
);
assertThat
(
properties
.
getCommitTime
().
getTime
()).
isEqualTo
(
1457527123000L
);
assertThat
(
properties
.
getCommitTime
().
getTime
()).
isEqualTo
(
1457527123000L
);
...
@@ -59,7 +59,7 @@ public class GitPropertiesTests {
...
@@ -59,7 +59,7 @@ public class GitPropertiesTests {
@Test
@Test
public
void
coerceDateString
()
{
public
void
coerceDateString
()
{
GitProperties
properties
=
new
GitProperties
(
GitProperties
properties
=
new
GitProperties
(
createProperties
(
"master"
,
"abcdefg"
,
"2016-03-04T14:36:33+0100"
));
createProperties
(
"master"
,
"abcdefg"
,
null
,
"2016-03-04T14:36:33+0100"
));
assertThat
(
properties
.
getCommitTime
()).
isNotNull
();
assertThat
(
properties
.
getCommitTime
()).
isNotNull
();
assertThat
(
properties
.
get
(
"commit.time"
)).
isEqualTo
(
"1457098593000"
);
assertThat
(
properties
.
get
(
"commit.time"
)).
isEqualTo
(
"1457098593000"
);
assertThat
(
properties
.
getCommitTime
().
getTime
()).
isEqualTo
(
1457098593000L
);
assertThat
(
properties
.
getCommitTime
().
getTime
()).
isEqualTo
(
1457098593000L
);
...
@@ -68,24 +68,43 @@ public class GitPropertiesTests {
...
@@ -68,24 +68,43 @@ public class GitPropertiesTests {
@Test
@Test
public
void
coerceUnsupportedFormat
()
{
public
void
coerceUnsupportedFormat
()
{
GitProperties
properties
=
new
GitProperties
(
GitProperties
properties
=
new
GitProperties
(
createProperties
(
"master"
,
"abcdefg"
,
"2016-03-04 15:22:24"
));
createProperties
(
"master"
,
"abcdefg"
,
null
,
"2016-03-04 15:22:24"
));
assertThat
(
properties
.
getCommitTime
()).
isNull
();
assertThat
(
properties
.
getCommitTime
()).
isNull
();
assertThat
(
properties
.
get
(
"commit.time"
)).
isEqualTo
(
"2016-03-04 15:22:24"
);
assertThat
(
properties
.
get
(
"commit.time"
)).
isEqualTo
(
"2016-03-04 15:22:24"
);
}
}
@Test
@Test
public
void
short
enCommitId
()
{
public
void
short
CommitUsedIfPresent
()
{
GitProperties
properties
=
new
GitProperties
(
GitProperties
properties
=
new
GitProperties
(
createProperties
(
"master"
,
"abc"
,
"1457527123"
));
createProperties
(
"master"
,
"abcdefghijklmno"
,
"abcdefgh"
,
"1457527123"
));
assertThat
(
properties
.
getCommitId
()).
isEqualTo
(
"abcdefghijklmno"
);
assertThat
(
properties
.
getShortCommitId
()).
isEqualTo
(
"abcdefgh"
);
}
@Test
public
void
shortenCommitIdShorterThan7
()
{
GitProperties
properties
=
new
GitProperties
(
createProperties
(
"master"
,
"abc"
,
null
,
"1457527123"
));
assertThat
(
properties
.
getCommitId
()).
isEqualTo
(
"abc"
);
assertThat
(
properties
.
getCommitId
()).
isEqualTo
(
"abc"
);
assertThat
(
properties
.
getShortCommitId
()).
isEqualTo
(
"abc"
);
assertThat
(
properties
.
getShortCommitId
()).
isEqualTo
(
"abc"
);
}
}
@Test
public
void
shortenCommitIdLongerThan7
()
{
GitProperties
properties
=
new
GitProperties
(
createProperties
(
"master"
,
"abcdefghijklmno"
,
null
,
"1457527123"
));
assertThat
(
properties
.
getCommitId
()).
isEqualTo
(
"abcdefghijklmno"
);
assertThat
(
properties
.
getShortCommitId
()).
isEqualTo
(
"abcdefg"
);
}
private
static
Properties
createProperties
(
String
branch
,
String
commitId
,
private
static
Properties
createProperties
(
String
branch
,
String
commitId
,
String
commitTime
)
{
String
commit
IdAbbrev
,
String
commit
Time
)
{
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
properties
.
put
(
"branch"
,
branch
);
properties
.
put
(
"branch"
,
branch
);
properties
.
put
(
"commit.id"
,
commitId
);
properties
.
put
(
"commit.id"
,
commitId
);
if
(
commitIdAbbrev
!=
null
)
{
properties
.
put
(
"commit.id.abbrev"
,
commitIdAbbrev
);
}
properties
.
put
(
"commit.time"
,
commitTime
);
properties
.
put
(
"commit.time"
,
commitTime
);
return
properties
;
return
properties
;
}
}
...
...
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