Search in sources :

Example 6 with XmlReportParser

use of org.apache.ivy.plugins.report.XmlReportParser in project ant-ivy by apache.

the class IvyArtifactProperty method doExecute.

public void doExecute() throws BuildException {
    prepareAndCheck();
    try {
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
        String resolveId = getResolveId();
        if (resolveId == null) {
            resolveId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
        }
        XmlReportParser parser = new XmlReportParser();
        for (String conf : splitToArray(getConf())) {
            File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
            parser.parse(report);
            for (Artifact artifact : parser.getArtifacts()) {
                String name = IvyPatternHelper.substitute(getSettings().substitute(getName()), artifact, conf);
                String value = IvyPatternHelper.substitute(getSettings().substitute(getValue()), artifact, conf);
                setProperty(name, value);
            }
        }
    } catch (Exception ex) {
        throw new BuildException("impossible to add artifact properties: " + ex, ex);
    }
}
Also used : XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) BuildException(org.apache.tools.ant.BuildException)

Example 7 with XmlReportParser

use of org.apache.ivy.plugins.report.XmlReportParser in project ant-ivy by apache.

the class IvyCacheTask method getAllArtifactReports.

private Collection<ArtifactDownloadReport> getAllArtifactReports() throws ParseException {
    String[] confs = splitToArray(getConf());
    Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
    ResolveReport report = getResolvedReport();
    if (report != null) {
        Message.debug("using internal report instance to get artifacts list");
        for (String conf : confs) {
            ConfigurationResolveReport configurationReport = report.getConfigurationReport(conf);
            if (configurationReport == null) {
                throw new BuildException("bad confs provided: " + conf + " not found among " + Arrays.asList(report.getConfigurations()));
            }
            for (ModuleRevisionId revId : configurationReport.getModuleRevisionIds()) {
                all.addAll(Arrays.asList(configurationReport.getDownloadReports(revId)));
            }
        }
    } else {
        Message.debug("using stored report to get artifacts list");
        XmlReportParser parser = new XmlReportParser();
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
        String resolvedId = getResolveId();
        if (resolvedId == null) {
            resolvedId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
        }
        for (String conf : confs) {
            File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolvedId, conf);
            parser.parse(reportFile);
            all.addAll(Arrays.asList(parser.getArtifactReports()));
        }
    }
    return all;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 8 with XmlReportParser

use of org.apache.ivy.plugins.report.XmlReportParser in project ant-ivy by apache.

the class Main method invoke.

@SuppressWarnings("resource")
private static void invoke(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, List<File> fileList, String mainclass, String[] args) {
    List<URL> urls = new ArrayList<>();
    // Add option cp (extra classpath) urls
    if (fileList != null && fileList.size() > 0) {
        for (File file : fileList) {
            try {
                urls.add(file.toURI().toURL());
            } catch (MalformedURLException e) {
            // Should not happen, just ignore.
            }
        }
    }
    try {
        Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
        ResolutionCacheManager cacheMgr = ivy.getResolutionCacheManager();
        XmlReportParser parser = new XmlReportParser();
        for (String conf : confs) {
            String resolveId = ResolveOptions.getDefaultResolveId(md);
            File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
            parser.parse(report);
            all.addAll(Arrays.asList(parser.getArtifactReports()));
        }
        for (ArtifactDownloadReport artifact : all) {
            if (artifact.getLocalFile() != null) {
                urls.add(artifact.getLocalFile().toURI().toURL());
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex);
    }
    URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Main.class.getClassLoader().getParent());
    try {
        Class<?> c = classLoader.loadClass(mainclass);
        Method mainMethod = c.getMethod("main", String[].class);
        Thread.currentThread().setContextClassLoader(classLoader);
        mainMethod.invoke(null, new Object[] { (args == null ? new String[0] : args) });
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException("Could not find class: " + mainclass, cnfe);
    } catch (SecurityException | NoSuchMethodException e) {
        throw new RuntimeException("Could not find main method: " + mainclass, e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("No permissions to invoke main method: " + mainclass, e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Unexpected exception invoking main method: " + mainclass, e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MalformedURLException(java.net.MalformedURLException) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ArrayList(java.util.ArrayList) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Method(java.lang.reflect.Method) URL(java.net.URL) ResolveProcessException(org.apache.ivy.core.resolve.ResolveProcessException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParseException(org.apache.ivy.util.cli.ParseException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) URLClassLoader(java.net.URLClassLoader) PropertiesFile(org.apache.ivy.util.PropertiesFile) File(java.io.File)

Example 9 with XmlReportParser

use of org.apache.ivy.plugins.report.XmlReportParser in project ant-ivy by apache.

the class Main method outputCachePath.

private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, String outFile) {
    try {
        StringBuilder buf = new StringBuilder();
        Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
        ResolutionCacheManager cacheMgr = ivy.getResolutionCacheManager();
        XmlReportParser parser = new XmlReportParser();
        for (String conf : confs) {
            String resolveId = ResolveOptions.getDefaultResolveId(md);
            File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
            parser.parse(report);
            all.addAll(Arrays.asList(parser.getArtifactReports()));
        }
        for (ArtifactDownloadReport artifact : all) {
            if (artifact.getLocalFile() != null) {
                buf.append(artifact.getLocalFile().getCanonicalPath());
                buf.append(File.pathSeparator);
            }
        }
        PrintWriter writer = new PrintWriter(new FileOutputStream(outFile));
        if (buf.length() > 0) {
            buf.setLength(buf.length() - File.pathSeparator.length());
            writer.println(buf);
        }
        writer.close();
        System.out.println("cachepath output to " + outFile);
    } catch (Exception ex) {
        throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) FileOutputStream(java.io.FileOutputStream) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) PropertiesFile(org.apache.ivy.util.PropertiesFile) File(java.io.File) ResolveProcessException(org.apache.ivy.core.resolve.ResolveProcessException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParseException(org.apache.ivy.util.cli.ParseException) PrintWriter(java.io.PrintWriter)

Aggregations

File (java.io.File)9 XmlReportParser (org.apache.ivy.plugins.report.XmlReportParser)9 ResolutionCacheManager (org.apache.ivy.core.cache.ResolutionCacheManager)8 LinkedHashSet (java.util.LinkedHashSet)5 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)5 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)4 HashSet (java.util.HashSet)3 BuildException (org.apache.tools.ant.BuildException)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 ResolveProcessException (org.apache.ivy.core.resolve.ResolveProcessException)2 PropertiesFile (org.apache.ivy.util.PropertiesFile)2 ParseException (org.apache.ivy.util.cli.ParseException)2 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 Method (java.lang.reflect.Method)1