Skip to content

Commit

Permalink
[MDEP-428] Unpack goal does not fail build when destination could not…
Browse files Browse the repository at this point in the history
… be created and unpacks to current working directory instead

Submitted-by: Dave Moten <davidmoten@gmail.com>

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1791617 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
michael-o committed Apr 16, 2017
1 parent 3082faa commit 5e3c820
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ protected void unpack( Artifact artifact, String type, File location, String inc
logUnpack( file, location, includes, excludes );

location.mkdirs();
if ( !location.exists() )
{
throw new MojoExecutionException(
"Location to write unpacked files to could not be created: " + location );
}

if ( file.isDirectory() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,41 @@ public void testUnpackToLocation()
assertMarkerFiles( list, true );
}

public void testUnpackToLocationWhereLocationCannotBeCreatedThrowsException()
throws Exception
{
List<ArtifactItem> list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts() );
ArtifactItem item = list.get( 0 );
item.setOutputDirectory( new File( mojo.getOutputDirectory(), "testOverride" ) );

mojo.setArtifactItems( list );
final File currentFile = mojo.getOutputDirectory();

// pretend that the output directory cannot be found event after mkdirs has been called by the mojo
// ifor instance in the case when the outputDirectory cannot be created because of permissions on the
// parent of the output directory
mojo.setOutputDirectory( new File( currentFile.getAbsolutePath() ) {

private static final long serialVersionUID = -8559876942040177020L;

@Override
public boolean exists()
{
//this file will always report that it does not exist
return false;
}
});
try
{
mojo.execute();
fail( "Expected Exception Here." );
}
catch ( MojoExecutionException e )
{
// caught the expected exception.
}
}

public void testMissingVersionNotFound()
throws Exception
{
Expand Down

0 comments on commit 5e3c820

Please sign in to comment.