Search in sources :

Example 6 with ModuleDescriptor

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

the class DefaultRepositoryCacheManager method doFindModuleInCache.

private ResolvedModuleRevision doFindModuleInCache(ModuleRevisionId mrid, CacheMetadataOptions options, String expectedResolver) {
    if (!lockMetadataArtifact(mrid)) {
        Message.error("impossible to acquire lock for " + mrid);
        return null;
    }
    boolean unlock = true;
    try {
        if (settings.getVersionMatcher().isDynamic(mrid)) {
            String resolvedRevision = getResolvedRevision(expectedResolver, mrid, options);
            if (resolvedRevision == null) {
                return null;
            }
            Message.verbose("found resolved revision in cache: " + mrid + " => " + resolvedRevision);
            // we have found another module in the cache, make sure we unlock
            // the original module
            unlockMetadataArtifact(mrid);
            mrid = ModuleRevisionId.newInstance(mrid, resolvedRevision);
            // don't forget to request a lock on the new module!
            if (!lockMetadataArtifact(mrid)) {
                Message.error("impossible to acquire lock for " + mrid);
                // we couldn't lock the new module, so no need to unlock it
                unlock = false;
                return null;
            }
        }
        File ivyFile = getIvyFileInCache(mrid);
        if (ivyFile.exists()) {
            // found in cache !
            try {
                ModuleDescriptorParser parser = getModuleDescriptorParser(ivyFile);
                ModuleDescriptor depMD = getMdFromCache(parser, options, ivyFile);
                String resolverName = getSavedResolverName(depMD);
                String artResolverName = getSavedArtResolverName(depMD);
                DependencyResolver resolver = settings.getResolver(resolverName);
                if (resolver == null) {
                    Message.debug("\tresolver not found: " + resolverName + " => trying to use the one configured for " + mrid);
                    resolver = settings.getResolver(depMD.getResolvedModuleRevisionId());
                    if (resolver != null) {
                        Message.debug("\tconfigured resolver found for " + depMD.getResolvedModuleRevisionId() + ": " + resolver.getName() + ": saving this data");
                        saveResolver(depMD, resolver.getName());
                    }
                }
                DependencyResolver artResolver = settings.getResolver(artResolverName);
                if (artResolver == null) {
                    artResolver = resolver;
                }
                if (resolver != null) {
                    Message.debug("\tfound ivy file in cache for " + mrid + " (resolved by " + resolver.getName() + "): " + ivyFile);
                    if (expectedResolver == null || expectedResolver.equals(resolver.getName())) {
                        MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(depMD.getMetadataArtifact());
                        madr.setDownloadStatus(DownloadStatus.NO);
                        madr.setSearched(false);
                        madr.setLocalFile(ivyFile);
                        madr.setSize(ivyFile.length());
                        madr.setArtifactOrigin(getSavedArtifactOrigin(depMD.getMetadataArtifact()));
                        if (madr.getArtifactOrigin().isExists()) {
                            if (madr.getArtifactOrigin().isLocal() && madr.getArtifactOrigin().getArtifact().getUrl() != null) {
                                madr.setOriginalLocalFile(new File(madr.getArtifactOrigin().getArtifact().getUrl().toURI()));
                            } else {
                                // find locally cached file
                                madr.setOriginalLocalFile(getArchiveFileInCache(madr.getArtifactOrigin().getArtifact()));
                            }
                        }
                        return new ResolvedModuleRevision(resolver, artResolver, depMD, madr);
                    }
                    Message.debug("found module in cache but with a different resolver: " + "discarding: " + mrid + "; expected resolver=" + expectedResolver + "; resolver=" + resolver.getName());
                } else {
                    Message.debug("\tresolver not found: " + resolverName + " => cannot use cached ivy file for " + mrid);
                }
            } catch (Exception e) {
                // will try with resolver
                Message.debug("\tproblem while parsing cached ivy file for: " + mrid, e);
            }
        } else {
            Message.debug("\tno ivy file in cache for " + mrid + ": tried " + ivyFile);
        }
    } finally {
        if (unlock) {
            unlockMetadataArtifact(mrid);
        }
    }
    return null;
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) PropertiesFile(org.apache.ivy.util.PropertiesFile) File(java.io.File) ModuleDescriptorParser(org.apache.ivy.plugins.parser.ModuleDescriptorParser) XmlModuleDescriptorParser(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser) ParseException(java.text.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 7 with ModuleDescriptor

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

the class ModuleDescriptorMemoryCache method getStale.

/**
 * Get the module descriptor from the mdProvider and store it into the cache.
 */
public ModuleDescriptor getStale(File ivyFile, ParserSettings ivySettings, boolean validated, ModuleDescriptorProvider mdProvider) throws ParseException, IOException {
    ParserSettingsMonitor settingsMonitor = new ParserSettingsMonitor(ivySettings);
    ModuleDescriptor descriptor = mdProvider.provideModule(settingsMonitor.getMonitoredSettings(), ivyFile, validated);
    putInCache(ivyFile, settingsMonitor, validated, descriptor);
    return descriptor;
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor)

Example 8 with ModuleDescriptor

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

the class IvyInfo method doExecute.

public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    try {
        if (organisation != null || module != null || revision != null || branch != null) {
            if (organisation == null) {
                throw new BuildException("no organisation provided for ivy info task");
            }
            if (module == null) {
                throw new BuildException("no module name provided for ivy info task");
            }
            if (revision == null) {
                throw new BuildException("no revision provided for ivy info task");
            }
            if (branch == null) {
                settings.getDefaultBranch(new ModuleId(organisation, module));
            }
            ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(organisation, module, branch, revision));
            if (rmr != null) {
                ModuleDescriptor md = rmr.getDescriptor();
                ModuleRevisionId mrid = rmr.getId();
                setProperties(md, mrid);
            }
        } else {
            if (file == null) {
                file = getProject().resolveFile(getProperty(settings, "ivy.dep.file"));
            }
            ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(settings, file.toURI().toURL(), doValidate(settings));
            ModuleRevisionId mrid = md.getModuleRevisionId();
            setProperties(md, mrid);
        }
    } catch (MalformedURLException e) {
        throw new BuildException("unable to convert given ivy file to url: " + file + ": " + e, e);
    } catch (ParseException e) {
        log(e.getMessage(), Project.MSG_ERR);
        throw new BuildException("syntax errors in ivy file: " + e, e);
    } catch (Exception e) {
        throw new BuildException("impossible to resolve dependencies: " + e, e);
    }
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) MalformedURLException(java.net.MalformedURLException) IvySettings(org.apache.ivy.core.settings.IvySettings) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) Ivy(org.apache.ivy.Ivy) MalformedURLException(java.net.MalformedURLException) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException)

