]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Do dependency management and unpacking itself
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 23 Apr 2009 20:11:10 +0000 (20:11 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 23 Apr 2009 20:11:10 +0000 (20:11 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk/maven@2336 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

maven-argeo-qooxdoo-plugin/pom.xml
maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java
maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java
maven-argeo-qooxdoo-plugin/src/main/resources/META-INF/maven/lifecycle.xml [deleted file]

index 1092ec48e22fff3b75da7d53efa746809cb9f82d..29bb3db34229ad809fc41638658780180ea8c664 100644 (file)
@@ -3,7 +3,7 @@
        <groupId>org.argeo.slc.maven</groupId>\r
        <artifactId>maven-argeo-qooxdoo-plugin\r
        </artifactId>\r
-       <version>0.8.1.2</version>\r
+       <version>0.8.1.3</version>\r
        <packaging>maven-plugin</packaging>\r
        <name>Argeo Qooxdoo Plugin</name>\r
 \r
                        <artifactId>maven-project</artifactId>\r
                        <version>2.0.7</version>\r
                </dependency>\r
+               <dependency>\r
+                       <groupId>org.codehaus.plexus</groupId>\r
+                       <artifactId>plexus-archiver</artifactId>\r
+                       <version>1.0-alpha-9</version>\r
+                       <exclusions>\r
+                               <exclusion>\r
+                                       <groupId>org.codehaus.plexus</groupId>\r
+                                       <artifactId>plexus-container-default\r
+                                       </artifactId>\r
+                               </exclusion>\r
+                               <exclusion>\r
+                                       <groupId>org.codehaus.plexus</groupId>\r
+                                       <artifactId>plexus-component-api</artifactId>\r
+                               </exclusion>\r
+                       </exclusions>\r
+               </dependency>\r
        </dependencies>\r
        <distributionManagement>\r
                <repository>\r
index e3b3f50928cf0db20fa661c06ece64cebf7ccc2e..c1326be39e0e9b9661e9b2d556a0ec8a9bb95fec 100644 (file)
 package org.argeo.slc.maven.plugins.qooxdoo;
 
+import java.io.File;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 
 /**
- * Prepares Jython / Qooxdoo environment
+ * Prepares Qooxdoo environment
  * 
  * @goal env
- * @execute lifecycle="env" phase="initialize"
  */
 public class EnvironmentMojo extends AbstractMojo {
+       /**
+        * Used to look up Artifacts in the remote repository.
+        * 
+        * @parameter expression=
+        *            "${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+        * @required
+        * @readonly
+        */
+       protected org.apache.maven.artifact.factory.ArtifactFactory factory;
+
+       /**
+        * Used to look up Artifacts in the remote repository.
+        * 
+        * @parameter expression=
+        *            "${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+        * @required
+        * @readonly
+        */
+       protected org.apache.maven.artifact.resolver.ArtifactResolver resolver;
+
+       /**
+        * Location of the local repository.
+        * 
+        * @parameter expression="${localRepository}"
+        * @readonly
+        * @required
+        */
+       protected org.apache.maven.artifact.repository.ArtifactRepository local;
+
+       /**
+        * List of Remote Repositories used by the resolver
+        * 
+        * @parameter expression="${project.remoteArtifactRepositories}"
+        * @readonly
+        * @required
+        */
+       protected java.util.List remoteRepos;
+       /**
+        * To look up Archiver/UnArchiver implementations
+        * 
+        * @parameter expression=
+        *            "${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
+        * @required
+        * @readonly
+        */
+       protected ArchiverManager archiverManager;
+
+       /**
+        * Source base where Qooxdoo SDK will be unpacked
+        * 
+        * @parameter expression="${srcBase}" default-value="src"
+        * @required
+        */
+       private File srcBase;
+
+       private String qxSdkDirName = "qooxdoo-sdk";
+
+       private String qxSdkGroupId = "org.argeo.dep.dist";
+       private String qxSdkArtifactId = "qooxdoo-sdk";
+       private String qxSdkClassifier = "dist";
+       private String qxSdkVersion = "0.8.1.argeo.1";
+       private String qxSdkType = "zip";
 
        public void execute() throws MojoExecutionException, MojoFailureException {
+               Artifact qxSdkArtifact = getQxSdkArtifact();
+               File qxSdkDir = new File(srcBase.getPath() + File.separator
+                               + qxSdkDirName);
+               if (!qxSdkDir.exists())
+                       unpackArtifact(qxSdkArtifact, srcBase);
+               else
+                       getLog()
+                                       .warn("Qooxdoo SDK already unpacked, skipping unpacking...");
                getLog().info("Qooxdoo environment prepared");
        }
 
+       protected Artifact getQxSdkArtifact() throws MojoExecutionException {
+               VersionRange vr;
+               try {
+                       vr = VersionRange.createFromVersionSpec(qxSdkVersion);
+               } catch (InvalidVersionSpecificationException e1) {
+                       e1.printStackTrace();
+                       vr = VersionRange.createFromVersion(qxSdkVersion);
+               }
+
+               Artifact qxSdkArtifact = factory.createDependencyArtifact(qxSdkGroupId,
+                               qxSdkArtifactId, vr, qxSdkType, qxSdkClassifier,
+                               Artifact.SCOPE_COMPILE);
+               try {
+                       resolver.resolve(qxSdkArtifact, remoteRepos, local);
+               } catch (ArtifactResolutionException e) {
+                       throw new MojoExecutionException("Unable to resolve artifact.", e);
+               } catch (ArtifactNotFoundException e) {
+                       throw new MojoExecutionException("Unable to find artifact.", e);
+               }
+
+               return qxSdkArtifact;
+       }
+
+       protected void unpackArtifact(Artifact artifact, File location)
+                       throws MojoExecutionException {
+               File file = artifact.getFile();
+               try {
+                       UnArchiver unArchiver;
+                       unArchiver = archiverManager.getUnArchiver(file);
+                       unArchiver.setSourceFile(file);
+                       unArchiver.setDestDirectory(location);
+                       unArchiver.extract();
+               } catch (NoSuchArchiverException e) {
+                       throw new MojoExecutionException("Unknown archiver type", e);
+               } catch (ArchiverException e) {
+                       e.printStackTrace();
+                       throw new MojoExecutionException("Error unpacking file: " + file
+                                       + " to: " + location + "\r\n" + e.toString(), e);
+               }
+       }
 }
index 3138fbc4eea11a40582d2efb631b09e472cf98d6..61988cbd0cbe8d6472f52ae173cd599ed850914a 100644 (file)
@@ -24,14 +24,13 @@ public class GenerateMojo extends AbstractMojo {
         * @required
         */
        private String job;
-
+       
        /**
         * Location of the qooxdoo sdk.
         * 
-        * @parameter expression="${qooxdooSdk}"
+        * @parameter expression="${qooxdooSdk}" default-value="src/qooxdoo-sdk"
         */
-       private String qooxdooSdk = "src" + File.separator + "main"
-                       + File.separator + "webapp" + File.separator + "qooxdoo-sdk";
+       private String qooxdooSdk;
 
        /**
         * The build directory.
@@ -79,7 +78,7 @@ public class GenerateMojo extends AbstractMojo {
 
                } catch (Exception e) {
                        throw new MojoExecutionException(
-                                       "Unexpected exception when running Jython", e);
+                                       "Unexpected exception when running Python", e);
                }
 
        }
diff --git a/maven-argeo-qooxdoo-plugin/src/main/resources/META-INF/maven/lifecycle.xml b/maven-argeo-qooxdoo-plugin/src/main/resources/META-INF/maven/lifecycle.xml
deleted file mode 100644 (file)
index 919033f..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<lifecycles>
-       <lifecycle>
-               <id>env</id>
-               <phases>
-                       <phase>
-                               <id>initialize</id>
-                               <executions>
-                                       <execution>
-                                               <goals>
-                                                       <goal>org.apache.maven.plugins:maven-antrun-plugin:run</goal>
-                                               </goals>
-                                               <configuration>
-                                                       <tasks>
-                                                               <!-- Removes qooxdoo-sdk -->
-                                                               <delete dir="${basedir}/src/main/webapp/qooxdoo-sdk"
-                                                                       failonerror="false" />
-                                                       </tasks>
-                                               </configuration>
-                                       </execution>
-                                       <execution>
-                                               <goals>
-                                                       <goal>org.apache.maven.plugins:maven-dependency-plugin:unpack
-                                                       </goal>
-                                               </goals>
-                                               <configuration>
-                                                       <artifactItems>
-                                                               <artifactItem>
-                                                                       <groupId>org.argeo.dep.dist</groupId>
-                                                                       <artifactId>qooxdoo-sdk</artifactId>
-                                                                       <classifier>dist</classifier>
-                                                                       <version>0.8.1.argeo.1</version>
-                                                                       <type>zip</type>
-                                                                       <outputDirectory>${basedir}/src/main/webapp
-                                                                       </outputDirectory>
-                                                                       <overWrite>false</overWrite>
-                                                               </artifactItem>
-                                                       </artifactItems>
-                                               </configuration>
-                                       </execution>
-                               </executions>
-                       </phase>
-                       <phase>
-                               <id>clean</id>
-                               <executions>
-                               </executions>
-                       </phase>
-               </phases>
-       </lifecycle>
-</lifecycles>