protected void checkRepositoryMapIsValid ( File repositoryMap ) throws MojoExecutionException { URL schemaFile = this . getClass ( ) . getResource ( "/RepositoryMap.xsd" ) ; Source xmlFile = new StreamSource ( repositoryMap ) ; SchemaFactory schemaFactory = SchemaFactory . newInstance ( XMLConstants . W3C_XML_SCHEMA_NS_URI ) ; try { Schema schema = schemaFactory . newSchema ( schemaFile ) ; Validator validator = schema . newValidator ( ) ; validator . validate ( xmlFile ) ; LOG . info ( "Repository map '" + xmlFile . getSystemId ( ) + "' is valid" ) ; LOG . info ( " " ) ; } catch ( SAXException | IOException ex ) { throw new MojoExecutionException ( repositoryMap . getName ( ) + " is not valid: " + ex . getLocalizedMessage ( ) ) ; } }
Validate any custom repository maps that are supplied against the xsd . Throw an error and stop if it is not valid . Assume it doesn t exist if we get an IOError and fall back to default file .