Search in sources :

Example 1 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project walkmod-core by walkmod.

the class IvyConfigurationProvider method resolveArtifacts.

public Collection<File> resolveArtifacts() throws Exception {
    if (ivy != null) {
        if (lastResolvedArtifacts.isEmpty() || !lastResolvedArtifacts.containsAll(artifacts)) {
            lastResolvedArtifacts = artifacts;
        } else {
            return artifactFiles;
        }
        XmlModuleDescriptorWriter.write(md, ivyfile);
        ResolveReport report = ivy.resolve(ivyfile.toURL(), resolveOptions);
        if (!report.hasError()) {
            ArtifactDownloadReport[] artifacts = report.getAllArtifactsReports();
            Collection<File> result = new LinkedList<File>();
            for (ArtifactDownloadReport item : artifacts) {
                result.add(item.getLocalFile());
            }
            artifactFiles = result;
            return result;
        } else {
            artifactFiles.clear();
            List problems = report.getAllProblemMessages();
            if (problems == null || problems.isEmpty()) {
                throw new ConfigurationException("Ivy can not resolve the artifacts. Undefined cause");
            } else {
                String msg = "";
                Iterator it = problems.iterator();
                while (it.hasNext()) {
                    String error = it.next().toString();
                    LOG.warn(error);
                    if ("".equals(msg)) {
                        msg = error;
                    } else {
                        msg = msg + ";" + error;
                    }
                }
                throw new ConfigurationException("Ivy can not resolve the artifacts. Cause: " + msg);
            }
        }
    }
    return null;
}
Also used : ResolveReport(org.apache.ivy.core.report.ResolveReport) ConfigurationException(org.walkmod.conf.ConfigurationException) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) File(java.io.File)

Example 2 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project build-info by JFrogDev.

the class ArtifactoryBuildInfoTrigger method collectDependencyInformation.

/**
 * Collect dependency information during the build.
 *
 * @param event The end of resolution Ivy event
 */
private void collectDependencyInformation(IvyEvent event) {
    Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
    ResolveReport report = ((EndResolveEvent) event).getReport();
    @SuppressWarnings("unchecked") Map<String, String> attributes = event.getAttributes();
    Module module = getOrCreateModule(attributes);
    project.log("[buildinfo:collect] Collecting dependencies for " + module.getId(), Project.MSG_INFO);
    if (module.getDependencies() == null || module.getDependencies().isEmpty()) {
        String[] configurations = report.getConfigurations();
        List<Dependency> moduleDependencies = Lists.newArrayList();
        for (String configuration : configurations) {
            project.log("[buildinfo:collect] Configuration: " + configuration + " Dependencies", Project.MSG_DEBUG);
            ConfigurationResolveReport configurationReport = report.getConfigurationReport(configuration);
            ArtifactDownloadReport[] allArtifactsReports = configurationReport.getAllArtifactsReports();
            for (final ArtifactDownloadReport artifactsReport : allArtifactsReports) {
                project.log("[buildinfo:collect] Artifact Download Report for configuration: " + configuration + " : " + artifactsReport, Project.MSG_DEBUG);
                ModuleRevisionId id = artifactsReport.getArtifact().getModuleRevisionId();
                String type = getType(artifactsReport.getArtifact());
                Dependency dependency = findDependencyInList(id, type, moduleDependencies);
                if (dependency == null) {
                    DependencyBuilder dependencyBuilder = new DependencyBuilder();
                    dependencyBuilder.type(type).scopes(Sets.newHashSet(configuration));
                    String idString = getModuleIdString(id.getOrganisation(), id.getName(), id.getRevision());
                    dependencyBuilder.id(idString);
                    File file = artifactsReport.getLocalFile();
                    Map<String, String> checksums;
                    try {
                        checksums = FileChecksumCalculator.calculateChecksums(file, MD5, SHA1);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    String md5 = checksums.get(MD5);
                    String sha1 = checksums.get(SHA1);
                    dependencyBuilder.md5(md5).sha1(sha1);
                    dependency = dependencyBuilder.build();
                    moduleDependencies.add(dependency);
                    project.log("[buildinfo:collect] Added dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
                } else {
                    if (!dependency.getScopes().contains(configuration)) {
                        dependency.getScopes().add(configuration);
                        project.log("[buildinfo:collect] Added scope " + configuration + " to dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
                    } else {
                        project.log("[buildinfo:collect] Find same dependency twice in configuration '" + configuration + "' for dependency '" + artifactsReport + "'", Project.MSG_WARN);
                    }
                }
            }
        }
        module.setDependencies(moduleDependencies);
    }
}
Also used : ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) Dependency(org.jfrog.build.api.Dependency) EndResolveEvent(org.apache.ivy.core.event.resolve.EndResolveEvent) Project(org.apache.tools.ant.Project) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) DependencyBuilder(org.jfrog.build.api.builder.DependencyBuilder) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) Module(org.jfrog.build.api.Module) File(java.io.File)

