Search in sources :

Example 96 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.

the class AetherBasedResolver method addRepo.

private void addRepo(List<RemoteRepository> list, MavenRepositoryURL repo) {
    String releasesUpdatePolicy = repo.getReleasesUpdatePolicy();
    if (releasesUpdatePolicy == null || releasesUpdatePolicy.isEmpty()) {
        releasesUpdatePolicy = new RepositoryPolicy().getUpdatePolicy();
    }
    String releasesChecksumPolicy = repo.getReleasesChecksumPolicy();
    if (releasesChecksumPolicy == null || releasesChecksumPolicy.isEmpty()) {
        releasesChecksumPolicy = new RepositoryPolicy().getChecksumPolicy();
    }
    String snapshotsUpdatePolicy = repo.getSnapshotsUpdatePolicy();
    if (snapshotsUpdatePolicy == null || snapshotsUpdatePolicy.isEmpty()) {
        snapshotsUpdatePolicy = new RepositoryPolicy().getUpdatePolicy();
    }
    String snapshotsChecksumPolicy = repo.getSnapshotsChecksumPolicy();
    if (snapshotsChecksumPolicy == null || snapshotsChecksumPolicy.isEmpty()) {
        snapshotsChecksumPolicy = new RepositoryPolicy().getChecksumPolicy();
    }
    RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getId(), REPO_TYPE, repo.getURL().toExternalForm());
    RepositoryPolicy releasePolicy = new RepositoryPolicy(repo.isReleasesEnabled(), releasesUpdatePolicy, releasesChecksumPolicy);
    builder.setReleasePolicy(releasePolicy);
    RepositoryPolicy snapshotPolicy = new RepositoryPolicy(repo.isSnapshotsEnabled(), snapshotsUpdatePolicy, snapshotsChecksumPolicy);
    builder.setSnapshotPolicy(snapshotPolicy);
    Authentication authentication = getAuthentication(repo.getId());
    if (authentication != null) {
        builder.setAuthentication(authentication);
    }
    list.add(builder.build());
}
Also used : RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Authentication(org.eclipse.aether.repository.Authentication) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 97 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.

the class AetherBasedResolver method collectDependencies.

