Search in sources :

Example 1 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class BasicResolver method getDependency.

public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
    IvyContext context = IvyContext.pushNewCopyContext();
    try {
        ResolvedModuleRevision mr = data.getCurrentResolvedModuleRevision();
        if (mr != null && shouldReturnResolvedModule(dd, mr)) {
            return mr;
        }
        if (isForce()) {
            dd = dd.clone(ModuleRevisionId.newInstance(dd.getDependencyRevisionId(), "latest.integration"));
        }
        DependencyDescriptor systemDd = dd;
        DependencyDescriptor nsDd = fromSystem(dd);
        context.setDependencyDescriptor(systemDd);
        context.setResolveData(data);
        clearIvyAttempts();
        clearArtifactAttempts();
        ModuleRevisionId systemMrid = systemDd.getDependencyRevisionId();
        ModuleRevisionId nsMrid = nsDd.getDependencyRevisionId();
        checkRevision(systemMrid);
        boolean isDynamic = getAndCheckIsDynamic(systemMrid);
        // we first search for the dependency in cache
        ResolvedModuleRevision rmr = findModuleInCache(systemDd, data);
        if (rmr != null) {
            if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
                Message.verbose("\t" + getName() + ": found revision in cache: " + systemMrid + " (resolved by " + rmr.getResolver().getName() + "): but it's a default one, maybe we can find a better one");
            } else if (isForce() && rmr.getResolver() != this) {
                Message.verbose("\t" + getName() + ": found revision in cache: " + systemMrid + " (resolved by " + rmr.getResolver().getName() + "): but we are in force mode, let's try to find one ourselves");
            } else {
                Message.verbose("\t" + getName() + ": revision in cache: " + systemMrid);
                return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
            }
        }
        if (data.getOptions().isUseCacheOnly()) {
            throw new UnresolvedDependencyException("\t" + getName() + " (useCacheOnly) : no ivy file found for " + systemMrid, false);
        }
        checkInterrupted();
        ResolvedResource ivyRef = findIvyFileRef(nsDd, data);
        checkInterrupted();
        // get module descriptor
        ModuleDescriptor nsMd;
        ModuleDescriptor systemMd = null;
        if (ivyRef == null) {
            if (!isAllownomd()) {
                throw new UnresolvedDependencyException("\t" + getName() + ": no ivy file found for " + systemMrid, false);
            }
            nsMd = DefaultModuleDescriptor.newDefaultInstance(nsMrid, nsDd.getAllDependencyArtifacts());
            ResolvedResource artifactRef = findFirstArtifactRef(nsMd, nsDd, data);
            checkInterrupted();
            if (artifactRef == null) {
                throw new UnresolvedDependencyException("\t" + getName() + ": no ivy file nor artifact found for " + systemMrid, false);
            }
            long lastModified = artifactRef.getLastModified();
            if (lastModified != 0 && nsMd instanceof DefaultModuleDescriptor) {
                ((DefaultModuleDescriptor) nsMd).setLastModified(lastModified);
            }
            Message.verbose("\t" + getName() + ": no ivy file found for " + systemMrid + ": using default data");
            if (isDynamic) {
                nsMd.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(nsMrid, artifactRef.getRevision()));
            }
            systemMd = toSystem(nsMd);
            MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(systemMd.getMetadataArtifact());
            madr.setDownloadStatus(DownloadStatus.NO);
            madr.setSearched(true);
            rmr = new ResolvedModuleRevision(this, this, systemMd, madr, isForce());
            getRepositoryCacheManager().cacheModuleDescriptor(this, artifactRef, toSystem(dd), systemMd.getAllArtifacts()[0], null, getCacheOptions(data));
        } else {
            if (ivyRef instanceof MDResolvedResource) {
                rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
            }
            if (rmr == null) {
                rmr = parse(ivyRef, systemDd, data);
                if (rmr == null) {
                    throw new UnresolvedDependencyException();
                }
            }
            if (!rmr.getReport().isDownloaded() && rmr.getReport().getLocalFile() != null) {
                return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
            }
            nsMd = rmr.getDescriptor();
            // check descriptor data is in sync with resource revision and names
            systemMd = toSystem(nsMd);
            if (isCheckconsistency()) {
                checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
                checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
            } else {
                if (systemMd instanceof DefaultModuleDescriptor) {
                    DefaultModuleDescriptor defaultMd = (DefaultModuleDescriptor) systemMd;
                    ModuleRevisionId revision = getRevision(ivyRef, systemMrid, systemMd);
                    defaultMd.setModuleRevisionId(revision);
                    defaultMd.setResolvedModuleRevisionId(revision);
                } else {
                    Message.warn("consistency disabled with instance of non DefaultModuleDescriptor... module info can't be updated, so consistency check will be done");
                    checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
                    checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
                }
            }
            rmr = new ResolvedModuleRevision(this, this, systemMd, toSystem(rmr.getReport()), isForce());
        }
        resolveAndCheckRevision(systemMd, systemMrid, ivyRef, isDynamic);
        resolveAndCheckPublicationDate(systemDd, systemMd, systemMrid, data);
        checkNotConvertedExclusionRule(systemMd, ivyRef, data);
        if (ivyRef == null || ivyRef.getResource() != null) {
            cacheModuleDescriptor(systemMd, systemMrid, ivyRef, rmr);
        }
        return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
    } catch (UnresolvedDependencyException ex) {
        if (!ex.getMessage().isEmpty()) {
            if (ex.isError()) {
                Message.error(ex.getMessage());
            } else {
                Message.verbose(ex.getMessage());
            }
        }
        return data.getCurrentResolvedModuleRevision();
    } finally {
        IvyContext.popContext();
    }
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvyContext(org.apache.ivy.core.IvyContext) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 2 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class BasicResolver method getDefaultRMDParser.

protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) {
    return new ResourceMDParser() {

        public MDResolvedResource parse(Resource resource, String rev) {
            DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(new ModuleRevisionId(mid, rev));
            MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
            madr.setDownloadStatus(DownloadStatus.NO);
            madr.setSearched(true);
            return new MDResolvedResource(resource, rev, new ResolvedModuleRevision(BasicResolver.this, BasicResolver.this, md, madr, isForce()));
        }
    };
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ResourceMDParser(org.apache.ivy.plugins.resolver.util.ResourceMDParser) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) Resource(org.apache.ivy.plugins.repository.Resource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) URLResource(org.apache.ivy.plugins.repository.url.URLResource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 3 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class JarJarDependencyAnalyser method analyze.

public ModuleDescriptor[] analyze(JarModule[] modules) {
    StringBuilder jarjarCmd = new StringBuilder("java -jar \"").append(jarjarjarLocation.getAbsolutePath()).append("\" --find --level=jar ");
    Map<String, JarModule> jarModulesMap = new HashMap<>();
    Map<ModuleRevisionId, DefaultModuleDescriptor> mds = new HashMap<>();
    for (JarModule jarModule : modules) {
        jarModulesMap.put(jarModule.getJar().getAbsolutePath(), jarModule);
        DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(jarModule.getMrid(), new Date(jarModule.getJar().lastModified()));
        mds.put(jarModule.getMrid(), md);
        jarjarCmd.append("\"").append(jarModule.getJar().getAbsolutePath()).append("\"");
        jarjarCmd.append(File.pathSeparator);
    }
    if (modules.length > 0) {
        jarjarCmd.setLength(jarjarCmd.length() - 1);
    }
    Message.verbose("jarjar command: " + jarjarCmd);
    try {
        Process p = Runtime.getRuntime().exec(jarjarCmd.toString());
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = r.readLine()) != null) {
            String[] deps = line.split(" -> ");
            JarModule module = jarModulesMap.get(deps[0]);
            JarModule dependency = jarModulesMap.get(deps[1]);
            if (module.getMrid().getModuleId().equals(dependency.getMrid().getModuleId())) {
                continue;
            }
            Message.verbose(module.getMrid() + " depends on " + dependency.getMrid());
            DefaultModuleDescriptor md = mds.get(module.getMrid());
            DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, dependency.getMrid(), false, false, true);
            dd.addDependencyConfiguration(ModuleDescriptor.DEFAULT_CONFIGURATION, ModuleDescriptor.DEFAULT_CONFIGURATION);
            md.addDependency(dd);
        }
    } catch (IOException e) {
        Message.debug(e);
    }
    return mds.values().toArray(new ModuleDescriptor[mds.values().size()]);
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IOException(java.io.IOException) Date(java.util.Date) BufferedReader(java.io.BufferedReader) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)

