From 8591af83bf8370e38e26e9cc0945d0b2c740c29d Mon Sep 17 00:00:00 2001 From: Stefan Sachs Date: Fri, 31 Jul 2015 17:41:24 +0200 Subject: [PATCH] Fix #3 Problem with docs jar not found if snapshotVersions element is missing in maven-metadata.xml --- .../service/ArtifactIdentifier.java | 2 +- .../service/RepositoryService.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rbmhtechnology/apidocserver/service/ArtifactIdentifier.java b/src/main/java/com/rbmhtechnology/apidocserver/service/ArtifactIdentifier.java index 6c8aade..2bffed0 100644 --- a/src/main/java/com/rbmhtechnology/apidocserver/service/ArtifactIdentifier.java +++ b/src/main/java/com/rbmhtechnology/apidocserver/service/ArtifactIdentifier.java @@ -20,7 +20,7 @@ */ public class ArtifactIdentifier { - private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; + public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; private final String groupId; private final String artifactId; private final String version; diff --git a/src/main/java/com/rbmhtechnology/apidocserver/service/RepositoryService.java b/src/main/java/com/rbmhtechnology/apidocserver/service/RepositoryService.java index 45a13be..e605f1b 100644 --- a/src/main/java/com/rbmhtechnology/apidocserver/service/RepositoryService.java +++ b/src/main/java/com/rbmhtechnology/apidocserver/service/RepositoryService.java @@ -340,6 +340,32 @@ private String getApidocFileNameFromMetadataXML(ArtifactIdentifier artifactIdent } } + // did not find a proper version, try to use "snapshot" + NodeList snapshotElements = rootElement.getElementsByTagName("snapshot"); + if (snapshotElements.getLength() == 1) { + Node snapshotNode = snapshotElements.item(0); + + NodeList childNodes = snapshotNode.getChildNodes(); + Node timestampNode = null; + Node buildNumberNode = null; + for (int childIndex = 0; childIndex < childNodes.getLength(); childIndex++) { + Node _node = childNodes.item(childIndex); + String nodeName = _node.getNodeName(); + if ("timestamp".equals(nodeName)) { + timestampNode = _node; + } else if ("buildNumber".equals(nodeName)) { + buildNumberNode = _node; + } + } + + if (timestampNode != null && buildNumberNode != null) { + return artifactIdentifier.getArtifactId() + "-" + + artifactIdentifier.getVersion().replace(ArtifactIdentifier.SNAPSHOT_SUFFIX, "") + "-" + + timestampNode.getTextContent() + "-" + buildNumberNode.getTextContent() + "-" + + artifactIdentifier.getClassifier() + ".jar"; + } + } + } catch (SAXException | IOException | ParserConfigurationException e) { throw new RepositoryException("Could not parse maven-metadata.xml for '" + artifactIdentifier + "'", e); }