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
498ca076
Commit
498ca076
authored
Nov 04, 2013
by
Christian Dupuis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-add Spring-Boot-Commit-Id to MANIFEST.MF of created jars
parent
6b599b84
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
pom.xml
spring-boot-tools/spring-boot-loader-tools/pom.xml
+38
-0
Repackager.java
...ava/org/springframework/boot/loader/tools/Repackager.java
+26
-0
No files found.
spring-boot-tools/spring-boot-loader-tools/pom.xml
View file @
498ca076
...
...
@@ -80,6 +80,44 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
exec-maven-plugin
</artifactId>
<version>
1.1.1
</version>
<executions>
<execution>
<phase>
generate-resources
</phase>
<goals>
<goal>
exec
</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>
git
</executable>
<arguments>
<argument>
log
</argument>
<argument>
--pretty=format:Spring-Boot-Commit-Id: %H
</argument>
<argument>
-n1
</argument>
</arguments>
<outputFile>
${project.build.directory}/build-number.mf
</outputFile>
<successCodes>
<!-- Skip failures due to missing Git or the project not being a Git repo
(needed for add-ons which ultimately extend this POM but don't use Git) -->
<successCode>
0
</successCode>
<successCode>
1
</successCode>
<successCode>
127
</successCode>
<successCode>
128
</successCode>
</successCodes>
</configuration>
</plugin>
<plugin>
<artifactId>
maven-jar-plugin
</artifactId>
<configuration>
<archive>
<manifestFile>
${project.build.directory}/build-number.mf
</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java
View file @
498ca076
...
...
@@ -18,8 +18,10 @@ package org.springframework.boot.loader.tools;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.jar.JarFile
;
import
java.util.jar.Manifest
;
import
java.util.zip.ZipEntry
;
/**
* Utility class that can be used to repackage an archive so that it can be executed using
...
...
@@ -34,6 +36,8 @@ public class Repackager {
private
static
final
String
START_CLASS_ATTRIBUTE
=
"Start-Class"
;
private
static
final
String
BOOT_VERSION_ATTRIBUTE
=
"Spring-Boot-Version"
;
private
static
final
String
GIT_COMMIT_ATTRIBUTE
=
"Spring-Boot-Commit-Id"
;
private
String
mainClass
;
...
...
@@ -181,6 +185,28 @@ public class Repackager {
String
bootVersion
=
getClass
().
getPackage
().
getImplementationVersion
();
manifest
.
getMainAttributes
().
putValue
(
BOOT_VERSION_ATTRIBUTE
,
bootVersion
);
String
gitCommitHash
=
null
;
JarFile
jarFile
=
null
;
try
{
URL
classContainer
=
getClass
().
getProtectionDomain
().
getCodeSource
().
getLocation
();
if
(
classContainer
.
toString
().
endsWith
(
".jar"
))
{
jarFile
=
new
JarFile
(
new
File
(
classContainer
.
toURI
()),
false
);
ZipEntry
manifestEntry
=
jarFile
.
getEntry
(
"META-INF/MANIFEST.MF"
);
gitCommitHash
=
new
Manifest
(
jarFile
.
getInputStream
(
manifestEntry
)).
getMainAttributes
().
getValue
(
GIT_COMMIT_ATTRIBUTE
);
}
}
catch
(
Exception
ignoreAndMoveOn
)
{
}
finally
{
if
(
jarFile
!=
null
)
{
try
{
jarFile
.
close
();
}
catch
(
IOException
ignored
)
{}
}
}
if
(
gitCommitHash
!=
null
&&
gitCommitHash
.
length
()
>
0
)
{
manifest
.
getMainAttributes
().
putValue
(
GIT_COMMIT_ATTRIBUTE
,
gitCommitHash
);
}
return
manifest
;
}
...
...
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