|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigurationLoader | Line # 52 | 89.5% |
0.8947368
|
32.12 | 79 | 31 | 31 | 0.39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigurationLoader.InternalLoader | Line # 85 | 86.4% |
0.8636364
|
12.37 | 29 | 12 | 12 | 0.41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (10) | |||
| Result | |||
|
0.7721519
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testCheckstyleChecks
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testCheckstyleChecks
|
1 PASS | |
|
0.37974682
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testEmptyConfiguration
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testEmptyConfiguration
|
1 PASS | |
|
0.3164557
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testReplacePropertiesReplace
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testReplacePropertiesReplace
|
1 PASS | |
|
0.30379745
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testMissingPropertyValue
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testMissingPropertyValue
|
1 PASS | |
|
0.30379745
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testMissingPropertyName
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testMissingPropertyName
|
1 PASS | |
|
0.2658228
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testReplacePropertiesNoReplace
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testReplacePropertiesNoReplace
|
1 PASS | |
|
0.25316456
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testReplacePropertiesMissingProperty
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testReplacePropertiesMissingProperty
|
1 PASS | |
|
0.23417722
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testMissingConfigName
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testMissingConfigName
|
1 PASS | |
|
0.23417722
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testMissingConfigParent
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testMissingConfigParent
|
1 PASS | |
|
0.12658228
|
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testReplacePropertiesSyntaxError
com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.testReplacePropertiesSyntaxError
|
1 PASS | |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2005 Oliver Burn | |
| 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 com.puppycrawl.tools.checkstyle; | |
| 20 | ||
| 21 | import java.io.BufferedInputStream; | |
| 22 | import java.io.FileInputStream; | |
| 23 | import java.io.FileNotFoundException; | |
| 24 | import java.io.IOException; | |
| 25 | import java.io.InputStream; | |
| 26 | import java.net.MalformedURLException; | |
| 27 | import java.net.URL; | |
| 28 | import java.util.ArrayList; | |
| 29 | import java.util.HashMap; | |
| 30 | import java.util.Iterator; | |
| 31 | import java.util.List; | |
| 32 | import java.util.Map; | |
| 33 | import java.util.Stack; | |
| 34 | import javax.xml.parsers.ParserConfigurationException; | |
| 35 | ||
| 36 | import com.puppycrawl.tools.checkstyle.api.AbstractLoader; | |
| 37 | import com.puppycrawl.tools.checkstyle.api.CheckstyleException; | |
| 38 | import com.puppycrawl.tools.checkstyle.api.Configuration; | |
| 39 | import com.puppycrawl.tools.checkstyle.api.SeverityLevel; | |
| 40 | ||
| 41 | import org.xml.sax.Attributes; | |
| 42 | import org.xml.sax.InputSource; | |
| 43 | import org.xml.sax.SAXException; | |
| 44 | import org.xml.sax.SAXParseException; | |
| 45 | ||
| 46 | /** | |
| 47 | * Loads a configuration from a standard configuration XML file. | |
| 48 | * | |
| 49 | * @author Oliver Burn | |
| 50 | * @version 1.0 | |
| 51 | */ | |
| 52 | public final class ConfigurationLoader | |
| 53 | { | |
| 54 | /** the public ID for version 1_0 of the configuration dtd */ | |
| 55 | private static final String DTD_PUBLIC_ID_1_0 = | |
| 56 | "-//Puppy Crawl//DTD Check Configuration 1.0//EN"; | |
| 57 | ||
| 58 | /** the resource for version 1_0 of the configuration dtd */ | |
| 59 | private static final String DTD_RESOURCE_NAME_1_0 = | |
| 60 | "com/puppycrawl/tools/checkstyle/configuration_1_0.dtd"; | |
| 61 | ||
| 62 | /** the public ID for version 1_1 of the configuration dtd */ | |
| 63 | private static final String DTD_PUBLIC_ID_1_1 = | |
| 64 | "-//Puppy Crawl//DTD Check Configuration 1.1//EN"; | |
| 65 | ||
| 66 | /** the resource for version 1_1 of the configuration dtd */ | |
| 67 | private static final String DTD_RESOURCE_NAME_1_1 = | |
| 68 | "com/puppycrawl/tools/checkstyle/configuration_1_1.dtd"; | |
| 69 | ||
| 70 | /** the public ID for version 1_2 of the configuration dtd */ | |
| 71 | private static final String DTD_PUBLIC_ID_1_2 = | |
| 72 | "-//Puppy Crawl//DTD Check Configuration 1.2//EN"; | |
| 73 | ||
| 74 | /** the resource for version 1_1 of the configuration dtd */ | |
| 75 | private static final String DTD_RESOURCE_NAME_1_2 = | |
| 76 | "com/puppycrawl/tools/checkstyle/configuration_1_2.dtd"; | |
| 77 | ||
| 78 | /** constant to specify two kilobyte of data */ | |
| 79 | private static final int TWO_KB = 2048; | |
| 80 | ||
| 81 | /** | |
| 82 | * Implements the SAX document handler interfaces, so they do not | |
| 83 | * appear in the public API of the ConfigurationLoader. | |
| 84 | */ | |
| 85 | private final class InternalLoader | |
| 86 | extends AbstractLoader | |
| 87 | { | |
| 88 | /** module elements */ | |
| 89 | private static final String MODULE = "module"; | |
| 90 | /** name attribute */ | |
| 91 | private static final String NAME = "name"; | |
| 92 | /** property element */ | |
| 93 | private static final String PROPERTY = "property"; | |
| 94 | /** value attribute */ | |
| 95 | private static final String VALUE = "value"; | |
| 96 | /** default attribute */ | |
| 97 | private static final String DEFAULT = "default"; | |
| 98 | /** name of the severity property */ | |
| 99 | private static final String SEVERITY = "severity"; | |
| 100 | ||
| 101 | /** | |
| 102 | * Creates a new InternalLoader. | |
| 103 | * @throws SAXException if an error occurs | |
| 104 | * @throws ParserConfigurationException if an error occurs | |
| 105 | */ | |
| 106 | 6 |
private InternalLoader() |
| 107 | throws SAXException, ParserConfigurationException | |
| 108 | { | |
| 109 | // super(DTD_PUBLIC_ID_1_1, DTD_RESOURCE_NAME_1_1); | |
| 110 | 6 | super(createIdToResourceNameMap()); |
| 111 | } | |
| 112 | ||
| 113 | /** {@inheritDoc} **/ | |
| 114 | 22 |
public void startElement(String aNamespaceURI, |
| 115 | String aLocalName, | |
| 116 | String aQName, | |
| 117 | Attributes aAtts) | |
| 118 | throws SAXException | |
| 119 | { | |
| 120 | // TODO: debug logging for support puposes | |
| 121 | 22 | if (aQName.equals(MODULE)) { |
| 122 | //create configuration | |
| 123 | 15 | final String name = aAtts.getValue(NAME); |
| 124 | 15 | final DefaultConfiguration conf = |
| 125 | new DefaultConfiguration(name); | |
| 126 | ||
| 127 | 15 | if (mConfiguration == null) { |
| 128 | 4 | mConfiguration = conf; |
| 129 | } | |
| 130 | ||
| 131 | //add configuration to it's parent | |
| 132 | 15 | if (!mConfigStack.isEmpty()) { |
| 133 | 11 | final DefaultConfiguration top = |
| 134 | (DefaultConfiguration) mConfigStack.peek(); | |
| 135 | 11 | top.addChild(conf); |
| 136 | } | |
| 137 | ||
| 138 | 15 | mConfigStack.push(conf); |
| 139 | } | |
| 140 | 7 | else if (aQName.equals(PROPERTY)) { |
| 141 | //extract name and value | |
| 142 | 7 | final String name = aAtts.getValue(NAME); |
| 143 | 7 | final String value; |
| 144 | 7 | try { |
| 145 | ||