Search in sources :

Example 51 with Artifact

use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.

the class Main method run.

@SuppressWarnings("ConstantConditions")
private static void run(File cacheDir, String[] extensionGAVs, List<FileArchive> oldArchives, List<FileArchive> oldSupplementaryArchives, List<FileArchive> newArchives, List<FileArchive> newSupplementaryArchives, String[] configFiles, Map<String, String> additionalConfig) throws Exception {
    ProjectModule.Builder bld = ProjectModule.build();
    bld.localRepository(cacheDir);
    if (extensionGAVs != null) {
        for (String gav : extensionGAVs) {
            bld.addDependency(gav);
        }
    }
    Properties libraryVersionsProps = new Properties();
    libraryVersionsProps.load(Main.class.getResourceAsStream("/library.versions"));
    Set<Artifact> globalArtifacts = libraryVersionsProps.stringPropertyNames().stream().map(p -> {
        String gav = p + ':' + libraryVersionsProps.get(p);
        return new DefaultArtifact(gav);
    }).collect(toSet());
    bld.moduleSpecController(new ModuleSpecController() {

        private boolean override;

        private String currentModuleName;

        @Override
        public void start(String moduleName) {
            currentModuleName = moduleName;
        }

        // TODO add warnings when the deps depend on another revapi version than the one bundled...
        @Override
        public DependencySpec modifyDependency(String dependencyName, DependencySpec original) {
            boolean overrideThis = false;
            Artifact a = new DefaultArtifact(dependencyName);
            for (Artifact ga : globalArtifacts) {
                if (ga.getGroupId().equals(a.getGroupId()) && ga.getArtifactId().equals(a.getArtifactId()) && !ga.getVersion().equals(a.getVersion())) {
                    LOG.warn("Detected version conflict in dependencies of extension " + currentModuleName + ". The extension depends on " + a + " while the CLI has " + ga + " on global" + " classpath. This will likely cause problems.");
                }
            }
            override = override || overrideThis;
            return overrideThis ? null : original;
        }

        @Override
        public void modify(ModuleSpec.Builder bld) {
            if (override) {
                Set<String> revapiPaths = new HashSet<>(Arrays.asList("org/revapi", "org/revapi/configuration", "org/revapi/query", "org/revapi/simple"));
                bld.addDependency(DependencySpec.createSystemDependencySpec(revapiPaths));
                override = false;
            }
        }

        @Override
        public void end(String moduleName) {
            currentModuleName = null;
        }
    });
    LOG.info("Downloading extensions");
    Module project = bld.create();
    Revapi revapi = Revapi.builder().withAllExtensionsFrom(project.getClassLoader()).withAllExtensionsFromThreadContextClassLoader().build();
    AnalysisContext.Builder ctxBld = AnalysisContext.builder(revapi).withOldAPI(API.of(oldArchives).supportedBy(oldSupplementaryArchives).build()).withNewAPI(API.of(newArchives).supportedBy(newSupplementaryArchives).build());
    if (configFiles != null) {
        for (String cf : configFiles) {
            File f = new File(cf);
            checkCanRead(f, "Configuration file");
            try (FileInputStream is = new FileInputStream(f)) {
                ctxBld.mergeConfigurationFromJSONStream(is);
            }
        }
    }
    for (Map.Entry<String, String> e : additionalConfig.entrySet()) {
        String[] keyPath = e.getKey().split("\\.");
        ModelNode additionalNode = new ModelNode();
        ModelNode key = additionalNode.get(keyPath);
        String value = e.getValue();
        if (value.startsWith("[") && value.endsWith("]")) {
            String[] values = value.substring(1, value.length() - 1).split("\\s*,\\s*");
            for (String v : values) {
                key.add(v);
            }
        } else {
            key.set(value);
        }
        ctxBld.mergeConfiguration(additionalNode);
    }
    LOG.info("Starting analysis");
    try (AnalysisResult result = revapi.analyze(ctxBld.build())) {
        if (!result.isSuccess()) {
            throw result.getFailure();
        }
    }
}
Also used : Arrays(java.util.Arrays) FileArchive(org.revapi.simple.FileArchive) MavenBootstrap(pw.krejci.modules.maven.MavenBootstrap) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) DependencySpec(org.jboss.modules.DependencySpec) ModuleSpec(org.jboss.modules.ModuleSpec) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) Getopt(gnu.getopt.Getopt) Collectors.toSet(java.util.stream.Collectors.toSet) Nullable(javax.annotation.Nullable) LongOpt(gnu.getopt.LongOpt) API(org.revapi.API) Properties(java.util.Properties) AnalysisContext(org.revapi.AnalysisContext) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) Artifact(org.eclipse.aether.artifact.Artifact) AnalysisResult(org.revapi.AnalysisResult) FileInputStream(java.io.FileInputStream) Revapi(org.revapi.Revapi) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) List(java.util.List) Module(org.jboss.modules.Module) RepositoryException(org.eclipse.aether.RepositoryException) ProjectModule(pw.krejci.modules.maven.ProjectModule) ModuleSpecController(pw.krejci.modules.maven.ModuleSpecController) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) ModelNode(org.jboss.dmr.ModelNode) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector) RepositorySystem(org.eclipse.aether.RepositorySystem) HashSet(java.util.HashSet) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) Revapi(org.revapi.Revapi) AnalysisContext(org.revapi.AnalysisContext) Properties(java.util.Properties) ModuleSpec(org.jboss.modules.ModuleSpec) DependencySpec(org.jboss.modules.DependencySpec) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) FileInputStream(java.io.FileInputStream) AnalysisResult(org.revapi.AnalysisResult) ProjectModule(pw.krejci.modules.maven.ProjectModule) ModuleSpecController(pw.krejci.modules.maven.ModuleSpecController) Module(org.jboss.modules.Module) ProjectModule(pw.krejci.modules.maven.ProjectModule) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 52 with Artifact

