Skip to content

Commit

Permalink
Add some null guards in GenerateUpdateSiteTask (Issue #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesse-gallagher committed Dec 14, 2023
1 parent 8dd562e commit db0e1dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -674,15 +674,15 @@ private Document fetchEclipseArtifacts() throws MalformedURLException {
* @since 3.3.0
*/
private void downloadSource(Path artifact, Path destDir, Document artifacts) throws Exception {
String fileName = artifact.getFileName().toString();
String fileName = StringUtil.toString(artifact.getFileName());
Matcher matcher = BUNDLE_FILENAME_PATTERN.matcher(fileName);
if(matcher.matches()) {
String symbolicName = matcher.group(1) + ".source"; //$NON-NLS-1$
String version = matcher.group(2);

String query = StringUtil.format("/repository/artifacts/artifact[@classifier='osgi.bundle'][@id='{0}'][@version='{1}']", symbolicName, version); //$NON-NLS-1$
NodeList result = NSFODPDomUtil.selectNodes(artifacts, query);
if(result.getLength() > 0) {
if(result != null && result.getLength() > 0) {
// Then we can be confident that it will exist at the expected URL
String bundleName = StringUtil.format("{0}_{1}.jar", symbolicName, version); //$NON-NLS-1$
Path dest = destDir.resolve(bundleName);
Expand All @@ -692,12 +692,12 @@ private void downloadSource(Path artifact, Path destDir, Document artifacts) thr
URL bundleUrl = new URL(urlString);
try(InputStream is = bundleUrl.openStream()) {
if(log.isInfoEnabled()) {
log.info(Messages.getString("GenerateUpdateSiteTask.downloadingSourceBundle") + artifact.getFileName().toString()); //$NON-NLS-1$
log.info(Messages.getString("GenerateUpdateSiteTask.downloadingSourceBundle", artifact.getFileName())); //$NON-NLS-1$
}
Files.copy(is, dest, StandardCopyOption.REPLACE_EXISTING);
} catch(IOException e) {
} catch(Exception e) {
if(log.isWarnEnabled()) {
log.warn(Messages.getString("GenerateUpdateSiteTask.unableToDownloadSourceBundle") + urlString, e); //$NON-NLS-1$
log.warn(Messages.getString("GenerateUpdateSiteTask.unableToDownloadSourceBundle", urlString), e); //$NON-NLS-1$
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ GenerateUpdateSiteTask.0=Unable to locate xsp.http.bootstrap.jar - skipping bund
GenerateUpdateSiteTask.copying=Copying
GenerateUpdateSiteTask.directoryExistsAsFile=Planned directory exists as a file:
GenerateUpdateSiteTask.directoryNotExists=Directory does not exist:
GenerateUpdateSiteTask.downloadingSourceBundle=- Downloading source bundle
GenerateUpdateSiteTask.downloadingSourceBundle=- Downloading source bundle {0}
GenerateUpdateSiteTask.errorWritingSiteXml=Error writing site.xml file
GenerateUpdateSiteTask.exceptionBuildingSiteXml=Exception while building site.xml document
GenerateUpdateSiteTask.mismatchedFilename=Could not match filename pattern to
GenerateUpdateSiteTask.repoDirDoesNotExist=Repository directory does not exist.
GenerateUpdateSiteTask.unableToDownloadSourceBundle=Unable to download source bundle
GenerateUpdateSiteTask.unableToDownloadSourceBundle=Unable to download source bundle\: {0}
GenerateUpdateSiteTask.unableToFindFeatures=Unable to find features directory:
GenerateUpdateSiteTask.unableToLoadNeon=Unable to load Neon artifacts.xml.xz
GenerateUpdateSiteTask.unableToLocateLibExtJar=Unable to locate {0} within {1}
Expand Down

0 comments on commit db0e1dd

Please sign in to comment.