01: /*****************************************************************************
02: * Java Plug-in Framework (JPF)
03: * Copyright (C) 2004-2007 Dmitry Olshansky
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *****************************************************************************/package org.java.plugin.tools.ant;
19:
20: import org.apache.tools.ant.BuildException;
21: import org.java.plugin.registry.IntegrityCheckReport;
22:
23: /**
24: * The Ant task to perform integrity check of plug-in set.
25: * @version $Id$
26: */
27: public final class CheckTask extends BaseJpfTask {
28: private boolean usePathResolver;
29:
30: /**
31: * @param aUsePathResolver <code>true</code> if PathResolver should be used
32: */
33: public void setUsePathResolver(final boolean aUsePathResolver) {
34: this .usePathResolver = aUsePathResolver;
35: }
36:
37: /**
38: * @see org.apache.tools.ant.Task#execute()
39: */
40: @Override
41: public void execute() {
42: initRegistry(usePathResolver);
43: IntegrityCheckReport report = getRegistry().checkIntegrity(
44: getPathResolver());
45: if (getVerbose()) {
46: log(integrityCheckReport2str(report));
47: }
48: log("Integrity check done. Errors: " + report.countErrors() //$NON-NLS-1$
49: + ". Warnings: " + report.countWarnings() + "."); //$NON-NLS-1$ //$NON-NLS-2$
50: if (report.countErrors() > 0) {
51: throw new BuildException(
52: "plug-ins set integrity check failed," //$NON-NLS-1$
53: + " errors count - " + report.countErrors()); //$NON-NLS-1$
54: }
55: }
56:
57: private static String integrityCheckReport2str(
58: final IntegrityCheckReport report) {
59: StringBuilder buf = new StringBuilder();
60: buf.append("Integrity check report:\r\n"); //$NON-NLS-1$
61: buf.append("-------------- REPORT BEGIN -----------------\r\n"); //$NON-NLS-1$
62: for (IntegrityCheckReport.ReportItem item : report.getItems()) {
63: buf.append("severity=").append(item.getSeverity()) //$NON-NLS-1$
64: .append("; code=").append(item.getCode()) //$NON-NLS-1$
65: .append("; message=").append(item.getMessage()) //$NON-NLS-1$
66: .append("; source=").append(item.getSource()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
67: }
68: buf.append("-------------- REPORT END -----------------"); //$NON-NLS-1$
69: return buf.toString();
70: }
71: }
|