From: Mathieu Baudier Date: Thu, 23 Apr 2009 20:11:10 +0000 (+0000) Subject: Do dependency management and unpacking itself X-Git-Tag: svn/tags/maven-plugins-0.3.0@2542~17 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=1f5048584343d4f784cbe3c35b8afdd06b5fc6b3;p=gpl%2Fargeo-slc.git Do dependency management and unpacking itself git-svn-id: https://svn.argeo.org/slc/trunk/maven@2336 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/maven-argeo-qooxdoo-plugin/pom.xml b/maven-argeo-qooxdoo-plugin/pom.xml index 1092ec48e..29bb3db34 100644 --- a/maven-argeo-qooxdoo-plugin/pom.xml +++ b/maven-argeo-qooxdoo-plugin/pom.xml @@ -3,7 +3,7 @@ org.argeo.slc.maven maven-argeo-qooxdoo-plugin - 0.8.1.2 + 0.8.1.3 maven-plugin Argeo Qooxdoo Plugin @@ -29,6 +29,22 @@ maven-project 2.0.7 + + org.codehaus.plexus + plexus-archiver + 1.0-alpha-9 + + + org.codehaus.plexus + plexus-container-default + + + + org.codehaus.plexus + plexus-component-api + + + diff --git a/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java b/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java index e3b3f5092..c1326be39 100644 --- a/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java +++ b/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java @@ -1,19 +1,139 @@ 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); + } + } } diff --git a/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java b/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java index 3138fbc4e..61988cbd0 100644 --- a/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java +++ b/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java @@ -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 index 919033fd7..000000000 --- a/maven-argeo-qooxdoo-plugin/src/main/resources/META-INF/maven/lifecycle.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - env - - - initialize - - - - org.apache.maven.plugins:maven-antrun-plugin:run - - - - - - - - - - - org.apache.maven.plugins:maven-dependency-plugin:unpack - - - - - - org.argeo.dep.dist - qooxdoo-sdk - dist - 0.8.1.argeo.1 - zip - ${basedir}/src/main/webapp - - false - - - - - - - - clean - - - - - -