Package org.apache.ivy.core.cache

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


        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, "", "", "", ext, confs[i]));
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();
       
        Message.verbose("\treport for "+report.getModuleDescriptor().getModuleRevisionId()+" "+report.getConfiguration()+" produced in "+reportFile);
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

    }

    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

        DependencyResolver oldDictator = getDictatorResolver();
        if (options.isUseCacheOnly()) {
          setDictatorResolver(new CacheResolver(_settings));
        }
        try {
            CacheManager cacheManager = options.getCache();
            if (cacheManager == null) {  // ensure that a cache is configured
              cacheManager = IvyContext.getContext().getCacheManager();
              options.setCache(cacheManager);
            } else {
              IvyContext.getContext().setCache(cacheManager.getCache());
            }
           
            String[] confs = options.getConfs();
            if (confs.length == 1 && confs[0].equals("*")) {
                confs = md.getConfigurationsNames();
            }
            options.setConfs(confs);
           
            if (options.getResolveId() == null) {
              options.setResolveId(ResolveOptions.getDefaultResolveId(md));
            }
           
            _eventManager.fireIvyEvent(new StartResolveEvent(md, confs));
           
            long start = System.currentTimeMillis();
            Message.info(":: resolving dependencies :: "+md.getResolvedModuleRevisionId()+(options.isTransitive()?"":" [not transitive]"));
            Message.info("\tconfs: "+Arrays.asList(confs));
            Message.verbose("\tvalidate = "+options.isValidate());
            ResolveReport report = new ResolveReport(md, options.getResolveId());

            // resolve dependencies
            IvyNode[] dependencies = getDependencies(md, options, report);
            report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());

           
            // produce resolved ivy file and ivy properties in cache
            File ivyFileInCache = cacheManager.getResolvedIvyFileInCache(md.getResolvedModuleRevisionId());
            md.toIvyFile(ivyFileInCache);

            // we store the resolved dependencies revisions and statuses per asked dependency revision id,
            // for direct dependencies only.
            // this is used by the deliver task to resolve dynamic revisions to static ones
            File ivyPropertiesInCache = cacheManager.getResolvedIvyPropertiesInCache(md.getResolvedModuleRevisionId());
            Properties props = new Properties();
            if (dependencies.length > 0) {
              IvyNode root = dependencies[0].getRoot();
              for (int i = 0; i < dependencies.length; i++) {
                if (!dependencies[i].isCompletelyEvicted() && !dependencies[i].hasProblem()) {
                  DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root);
                  if (dd != null) {
                    String rev = dependencies[i].getResolvedId().getRevision();
                    String status = dependencies[i].getDescriptor().getStatus();
                    props.put(dd.getDependencyRevisionId().encodeToString(), rev+" "+status);
                  }
                }
              }
            }
            props.store(new FileOutputStream(ivyPropertiesInCache), md.getResolvedModuleRevisionId()+ " resolved revisions");
            Message.verbose("\tresolved ivy file produced in "+ivyFileInCache);
           
            report.setResolveTime(System.currentTimeMillis()-start);

            if (options.isDownload()) {
              Message.verbose(":: downloading artifacts ::");
 
              downloadArtifacts(report, cacheManager, options.isUseOrigin(), options.getArtifactFilter());
            }
           
           
            if (options.isOutputReport()) {
              outputReport(report, cacheManager.getCache());
            }
           
            _eventManager.fireIvyEvent(new EndResolveEvent(md, confs, report));
            return report;
        } finally {
View Full Code Here

     */
    public IvyNode[] getDependencies(ModuleDescriptor md, ResolveOptions options, ResolveReport report) {
        if (md == null) {
            throw new NullPointerException("module descriptor must not be null");
        }
        CacheManager cacheManager = options.getCache();
        if (cacheManager == null) {  // ensure that a cache is configured
          cacheManager = IvyContext.getContext().getCacheManager();
          options.setCache(cacheManager);
        } else {
          IvyContext.getContext().setCache(cacheManager.getCache());
        }
       
        String[] confs = options.getConfs();
        if (confs.length == 1 && confs[0].equals("*")) {
            confs = md.getConfigurationsNames();
View Full Code Here

        _pattern = getProperty(_pattern, getSettings(), "ivy.retrieve.pattern");

        try {
            String[] confs = splitConfs(getConf());
            CacheManager cacheManager = CacheManager.getInstance(getSettings(), getCache());
            ModuleDescriptor md = null;
            if (getResolveId() != null) {
              md = (ModuleDescriptor) getResolvedDescriptor(getResolveId());
            } else {
              md = (ModuleDescriptor) getResolvedDescriptor(getOrganisation(), getModule(), false);
View Full Code Here

    public void execute() throws BuildException {
      prepareAndCheck();

        try {
          CacheManager cacheMgr = getIvyInstance().getCacheManager(getCache());
            String[] confs = splitConfs(getConf());
            String resolveId = getResolveId();
            if (resolveId == null) {
              resolveId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
            }
            XmlReportParser parser = new XmlReportParser();
            for (int i = 0; i < confs.length; i++) {
              File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]);
              parser.parse(report);
             
                Artifact[] artifacts = parser.getArtifacts();
                for (int j = 0; j < artifacts.length; j++) {
                    Artifact artifact = artifacts[j];
View Full Code Here

            new ResolveOptions()
              .setResolveId(resolveId)
              .setCache(CacheManager.getInstance(settings, _cache))
              .setValidate(doValidate(settings)));
       
        CacheManager cacheMgr = getIvyInstance().getCacheManager(_cache);
        new XmlReportOutputter().output(report, _cache);
        if (_graph) {
          gengraph(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
        }
        if (_dot) {
          gendot(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
        }
        if (_xml) {
         
          FileUtil.copy(cacheMgr.getConfigurationResolveReportInCache(resolveId, "default"), new File(_todir, _outputname+".xml"), null);
        }
        if (_xsl) {
          genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
        }
        } catch (Exception e) {
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.