summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorNeil Guzman2013-08-26 14:19:44 (EDT)
committer Roland Grunberg2013-09-04 13:42:28 (EDT)
commit564a439e7697b27f523d0eee480d3ef606818fd1 (patch)
tree9e6eed9b47edda02b492a6a72ae06e871cae9f7c
parented5a40190cca0708a0b749f753869f621ce15b45 (diff)
downloadorg.eclipse.linuxtools-564a439e7697b27f523d0eee480d3ef606818fd1.zip
org.eclipse.linuxtools-564a439e7697b27f523d0eee480d3ef606818fd1.tar.gz
org.eclipse.linuxtools-564a439e7697b27f523d0eee480d3ef606818fd1.tar.bz2
RPMStubby: eclipse template uses tycho if possiblerefs/changes/64/15864/10
RPMStubby will find the parent pom within the project if it exists, and build using tycho and using the pom.xml; otherwise, RPMStubby will use the feature.xml file as before. Change-Id: I0b50fa6fa80a04e0fbbd5ef4f5e6869499f00d9b Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/15864 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF2
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/pom.xml2
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java65
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/RPMStubbyUtils.java88
4 files changed, 137 insertions, 20 deletions
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF b/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
index a5ba318..477b883 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.linuxtools.rpmstubby;singleton:=true
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Bundle-Vendor: %provider
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/pom.xml b/rpmstubby/org.eclipse.linuxtools.rpmstubby/pom.xml
index 7497177..1f2423d 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/pom.xml
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/pom.xml
@@ -24,7 +24,7 @@
<artifactId>org.eclipse.linuxtools.rpmstubby</artifactId>
<packaging>eclipse-plugin</packaging>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<name>Linux Tools RPM Stubby Plug-in</name>
<build>
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java
index abc37f4..cbcc4f3 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Alphonse Van Assche.
+ * Copyright (c) 2007, 2013 Alphonse Van Assche.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,6 +23,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.linuxtools.internal.rpmstubby.model.FeatureModel;
+import org.eclipse.linuxtools.rpmstubby.RPMStubbyUtils;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
@@ -35,6 +36,7 @@ public class StubbyGenerator extends AbstractGenerator {
private FeatureModel model;
private IFile featureFile;
+ private boolean pomExists;
/**
* Creates the specfile and fetch script generator for the given packages.
@@ -47,6 +49,7 @@ public class StubbyGenerator extends AbstractGenerator {
parse(featureFile);
specfileName = model.getPackageName().toLowerCase() + ".spec";
projectName = featureFile.getProject().getName();
+ pomExists = new RPMStubbyUtils().findPom(featureFile.getParent().getLocation());
}
private void parse(IFile featureFile) {
@@ -88,7 +91,6 @@ public class StubbyGenerator extends AbstractGenerator {
@Override
public String generateSpecfile() {
StringBuilder buffer = new StringBuilder();
- buffer.append("%global eclipse_base %{_libdir}/eclipse\n");
buffer.append("%global install_loc %{_datadir}/eclipse/dropins/"
+ model.getSimplePackageName() + "\n\n");
buffer.append("Name: " + model.getPackageName().toLowerCase()
@@ -100,9 +102,9 @@ public class StubbyGenerator extends AbstractGenerator {
buffer.append("License: " + model.getLicense() + "\n");
buffer.append("URL: " + model.getURL() + "\n");
buffer.append("Source0: #FIXME\n");
- buffer.append("BuildArch: noarch\n\n");
+ buffer.append("BuildArch: noarch\n\n");
generateRequires(buffer);
- buffer.append("\n%description\n" + model.getDescription() + "\n");
+ buffer.append("%description\n" + model.getDescription() + "\n");
generatePrepSection(buffer);
generateBuildSection(buffer);
generateInstallSection(buffer);
@@ -112,19 +114,25 @@ public class StubbyGenerator extends AbstractGenerator {
return buffer.toString();
}
- private static void generateRequires(StringBuilder buffer) {
- buffer.append("BuildRequires: eclipse-pde >= 1:3.4.0\n");
- buffer.append("Requires: eclipse-platform >= 3.4.0\n");
-
+ private void generateRequires(StringBuilder buffer) {
+ buffer.append("Requires: eclipse-platform >= 3.4.0\n");
+ buffer.append("BuildRequires: maven-local\n");
+ buffer.append("\n\n");
}
private void generateInstallSection(StringBuilder buffer) {
buffer.append("%install\n");
- buffer.append("install -d -m 755 %{buildroot}%{install_loc}\n\n");
- buffer.append("%{__unzip} -q -d %{buildroot}%{install_loc} \\\n");
- buffer.append(" build/rpmBuild/" + model.getFeatureId()
- + ".zip \n\n");
-
+ if (!pomExists) {
+ generateTempPom(buffer);
+ }
+ buffer.append("mvn-rpmbuild ");
+ if (!pomExists) {
+ buffer.append("-f temp/pom.xml ");
+ }
+ buffer.append("org.fedoraproject:feclipse-maven-plugin:install \\" + "\n");
+ buffer.append("\t" + "-DsourceRepo=#FIXME \\" + "\n");
+ buffer.append("\t" + "-DtargetLocation=%{buildroot}%{install_loc}/eclipse" + "\n");
+ buffer.append("\n\n");
}
private void generateFilesSections(StringBuilder buffer) {
@@ -139,19 +147,25 @@ public class StubbyGenerator extends AbstractGenerator {
buffer.append("%doc " + docsRoot + "/" + file + "\n");
}
}
- buffer.append("\n");
+ buffer.append("\n\n");
}
private static void generatePrepSection(StringBuilder buffer) {
buffer.append("\n%prep\n");
- buffer.append("#FIXME Replace FIXME with the root directory name in Source0\n");
- buffer.append("%setup -q -n FIXME\n\n");
+ buffer.append("%setup -q #You may need to update this according to your Source0\n");
+ buffer.append("\n\n");
}
private void generateBuildSection(StringBuilder buffer) {
buffer.append("%build\n");
- buffer.append("%{eclipse_base}/buildscripts/pdebuild -f ").append(
- model.getFeatureId());
+ if (!pomExists) {
+ generateTempPom(buffer);
+ }
+ buffer.append("mvn-rpmbuild ");
+ if (!pomExists) {
+ buffer.append("-f temp/pom.xml ");
+ }
+ buffer.append("install\n");
buffer.append("\n\n");
}
@@ -171,4 +185,19 @@ public class StubbyGenerator extends AbstractGenerator {
}
return "eclipse-" + name;
}
+
+ private static void generateTempPom(StringBuilder buffer) {
+ buffer.append("mkdir temp\n");
+ buffer.append("pushd temp\n");
+ buffer.append("cat > pom.xml << EOF\n");
+ buffer.append("<project>\n");
+ buffer.append(" <modelVersion>4.0.0</modelVersion>\n");
+ buffer.append(" <name>Maven Default Project</name>\n");
+ buffer.append(" <groupId>org.fedoraproject</groupId>\n");
+ buffer.append(" <artifactId>dummy</artifactId>\n");
+ buffer.append(" <version>1.0.0</version>\n");
+ buffer.append("</project>\n");
+ buffer.append("EOF\n");
+ buffer.append("popd\n");
+ }
}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/RPMStubbyUtils.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/RPMStubbyUtils.java
new file mode 100644
index 0000000..70abf96
--- /dev/null
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/RPMStubbyUtils.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.rpmstubby;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.internal.rpmstubby.StubbyLog;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * Utility class for RPMStubby to find the parent pom
+ *
+ * @since 1.2
+ */
+public class RPMStubbyUtils {
+
+ private DocumentBuilder builder;
+ private XPath xPath;
+ private static final String PARENT_NODE = "/project/parent";
+
+ /**
+ * Constructor.
+ *
+ */
+ public RPMStubbyUtils() {
+ DocumentBuilderFactory builderFactory =
+ DocumentBuilderFactory.newInstance();
+ builder = null;
+ try {
+ builder = builderFactory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ StubbyLog.logError(e);
+ }
+ xPath = XPathFactory.newInstance().newXPath();
+ }
+
+ /**
+ * Find the parent pom.xml of a file by recursively checking
+ * the current directory for the parent pom.xml and moving up
+ * the directory structure if there is none.
+ *
+ * @param folderPath The container of the file to check.
+ * @return The path of the parent pom. Null otherwise.
+ */
+ public boolean findPom(IPath folderPath) {
+ IPath filePath = folderPath.append(new Path("pom.xml"));
+ File file = filePath.toFile();
+ boolean rc = false;
+ if (file.exists()) {
+ try {
+ Document xmlDocument = builder.parse(new FileInputStream(file));
+ String parent = xPath.compile(PARENT_NODE).evaluate(xmlDocument);
+ if (!parent.equals("")) {
+ rc = findPom(folderPath.removeLastSegments(1));
+ } else {
+ rc = true;
+ }
+ } catch (SAXException e) {
+ StubbyLog.logError(e);
+ } catch (IOException e) {
+ StubbyLog.logError(e);
+ } catch (XPathExpressionException e) {
+ StubbyLog.logError(e);
+ }
+ }
+ return rc;
+ }
+}