Ejemplo n.º 1
0
 /**
  * Loads the import control file from a {@link InputSource}.
  *
  * @param source the source to load from.
  * @param uri uri of the source being loaded.
  * @return the root {@link PkgControl} object.
  * @throws CheckstyleException if an error occurs.
  */
 private static PkgControl load(final InputSource source, final URI uri)
     throws CheckstyleException {
   try {
     final ImportControlLoader loader = new ImportControlLoader();
     loader.parseInputSource(source);
     return loader.getRoot();
   } catch (final ParserConfigurationException | SAXException ex) {
     throw new CheckstyleException("unable to parse " + uri + " - " + ex.getMessage(), ex);
   } catch (final IOException ex) {
     throw new CheckstyleException("unable to read " + uri, ex);
   }
 }
Ejemplo n.º 2
0
  /**
   * Set the name for the file containing the import control configuration. It will cause the file
   * to be loaded.
   *
   * @param name the name of the file to load.
   * @throws ConversionException on error loading the file.
   */
  public void setFile(final String name) {
    // Handle empty param
    if (StringUtils.isBlank(name)) {
      return;
    }

    try {
      root = ImportControlLoader.load(new File(name).toURI());
    } catch (final CheckstyleException ex) {
      throw new ConversionException(UNABLE_TO_LOAD + name, ex);
    }
  }
Ejemplo n.º 3
0
 /**
  * Set the parameter for the url containing the import control configuration. It will cause the
  * url to be loaded.
  *
  * @param url the url of the file to load.
  * @throws ConversionException on error loading the file.
  */
 public void setUrl(final String url) {
   // Handle empty param
   if (StringUtils.isBlank(url)) {
     return;
   }
   final URI uri;
   try {
     uri = URI.create(url);
   } catch (final IllegalArgumentException ex) {
     throw new ConversionException("Syntax error in url " + url, ex);
   }
   try {
     root = ImportControlLoader.load(uri);
   } catch (final CheckstyleException ex) {
     throw new ConversionException(UNABLE_TO_LOAD + url, ex);
   }
 }
 @Test
 public void testExtraElementInConfig() throws Exception {
   final PkgControl root =
       ImportControlLoader.load(new File(getPath("import-control_WithNewElement.xml")).toURI());
   assertNotNull(root);
 }
 @Test(expected = CheckstyleException.class)
 public void testWrongFormatURI() throws Exception {
   final PkgControl root =
       ImportControlLoader.load(new URI("aaa://" + getPath("import-control_complete.xml")));
   assertNotNull(root);
 }
 @Test
 public void testLoad() throws CheckstyleException {
   final PkgControl root =
       ImportControlLoader.load(new File(getPath("import-control_complete.xml")).toURI());
   assertNotNull(root);
 }