KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > maven > plugin > jbi > ServiceMixMojo


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.maven.plugin.jbi;
18
19 import java.io.File JavaDoc;
20
21 import javax.jbi.JBIException;
22
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.servicemix.jbi.container.JBIContainer;
26 import org.codehaus.plexus.util.FileUtils;
27
28 /**
29  * Starts a ServiceMix JBI container and them uses the deploy project MOJO to
30  * push the current project and dependencies to it
31  *
32  * @author <a HREF="pdodds@apache.org">Philip Dodds</a>
33  * @version $Id: GenerateComponentDescriptorMojo 314956 2005-10-12 16:27:15Z
34  * brett $
35  * @goal servicemix
36  * @requiresDependencyResolution runtime
37  * @description installs the project (and all dependencies) to a local
38  * ServiceMix instance
39  */

40 public class ServiceMixMojo extends JbiProjectDeployerMojo {
41
42     private JBIContainer jbiContainer;
43
44     /**
45      * @parameter default-value="${project.build.directory}/servicemix/install"
46      */

47     private String JavaDoc installDirectory;
48
49     /**
50      * @parameter default-value="${project.build.directory}/servicemix/deploy"
51      */

52     private String JavaDoc deploymentDirectory;
53
54     /**
55      * @parameter default-value="${project.build.directory}/servicemix/rootDir"
56      */

57     private String JavaDoc rootDirectory;
58
59     /**
60      * @parameter default-value="true"
61      */

62     private boolean cleanStart;
63
64     public void execute() throws MojoExecutionException, MojoFailureException {
65
66         try {
67
68             if (cleanStart) {
69                 getLog().info(
70                         "Cleaning ServiceMix root directory [" + rootDirectory
71                                 + "]");
72                 File JavaDoc rootDir = new File JavaDoc(rootDirectory);
73                 FileUtils.deleteDirectory(rootDir);
74                 rootDir.mkdirs();
75             }
76
77             startServiceMix();
78             deployProject();
79
80             getLog().info("Project deployed");
81
82             while (true) {
83                 Thread.sleep(1000);
84             }
85         } catch (Exception JavaDoc e) {
86             stopServiceMix();
87             throw new MojoExecutionException(
88                     "Apache ServiceMix was unable to deploy project", e);
89         }
90
91     }
92
93     private void stopServiceMix() {
94         getLog().info("Shutting down Apache ServiceMix");
95         if (jbiContainer != null)
96             try {
97                 jbiContainer.shutDown();
98             } catch (JBIException e) {
99                 getLog().warn(e);
100             }
101     }
102
103     private void startServiceMix() throws MojoExecutionException {
104         try {
105             getLog().info("Starting Apache ServiceMix");
106             jbiContainer = new JBIContainer();
107             jbiContainer.setRmiPort(Integer.parseInt(port));
108             jbiContainer.setCreateMBeanServer(true);
109             jbiContainer.setInstallationDirPath(installDirectory);
110             jbiContainer.setDeploymentDirPath(deploymentDirectory);
111             jbiContainer.setRootDir(rootDirectory);
112             jbiContainer.init();
113             jbiContainer.start();
114         } catch (JBIException e) {
115             throw new MojoExecutionException(
116                     "Unable to start the JBI container", e);
117         }
118     }
119 }
120
Popular Tags