[MDEPLOY-109] Have plugin itself respect Maven's online/offline mode
authorBenjamin Bentmann <bentmann@apache.org>
Tue, 11 Aug 2009 16:03:19 +0000 (16:03 +0000)
committerBenjamin Bentmann <bentmann@apache.org>
Tue, 11 Aug 2009 16:03:19 +0000 (16:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@803177 13f79535-47bb-0310-9956-ffa450edef68

src/it/offline/invoker.properties [new file with mode: 0644]
src/it/offline/pom.xml [new file with mode: 0644]
src/it/offline/setup.bsh [new file with mode: 0644]
src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java

diff --git a/src/it/offline/invoker.properties b/src/it/offline/invoker.properties
new file mode 100644 (file)
index 0000000..23bfbd2
--- /dev/null
@@ -0,0 +1,4 @@
+invoker.goals.1 = deploy
+
+invoker.goals.2 = --offline deploy
+invoker.buildResult.2 = failure
diff --git a/src/it/offline/pom.xml b/src/it/offline/pom.xml
new file mode 100644 (file)
index 0000000..c604314
--- /dev/null
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.deploy.om</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <description>
+    Tests that the deployment fails when Maven is in offline mode.
+  </description>
+
+  <properties>
+    <maven.test.skip>true</maven.test.skip>
+  </properties>
+
+  <distributionManagement>
+    <repository>
+      <id>it</id>
+      <url>file:///${basedir}/target/repo</url>
+      <uniqueVersion>false</uniqueVersion>
+    </repository>
+  </distributionManagement>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-install-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.1</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3.1</version>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/offline/setup.bsh b/src/it/offline/setup.bsh
new file mode 100644 (file)
index 0000000..1e30bde
--- /dev/null
@@ -0,0 +1,14 @@
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/deploy/om" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+file = new File( basedir, "target/repo" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
index 08346b2..5382a68 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.maven.artifact.deployer.ArtifactDeployer;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoFailureException;
 
 /**
  * @version $Id$
@@ -50,6 +51,14 @@ public abstract class AbstractDeployMojo
     private ArtifactRepository localRepository;
 
     /**
+     * Flag whether Maven is currently in online/offline mode.
+     * 
+     * @parameter default-value="${settings.offline}"
+     * @readonly
+     */
+    private boolean offline;
+
+    /**
      * Parameter used to update the metadata to make the artifact as release.
      * 
      * @parameter expression="${updateReleaseInfo}" default-value="false"
@@ -77,4 +86,14 @@ public abstract class AbstractDeployMojo
     {
         this.localRepository = localRepository;
     }
+
+    void failIfOffline()
+        throws MojoFailureException
+    {
+        if ( offline )
+        {
+            throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" );
+        }
+    }
+
 }
index f582524..f0df72d 100644 (file)
@@ -195,6 +195,8 @@ public class DeployFileMojo
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
+        failIfOffline();
+
         initProperties();
 
         validateArtifactInformation();
index f5e7abb..3562f41 100644 (file)
@@ -117,13 +117,14 @@ public class DeployMojo
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-        
         if ( skip )
         {
             getLog().info( "Skipping artifact deployment" );
             return;
         }
-        
+
+        failIfOffline();
+
         ArtifactRepository repo = getDeploymentRepository();
 
         String protocol = repo.getProtocol();