Search in sources :

Example 1 with Parser

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);
        }
    }
}
Also used : DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) Parser(io.fabric8.maven.util.Parser)

Example 2 with Parser

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;
}
Also used : TreeMap(java.util.TreeMap) Profile(io.fabric8.api.Profile) Parser(io.fabric8.maven.util.Parser)

Example 3 with Parser

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);
    }
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Parser(io.fabric8.maven.util.Parser)

Example 4 with Parser

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;
}
Also used : Element(org.w3c.dom.Element) Parser(io.fabric8.maven.util.Parser)

Example 5 with Parser

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/");
}
Also used : OpenShiftPomDeployer(io.fabric8.openshift.agent.OpenShiftPomDeployer) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) MavenRepositoryURL(io.fabric8.maven.util.MavenRepositoryURL) Document(org.w3c.dom.Document) File(java.io.File) Parser(io.fabric8.maven.util.Parser)

Aggregations

Parser (io.fabric8.maven.util.Parser)12 Profile (io.fabric8.api.Profile)5 ProfileService (io.fabric8.api.ProfileService)5 HashMap (java.util.HashMap)5 File (java.io.File)4 Map (java.util.Map)4 Feature (io.fabric8.agent.model.Feature)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Element (org.w3c.dom.Element)3 BundleInfo (io.fabric8.agent.model.BundleInfo)2 MalformedURLException (java.net.MalformedURLException)2 HashSet (java.util.HashSet)2 KubernetesListener (com.github.isdream.cwatcher.listeners.KubernetesListener)1 OpenShiftListener (com.github.isdream.cwatcher.listeners.OpenShiftListener)1 ProfileVersionKey (io.fabric8.agent.commands.support.ProfileVersionKey)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Downloader (io.fabric8.agent.download.Downloader)1 StreamProvider (io.fabric8.agent.download.StreamProvider)1 MapUtils.addToMapSet (io.fabric8.agent.internal.MapUtils.addToMapSet)1