aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-12-05 09:25:35 (EST)
committerAlexander Kurtakov2013-12-05 10:43:40 (EST)
commitac8df23dfb9589e89da50858261b9dfc7160d131 (patch)
tree0ab7270c4d2714a965e21ea6ac8132f9ccd5749d
parent8c9437b66ca8147a085e1d3c95dac0e074228a35 (diff)
downloadorg.eclipse.linuxtools-ac8df23dfb9589e89da50858261b9dfc7160d131.zip
org.eclipse.linuxtools-ac8df23dfb9589e89da50858261b9dfc7160d131.tar.gz
org.eclipse.linuxtools-ac8df23dfb9589e89da50858261b9dfc7160d131.tar.bz2
RPM: createrepo execute commandrefs/changes/86/19086/5
Added functionality to the execute button on the Import RPMs page and to the execute button at the top of the form pages. The default call to the execute command would simply be the createrepo command executing on the content folder, e.g.: "createrepo /path/to/project/content" It calls the RPM Utils.runCommand(...) to execute createrepo. Further implementation will grab command line arguments from the project preferences. Change-Id: Ic20f6a74cd0eeccce911fac6e8510e638010ee54 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/19086 Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> IP-Clean: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/META-INF/MANIFEST.MF3
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/plugin.xml7
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Createrepo.java69
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java2
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java8
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/handler/CreaterepoExecuteCommandHandler.java71
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties1
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java28
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java7
9 files changed, 189 insertions, 7 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/META-INF/MANIFEST.MF b/rpm/org.eclipse.linuxtools.rpm.createrepo/META-INF/MANIFEST.MF
index 0d28958..e3e343a 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/META-INF/MANIFEST.MF
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ui.editors;bundle-version="3.8.100",
org.eclipse.ui.forms;bundle-version="3.6.1",
org.eclipse.ui.console;bundle-version="3.5.200",
- org.eclipse.core.resources
+ org.eclipse.core.resources,
+ org.eclipse.linuxtools.rpm.core
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/plugin.xml b/rpm/org.eclipse.linuxtools.rpm.createrepo/plugin.xml
index 40c2110..947cc8d 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/plugin.xml
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/plugin.xml
@@ -69,4 +69,11 @@
name="%execute.command">
</command>
</extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.linuxtools.internal.rpm.createrepo.handler.CreaterepoExecuteCommandHandler"
+ commandId="org.eclipse.linuxtools.rpm.createrepo.executeCommand">
+ </handler>
+ </extension>
</plugin>
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Createrepo.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Createrepo.java
new file mode 100644
index 0000000..246d948
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Createrepo.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.createrepo;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.rpm.core.utils.Utils;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * This class will execute the actual createrepo command.
+ */
+public class Createrepo {
+
+ /**
+ * Holds the command line switches.
+ */
+ private List<String> commandSwitches;
+
+ /**
+ * Initialize the command switches to only be "createrepo".
+ */
+ public Createrepo() {
+ commandSwitches = new ArrayList<String>();
+ commandSwitches.add(ICreaterepoConstants.CREATEREPO_COMMAND);
+ }
+
+ /**
+ * Execute a createrepo command with custom arguments. The target directory
+ * will always be the current project's content folder and will automatically be
+ * added before execution. A blank list will result in the default createrepo execution.
+ *
+ * @param os Direct execution stream to this.
+ * @param project The project.
+ * @param commands A list of command switches to execute with the createrepo command.
+ * @return The status of the execution.
+ * @throws CoreException Occurs when error trying to execute the command.
+ */
+ public IStatus execute(final OutputStream os, CreaterepoProject project, List<String> commands) throws CoreException {
+ commandSwitches.addAll(commands);
+ commandSwitches.add(project.getContentFolder().getLocation().toOSString());
+ try {
+ return Utils.runCommand(os, project.getProject(), commandSwitches.toArray(new String[commandSwitches.size()]));
+ } catch (IOException e) {
+ IStatus status = new Status(
+ IStatus.ERROR,
+ FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(),
+ Messages.Createrepo_errorExecuting, null);
+ throw new CoreException(status);
+ }
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
index 4a77328..bb859b8 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
@@ -66,6 +66,8 @@ public final class Messages {
// Createrepo
/****/
public static String Createrepo_jobName;
+ /****/
+ public static String Createrepo_errorExecuting;
// RepoFormEditor
/****/
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
index 18bce2c..7f68fad 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
@@ -24,7 +24,6 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
@@ -359,12 +358,13 @@ public class ImportRPMsPage extends FormPage implements IResourceChangeListener
monitor.beginTask(Messages.CreaterepoProject_executeCreaterepo, IProgressMonitor.UNKNOWN);
MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName)
.newMessageStream();
- String message = "Createrepo functionality to be implemented when clicking this button"; //$NON-NLS-1$
- os.print(message);
- return new Status(IStatus.OK, Activator.PLUGIN_ID, message);
+ return project.createrepo(os);
+ } catch (CoreException e) {
+ Activator.logError(Messages.Createrepo_errorExecuting, e);
} finally {
monitor.done();
}
+ return null;
}
};
executeCreaterepo.setUser(true);
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/handler/CreaterepoExecuteCommandHandler.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/handler/CreaterepoExecuteCommandHandler.java
new file mode 100644
index 0000000..36949cf
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/handler/CreaterepoExecuteCommandHandler.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.createrepo.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils;
+import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.console.MessageConsoleStream;
+import org.eclipse.ui.ide.ResourceUtil;
+
+public class CreaterepoExecuteCommandHandler extends AbstractHandler {
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ try {
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchPage wbPage = wb.getActiveWorkbenchWindow().getActivePage();
+ IEditorInput editorInput = wbPage.getActiveEditor().getEditorInput();
+ IResource resource = ResourceUtil.getResource(editorInput);
+ final CreaterepoProject project = new CreaterepoProject(resource.getProject());
+ Job executeCreaterepo = new Job(Messages.Createrepo_jobName) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ monitor.beginTask(Messages.CreaterepoProject_executeCreaterepo, IProgressMonitor.UNKNOWN);
+ MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName)
+ .newMessageStream();
+ return project.createrepo(os);
+ } catch (CoreException e) {
+ Activator.logError(Messages.Createrepo_errorExecuting, e);
+ } finally {
+ monitor.done();
+ }
+ return null;
+ }
+ };
+ executeCreaterepo.setUser(true);
+ executeCreaterepo.schedule();
+ } catch (CoreException e) {
+ Activator.logError(Messages.CreaterepoProject_executeCreaterepo, e);
+ }
+ return null;
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
index 70c14e1..a61b720 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
@@ -40,6 +40,7 @@ CreaterepoProject_consoleName=Createrepo Console
# Createrepo
Createrepo_jobName=Create repository
+Createrepo_errorExecuting=Error executing the createrepo command: {0}
# RepoFormEditor
RepoFormEditor_errorInitializingForm=Error while trying to initialize the form page.
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
index 0fbfb5e..70f3c9e 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.rpm.createrepo;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -29,6 +30,7 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Createrepo;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
import org.osgi.framework.FrameworkUtil;
@@ -132,6 +134,20 @@ public class CreaterepoProject {
}
/**
+ * Execute the createrepo command.
+ *
+ * @param os Direct execution stream to this.
+ * @return The status of the execution.
+ * @throws CoreException Thrown when failure to execute command.
+ */
+ public IStatus createrepo(OutputStream os) throws CoreException {
+ Createrepo createrepo = new Createrepo();
+ IStatus result = createrepo.execute(os, this, getCommandArguments());
+ getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ return result;
+ }
+
+ /**
* Get the project.
*
* @return The project.
@@ -186,4 +202,16 @@ public class CreaterepoProject {
return projectPreferences;
}
+ /**
+ * Get the command arguments to pass to the createrepo command. The
+ * arguments come from the stored preferences from the preference page
+ * and the project preferences.
+ *
+ * @return The command arguments.
+ */
+ private static List<String> getCommandArguments() {
+ List<String> commands = new ArrayList<String>();
+ return commands;
+ }
+
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java
index 1e1f8fb..f7f9ed3 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.linuxtools.rpm.createrepo;
-
-
/**
* Common constants used in createrepo.
*/
@@ -43,4 +41,9 @@ public interface ICreaterepoConstants {
*/
String EMPTY_STRING = ""; //$NON-NLS-1$
+ /**
+ * The main createrepo command name.
+ */
+ String CREATEREPO_COMMAND = "createrepo"; //$NON-NLS-1$
+
}