buildframework/helium/sf/java/antlint/src/com/nokia/helium/antlint/ant/types/CheckIndentation.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     1
/*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     3
 * All rights reserved.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     8
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    11
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    12
 * Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    13
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    14
 * Description: 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    15
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    16
 */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    17
package com.nokia.helium.antlint.ant.types;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    18
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    19
import java.io.File;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    20
import java.io.IOException;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    21
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    22
import javax.xml.parsers.ParserConfigurationException;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    23
import javax.xml.parsers.SAXParser;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    24
import javax.xml.parsers.SAXParserFactory;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    25
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    26
import org.xml.sax.SAXException;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    27
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    28
import com.nokia.helium.antlint.AntLintHandler;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    29
import com.nokia.helium.antlint.ant.AntlintException;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    30
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    31
/**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    32
 * <code>CheckIndentation</code> is used to check the indentations in the ant
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    33
 * files.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    34
 * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    35
 * <pre>
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    36
 * Usage:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    37
 * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    38
 *  &lt;antlint&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    39
 *       &lt;fileset id=&quot;antlint.files&quot; dir=&quot;${antlint.test.dir}/data&quot;&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    40
 *               &lt;include name=&quot;*.ant.xml&quot;/&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    41
 *               &lt;include name=&quot;*build.xml&quot;/&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    42
 *               &lt;include name=&quot;*.antlib.xml&quot;/&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    43
 *       &lt;/fileset&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    44
 *       &lt;CheckIndentation&quot; severity=&quot;error&quot; enabled=&quot;true&quot; /&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    45
 *  &lt;/antlint&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    46
 * </pre>
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    47
 * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    48
 * @ant.task name="CheckIndentation" category="AntLint"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    49
 * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    50
 */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    51
public class CheckIndentation extends AbstractCheck {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    52
    private File antFile;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    53
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    54
    /*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    55
     * (non-Javadoc)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    56
     * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    57
     * @see com.nokia.helium.antlint.ant.types.Check#run(java.io.File)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    58
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    59
    public void run(File antFilename) throws AntlintException {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    60
        try {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    61
            this.antFile = antFilename;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    62
            SAXParserFactory saxFactory = SAXParserFactory.newInstance();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    63
            saxFactory.setNamespaceAware(true);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    64
            saxFactory.setValidating(true);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    65
            SAXParser parser = saxFactory.newSAXParser();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    66
            AntLintHandler handler = new AntLintHandler(this);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    67
            handler.setIndentationCheck(true);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    68
            parser.parse(antFilename, handler);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    69
        } catch (ParserConfigurationException e) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    70
            throw new AntlintException("Not able to parse XML file "
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    71
                    + e.getMessage());
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    72
        } catch (SAXException e) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    73
            throw new AntlintException("Not able to parse XML file "
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    74
                    + e.getMessage());
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    75
        } catch (IOException e) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    76
            throw new AntlintException("Not able to find XML file "
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    77
                    + e.getMessage());
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    78
        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    79
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    80
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    81
    /*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    82
     * (non-Javadoc)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    83
     * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    84
     * @see org.apache.tools.ant.types.DataType#toString()
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    85
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    86
    public String toString() {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    87
        return "CheckIndentation";
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    88
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    89
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    90
    /*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    91
     * (non-Javadoc)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    92
     * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    93
     * @see com.nokia.helium.antlint.ant.types.Check#getAntFile()
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    94
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    95
    public File getAntFile() {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    96
        return this.antFile;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    97
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    98
}