From: Mathieu Baudier Date: Fri, 12 Jun 2009 15:57:39 +0000 (+0000) Subject: Rename to org.argeo.maven.plugins.shared X-Git-Tag: svn/tags/maven-plugins-0.3.0@2560~4 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=189fbfeae2500b7c8a904387f8285c2db63abe82;p=gpl%2Fargeo-slc.git Rename to org.argeo.maven.plugins.shared git-svn-id: https://svn.argeo.org/maven-plugins/trunk@2544 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.maven.plugins.shared/.classpath b/org.argeo.maven.plugins.shared/.classpath new file mode 100644 index 000000000..0c1a2f036 --- /dev/null +++ b/org.argeo.maven.plugins.shared/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/org.argeo.maven.plugins.shared/.project b/org.argeo.maven.plugins.shared/.project new file mode 100644 index 000000000..a175de63e --- /dev/null +++ b/org.argeo.maven.plugins.shared/.project @@ -0,0 +1,23 @@ + + + org.argeo.slc.maven.shared + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/org.argeo.maven.plugins.shared/.settings/org.eclipse.jdt.core.prefs b/org.argeo.maven.plugins.shared/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..1c2c72d9b --- /dev/null +++ b/org.argeo.maven.plugins.shared/.settings/org.eclipse.jdt.core.prefs @@ -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.maven.plugins.shared/.settings/org.maven.ide.eclipse.prefs b/org.argeo.maven.plugins.shared/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..e182abcb1 --- /dev/null +++ b/org.argeo.maven.plugins.shared/.settings/org.maven.ide.eclipse.prefs @@ -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.maven.plugins.shared/pom.xml b/org.argeo.maven.plugins.shared/pom.xml new file mode 100644 index 000000000..a35fa16f2 --- /dev/null +++ b/org.argeo.maven.plugins.shared/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + + org.argeo.slc.maven + slc-maven + 0.1.4 + .. + + org.argeo.slc.maven.shared + 0.1.3 + jar + Argeo Maven Plugin Development Support + + + + + maven-compiler-plugin + + + + + + org.apache.maven + maven-plugin-api + + + org.apache.maven + maven-project + + + org.codehaus.plexus + plexus-archiver + + + commons-io + commons-io + + + + diff --git a/org.argeo.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java b/org.argeo.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java new file mode 100644 index 000000000..641b8f2a8 --- /dev/null +++ b/org.argeo.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java @@ -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.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java b/org.argeo.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java new file mode 100644 index 000000000..94e715a93 --- /dev/null +++ b/org.argeo.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java @@ -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.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java b/org.argeo.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java new file mode 100644 index 000000000..2265cd3a4 --- /dev/null +++ b/org.argeo.maven.plugins.shared/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java @@ -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.maven.plugins.shared/src/main/resources/META-INF/plexus/components.xml b/org.argeo.maven.plugins.shared/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 000000000..b8203e2bd --- /dev/null +++ b/org.argeo.maven.plugins.shared/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,35 @@ + + + + org.argeo.slc.maven.plugin.MavenDependencyManager + + + org.argeo.slc.maven.plugin.DefaultMavenDependencyManager + + + + org.apache.maven.artifact.factory.ArtifactFactory + + factory + + + org.apache.maven.artifact.resolver.ArtifactResolver + + resolver + + + org.codehaus.plexus.archiver.manager.ArchiverManager + + archiverManager + + + org.apache.maven.artifact.metadata.ArtifactMetadataSource + + artifactMetadataSource + + + + + + + diff --git a/org.argeo.slc.maven.shared/.classpath b/org.argeo.slc.maven.shared/.classpath deleted file mode 100644 index 0c1a2f036..000000000 --- a/org.argeo.slc.maven.shared/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/org.argeo.slc.maven.shared/.project b/org.argeo.slc.maven.shared/.project deleted file mode 100644 index a175de63e..000000000 --- a/org.argeo.slc.maven.shared/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - org.argeo.slc.maven.shared - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.maven.ide.eclipse.maven2Builder - - - - - - org.maven.ide.eclipse.maven2Nature - org.eclipse.jdt.core.javanature - - 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 deleted file mode 100644 index 1c2c72d9b..000000000 --- a/org.argeo.slc.maven.shared/.settings/org.eclipse.jdt.core.prefs +++ /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.shared/.settings/org.maven.ide.eclipse.prefs b/org.argeo.slc.maven.shared/.settings/org.maven.ide.eclipse.prefs deleted file mode 100644 index e182abcb1..000000000 --- a/org.argeo.slc.maven.shared/.settings/org.maven.ide.eclipse.prefs +++ /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.shared/pom.xml b/org.argeo.slc.maven.shared/pom.xml deleted file mode 100644 index a35fa16f2..000000000 --- a/org.argeo.slc.maven.shared/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - 4.0.0 - - org.argeo.slc.maven - slc-maven - 0.1.4 - .. - - org.argeo.slc.maven.shared - 0.1.3 - jar - Argeo Maven Plugin Development Support - - - - - maven-compiler-plugin - - - - - - org.apache.maven - maven-plugin-api - - - org.apache.maven - maven-project - - - org.codehaus.plexus - plexus-archiver - - - commons-io - commons-io - - - - 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 deleted file mode 100644 index 641b8f2a8..000000000 --- a/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java +++ /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.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 deleted file mode 100644 index 94e715a93..000000000 --- a/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java +++ /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.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 deleted file mode 100644 index 2265cd3a4..000000000 --- a/org.argeo.slc.maven.shared/src/main/java/org/argeo/slc/maven/plugin/SystemCall.java +++ /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.shared/src/main/resources/META-INF/plexus/components.xml b/org.argeo.slc.maven.shared/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index b8203e2bd..000000000 --- a/org.argeo.slc.maven.shared/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - org.argeo.slc.maven.plugin.MavenDependencyManager - - - org.argeo.slc.maven.plugin.DefaultMavenDependencyManager - - - - org.apache.maven.artifact.factory.ArtifactFactory - - factory - - - org.apache.maven.artifact.resolver.ArtifactResolver - - resolver - - - org.codehaus.plexus.archiver.manager.ArchiverManager - - archiverManager - - - org.apache.maven.artifact.metadata.ArtifactMetadataSource - - artifactMetadataSource - - - - - - -