Search in sources :

Example 6 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IvyRepositoryReport method doExecute.

public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    if (xsl && xslFile == null) {
        throw new BuildException("xsl file is mandatory when using xsl generation");
    }
    if (module == null && PatternMatcher.EXACT.equals(matcher)) {
        throw new BuildException("no module name provided for ivy repository graph task: " + "It can either be set explicitly via the attribute 'module' or " + "via 'ivy.module' property or a prior call to <resolve/>");
    } else if (module == null && !PatternMatcher.EXACT.equals(matcher)) {
        module = PatternMatcher.ANY_EXPRESSION;
    }
    ModuleRevisionId moduleRevisionId = ModuleRevisionId.newInstance(organisation, module, revision);
    try {
        ModuleRevisionId criteria = (revision == null) || settings.getVersionMatcher().isDynamic(moduleRevisionId) ? new ModuleRevisionId(new ModuleId(organisation, module), branch, "*") : new ModuleRevisionId(new ModuleId(organisation, module), branch, revision);
        ModuleRevisionId[] mrids = ivy.listModules(criteria, settings.getMatcher(matcher));
        // replace all found revisions with the original requested revision
        Set<ModuleRevisionId> modules = new HashSet<>();
        for (ModuleRevisionId mrid : mrids) {
            modules.add(ModuleRevisionId.newInstance(mrid, revision));
        }
        mrids = modules.toArray(new ModuleRevisionId[modules.size()]);
        ModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(mrids, true, false);
        String resolveId = ResolveOptions.getDefaultResolveId(md);
        ResolveReport report = ivy.resolve(md, new ResolveOptions().setResolveId(resolveId).setValidate(doValidate(settings)));
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
        new XmlReportOutputter().output(report, cacheMgr, new ResolveOptions());
        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(getTodir(), outputname + ".xml"), null);
        }
        if (xsl) {
            genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
        }
    } catch (Exception e) {
        throw new BuildException("impossible to generate graph for " + moduleRevisionId + ": " + e, e);
    }
}
Also used : ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Ivy(org.apache.ivy.Ivy) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ModuleId(org.apache.ivy.core.module.id.ModuleId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) XmlReportOutputter(org.apache.ivy.plugins.report.XmlReportOutputter) ResolveReport(org.apache.ivy.core.report.ResolveReport) BuildException(org.apache.tools.ant.BuildException) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) HashSet(java.util.HashSet)

Example 7 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IvyTask method getIvyInstance.

protected Ivy getIvyInstance() {
    Object antIvyEngine;
    if (antIvyEngineRef == null) {
        antIvyEngine = IvyAntSettings.getDefaultInstance(this);
    } else {
        antIvyEngine = antIvyEngineRef.getReferencedObject(getProject());
        if (!antIvyEngine.getClass().getName().equals(IvyAntSettings.class.getName())) {
            throw new BuildException(antIvyEngineRef.getRefId() + " doesn't reference an ivy:settings", getLocation());
        }
        if (!(antIvyEngine instanceof IvyAntSettings)) {
            throw new BuildException(antIvyEngineRef.getRefId() + " has been defined in a different classloader.  " + "Please use the same loader when defining your task, or " + "redeclare your ivy:settings in this classloader", getLocation());
        }
    }
    Ivy ivy = ((IvyAntSettings) antIvyEngine).getConfiguredIvyInstance(this);
    AntMessageLogger.register(this, ivy);
    return ivy;
}
Also used : BuildException(org.apache.tools.ant.BuildException) Ivy(org.apache.ivy.Ivy)

Example 8 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IvyVar method doExecute.

