Author: mickael_istria
Date: 2012-10-04 13:33:05 -0400 (Thu, 04 Oct 2012)
New Revision: 44304
Added:
trunk/build/tycho-plugins/target-platform-utils/
trunk/build/tycho-plugins/target-platform-utils/pom.xml
trunk/build/tycho-plugins/target-platform-utils/src/
trunk/build/tycho-plugins/target-platform-utils/src/main/
trunk/build/tycho-plugins/target-platform-utils/src/main/java/
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java
Modified:
trunk/build/tycho-plugins/pom.xml
Log:
A target-platform-utils maven plugin
Modified: trunk/build/tycho-plugins/pom.xml
===================================================================
--- trunk/build/tycho-plugins/pom.xml 2012-10-04 16:31:51 UTC (rev 44303)
+++ trunk/build/tycho-plugins/pom.xml 2012-10-04 17:33:05 UTC (rev 44304)
@@ -13,6 +13,7 @@
<modules>
<module>repository-utils</module>
+ <module>target-platform-utils</module>
</modules>
<build>
Added: trunk/build/tycho-plugins/target-platform-utils/pom.xml
===================================================================
--- trunk/build/tycho-plugins/target-platform-utils/pom.xml (rev
0)
+++ trunk/build/tycho-plugins/target-platform-utils/pom.xml 2012-10-04 17:33:05 UTC (rev
44304)
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.tools</groupId>
+ <artifactId>tycho-plugins</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>org.jboss.tools.tycho-plugins</groupId>
+ <artifactId>target-platform-utils</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+ <name>target-platform-utils Maven Mojo</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-annotations</artifactId>
+ <version>1.5.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-p2-facade</artifactId>
+ <version>0.15.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Property changes on: trunk/build/tycho-plugins/target-platform-utils/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java
===================================================================
---
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java
(rev 0)
+++
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java 2012-10-04
17:33:05 UTC (rev 44304)
@@ -0,0 +1,144 @@
+/**
+ * Copyright (c) 2012, Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Mickael Istria (Red Hat, Inc.) - initial API and implementation
+ */
+package org.jboss.tools.tycho.targets;
+
+import java.io.File;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.RepositorySystem;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Takes a multi-site .target file as input and flatten it to have same IUs, but from a
single site.
+ *
+ * @goal flatten-target
+ */
+public class FlattenTargetMojo extends AbstractMojo
+{
+
+ /**
+ * @parameter default-value="${project}"
+ * @readonly
+ */
+ private MavenProject project;
+ /**
+ * @parameter expression="${session}"
+ * @readonly
+ */
+ private MavenSession session;
+
+ /**
+ * @component
+ */
+ @Requirement
+ private RepositorySystem repositorySystem;
+
+ /**
+ * Location of the output file.
+ * @parameter
expression="${project.build.directory}/${project.artifactId}.target"
+ * @required
+ */
+ private File outputFile;
+
+ /**
+ * Target to transform (as a file)
+ * @parameter
+ */
+ private File sourceTargetFile;
+
+ /**
+ * @parameter
+ */
+ private TargetArtifact sourceTargetArtifact;
+
+ /**
+ * @parameter
+ * @required
+ */
+ private String targetRepositoryUrl;
+
+ public void execute() throws MojoExecutionException {
+ if (!this.outputFile.getParentFile().exists()) {
+ this.outputFile.getParentFile().mkdirs();
+ }
+
+ if ((this.sourceTargetFile != null && this.sourceTargetArtifact != null)
||
+ (this.sourceTargetFile == null && this.sourceTargetArtifact == null))
{
+ throw new MojoExecutionException("Set either 'sourceTargetFile' XOR
'sourceTargetArtifact'");
+ }
+
+ if (this.sourceTargetArtifact != null) {
+ if (!this.sourceTargetArtifact.isCorrectlySet()) {
+ throw new MojoExecutionException("'sourceTargetArtifact' must
define groupId, artifactId and version");
+ }
+ getLog().info("Downloading " + sourceTargetArtifact.toString());
+ Artifact artifact =
this.repositorySystem.createArtifactWithClassifier(this.sourceTargetArtifact.getGroupId(),
this.sourceTargetArtifact.getArtifactId(), this.sourceTargetArtifact.getVersion(),
"target",
+ this.sourceTargetArtifact.getArtifactId());
+ ArtifactResolutionRequest request = new ArtifactResolutionRequest();
+ request.setArtifact(artifact);
+ request.setLocalRepository(this.session.getLocalRepository());
+ request.setRemoteRepositories(this.project.getRemoteArtifactRepositories());
+ this.repositorySystem.resolve(request);
+
+ if (!artifact.isResolved()) {
+ throw new RuntimeException("Could not resolve target platform
specification artifact " + artifact);
+ }
+
+ this.sourceTargetFile = artifact.getFile();
+ }
+
+ try {
+ DocumentBuilder docBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document targetDoc = docBuilder.parse(this.sourceTargetFile);
+ NodeList locations = ((Element)
((Element)targetDoc.getElementsByTagName("target").item(0)).getElementsByTagName("locations").item(0)).getElementsByTagName("location");
+ getLog().debug("number of locations: " + locations.getLength());
+ Element targetItem = (Element) locations.item(0);
+
((Element)targetItem.getElementsByTagName("repository").item(0)).setAttribute("location",
this.targetRepositoryUrl);
+ while (locations.getLength() > 1) {
+ Element location = (Element)locations.item(1);
+ NodeList children = location.getChildNodes();
+ while (children.getLength() > 0) {
+ if ((children.item(0) instanceof Element) &&
((Element)children.item(0)).getTagName().equals("repository")) {
+ location.removeChild(children.item(0));
+ } else {
+ targetItem.appendChild(children.item(0));
+ }
+ }
+ location.getParentNode().removeChild(location);
+ }
+
+ //write the content into xml file
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, Boolean.TRUE.toString());
+ DOMSource source = new DOMSource(targetDoc);
+ StreamResult result = new StreamResult(outputFile);
+ transformer.transform(source, result);
+ } catch (Exception ex) {
+ throw new MojoExecutionException("Error processing files", ex);
+ }
+ }
+}
Property changes on:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java
===================================================================
---
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java
(rev 0)
+++
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java 2012-10-04
17:33:05 UTC (rev 44304)
@@ -0,0 +1,27 @@
+package org.jboss.tools.tycho.targets;
+
+public class TargetArtifact {
+
+ private String groupId;
+ private String artifactId;
+ private String version;
+
+ public String getGroupId() {
+ return this.groupId;
+ }
+ public String getArtifactId() {
+ return this.artifactId;
+ }
+ public String getVersion() {
+ return this.version;
+ }
+
+ public boolean isCorrectlySet() {
+ return this.groupId != null && this.artifactId != null && this.version
!= null;
+ }
+
+ @Override
+ public String toString() {
+ return this.groupId + ":" + this.artifactId + ":" + this.version;
+ }
+}
Property changes on:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain