Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'rpmstubby')
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/AbstractGenerator.java95
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfilePomWriter.java36
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java35
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java87
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPomGenerator.java108
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/Generator.java8
6 files changed, 136 insertions, 233 deletions
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/AbstractGenerator.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/AbstractGenerator.java
new file mode 100644
index 0000000000..11aaefae11
--- /dev/null
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/AbstractGenerator.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.internal.rpmstubby;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * Abstract class holding the common part of generators.
+ *
+ */
+public abstract class AbstractGenerator {
+
+ String projectName;
+ String specfileName;
+
+ /**
+ * Writes the given contents to a file with the given fileName in the
+ * specified project.
+ */
+ public void writeContent() {
+ String contents = generateSpecfile();
+ InputStream contentInputStream = new ByteArrayInputStream(
+ contents.getBytes());
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource resource = root.findMember(new Path(projectName));
+ if (!resource.exists() || !(resource instanceof IContainer)) {
+ logCoreException("Project \"" + projectName + "\" does not exist.");
+ }
+ IContainer container = (IContainer) resource;
+ final IFile file = container.getFile(new Path(specfileName));
+ try {
+ InputStream stream = contentInputStream;
+ if (file.exists()) {
+ file.setContents(stream, true, true, null);
+ } else {
+ file.create(stream, true, null);
+ }
+ stream.close();
+ } catch (IOException e) {
+ StubbyLog.logError(e);
+ } catch (CoreException e) {
+ StubbyLog.logError(e);
+ }
+ StubbyPlugin.getActiveWorkbenchShell().getDisplay()
+ .asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ try {
+ IDE.openEditor(page, file, true);
+ } catch (PartInitException e) {
+ StubbyLog.logError(e);
+ }
+ }
+ });
+ }
+
+ /**
+ * The method that returns the string representation of the spec file.
+ *
+ * @return The specfile.
+ */
+ public abstract String generateSpecfile();
+
+ private void logCoreException(String message) {
+ IStatus status = new Status(IStatus.ERROR, StubbyPlugin.PLUGIN_ID,
+ IStatus.OK, message, null);
+ StubbyLog.logError(new CoreException(status));
+ }
+
+}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfilePomWriter.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfilePomWriter.java
deleted file mode 100644
index 8d6c94893c..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfilePomWriter.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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.internal.rpmstubby;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Utility class used for writing the generated specfile to a file.
- *
- */
-public class SpecfilePomWriter {
-
- /**
- * Parse the pom.xml and write the generated specfile.
- * @param pomFile The pom.xml file.
- */
- public void write(IFile pomFile) {
-
- StubbyPomGenerator generator = new StubbyPomGenerator(pomFile);
- try {
- generator.writeContent(pomFile.getProject().getName());
- } catch (CoreException e) {
- StubbyLog.logError(e);
- }
- }
-
-}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java
deleted file mode 100644
index 617d78db28..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alphonse Van Assche - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.rpmstubby;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Utility class used for writing the generated specfile to a file.
- *
- */
-public class SpecfileWriter {
-
- /**
- * Parse the feature.xml and write the generated specfile.
- * @param featureFile The feature.xml file.
- */
- public void write(IFile featureFile) {
-
- StubbyGenerator generator = new StubbyGenerator(featureFile);
- try {
- generator.writeContent(featureFile.getProject().getName());
- } catch (CoreException e) {
- StubbyLog.logError(e);
- }
- }
-}
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 e5dcc5bfc4..32c3602559 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
@@ -10,32 +10,19 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.rpmstubby;
-import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.internal.rpmstubby.model.FeatureModel;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
@@ -44,7 +31,7 @@ import org.xml.sax.SAXException;
* preferences.
*
*/
-public class StubbyGenerator {
+public class StubbyGenerator extends AbstractGenerator {
private FeatureModel model;
private IFile featureFile;
@@ -58,6 +45,8 @@ public class StubbyGenerator {
public StubbyGenerator(IFile featureFile) {
this.featureFile = featureFile;
parse(featureFile);
+ specfileName = model.getPackageName().toLowerCase() + ".spec";
+ projectName = featureFile.getProject().getName();
}
private void parse(IFile featureFile) {
@@ -65,7 +54,7 @@ public class StubbyGenerator {
.newInstance();
IPath featureDir = featureFile.getLocation().removeLastSegments(1);
String featurePropertiesFile = featureDir.toOSString()
- + "/feature.properties";
+ + "/feature.properties";
Properties featureProperties = new Properties();
try {
featureProperties.load(new FileInputStream(featurePropertiesFile));
@@ -96,12 +85,14 @@ public class StubbyGenerator {
*
* @return The generated specfile.
*/
+ @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() + "\n");
+ buffer.append("Name: " + model.getPackageName().toLowerCase()
+ + "\n");
buffer.append("Version: " + model.getVersion() + "\n");
buffer.append("Release: 1%{?dist}" + "\n");
buffer.append("Summary: " + model.getSummary() + "\n\n");
@@ -139,11 +130,13 @@ public class StubbyGenerator {
private void generateFilesSections(StringBuilder buffer) {
buffer.append("%files\n");
buffer.append("%{install_loc}\n");
- String docsRoot = featureFile.getLocation().removeLastSegments(1).lastSegment();
- String[] files = featureFile.getLocation().removeLastSegments(1).toFile().list();
- for (String file :files){
- if (file.matches("(epl-.*|license)\\.html")){
- buffer.append("%doc "+docsRoot+"/"+file+"\n");
+ String docsRoot = featureFile.getLocation().removeLastSegments(1)
+ .lastSegment();
+ String[] files = featureFile.getLocation().removeLastSegments(1)
+ .toFile().list();
+ for (String file : files) {
+ if (file.matches("(epl-.*|license)\\.html")) {
+ buffer.append("%doc " + docsRoot + "/" + file + "\n");
}
}
buffer.append("\n");
@@ -179,61 +172,9 @@ public class StubbyGenerator {
return "eclipse-" + name;
}
- private void throwCoreException(String message) throws CoreException {
- IStatus status = new Status(IStatus.ERROR, StubbyPlugin.PLUGIN_ID,
- IStatus.OK, message, null);
- throw new CoreException(status);
- }
-
private void generateChangelog(StringBuilder buffer) {
buffer.append("%changelog\n\n");
buffer.append("#FIXME\n");
}
- /**
- * Writes the given contents to a file with the given fileName in the
- * specified project.
- *
- * @param projectName
- * The name of the project to put the file into.
- * @throws CoreException
- * Thrown when the project doesn't exist.
- */
- public void writeContent(String projectName) throws CoreException {
- String fileName = model.getPackageName().toLowerCase() + ".spec";
- String contents = generateSpecfile();
- InputStream contentInputStream = new ByteArrayInputStream(
- contents.getBytes());
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IResource resource = root.findMember(new Path(projectName));
- if (!resource.exists() || !(resource instanceof IContainer)) {
- throwCoreException("Project \"" + projectName
- + "\" does not exist.");
- }
- IContainer container = (IContainer) resource;
- final IFile file = container.getFile(new Path(fileName));
- try {
- InputStream stream = contentInputStream;
- if (file.exists()) {
- file.setContents(stream, true, true, null);
- } else {
- file.create(stream, true, null);
- }
- stream.close();
- } catch (IOException e) {
- StubbyLog.logError(e);
- }
- StubbyPlugin.getActiveWorkbenchShell().getDisplay()
- .asyncExec(new Runnable() {
- public void run() {
- IWorkbenchPage page = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- try {
- IDE.openEditor(page, file, true);
- } catch (PartInitException e) {
- StubbyLog.logError(e);
- }
- }
- });
- }
}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPomGenerator.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPomGenerator.java
index 71b712b7ca..3d146c0f93 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPomGenerator.java
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPomGenerator.java
@@ -10,46 +10,37 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.rpmstubby;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.internal.rpmstubby.model.PomModel;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
/**
* Generator for RPM specfile from maven pom.xml.
- *
+ *
*/
-public class StubbyPomGenerator {
+public class StubbyPomGenerator extends AbstractGenerator {
private PomModel model;
/**
* Creates the generator by parsing the pom.xml file.
- * @param pomFile The pom.xml file to generate specfile for.
+ *
+ * @param pomFile
+ * The pom.xml file to generate specfile for.
*/
public StubbyPomGenerator(IFile pomFile) {
parse(pomFile);
+ specfileName = model.getPackageName().toLowerCase() + ".spec";
+ projectName = pomFile.getProject().getName();
}
private void parse(IFile pomFile) {
@@ -74,9 +65,10 @@ public class StubbyPomGenerator {
/**
* Generates a RPM specfile based on the parsed data from the pom file.
- *
+ *
* @return The generated specfile.
*/
+ @Override
public String generateSpecfile() {
StringBuilder buffer = new StringBuilder();
String packageName = model.getPackageName();
@@ -102,11 +94,15 @@ public class StubbyPomGenerator {
}
private void generateRequires(StringBuilder buffer) {
- for (Map.Entry<String,String> entry : model.getDependencies().entrySet()) {
- buffer.append("BuildRequires: mvn("+entry.getKey()+":"+entry.getValue()+")\n");
+ for (Map.Entry<String, String> entry : model.getDependencies()
+ .entrySet()) {
+ buffer.append("BuildRequires: mvn(" + entry.getKey() + ":"
+ + entry.getValue() + ")\n");
}
- for (Map.Entry<String,String> entry : model.getDependencies().entrySet()) {
- buffer.append("Requires: mvn("+entry.getKey()+":"+entry.getValue()+")\n");
+ for (Map.Entry<String, String> entry : model.getDependencies()
+ .entrySet()) {
+ buffer.append("Requires: mvn(" + entry.getKey() + ":"
+ + entry.getValue() + ")\n");
}
}
@@ -130,24 +126,18 @@ public class StubbyPomGenerator {
buffer.append("%install\n");
buffer.append("# jars\n");
buffer.append("install -d -m 0755 %{buildroot}%{_javadir}\n");
- buffer
- .append("install -m 644 target/%{name}-%{version}.jar %{buildroot}%{_javadir}/%{name}.jar\n\n");
-
+ buffer.append("install -m 644 target/%{name}-%{version}.jar %{buildroot}%{_javadir}/%{name}.jar\n\n");
buffer.append("# poms\n");
- buffer
- .append("install -d -m 755 %{buildroot}%{_mavenpomdir}\n");
+ buffer.append("install -d -m 755 %{buildroot}%{_mavenpomdir}\n");
buffer.append("install -pm 644 pom.xml \\\n");
- buffer
- .append(" %{buildroot}%{_mavenpomdir}/JPP.%{name}.pom\n\n");
+ buffer.append(" %{buildroot}%{_mavenpomdir}/JPP.%{name}.pom\n\n");
buffer.append("%add_maven_depmap JPP.%{name}.pom %{name}.jar\n\n");
-
+
buffer.append("# javadoc\n");
- buffer
- .append("install -d -m 0755 %{buildroot}%{_javadocdir}/%{name}\n");
- buffer
- .append("cp -pr target/site/api*/* %{buildroot}%{_javadocdir}/%{name}/\n");
+ buffer.append("install -d -m 0755 %{buildroot}%{_javadocdir}/%{name}\n");
+ buffer.append("cp -pr target/site/api*/* %{buildroot}%{_javadocdir}/%{name}/\n");
buffer.append("rm -rf target/site/api*\n\n");
}
@@ -173,56 +163,4 @@ public class StubbyPomGenerator {
buffer.append(" install javadoc:javadoc\n\n");
}
- /**
- * Writes the given contents to a file with the given fileName in the
- * specified project.
- *
- * @param projectName
- * The name of the project to put the file into.
- * @throws CoreException
- * Thrown when the project doesn't exist.
- */
- public void writeContent(String projectName) throws CoreException {
- String fileName = model.getPackageName().toLowerCase() + ".spec";
- String contents = generateSpecfile();
- InputStream contentInputStream = new ByteArrayInputStream(contents
- .getBytes());
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IResource resource = root.findMember(new Path(projectName));
- if (!resource.exists() || !(resource instanceof IContainer)) {
- throwCoreException("Project \"" + projectName
- + "\" does not exist.");
- }
- IContainer container = (IContainer) resource;
- final IFile file = container.getFile(new Path(fileName));
- try {
- InputStream stream = contentInputStream;
- if (file.exists()) {
- file.setContents(stream, true, true, null);
- } else {
- file.create(stream, true, null);
- }
- stream.close();
- } catch (IOException e) {
- StubbyLog.logError(e);
- }
- StubbyPlugin.getActiveWorkbenchShell().getDisplay().asyncExec(
- new Runnable() {
- public void run() {
- IWorkbenchPage page = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- try {
- IDE.openEditor(page, file, true);
- } catch (PartInitException e) {
- StubbyLog.logError(e);
- }
- }
- });
- }
-
- private void throwCoreException(String message) throws CoreException {
- IStatus status = new Status(IStatus.ERROR, StubbyPlugin.PLUGIN_ID,
- IStatus.OK, message, null);
- throw new CoreException(status);
- }
}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/Generator.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/Generator.java
index 6be1708e93..13aa7c4d0d 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/Generator.java
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/Generator.java
@@ -12,8 +12,8 @@
package org.eclipse.linuxtools.rpmstubby;
import org.eclipse.core.resources.IFile;
-import org.eclipse.linuxtools.internal.rpmstubby.SpecfilePomWriter;
-import org.eclipse.linuxtools.internal.rpmstubby.SpecfileWriter;
+import org.eclipse.linuxtools.internal.rpmstubby.StubbyGenerator;
+import org.eclipse.linuxtools.internal.rpmstubby.StubbyPomGenerator;
/**
* Utility API for stubifying spec files for different input types.
@@ -42,10 +42,10 @@ public class Generator {
public void generate(IFile file) {
switch (type) {
case ECLIPSE_FEATURE:
- new SpecfileWriter().write(file);
+ new StubbyGenerator(file).writeContent();
break;
case MAVEN_POM:
- new SpecfilePomWriter().write(file);
+ new StubbyPomGenerator(file).writeContent();
break;
default:
break;

Back to the top