protected DependencyNode collectDependencies(Artifact root, String pomVersion, final Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
    final DefaultRepositorySystemSession session = newSession();
    try {
        List<RemoteRepository> repos = selectRepositories();
        assignProxyAndMirrors(repos);
        ArtifactDescriptorResult artifactDescriptorResult = m_repoSystem.readArtifactDescriptor(session, new ArtifactDescriptorRequest(root, repos, null));
        repos.addAll(artifactDescriptorResult.getRepositories());
        Dependency rootDependency = new Dependency(root, null);
        List<Dependency> dependencies = artifactDescriptorResult.getDependencies();
        final DefaultDependencyNode rootNode = new DefaultDependencyNode(rootDependency);
        GenericVersionScheme versionScheme = new GenericVersionScheme();
        rootNode.setVersion(versionScheme.parseVersion(pomVersion));
        rootNode.setVersionConstraint(versionScheme.parseVersionConstraint(pomVersion));
        DependencyNode pomNode = rootNode;
        // final Filter<Dependency> shouldExclude = Filters.or(DependencyFilters.testScopeFilter, excludeDependencyFilter, new NewerVersionExistsFilter(rootNode));
        final Filter<Dependency> shouldExclude = Filters.or(Arrays.asList(DependencyFilters.testScopeFilter, excludeDependencyFilter));
        DependencySelector dependencySelector = new AndDependencySelector(new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new DependencySelector() {

            @Override
            public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
                return this;
            }

            @Override
            public boolean selectDependency(Dependency dependency) {
                try {
                    return !DependencyFilters.matches(dependency, shouldExclude);
                } catch (Exception e) {
                    failedToMakeDependencyTree(dependency, e);
                    return false;
                }
            }
        });
        session.setDependencySelector(dependencySelector);
        // work on the root dependency directly?
        if (true) {
            for (Dependency dependency : dependencies) {
                DependencyNode node = resolveDependencies(session, repos, pomNode, dependency, shouldExclude);
                if (node != null) {
                    pomNode.getChildren().add(node);
                }
            }
        } else {
            DependencyNode node = resolveDependencies(session, repos, pomNode, rootDependency, shouldExclude);
            if (node != null) {
                pomNode = node;
            }
        }
        // now lets transform the dependency tree to remove different versions for the same artifact
        final DependencyGraphTransformationContext tranformContext = new DependencyGraphTransformationContext() {

            Map<Object, Object> map = new HashMap<>();

            public RepositorySystemSession getSession() {
                return session;
            }

            public Object get(Object key) {
                return map.get(key);
            }

            public Object put(Object key, Object value) {
                return map.put(key, value);
            }
        };
        DependencyGraphTransformer transformer = new ReplaceConflictingVersionResolver();
        pomNode = transformer.transformGraph(pomNode, tranformContext);
        transformer = new DuplicateTransformer();
        pomNode = transformer.transformGraph(pomNode, tranformContext);
        return pomNode;
    } finally {
        releaseSession(session);
    }
}
Also used : DependencyGraphTransformationContext(org.eclipse.aether.collection.DependencyGraphTransformationContext) ReplaceConflictingVersionResolver(io.fabric8.maven.ReplaceConflictingVersionResolver) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DuplicateTransformer(io.fabric8.maven.DuplicateTransformer) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DependencyNode(org.eclipse.aether.graph.DependencyNode) ChainedDependencyGraphTransformer(org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer) DependencyGraphTransformer(org.eclipse.aether.collection.DependencyGraphTransformer) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector) DependencyCollectionContext(org.eclipse.aether.collection.DependencyCollectionContext) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) Dependency(org.eclipse.aether.graph.Dependency) FailedToResolveDependency(io.fabric8.maven.FailedToResolveDependency) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) RepositoryException(org.eclipse.aether.RepositoryException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) NoRouteToHostException(java.net.NoRouteToHostException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MalformedURLException(java.net.MalformedURLException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector) DependencySelector(org.eclipse.aether.collection.DependencySelector) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 98 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.

the class MavenProxyServletSupport method download.

@Override
public File download(String path) throws InvalidMavenArtifactRequest {
    if (path == null) {
        throw new InvalidMavenArtifactRequest();
    }
    Matcher artifactMatcher = ARTIFACT_REQUEST_URL_REGEX.matcher(path);
    Matcher metdataGaMatcher = ARTIFACT_GA_METADATA_URL_REGEX.matcher(path);
    if (metdataGaMatcher.matches()) {
        LOGGER.info("Received request for maven metadata : {}", path);
        Metadata metadata = null;
        try {
            metadata = convertPathToMetadata(path);
            // Only handle xxx/maven-metadata.xml requests
            if (!"maven-metadata.xml".equals(metadata.getType()) || metdataGaMatcher.group(7) != null) {
                return null;
            }
            if (isHostedRepository()) {
                // do not resolve metadata via Aether - simply look it up in hosted storage
                // This is important, because `mvn deploy` or `mvn fabric8:deploy` goals, even if they PUT
                // artifacts and metadata also GET metadata (not artifacts)
                File hostedMetadata = new File(uploadRepository, path);
                LOGGER.debug("Getting metadata from hosted storage : {}", hostedMetadata);
                if (hostedMetadata.isFile()) {
                    File tmpFile = Files.createTempFile(runtimeProperties.getDataPath());
                    Files.copy(hostedMetadata, tmpFile);
                    return tmpFile;
                }
                // never look up in io.fabric8.maven.defaultRepositories or io.fabric8.maven.repositories
                return null;
            }
            // Try with default repositories - first metadata found is returned
            VersionConstraint vc = new GenericVersionScheme().parseVersionConstraint(metadata.getVersion());
            if (vc.getVersion() != null) {
                for (LocalRepository repo : resolver.getDefaultRepositories()) {
                    if (vc.getVersion().toString().endsWith("SNAPSHOT") && !resolver.handlesSnapshot(repo)) {
                        continue;
                    }
                    // clone session to swap local repository manager
                    DefaultRepositorySystemSession localSession = new DefaultRepositorySystemSession(session);
                    localSession.setLocalRepositoryManager(system.newLocalRepositoryManager(localSession, repo));
                    LOGGER.debug("Getting metadata from default repository : {}", repo.getBasedir());
                    List<MetadataResult> results = system.resolveMetadata(localSession, Collections.singletonList(new MetadataRequest(metadata, null, null)));
                    File file = processMetadataResults(metadata, results);
                    if (file != null) {
                        return file;
                    }
                }
            }
            // fallback to remote repositories - this time results are merged
            List<MetadataRequest> requests = new ArrayList<>();
            for (RemoteRepository repository : repositories) {
                MetadataRequest request = new MetadataRequest(metadata, repository, null);
                request.setFavorLocalRepository(false);
                requests.add(request);
            }
            MetadataRequest request = new MetadataRequest(metadata, null, null);
            request.setFavorLocalRepository(true);
            requests.add(request);
            List<MetadataResult> results = system.resolveMetadata(session, requests);
            File result = processMetadataResults(metadata, results);
            if (result != null) {
                return result;
            }
        } catch (Exception e) {
            LOGGER.warn(String.format("Could not find metadata : %s due to %s", metadata, e.getMessage()), e);
            return null;
        }
        // If no matching metadata found return nothing
        return null;
    } else if (artifactMatcher.matches()) {
        LOGGER.info("Received request for maven artifact : {}", path);
        Artifact artifact = convertPathToArtifact(path);
        try {
            if (artifact.getExtension() != null && (artifact.getExtension().endsWith(".sha1") || artifact.getExtension().endsWith(".md5"))) {
                return null;
            }
            File download = resolver.resolveFile(artifact);
            File tmpFile = Files.createTempFile(runtimeProperties.getDataPath());
            Files.copy(download, tmpFile);
            return tmpFile;
        } catch (Exception e) {
            LOGGER.warn(String.format("Could not find artifact : %s due to %s", artifact, e.getMessage()), e);
            return null;
        }
    }
    return null;
}
Also used : VersionConstraint(org.eclipse.aether.version.VersionConstraint) Matcher(java.util.regex.Matcher) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) Metadata(org.eclipse.aether.metadata.Metadata) LocalRepository(org.eclipse.aether.repository.LocalRepository) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) MetadataResult(org.eclipse.aether.resolution.MetadataResult) MetadataRequest(org.eclipse.aether.resolution.MetadataRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 99 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project drools by kiegroup.

the class MavenDeployTest method testDeploy.

@Test
public void testDeploy() throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy", "1.0-SNAPSHOT");
    Path m2Folder = Files.createTempDirectory("temp-m2");
    Path settingsXmlPath = generateSettingsXml(m2Folder);
    String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
    try {
        System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
        MavenSettings.reinitSettings();
        InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
        KieContainer kieContainer = ks.newKieContainer(releaseId);
        KieMavenRepository repository = getKieMavenRepository();
        RemoteRepository remote = createRemoteRepository(m2Folder);
        repository.deployArtifact(remote, releaseId, kJar1, createKPom(m2Folder, releaseId).toFile());
        // create a ksesion and check it works as expected
        KieSession ksession = kieContainer.newKieSession("KSession1");
        checkKSession(ksession, "rule1", "rule2");
        // create a new kjar
        InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
        // deploy it on maven
        repository.deployArtifact(remote, releaseId, kJar2, createKPom(m2Folder, releaseId).toFile());
        // since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
        KieScanner scanner = ks.newKieScanner(kieContainer);
        // scan the maven repo to get the new kjar version and deploy it on the kcontainer
        scanner.scanNow();
        // create a ksesion and check it works as expected
        KieSession ksession2 = kieContainer.newKieSession("KSession1");
        checkKSession(ksession2, "rule2", "rule3");
        ks.getRepository().removeKieModule(releaseId);
    } finally {
        if (oldSettingsXmlPath == null) {
            System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
        } else {
            System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
        }
        MavenSettings.reinitSettings();
    }
}
Also used : Path(java.nio.file.Path) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) AbstractKieCiTest(org.kie.scanner.AbstractKieCiTest)

