01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.report;
19:
20: import java.io.File;
21: import java.io.FileOutputStream;
22: import java.io.IOException;
23: import java.io.OutputStream;
24:
25: import org.apache.ivy.core.cache.ResolutionCacheManager;
26: import org.apache.ivy.core.report.ConfigurationResolveReport;
27: import org.apache.ivy.core.report.ResolveReport;
28: import org.apache.ivy.core.resolve.ResolveOptions;
29: import org.apache.ivy.util.FileUtil;
30: import org.apache.ivy.util.Message;
31:
32: /**
33: * A Report outputter implementation using {@link XmlReportWriter} to write xml reports to the
34: * resolution cache.
35: */
36: public class XmlReportOutputter implements ReportOutputter {
37: private XmlReportWriter writer = new XmlReportWriter();
38:
39: public String getName() {
40: return XML;
41: }
42:
43: public void output(ResolveReport report,
44: ResolutionCacheManager cacheMgr, ResolveOptions options)
45: throws IOException {
46: String[] confs = report.getConfigurations();
47: for (int i = 0; i < confs.length; i++) {
48: output(report.getConfigurationReport(confs[i]), report
49: .getResolveId(), confs, cacheMgr);
50: }
51: }
52:
53: public void output(ConfigurationResolveReport report,
54: String resolveId, String[] confs,
55: ResolutionCacheManager cacheMgr) throws IOException {
56: File reportFile = cacheMgr
57: .getConfigurationResolveReportInCache(resolveId, report
58: .getConfiguration());
59: File reportParentDir = reportFile.getParentFile();
60: reportParentDir.mkdirs();
61: OutputStream stream = new FileOutputStream(reportFile);
62: writer.output(report, confs, stream);
63: stream.close();
64:
65: Message.verbose("\treport for "
66: + report.getModuleDescriptor().getModuleRevisionId()
67: + " " + report.getConfiguration() + " produced in "
68: + reportFile);
69:
70: File reportXsl = new File(reportParentDir, "ivy-report.xsl");
71: File reportCss = new File(reportParentDir, "ivy-report.css");
72: if (!reportXsl.exists()) {
73: FileUtil.copy(XmlReportOutputter.class
74: .getResource("ivy-report.xsl"), reportXsl, null);
75: }
76: if (!reportCss.exists()) {
77: FileUtil.copy(XmlReportOutputter.class
78: .getResource("ivy-report.css"), reportCss, null);
79: }
80: }
81: }
|