use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.

the class Analyzer method findProjectArtifact.

private static Artifact findProjectArtifact(MavenProject project) {
    String extension = project.getArtifact().getArtifactHandler().getExtension();
    String fileName = project.getModel().getBuild().getFinalName() + "." + extension;
    File f = new File(new File(project.getBasedir(), "target"), fileName);
    if (f.exists()) {
        Artifact ret = RepositoryUtils.toArtifact(project.getArtifact());
        return ret.setFile(f);
    } else {
        return null;
    }
}
Also used : File(java.io.File) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 53 with Artifact

use of org.eclipse.aether.artifact.Artifact in project activemq-artemis by apache.

the class ArtemisAbstractPlugin method explodeDependencies.

protected List<Artifact> explodeDependencies(Artifact artifact) throws DependencyCollectionException {
    final List<Artifact> dependencies = new LinkedList<>();
    CollectRequest exploreDependenciesRequest = new CollectRequest(new Dependency(artifact, "compile"), remoteRepos);
    CollectResult result = repositorySystem.collectDependencies(repoSession, exploreDependenciesRequest);
    final AtomicInteger level = new AtomicInteger(0);
    DependencyNode node = result.getRoot();
    StringWriter writer = new StringWriter();
    final PrintWriter strPrint = new PrintWriter(writer);
    strPrint.println("Dependencies explored for " + artifact + ":");
    if (node != null) {
        node.accept(new DependencyVisitor() {

            @Override
            public boolean visitEnter(DependencyNode node) {
                for (int i = 0; i < level.get(); i++) {
                    strPrint.print("!...");
                }
                level.incrementAndGet();
                strPrint.println("Dependency:: " + node.getDependency() + " node = " + node.getArtifact());
                dependencies.add(node.getArtifact());
                return true;
            }

            @Override
            public boolean visitLeave(DependencyNode node) {
                level.decrementAndGet();
                return true;
            }
        });
    }
    getLog().info(writer.toString());
    return dependencies;
}
Also used : StringWriter(java.io.StringWriter) CollectResult(org.eclipse.aether.collection.CollectResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) LinkedList(java.util.LinkedList) PrintWriter(java.io.PrintWriter)

Example 54 with Artifact

use of org.eclipse.aether.artifact.Artifact in project storm by apache.

the class AetherUtils method parseDependency.

/**
 * Parses dependency parameter and build {@link Dependency} object.
 *
 * @param dependency string representation of dependency parameter
 * @return Dependency object
 */
public static Dependency parseDependency(String dependency) {
    List<String> dependencyAndExclusions = Arrays.asList(dependency.split("\\^"));
    Collection<Exclusion> exclusions = new ArrayList<>();
    for (int idx = 1; idx < dependencyAndExclusions.size(); idx++) {
        exclusions.add(AetherUtils.createExclusion(dependencyAndExclusions.get(idx)));
    }
    Artifact artifact = new DefaultArtifact(dependencyAndExclusions.get(0));
    return new Dependency(artifact, JavaScopes.COMPILE, false, exclusions);
}
Also used : Exclusion(org.eclipse.aether.graph.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 55 with Artifact

use of org.eclipse.aether.artifact.Artifact in project storm by apache.

the class DependencyResolverMain method transformArtifactResultToArtifactToPaths.

private static Map<String, String> transformArtifactResultToArtifactToPaths(List<ArtifactResult> artifactResults) {
    Map<String, String> artifactToPath = new LinkedHashMap<>();
    for (ArtifactResult artifactResult : artifactResults) {
        Artifact artifact = artifactResult.getArtifact();
        artifactToPath.put(AetherUtils.artifactToString(artifact), artifact.getFile().getAbsolutePath());
    }
    return artifactToPath;
}
Also used : Artifact(org.eclipse.aether.artifact.Artifact) LinkedHashMap(java.util.LinkedHashMap) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)122 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)97 File (java.io.File)51 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)34 Dependency (org.eclipse.aether.graph.Dependency)32 IOException (java.io.IOException)29 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)26 ArrayList (java.util.ArrayList)23 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)22 List (java.util.List)20 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)18 CollectRequest (org.eclipse.aether.collection.CollectRequest)15 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)15 DependencyNode (org.eclipse.aether.graph.DependencyNode)14 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)14 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 URL (java.net.URL)12 Map (java.util.Map)12 RepositorySystem (org.eclipse.aether.RepositorySystem)11