Example 100 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project drools by kiegroup.

the class KieMavenRepository method deployArtifact.

/**
 * Deploys the kjar in the given kieModule on the remote repository defined in the
 * distributionManagement tag of the provided pom file. If the pom file doesn't define
 * a distributionManagement no deployment will be performed and a warning message will be logged.
 *
 * @param releaseId The releaseId with which the deployment will be made
 * @param kieModule The kieModule containing the kjar to be deployed
 * @param pomfile The pom file to be deployed together with the kjar
 */
public void deployArtifact(ReleaseId releaseId, InternalKieModule kieModule, File pomfile) {
    RemoteRepository repository = getRemoteRepositoryFromDistributionManagement(pomfile);
    if (repository == null) {
        log.warn("No Distribution Management configured: unknown repository");
        return;
    }
    deployArtifact(repository, releaseId, kieModule, pomfile);
}
Also used : RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Aggregations

RemoteRepository (org.eclipse.aether.repository.RemoteRepository)258 File (java.io.File)69 ArrayList (java.util.ArrayList)66 Artifact (org.eclipse.aether.artifact.Artifact)59 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)59 Test (org.junit.Test)52 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)46 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)43 RepositorySystem (org.eclipse.aether.RepositorySystem)40 IOException (java.io.IOException)36 Dependency (org.eclipse.aether.graph.Dependency)36 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)36 RepositoryPolicy (org.eclipse.aether.repository.RepositoryPolicy)29 Proxy (org.eclipse.aether.repository.Proxy)28 AuthenticationBuilder (org.eclipse.aether.util.repository.AuthenticationBuilder)27 CollectRequest (org.eclipse.aether.collection.CollectRequest)26 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)26 List (java.util.List)25 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)24 Map (java.util.Map)22