KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > tools > ant > CheckTask


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2005 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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  *****************************************************************************/

19 package org.java.plugin.tools.ant;
20
21 import java.util.Iterator JavaDoc;
22
23 import org.apache.tools.ant.BuildException;
24 import org.java.plugin.registry.IntegrityCheckReport;
25
26 /**
27  * The Ant task to perform integrity check of plug-in set.
28  * @version $Id: CheckTask.java,v 1.4 2005/07/20 18:43:47 ddimon Exp $
29  */

30 public final class CheckTask extends BaseJpfTask {
31     private boolean usePathResolver;
32     
33     /**
34      * @param aUsePathResolver <code>true</code> if PathResolver should be used
35      */

36     public void setUsePathResolver(final boolean aUsePathResolver) {
37         this.usePathResolver = aUsePathResolver;
38     }
39     
40     /**
41      * @see org.apache.tools.ant.Task#execute()
42      */

43     public void execute() {
44         initRegistry(usePathResolver);
45         log("Checking plug-ins integrity..."); //$NON-NLS-1$
46
IntegrityCheckReport report =
47             getRegistry().checkIntegrity(getPathResolver());
48         log("... integrity check done. Errors: " + report.countErrors() //$NON-NLS-1$
49
+ ". Warnings: " + report.countWarnings() + "."); //$NON-NLS-1$ //$NON-NLS-2$
50
if (getVerbose()) {
51             log(integrityCheckReport2str(report));
52         }
53         if (report.countErrors() > 0) {
54             throw new BuildException("plug-ins set integrity check failed," //$NON-NLS-1$
55
+ " errors count - " + report.countErrors()); //$NON-NLS-1$
56
}
57     }
58
59     private static String JavaDoc integrityCheckReport2str(
60             final IntegrityCheckReport report) {
61         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
62         buf.append("Integrity check report:\r\n"); //$NON-NLS-1$
63
buf.append("-------------- REPORT BEGIN -----------------\r\n"); //$NON-NLS-1$
64
for (Iterator JavaDoc it = report.getItems().iterator(); it.hasNext();) {
65             IntegrityCheckReport.ReportItem item =
66                 (IntegrityCheckReport.ReportItem) it.next();
67             buf.append("severity=").append(item.getSeverity()) //$NON-NLS-1$
68
.append("; code=").append(item.getCode()) //$NON-NLS-1$
69
.append("; message=").append(item.getMessage()) //$NON-NLS-1$
70
.append("; source=").append(item.getSource()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
71
}
72         buf.append("-------------- REPORT END -----------------"); //$NON-NLS-1$
73
return buf.toString();
74     }
75 }
76
Popular Tags