You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2017/04/16 18:35:47 UTC

svn commit: r1791617 - in /maven/plugins/trunk/maven-dependency-plugin/src: main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java

Author: michaelo
Date: Sun Apr 16 18:35:47 2017
New Revision: 1791617

URL: http://svn.apache.org/viewvc?rev=1791617&view=rev
Log:
[MDEP-428] Unpack goal does not fail build when destination could not be created and unpacks to current working directory instead

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

Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java?rev=1791617&r1=1791616&r2=1791617&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java Sun Apr 16 18:35:47 2017
@@ -219,6 +219,11 @@ public abstract class AbstractDependency
             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() )
             {

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java?rev=1791617&r1=1791616&r2=1791617&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java Sun Apr 16 18:35:47 2017
@@ -173,6 +173,41 @@ public class TestUnpackMojo
         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
     {