588
|
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 |
package com.nokia.helium.antlint.ant.types;
|
|
18 |
|
|
19 |
import java.io.File;
|
628
|
20 |
import java.io.IOException;
|
588
|
21 |
|
628
|
22 |
import javax.xml.parsers.ParserConfigurationException;
|
588
|
23 |
import javax.xml.parsers.SAXParser;
|
|
24 |
import javax.xml.parsers.SAXParserFactory;
|
628
|
25 |
|
588
|
26 |
import org.xml.sax.SAXException;
|
|
27 |
|
|
28 |
import com.nokia.helium.antlint.AntLintHandler;
|
|
29 |
import com.nokia.helium.antlint.ant.AntlintException;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* <code>CheckIndentation</code> is used to check the indentations in the ant
|
|
33 |
* files.
|
|
34 |
*
|
|
35 |
* <pre>
|
|
36 |
* Usage:
|
|
37 |
*
|
|
38 |
* <antlint>
|
|
39 |
* <fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
40 |
* <include name="*.ant.xml"/>
|
|
41 |
* <include name="*build.xml"/>
|
|
42 |
* <include name="*.antlib.xml"/>
|
|
43 |
* </fileset>
|
|
44 |
* <CheckIndentation" severity="error" enabled="true" />
|
|
45 |
* </antlint>
|
|
46 |
* </pre>
|
|
47 |
*
|
|
48 |
* @ant.task name="CheckIndentation" category="AntLint"
|
|
49 |
*
|
|
50 |
*/
|
|
51 |
public class CheckIndentation extends AbstractCheck {
|
|
52 |
private File antFile;
|
|
53 |
|
|
54 |
/*
|
|
55 |
* (non-Javadoc)
|
|
56 |
*
|
|
57 |
* @see com.nokia.helium.antlint.ant.types.Check#run(java.io.File)
|
|
58 |
*/
|
|
59 |
public void run(File antFilename) throws AntlintException {
|
|
60 |
try {
|
|
61 |
this.antFile = antFilename;
|
|
62 |
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
|
63 |
saxFactory.setNamespaceAware(true);
|
|
64 |
saxFactory.setValidating(true);
|
|
65 |
SAXParser parser = saxFactory.newSAXParser();
|
|
66 |
AntLintHandler handler = new AntLintHandler(this);
|
|
67 |
handler.setIndentationCheck(true);
|
|
68 |
parser.parse(antFilename, handler);
|
|
69 |
} catch (ParserConfigurationException e) {
|
|
70 |
throw new AntlintException("Not able to parse XML file "
|
|
71 |
+ e.getMessage());
|
|
72 |
} catch (SAXException e) {
|
|
73 |
throw new AntlintException("Not able to parse XML file "
|
|
74 |
+ e.getMessage());
|
|
75 |
} catch (IOException e) {
|
|
76 |
throw new AntlintException("Not able to find XML file "
|
|
77 |
+ e.getMessage());
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
/*
|
|
82 |
* (non-Javadoc)
|
|
83 |
*
|
|
84 |
* @see org.apache.tools.ant.types.DataType#toString()
|
|
85 |
*/
|
|
86 |
public String toString() {
|
|
87 |
return "CheckIndentation";
|
|
88 |
}
|
|
89 |
|
|
90 |
/*
|
|
91 |
* (non-Javadoc)
|
|
92 |
*
|
|
93 |
* @see com.nokia.helium.antlint.ant.types.Check#getAntFile()
|
|
94 |
*/
|
|
95 |
public File getAntFile() {
|
|
96 |
return this.antFile;
|
|
97 |
}
|
|
98 |
}
|