Update of /cvsroot/checkstyle/checkstyle/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports
In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv27245/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports
Modified Files:
ImportControlLoader.java ImportControlCheck.java
Log Message:
Add a url option for ImportControl check. Thanks to Benjamin Lerman for
the patch 1724683.
Index: ImportControlLoader.java
===================================================================
RCS file: /cvsroot/checkstyle/checkstyle/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlLoader.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ImportControlLoader.java 27 Jan 2007 14:51:19 -0000 1.7
--- ImportControlLoader.java 4 Jun 2007 04:02:05 -0000 1.8
***************
*** 21,27 ****
import com.puppycrawl.tools.checkstyle.api.AbstractLoader;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Stack;
import javax.xml.parsers.ParserConfigurationException;
--- 21,28 ----
import com.puppycrawl.tools.checkstyle.api.AbstractLoader;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import java.io.IOException;
+ import java.io.InputStream;
+ import java.net.MalformedURLException;
+ import java.net.URI;
import java.util.Stack;
import javax.xml.parsers.ParserConfigurationException;
***************
*** 110,128 ****
/**
* Loads the import control file from a file.
! * @param aFilename the name of the file to load.
* @return the root {@link PkgControl} object.
* @throws CheckstyleException if an error occurs.
*/
! static PkgControl load(final String aFilename) throws CheckstyleException
{
! FileInputStream fis = null;
try {
! fis = new FileInputStream(aFilename);
}
! catch (final FileNotFoundException e) {
! throw new CheckstyleException("unable to find " + aFilename, e);
}
! final InputSource source = new InputSource(fis);
! return load(source, aFilename);
}
--- 111,132 ----
/**
* Loads the import control file from a file.
! * @param aUri the uri of the file to load.
* @return the root {@link PkgControl} object.
* @throws CheckstyleException if an error occurs.
*/
! static PkgControl load(final URI aUri) throws CheckstyleException
{
! InputStream is = null;
try {
! is = aUri.toURL().openStream();
}
! catch (final MalformedURLException e) {
! throw new CheckstyleException("syntax error in url " + aUri, e);
}
! catch (final IOException e) {
! throw new CheckstyleException("unable to find " + aUri, e);
! }
! final InputSource source = new InputSource(is);
! return load(source, aUri);
}
***************
*** 130,139 ****
* Loads the import control file from a {@link InputSource}.
* @param aSource the source to load from.
! * @param aSourceName name of the source being loaded.
* @return the root {@link PkgControl} object.
* @throws CheckstyleException if an error occurs.
*/
private static PkgControl load(final InputSource aSource,
! final String aSourceName) throws CheckstyleException
{
try {
--- 134,143 ----
* Loads the import control file from a {@link InputSource}.
* @param aSource the source to load from.
! * @param aUri uri of the source being loaded.
* @return the root {@link PkgControl} object.
* @throws CheckstyleException if an error occurs.
*/
private static PkgControl load(final InputSource aSource,
! final URI aUri) throws CheckstyleException
{
try {
***************
*** 143,154 ****
}
catch (final ParserConfigurationException e) {
! throw new CheckstyleException("unable to parse " + aSourceName, e);
}
catch (final SAXException e) {
! throw new CheckstyleException("unable to parse " + aSourceName
+ " - " + e.getMessage(), e);
}
catch (final IOException e) {
! throw new CheckstyleException("unable to read " + aSourceName, e);
}
}
--- 147,158 ----
}
catch (final ParserConfigurationException e) {
! throw new CheckstyleException("unable to parse " + aUri, e);
}
catch (final SAXException e) {
! throw new CheckstyleException("unable to parse " + aUri
+ " - " + e.getMessage(), e);
}
catch (final IOException e) {
! throw new CheckstyleException("unable to read " + aUri, e);
}
}
***************
*** 171,175 ****
* @throws SAXException if the attribute does not exist.
*/
! private String safeGet(final Attributes aAtts, String aName)
throws SAXException
{
--- 175,179 ----
* @throws SAXException if the attribute does not exist.
*/
! private String safeGet(final Attributes aAtts, final String aName)
throws SAXException
{
Index: ImportControlCheck.java
===================================================================
RCS file: /cvsroot/checkstyle/checkstyle/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ImportControlCheck.java 27 Jan 2007 14:51:19 -0000 1.8
--- ImportControlCheck.java 4 Jun 2007 04:02:05 -0000 1.9
***************
*** 19,22 ****
--- 19,25 ----
package com.puppycrawl.tools.checkstyle.checks.imports;
+ import java.io.File;
+ import java.net.URI;
+
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
***************
*** 99,102 ****
--- 102,132 ----
/**
+ * Set the parameter for the url containing the import control
+ * configuration. It will cause the url to be loaded.
+ * @param aUrl the url of the file to load.
+ * @throws ConversionException on error loading the file.
+ */
+ public void setUrl(final String aUrl)
+ {
+ // Handle empty param
+ if ((aUrl == null) || (aUrl.trim().length() == 0)) {
+ return;
+ }
+ final URI uri;
+ try {
+ uri = URI.create(aUrl);
+ }
+ catch (final IllegalArgumentException ex) {
+ throw new ConversionException("syntax error in url " + aUrl, ex);
+ }
+ try {
+ mRoot = ImportControlLoader.load(uri);
+ }
+ catch (final CheckstyleException ex) {
+ throw new ConversionException("Unable to load " + aUrl, ex);
+ }
+ }
+
+ /**
* Set the parameter for the file containing the import control
* configuration. It will cause the file to be loaded.
***************
*** 112,116 ****
try {
! mRoot = ImportControlLoader.load(aName);
}
catch (final CheckstyleException ex) {
--- 142,146 ----
try {
! mRoot = ImportControlLoader.load(new File(aName).toURI());
}
catch (final CheckstyleException ex) {
|