+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.argeo.slc.maven.plugin</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-#Fri Apr 24 16:09:20 CEST 2009
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.source=1.3
+++ /dev/null
-#Fri Apr 24 08:11:23 CEST 2009
-activeProfiles=
-eclipse.preferences.version=1
-fullBuildGoals=process-test-resources
-includeModules=false
-resolveWorkspaceProjects=true
-resourceFilterGoals=process-resources resources\:testResources
-skipCompilerPlugin=true
-version=1
+++ /dev/null
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
- <modelVersion>4.0.0</modelVersion>\r
- <parent>\r
- <groupId>org.argeo.slc.maven</groupId>\r
- <artifactId>slc-maven</artifactId>\r
- <version>0.1.3</version>\r
- <relativePath>..</relativePath>\r
- </parent>\r
- <artifactId>org.argeo.slc.maven.plugin</artifactId>\r
- <version>0.1.3-SNAPSHOT</version>\r
- <packaging>jar</packaging>\r
- <name>Argeo Maven Plugin Development Support</name>\r
-\r
- <build>\r
- <plugins>\r
- <plugin>\r
- <artifactId>maven-compiler-plugin</artifactId>\r
- </plugin>\r
- </plugins>\r
- </build>\r
- <dependencies>\r
- <dependency>\r
- <groupId>org.apache.maven</groupId>\r
- <artifactId>maven-plugin-api</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.apache.maven</groupId>\r
- <artifactId>maven-project</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.codehaus.plexus</groupId>\r
- <artifactId>plexus-archiver</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>commons-io</groupId>\r
- <artifactId>commons-io</artifactId>\r
- </dependency>\r
-\r
- </dependencies>\r
-</project>
+++ /dev/null
-package org.argeo.slc.maven.plugin;
-
-import java.io.File;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-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;
-
-/**
- * Abstract Maven plugin for interacting with dependencies
- */
-public class DefaultMavenDependencyManager implements MavenDependencyManager {
- /**
- * 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;
-
- /**
- * To look up Archiver/UnArchiver implementations
- *
- * @parameter expression=
- * "${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
- * @required
- * @readonly
- */
- protected ArchiverManager archiverManager;
-
- /** @component */
- protected ArtifactMetadataSource artifactMetadataSource;
-
- public DefaultMavenDependencyManager() {
- }
-
- public Artifact getResolvedArtifact(List remoteRepos,
- ArtifactRepository local, String groupId, String artifactId,
- String version, String type, String classifier, String scope)
- throws MojoExecutionException {
- VersionRange vr;
- try {
- vr = VersionRange.createFromVersionSpec(version);
- } catch (InvalidVersionSpecificationException e1) {
- e1.printStackTrace();
- vr = VersionRange.createFromVersion(version);
- }
-
- Artifact qxSdkArtifact = factory.createDependencyArtifact(groupId,
- artifactId, vr, type, classifier, scope);
- 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;
- }
-
- public 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);
- }
- }
-
- public Set getTransitiveProjectDependencies(MavenProject project,
- List remoteRepos, ArtifactRepository local)
- throws InvalidDependencyVersionException,
- ArtifactNotFoundException, ArtifactResolutionException {
- Set artifacts = project.createArtifacts(this.factory, null, null);
-
- ArtifactResolutionResult arr = resolver.resolveTransitively(artifacts,
- project.getArtifact(), local, remoteRepos,
- this.artifactMetadataSource, null);
-
- // Order, just for display
- Set dependencies = new TreeSet(new ArtifactComparator());
- dependencies.addAll(arr.getArtifacts());
- return dependencies;
- }
-
- protected static class ArtifactComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Artifact a1 = (Artifact) o1;
- Artifact a2 = (Artifact) o2;
-
- if (!a1.getGroupId().equals(a2.getGroupId()))
- return a1.getGroupId().compareTo(a2.getGroupId());
- else
- return a1.getArtifactId().compareTo(a2.getArtifactId());
- }
- }
-
-}
+++ /dev/null
-package org.argeo.slc.maven.plugin;
-
-import java.io.File;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-
-public interface MavenDependencyManager {
- String ROLE = MavenDependencyManager.class.getName();
-
- public Artifact getResolvedArtifact(List remoteRepos,
- ArtifactRepository local, String groupId, String artifactId,
- String version, String type, String classifier, String scope)
- throws MojoExecutionException;
-
- public void unpackArtifact(Artifact artifact, File location)
- throws MojoExecutionException;
-
- public Set getTransitiveProjectDependencies(MavenProject project,
- List remoteRepos, ArtifactRepository local)
- throws InvalidDependencyVersionException,
- ArtifactNotFoundException, ArtifactResolutionException;
-}
+++ /dev/null
-package org.argeo.slc.maven.plugin;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-
-import org.apache.commons.io.IOUtils;
-
-public class SystemCall implements Runnable {
- private String execDir;
-
- private String cmd = null;
- private String[] command = null;
-
- private boolean synchronous = true;
- private boolean captureStdIn = false;
-
- public SystemCall() {
-
- }
-
- public SystemCall(String execDir, String cmd, boolean captureStdIn) {
- super();
- this.execDir = execDir;
- this.cmd = cmd;
- this.synchronous = true;
- this.captureStdIn = captureStdIn;
- }
-
- public SystemCall(String execDir, String[] command, boolean captureStdIn) {
- super();
- this.execDir = execDir;
- this.command = command;
- this.synchronous = true;
- this.captureStdIn = captureStdIn;
- }
-
- public void run() {
- try {
- // Execution directory
- File dir = null;
- if (execDir != null) {
- // Replace '/' by local file separator, for portability
- execDir.replace('/', File.separatorChar);
- dir = new File(execDir).getCanonicalFile();
- }
-
- final Process process;
-
- if (cmd != null) {
- process = Runtime.getRuntime().exec(cmd, null, dir);
- } else if (command != null) {
- process = Runtime.getRuntime().exec(command, null, dir);
- ;
- } else {
- throw new RuntimeException("No command specified");
- }
-
- Runtime.getRuntime().addShutdownHook(new Thread() {
-
- public void run() {
- if (process != null) {
- try {
- process.exitValue();
- } catch (Exception e) {
- process.destroy();
- System.err.println("Killed process " + process);
- }
- }
- }
- });
-
- // Manage standard streams
- StreamReaderThread stdOutThread = new StreamReaderThread(process
- .getInputStream(), false);
- stdOutThread.start();
- // TODO: understand why streams are not properly flushed
- StreamReaderThread stdErrThread = new StreamReaderThread(process
- .getInputStream(), false);
- stdErrThread.start();
- if (captureStdIn)
- new StdInThread(process.getOutputStream()).start();
-
- // Wait for the end of the process
- if (synchronous) {
- int exitCode = process.waitFor();
- if (exitCode != 0) {
- Thread.sleep(5000);// leave the process a chance to log
- System.err.println("Process return exit code " + exitCode);
- }
- } else {
- // asynchronous: return
- }
- } catch (Exception e) {
- throw new RuntimeException("Could not execute command " + cmd, e);
- }
-
- }
-
- /**
- * Shortcut method returning the current exec dir if the specified one is
- * null.
- */
- private String getUsedDir(File dir) {
- if (dir == null)
- return System.getProperty("user.dir");
- else
- return dir.getPath();
- }
-
- public void setCmd(String command) {
- this.cmd = command;
- }
-
- public void setExecDir(String execdir) {
- this.execDir = execdir;
- }
-
- public void setCommand(String[] command) {
- this.command = command;
- }
-
- protected synchronized void write(String str, boolean isErr) {
- if (isErr) {
- System.err.print(str);
- System.err.flush();
- } else {
- System.out.print(str);
- System.out.flush();
- }
- notifyAll();
- }
-
- protected class StreamReaderThread extends Thread {
- private final InputStream stream;
- private final boolean isErr;
-
- public StreamReaderThread(InputStream stream, boolean isErr) {
- this.stream = stream;
- this.isErr = isErr;
- }
-
- public void run() {
- // BufferedReader in = null;
- InputStreamReader isr = null;
- try {
- isr = new InputStreamReader(stream);
- int c;
- StringBuffer buf = new StringBuffer(256);
- char lastCr = '\n';
- while ((c = isr.read()) != -1) {
- char cr = (char) c;
-
- buf.append(cr);
-
- boolean write = false;
- if (lastCr == '>' && cr == ' ')
- write = true;
- else if (cr == '\n')
- write = true;
-
- lastCr = cr;
- if (write) {
- write(buf.toString(), isErr);
- buf = new StringBuffer(256);
- }
-
- // if (isErr) {
- // System.err.print(cr);
- // if (cr == '\n' || cr == '>')
- // System.err.flush();
- // } else {
- // System.out.print(cr);
- // if (cr == '\n' || cr == '>')
- // System.out.flush();
- // }
- }
- // String line = null;
- // while ((line = in.readLine()) != null) {
- // stdOutCallback(line);
- // System.out.
- // }
- } catch (IOException e) {
- // catch silently
- // because the other methods
- // to check whether the stream
- // is closed would probably
- // be to costly
- } finally {
- if (synchronous)
- IOUtils.closeQuietly(isr);
- }
- }
- }
-
- protected class StdInThread extends Thread {
- private final OutputStream stream;
-
- public StdInThread(OutputStream stream) {
- this.stream = stream;
- }
-
- public void run() {
- // BufferedReader in = null;
- // Writer out = null;
- InputStreamReader isr = null;
- try {
- // out = new OutputStreamWriter(stream);
- isr = new InputStreamReader(System.in);
- int c;
- while ((c = isr.read()) != -1) {
- stream.write(c);
- stream.flush();
- }
-
- /*
- * in = new BufferedReader(new InputStreamReader(System.in));
- * String line = null; while ((line = in.readLine()) != null) {
- * out.write(line); out.write("\n"); out.flush(); }
- */
- } catch (IOException e) {
- throw new RuntimeException("Could not write to stdin stream", e);
- } finally {
- if (synchronous) {
- IOUtils.closeQuietly(isr);
- // IOUtils.closeQuietly(in);
- // IOUtils.closeQuietly(out);
- }
- }
- }
-
- }
-}
+++ /dev/null
-<component-set>
- <components>
- <component>
- <role>org.argeo.slc.maven.plugin.MavenDependencyManager
- </role>
- <implementation>
- org.argeo.slc.maven.plugin.DefaultMavenDependencyManager
- </implementation>
- <requirements>
- <requirement>
- <role>org.apache.maven.artifact.factory.ArtifactFactory
- </role>
- <field-name>factory</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.artifact.resolver.ArtifactResolver
- </role>
- <field-name>resolver</field-name>
- </requirement>
- <requirement>
- <role>org.codehaus.plexus.archiver.manager.ArchiverManager
- </role>
- <field-name>archiverManager</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.artifact.metadata.ArtifactMetadataSource
- </role>
- <field-name>artifactMetadataSource
- </field-name>
- </requirement>
- </requirements>
- <configuration />
- </component>
- </components>
-</component-set>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.slc.maven.plugin</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Fri Apr 24 16:09:20 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
--- /dev/null
+#Fri Apr 24 08:11:23 CEST 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <parent>\r
+ <groupId>org.argeo.slc.maven</groupId>\r
+ <artifactId>slc-maven</artifactId>\r
+ <version>0.1.3</version>\r
+ <relativePath>..</relativePath>\r
+ </parent>\r
+ <artifactId>org.argeo.slc.maven.plugin</artifactId>\r
+ <version>0.1.3-SNAPSHOT</version>\r
+ <packaging>jar</packaging>\r
+ <name>Argeo Maven Plugin Development Support</name>\r
+\r
+ <build>\r
+ <plugins>\r
+ <plugin>\r
+ <artifactId>maven-compiler-plugin</artifactId>\r
+ </plugin>\r
+ </plugins>\r
+ </build>\r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>org.apache.maven</groupId>\r
+ <artifactId>maven-plugin-api</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.maven</groupId>\r
+ <artifactId>maven-project</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.codehaus.plexus</groupId>\r
+ <artifactId>plexus-archiver</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>commons-io</groupId>\r
+ <artifactId>commons-io</artifactId>\r
+ </dependency>\r
+\r
+ </dependencies>\r
+</project>
--- /dev/null
+package org.argeo.slc.maven.plugin;
+
+import java.io.File;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+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;
+
+/**
+ * Abstract Maven plugin for interacting with dependencies
+ */
+public class DefaultMavenDependencyManager implements MavenDependencyManager {
+ /**
+ * 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;
+
+ /**
+ * To look up Archiver/UnArchiver implementations
+ *
+ * @parameter expression=
+ * "${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
+ * @required
+ * @readonly
+ */
+ protected ArchiverManager archiverManager;
+
+ /** @component */
+ protected ArtifactMetadataSource artifactMetadataSource;
+
+ public DefaultMavenDependencyManager() {
+ }
+
+ public Artifact getResolvedArtifact(List remoteRepos,
+ ArtifactRepository local, String groupId, String artifactId,
+ String version, String type, String classifier, String scope)
+ throws MojoExecutionException {
+ VersionRange vr;
+ try {
+ vr = VersionRange.createFromVersionSpec(version);
+ } catch (InvalidVersionSpecificationException e1) {
+ e1.printStackTrace();
+ vr = VersionRange.createFromVersion(version);
+ }
+
+ Artifact qxSdkArtifact = factory.createDependencyArtifact(groupId,
+ artifactId, vr, type, classifier, scope);
+ 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;
+ }
+
+ public 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);
+ }
+ }
+
+ public Set getTransitiveProjectDependencies(MavenProject project,
+ List remoteRepos, ArtifactRepository local)
+ throws InvalidDependencyVersionException,
+ ArtifactNotFoundException, ArtifactResolutionException {
+ Set artifacts = project.createArtifacts(this.factory, null, null);
+
+ ArtifactResolutionResult arr = resolver.resolveTransitively(artifacts,
+ project.getArtifact(), local, remoteRepos,
+ this.artifactMetadataSource, null);
+
+ // Order, just for display
+ Set dependencies = new TreeSet(new ArtifactComparator());
+ dependencies.addAll(arr.getArtifacts());
+ return dependencies;
+ }
+
+ protected static class ArtifactComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Artifact a1 = (Artifact) o1;
+ Artifact a2 = (Artifact) o2;
+
+ if (!a1.getGroupId().equals(a2.getGroupId()))
+ return a1.getGroupId().compareTo(a2.getGroupId());
+ else
+ return a1.getArtifactId().compareTo(a2.getArtifactId());
+ }
+ }
+
+}
--- /dev/null
+package org.argeo.slc.maven.plugin;
+
+import java.io.File;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+
+public interface MavenDependencyManager {
+ String ROLE = MavenDependencyManager.class.getName();
+
+ public Artifact getResolvedArtifact(List remoteRepos,
+ ArtifactRepository local, String groupId, String artifactId,
+ String version, String type, String classifier, String scope)
+ throws MojoExecutionException;
+
+ public void unpackArtifact(Artifact artifact, File location)
+ throws MojoExecutionException;
+
+ public Set getTransitiveProjectDependencies(MavenProject project,
+ List remoteRepos, ArtifactRepository local)
+ throws InvalidDependencyVersionException,
+ ArtifactNotFoundException, ArtifactResolutionException;
+}
--- /dev/null
+package org.argeo.slc.maven.plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+
+public class SystemCall implements Runnable {
+ private String execDir;
+
+ private String cmd = null;
+ private String[] command = null;
+
+ private boolean synchronous = true;
+ private boolean captureStdIn = false;
+
+ public SystemCall() {
+
+ }
+
+ public SystemCall(String execDir, String cmd, boolean captureStdIn) {
+ super();
+ this.execDir = execDir;
+ this.cmd = cmd;
+ this.synchronous = true;
+ this.captureStdIn = captureStdIn;
+ }
+
+ public SystemCall(String execDir, String[] command, boolean captureStdIn) {
+ super();
+ this.execDir = execDir;
+ this.command = command;
+ this.synchronous = true;
+ this.captureStdIn = captureStdIn;
+ }
+
+ public void run() {
+ try {
+ // Execution directory
+ File dir = null;
+ if (execDir != null) {
+ // Replace '/' by local file separator, for portability
+ execDir.replace('/', File.separatorChar);
+ dir = new File(execDir).getCanonicalFile();
+ }
+
+ final Process process;
+
+ if (cmd != null) {
+ process = Runtime.getRuntime().exec(cmd, null, dir);
+ } else if (command != null) {
+ process = Runtime.getRuntime().exec(command, null, dir);
+ ;
+ } else {
+ throw new RuntimeException("No command specified");
+ }
+
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+
+ public void run() {
+ if (process != null) {
+ try {
+ process.exitValue();
+ } catch (Exception e) {
+ process.destroy();
+ System.err.println("Killed process " + process);
+ }
+ }
+ }
+ });
+
+ // Manage standard streams
+ StreamReaderThread stdOutThread = new StreamReaderThread(process
+ .getInputStream(), false);
+ stdOutThread.start();
+ // TODO: understand why streams are not properly flushed
+ StreamReaderThread stdErrThread = new StreamReaderThread(process
+ .getInputStream(), false);
+ stdErrThread.start();
+ if (captureStdIn)
+ new StdInThread(process.getOutputStream()).start();
+
+ // Wait for the end of the process
+ if (synchronous) {
+ int exitCode = process.waitFor();
+ if (exitCode != 0) {
+ Thread.sleep(5000);// leave the process a chance to log
+ System.err.println("Process return exit code " + exitCode);
+ }
+ } else {
+ // asynchronous: return
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Could not execute command " + cmd, e);
+ }
+
+ }
+
+ /**
+ * Shortcut method returning the current exec dir if the specified one is
+ * null.
+ */
+ private String getUsedDir(File dir) {
+ if (dir == null)
+ return System.getProperty("user.dir");
+ else
+ return dir.getPath();
+ }
+
+ public void setCmd(String command) {
+ this.cmd = command;
+ }
+
+ public void setExecDir(String execdir) {
+ this.execDir = execdir;
+ }
+
+ public void setCommand(String[] command) {
+ this.command = command;
+ }
+
+ protected synchronized void write(String str, boolean isErr) {
+ if (isErr) {
+ System.err.print(str);
+ System.err.flush();
+ } else {
+ System.out.print(str);
+ System.out.flush();
+ }
+ notifyAll();
+ }
+
+ protected class StreamReaderThread extends Thread {
+ private final InputStream stream;
+ private final boolean isErr;
+
+ public StreamReaderThread(InputStream stream, boolean isErr) {
+ this.stream = stream;
+ this.isErr = isErr;
+ }
+
+ public void run() {
+ // BufferedReader in = null;
+ InputStreamReader isr = null;
+ try {
+ isr = new InputStreamReader(stream);
+ int c;
+ StringBuffer buf = new StringBuffer(256);
+ char lastCr = '\n';
+ while ((c = isr.read()) != -1) {
+ char cr = (char) c;
+
+ buf.append(cr);
+
+ boolean write = false;
+ if (lastCr == '>' && cr == ' ')
+ write = true;
+ else if (cr == '\n')
+ write = true;
+
+ lastCr = cr;
+ if (write) {
+ write(buf.toString(), isErr);
+ buf = new StringBuffer(256);
+ }
+
+ // if (isErr) {
+ // System.err.print(cr);
+ // if (cr == '\n' || cr == '>')
+ // System.err.flush();
+ // } else {
+ // System.out.print(cr);
+ // if (cr == '\n' || cr == '>')
+ // System.out.flush();
+ // }
+ }
+ // String line = null;
+ // while ((line = in.readLine()) != null) {
+ // stdOutCallback(line);
+ // System.out.
+ // }
+ } catch (IOException e) {
+ // catch silently
+ // because the other methods
+ // to check whether the stream
+ // is closed would probably
+ // be to costly
+ } finally {
+ if (synchronous)
+ IOUtils.closeQuietly(isr);
+ }
+ }
+ }
+
+ protected class StdInThread extends Thread {
+ private final OutputStream stream;
+
+ public StdInThread(OutputStream stream) {
+ this.stream = stream;
+ }
+
+ public void run() {
+ // BufferedReader in = null;
+ // Writer out = null;
+ InputStreamReader isr = null;
+ try {
+ // out = new OutputStreamWriter(stream);
+ isr = new InputStreamReader(System.in);
+ int c;
+ while ((c = isr.read()) != -1) {
+ stream.write(c);
+ stream.flush();
+ }
+
+ /*
+ * in = new BufferedReader(new InputStreamReader(System.in));
+ * String line = null; while ((line = in.readLine()) != null) {
+ * out.write(line); out.write("\n"); out.flush(); }
+ */
+ } catch (IOException e) {
+ throw new RuntimeException("Could not write to stdin stream", e);
+ } finally {
+ if (synchronous) {
+ IOUtils.closeQuietly(isr);
+ // IOUtils.closeQuietly(in);
+ // IOUtils.closeQuietly(out);
+ }
+ }
+ }
+
+ }
+}
--- /dev/null
+<component-set>
+ <components>
+ <component>
+ <role>org.argeo.slc.maven.plugin.MavenDependencyManager
+ </role>
+ <implementation>
+ org.argeo.slc.maven.plugin.DefaultMavenDependencyManager
+ </implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.artifact.factory.ArtifactFactory
+ </role>
+ <field-name>factory</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.resolver.ArtifactResolver
+ </role>
+ <field-name>resolver</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.archiver.manager.ArchiverManager
+ </role>
+ <field-name>archiverManager</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.metadata.ArtifactMetadataSource
+ </role>
+ <field-name>artifactMetadataSource
+ </field-name>
+ </requirement>
+ </requirements>
+ <configuration />
+ </component>
+ </components>
+</component-set>