]> jfr.im git - irc/rizon/moo.git/commitdiff
Import artifactresolver from acid, drop jcabi
authorAdam <redacted>
Wed, 19 Oct 2016 18:03:07 +0000 (14:03 -0400)
committerAdam <redacted>
Wed, 19 Oct 2016 18:03:07 +0000 (14:03 -0400)
moo/pom.xml
moo/src/main/java/net/rizon/moo/ArtifactResolver.java [new file with mode: 0644]
moo/src/main/java/net/rizon/moo/Plugin.java
moo/src/main/java/net/rizon/moo/PluginManager.java

index 8debbb660efa08121736fbe836590f937b217753..2218d5f2a50d7e10a2c28c820c10fa6e0407dc32 100644 (file)
                <slf4j.version>1.7.12</slf4j.version>
                <logback.version>1.1.3</logback.version>
                <guava.version>19.0-rc1</guava.version>
+               <aether.version>1.1.0</aether.version>
+               <maven.version>3.1.0</maven.version>
        </properties>
 
        <dependencies>
-               <dependency>
-                       <groupId>org.slf4j</groupId>
-                       <artifactId>slf4j-api</artifactId>
-                       <version>${slf4j.version}</version>
-               </dependency>
                <dependency>
                        <groupId>org.xerial</groupId>
                        <artifactId>sqlite-jdbc</artifactId>
                        <artifactId>commons-validator</artifactId>
                        <version>1.4.0</version>
                </dependency>
+               
                <dependency>
                        <groupId>io.netty</groupId>
                        <artifactId>netty-all</artifactId>
                        <version>${netty.version}</version>
                </dependency>
+               
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>${slf4j.version}</version>
+               </dependency>
                <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-classic</artifactId>
@@ -56,6 +60,7 @@
                        <artifactId>logback-core</artifactId>
                        <version>${logback.version}</version>
                </dependency>
+               
                <dependency>
                        <groupId>com.google.guava</groupId>
                        <artifactId>guava</artifactId>
                        <artifactId>guice-multibindings</artifactId>
                        <version>${guice.version}</version>
                </dependency>
+
                <dependency>
-                       <groupId>com.jcabi</groupId>
-                       <artifactId>jcabi-aether</artifactId>
-                       <version>0.10.1</version>
+                       <groupId>org.eclipse.aether</groupId>
+                       <artifactId>aether-api</artifactId>
+                       <version>${aether.version}</version>
                </dependency>
                <dependency>
-                       <groupId>org.sonatype.aether</groupId>
-                       <artifactId>aether-api</artifactId>
-                       <version>1.13.1</version>
+                       <groupId>org.eclipse.aether</groupId>
+                       <artifactId>aether-impl</artifactId>
+                       <version>${aether.version}</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.maven</groupId>
-                       <artifactId>maven-core</artifactId>
-                       <version>3.0.3</version>
+                       <artifactId>maven-aether-provider</artifactId>
+                       <version>${maven.version}</version>
                </dependency>
        </dependencies>
 
diff --git a/moo/src/main/java/net/rizon/moo/ArtifactResolver.java b/moo/src/main/java/net/rizon/moo/ArtifactResolver.java
new file mode 100644 (file)
index 0000000..66633aa
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2016, Adam <Adam@sigterm.info>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Adam <Adam@sigterm.info>
+ * 4. Neither the name of the Adam <Adam@sigterm.info> nor the
+ *    names of its contributors may be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Adam <Adam@sigterm.info> ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Adam <Adam@sigterm.info> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package net.rizon.moo;
+
+import java.io.File;
+import java.util.List;
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.collection.CollectRequest;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyFilter;
+import org.eclipse.aether.impl.DefaultServiceLocator;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.resolution.ArtifactResult;
+import org.eclipse.aether.resolution.DependencyRequest;
+import org.eclipse.aether.resolution.DependencyResolutionException;
+import org.eclipse.aether.util.artifact.JavaScopes;
+import org.eclipse.aether.util.filter.DependencyFilterUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ArtifactResolver
+{
+       private static final Logger logger = LoggerFactory.getLogger(ArtifactResolver.class);
+       
+       private final File repository;
+
+       public ArtifactResolver()
+       {
+               repository = new File(System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository");
+       }
+
+       public List<ArtifactResult> resolveArtifacts(Artifact artifact) throws DependencyResolutionException
+       {
+               RepositorySystem system = newRepositorySystem();
+
+               RepositorySystemSession session = newRepositorySystemSession(system);
+
+               DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME);
+
+               CollectRequest collectRequest = new CollectRequest();
+               collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
+
+               DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
+
+               List<ArtifactResult> results = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
+               return results;
+       }
+
+       private DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system)
+       {
+               DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
+
+               LocalRepository localRepo = new LocalRepository(repository.getAbsolutePath());
+               session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
+
+               return session;
+       }
+
+       private RepositorySystem newRepositorySystem()
+       {
+               DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
+
+               return locator.getService(RepositorySystem.class);
+       }
+}
index 4ed84a23833fc619db334d8ba640e8062b66b571..d517cbee1edc2ece6d09ae9e94cb87f499cf1b9b 100644 (file)
@@ -5,8 +5,8 @@ import com.google.inject.Inject;
 import java.io.IOException;
 import java.util.List;
 import java.util.jar.Manifest;
