public File download(String url) throws IOException { Parser parser = Parser.parsePathWithSchemePrefix(url); return resolveFile( parser.getGroup(), parser.getArtifact(), parser.getClassifier(), parser.getType(), parser.getVersion(), parser.getRepositoryURL() ); }
protected void addMavenCoordinates(Element owner, Parser parser, int indent) { String group = groupId(parser); createAndAppendChild(owner, "groupId", indent, group); createAndAppendChild(owner, "artifactId", indent, parser.getArtifact()); createAndAppendChild(owner, "version", indent, parser.getVersion()); String type = parser.getType(); if (type != null && !Objects.equal("jar", type)) { createAndAppendChild(owner, "type", indent, type); } String classifier = parser.getClassifier(); if (Strings.isNotBlank(classifier)) { createAndAppendChild(owner, "classifier", indent, classifier); } }
protected Element recreateDependencyExecution(Element executions, Element dependencies, String executionId, String outputDir, List<Parser> list, boolean isWar) throws XPathExpressionException { // lets make sure the output dir is trimmed of "/" while (outputDir.startsWith("/")) { outputDir = outputDir.substring(1); } Element execution = recreateChild(executions, "execution[id = '" + executionId + "']", "execution", 7); createAndAppendChild(execution, "id", 8, executionId); createAndAppendChild(execution, "phase", 8, "package"); Element goals = createAndAppendChild(execution, "goals", 8); createAndAppendChild(goals, "goal", 9, "copy"); Element configuration = createAndAppendChild(execution, "configuration", 9); Element artifactItems = createAndAppendChild(configuration, "artifactItems", 10); for (Parser parser : list) { Element artifactItem = createAndAppendChild(artifactItems, "artifactItem", 11); addMavenCoordinates(artifactItem, parser, 12); addOrUpdateDependency(dependencies, parser); createAndAppendChild(artifactItem, "overWrite", 12, "true"); createAndAppendChild(artifactItem, "outputDirectory", 12, "${basedir}/" + outputDir); // TODO use ROOT if this is the configured web app! if (isWar) { createAndAppendChild(artifactItem, "destFileName", 12, parser.getArtifact() + ".war"); } } createAndAppendChild(configuration, "outputDirectory", 10, "${basedir}/" + outputDir); createAndAppendChild(configuration, "overWriteReleases", 10, "true"); createAndAppendChild(configuration, "overWriteSnapshots", 10, "true"); return configuration; }
protected void addOrUpdateDependency(Element dependencies, Parser parser) throws XPathExpressionException { String group = groupId(parser); String artifact = parser.getArtifact(); String xpath = "dependency[groupId = '" + group + "' and artifactId = '" + artifact + "'"; String type = parser.getType(); if (Strings.isNotBlank(type) && !Objects.equal("jar", type)) { xpath += " and type='" + type + "'"; } String classifier = parser.getClassifier(); if (Strings.isNotBlank(classifier)) { xpath += " and classifier='" + classifier + "'"; } xpath += "]"; String scope = "provided"; Element dependency = xpath(xpath).element(dependencies); if (dependency != null) { // lets preserve the scope or not add it if there is no scope // on the previously found dependency scope = xpath("scope").elementTextContent(dependency); detachElement(dependency); } dependency = createAndAppendChild(dependencies, "dependency", 2); addMavenCoordinates(dependency, parser, 3); if (Strings.isNotBlank(scope)) { createAndAppendChild(dependency, "scope", 3, scope); } }