Example 3 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class CacheResolver method download.

@Override
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    ensureConfigured();
    clearArtifactAttempts();
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
        dr.addArtifactReport(adr);
        ResolvedResource artifactRef = getArtifactRef(artifact, null);
        if (artifactRef != null) {
            Message.verbose("\t[NOT REQUIRED] " + artifact);
            ArtifactOrigin origin = new ArtifactOrigin(artifact, true, artifactRef.getResource().getName());
            File archiveFile = ((FileResource) artifactRef.getResource()).getFile();
            adr.setDownloadStatus(DownloadStatus.NO);
            adr.setSize(archiveFile.length());
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(archiveFile);
        } else {
            adr.setDownloadStatus(DownloadStatus.FAILED);
        }
    }
    return dr;
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact)

Example 4 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class ChainResolver method download.

public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    List<Artifact> artifactsToDownload = new ArrayList<>(Arrays.asList(artifacts));
    DownloadReport report = new DownloadReport();
    for (DependencyResolver resolver : chain) {
        if (artifactsToDownload.isEmpty()) {
            break;
        }
        DownloadReport r = resolver.download(artifactsToDownload.toArray(new Artifact[artifactsToDownload.size()]), options);
        for (ArtifactDownloadReport adr : r.getArtifactsReports()) {
            if (adr.getDownloadStatus() != DownloadStatus.FAILED) {
                artifactsToDownload.remove(adr.getArtifact());
                report.addArtifactReport(adr);
            }
        }
    }
    for (Artifact art : artifactsToDownload) {
        ArtifactDownloadReport adr = new ArtifactDownloadReport(art);
        adr.setDownloadStatus(DownloadStatus.FAILED);
        report.addArtifactReport(adr);
    }
    return report;
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArrayList(java.util.ArrayList) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Artifact(org.apache.ivy.core.module.descriptor.Artifact)

Example 5 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class JarResolver method setSettings.

@Override
public void setSettings(ResolverSettings settings) {
    super.setSettings(settings);
    if (url == null) {
        return;
    }
    // let's resolve the url
    ArtifactDownloadReport report;
    EventManager eventManager = getEventManager();
    try {
        if (eventManager != null) {
            getRepository().addTransferListener(eventManager);
        }
        Resource jarResource = new URLResource(url, this.getTimeoutConstraint());
        CacheResourceOptions options = new CacheResourceOptions();
        report = getRepositoryCacheManager().downloadRepositoryResource(jarResource, "jarrepository", "jar", "jar", options, new URLRepository());
    } finally {
        if (eventManager != null) {
            getRepository().removeTransferListener(eventManager);
        }
    }
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        throw new RuntimeException("The jar file " + url.toExternalForm() + " could not be downloaded (" + report.getDownloadDetails() + ")");
    }
    setJarFile(report.getLocalFile());
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) EventManager(org.apache.ivy.core.event.EventManager) Resource(org.apache.ivy.plugins.repository.Resource) URLResource(org.apache.ivy.plugins.repository.url.URLResource) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) CacheResourceOptions(org.apache.ivy.core.cache.CacheResourceOptions) URLRepository(org.apache.ivy.plugins.repository.url.URLRepository)

Aggregations

ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)64 File (java.io.File)33 Artifact (org.apache.ivy.core.module.descriptor.Artifact)29 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)26 Test (org.junit.Test)25 DownloadReport (org.apache.ivy.core.report.DownloadReport)23 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)18 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)17 ResolveReport (org.apache.ivy.core.report.ResolveReport)15 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)11 IOException (java.io.IOException)10 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)10 URL (java.net.URL)8 JarFile (java.util.jar.JarFile)8 Date (java.util.Date)7 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)7 URLResource (org.apache.ivy.plugins.repository.url.URLResource)7 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)6 MalformedURLException (java.net.MalformedURLException)5