587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.ant.data.taskdefs;
|
|
19 |
|
|
20 |
import java.io.IOException;
|
|
21 |
import java.util.ArrayList;
|
|
22 |
import java.util.HashMap;
|
|
23 |
import java.util.List;
|
|
24 |
import java.util.Map;
|
|
25 |
|
|
26 |
import org.apache.tools.ant.BuildException;
|
|
27 |
import org.apache.tools.ant.DynamicElement;
|
|
28 |
import org.apache.tools.ant.Project;
|
|
29 |
import org.apache.tools.ant.Task;
|
|
30 |
|
|
31 |
import com.nokia.helium.ant.data.Database;
|
|
32 |
import com.nokia.helium.ant.data.types.AntLintCheck;
|
|
33 |
import com.nokia.helium.ant.data.types.LintIssue;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Another version of AntLint that fits with the antdata API more closely.
|
|
37 |
*/
|
|
38 |
@SuppressWarnings("serial")
|
|
39 |
public class AntConfigLintTask extends Task implements DynamicElement {
|
|
40 |
|
|
41 |
// Temporary solution, should change to scanning jar
|
|
42 |
public static final Map<String, String> CHECKS = new HashMap<String, String>() {
|
|
43 |
{
|
|
44 |
put("wrongtypepropertycheck", "WrongTypePropertyCheck");
|
|
45 |
// put("protected", new Integer(2));
|
|
46 |
// put("private", new Integer(3));
|
|
47 |
}
|
|
48 |
};
|
|
49 |
private List<AntLintCheck> checks = new ArrayList<AntLintCheck>();
|
|
50 |
private List<LintIssue> issues = new ArrayList<LintIssue>();
|
|
51 |
private Database db;
|
|
52 |
private int errorsTotal;
|
|
53 |
|
|
54 |
public AntConfigLintTask() throws IOException {
|
|
55 |
setTaskName("antconfiglint");
|
|
56 |
}
|
|
57 |
|
|
58 |
@SuppressWarnings("unchecked")
|
|
59 |
public Object createDynamicElement(String name) {
|
|
60 |
AntLintCheck check = null;
|
|
61 |
String className = "com.nokia.helium.ant.data.types." + CHECKS.get(name);
|
|
62 |
log("Creating check: " + className, Project.MSG_DEBUG);
|
|
63 |
try {
|
|
64 |
Class<AntLintCheck> clazz = (Class<AntLintCheck>) Class.forName(className);
|
|
65 |
if (clazz != null) {
|
|
66 |
check = (AntLintCheck) clazz.newInstance();
|
|
67 |
checks.add(check);
|
|
68 |
}
|
|
69 |
}
|
|
70 |
catch (ClassNotFoundException th) {
|
|
71 |
th.printStackTrace();
|
|
72 |
throw new BuildException("Error in Antlint configuration: " + th.getMessage());
|
|
73 |
} catch (InstantiationException th) {
|
|
74 |
th.printStackTrace();
|
|
75 |
throw new BuildException("Error in Antlint configuration: " + th.getMessage());
|
|
76 |
} catch (IllegalAccessException th) {
|
|
77 |
th.printStackTrace();
|
|
78 |
throw new BuildException("Error in Antlint configuration: " + th.getMessage());
|
|
79 |
}
|
|
80 |
return check;
|
|
81 |
}
|
|
82 |
|
|
83 |
public void execute() {
|
|
84 |
errorsTotal = 0;
|
|
85 |
try {
|
|
86 |
db = new Database(getProject());
|
|
87 |
if (checks.size() == 0) {
|
|
88 |
throw new BuildException("No checks defined.");
|
|
89 |
}
|
|
90 |
for (AntLintCheck check : checks) {
|
|
91 |
check.setTask(this);
|
|
92 |
|
|
93 |
log("Running check: " + check, Project.MSG_DEBUG);
|
|
94 |
check.run();
|
|
95 |
|
|
96 |
}
|
|
97 |
for (LintIssue issue : issues) {
|
|
98 |
log(issue.toString());
|
|
99 |
}
|
|
100 |
if (errorsTotal > 0) {
|
|
101 |
throw new BuildException("AntLint errors found: " + errorsTotal);
|
|
102 |
}
|
|
103 |
}
|
|
104 |
catch (IOException e) {
|
|
105 |
throw new BuildException(e.getMessage());
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
public void addLintIssue(LintIssue issue) {
|
|
110 |
issues.add(issue);
|
|
111 |
if (issue.getSeverity() == AntLintCheck.SEVERITY_ERROR) {
|
|
112 |
errorsTotal++;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
public Database getDatabase() {
|
|
117 |
return db;
|
|
118 |
}
|
|
119 |
}
|