Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZeb Ford-Reitz2014-03-20 11:52:58 -0400
committerZeb Ford-Reitz2014-03-20 11:53:13 -0400
commitcef5e49ce049eed2cd2b5c910784c600d48f43a7 (patch)
treefbf89bd75e8db6525b7ff869403f08ab08a8c646 /org.eclipse.jubula.autagent
parent32784a2077f19b3856c2f2384fdd6ea60b071a37 (diff)
downloadorg.eclipse.jubula.core-cef5e49ce049eed2cd2b5c910784c600d48f43a7.tar.gz
org.eclipse.jubula.core-cef5e49ce049eed2cd2b5c910784c600d48f43a7.tar.xz
org.eclipse.jubula.core-cef5e49ce049eed2cd2b5c910784c600d48f43a7.zip
RC: Adds a check to ignore source-bundles when building a classpath.
Since Jubula added source-bundles to the build, it has been impossible to start an AUT from the embedded AUT Agent of an ITE started from the IDE (well that was a mouthful). This bothered me enough to put in a fix for it. Theoretically, this check could be expanded such that only valid JAR files are included, but for now it seems prudent to take a conservative approach: If its a source-bundle JAR, don't include it on the classpath. If *anything* goes wrong while trying to determine whether its a source-bundle JAR, then just include it on the classpath.
Diffstat (limited to 'org.eclipse.jubula.autagent')
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartToolkitAut.java62
1 files changed, 59 insertions, 3 deletions
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartToolkitAut.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartToolkitAut.java
index bc3e79109..b6cccf363 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartToolkitAut.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartToolkitAut.java
@@ -18,6 +18,9 @@ import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
@@ -46,6 +49,13 @@ public abstract class AbstractStartToolkitAut implements IStartAut {
private static Logger log =
LoggerFactory.getLogger(AbstractStartToolkitAut.class);
+ /**
+ * the name of the bundle JAR Manifest Attribute that indicates that the
+ * bundle is a source-bundle
+ */
+ private static final String SOURCE_BUNDLE_MANIFEST_ATTR =
+ "Eclipse-SourceBundle"; //$NON-NLS-1$
+
/**
* the message to send back if the command for starting the AUTServer could
* not created
@@ -312,9 +322,13 @@ public abstract class AbstractStartToolkitAut implements IStartAut {
if (e != null) {
while (e.hasMoreElements()) {
URL jarUrl = e.nextElement();
- classpathEntries.add(
- new File(bundleFile + jarUrl.getFile())
- .getAbsolutePath());
+ File jarFile =
+ new File(bundleFile + jarUrl.getFile());
+ if (!isJarFileWithManifestAttr(
+ jarFile, SOURCE_BUNDLE_MANIFEST_ATTR)) {
+
+ classpathEntries.add(jarFile.getAbsolutePath());
+ }
}
}
}
@@ -327,6 +341,48 @@ public abstract class AbstractStartToolkitAut implements IStartAut {
/**
*
+ * @param file The file to check.
+ * @param manifestAttr The name of the Manifest Attribute to check for.
+ * @return <code>true</code> iff all of the following statements apply:<ul>
+ * <li><code>file</code> is a valid, existing JAR file</li>
+ * <li><code>file</code> has a JAR Manifest</li>
+ * <li><code>file</code>'s JAR Manifest contains an Attribute
+ * named <code>manifestAttr</code></li>
+ * <li>no error occurs while performing the above checks</li>
+ * </ul>
+ */
+ private static boolean isJarFileWithManifestAttr(
+ File file,
+ String manifestAttr) {
+
+ try {
+ JarFile jarFile = new JarFile(file);
+ try {
+ Manifest manifest = jarFile.getManifest();
+ if (manifest != null) {
+ return manifest.getMainAttributes().containsKey(
+ new Attributes.Name(manifestAttr));
+ }
+ } catch (IOException ioe) {
+ log.error("Error while reading JAR file.", ioe); //$NON-NLS-1$
+ } finally {
+ try {
+ jarFile.close();
+ } catch (IOException ioe) {
+ log.error("Error while closing JAR file.", ioe); //$NON-NLS-1$
+ }
+ }
+ } catch (IOException ioe) {
+ log.error("Error while opening JAR file.", ioe); //$NON-NLS-1$
+ } catch (SecurityException se) {
+ log.error("Error while opening JAR file.", se); //$NON-NLS-1$
+ }
+
+ return false;
+ }
+
+ /**
+ *
* @param bundleId The ID of the bundle to search for a classpath.
* @return the classpath contained within the bundle with the given ID.
* If

Back to the top