Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2011-08-09 06:47:18 -0400
committerAlexander Kurtakov2011-08-09 06:47:18 -0400
commitdd20fb2ce40e172aad859741e8eebd4cbc48c563 (patch)
treeff97baeec7da1f05d7dea5f9666cf42d59425f30 /rpmstubby
parent1a45eb1d805ad282005bc7d8c85fc72a184be9f6 (diff)
downloadorg.eclipse.linuxtools-dd20fb2ce40e172aad859741e8eebd4cbc48c563.tar.gz
org.eclipse.linuxtools-dd20fb2ce40e172aad859741e8eebd4cbc48c563.tar.xz
org.eclipse.linuxtools-dd20fb2ce40e172aad859741e8eebd4cbc48c563.zip
Define a small public API.
Additionally redo the commands handler in a way to simplify it significantly and makin use of this API.
Diffstat (limited to 'rpmstubby')
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF1
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml4
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyFeatureHandler.java26
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyHandler.java (renamed from rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyFeatureAction.java)18
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyPomAction.java57
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyPomHandler.java26
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/Generator.java55
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/InputType.java40
8 files changed, 161 insertions, 66 deletions
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF b/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
index ee142c4b3a..f796630410 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
@@ -16,3 +16,4 @@ Require-Bundle: org.eclipse.ui,
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.linuxtools.rpmstubby
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml b/rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml
index dfecb4ba9d..a7e194e3c7 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml
@@ -47,11 +47,11 @@
<extension
point="org.eclipse.ui.handlers">
<handler
- class="org.eclipse.linuxtools.internal.rpmstubby.popup.actions.StubifyFeatureAction"
+ class="org.eclipse.linuxtools.internal.rpmstubby.popup.actions.StubifyFeatureHandler"
commandId="rpmstubby.stubifyFeature">
</handler>
<handler
- class="org.eclipse.linuxtools.internal.rpmstubby.popup.actions.StubifyPomAction"
+ class="org.eclipse.linuxtools.internal.rpmstubby.popup.actions.StubifyPomHandler"
commandId="rpmstubby.stubifyPom">
</handler>
</extension>
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyFeatureHandler.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyFeatureHandler.java
new file mode 100644
index 0000000000..562438cd32
--- /dev/null
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyFeatureHandler.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Alexander Kurtakov - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpmstubby.popup.actions;
+
+import org.eclipse.linuxtools.rpmstubby.InputType;
+
+/**
+ * Handler for the feature.xml stubify command.
+ *
+ */
+public class StubifyFeatureHandler extends StubifyHandler {
+
+ @Override
+ protected InputType getInputType() {
+ return InputType.ECLIPSE_FEATURE;
+ }
+
+}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyFeatureAction.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyHandler.java
index 530b9f3d69..14ffae3ac9 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyFeatureAction.java
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyHandler.java
@@ -17,15 +17,18 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.linuxtools.internal.rpmstubby.SpecfileWriter;
+import org.eclipse.linuxtools.rpmstubby.Generator;
+import org.eclipse.linuxtools.rpmstubby.InputType;
import org.eclipse.ui.handlers.HandlerUtil;
/**
- * Action handling stybifying RPM spec file from a Eclipse feature.xml file.
- *
+ * Common functionality for all the stubify commands.
+ *
*/
-public class StubifyFeatureAction extends AbstractHandler {
-
+public abstract class StubifyHandler extends AbstractHandler {
+
+ protected abstract InputType getInputType();
+
public Object execute(ExecutionEvent event) {
IFile featureFile = null;
@@ -39,11 +42,12 @@ public class StubifyFeatureAction extends AbstractHandler {
.getAdapter(IFile.class);
}
if (featureFile != null) {
- SpecfileWriter specfileWriter = new SpecfileWriter();
- specfileWriter.write(featureFile);
+ Generator generator = new Generator(getInputType());
+ generator.generate(featureFile);
}
}
}
return null;
}
+
}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyPomAction.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyPomAction.java
deleted file mode 100644
index 909b4bcf9f..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyPomAction.java
+++ /dev/null
@@ -1,57 +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.popup.actions;
-/*******************************************************************************
- * Copyright (c) 2011 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:
- * Alexander Kurtakov - initial API and implementation
- *******************************************************************************/
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.linuxtools.internal.rpmstubby.SpecfilePomWriter;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * Action handling stybifying RPM spec file from a Maven pom.xml file.
- *
- */
-public class StubifyPomAction extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) {
- IFile pomFile = null;
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- for (Object element : ((IStructuredSelection) selection).toList()) {
- if (element instanceof IFile) {
- pomFile = (IFile) element;
- } else if (element instanceof IAdaptable) {
- pomFile = (IFile) ((IAdaptable) element)
- .getAdapter(IFile.class);
- }
- if (pomFile != null) {
- SpecfilePomWriter specfileWriter = new SpecfilePomWriter();
- specfileWriter.write(pomFile);
- }
- }
- }
- return null;
- }
-
-}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyPomHandler.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyPomHandler.java
new file mode 100644
index 0000000000..f31bcf97b0
--- /dev/null
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/popup/actions/StubifyPomHandler.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Alexander Kurtakov - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpmstubby.popup.actions;
+
+import org.eclipse.linuxtools.rpmstubby.InputType;
+
+/**
+ * Handler for the pom stubify command.
+ *
+ */
+public class StubifyPomHandler extends StubifyHandler {
+
+ @Override
+ protected InputType getInputType() {
+ return InputType.MAVEN_POM;
+ }
+
+}
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
new file mode 100644
index 0000000000..6be1708e93
--- /dev/null
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/Generator.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat Inc. and others.
+ * 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:
+ * Alexander Kurtakov - initial API and implementation
+ *******************************************************************************/
+
+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;
+
+/**
+ * Utility API for stubifying spec files for different input types.
+ *
+ */
+public class Generator {
+
+ private InputType type;
+
+ /**
+ * Creates the generator for the given input type.
+ *
+ * @param type
+ * The input type for this generator.
+ */
+ public Generator(InputType type) {
+ this.type = type;
+ }
+
+ /**
+ * Generate the spec file for the given input file.
+ *
+ * @param file
+ * The input file.
+ */
+ public void generate(IFile file) {
+ switch (type) {
+ case ECLIPSE_FEATURE:
+ new SpecfileWriter().write(file);
+ break;
+ case MAVEN_POM:
+ new SpecfilePomWriter().write(file);
+ break;
+ default:
+ break;
+ }
+ }
+
+}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/InputType.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/InputType.java
new file mode 100644
index 0000000000..9c383517d4
--- /dev/null
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/InputType.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Alexander Kurtakov - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.rpmstubby;
+
+/**
+ * Supported input types and file name patterns for the corresponding files.
+ *
+ */
+public enum InputType {
+
+ /** Eclipse feature.xml file. */
+ ECLIPSE_FEATURE("feature.xml"),
+ /** Maven pom.xml file. */
+ MAVEN_POM("pom.xml");
+
+ private String fileNamePattern;
+
+ private InputType(String fileName) {
+ this.fileNamePattern = fileName;
+ }
+
+ /**
+ * Returns the file name pattern for the input type.
+ *
+ * @return The pattern for the file name e.g. feature.xml or pom.xml.
+ */
+ public String getFileNamePattern() {
+ return fileNamePattern;
+ }
+
+}

Back to the top