diff options
8 files changed, 149 insertions, 3 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java index 9fdc848cc7..c693689855 100644 --- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java @@ -31,9 +31,11 @@ import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants; import org.eclipse.linuxtools.rpm.createrepo.IRepoFileConstants; import org.eclipse.linuxtools.rpm.createrepo.tests.ICreaterepoTestConstants; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.junit.After; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -70,6 +72,18 @@ public class CreaterepoWizardTest { } /** + * Focus on main eclipse platform shell before continue SWTBot tests. + */ + @Before + public void setUp() { + try { + bot.shell(ICreaterepoTestConstants.MAIN_SHELL).activate(); + } catch (WidgetNotFoundException e) { + // cannot activate main shell, continue anyways + } + } + + /** * Delete the project and its contents for each test itereation. * * @throws CoreException diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java index ce13ae0b75..8ee235dbfa 100644 --- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java @@ -31,10 +31,12 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.internal.rpm.createrepo.Createrepo; import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject; import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProjectCreator; import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils; import org.junit.After; +import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -205,8 +207,11 @@ public class CreaterepoProjectTest { public void testSimpleExecute() throws CoreException { CreaterepoProject createrepoProject = new CreaterepoProject(project); assertTrue(!createrepoProject.getContentFolder().exists()); - IStatus status = createrepoProject.createrepo(CreaterepoUtils.findConsole("test").newMessageStream()); //$NON-NLS-1$ + // assume that there is creatrepo version of >= 0.9.8 + IStatus validVersion = Createrepo.isCorrectVersion(CreaterepoUtils.findConsole("test").newMessageStream()); //$NON-NLS-1$ + Assume.assumeTrue(validVersion.isOK()); + IStatus status = createrepoProject.createrepo(CreaterepoUtils.findConsole("test").newMessageStream()); //$NON-NLS-1$ // check if executing has an OK status and that content folder is created with the repodata contents assertEquals(Status.OK_STATUS, status); assertTrue(createrepoProject.getContentFolder().exists()); diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java index 2b6d4908e5..f6d0f3b78f 100644 --- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java @@ -19,6 +19,7 @@ public interface ICreaterepoTestConstants { /* * Dialog specific stuff */ + String MAIN_SHELL = "Resource - Eclipse Platform"; //$NON-NLS-1$ String FILE = "File"; //$NON-NLS-1$ String NEW = "New"; //$NON-NLS-1$ String OTHER = "Other..."; //$NON-NLS-1$ 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 3979ba7794..abf316f821 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 @@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.rpm.createrepo; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.eclipse.core.runtime.CoreException; @@ -70,6 +71,10 @@ public class Createrepo { if (!available.isOK()) { return available; } + IStatus validVersion = isCorrectVersion(os); + if (!validVersion.isOK()) { + return validVersion; + } commandSwitches.addAll(commands); commandSwitches.add(project.getContentFolder().getLocation().toOSString()); /* Display what the execution looks like */ @@ -99,7 +104,7 @@ public class Createrepo { */ public static IStatus checkIfAvailable(final OutputStream os) throws CoreException { try { - BufferedProcessInputStream bpis = Utils.runCommandToInputStream("which", "createrepo"); //$NON-NLS-1$ //$NON-NLS-2$ + BufferedProcessInputStream bpis = Utils.runCommandToInputStream("which", ICreaterepoConstants.CREATEREPO_COMMAND); //$NON-NLS-1$ // error executing "which createrepo", most likely due to it not being found if (bpis.getExitValue() == 1) { return new Status(IStatus.ERROR, @@ -123,4 +128,109 @@ public class Createrepo { } } + /** + * Grab the version of the system's createrepo command and if it + * is >= 0.9.8 and also has a yum version >= 3.2.23, then program + * can continue on executing. + * + * 0.9.8 = latest development release + * requires: yum version >= 3.2.23 + * + * @return True if version is supported, false otherwise. + * @throws CoreException Occurs when failure to get version number. + */ + public static IStatus isCorrectVersion(final OutputStream os) throws CoreException { + final String CREATEREPO_VALID_VERSION = "0.9.8"; //$NON-NLS-1$ + final String YUM_VALID_VERSION = "3.2.23"; //$NON-NLS-1$ + String createrepoVersion = ICreaterepoConstants.EMPTY_STRING; + String yumVersion = ICreaterepoConstants.EMPTY_STRING; + try { + String repoOutput = Utils.runCommandToString(ICreaterepoConstants.CREATEREPO_COMMAND, "--version").trim(); //$NON-NLS-1$ + // createrepo --version output is like: + // createrepo x.x.x + String[] createrepoTemp = repoOutput.split(" "); //$NON-NLS-1$ + if (createrepoTemp.length > 1) { + createrepoVersion = createrepoTemp[1]; + } + boolean createrepoValid = isGreaterOrEqual(createrepoVersion.split("\\."), CREATEREPO_VALID_VERSION.split("\\.")); //$NON-NLS-1$ //$NON-NLS-2$ + // exit return an error early if the version does not meet the requirements + if (!createrepoValid) { + return new Status( + IStatus.ERROR, + FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(), + NLS.bind(Messages.Createrepo_errorWrongVersionCreaterepo, new String[] { + CREATEREPO_VALID_VERSION, createrepoVersion}), + null); + } + String yumOutput = Utils.runCommandToString("yum", "--version").trim(); //$NON-NLS-1$ //$NON-NLS-2$ + // yum --version output is like: + // x.x.x + // blah... + // blah... + String[] yumTemp = yumOutput.split("\n"); //$NON-NLS-1$ + if (yumTemp.length > 0) { + yumVersion = yumTemp[0]; + } + boolean yumValid = isGreaterOrEqual(yumVersion.split("\\."), YUM_VALID_VERSION.split("\\.")); //$NON-NLS-1$ //$NON-NLS-2$ + if (yumValid) { + // return an OK status only if yum is valid version + return new Status( + IStatus.OK, + FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(), + ICreaterepoConstants.EMPTY_STRING, null); + } else { + // return an error status otherwise stating the versions in the message + return new Status( + IStatus.ERROR, + FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(), + NLS.bind(Messages.Createrepo_errorWrongVersionYum, new String[] { + YUM_VALID_VERSION, yumVersion}), null); + } + } catch (IOException e) { + IStatus status = new Status( + IStatus.CANCEL, + FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(), + Messages.Createrepo_errorCancelled, null); + throw new CoreException(status); + } catch (ArrayIndexOutOfBoundsException e) { + IStatus status = new Status( + IStatus.ERROR, + FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(), + NLS.bind(Messages.Createrepo_errorPasingVersion, new String[] {createrepoVersion, yumVersion}), null); + throw new CoreException(status); + } + } + + /** + * Go through the version and compare if the current version passed is + * greater or equal to the minimum version required. Assumes left-most + * value is higher priority than right-most. + * + * The minimum should always follow a x.x.x version format, the current can + * be x or x.x or x.x.x + * + * @param current Current version to check. + * @param minimum The minimum version to pass. + * @return True if the current version is higher or equal to the minimum version. + */ + private static boolean isGreaterOrEqual(String[] current, String[] minimum) { + if (current.length > 0) { + try { + int iCurrent = Integer.parseInt(current[0]); + int iMinimum = minimum.length == 0 ? 0 : Integer.parseInt(minimum[0]); + if (iCurrent > iMinimum || (current.length == 1 && iCurrent == iMinimum)) { + return true; + } else if (iCurrent == iMinimum && current.length > 1){ + return isGreaterOrEqual(Arrays.copyOfRange(current, 1, current.length), + Arrays.copyOfRange(minimum, 1, minimum.length)); + } else { + return false; + } + } catch (NumberFormatException e) { + return false; + } + } + return false; + } + } 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 5dacf44630..4780a056e1 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 @@ -80,6 +80,14 @@ public final class Messages { public static String Createrepo_errorTryingToFindCommand; /****/ public static String Createrepo_errorCommandNotFound; + /****/ + public static String Createrepo_errorWrongVersionCreaterepo; + /****/ + public static String Createrepo_errorWrongVersionYum; + /****/ + public static String Createrepo_errorCancelled; + /****/ + public static String Createrepo_errorPasingVersion; // 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 d2c7b1e455..af653e2ecb 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 @@ -47,6 +47,12 @@ 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. +Createrepo_errorWrongVersionCreaterepo=Required createrepo version: {0}, current version in system: {1} +Createrepo_errorWrongVersionYum=Required yum version: {0}, current version in system: {1} +Createrepo_errorCancelled=Cancelled while trying to get version number. +Createrepo_errorPasingVersion=Error occured while trying to get the version.\n\ + Createrepo output: {0}\n\ + Yum output: {1} # 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 3fc85c4e8b..25e24e023a 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 @@ -104,7 +104,7 @@ public class CreaterepoProject { private void createContentFolder() throws CoreException { content = getProject().getFolder(ICreaterepoConstants.CONTENT_FOLDER); if (!content.exists()) { - content.create(false, true, monitor); + content.create(true, true, monitor); } } diff --git a/rpm/pom.xml b/rpm/pom.xml index c274bae475..4520170db9 100644 --- a/rpm/pom.xml +++ b/rpm/pom.xml @@ -49,6 +49,8 @@ <module>org.eclipse.linuxtools.rpm.ui.editor.doc</module> <module>org.eclipse.linuxtools.rpm.ui.editor.tests</module> <module>org.eclipse.linuxtools.rpmstubby</module> + <module>org.eclipse.linuxtools.rpm.createrepo</module> + <module>org.eclipse.linuxtools.rpm.createrepo.tests</module> </modules> </project> |