Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2012-03-13 09:21:13 -0400
committerMarkus Tiede2012-03-13 09:21:13 -0400
commit52f5e87f72ca2e52a8e9d5a1a6c168bc1e373584 (patch)
treea370621c880628211d1ac1d5fd8a5cfab7421a41 /org.eclipse.jubula.autagent
parent2f97ae2707981a184a4c32148740d32db01d3a50 (diff)
downloadorg.eclipse.jubula.core-52f5e87f72ca2e52a8e9d5a1a6c168bc1e373584.tar.gz
org.eclipse.jubula.core-52f5e87f72ca2e52a8e9d5a1a6c168bc1e373584.tar.xz
org.eclipse.jubula.core-52f5e87f72ca2e52a8e9d5a1a6c168bc1e373584.zip
Sprint task - fix for issue 373919.
Diffstat (limited to 'org.eclipse.jubula.autagent')
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartJavaAut.java131
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartRcpAutServerCommand.java18
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartSwingAutServerCommand.java3
3 files changed, 65 insertions, 87 deletions
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartJavaAut.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartJavaAut.java
index e269a4d13..a6ebc7bdd 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartJavaAut.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/AbstractStartJavaAut.java
@@ -15,14 +15,12 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jubula.autagent.monitoring.IMonitoring;
@@ -311,33 +309,6 @@ public abstract class AbstractStartJavaAut extends AbstractStartToolkitAut {
}
/**
- * @param parameters
- * The parameters for starting the AUT.
- * @return <code>true</code> if the AUT is supposed to be started with a
- * monitoring agent and all necessary information are available.
- * Otherwise <code>false</code>.
- */
- protected boolean shouldAndCanRunWithMonitoring(Map parameters) {
- List<String> requiredInformation = new ArrayList<String>();
- requiredInformation.add((String) parameters
- .get(AutConfigConstants.MONITORING_AGENT_ID));
- requiredInformation.add((String) parameters
- .get(AutConfigConstants.AUT_ID));
-
- requiredInformation.add((String) parameters
- .get(MonitoringConstants.BUNDLE_ID));
- requiredInformation.add((String) parameters
- .get(MonitoringConstants.AGENT_CLASS));
-
- for (String required : requiredInformation) {
- if (StringUtils.isEmpty(required)) {
- return false;
- }
- }
- return true;
- }
-
- /**
* Sets -javaagent and JRE arguments as SUN environment variable.
* @param parameters The parameters for starting the AUT
* @return the _JAVA_OPTIONS environment variable including -javaagent
@@ -350,9 +321,12 @@ public abstract class AbstractStartJavaAut extends AbstractStartToolkitAut {
// set agent and locals
sb.append(JAVA_OPTIONS_INTRO);
- if (shouldAndCanRunWithMonitoring(parameters)) {
- sb.append(getMonitoringAgent(parameters))
- .append(StringConstants.SPACE);
+ if (org.eclipse.jubula.tools.utils.MonitoringUtil
+ .shouldAndCanRunWithMonitoring(parameters)) {
+ String monAgent = getMonitoringAgent(parameters);
+ if (monAgent != null) {
+ sb.append(monAgent).append(StringConstants.SPACE);
+ }
}
sb.append(StringConstants.QUOTE)
.append("-javaagent:") //$NON-NLS-1$
@@ -368,9 +342,12 @@ public abstract class AbstractStartJavaAut extends AbstractStartToolkitAut {
.append(locale.getLanguage());
}
} else {
- if (shouldAndCanRunWithMonitoring(parameters)) {
- sb.append(JAVA_OPTIONS_INTRO)
- .append(getMonitoringAgent(parameters));
+ if (org.eclipse.jubula.tools.utils.MonitoringUtil
+ .shouldAndCanRunWithMonitoring(parameters)) {
+ String monAgent = getMonitoringAgent(parameters);
+ if (monAgent != null) {
+ sb.append(JAVA_OPTIONS_INTRO).append(monAgent);
+ }
}
}
@@ -400,7 +377,7 @@ public abstract class AbstractStartJavaAut extends AbstractStartToolkitAut {
* interface, and will invoke the "getAgent" method.
* @param parameters The AutConfigMap
* @return agentString The agent String like -javaagent:myagent.jar
- * or null if the monitoring agent String could't be generated
+ * or null if the monitoring agent String couldn't be generated
*/
protected String getMonitoringAgent(Map parameters) {
String autId = (String)parameters.get(
@@ -409,49 +386,47 @@ public abstract class AbstractStartJavaAut extends AbstractStartToolkitAut {
boolean duplicate = MonitoringUtil.checkForDuplicateAutID(autId);
if (!duplicate) {
mds.putConfigMap(autId, parameters);
- }
- String agentString = null;
- if (shouldAndCanRunWithMonitoring(parameters)) {
- String monitoringImplClass = (String)parameters.get(
- MonitoringConstants.AGENT_CLASS);
- String bundleId = (String)parameters.get(
- MonitoringConstants.BUNDLE_ID);
- try {
- Bundle bundle = Platform.getBundle(bundleId);
- if (bundle == null) {
- LOG.error("No bundle was found for the given bundleId"); //$NON-NLS-1$
- return null;
- }
- Class<?> monitoringClass =
- bundle.loadClass(monitoringImplClass);
- Constructor<?> constructor = monitoringClass.getConstructor();
- IMonitoring agentInstance =
- (IMonitoring)constructor.newInstance();
- agentInstance.setAutId(autId);
- //set the path to the agent jar file
- agentInstance.setInstallDir(FileLocator.getBundleFile(bundle));
- agentString = agentInstance.createAgent();
- if (!duplicate) {
- mds.putMonitoringAgent(autId, agentInstance);
- }
- } catch (InstantiationException e) {
- LOG.error("The instantiation of the monitoring class failed ", e); //$NON-NLS-1$
- } catch (IllegalAccessException e) {
- LOG.error("Access to the monitoring class failed ", e); //$NON-NLS-1$
- } catch (SecurityException e) {
- LOG.error("Access to the monitoring class failed ", e); //$NON-NLS-1$
- } catch (NoSuchMethodException e) {
- LOG.error("A method in the monitoring class could not be found", e); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- LOG.error("A argument which is passed to monitoring class is invalide", e); //$NON-NLS-1$
- } catch (InvocationTargetException e) {
- LOG.error("The method call of 'getAgent' failed, you have to implement the interface IMonitoring", e); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- LOG.error("The monitoring class can not be found", e); //$NON-NLS-1$
- } catch (IOException e) {
- LOG.error("IOException while searching for the given bundle", e); //$NON-NLS-1$
- }
}
+ String agentString = null;
+ String monitoringImplClass = (String)parameters.get(
+ MonitoringConstants.AGENT_CLASS);
+ String bundleId = (String)parameters.get(
+ MonitoringConstants.BUNDLE_ID);
+ try {
+ Bundle bundle = Platform.getBundle(bundleId);
+ if (bundle == null) {
+ LOG.error("No bundle was found for the given bundleId"); //$NON-NLS-1$
+ return null;
+ }
+ Class<?> monitoringClass =
+ bundle.loadClass(monitoringImplClass);
+ Constructor<?> constructor = monitoringClass.getConstructor();
+ IMonitoring agentInstance =
+ (IMonitoring)constructor.newInstance();
+ agentInstance.setAutId(autId);
+ //set the path to the agent jar file
+ agentInstance.setInstallDir(FileLocator.getBundleFile(bundle));
+ agentString = agentInstance.createAgent();
+ if (!duplicate) {
+ mds.putMonitoringAgent(autId, agentInstance);
+ }
+ } catch (InstantiationException e) {
+ LOG.error("The instantiation of the monitoring class failed ", e); //$NON-NLS-1$
+ } catch (IllegalAccessException e) {
+ LOG.error("Access to the monitoring class failed ", e); //$NON-NLS-1$
+ } catch (SecurityException e) {
+ LOG.error("Access to the monitoring class failed ", e); //$NON-NLS-1$
+ } catch (NoSuchMethodException e) {
+ LOG.error("A method in the monitoring class could not be found", e); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ LOG.error("A argument which is passed to monitoring class is invalide", e); //$NON-NLS-1$
+ } catch (InvocationTargetException e) {
+ LOG.error("The method call of 'getAgent' failed, you have to implement the interface IMonitoring", e); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ LOG.error("The monitoring class can not be found", e); //$NON-NLS-1$
+ } catch (IOException e) {
+ LOG.error("IOException while searching for the given bundle", e); //$NON-NLS-1$
+ }
return agentString;
}
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartRcpAutServerCommand.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartRcpAutServerCommand.java
index b597457c1..8380ab5b4 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartRcpAutServerCommand.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartRcpAutServerCommand.java
@@ -24,6 +24,7 @@ import org.eclipse.jubula.tools.constants.CommandConstants;
import org.eclipse.jubula.tools.constants.RcpAccessorConstants;
import org.eclipse.jubula.tools.constants.StringConstants;
import org.eclipse.jubula.tools.utils.EnvironmentUtils;
+import org.eclipse.jubula.tools.utils.MonitoringUtil;
/**
@@ -215,14 +216,15 @@ public class StartRcpAutServerCommand extends AbstractStartJavaAut {
parameters, StartSwtAutServerCommand.ENV_VAR_PREFIX,
StartSwtAutServerCommand.ENV_VALUE_SEP));
- if (shouldAndCanRunWithMonitoring(parameters)) {
-
- StringBuffer sb = new StringBuffer();
- sb.append(JAVA_OPTIONS_INTRO);
- sb.append(this.getMonitoringAgent(parameters));
- envList.add(sb.toString());
- envArray = super.createEnvArray(parameters, true);
-
+ if (MonitoringUtil.shouldAndCanRunWithMonitoring(parameters)) {
+ String monAgent = this.getMonitoringAgent(parameters);
+ if (monAgent != null) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(JAVA_OPTIONS_INTRO);
+ sb.append(monAgent);
+ envList.add(sb.toString());
+ envArray = super.createEnvArray(parameters, true);
+ }
}
envArray = envList.toArray(new String [envList.size()]);
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartSwingAutServerCommand.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartSwingAutServerCommand.java
index 6fa68aef3..b0d59bd23 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartSwingAutServerCommand.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StartSwingAutServerCommand.java
@@ -24,6 +24,7 @@ import org.eclipse.jubula.autagent.AutStarter;
import org.eclipse.jubula.tools.constants.AutConfigConstants;
import org.eclipse.jubula.tools.constants.CommandConstants;
import org.eclipse.jubula.tools.constants.StringConstants;
+import org.eclipse.jubula.tools.utils.MonitoringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +52,7 @@ public class StartSwingAutServerCommand extends AbstractStartJavaAut {
protected String[] createEnvArray(Map parameters, boolean isAgentSet) {
if (isRunningFromExecutable(parameters)
- || shouldAndCanRunWithMonitoring(parameters)) {
+ || MonitoringUtil.shouldAndCanRunWithMonitoring(parameters)) {
setEnv(parameters);
boolean agentActive = true;
return super.createEnvArray(parameters, agentActive);

Back to the top