1 17 package org.apache.servicemix.maven.plugin.jbi; 18 19 import java.io.File ; 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 40 public class ServiceMixMojo extends JbiProjectDeployerMojo { 41 42 private JBIContainer jbiContainer; 43 44 47 private String installDirectory; 48 49 52 private String deploymentDirectory; 53 54 57 private String rootDirectory; 58 59 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 rootDir = new File (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 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 |