You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/02/06 14:35:29 UTC
svn commit: r375277 - in
/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task:
InstallComponentTask.java JbiTask.java
Author: gnodet
Date: Mon Feb 6 05:35:29 2006
New Revision: 375277
URL: http://svn.apache.org/viewcvs?rev=375277&view=rev
Log:
Fix ant task to allow the use of installation properties
Modified:
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java?rev=375277&r1=375276&r2=375277&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java Mon Feb 6 05:35:29 2006
@@ -15,15 +15,18 @@
*/
package org.apache.servicemix.jbi.management.task;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.jbi.framework.FrameworkInstallationService;
+import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
import org.apache.tools.ant.BuildException;
-import javax.jbi.management.DeploymentException;
-
-import java.io.IOException;
-
/**
* Install a Component
*
@@ -32,6 +35,8 @@
public class InstallComponentTask extends JbiTask {
private static final Log log = LogFactory.getLog(InstallComponentTask.class);
private String file; //file to install
+ private String paramsFile;
+ private List nestedParams;
/**
* @return Returns the file.
@@ -46,6 +51,22 @@
this.file = file;
}
+ public String getParams() {
+ return paramsFile;
+ }
+ public void setParams(String paramsFile) {
+ this.paramsFile = paramsFile;
+ }
+
+ public Param addParam() {
+ Param p = new Param();
+ if (nestedParams == null) {
+ nestedParams = new ArrayList();
+ }
+ nestedParams.add(p);
+ return p;
+ }
+
/**
* execute the task
* @throws BuildException
@@ -54,21 +75,59 @@
if (file == null){
throw new BuildException("null file - file should be an archive");
}
- if (file.endsWith(".zip") || file.endsWith(".jar")){
- try {
- FrameworkInstallationService is = getInstallationService();
- is.install(file);
- }
- catch (IOException e) {
- log.error("Caught an exception getting the installation service",e);
- throw new BuildException(e);
- }
- catch (DeploymentException e) {
- log.error("Deployment failed",e);
- throw new BuildException(e);
- }
- }else {
+ if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
throw new BuildException("file: " + file + " is not an archive");
+ }
+ Properties props;
+ try {
+ props = getProperties();
+ } catch (IOException e) {
+ log.error("Error retrieving installation properties", e);
+ throw new BuildException(e);
+ }
+ AdminCommandsServiceMBean acs;
+ try {
+ acs = getAdminCommandsService();
+ } catch (IOException e) {
+ log.error("Caught an exception getting the installation service", e);
+ throw new BuildException(e);
+ }
+ try {
+ acs.installComponent(file, props);
+ } catch (Exception e) {
+ log.error("Error installing component", e);
+ throw new BuildException(e);
+ }
+ }
+
+ private Properties getProperties() throws IOException {
+ Properties props = new Properties();
+ if (paramsFile != null) {
+ props.load(new FileInputStream(paramsFile));
+ }
+ if (nestedParams != null) {
+ for (Iterator iter = nestedParams.iterator(); iter.hasNext();) {
+ Param p = (Param) iter.next();
+ props.setProperty(p.getValue(), p.getName());
+ }
+ }
+ return props;
+ }
+
+ private static class Param {
+ private String name;
+ private String value;
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getValue() {
+ return value;
+ }
+ public void setValue(String value) {
+ this.value = value;
}
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java?rev=375277&r1=375276&r2=375277&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java Mon Feb 6 05:35:29 2006
@@ -18,6 +18,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
import org.apache.servicemix.jbi.framework.DeploymentService;
import org.apache.servicemix.jbi.framework.FrameworkInstallationService;
import org.apache.servicemix.jbi.framework.InstallationService;
@@ -26,7 +27,6 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
-import javax.jbi.management.AdminServiceMBean;
import javax.jbi.management.DeploymentServiceMBean;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
@@ -133,6 +133,18 @@
return (FrameworkInstallationService) MBeanServerInvocationHandler.newProxyInstance(jmxConnector.getMBeanServerConnection(), objectName,
FrameworkInstallationService.class, true);
+ }
+
+ /**
+ * Get the AdminCommandsService
+ * @return the main administration service MBean
+ * @throws IOException
+ */
+ public AdminCommandsServiceMBean getAdminCommandsService() throws IOException{
+ ObjectName objectName = getObjectName(AdminCommandsServiceMBean.class);
+
+ return (AdminCommandsServiceMBean) MBeanServerInvocationHandler.newProxyInstance(jmxConnector.getMBeanServerConnection(), objectName,
+ AdminCommandsServiceMBean.class, true);
}
/**