<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>
<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>
--- /dev/null
+/*
+ * 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);
+ }
+}
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
{
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;
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
{
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";
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
p = (Plugin) con.newInstance();
- p.artifact = artifact;
+ p.artifact = artifact.getArtifact();
p.loader = cl;
cl = null;
p.manifest = mf;