Example 4 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class IvyDependencyUpdateChecker method doExecute.

public void doExecute() throws BuildException {
    prepareAndCheck();
    ModuleDescriptor originalModuleDescriptor = getResolvedReport().getModuleDescriptor();
    // clone module descriptor
    DefaultModuleDescriptor latestModuleDescriptor = new DefaultModuleDescriptor(originalModuleDescriptor.getModuleRevisionId(), originalModuleDescriptor.getStatus(), originalModuleDescriptor.getPublicationDate());
    // copy configurations
    for (Configuration configuration : originalModuleDescriptor.getConfigurations()) {
        latestModuleDescriptor.addConfiguration(configuration);
    }
    // clone dependency and add new one with the requested revisionToCheck
    for (DependencyDescriptor dependencyDescriptor : originalModuleDescriptor.getDependencies()) {
        ModuleRevisionId upToDateMrid = ModuleRevisionId.newInstance(dependencyDescriptor.getDependencyRevisionId(), revisionToCheck);
        latestModuleDescriptor.addDependency(dependencyDescriptor.clone(upToDateMrid));
    }
    // resolve
    ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setDownload(isDownload());
    resolveOptions.setLog(getLog());
    resolveOptions.setConfs(splitToArray(getConf()));
    resolveOptions.setCheckIfChanged(checkIfChanged);
    ResolveReport latestReport;
    try {
        latestReport = getIvyInstance().getResolveEngine().resolve(latestModuleDescriptor, resolveOptions);
        displayDependencyUpdates(getResolvedReport(), latestReport);
        if (showTransitive) {
            displayNewDependencyOnLatest(getResolvedReport(), latestReport);
            displayMissingDependencyOnLatest(getResolvedReport(), latestReport);
        }
    } catch (ParseException | IOException e) {
        throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
    }
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) Configuration(org.apache.ivy.core.module.descriptor.Configuration) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ParseException(java.text.ParseException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions)

Example 5 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class InstallEngine method install.

