aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-06-20 13:04:40 (EDT)
committerAlexander Kurtakov2013-07-09 15:53:43 (EDT)
commit425cbaf44f604482455bb6456a2f2e84f51089d0 (patch)
tree54e2c1035756ad39680641fd379776f2cdd82aeb
parent50a2ab8f883f23adbb146f23ef1061f61e4adc41 (diff)
downloadorg.eclipse.linuxtools-425cbaf44f604482455bb6456a2f2e84f51089d0.zip
org.eclipse.linuxtools-425cbaf44f604482455bb6456a2f2e84f51089d0.tar.gz
org.eclipse.linuxtools-425cbaf44f604482455bb6456a2f2e84f51089d0.tar.bz2
RPM: evaluate %{?...} macrosrefs/changes/61/13961/14
%{?...} macros will be evaluated using RPMQuery.eval(...), but resolveEval(...) will stay for future use. Amend1: added test Amend2: used SpecfileLog to log error, rather than print to console Amend2: changed from evaluate everything to evaluate some things Amend3: removed evald functions Change-Id: I500f4cd2682404b4826cf7cae20a69287fc959d0 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/13961 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.core.tests/src/org/eclipse/linuxtools/rpm/core/utils/tests/RPMQueryTest.java40
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/parser/SpecfileDefineTest.java10
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF4
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java2
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileLabelProvider.java43
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileElement.java32
6 files changed, 105 insertions, 26 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/utils/tests/RPMQueryTest.java b/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/utils/tests/RPMQueryTest.java
index ea3134a..3014e1b 100644
--- a/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/utils/tests/RPMQueryTest.java
+++ b/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/utils/tests/RPMQueryTest.java
@@ -18,16 +18,46 @@ import org.junit.Test;
public class RPMQueryTest {
+ private static final String[] testWrongNVRs = {
+ "%{?scl_prefix}eclipse-jgit-3.0.0-1.fc20",
+ "%{?scl_prefix}eclipse-egit-2.3.1-1.fc20",
+ "eclipse-egit-github-2.3.0-5.fc20",
+ "eclipse-fedorapackager-0.4.1-6.fc20",
+ "%{?scl_prefix}eclipse-jgit-3.0.0-1.fc20",
+ "fedora-packager-0.5.10.1-3.fc20"
+ };
+
+ private static final String[] testCorrectNVRs = {
+ "eclipse-jgit-3.0.0-1.fc20",
+ "eclipse-egit-2.3.1-1.fc20",
+ "eclipse-egit-github-2.3.0-5.fc20",
+ "eclipse-fedorapackager-0.4.1-6.fc20",
+ "eclipse-jgit-3.0.0-1.fc20",
+ "fedora-packager-0.5.10.1-3.fc20"
+ };
+
@Test
public void testEval() throws CoreException {
- //check eval for string without macro
+ // check eval for string without macro
assertEquals("should be same", RPMQuery.eval("should be same").trim());
- //check eval for macro only
+ // check eval for macro only
assertEquals("/usr/share", RPMQuery.eval("%{_datadir}").trim());
- //check eval for macro and string
- assertEquals("/usr/share/eclipse", RPMQuery.eval("%{_datadir}/eclipse").trim());
- //check eval for conditional undefined macro
+ // check eval for macro and string
+ assertEquals("/usr/share/eclipse", RPMQuery.eval("%{_datadir}/eclipse")
+ .trim());
+ // check eval for conditional undefined macro
assertEquals("eclipse", RPMQuery.eval("%{?scl_prefix}eclipse").trim());
}
+ // Test evaluating NVRs when displaying bodhi update dialog
+ @Test
+ public void testNVREval() throws CoreException {
+ String toEval;
+ for (int i = 0; i < testCorrectNVRs.length; i++) {
+ toEval = RPMQuery.eval(testWrongNVRs[i]).trim();
+ assertNotNull(toEval);
+ assertEquals(toEval, testCorrectNVRs[i]);
+ }
+ }
+
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/parser/SpecfileDefineTest.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/parser/SpecfileDefineTest.java
index 8b46ef6..a985439 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/parser/SpecfileDefineTest.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/parser/SpecfileDefineTest.java
@@ -16,6 +16,7 @@ import static org.junit.Assert.fail;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.linuxtools.internal.rpm.ui.editor.UiUtils;
+import org.eclipse.linuxtools.rpm.core.utils.RPMQuery;
import org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler;
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine;
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement;
@@ -132,6 +133,7 @@ public class SpecfileDefineTest extends FileTestCase {
fail();
}
}
+
@Test
public void testUnderscoreDefine() {
SpecfileDefine blahDefine = specfile.getDefine("__find_requires");
@@ -139,10 +141,18 @@ public class SpecfileDefineTest extends FileTestCase {
assertEquals("__find_requires", blahDefine.getName());
assertEquals("%{SOURCE3}", blahDefine.getStringValue());
}
+
@Test
public void testWholeWordResolveDefine() {
String testResolve = UiUtils.resolveDefines(specfile, "%{version}.%{version_suffix}");
assertEquals(testResolve, "2.3.0.201302130906");
}
+ @Test
+ public void testResolveSCLMacro() throws CoreException {
+ String specText = "Name: %{?scl_prefix}eclipse-jgit" + "\n" + "%{name}";
+ newFile(specText);
+ assertEquals("eclipse-jgit", RPMQuery.eval(specfile.getName()).trim());
+ }
+
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF b/rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF
index 2d36c8c..30e999b 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF
@@ -13,12 +13,14 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ui.views,
org.eclipse.core.resources,
org.eclipse.ui.ide,
+ org.eclipse.ui.console,
org.eclipse.linuxtools.changelog.core,
com.ibm.icu,
org.eclipse.ui.forms;bundle-version="3.3.101",
org.eclipse.compare;bundle-version="3.4.0",
org.eclipse.linuxtools.rpm.core,
- org.eclipse.ui.console
+ org.eclipse.ui.console,
+ org.eclipse.equinox.registry
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.linuxtools.rpm.ui.editor,
org.eclipse.linuxtools.rpm.ui.editor.markers,
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java
index c22727d..6f83c83 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java
@@ -68,7 +68,7 @@ public class UiUtils {
while (variableMatcher.find()) {
define = specfile.getDefine(variableMatcher.group(1));
if (define != null) {
- stringToResolve = stringToResolve.replaceAll("\\b"+variableMatcher.group(1)+"\\b", define.getStringValue()); //$NON-NLS-1$//$NON-NLS-2$
+ stringToResolve = stringToResolve.replaceAll("\\b"+variableMatcher.group(1)+"\\b", define.getStringValue()); //$NON-NLS-1$ //$NON-NLS-2$
} else {
return originalString;
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileLabelProvider.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileLabelProvider.java
index 54c8fff..f0bdd34 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileLabelProvider.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileLabelProvider.java
@@ -11,10 +11,13 @@
package org.eclipse.linuxtools.internal.rpm.ui.editor.outline;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.linuxtools.internal.rpm.ui.editor.Activator;
+import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileLog;
import org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePreamble;
+import org.eclipse.linuxtools.rpm.core.utils.RPMQuery;
import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile;
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement;
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage;
@@ -56,24 +59,30 @@ public class SpecfileLabelProvider implements ILabelProvider {
}
public String getText(Object element) {
- if (element instanceof SpecfileSection) {
- SpecfileSection specfileSection = (SpecfileSection) element;
- return specfileSection.toString();
- } else if (element instanceof Specfile) {
- return ((Specfile) element).getName();
- } else if (element instanceof SpecfilePackageContainer) {
- return Messages.SpecfileLabelProvider_0;
- } else if (element instanceof SpecfilePreamble){
- return Messages.SpecfileLabelProvider_1;
- } else if (element instanceof SpecfileElement) {
- SpecfileElement specfileElement = (SpecfileElement) element;
- return specfileElement.getName();
- } else if (element instanceof String) {
- return (String) element;
- } else if (element instanceof SpecfilePackage) {
- return ((SpecfilePackage) element).getName();
+ String str = ""; //$NON-NLS-1$
+ try {
+ if (element instanceof SpecfileSection) {
+ SpecfileSection specfileSection = (SpecfileSection) element;
+ str = specfileSection.toString();
+ } else if (element instanceof Specfile) {
+ str = ((Specfile) element).getName();
+ } else if (element instanceof SpecfilePackageContainer) {
+ str = Messages.SpecfileLabelProvider_0;
+ } else if (element instanceof SpecfilePreamble){
+ str = Messages.SpecfileLabelProvider_1;
+ } else if (element instanceof SpecfileElement) {
+ SpecfileElement specfileElement = (SpecfileElement) element;
+ str = specfileElement.getName();
+ } else if (element instanceof String) {
+ str = (String) element;
+ } else if (element instanceof SpecfilePackage) {
+ str = ((SpecfilePackage) element).getName();
+ }
+ str = RPMQuery.eval(str).trim();
+ } catch (CoreException e) {
+ SpecfileLog.logError("Within Project Outline, unable to evaluate " + str, e); //$NON-NLS-1$
}
- return ""; //$NON-NLS-1$
+ return str;
}
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileElement.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileElement.java
index fddfaed..7ca9947 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileElement.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Red Hat, Inc.
+ * Copyright (c) 2007, 2009, 2013 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
@@ -11,7 +11,10 @@
package org.eclipse.linuxtools.rpm.ui.editor.parser;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileLog;
import org.eclipse.linuxtools.internal.rpm.ui.editor.UiUtils;
+import org.eclipse.linuxtools.rpm.core.utils.RPMQuery;
public class SpecfileElement {
private Specfile specfile;
@@ -75,11 +78,36 @@ public class SpecfileElement {
public String resolve(String toResolve) {
if (specfile == null || toResolve.equals("")) {//$NON-NLS-1$
- if (toResolve.length()>2 && toResolve.substring(2, toResolve.length() - 1).equals(name)) {
+ if (toResolve.length() > 2
+ && toResolve.substring(2, toResolve.length() - 1)
+ .equals(name)) {
return toResolve;
}
}
return UiUtils.resolveDefines(specfile, toResolve);
}
+ /**
+ * Resolve using RPM to evaluate string
+ *
+ * @param toResolve The string to be evaluated
+ * @return The evaluated string
+ */
+ public String resolveEval(String toResolve) {
+ String str = ""; //$NON-NLS-1$
+ try {
+ if (specfile == null || toResolve.equals("")) {//$NON-NLS-1$
+ if (toResolve.length() > 2
+ && toResolve.substring(2, toResolve.length() - 1)
+ .equals(name)) {
+ return toResolve;
+ }
+ }
+ str = RPMQuery.eval(UiUtils.resolveDefines(specfile, toResolve)).trim();
+ } catch (CoreException e) {
+ SpecfileLog.logError("Unable to evaluate " + toResolve, e); //$NON-NLS-1$
+ }
+ return str;
+ }
+
}