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
f55ca992
Commit
f55ca992
authored
Mar 18, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish zip file detection
parent
08b95926
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
30 deletions
+31
-30
Repackager.java
...ava/org/springframework/boot/loader/tools/Repackager.java
+30
-30
RepackagerTests.java
...rg/springframework/boot/loader/tools/RepackagerTests.java
+1
-0
No files found.
spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java
View file @
f55ca992
...
@@ -19,8 +19,8 @@ package org.springframework.boot.loader.tools;
...
@@ -19,8 +19,8 @@ package org.springframework.boot.loader.tools;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.jar.JarFile
;
import
java.util.jar.JarFile
;
import
java.util.jar.Manifest
;
import
java.util.jar.Manifest
;
...
@@ -35,14 +35,14 @@ import org.springframework.boot.loader.tools.MainClassFinder.ClassNameCallback;
...
@@ -35,14 +35,14 @@ import org.springframework.boot.loader.tools.MainClassFinder.ClassNameCallback;
*/
*/
public
class
Repackager
{
public
class
Repackager
{
private
static
final
byte
[]
ZIP_FILE_HEADER
=
new
byte
[]
{
'P'
,
'K'
,
3
,
4
};
private
static
final
String
MAIN_CLASS_ATTRIBUTE
=
"Main-Class"
;
private
static
final
String
MAIN_CLASS_ATTRIBUTE
=
"Main-Class"
;
private
static
final
String
START_CLASS_ATTRIBUTE
=
"Start-Class"
;
private
static
final
String
START_CLASS_ATTRIBUTE
=
"Start-Class"
;
private
static
final
String
BOOT_VERSION_ATTRIBUTE
=
"Spring-Boot-Version"
;
private
static
final
String
BOOT_VERSION_ATTRIBUTE
=
"Spring-Boot-Version"
;
private
static
final
byte
[]
ZIP_FILE_HEADER
=
new
byte
[]
{
'P'
,
'K'
,
3
,
4
};
private
String
mainClass
;
private
String
mainClass
;
private
boolean
backupSource
=
true
;
private
boolean
backupSource
=
true
;
...
@@ -142,12 +142,11 @@ public class Repackager {
...
@@ -142,12 +142,11 @@ public class Repackager {
try
{
try
{
writer
.
writeManifest
(
buildManifest
(
sourceJar
));
writer
.
writeManifest
(
buildManifest
(
sourceJar
));
writer
.
writeEntries
(
sourceJar
);
writer
.
writeEntries
(
sourceJar
);
libraries
.
doWithLibraries
(
new
LibraryCallback
()
{
libraries
.
doWithLibraries
(
new
LibraryCallback
()
{
@Override
@Override
public
void
library
(
File
file
,
LibraryScope
scope
)
throws
IOException
{
public
void
library
(
File
file
,
LibraryScope
scope
)
throws
IOException
{
if
(
isZip
(
file
))
{
if
(
isZipFile
(
file
))
{
String
destination
=
Repackager
.
this
.
layout
String
destination
=
Repackager
.
this
.
layout
.
getLibraryDestination
(
file
.
getName
(),
scope
);
.
getLibraryDestination
(
file
.
getName
(),
scope
);
if
(
destination
!=
null
)
{
if
(
destination
!=
null
)
{
...
@@ -155,31 +154,8 @@ public class Repackager {
...
@@ -155,31 +154,8 @@ public class Repackager {
}
}
}
}
}
}
private
boolean
isZipFile
(
File
file
)
{
byte
[]
buffer
=
new
byte
[
4
];
FileInputStream
fis
=
null
;
try
{
fis
=
new
FileInputStream
(
file
);
int
read
=
fis
.
read
(
buffer
);
return
(
read
==
4
&&
Arrays
.
equals
(
buffer
,
ZIP_FILE_HEADER
));
}
catch
(
IOException
ioe
)
{
return
false
;
}
finally
{
if
(
fis
!=
null
)
{
try
{
fis
.
close
();
}
catch
(
IOException
ioe
)
{
// Close quietly
}
}
}
}
});
});
if
(!(
this
.
layout
instanceof
Layouts
.
None
))
{
if
(!(
this
.
layout
instanceof
Layouts
.
None
))
{
writer
.
writeLoaderClasses
();
writer
.
writeLoaderClasses
();
}
}
...
@@ -194,6 +170,30 @@ public class Repackager {
...
@@ -194,6 +170,30 @@ public class Repackager {
}
}
}
}
private
boolean
isZip
(
File
file
)
{
try
{
FileInputStream
fileInputStream
=
new
FileInputStream
(
file
);
try
{
return
isZip
(
fileInputStream
);
}
finally
{
fileInputStream
.
close
();
}
}
catch
(
IOException
ex
)
{
return
false
;
}
}
private
boolean
isZip
(
InputStream
inputStream
)
throws
IOException
{
for
(
int
i
=
0
;
i
<
ZIP_FILE_HEADER
.
length
;
i
++)
{
if
(
inputStream
.
read
()
!=
ZIP_FILE_HEADER
[
i
])
{
return
false
;
}
}
return
true
;
}
private
Manifest
buildManifest
(
JarFile
source
)
throws
IOException
{
private
Manifest
buildManifest
(
JarFile
source
)
throws
IOException
{
Manifest
manifest
=
source
.
getManifest
();
Manifest
manifest
=
source
.
getManifest
();
if
(
manifest
==
null
)
{
if
(
manifest
==
null
)
{
...
...
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java
View file @
f55ca992
...
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.mock;
...
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link Repackager}.
* Tests for {@link Repackager}.
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
*/
*/
public
class
RepackagerTests
{
public
class
RepackagerTests
{
...
...
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