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() ); }
/** * Returns the complete path to artifact as stated by Maven 2 repository layout. * * @return artifact path */ public String getArtifactPath() { return getArtifactPath( m_version ); }
/** * Lets trim any kind of "mvn:" prefix before parsing */ public static Parser parsePathWithSchemePrefix(String location) throws MalformedURLException { String withoutMvnPrefix = location; boolean done = false; while (!done) { int idx = withoutMvnPrefix.indexOf(':'); if (idx >= 0) { withoutMvnPrefix = withoutMvnPrefix.substring(idx + 1); } // there may be a inlined maven repo location (assuming http), so we are done if we find that if (withoutMvnPrefix.startsWith("http:") || withoutMvnPrefix.startsWith("https:")) { done = true; } else if (withoutMvnPrefix.indexOf(':') < 0) { done = true; } } return new Parser(withoutMvnPrefix); }
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 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); } }
public static boolean isSnapshot(Parser parser) { String version = parser.getVersion(); return version != null && version.contains("SNAPSHOT"); }
public static String groupId(Parser parser) { String group = parser.getGroup(); int idx = group.indexOf(':'); if (idx > 0) { group = group.substring(idx + 1); } return group; }
protected static void addMavenDependencies(Map<String, Parser> artifacts, DependencyDTO dependency) throws MalformedURLException { String url = dependency.toBundleUrlWithType(); Parser parser = Parser.parsePathWithSchemePrefix(url); String scope = dependency.getScope(); if (!artifacts.containsKey(url) && !artifacts.containsValue(parser) && !(Objects.equal("test", scope))) { LOGGER.debug("Adding url: " + url + " parser: " + parser); artifacts.put(url, parser); } List<DependencyDTO> children = dependency.getChildren(); if (children != null) { for (DependencyDTO child : children) { addMavenDependencies(artifacts, child); } } }
/** * Lets add/update the maven dependency plugin configuration to copy deployments * to the deployDir or the webAppDir */ protected void updateDependencyPlugin(Element plugins, Element dependencies, Collection<Parser> artifacts) throws XPathExpressionException { Element plugin = getOrCreatePlugin(plugins, "maven-dependency-plugin", "2.8"); Element executions = getOrCreateChild(plugin, "executions", 6); List<Parser> warArtifacts = new ArrayList<Parser>(); List<Parser> jarArtifacts = new ArrayList<Parser>(); for (Parser artifact : artifacts) { String type = artifact.getType(); if (Objects.equal("war", type)) { warArtifacts.add(artifact); } else { jarArtifacts.add(artifact); } } if (Strings.isNotBlank(webAppDir) && !warArtifacts.isEmpty()) { recreateDependencyExecution(executions, dependencies, "fuse-fabric-deploy-webapps", webAppDir, warArtifacts, true); } if (Strings.isNotBlank(deployDir) && !jarArtifacts.isEmpty()) { recreateDependencyExecution(executions, dependencies, "fuse-fabric-deploy-shared", deployDir, jarArtifacts, false); } }
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; }
String password = fabricService.get().getZookeeperPassword(); URI uploadUri = fabricService.get().getMavenRepoUploadURI(); URI artifactUri = uploadUri.resolve(parser.getArtifactPath()); URL url; try {
/** * Creates a new connection. * * @param url the url; cannot be null. * @param resolver resolver service; cannot be null * * @throws java.net.MalformedURLException in case of a malformed url */ public Connection( final URL url, final MavenResolver resolver ) throws MalformedURLException { super( url ); NullArgumentException.validateNotNull(url, "URL cannot be null"); NullArgumentException.validateNotNull( resolver, "Service configuration" ); m_resolver = resolver; // Verify the url syntax, will throw an exception when invalid new Parser( url.getPath() ); }
File file = new File(localRepository.getPath() + File.separator + parser.getArtifactPath()); if (!file.exists()) { LOG.info("Ignoring file " + file.getPath() + " as it does not exist");