Skip to content

Commit 7ce2dd0

Browse files
committed
Fix #57 NPE's being thrown if a repository map what not explicitly specified
1 parent c2dcf2f commit 7ce2dd0

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
##Version 1.0.14 Release Notes
66

7-
* Fix #55 Relative file paths are now supported again.
7+
* Fix #55 Relative file paths are now supported again.
8+
* Fix #57 NPE's being thrown if a repository map what not explicitly specified.
89

910
##Version 1.0.13 Release Notes
1011

src/main/java/com/lazerycode/selenium/SeleniumServerMojo.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ private File getRepositoryMapFile(String customRepositoryMap) {
279279
try {
280280
repositoryMap = locator.getResourceAsFile(customRepositoryMap);
281281
} catch (ResourceNotFoundException | FileResourceCreationException e) {
282-
LOG.info("Unable to find the specified custom repository map, attempting to use value as a file path...\n");
282+
LOG.info("Unable to find the specified custom repository map in dependencies, attempting to use value as a file path...");
283+
LOG.info(" ");
283284
repositoryMap = new File(customRepositoryMap);
284285
}
285286
return repositoryMap;
@@ -292,17 +293,23 @@ private File getRepositoryMapFile(String customRepositoryMap) {
292293
* @throws MojoExecutionException
293294
*/
294295
private void setRepositoryMapFile() throws MojoExecutionException {
295-
File repositoryMap = getRepositoryMapFile(this.customRepositoryMap);
296-
if (repositoryMap == null || !repositoryMap.exists()) {
297-
this.xmlRepositoryMap = this.getClass().getResourceAsStream("/RepositoryMap.xml");
298-
} else {
299-
checkRepositoryMapIsValid(repositoryMap);
300-
try {
301-
this.xmlRepositoryMap = repositoryMap.toURI().toURL().openStream();
302-
} catch (IOException ioe) {
303-
throw new MojoExecutionException(ioe.getLocalizedMessage());
296+
if (this.customRepositoryMap != null && !this.customRepositoryMap.isEmpty()) {
297+
File repositoryMap = getRepositoryMapFile(this.customRepositoryMap);
298+
if (repositoryMap.exists()) {
299+
checkRepositoryMapIsValid(repositoryMap);
300+
try {
301+
this.xmlRepositoryMap = repositoryMap.toURI().toURL().openStream();
302+
} catch (IOException ioe) {
303+
throw new MojoExecutionException(ioe.getLocalizedMessage());
304+
}
305+
} else {
306+
throw new MojoExecutionException("Repository map '" + repositoryMap.getAbsolutePath() + "' does not exist");
304307
}
305308
}
309+
310+
if (this.xmlRepositoryMap == null) {
311+
this.xmlRepositoryMap = this.getClass().getResourceAsStream("/RepositoryMap.xml");
312+
}
306313
}
307314

308315
/**
@@ -320,7 +327,7 @@ protected void checkRepositoryMapIsValid(File repositoryMap) throws MojoExecutio
320327
Schema schema = schemaFactory.newSchema(schemaFile);
321328
Validator validator = schema.newValidator();
322329
validator.validate(xmlFile);
323-
LOG.info(" " + xmlFile.getSystemId() + " is valid");
330+
LOG.info("Repository map '" + xmlFile.getSystemId() + "' is valid");
324331
LOG.info(" ");
325332
} catch (SAXException | IOException ex) {
326333
throw new MojoExecutionException(repositoryMap.getName() + " is not valid: " + ex.getLocalizedMessage());

0 commit comments

Comments
 (0)