aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-12-12 17:33:20 (EST)
committerAlexander Kurtakov2013-12-13 02:41:39 (EST)
commit0b1a3c2b8e7109705deb5489a3665bab29b2664b (patch)
tree1dfb2dccf95c74b41f473bf81f07a0aa3855a144
parentde62d5de57b6c91601e654dc3eb5be01bc4dd4d8 (diff)
downloadorg.eclipse.linuxtools-0b1a3c2b8e7109705deb5489a3665bab29b2664b.zip
org.eclipse.linuxtools-0b1a3c2b8e7109705deb5489a3665bab29b2664b.tar.gz
org.eclipse.linuxtools-0b1a3c2b8e7109705deb5489a3665bab29b2664b.tar.bz2
RPM: createrepo check for commandrefs/changes/37/19737/2
Do not do any of the execution code if createrepo command was not found. Change-Id: Ie78c2fb1d2659a47987dfbc56f5a586b79f635ad Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/19737 Tested-by: Hudson CI 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/src/org/eclipse/linuxtools/internal/rpm/createrepo/Createrepo.java41
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java6
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties5
3 files changed, 50 insertions, 2 deletions
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
index d1c02b7..3979ba7 100644
--- 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
@@ -18,10 +18,12 @@ 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.BufferedProcessInputStream;
import org.eclipse.linuxtools.rpm.core.utils.Utils;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoPreferenceConstants;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
+import org.eclipse.osgi.util.NLS;
import org.osgi.framework.FrameworkUtil;
/**
@@ -64,6 +66,10 @@ public class Createrepo {
* @throws CoreException Occurs when error trying to execute the command.
*/
public IStatus execute(final OutputStream os, CreaterepoProject project, List<String> commands) throws CoreException {
+ IStatus available = checkIfAvailable(os);
+ if (!available.isOK()) {
+ return available;
+ }
commandSwitches.addAll(commands);
commandSwitches.add(project.getContentFolder().getLocation().toOSString());
/* Display what the execution looks like */
@@ -79,7 +85,40 @@ public class Createrepo {
IStatus status = new Status(
IStatus.ERROR,
FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(),
- Messages.Createrepo_errorExecuting, null);
+ NLS.bind(Messages.Createrepo_errorExecuting, commandString), null);
+ throw new CoreException(status);
+ }
+ }
+
+ /**
+ * Check if the createrepo command is available in the system.
+ *
+ * @param os The outputstream to place the messages.
+ * @return The status of whether or not createrepo was found.
+ * @throws CoreException Occurs when createrepo is not found or executing the command failed.
+ */
+ public static IStatus checkIfAvailable(final OutputStream os) throws CoreException {
+ try {
+ BufferedProcessInputStream bpis = Utils.runCommandToInputStream("which", "createrepo"); //$NON-NLS-1$ //$NON-NLS-2$
+ // error executing "which createrepo", most likely due to it not being found
+ if (bpis.getExitValue() == 1) {
+ return new Status(IStatus.ERROR,
+ FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(),
+ Messages.Createrepo_errorCommandNotFound, null);
+ }
+ return new Status(IStatus.OK, FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(),
+ ICreaterepoConstants.EMPTY_STRING, null);
+ } catch (IOException e) {
+ IStatus status = new Status(
+ IStatus.WARNING,
+ FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(),
+ Messages.Createrepo_errorTryingToFindCommand, null);
+ throw new CoreException(status);
+ } catch (InterruptedException e) {
+ IStatus status = new Status(
+ IStatus.CANCEL,
+ FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(),
+ Messages.Createrepo_jobCancelled, 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 4838e7c..1d13bd0 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
@@ -67,7 +67,13 @@ public final class Messages {
/****/
public static String Createrepo_jobName;
/****/
+ public static String Createrepo_jobCancelled;
+ /****/
public static String Createrepo_errorExecuting;
+ /****/
+ public static String Createrepo_errorTryingToFindCommand;
+ /****/
+ public static String Createrepo_errorCommandNotFound;
// RepoFormEditor
/****/
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 cff4350..c1da0f6 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,7 +40,10 @@ CreaterepoProject_consoleName=Createrepo Console
# Createrepo
Createrepo_jobName=Create repository
-Createrepo_errorExecuting=Error executing the createrepo command: {0}
+Createrepo_jobCancelled=Job was cancelled.
+Createrepo_errorExecuting=Error executing: {0}
+Createrepo_errorTryingToFindCommand=Error occured trying to find the createrepo command.
+Createrepo_errorCommandNotFound=Createrepo command not found.
# RepoFormEditor
RepoFormEditor_errorInitializingForm=Error while trying to initialize the form page.