Package org.apache.ivy.core.report

Examples of org.apache.ivy.core.report.ArtifactDownloadReport


                        String type = attributes.getValue("type");
                        String ext = attributes.getValue("ext");
                        Artifact artifact = new DefaultArtifact(mrid, pubdate, artifactName,
                                type, ext, ExtendableItemHelper.getExtraAttributes(attributes,
                                    "extra-"));
                        ArtifactDownloadReport aReport = new ArtifactDownloadReport(artifact);
                        aReport.setDownloadStatus(DownloadStatus.fromString(status));
                        aReport.setDownloadDetails(attributes.getValue("details"));
                        aReport.setSize(Long.parseLong(attributes.getValue("size")));
                        aReport.setDownloadTimeMillis(Long.parseLong(attributes.getValue("time")));
                        if (attributes.getValue("location") != null) {
                            aReport.setLocalFile(new File(attributes.getValue("location")));
                        }
                        revisionArtifacts.add(aReport);
                    } else if ("origin-location".equals(qName)) {
                        if (skip) {
                            return;
                        }
                        ArtifactDownloadReport aReport = (ArtifactDownloadReport)
                            revisionArtifacts.get(revisionArtifacts.size() - 1);
                       
                        if (ArtifactOrigin.UNKNOWN.getLocation().equals(
                            attributes.getValue("location"))) {
                            aReport.setArtifactOrigin(ArtifactOrigin.UNKNOWN);
                        } else {
                            aReport.setArtifactOrigin(
                                new ArtifactOrigin(
                                    parseBoolean(attributes.getValue("is-local")),
                                    attributes.getValue("location")));
                        }
                    } else if ("info".equals(qName)) {
                        String organisation = attributes.getValue("organisation");
                        String name = attributes.getValue("module");
                        String branch = attributes.getValue("branch");
                        String revision = attributes.getValue("revision");
                        Map extraAttributes = new HashMap();
                        for (int i = 0; i < attributes.getLength(); i++) {
                            String attName = attributes.getQName(i);
                            if (attName.startsWith("extra-")) {
                                String extraAttrName = attName.substring("extra-".length());
                                String extraAttrValue = attributes.getValue(i);
                                extraAttributes.put(extraAttrName, extraAttrValue);
                            }
                        }
                        mRevisionId = ModuleRevisionId.newInstance(organisation, name, branch,
                            revision, extraAttributes);
                    }
                }

                public void endElement(String uri, String localName, String qname)
                        throws SAXException {
                    if ("dependencies".equals(qname)) {
                        // add the artifacts in the correct order
                        for (Iterator it = revisionsMap.values().iterator(); it.hasNext();) {
                            List artifactReports = (List) it.next();
                            SaxXmlReportParser.this.artifactReports.addAll(artifactReports);
                            for (Iterator iter = artifactReports.iterator(); iter.hasNext();) {
                                ArtifactDownloadReport artifactReport
                                    = (ArtifactDownloadReport) iter.next();
                                if (artifactReport.getDownloadStatus() != DownloadStatus.FAILED) {
                                    artifacts.add(artifactReport.getArtifact());
                                }
                            }
                           
                        }
                    }
View Full Code Here


        RepositoryCacheManager cacheManager = getRepositoryCacheManager();

        clearArtifactAttempts();
        DownloadReport dr = new DownloadReport();
        for (int i = 0; i < artifacts.length; i++) {
            ArtifactDownloadReport adr = cacheManager.download(
                artifacts[i], artifactResourceResolver, downloader,
                getCacheDownloadOptions(options));
            if (DownloadStatus.FAILED == adr.getDownloadStatus()) {
                if (!ArtifactDownloadReport.MISSING_ARTIFACT.equals(adr.getDownloadDetails())) {
                    Message.warn("\t" + adr);
                }
            } else if (DownloadStatus.NO == adr.getDownloadStatus()) {
                Message.verbose("\t" + adr);
            } else if (LogOptions.LOG_QUIET.equals(options.getLog())) {
                Message.verbose("\t" + adr);
            } else {
                Message.info("\t" + adr);
View Full Code Here

    public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
        clearArtifactAttempts();
        DownloadReport dr = new DownloadReport();
        for (int i = 0; i < artifacts.length; i++) {
            final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifacts[i]);
            dr.addArtifactReport(adr);
            ResolvedResource artifactRef = getArtifactRef(artifacts[i], null);
            if (artifactRef != null) {
                Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
                ArtifactOrigin origin = new ArtifactOrigin(
                    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;
    }
View Full Code Here

    public ArtifactDownloadReport download(
            Artifact artifact,
            ArtifactResourceResolver resourceResolver,
            ResourceDownloader resourceDownloader,
            CacheDownloadOptions options) {
        final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
        boolean useOrigin = isUseOrigin();
       
        // TODO: see if we could lock on the artifact to download only, instead of the module
        // metadata artifact. We'd need to store artifact origin and is local in artifact specific
        // file to do so, or lock the metadata artifact only to update artifact origin, which would
        // mean acquiring nested locks, which can be a dangerous thing
        ModuleRevisionId mrid = artifact.getModuleRevisionId();
        if (!lockMetadataArtifact(mrid)) {
            adr.setDownloadStatus(DownloadStatus.FAILED);
            adr.setDownloadDetails("impossible to get lock for " + mrid);
            return adr;
        }
        try {
            DownloadListener listener = options.getListener();
            if (listener != null) {
                listener.needArtifact(this, artifact);
            }
            ArtifactOrigin origin = getSavedArtifactOrigin(artifact);
            // if we can use origin file, we just ask ivy for the file in cache, and it will
            // return the original one if possible. If we are not in useOrigin mode, we use the
            // getArchivePath method which always return a path in the actual cache
            File archiveFile = getArchiveFileInCache(artifact, origin, useOrigin);

            if (archiveFile.exists() && !options.isForce()) {
                adr.setDownloadStatus(DownloadStatus.NO);
                adr.setSize(archiveFile.length());
                adr.setArtifactOrigin(origin);
                adr.setLocalFile(archiveFile);
            } else {
                long start = System.currentTimeMillis();
                try {
                    ResolvedResource artifactRef = resourceResolver.resolve(artifact);
                    if (artifactRef != null) {
                        origin = new ArtifactOrigin(artifactRef.getResource().isLocal(),
                            artifactRef.getResource().getName());
                        if (useOrigin && artifactRef.getResource().isLocal()) {
                            saveArtifactOrigin(artifact, origin);
                            archiveFile = getArchiveFileInCache(artifact,
                                origin);
                            adr.setDownloadStatus(DownloadStatus.NO);
                            adr.setSize(archiveFile.length());
                            adr.setArtifactOrigin(origin);
                            adr.setLocalFile(archiveFile);
                        } else {
                            // refresh archive file now that we better now its origin
                            archiveFile = getArchiveFileInCache(artifact,
                                origin, useOrigin);
                            if (ResourceHelper.equals(artifactRef.getResource(), archiveFile)) {
                                throw new IllegalStateException("invalid settings for '"
                                    + resourceResolver
                                    + "': pointing repository to ivy cache is forbidden !");
                            }
                            if (listener != null) {
                                listener.startArtifactDownload(this, artifactRef, artifact, origin);
                            }

                            resourceDownloader.download(
                                artifact, artifactRef.getResource(), archiveFile);
                            adr.setSize(archiveFile.length());
                            saveArtifactOrigin(artifact, origin);
                            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
                            adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
                            adr.setArtifactOrigin(origin);
                            adr.setLocalFile(archiveFile);
                        }
                    } else {
                        adr.setDownloadStatus(DownloadStatus.FAILED);
                        adr.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT);
                        adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
                    }
                } catch (Exception ex) {
                    adr.setDownloadStatus(DownloadStatus.FAILED);
                    adr.setDownloadDetails(ex.getMessage());
                    adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
                }
            }
            if (listener != null) {
                listener.endArtifactDownload(this, artifact, adr, archiveFile);
            }
View Full Code Here

            Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options)
            throws ParseException {
        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry
            .getInstance().getParser(mdRef.getResource());
        Date cachedPublicationDate = null;
        ArtifactDownloadReport report;
        ModuleRevisionId mrid = moduleArtifact.getModuleRevisionId();
        Artifact originalMetadataArtifact = getOriginalMetadataArtifact(moduleArtifact);
        if (!lockMetadataArtifact(mrid)) {
            Message.error("impossible to acquire lock for " + mrid);
            return null;
        }
        try {
            // now let's see if we can find it in cache and if it is up to date
            ResolvedModuleRevision rmr = doFindModuleInCache(mrid, options, null);
            if (rmr != null) {
                if (rmr.getDescriptor().isDefault() && rmr.getResolver() != resolver) {
                    Message.verbose("\t" + getName() + ": found revision in cache: " + mrid
                        + " (resolved by " + rmr.getResolver().getName()
                        + "): but it's a default one, maybe we can find a better one");
                } else {
                    if (!isCheckmodified(dd, options) && !isChanging(dd, options)) {
                        Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
                        rmr.getReport().setSearched(true);
                        return rmr;
                    }
                    long repLastModified = mdRef.getLastModified();
                    long cacheLastModified = rmr.getDescriptor().getLastModified();
                    if (!rmr.getDescriptor().isDefault() && repLastModified <= cacheLastModified) {
                        Message.verbose("\t" + getName() + ": revision in cache (not updated): "
                            + mrid);
                        rmr.getReport().setSearched(true);
                        return rmr;
                    } else {
                        Message.verbose("\t" + getName() + ": revision in cache is not up to date: "
                            + mrid);
                        if (isChanging(dd, options)) {
                            // ivy file has been updated, we should see if it has a new publication
                            // date to see if a new download is required (in case the dependency is
                            // a changing one)
                            cachedPublicationDate =
                                rmr.getDescriptor().getResolvedPublicationDate();
                        }
                    }
                }
            }

            // now download module descriptor and parse it
            report = download(
                originalMetadataArtifact,
                new ArtifactResourceResolver() {
                    public ResolvedResource resolve(Artifact artifact) {
                        return mdRef;
                    }
                }, downloader,
                new CacheDownloadOptions().setListener(options.getListener()).setForce(true));
            Message.verbose("\t" + report);

            if (report.getDownloadStatus() == DownloadStatus.FAILED) {
                Message.warn("problem while downloading module descriptor: " + mdRef.getResource()
                    + ": " + report.getDownloadDetails()
                    + " (" + report.getDownloadTimeMillis() + "ms)");
                return null;
            }

            URL cachedMDURL = null;
            try {
                cachedMDURL = report.getLocalFile().toURL();
            } catch (MalformedURLException ex) {
                Message.warn("malformed url exception for original in cache file: "
                    + report.getLocalFile() + ": " + ex.getMessage());
                return null;
            }
            try {
                ModuleDescriptor md = parser.parseDescriptor(
                    settings, cachedMDURL, mdRef.getResource(), options.isValidate());
                if (md == null) {
                    throw new IllegalStateException(
                        "module descriptor parser returned a null module descriptor, "
                        + "which is not allowed. "
                        + "parser=" + parser
                        + "; parser class=" + parser.getClass().getName()
                        + "; module descriptor resource=" + mdRef.getResource());
                }
                Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid
                    + "; parsed=" + md.getModuleRevisionId());

                // check if we should delete old artifacts
                boolean deleteOldArtifacts = false;
                if (cachedPublicationDate != null
                        && !cachedPublicationDate.equals(md.getResolvedPublicationDate())) {
                    // artifacts have changed, they should be downloaded again
                    Message.verbose(mrid + " has changed: deleting old artifacts");
                    deleteOldArtifacts = true;
                }
                if (deleteOldArtifacts) {
                    String[] confs = md.getConfigurationsNames();
                    for (int i = 0; i < confs.length; i++) {
                        Artifact[] arts = md.getArtifacts(confs[i]);
                        for (int j = 0; j < arts.length; j++) {
                            Artifact transformedArtifact = NameSpaceHelper.transform(
                                arts[j], options.getNamespace().getToSystemTransformer());
                            ArtifactOrigin origin = getSavedArtifactOrigin(
                                transformedArtifact);
                            File artFile = getArchiveFileInCache(
                                transformedArtifact, origin, false);
                            if (artFile.exists()) {
                                Message.debug("deleting " + artFile);
                                artFile.delete();
                            }
                            removeSavedArtifactOrigin(transformedArtifact);
                        }
                    }
                } else if (isChanging(dd, options)) {
                    Message.verbose(mrid
                        + " is changing, but has not changed: will trust cached artifacts if any");
                }
               
                MetadataArtifactDownloadReport madr
                    = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
                madr.setSearched(true);
                madr.setDownloadStatus(report.getDownloadStatus());
                madr.setDownloadDetails(report.getDownloadDetails());
                madr.setArtifactOrigin(report.getArtifactOrigin());
                madr.setDownloadTimeMillis(report.getDownloadTimeMillis());
                madr.setOriginalLocalFile(report.getLocalFile());
                madr.setSize(report.getSize());
                saveArtifactOrigin(md.getMetadataArtifact(), report.getArtifactOrigin());
               
                return new ResolvedModuleRevision(resolver, resolver, md, madr);
            } catch (IOException ex) {
                Message.warn("io problem while parsing ivy file: " + mdRef.getResource() + ": "
                    + ex.getMessage());
View Full Code Here

        RepositoryCacheManager cacheManager = getRepositoryCacheManager();

        clearArtifactAttempts();
        DownloadReport dr = new DownloadReport();
        for (int i = 0; i < artifacts.length; i++) {
            ArtifactDownloadReport adr = cacheManager.download(
                artifacts[i], artifactResourceResolver, downloader,
                getCacheDownloadOptions(options));
            if (DownloadStatus.FAILED == adr.getDownloadStatus()) {
                if (!ArtifactDownloadReport.MISSING_ARTIFACT.equals(adr.getDownloadDetails())) {
                    Message.warn("\t" + adr);
                }
            } else if (DownloadStatus.NO == adr.getDownloadStatus()) {
                Message.verbose("\t" + adr);
            } else if (LogOptions.LOG_QUIET.equals(options.getLog())) {
                Message.verbose("\t" + adr);
            } else {
                Message.info("\t" + adr);
View Full Code Here

            // do retrieve
            int targetsCopied = 0;
            int targetsUpToDate = 0;
            long totalCopiedSize = 0;
            for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) {
                ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next();
                File archive = artifact.getLocalFile();
                if (archive == null) {
                    Message.verbose("\tno local file available for " + artifact + ": skipping");
                    continue;
                }
                Set dest = (Set) artifactsToCopy.get(artifact);
                Message.verbose("\tretrieving " + archive);
                for (Iterator it2 = dest.iterator(); it2.hasNext();) {
                    IvyContext.getContext().checkInterrupted();
                    File destFile = new File((String) it2.next());
                    if (!settings.isCheckUpToDate() || !upToDate(archive, destFile)) {
                        Message.verbose("\t\tto " + destFile);
                        if (options.isMakeSymlinks()) {
                            FileUtil.symlink(archive, destFile, null, true);
                        } else {
                            FileUtil.copy(archive, destFile, null, true);
                        }
                        totalCopiedSize += destFile.length();
                        targetsCopied++;
                    } else {
                        Message.verbose("\t\tto " + destFile + " [NOT REQUIRED]");
                        targetsUpToDate++;
                    }
                    if ("ivy".equals(artifact.getType())) {
                        targetIvysStructure
                                .addAll(FileUtil.getPathFiles(ivyRetrieveRoot, destFile));
                    } else {
                        targetArtifactsStructure.addAll(FileUtil.getPathFiles(fileRetrieveRoot,
                            destFile));
View Full Code Here

                for (int j = 0; j < mrids.length; j++) {
                    artifacts.add(parser.getMetadataArtifactReport(mrids[j]));
                }
            }
            for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
                ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next();
                String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern
                        : destFilePattern;

                if (!"ivy".equals(artifact.getType())
                        && !options.getArtifactFilter().accept(artifact.getArtifact())) {
                    continue; // skip this artifact, the filter didn't accept it!
                }

                String destFileName = IvyPatternHelper.substitute(
                                        destPattern, artifact.getArtifact(), conf);

                Set dest = (Set) artifactsToCopy.get(artifact);
                if (dest == null) {
                    dest = new HashSet();
                    artifactsToCopy.put(artifact, dest);
                }
                String copyDest = new File(destFileName).getAbsolutePath();
                dest.add(copyDest);

                Set conflicts = (Set) conflictsMap.get(copyDest);
                Set conflictsConf = (Set) conflictsConfMap.get(copyDest);
                if (conflicts == null) {
                    conflicts = new HashSet();
                    conflictsMap.put(copyDest, conflicts);
                }
                if (conflictsConf == null) {
                    conflictsConf = new HashSet();
                    conflictsConfMap.put(copyDest, conflictsConf);
                }
                conflicts.add(artifact);
                conflictsConf.add(conf);
            }
        }

        // resolve conflicts if any
        for (Iterator iter = conflictsMap.keySet().iterator(); iter.hasNext();) {
            String copyDest = (String) iter.next();
            Set artifacts = (Set) conflictsMap.get(copyDest);
            Set conflictsConfs = (Set) conflictsConfMap.get(copyDest);
            if (artifacts.size() > 1) {
                List artifactsList = new ArrayList(artifacts);
                // conflicts battle is resolved by a sort using a conflict resolving policy
                // comparator
                // which consider as greater a winning artifact
                Collections.sort(artifactsList, getConflictResolvingPolicy());
                // after the sort, the winning artifact is the greatest one, i.e. the last one
                Message.info("\tconflict on "
                        + copyDest
                        + " in "
                        + conflictsConfs
                        + ": "
                        + ((ArtifactDownloadReport) artifactsList.get(artifactsList.size() - 1))
                                .getArtifact().getModuleRevisionId().getRevision() + " won");

                // we now iterate over the list beginning with the artifact preceding the winner,
                // and going backward to the least artifact
                for (int i = artifactsList.size() - 2; i >= 0; i--) {
                    ArtifactDownloadReport looser = (ArtifactDownloadReport) artifactsList.get(i);
                    Message.verbose("\t\tremoving conflict looser artifact: "
                        + looser.getArtifact());
                    // for each loser, we remove the pair (loser - copyDest) in the artifactsToCopy
                    // map
                    Set dest = (Set) artifactsToCopy.get(looser);
                    dest.remove(copyDest);
                    if (dest.isEmpty()) {
View Full Code Here

                }
            }
        }
        for (Iterator iter = artifactsToDownload.iterator(); iter.hasNext();) {
            Artifact art = (Artifact) iter.next();
            ArtifactDownloadReport adr = new ArtifactDownloadReport(art);
            adr.setDownloadStatus(DownloadStatus.FAILED);
            report.addArtifactReport(adr);
        }
        return report;
    }
View Full Code Here

                parser.parse(report);

                all.addAll(Arrays.asList(parser.getArtifactReports()));
            }
            for (Iterator iter = all.iterator(); iter.hasNext();) {
                ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next();
                if (artifact.getLocalFile() != null) {
                    buf.append(artifact.getLocalFile().getCanonicalPath());
                    buf.append(pathSeparator);
                }
            }
           
            PrintWriter writer = new PrintWriter(new FileOutputStream(outFile));
View Full Code Here

TOP

Related Classes of org.apache.ivy.core.report.ArtifactDownloadReport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.