Renamed into shared
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 25 Apr 2009 09:49:40 +0000 (09:49 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 25 Apr 2009 09:49:40 +0000 (09:49 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk/maven@2352 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

18 files changed:
org.argeo.slc.maven.plugin/.classpath [deleted file]
org.argeo.slc.maven.plugin/.project [deleted file]
org.argeo.slc.maven.plugin/.settings/org.eclipse.jdt.core.prefs [deleted file]
org.argeo.slc.maven.plugin/.settings/org.maven.ide.eclipse.prefs [deleted file]
org.argeo.slc.maven.plugin/pom.xml [deleted file]
org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java [deleted file]
org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java [deleted file]
org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java [deleted file]
org.argeo.slc.maven.plugin/src/main/resources/META-INF/plexus/components.xml [deleted file]
org.argeo.slc.maven.shared/.classpath [new file with mode: 0644]
org.argeo.slc.maven.shared/.project [new file with mode: 0644]
org.argeo.slc.maven.shared/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
org.argeo.slc.maven.shared/.settings/org.maven.ide.eclipse.prefs [new file with mode: 0644]
org.argeo.slc.maven.shared/pom.xml [new file with mode: 0644]
org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java [new file with mode: 0644]
org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java [new file with mode: 0644]
org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java [new file with mode: 0644]
org.argeo.slc.maven.shared/src/main/resources/META-INF/plexus/components.xml [new file with mode: 0644]

diff --git a/org.argeo.slc.maven.plugin/.classpath b/org.argeo.slc.maven.plugin/.classpath
deleted file mode 100644 (file)
index 0c1a2f0..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?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>
diff --git a/org.argeo.slc.maven.plugin/.project b/org.argeo.slc.maven.plugin/.project
deleted file mode 100644 (file)
index 25790ca..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?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>
diff --git a/org.argeo.slc.maven.plugin/.settings/org.eclipse.jdt.core.prefs b/org.argeo.slc.maven.plugin/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644 (file)
index 1c2c72d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#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
diff --git a/org.argeo.slc.maven.plugin/.settings/org.maven.ide.eclipse.prefs b/org.argeo.slc.maven.plugin/.settings/org.maven.ide.eclipse.prefs
deleted file mode 100644 (file)
index e182abc..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#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
diff --git a/org.argeo.slc.maven.plugin/pom.xml b/org.argeo.slc.maven.plugin/pom.xml
deleted file mode 100644 (file)
index e7cd455..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<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>
diff --git a/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java b/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java
deleted file mode 100644 (file)
index 641b8f2..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-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());
-               }
-       }
-
-}
diff --git a/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java b/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java
deleted file mode 100644 (file)
index 94e715a..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-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;
-}
diff --git a/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java b/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java
deleted file mode 100644 (file)
index 2265cd3..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-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);
-                               }
-                       }
-               }
-
-       }
-}
diff --git a/org.argeo.slc.maven.plugin/src/main/resources/META-INF/plexus/components.xml b/org.argeo.slc.maven.plugin/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644 (file)
index b8203e2..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<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>
diff --git a/org.argeo.slc.maven.shared/.classpath b/org.argeo.slc.maven.shared/.classpath
new file mode 100644 (file)
index 0000000..0c1a2f0
--- /dev/null
@@ -0,0 +1,8 @@
+<?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>
diff --git a/org.argeo.slc.maven.shared/.project b/org.argeo.slc.maven.shared/.project
new file mode 100644 (file)
index 0000000..25790ca
--- /dev/null
@@ -0,0 +1,23 @@
+<?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>
diff --git a/org.argeo.slc.maven.shared/.settings/org.eclipse.jdt.core.prefs b/org.argeo.slc.maven.shared/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..1c2c72d
--- /dev/null
@@ -0,0 +1,12 @@
+#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
diff --git a/org.argeo.slc.maven.shared/.settings/org.maven.ide.eclipse.prefs b/org.argeo.slc.maven.shared/.settings/org.maven.ide.eclipse.prefs
new file mode 100644 (file)
index 0000000..e182abc
--- /dev/null
@@ -0,0 +1,9 @@
+#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
diff --git a/org.argeo.slc.maven.shared/pom.xml b/org.argeo.slc.maven.shared/pom.xml
new file mode 100644 (file)
index 0000000..e7cd455
--- /dev/null
@@ -0,0 +1,41 @@
+<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>
diff --git a/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java b/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java
new file mode 100644 (file)
index 0000000..641b8f2
--- /dev/null
@@ -0,0 +1,136 @@
+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());
+               }
+       }
+
+}
diff --git a/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java b/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java
new file mode 100644 (file)
index 0000000..94e715a
--- /dev/null
@@ -0,0 +1,31 @@
+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;
+}
diff --git a/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java b/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java
new file mode 100644 (file)
index 0000000..2265cd3
--- /dev/null
@@ -0,0 +1,235 @@
+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);
+                               }
+                       }
+               }
+
+       }
+}
diff --git a/org.argeo.slc.maven.shared/src/main/resources/META-INF/plexus/components.xml b/org.argeo.slc.maven.shared/src/main/resources/META-INF/plexus/components.xml
new file mode 100644 (file)
index 0000000..b8203e2
--- /dev/null
@@ -0,0 +1,35 @@
+<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>