+import org.eclipse.aether.artifact.Artifact;
 import org.slf4j.Logger;
-import org.sonatype.aether.artifact.Artifact;
 
 public abstract class Plugin extends AbstractModule
 {
index c7bc3c5a3c417202496443d63d05a2417d674bb1..4e8961855a88218f448faecdef3c6f48f1fae695 100644 (file)
@@ -1,7 +1,6 @@
 package net.rizon.moo;
 
 import com.google.inject.Inject;
-import com.jcabi.aether.Aether;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -14,11 +13,10 @@ import java.util.Collection;
 import java.util.List;
 import java.util.jar.Manifest;
 import net.rizon.moo.conf.Config;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.resolution.ArtifactResult;
 import org.slf4j.Logger;
-import org.sonatype.aether.artifact.Artifact;
-import org.sonatype.aether.repository.RemoteRepository;
-import org.sonatype.aether.resolution.DependencyResolutionException;
-import org.sonatype.aether.util.artifact.DefaultArtifact;
 
 public class PluginManager
 {
@@ -30,17 +28,6 @@ public class PluginManager
 
        private final List<Plugin> plugins = new ArrayList<>();
 
-       private List<Artifact> resolveArtifacts(Artifact artifact) throws DependencyResolutionException
-       {
-               File local = new File(conf.plugin_repository);
-               Collection<RemoteRepository> remotes = Arrays.asList();
-
-               Aether a = new Aether(remotes, local);
-
-               Collection<Artifact> deps = a.resolve(artifact, "runtime");
-               return new ArrayList<>(deps);
-       }
-
        private Manifest getManifest(File jar) throws IOException
        {
                String manifestPath = "jar:file:" + jar.getAbsolutePath() + "!/META-INF/MANIFEST.MF";
@@ -64,18 +51,21 @@ public class PluginManager
                if (p != null)
                        return p;
 
-               List<Artifact> artifacts = resolveArtifacts(a);
+               ArtifactResolver resolver = new ArtifactResolver();
+               List<ArtifactResult> artifacts = resolver.resolveArtifacts(a);
 
-               Artifact artifact = artifacts.remove(0);
+               ArtifactResult artifact = artifacts.remove(0);
                // artifacts contains dependencies now
 
-               ClassLoader cl = new ClassLoader(this, artifact.getFile());
+               logger.debug("Located artifact {}: {}", artifact, artifact.getArtifact().getFile());
+
+               ClassLoader cl = new ClassLoader(this, artifact.getArtifact().getFile());
                try
                {
-                       for (Artifact a2 : artifacts)
-                               cl.addFile(a2.getFile());
+                       for (ArtifactResult a2 : artifacts)
+                               cl.addFile(a2.getArtifact().getFile());
 
-                       Manifest mf = getManifest(artifact.getFile());
+                       Manifest mf = getManifest(artifact.getArtifact().getFile());
 
                        Class<?> c;
                        try
@@ -93,7 +83,7 @@ public class PluginManager
 
                        p = (Plugin) con.newInstance();
 
-                       p.artifact = artifact;
+                       p.artifact = artifact.getArtifact();
                        p.loader = cl;
                        cl = null;
                        p.manifest = mf;