public ResolveReport install(ModuleRevisionId mrid, String from, String to, InstallOptions options) throws IOException {
    DependencyResolver fromResolver = settings.getResolver(from);
    DependencyResolver toResolver = settings.getResolver(to);
    if (fromResolver == null) {
        throw new IllegalArgumentException("unknown resolver " + from + ". Available resolvers are: " + settings.getResolverNames());
    }
    if (toResolver == null) {
        throw new IllegalArgumentException("unknown resolver " + to + ". Available resolvers are: " + settings.getResolverNames());
    }
    PatternMatcher matcher = settings.getMatcher(options.getMatcherName());
    if (matcher == null) {
        throw new IllegalArgumentException("unknown matcher " + options.getMatcherName() + ". Available matchers are: " + settings.getMatcherNames());
    }
    // build module file declaring the dependency
    Message.info(":: installing " + mrid + " ::");
    DependencyResolver oldDictator = resolveEngine.getDictatorResolver();
    boolean log = settings.logNotConvertedExclusionRule();
    try {
        settings.setLogNotConvertedExclusionRule(true);
        resolveEngine.setDictatorResolver(fromResolver);
        DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("apache", "ivy-install", "1.0"), settings.getStatusManager().getDefaultStatus(), new Date());
        String resolveId = ResolveOptions.getDefaultResolveId(md);
        md.addConfiguration(new Configuration("default"));
        md.addConflictManager(new ModuleId(ExactPatternMatcher.ANY_EXPRESSION, ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, new NoConflictManager());
        for (String dc : options.getConfs()) {
            final String depConf = dc.trim();
            if (MatcherHelper.isExact(matcher, mrid)) {
                DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, false, false, options.isTransitive());
                dd.addDependencyConfiguration("default", depConf);
                md.addDependency(dd);
            } else {
                for (ModuleRevisionId imrid : searchEngine.listModules(fromResolver, mrid, matcher)) {
                    Message.info("\tfound " + imrid + " to install: adding to the list");
                    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, imrid, false, false, options.isTransitive());
                    dd.addDependencyConfiguration("default", depConf);
                    md.addDependency(dd);
                }
            }
        }
        // resolve using appropriate resolver
        ResolveReport report = new ResolveReport(md, resolveId);
        Message.info(":: resolving dependencies ::");
        ResolveOptions resolveOptions = new ResolveOptions().setResolveId(resolveId).setConfs(new String[] { "default" }).setValidate(options.isValidate());
        IvyNode[] dependencies = resolveEngine.getDependencies(md, resolveOptions, report);
        report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());
        Message.info(":: downloading artifacts to cache ::");
        resolveEngine.downloadArtifacts(report, options.getArtifactFilter(), new DownloadOptions());
        // now that everything is in cache, we can publish all these modules
        Message.info(":: installing in " + to + " ::");
        for (IvyNode dependency : dependencies) {
            ModuleDescriptor depmd = dependency.getDescriptor();
            if (depmd != null) {
                ModuleRevisionId depMrid = depmd.getModuleRevisionId();
                Message.verbose("installing " + depMrid);
                boolean successfullyPublished = false;
                try {
                    toResolver.beginPublishTransaction(depMrid, options.isOverwrite());
                    // publish artifacts
                    for (ArtifactDownloadReport artifact : report.getArtifactsReports(depMrid)) {
                        if (artifact.getLocalFile() != null) {
                            toResolver.publish(artifact.getArtifact(), artifact.getLocalFile(), options.isOverwrite());
                        }
                    }
                    // publish metadata
                    MetadataArtifactDownloadReport artifactDownloadReport = dependency.getModuleRevision().getReport();
                    File localIvyFile = artifactDownloadReport.getLocalFile();
                    toResolver.publish(depmd.getMetadataArtifact(), localIvyFile, options.isOverwrite());
                    if (options.isInstallOriginalMetadata()) {
                        if (artifactDownloadReport.getArtifactOrigin() != null && artifactDownloadReport.getArtifactOrigin().isExists() && !ArtifactOrigin.isUnknown(artifactDownloadReport.getArtifactOrigin()) && artifactDownloadReport.getArtifactOrigin().getArtifact() != null && artifactDownloadReport.getArtifactOrigin().getArtifact().getType().endsWith(".original") && !artifactDownloadReport.getArtifactOrigin().getArtifact().getType().equals(depmd.getMetadataArtifact().getType() + ".original")) {
                            // publish original metadata artifact, too, as it has a different
                            // type
                            toResolver.publish(artifactDownloadReport.getArtifactOrigin().getArtifact(), artifactDownloadReport.getOriginalLocalFile(), options.isOverwrite());
                        }
                    }
                    // end module publish
                    toResolver.commitPublishTransaction();
                    successfullyPublished = true;
                } finally {
                    if (!successfullyPublished) {
                        toResolver.abortPublishTransaction();
                    }
                }
            }
        }
        Message.info(":: install resolution report ::");
        // output report
        resolveEngine.outputReport(report, settings.getResolutionCacheManager(), resolveOptions);
        return report;
    } finally {
        // IVY-834: log the problems if there were any...
        Message.sumupProblems();
        resolveEngine.setDictatorResolver(oldDictator);
        settings.setLogNotConvertedExclusionRule(log);
    }
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Date(java.util.Date) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) ModuleId(org.apache.ivy.core.module.id.ModuleId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) NoConflictManager(org.apache.ivy.plugins.conflict.NoConflictManager) ResolveReport(org.apache.ivy.core.report.ResolveReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ExactPatternMatcher(org.apache.ivy.plugins.matcher.ExactPatternMatcher) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Aggregations

DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)30 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)17 Date (java.util.Date)10 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)9 File (java.io.File)7 Configuration (org.apache.ivy.core.module.descriptor.Configuration)7 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 Test (org.junit.Test)6 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)5 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)5 ParseException (java.text.ParseException)4 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)4 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)4 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 Map (java.util.Map)3 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 ModuleId (org.apache.ivy.core.module.id.ModuleId)3