Search in sources :

Example 1 with RepositoryException

use of org.sonatype.aether.RepositoryException in project sonatype-aether by sonatype.

the class DefaultDeployerTest method testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo.

@Test
public void testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo() throws Exception {
    MergeableMetadata metadata = new MergeableMetadata() {

        public Metadata setFile(File file) {
            return this;
        }

        public String getVersion() {
            return "";
        }

        public String getType() {
            return "test.properties";
        }

        public Nature getNature() {
            return Nature.RELEASE;
        }

        public String getGroupId() {
            return "org";
        }

        public File getFile() {
            return null;
        }

        public String getArtifactId() {
            return "aether";
        }

        public void merge(File current, File result) throws RepositoryException {
            Properties props = new Properties();
            try {
                if (current.isFile()) {
                    TestFileUtils.read(props, current);
                }
                props.setProperty("new", "value");
                TestFileUtils.write(props, result);
            } catch (IOException e) {
                throw new RepositoryException(e.getMessage(), e);
            }
        }

        public boolean isMerged() {
            return false;
        }
    };
    manager.setConnector(new RepositoryConnector() {

        public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
        }

        public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
            if (metadataDownloads != null) {
                for (MetadataDownload download : metadataDownloads) {
                    download.setException(new MetadataNotFoundException(download.getMetadata(), null, null));
                }
            }
        }

        public void close() {
        }
    });
    request.addMetadata(metadata);
    File metadataFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, request.getRepository(), ""));
    Properties props = new Properties();
    props.setProperty("old", "value");
    TestFileUtils.write(props, metadataFile);
    deployer.deploy(session, request);
    props = new Properties();
    TestFileUtils.read(props, metadataFile);
    assertNull(props.toString(), props.get("old"));
}
Also used : MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) MergeableMetadata(org.sonatype.aether.metadata.MergeableMetadata) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) RepositoryException(org.sonatype.aether.RepositoryException) IOException(java.io.IOException) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 2 with RepositoryException

use of org.sonatype.aether.RepositoryException in project sonatype-aether by sonatype.

the class JavaEffectiveScopeCalculator method transformGraph.

public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException {
    List<?> sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
    if (sortedConflictIds == null) {
        ConflictIdSorter sorter = new ConflictIdSorter();
        sorter.transformGraph(node, context);
        sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
    }
    Map<?, ?> conflictIds = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
    if (conflictIds == null) {
        throw new RepositoryException("conflict groups have not been identified");
    }
    Boolean cyclicConflictIds = (Boolean) context.get(TransformationContextKeys.CYCLIC_CONFLICT_IDS);
    Map<Object, ConflictGroup> groups = new HashMap<Object, ConflictGroup>(256);
    buildConflictGroups(groups, node, null, conflictIds);
    String rootScope = "";
    if (node.getDependency() != null) {
        Object key = conflictIds.get(node);
        groups.get(key).scope = rootScope = node.getDependency().getScope();
    }
    for (DependencyNode child : node.getChildren()) {
        Object key = conflictIds.get(child);
        groups.get(key).scope = getInheritedScope(rootScope, child.getDependency().getScope());
    }
    Set<Object> prequisites = null;
    if (Boolean.TRUE.equals(cyclicConflictIds)) {
        prequisites = new HashSet<Object>(sortedConflictIds.size() * 2);
    }
    for (Object key : sortedConflictIds) {
        if (prequisites != null) {
            prequisites.add(key);
        }
        ConflictGroup group = groups.get(key);
        resolve(group, conflictIds, prequisites);
    }
    return node;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) RepositoryException(org.sonatype.aether.RepositoryException) DependencyNode(org.sonatype.aether.graph.DependencyNode) List(java.util.List) ArrayList(java.util.ArrayList) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with RepositoryException

use of org.sonatype.aether.RepositoryException in project SSM by Intel-bigdata.

the class DependencyResolver method getArtifactsWithDep.

