001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.plugins.report;
019:
020: import java.io.IOException;
021: import java.util.ArrayList;
022: import java.util.Arrays;
023: import java.util.Collection;
024: import java.util.Collections;
025: import java.util.List;
026:
027: import org.apache.ivy.core.IvyContext;
028: import org.apache.ivy.core.cache.ResolutionCacheManager;
029: import org.apache.ivy.core.report.ArtifactDownloadReport;
030: import org.apache.ivy.core.report.ConfigurationResolveReport;
031: import org.apache.ivy.core.report.ResolveReport;
032: import org.apache.ivy.core.resolve.IvyNode;
033: import org.apache.ivy.core.resolve.ResolveOptions;
034: import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData;
035: import org.apache.ivy.core.settings.IvySettings;
036: import org.apache.ivy.util.Message;
037:
038: /**
039: *
040: */
041: public class LogReportOutputter implements ReportOutputter {
042:
043: public String getName() {
044: return CONSOLE;
045: }
046:
047: public void output(ResolveReport report,
048: ResolutionCacheManager cacheMgr, ResolveOptions options)
049: throws IOException {
050: IvySettings settings = IvyContext.getContext().getSettings();
051: if (settings.logModulesInUse()
052: && ResolveOptions.LOG_DEFAULT.equals(options.getLog())) {
053: Message.info("\t:: modules in use:");
054: List dependencies = new ArrayList(report.getDependencies());
055: Collections.sort(dependencies);
056: if (dependencies.size() > 0) {
057: String[] confs = report.getConfigurations();
058: for (int i = 0; i < dependencies.size(); i++) {
059: IvyNode node = (IvyNode) dependencies.get(i);
060: if (node.isCompletelyEvicted()) {
061: continue;
062: }
063: List nodeConfs = new ArrayList(confs.length);
064: for (int j = 0; j < confs.length; j++) {
065: String conf = confs[j];
066: if (report.getConfigurationReport(conf)
067: .getModuleRevisionIds().contains(
068: node.getResolvedId())) {
069: nodeConfs.add(conf);
070: }
071: }
072: Message.info("\t"
073: + node
074: + " from "
075: + node.getModuleRevision().getResolver()
076: .getName() + " in " + nodeConfs);
077: }
078: }
079: }
080:
081: IvyNode[] evicted = report.getEvictedNodes();
082:
083: if (evicted.length > 0
084: && ResolveOptions.LOG_DEFAULT.equals(options.getLog())) {
085: Message.info("\t:: evicted modules:");
086: for (int i = 0; i < evicted.length; i++) {
087: Collection allEvictingNodes = evicted[i]
088: .getAllEvictingNodesDetails();
089: if (allEvictingNodes == null) {
090: Message.info("\t"
091: + evicted[i]
092: + " transitively in "
093: + Arrays.asList(evicted[i]
094: .getEvictedConfs()));
095: } else if (allEvictingNodes.isEmpty()) {
096: Message.info("\t"
097: + evicted[i]
098: + " by [] ("
099: + evicted[i]
100: .getAllEvictingConflictManagers()
101: + ") in "
102: + Arrays.asList(evicted[i]
103: .getEvictedConfs()));
104: } else {
105: Message.info("\t"
106: + evicted[i]
107: + " by "
108: + allEvictingNodes
109: + " in "
110: + Arrays.asList(evicted[i]
111: .getEvictedConfs()));
112: }
113: String[] confs = evicted[i].getEvictedConfs();
114: for (int j = 0; j < confs.length; j++) {
115: EvictionData evictedData = evicted[i]
116: .getEvictedData(confs[j]);
117: if (evictedData.getParent() != null) {
118: Message.verbose("\t in "
119: + evictedData.getParent() + " with "
120: + evictedData.getConflictManager());
121: }
122: }
123: }
124: }
125:
126: if (ResolveOptions.LOG_DEFAULT.equals(options.getLog())) {
127: //CheckStyle:MagicNumber| OFF
128: char[] sep = new char[69];
129: Arrays.fill(sep, '-');
130: Message.rawinfo("\t" + new String(sep));
131: StringBuffer line = new StringBuffer("\t");
132: append(line, "", 18);
133: append(line, "modules", 31);
134: line.append("|");
135: append(line, "artifacts", 15);
136: line.append("|");
137: Message.rawinfo(line.toString());
138:
139: line = new StringBuffer("\t");
140: append(line, "conf", 18);
141: append(line, "number", 7);
142: append(line, "search", 7);
143: append(line, "dwnlded", 7);
144: append(line, "evicted", 7);
145: line.append("|");
146: append(line, "number", 7);
147: append(line, "dwnlded", 7);
148: //CheckStyle:MagicNumber| ON
149: line.append("|");
150: Message.rawinfo(line.toString());
151: Message.rawinfo("\t" + new String(sep));
152:
153: String[] confs = report.getConfigurations();
154: for (int i = 0; i < confs.length; i++) {
155: output(report.getConfigurationReport(confs[i]));
156: }
157: Message.rawinfo("\t" + new String(sep));
158: }
159:
160: IvyNode[] unresolved = report.getUnresolvedDependencies();
161: if (unresolved.length > 0) {
162: Message
163: .warn("\t::::::::::::::::::::::::::::::::::::::::::::::");
164: Message
165: .warn("\t:: UNRESOLVED DEPENDENCIES ::");
166: Message
167: .warn("\t::::::::::::::::::::::::::::::::::::::::::::::");
168: }
169: for (int i = 0; i < unresolved.length; i++) {
170: Message.warn("\t:: " + unresolved[i] + ": "
171: + unresolved[i].getProblemMessage());
172: }
173: if (unresolved.length > 0) {
174: Message
175: .warn("\t::::::::::::::::::::::::::::::::::::::::::::::\n");
176: }
177:
178: ArtifactDownloadReport[] errors = report
179: .getFailedArtifactsReports();
180: if (errors.length > 0) {
181: Message
182: .warn("\t::::::::::::::::::::::::::::::::::::::::::::::");
183: Message
184: .warn("\t:: FAILED DOWNLOADS ::");
185: Message
186: .warn("\t:: ^ see resolution messages for details ^ ::");
187: Message
188: .warn("\t::::::::::::::::::::::::::::::::::::::::::::::");
189: }
190: for (int i = 0; i < errors.length; i++) {
191: Message.warn("\t:: " + errors[i].getArtifact());
192: }
193: if (errors.length > 0) {
194: Message
195: .warn("\t::::::::::::::::::::::::::::::::::::::::::::::\n");
196: }
197: }
198:
199: public void output(ConfigurationResolveReport report) {
200: StringBuffer line = new StringBuffer("\t");
201: //CheckStyle:MagicNumber| OFF
202: append(line, report.getConfiguration(), 18);
203: append(line, String.valueOf(report.getNodesNumber()), 7);
204: append(line, String.valueOf(report.getSearchedNodes().length),
205: 7);
206: append(line,
207: String.valueOf(report.getDownloadedNodes().length), 7);
208: append(line, String.valueOf(report.getEvictedNodes().length), 7);
209: line.append("|");
210: append(line, String.valueOf(report.getArtifactsNumber()), 7);
211: append(line, String.valueOf(report
212: .getDownloadedArtifactsReports().length), 7);
213: //CheckStyle:MagicNumber| ON
214: line.append("|");
215:
216: Message.rawinfo(line.toString());
217: }
218:
219: private void append(StringBuffer line, Object o, int limit) {
220: String v = String.valueOf(o);
221: if (v.length() >= limit) {
222: v = v.substring(0, limit);
223: } else {
224: int missing = limit - v.length();
225: int half = missing / 2;
226: char[] c = new char[limit];
227: Arrays.fill(c, ' ');
228: System.arraycopy(v.toCharArray(), 0, c, missing - half, v
229: .length());
230: v = new String(c);
231: }
232: line.append("|");
233: line.append(v);
234: }
235:
236: }
|