Search in sources :

Example 11 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager 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 12 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager 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 13 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager 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)

Example 14 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.

the class IvyReport method getStylePath.

private File getStylePath(String styleResourceName) throws IOException {
    // style should be a file (and not an url)
    // so we have to copy it from classpath to cache
    ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
    File style = new File(cacheMgr.getResolutionCacheRoot(), styleResourceName);
    FileUtil.copy(XmlReportOutputter.class.getResourceAsStream(styleResourceName), style, null);
    return style;
}
Also used : XmlReportOutputter(org.apache.ivy.plugins.report.XmlReportOutputter) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) File(java.io.File)

Example 15 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.

the class IvyReport method getReportStylePath.

private File getReportStylePath() throws IOException {
    if (xslFile != null) {
        return xslFile;
    }
    // style should be a file (and not an url)
    // so we have to copy it from classpath to cache
    ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
    File style = new File(cacheMgr.getResolutionCacheRoot(), "ivy-report.xsl");
    if (!style.exists()) {
        Message.debug("copying ivy-report.xsl to " + style.getAbsolutePath());
        FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.xsl"), style, null);
    }
    return style;
}
Also used : XmlReportOutputter(org.apache.ivy.plugins.report.XmlReportOutputter) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) File(java.io.File)

Aggregations

File (java.io.File)16 ResolutionCacheManager (org.apache.ivy.core.cache.ResolutionCacheManager)16 XmlReportParser (org.apache.ivy.plugins.report.XmlReportParser)8 HashSet (java.util.HashSet)6 LinkedHashSet (java.util.LinkedHashSet)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)6 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)5 BuildException (org.apache.tools.ant.BuildException)5 IOException (java.io.IOException)4 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 ResolveReport (org.apache.ivy.core.report.ResolveReport)3 XmlReportOutputter (org.apache.ivy.plugins.report.XmlReportOutputter)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)2