- // /** Relative path to the directories where the files will be stored */
- // private String getCategoryFromRelativeUrl(String relativeUrl,
- // String moduleName) {
- // int index = relativeUrl.indexOf("moduleName");
- // if (index < 1)
- // throw new SlcException("Unvalid relative URL: " + relativeUrl
- // + " for module " + moduleName);
- // // Remove trailing /
- // String result = relativeUrl.substring(0, index - 1);
- // return result.replace('/', '.');
- // }
-
- /**
- * List full URLs of the bundles, based on base URL, usable directly for
- * download.
- */
- // public List/* <String> */listUrls() {
- // if (baseUrl == null)
- // throw new SlcException("Base URL is not set");
- //
- // if (artifacts == null)
- // throw new SlcException("Artifact list not initialized");
- //
- // List/* <String> */urls = new ArrayList();
- // for (int i = 0; i < artifacts.size(); i++) {
- // OsgiArtifact osgiArtifact = (OsgiArtifact) artifacts.get(i);
- // urls.add(baseUrl + osgiArtifact.getRelativeUrl());
- // }
- // return urls;
- // }
- //
- // public void setBaseUrl(String baseUrl) {
- // this.baseUrl = baseUrl;
- // }
+ protected void listModulesFromPomIndex(Set<Artifact> artifacts,
+ Node fileNode, Binary fileBinary) {
+ InputStream input = null;
+ try {
+ input = fileBinary.getStream();
+
+ DocumentBuilder documentBuilder = DocumentBuilderFactory
+ .newInstance().newDocumentBuilder();
+ Document doc = documentBuilder.parse(input);
+
+ // properties
+ Properties props = new Properties();
+ // props.setProperty("project.version",
+ // pomArtifact.getBaseVersion());
+ NodeList properties = doc.getElementsByTagName("properties");
+ if (properties.getLength() > 0) {
+ NodeList propertiesElems = properties.item(0).getChildNodes();
+ for (int i = 0; i < propertiesElems.getLength(); i++) {
+ if (propertiesElems.item(i) instanceof Element) {
+ Element property = (Element) propertiesElems.item(i);
+ props.put(property.getNodeName(),
+ property.getTextContent());
+ }
+ }
+ }
+
+ // full coordinates are under <dependencyManagement><dependencies>
+ NodeList dependencies = ((Element) doc.getElementsByTagName(
+ "dependencyManagement").item(0))
+ .getElementsByTagName("dependency");
+ for (int i = 0; i < dependencies.getLength(); i++) {
+ Element dependency = (Element) dependencies.item(i);
+ String groupId = dependency.getElementsByTagName("groupId")
+ .item(0).getTextContent().trim();
+ String artifactId = dependency
+ .getElementsByTagName("artifactId").item(0)
+ .getTextContent().trim();
+ String version = dependency.getElementsByTagName("version")
+ .item(0).getTextContent().trim();
+ // if (version.startsWith("${")) {
+ // String versionKey = version.substring(0,
+ // version.length() - 1).substring(2);
+ // if (!props.containsKey(versionKey))
+ // throw new SlcException("Cannot interpret version "
+ // + version);
+ // version = props.getProperty(versionKey);
+ // }
+ // NodeList scopes = dependency.getElementsByTagName("scope");
+ // if (scopes.getLength() > 0
+ // && scopes.item(0).getTextContent().equals("import")) {
+ // // recurse
+ // gatherPomDependencies(aetherTemplate, artifacts,
+ // new DefaultArtifact(groupId, artifactId, "pom",
+ // version));
+ // } else {
+ // TODO: deal with scope?
+ // TODO: deal with type
+ String type = "jar";
+ Artifact artifact = new DefaultArtifact(groupId, artifactId,
+ type, version);
+ artifacts.add(artifact);
+ // }
+ }
+ } catch (Exception e) {
+ throw new SlcException("Cannot process pom " + fileNode, e);
+ } finally {
+ IOUtils.closeQuietly(input);
+ }
+ }