Example 9 with ModuleDescriptor

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

the class IvyMakePom method doExecute.

@Override
public void doExecute() throws BuildException {
    try {
        if (ivyFile == null) {
            throw new BuildException("source ivy file is required for makepom task");
        }
        if (pomFile == null) {
            throw new BuildException("destination pom file is required for makepom task");
        }
        ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(getSettings(), ivyFile.toURI().toURL(), false);
        PomModuleDescriptorWriter.write(md, pomFile, getPomWriterOptions());
    } catch (MalformedURLException e) {
        throw new BuildException("unable to convert given ivy file to url: " + ivyFile + ": " + e, e);
    } catch (ParseException e) {
        log(e.getMessage(), Project.MSG_ERR);
        throw new BuildException("syntax errors in ivy file " + ivyFile + ": " + e, e);
    } catch (Exception e) {
        throw new BuildException("impossible convert given ivy file to pom file: " + e + " from=" + ivyFile + " to=" + pomFile, e);
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) MalformedURLException(java.net.MalformedURLException) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException)

Example 10 with ModuleDescriptor

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

the class IvyPostResolveTask method getConfsToResolve.

protected String[] getConfsToResolve(String resolveId, String conf) {
    ModuleDescriptor reference = getResolvedDescriptor(resolveId, false);
    if (reference == null) {
        // TODO: find a way to discover which confs were resolved by that previous resolve
        if (conf == null) {
            return new String[] { "*" };
        }
        return splitToArray(conf);
    }
    String[] rconfs = getProject().getReference("ivy.resolved.configurations.ref." + resolveId);
    return getConfsToResolve(reference, conf, rconfs);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor)

Aggregations

ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)284 Test (org.junit.Test)233 File (java.io.File)143 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)114 ResolveReport (org.apache.ivy.core.report.ResolveReport)94 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)80 JarFile (java.util.jar.JarFile)76 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)76 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)69 IvySettings (org.apache.ivy.core.settings.IvySettings)60 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)44 Configuration (org.apache.ivy.core.module.descriptor.Configuration)30 Artifact (org.apache.ivy.core.module.descriptor.Artifact)28 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)27 IOException (java.io.IOException)24 ParseException (java.text.ParseException)23 Ivy (org.apache.ivy.Ivy)23 BufferedReader (java.io.BufferedReader)19 FileReader (java.io.FileReader)19 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)17