/**
 * @param dependency
 * @param excludes list of pattern can either be of the form groupId:artifactId
 * @return
 * @throws Exception
 */
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws RepositoryException {
    Artifact artifact = new DefaultArtifact(dependency);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(excludes);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            collectRequest.addRepository(repo);
        }
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    try {
        return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    } catch (NullPointerException ex) {
        throw new RepositoryException(String.format("Cannot fetch dependencies for %s", dependency));
    }
}
Also used : DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) RepositoryException(org.sonatype.aether.RepositoryException) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)

Example 4 with RepositoryException

use of org.sonatype.aether.RepositoryException in project gradle by gradle.

the class AbstractMavenPublishAction method publish.

public void publish() {
    List<Artifact> artifacts = new ArrayList<Artifact>();
    if (mainArtifact.getFile() != null) {
        artifacts.add(mainArtifact);
    }
    artifacts.add(pomArtifact);
    if (metadataArtifact != null) {
        artifacts.add(metadataArtifact);
    }
    for (Artifact artifact : attached) {
        File file = artifact.getFile();
        if (file != null && file.isFile()) {
            artifacts.add(artifact);
        }
    }
    try {
        publishArtifacts(artifacts, newRepositorySystem(), session);
    } catch (RepositoryException e) {
        throw new GradleException(e.getMessage(), e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) RepositoryException(org.sonatype.aether.RepositoryException) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 5 with RepositoryException

use of org.sonatype.aether.RepositoryException in project motech by motech.

the class ModuleAdminServiceImpl method installWithDependenciesFromFile.

private BundleInformation installWithDependenciesFromFile(File bundleFile, boolean startBundle) throws IOException {
    JarInformation jarInformation = getJarInformations(bundleFile);
    List<Bundle> bundlesInstalled = new ArrayList<>();
    BundleInformation bundleInformation = null;
    if (jarInformation == null) {
        throw new IOException("Unable to read bundleFile " + bundleFile.getAbsolutePath());
    }
    try {
        List<ArtifactResult> artifactResults = new LinkedList<>();
        bundleWatcherSuspensionService.suspendBundleProcessing();
        for (Dependency dependency : jarInformation.getPomInformation().getDependencies()) {
            artifactResults.addAll(resolveDependencies(dependency, jarInformation.getPomInformation()));
        }
        artifactResults = removeDuplicatedArtifacts(artifactResults);
        bundlesInstalled = installBundlesFromArtifacts(artifactResults);
        final Bundle requestedModule = installBundleFromFile(bundleFile, true, false);
        if (requestedModule != null) {
            if (!isFragmentBundle(requestedModule) && startBundle) {
                requestedModule.start();
            }
            bundlesInstalled.add(requestedModule);
            bundleInformation = null;
        } else {
            bundleInformation = new BundleInformation(null);
        }
    } catch (BundleException | RepositoryException e) {
        throw new MotechException("Error while installing bundle and dependencies.", e);
    } finally {
        bundleWatcherSuspensionService.restoreBundleProcessing();
    }
    // start bundles after all bundles installed to avoid any dependency resolution problems.
    startBundles(bundlesInstalled, startBundle);
    return bundleInformation;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) RepositoryException(org.sonatype.aether.RepositoryException) IOException(java.io.IOException) Dependency(org.sonatype.aether.graph.Dependency) JarInformation(org.motechproject.admin.bundles.JarInformation) LinkedList(java.util.LinkedList) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) MotechException(org.motechproject.commons.api.MotechException) BundleInformation(org.motechproject.admin.bundles.BundleInformation) ExtendedBundleInformation(org.motechproject.admin.bundles.ExtendedBundleInformation) BundleException(org.osgi.framework.BundleException)

Aggregations

RepositoryException (org.sonatype.aether.RepositoryException)8 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 Dependency (org.sonatype.aether.graph.Dependency)3 Artifact (org.sonatype.aether.artifact.Artifact)2 MergeableMetadata (org.sonatype.aether.metadata.MergeableMetadata)2 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)2 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)2 MetadataNotFoundException (org.sonatype.aether.transfer.MetadataNotFoundException)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 DependencyResolver (org.apache.zeppelin.dep.DependencyResolver)1 GradleException (org.gradle.api.GradleException)1 Test (org.junit.Test)1 BundleInformation (org.motechproject.admin.bundles.BundleInformation)1