use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.
the class JavaContainers method addMavenDependencies.
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);
}
}
}
use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.
the class JavaContainers method getJavaContainerArtifacts.
public static Map<String, Parser> getJavaContainerArtifacts(FabricService fabric, List<Profile> profileList, DownloadManager downloadManager) throws Exception {
Map<String, Parser> artifacts = new TreeMap<String, Parser>();
for (Profile profile : profileList) {
Map<String, Parser> profileArtifacts = AgentUtils.getProfileArtifacts(fabric, downloadManager, profile);
artifacts.putAll(profileArtifacts);
appendMavenDependencies(artifacts, profile);
}
return artifacts;
}
use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.
the class OpenShiftPomDeployer method updateDependencyPlugin.
/**
* 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);
}
}
use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.
the class OpenShiftPomDeployer method recreateDependencyExecution.
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;
}
use of io.fabric8.maven.util.Parser in project fabric8 by jboss-fuse.
the class OpenShiftPomDeployerTest method doTest.
protected void doTest(String folder, String[] artifactUrls, String[] repoUrls, String expectedCamelDependencyScope, String expectedHawtioDependencyScope) throws Exception {
File sourceDir = new File(baseDir, "src/test/resources/" + folder);
assertDirectoryExists(sourceDir);
File pomSource = new File(sourceDir, "pom.xml");
assertFileExists(pomSource);
File outputDir = new File(baseDir, "target/" + getClass().getName() + "/" + folder);
outputDir.mkdirs();
assertDirectoryExists(outputDir);
File pom = new File(outputDir, "pom.xml");
Files.copy(pomSource, pom);
assertFileExists(pom);
git = Git.init().setDirectory(outputDir).setGitDir(new File(outputDir, ".git")).call();
assertDirectoryExists(new File(outputDir, ".git"));
git.add().addFilepattern("pom.xml").call();
git.commit().setMessage("Initial import").call();
// now we have the git repo setup; lets run the update
OpenShiftPomDeployer deployer = new OpenShiftPomDeployer(git, outputDir, deployDir, webAppDir);
System.out.println("About to update the pom " + pom + " with artifacts: " + Arrays.asList(artifactUrls));
List<Parser> artifacts = new ArrayList<Parser>();
for (String artifactUrl : artifactUrls) {
artifacts.add(Parser.parsePathWithSchemePrefix(artifactUrl));
}
List<MavenRepositoryURL> repos = new ArrayList<MavenRepositoryURL>();
for (String repoUrl : repoUrls) {
repos.add(new MavenRepositoryURL(repoUrl));
}
deployer.update(artifacts, repos);
System.out.println("Completed the new pom is: ");
System.out.println(Files.toString(pom));
Document xml = XmlUtils.parseDoc(pom);
Element plugins = assertXPathElement(xml, "project/profiles/profile[id = 'openshift']/build/plugins");
Element cleanExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-clean-plugin']/executions/execution[id = 'fuse-fabric-clean']");
Element dependencySharedExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-dependency-plugin']/executions/execution[id = 'fuse-fabric-deploy-shared']");
Element dependencyWebAppsExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-dependency-plugin']/executions/execution[id = 'fuse-fabric-deploy-webapps']");
Element warPluginWarName = xpath("plugin[artifactId = 'maven-war-plugin']/configuration/warName").element(plugins);
if (warPluginWarName != null) {
String warName = warPluginWarName.getTextContent();
System.out.println("WarName is now: " + warName);
assertTrue("Should not have ROOT war name", !"ROOT".equals(warName));
}
Element dependencies = assertXPathElement(xml, "project/dependencies");
Element repositories = assertXPathElement(xml, "project/repositories");
for (Parser artifact : artifacts) {
// lets check there's only 1 dependency for group & artifact and it has the right version
String group = groupId(artifact);
String artifactId = artifact.getArtifact();
Element dependency = assertSingleDependencyForGroupAndArtifact(dependencies, group, artifactId);
Element version = assertXPathElement(dependency, "version");
assertEquals("Version", artifact.getVersion(), version.getTextContent());
}
// lets check we either preserve scope, add provided or don't add a scope if there's none present in the underlying pom
assertDependencyScope(dependencies, "org.apache.camel", "camel-core", expectedCamelDependencyScope);
assertDependencyScope(dependencies, "org.drools", "drools-wb-distribution-wars", "provided");
assertDependencyScope(dependencies, "io.hawt", "hawtio-web", expectedHawtioDependencyScope);
assertRepositoryUrl(repositories, "https://maven.repository.redhat.com/ga/");
assertRepositoryUrl(repositories, "https://repo.fusesource.com/nexus/content/groups/ea/");
}
Aggregations