-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close resources and check for I/O operation success
- Loading branch information
Showing
5 changed files
with
256 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -754,13 +754,19 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer | |
// Create a temporary work directory | ||
// MEAR-167 use uri as directory to prevent merging of artifacts with the same artifactId | ||
workDirectory = new File( new File( getTempFolder(), "temp" ), module.getUri() ); | ||
workDirectory.mkdirs(); | ||
getLog().debug( "Created a temporary work directory: " + workDirectory.getAbsolutePath() ); | ||
|
||
// Unpack the archive to a temporary work directory | ||
zipUnArchiver.setSourceFile( original ); | ||
zipUnArchiver.setDestDirectory( workDirectory ); | ||
zipUnArchiver.extract(); | ||
if ( workDirectory.mkdirs() ) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
elharo
Author
Contributor
|
||
{ | ||
getLog().debug( "Created a temporary work directory: " + workDirectory.getAbsolutePath() ); | ||
|
||
// Unpack the archive to a temporary work directory | ||
zipUnArchiver.setSourceFile( original ); | ||
zipUnArchiver.setDestDirectory( workDirectory ); | ||
zipUnArchiver.extract(); | ||
} | ||
else | ||
{ | ||
throw new MojoFailureException( "Failed to create directory " + workDirectory ); | ||
} | ||
} | ||
else | ||
{ | ||
|
@@ -772,21 +778,18 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer | |
boolean newMetaInfCreated = metaInfDirectory.mkdirs(); | ||
if ( newMetaInfCreated ) | ||
{ | ||
// CHECKSTYLE_OFF: LineLength | ||
getLog().debug( "This project did not have a META-INF directory before, so a new directory was created." ); | ||
// CHECKSTYLE_ON: LineLength | ||
getLog().debug( | ||
"This project did not have a META-INF directory before, so a new directory was created." ); | ||
} | ||
File newCreatedManifestFile = new File( metaInfDirectory, "MANIFEST.MF" ); | ||
boolean newManifestCreated = newCreatedManifestFile.createNewFile(); | ||
File manifestFile = new File( metaInfDirectory, "MANIFEST.MF" ); | ||
boolean newManifestCreated = manifestFile.createNewFile(); | ||
if ( newManifestCreated ) | ||
{ | ||
// CHECKSTYLE_OFF: LineLength | ||
getLog().debug( "This project did not have a META-INF/MANIFEST.MF file before, so a new file was created." ); | ||
// CHECKSTYLE_ON: LineLength | ||
getLog().debug( | ||
"This project did not have a META-INF/MANIFEST.MF file before, so a new file was created." ); | ||
} | ||
|
||
// Read the manifest from disk | ||
Manifest mf = new Manifest( new FileInputStream( newCreatedManifestFile ) ); | ||
Manifest mf = readManifest( manifestFile ); | ||
Attribute classPath = mf.getMainSection().getAttribute( "Class-Path" ); | ||
List<String> classPathElements = new ArrayList<String>(); | ||
|
||
|
@@ -808,10 +811,8 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer | |
// We use the original name, cause in case of outputFileNameMapping | ||
// we could not not delete it and it will end up in the resulting EAR and the WAR | ||
// will not be cleaned up. | ||
// CHECKSTYLE_OFF: LineLength | ||
File artifact = new File( new File( workDirectory, module.getLibDir() ), | ||
module.getArtifact().getFile().getName() ); | ||
// CHECKSTYLE_ON: LineLength | ||
|
||
// MEAR-217 | ||
// If WAR contains files with timestamps, but EAR strips them away (useBaseVersion=true) | ||
|
@@ -873,7 +874,7 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer | |
mf.getMainSection().addConfiguredAttribute( classPath ); | ||
|
||
// Write the manifest to disk | ||
try ( FileOutputStream out = new FileOutputStream( newCreatedManifestFile ); | ||
try ( FileOutputStream out = new FileOutputStream( manifestFile ); | ||
OutputStreamWriter writer = new OutputStreamWriter( out, StandardCharsets.UTF_8 ) ) | ||
{ | ||
mf.write( writer ); | ||
|
@@ -898,4 +899,15 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer | |
throw new MojoFailureException( e.getMessage(), e ); | ||
} | ||
} | ||
|
||
private static Manifest readManifest( File manifestFile ) | ||
throws IOException | ||
{ | ||
// Read the manifest from disk | ||
try ( FileInputStream in = new FileInputStream( manifestFile ) ) | ||
{ | ||
Manifest manifest = new Manifest( in ); | ||
return manifest; | ||
} | ||
} | ||
} |
Oops, something went wrong.
this breaks builds - mkdirs() also returns false if there was nothing that had to be created (f.e. the directory still exists from a previous run).