Search in sources :

Example 76 with Artifact

use of org.eclipse.aether.artifact.Artifact in project kie-wb-common by kiegroup.

the class MavenDependencyConfigExecutorTest method installArtifactLocally.

private void installArtifactLocally(final String groupId, final String artifactId, final String version) throws Exception {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "pom", version);
    final Path pom = getPom(groupId, artifactId, version);
    pomArtifact = pomArtifact.setFile(pom.toFile());
    final InstallRequest installRequest = new InstallRequest();
    installRequest.addArtifact(pomArtifact);
    final DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
    RepositorySystem system = locator.getService(RepositorySystem.class);
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    final LocalRepository localRepo = new LocalRepository(m2Folder);
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
    system.install(session, installRequest);
}
Also used : Path(java.nio.file.Path) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InstallRequest(org.eclipse.aether.installation.InstallRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 77 with Artifact

use of org.eclipse.aether.artifact.Artifact in project drools by kiegroup.

the class MavenClassLoaderResolver method getClassLoader.

@Override
public ClassLoader getClassLoader(KieModule kmodule) {
    ClassLoader parent = Thread.currentThread().getContextClassLoader();
    if (parent == null) {
        parent = ClassLoader.getSystemClassLoader();
    }
    if (parent == null) {
        parent = MavenClassLoaderResolver.class.getClassLoader();
    }
    InternalKieModule internalKModule = (InternalKieModule) kmodule;
    Collection<ReleaseId> jarDependencies = internalKModule.getJarDependencies(DependencyFilter.COMPILE_FILTER);
    if (jarDependencies.isEmpty()) {
        return parent;
    }
    ArtifactResolver resolver = ArtifactResolver.getResolverFor(internalKModule.getPomModel());
    List<URL> urls = new ArrayList<URL>();
    List<ReleaseId> unresolvedDeps = new ArrayList<ReleaseId>();
    for (ReleaseId rid : jarDependencies) {
        try {
            Artifact artifact = resolver.resolveArtifact(rid);
            if (artifact != null) {
                File jar = artifact.getFile();
                urls.add(jar.toURI().toURL());
            } else {
                logger.error("Dependency artifact not found for: " + rid);
                unresolvedDeps.add(rid);
            }
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }
    internalKModule.setUnresolvedDependencies(unresolvedDeps);
    return new URLClassLoader(urls.toArray(new URL[urls.size()]), parent);
}
Also used : MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) ArtifactResolver(org.appformer.maven.integration.ArtifactResolver) URL(java.net.URL) Artifact(org.eclipse.aether.artifact.Artifact) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 78 with Artifact

use of org.eclipse.aether.artifact.Artifact in project drools by kiegroup.

the class KieRepositoryScannerImpl method scanForUpdates.

private Map<DependencyDescriptor, Artifact> scanForUpdates() {
    artifactResolver = getResolverFor(kieContainer, true);
    if (!kieProjectDescr.getReleaseId().equals(this.kieContainer.getReleaseId())) {
        kieProjectDescr = new DependencyDescriptor(this.kieContainer.getReleaseId(), this.kieContainer.getCreationTimestamp());
    }
    Map<DependencyDescriptor, Artifact> newArtifacts = new HashMap<DependencyDescriptor, Artifact>();
    Artifact newArtifact = artifactResolver.resolveArtifact(this.kieContainer.getConfiguredReleaseId());
    if (newArtifact != null) {
        DependencyDescriptor resolvedDep = new DependencyDescriptor(newArtifact);
        if (resolvedDep.isNewerThan(kieProjectDescr)) {
            newArtifacts.put(kieProjectDescr, newArtifact);
            kieProjectDescr = new DependencyDescriptor(newArtifact);
        }
    }
    for (DependencyDescriptor dep : artifactResolver.getAllDependecies()) {
        ReleaseId artifactId = adapt(dep.getReleaseIdWithoutVersion());
        DependencyDescriptor oldDep = usedDependencies.get(artifactId);
        if (oldDep != null) {
            newArtifact = artifactResolver.resolveArtifact(dep.getReleaseId());
            if (newArtifact != null) {
                DependencyDescriptor newDep = new DependencyDescriptor(newArtifact);
                if (newDep.isNewerThan(oldDep)) {
                    newArtifacts.put(oldDep, newArtifact);
                    usedDependencies.put(artifactId, newDep);
                }
            }
        }
    }
    return newArtifacts;
}
Also used : DependencyDescriptor(org.appformer.maven.integration.DependencyDescriptor) HashMap(java.util.HashMap) ReleaseId(org.kie.api.builder.ReleaseId) Artifact(org.eclipse.aether.artifact.Artifact)

Example 79 with Artifact

use of org.eclipse.aether.artifact.Artifact in project drools by kiegroup.

the class KieRepositoryScannerImpl method indexArtifacts.

private Map<ReleaseId, DependencyDescriptor> indexArtifacts() {
    Map<ReleaseId, DependencyDescriptor> depsMap = new HashMap<ReleaseId, DependencyDescriptor>();
    for (DependencyDescriptor dep : artifactResolver.getAllDependecies()) {
        if (!"test".equals(dep.getScope()) && !"provided".equals(dep.getScope()) && !"system".equals(dep.getScope())) {
            Artifact artifact = artifactResolver.resolveArtifact(dep.getReleaseId());
            log.debug(artifact + " resolved to  " + artifact.getFile());
            if (isKJar(artifact.getFile())) {
                depsMap.put(adapt(dep.getReleaseIdWithoutVersion()), new DependencyDescriptor(artifact));
            }
        } else {
            log.debug("{} does not need to be resolved because in scope {}", dep, dep.getScope());
        }
    }
    return depsMap;
}
Also used : DependencyDescriptor(org.appformer.maven.integration.DependencyDescriptor) HashMap(java.util.HashMap) ReleaseId(org.kie.api.builder.ReleaseId) Artifact(org.eclipse.aether.artifact.Artifact)

Example 80 with Artifact

use of org.eclipse.aether.artifact.Artifact in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getAllVersions.

@Override
public List<MavenPluginVersion> getAllVersions() {
    List<MavenPluginVersion> pluginVersions = new ArrayList<>();
    Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(mavenPluginRepository.getRepositories());
    // RemoteRepository centralRepo = newCentralRepository();
    try {
        VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
        List<Version> versions = rangeResult.getVersions();
        if (!versions.isEmpty()) {
            for (int i = versions.size() - 1; i >= Math.max(0, versions.size() - 3); i--) {
                Version version = versions.get(i);
                ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
                Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
                descriptorRequest.setArtifact(versionArtifact);
                descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
                MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
                ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
                ArtifactRequest request = new ArtifactRequest();
                request.setArtifact(descriptorResult.getArtifact());
                request.setRepositories(mavenPluginRepository.getRepositories());
                ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                File pomFile = resolveArtifact.getArtifact().getFile();
                MavenXpp3Reader mavenreader = new MavenXpp3Reader();
                try (FileReader fileReader = new FileReader(pomFile)) {
                    Model model = mavenreader.read(fileReader);
                    mavenPluginVersion.setModel(model);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                }
                for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
                    DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
                    mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
                }
                pluginVersions.add(0, mavenPluginVersion);
            }
        }
    } catch (VersionRangeResolutionException e) {
        e.printStackTrace();
    } catch (ArtifactDescriptorException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return pluginVersions;
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.eclipse.aether.version.Version) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Model(org.apache.maven.model.Model) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

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