You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by js...@apache.org on 2007/09/25 06:23:49 UTC

svn commit: r579053 - in /incubator/servicemix/trunk/core/servicemix-core/src/main: java/org/apache/servicemix/jbi/container/ resources/META-INF/

Author: jstrachan
Date: Mon Sep 24 21:23:44 2007
New Revision: 579053

URL: http://svn.apache.org/viewvc?rev=579053&view=rev
Log:
added the ability to install shared libraries, components and service assemblies using either files or maven group ids, artifacts and optional versions via the XML configuration files for doing spring based integration tests

Added:
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeployServiceAssembly.java   (with props)
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeploySupport.java   (with props)
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallComponent.java   (with props)
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallSharedLibrary.java   (with props)
    incubator/servicemix/trunk/core/servicemix-core/src/main/resources/META-INF/spring.schemas
Modified:
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java

Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeployServiceAssembly.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeployServiceAssembly.java?rev=579053&view=auto
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeployServiceAssembly.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeployServiceAssembly.java Mon Sep 24 21:23:44 2007
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.container;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Deploys a service assembly using either a File URL or the maven groupId, artifactId and optional versions.
+ *
+ * @version $Revision: 1.1 $
+ * @org.apache.xbean.XBean element="deployServiceAssembly"
+ * description="Deploys a service assembly"
+ */
+public class DeployServiceAssembly extends DeploySupport {
+    private static final transient Log LOG = LogFactory.getLog(InstallSharedLibrary.class);
+    private String serviceAssemblyName;
+
+    public DeployServiceAssembly() {
+        setType(".zip");
+    }
+
+    public String getServiceAssemblyName() {
+        if (serviceAssemblyName == null) {
+            return getArtifactId();
+        }
+        return serviceAssemblyName;
+    }
+
+    public void setServiceAssemblyName(String serviceAssemblyName) {
+        this.serviceAssemblyName = serviceAssemblyName;
+    }
+
+    protected void doDeploy() throws Exception {
+        String name = getServiceAssemblyName();
+        if (name == null) {
+            throw new IllegalArgumentException("You must specify a serviceAssemblyName or an artifactId property");
+        }
+
+        String file = getFile();
+
+        LOG.info("Deploying shared library: " + file);
+        getCommandsService().deployServiceAssembly(file, isDeferException());
+        getCommandsService().startServiceAssembly(name);
+    }
+}
\ No newline at end of file

Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeployServiceAssembly.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeploySupport.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeploySupport.java?rev=579053&view=auto
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeploySupport.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeploySupport.java Mon Sep 24 21:23:44 2007
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.container;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.framework.AdminCommandsService;
+import org.springframework.beans.factory.InitializingBean;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public abstract class DeploySupport implements InitializingBean {
+    private static final transient Log LOG = LogFactory.getLog(DeploySupport.class);
+
+    private JBIContainer jbiContainer;
+    private AdminCommandsService commandsService;
+    private boolean deferException;
+    private String homeDir;
+    private String repositoryDir;
+    private String groupId;
+    private String artifactId;
+    private String version;
+    private String type = "-installer.zip";
+    private String file;
+
+    public void afterPropertiesSet() throws Exception {
+    }
+
+    public void deploy(JBIContainer container) throws Exception {
+        setJbiContainer(container);
+        if (container == null) {
+            throw new IllegalArgumentException("No JBI container configured!");
+        }
+        if (getCommandsService() == null) {
+            setCommandsService(getJbiContainer().getAdminCommandsService());
+        }
+        doDeploy();
+    }
+
+
+    // Properties
+    //-------------------------------------------------------------------------
+
+    public JBIContainer getJbiContainer() {
+        return jbiContainer;
+    }
+
+    public void setJbiContainer(JBIContainer jbiContainer) {
+        this.jbiContainer = jbiContainer;
+    }
+
+    public AdminCommandsService getCommandsService() {
+        return commandsService;
+    }
+
+    public void setCommandsService(AdminCommandsService commandsService) {
+        this.commandsService = commandsService;
+    }
+
+    public boolean isDeferException() {
+        return deferException;
+    }
+
+    public void setDeferException(boolean deferException) {
+        this.deferException = deferException;
+    }
+
+    public String getArtifactId() {
+        if (artifactId == null) {
+            throw new IllegalArgumentException("You must specify either a file or a groupId and an artifactId property");
+        }
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getGroupId() {
+        if (groupId == null) {
+            throw new IllegalArgumentException("You must specify either a file or a groupId and an artifactId property");
+        }
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getHomeDir() {
+        if (homeDir == null) {
+            homeDir = System.getProperty("user.home", "~");
+        }
+        return homeDir;
+    }
+
+    public void setHomeDir(String homeDir) {
+        this.homeDir = homeDir;
+    }
+
+    public String getRepositoryDir() {
+        if (repositoryDir == null) {
+            repositoryDir = getHomeDir() + "/.m2/repository";
+        }
+        return repositoryDir;
+    }
+
+    public void setRepositoryDir(String repositoryDir) {
+        this.repositoryDir = repositoryDir;
+    }
+
+    public String getVersion() {
+        if (version == null) {
+            version = createVersion();
+        }
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public String getFile() {
+        if (file == null) {
+            file = createFile();
+        }
+        return file;
+    }
+
+    public void setFile(String file) {
+        this.file = file;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    // Implementation methods
+    //-------------------------------------------------------------------------
+    protected abstract void doDeploy() throws Exception;
+
+    protected String createFile() {
+        String group = getGroupId();
+        String artifact = getArtifactId();
+        String v = getVersion();
+        if (v == null) {
+            throw new IllegalArgumentException(
+                    "You must specify a version property as it could not be deduced for "
+                            + getGroupId() + ":" + getArtifactId());
+        }
+        group = group.replace('.', '/');
+        return getFilePrefix() + getRepositoryDir() + "/" + group + "/" + artifact + "/" + v + "/" + artifact + "-" + v + type;
+    }
+
+
+    protected String createVersion() {
+        String group = getGroupId();
+        String artifact = getArtifactId();
+        String key = group + "/" + artifact + "/version";
+
+        // now lets load all of the maven dependencies and look for this version
+        try {
+            Enumeration iter = Thread.currentThread().getContextClassLoader().getResources("META-INF/maven/dependencies.properties");
+            while (iter.hasMoreElements()) {
+                URL url = (URL) iter.nextElement();
+
+                LOG.debug("looking into properties file: " + url + " with key: " + key);
+                Properties properties = new Properties();
+                InputStream in = url.openStream();
+                properties.load(in);
+                in.close();
+                String answer = properties.getProperty(key);
+                if (answer != null) {
+                    answer = answer.trim();
+                    LOG.debug("Found version: " + answer);
+                    return answer;
+                }
+            }
+        } catch (IOException e) {
+            LOG.error("Failed: " + e, e);
+        }
+        return null;
+    }
+
+    protected String getFilePrefix() {
+        return isFileUrlFormat() ? "file://" : "";
+    }
+
+    protected boolean isFileUrlFormat() {
+        return true;
+    }
+}

Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/DeploySupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallComponent.java?rev=579053&view=auto
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallComponent.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallComponent.java Mon Sep 24 21:23:44 2007
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.container;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Installs a component using either a File URL or the maven groupId, artifactId and optional versions.
+ *
+ * @org.apache.xbean.XBean element="installComponent"
+ * description="Installs a shared library"
+ *
+ * @version $Revision: 1.1 $
+ */
+public class InstallComponent extends DeploySupport {
+    private static final transient Log LOG = LogFactory.getLog(InstallSharedLibrary.class);
+
+    private Properties properties = new Properties();
+    private String componentName;
+
+    public Properties getProperties() {
+        return properties;
+    }
+
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
+
+    public String getComponentName() {
+        if (componentName == null) {
+            return getArtifactId();
+        }
+        return componentName;
+    }
+
+    public void setComponentName(String componentName) {
+        this.componentName = componentName;
+    }
+
+    protected void doDeploy() throws Exception {
+        String name = getComponentName();
+        if (name == null) {
+            throw new IllegalArgumentException("You must specify a componentName or an artifactId property");
+        }
+
+        String file = getFile();
+
+        LOG.info("Deploying component: " + file);
+        getCommandsService().installComponent(file, getProperties(), isDeferException());
+
+        getCommandsService().startComponent(name);
+    }
+}
\ No newline at end of file

Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallSharedLibrary.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallSharedLibrary.java?rev=579053&view=auto
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallSharedLibrary.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallSharedLibrary.java Mon Sep 24 21:23:44 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.container;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Installs a shared library using either a File URL or the maven groupId, artifactId and optional versions.
+ *
+ * @org.apache.xbean.XBean element="installSharedLibrary"
+ * description="Installs a shared library"
+ *
+ * @version $Revision: 1.1 $
+ */
+public class InstallSharedLibrary extends DeploySupport {
+    private static final transient Log LOG = LogFactory.getLog(InstallSharedLibrary.class);
+
+    protected void doDeploy() throws Exception {
+        String file = getFile();
+
+        LOG.info("Deploying shared library: " + file);
+        getCommandsService().installSharedLibrary(file, isDeferException());
+    }
+}

Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/InstallSharedLibrary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java?rev=579053&r1=579052&r2=579053&view=diff
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java Mon Sep 24 21:23:44 2007
@@ -57,6 +57,7 @@
     private BeanFactory beanFactory;
     private ApplicationContext applicationContext;
     private String[] deployArchives;
+    private DeploySupport[] deployments;
     private Object shutdownLock;
     private Map components;
     private Map endpoints;
@@ -105,6 +106,12 @@
             initEndpoints();
         }
 
+        if (deployments != null) {
+            for (DeploySupport deployment : deployments) {
+                deployment.deploy(this);
+            }
+        }
+
         start();
     }
 
@@ -260,6 +267,14 @@
 
     public void setDeployArchives(String[] deployArchives) {
         this.deployArchives = deployArchives;
+    }
+
+    public DeploySupport[] getDeployments() {
+        return deployments;
+    }
+
+    public void setDeployments(DeploySupport[] deployments) {
+        this.deployments = deployments;
     }
 
     // Implementation methods

Added: incubator/servicemix/trunk/core/servicemix-core/src/main/resources/META-INF/spring.schemas
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/resources/META-INF/spring.schemas?rev=579053&view=auto
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/resources/META-INF/spring.schemas (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/resources/META-INF/spring.schemas Mon Sep 24 21:23:44 2007
@@ -0,0 +1,5 @@
+
+http\://incubator.apache.org/servicemix/schema/core/servicemix-core.xsd = servicemix.xsd
+
+# TODO remove the old value which is pointless
+http\://servicemix.apache.org/config/1.0=servicemix.xsd