Package org.apache.ivy.core.cache

Examples of org.apache.ivy.core.cache.CacheManager


            }
        }
        try {
            Path path = new Path(getProject());
            getProject().addReference(pathid, path);
            CacheManager cache = getCacheManager();
            for (Iterator iter = getArtifacts().iterator(); iter.hasNext();) {
                Artifact a = (Artifact) iter.next();
                path.createPathElement().setLocation(
                    cache.getArchiveFileInCache(a, cache.getSavedArtifactOrigin(a), isUseOrigin()));
            }
        } catch (Exception ex) {
            throw new BuildException("impossible to build ivy path: " + ex, ex);
        }
View Full Code Here


            // verify that the module in the default cache doesn't exist
            assertEquals("Default cache is not empty", cache.list().length, 0);

            // verify the artifact does exist in the non-default cache.
            CacheManager nonDefaultManager = ivy.getCacheManager(cache2);
            assertTrue(TestHelper.getArchiveFileInCache(nonDefaultManager, "org1", "mod1.1", "1.0",
                "mod1.1", "jar", "jar").exists());
            assertTrue(nonDefaultManager.getResolvedIvyFileInCache(resolvedModule).exists());
            assertTrue(nonDefaultManager.getResolvedIvyPropertiesInCache(resolvedModule).exists());
            assertNotNull(nonDefaultManager.getSavedArtifactOrigin((Artifact) report.getArtifacts()
                    .get(0)));
        } finally {
            // delete the non-default cache
            Delete del = new Delete();
            del.setProject(new Project());
View Full Code Here

    }

    public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
        IvyContext.getContext().pushResolver(this);
        try {
            CacheManager cacheManager = options.getCacheManager();
            EventManager eventManager = options.getEventManager();

            boolean useOrigin = options.isUseOrigin();

            clearArtifactAttempts();
            DownloadReport dr = new DownloadReport();
            for (int i = 0; i < artifacts.length; i++) {
                final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifacts[i]);
                dr.addArtifactReport(adr);
                if (eventManager != null) {
                    eventManager.fireIvyEvent(new NeedArtifactEvent(this, artifacts[i]));
                }
                ArtifactOrigin origin = cacheManager.getSavedArtifactOrigin(artifacts[i]);
                // 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 = cacheManager.getArchiveFileInCache(artifacts[i], origin, options
                        .isUseOrigin());

                if (archiveFile.exists()) {
                    Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
                    adr.setDownloadStatus(DownloadStatus.NO);
                    adr.setSize(archiveFile.length());
                    adr.setArtifactOrigin(origin);
                } else {
                    Artifact artifact = fromSystem(artifacts[i]);
                    if (!artifact.equals(artifacts[i])) {
                        Message.verbose("\t" + getName() + "looking for artifact " + artifact
                                + " (is " + artifacts[i] + " in system namespace)");
                    }
                    long start = System.currentTimeMillis();
                    try {
                        ResolvedResource artifactRef = getArtifactRef(artifact, null);
                        if (artifactRef != null) {
                            origin = new ArtifactOrigin(artifactRef.getResource().isLocal(),
                                    artifactRef.getResource().getName());
                            if (useOrigin && artifactRef.getResource().isLocal()) {
                                Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
                                cacheManager.saveArtifactOrigin(artifacts[i], origin);
                                archiveFile = cacheManager.getArchiveFileInCache(artifacts[i],
                                    origin);
                                adr.setDownloadStatus(DownloadStatus.NO);
                                adr.setSize(archiveFile.length());
                                adr.setArtifactOrigin(origin);
                            } else {
                                // refresh archive file now that we better now its origin
                                archiveFile = cacheManager.getArchiveFileInCache(artifacts[i],
                                    origin, useOrigin);
                                if (ResourceHelper.equals(artifactRef.getResource(), archiveFile)) {
                                    Message.error("invalid configuration for resolver '"
                                            + getName()
                                            + "': pointing artifacts to ivy cache is forbidden !");
                                    return null;
                                }
                                Message.info("downloading " + artifactRef.getResource() + " ...");
                                if (eventManager != null) {
                                    eventManager.fireIvyEvent(new StartArtifactDownloadEvent(this,
                                            artifacts[i], origin));
                                }

                                File tmp = cacheManager.getArchiveFileInCache(new DefaultArtifact(
                                        artifacts[i].getModuleRevisionId(), artifacts[i]
                                                .getPublicationDate(), artifacts[i].getName(),
                                        artifacts[i].getType(), artifacts[i].getExt() + ".part",
                                        artifacts[i].getExtraAttributes()), origin, useOrigin);

                                // deal with artifact with url special case
                                if (artifactRef.getResource().getName().equals(
                                    String.valueOf(artifacts[i].getUrl()))) {
                                    Message.verbose("\t" + getName() + ": downloading "
                                            + artifactRef.getResource().getName());
                                    Message.debug("\t\tto " + tmp);
                                    if (tmp.getParentFile() != null) {
                                        tmp.getParentFile().mkdirs();
                                    }
                                    extartifactrep.get(artifactRef.getResource().getName(), tmp);
                                    adr.setSize(tmp.length());
                                } else {
                                    adr.setSize(getAndCheck(artifactRef.getResource(), tmp));
                                }
                                if (!tmp.renameTo(archiveFile)) {
                                    Message.warn("\t[FAILED     ] " + artifacts[i]
                                            + " impossible to move temp file to definitive one ("
                                            + (System.currentTimeMillis() - start) + "ms)");
                                    adr.setDownloadStatus(DownloadStatus.FAILED);
                                } else {
                                    cacheManager.saveArtifactOrigin(artifacts[i], origin);
                                    Message.info("\t[SUCCESSFUL ] " + artifacts[i] + " ("
                                            + (System.currentTimeMillis() - start) + "ms)");
                                    adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
                                    adr.setArtifactOrigin(origin);
                                }
View Full Code Here

            List paths = getArtifacts();
            if (paths.isEmpty()) {
                NameEntry ne = fileset.createExclude();
                ne.setName("**/*");
            } else {
                CacheManager cache = getCacheManager();
                for (Iterator iter = paths.iterator(); iter.hasNext();) {
                    Artifact a = (Artifact) iter.next();
                    NameEntry ne = fileset.createInclude();
                    ne.setName(cache.getArchivePathInCache(a, cache.getSavedArtifactOrigin(a)));
                }
            }
        } catch (Exception ex) {
            throw new BuildException("impossible to build ivy cache fileset: " + ex, ex);
        }
View Full Code Here

    public void output(ConfigurationResolveReport report, String resolveId, String[] confs,
            File destDir) {
        try {
            destDir.mkdirs();
            CacheManager cacheMgr = new CacheManager(null, destDir);
            File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, report
                    .getConfiguration());
            OutputStream stream = new FileOutputStream(reportFile);
            output(report, confs, stream);
            stream.close();
View Full Code Here

        return "working@" + HostUtil.getLocalHostName();
    }

    public CacheManager getCacheManager(File cache) {
        // TODO : reuse instance
        CacheManager cacheManager = new CacheManager(settings, cache);
        return cacheManager;
    }
View Full Code Here

            }
        } else {
            Message.debug("using stored report to get artifacts list");

            XmlReportParser parser = new XmlReportParser();
            CacheManager cacheMgr = getIvyInstance().getCacheManager(getCache());
            for (int i = 0; i < confs.length; i++) {
                File reportFile = cacheMgr.getConfigurationResolveReportInCache(getResolveId(),
                    confs[i]);
                parser.parse(reportFile);

                Artifact[] artifacts = parser.getArtifacts();
                all.addAll(Arrays.asList(artifacts));
View Full Code Here

        }
        return all;
    }

    protected CacheManager getCacheManager() {
        CacheManager cache = new CacheManager(getSettings(), getCache());
        return cache;
    }
View Full Code Here

        }
    }

    private void genxml(File cache, String organisation, String module, String[] confs)
            throws IOException {
        CacheManager cacheMgr = getIvyInstance().getCacheManager(cache);
        for (int i = 0; i < confs.length; i++) {
            File xml = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]);

            File out;
            if (todir != null) {
                out = new File(todir, IvyPatternHelper.substitute(outputpattern, organisation,
                    module, "", "", "", "xml", confs[i]));
View Full Code Here

        xslt.setBasedir(cache);

        Mapper mapper = new Mapper(getProject());
        xslt.addMapper(mapper);

        CacheManager cacheMgr = getIvyInstance().getCacheManager(cache);
        for (int i = 0; i < confs.length; i++) {
            File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]);
            xslt.setIncludes(reportFile.getName());

            FileNameMapper reportMapper = new GlobPatternMapper();
            reportMapper.setFrom(reportFile.getName());
            reportMapper.setTo(IvyPatternHelper.substitute(outputpattern, organisation, module,
View Full Code Here

TOP

Related Classes of org.apache.ivy.core.cache.CacheManager

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.