public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    if (getName() != null) {
        settings.setVariable(getVarName(getName()), getValue());
    } else {
        Properties props = new Properties();
        InputStream is = null;
        try {
            if (getFile() != null) {
                is = new FileInputStream(getFile());
            } else if (getUrl() != null) {
                is = new URL(getUrl()).openStream();
            } else {
                throw new BuildException("specify either name or file or url to ivy var task");
            }
            props.load(is);
        } catch (Exception ex) {
            throw new BuildException("impossible to load variables from file: " + ex, ex);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                // ignore
                }
            }
        }
        for (Map.Entry<Object, Object> entry : props.entrySet()) {
            settings.setVariable(getVarName((String) entry.getKey()), (String) entry.getValue());
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IvySettings(org.apache.ivy.core.settings.IvySettings) BuildException(org.apache.tools.ant.BuildException) Properties(java.util.Properties) Ivy(org.apache.ivy.Ivy) Map(java.util.Map) FileInputStream(java.io.FileInputStream) URL(java.net.URL) BuildException(org.apache.tools.ant.BuildException)

Example 9 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IvyConfigureTest method testOverrideTrue.

@Test
public void testOverrideTrue() {
    configure.setFile(new File("test/repositories/ivysettings.xml"));
    configure.execute();
    Ivy ivy = getIvyInstance();
    assertNotNull(ivy);
    configure = new IvyConfigure();
    configure.setProject(project);
    configure.setOverride("true");
    configure.setFile(new File("test/repositories/ivysettings.xml"));
    configure.execute();
    assertNotNull(getIvyInstance());
    assertNotSame(ivy, getIvyInstance());
}
Also used : File(java.io.File) Ivy(org.apache.ivy.Ivy) Test(org.junit.Test)

Example 10 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class BuildOBRTask method doExecute.

public void doExecute() throws BuildException {
    if (file == null) {
        throw new BuildException("No output file specified: use the attribute 'out'");
    }
    Iterable<ManifestAndLocation> it;
    if (resolverName != null) {
        if (baseDir != null) {
            throw new BuildException("specify only one of 'resolver' or 'baseDir'");
        }
        if (cacheName != null) {
            throw new BuildException("specify only one of 'resolver' or 'cache'");
        }
        Ivy ivy = getIvyInstance();
        IvySettings settings = ivy.getSettings();
        DependencyResolver resolver = settings.getResolver(resolverName);
        if (resolver == null) {
            throw new BuildException("the resolver '" + resolverName + "' was not found");
        }
        if (!(resolver instanceof BasicResolver)) {
            throw new BuildException("the type of resolver '" + resolver.getClass().getName() + "' is not supported.");
        }
        it = new ResolverManifestIterable((BasicResolver) resolver);
    } else if (baseDir != null) {
        if (cacheName != null) {
            throw new BuildException("specify only one of 'baseDir' or 'cache'");
        }
        if (!baseDir.isDirectory()) {
            throw new BuildException(baseDir + " is not a directory");
        }
        it = new FSManifestIterable(baseDir);
    } else if (cacheName != null) {
        Ivy ivy = getIvyInstance();
        RepositoryCacheManager cacheManager = ivy.getSettings().getRepositoryCacheManager(cacheName);
        if (!(cacheManager instanceof DefaultRepositoryCacheManager)) {
            throw new BuildException("the type of cache '" + cacheManager.getClass().getName() + "' is not supported.");
        }
        File basedir = ((DefaultRepositoryCacheManager) cacheManager).getBasedir();
        it = new FSManifestIterable(basedir);
    } else {
        prepareAndCheck();
        try {
            it = new ArtifactReportManifestIterable(getArtifactReports(), sourceTypes);
        } catch (ParseException e) {
            throw new BuildException("Impossible to parse the artifact reports: " + e.getMessage(), e);
        }
    }
    OutputStream out;
    try {
        out = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        throw new BuildException(file + " was not found", e);
    }
    ContentHandler hd;
    try {
        hd = OBRXMLWriter.newHandler(out, encoding, indent);
    } catch (TransformerConfigurationException e) {
        throw new BuildException("Sax configuration error: " + e.getMessage(), e);
    }
    class AntMessageLogger2 extends AntMessageLogger {

        AntMessageLogger2() {
            super(BuildOBRTask.this);
        }
    }
    IvyContext.getContext().getMessageLogger();
    Message.setDefaultLogger(new AntMessageLogger2());
    try {
        OBRXMLWriter.writeManifests(it, hd, quiet);
    } catch (SAXException e) {
        throw new BuildException("Sax serialisation error: " + e.getMessage(), e);
    }
    try {
        out.flush();
        out.close();
    } catch (IOException e) {
    // don't care
    }
    Message.sumupProblems();
}
Also used : DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IvySettings(org.apache.ivy.core.settings.IvySettings) ArtifactReportManifestIterable(org.apache.ivy.osgi.repo.ArtifactReportManifestIterable) IOException(java.io.IOException) Ivy(org.apache.ivy.Ivy) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) ContentHandler(org.xml.sax.ContentHandler) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) SAXException(org.xml.sax.SAXException) FSManifestIterable(org.apache.ivy.osgi.repo.FSManifestIterable) FileOutputStream(java.io.FileOutputStream) BasicResolver(org.apache.ivy.plugins.resolver.BasicResolver) ResolverManifestIterable(org.apache.ivy.osgi.repo.ResolverManifestIterable) ManifestAndLocation(org.apache.ivy.osgi.repo.ManifestAndLocation) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) File(java.io.File)

Aggregations

Ivy (org.apache.ivy.Ivy)169 File (java.io.File)147 Test (org.junit.Test)137 ResolveReport (org.apache.ivy.core.report.ResolveReport)102 JarFile (java.util.jar.JarFile)100 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)97 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)40 IvySettings (org.apache.ivy.core.settings.IvySettings)26 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)23 BuildException (org.apache.tools.ant.BuildException)17 Before (org.junit.Before)12 HashMap (java.util.HashMap)9 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)8 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)6 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)6 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)5 ModuleId (org.apache.ivy.core.module.id.ModuleId)5 IOException (java.io.IOException)4 ParseException (java.text.ParseException)4 Date (java.util.Date)4