1 package org.apache.activemq.maven; 2 3 19 20 import org.apache.activemq.console.Main; 21 import org.apache.maven.plugin.AbstractMojo; 22 import org.apache.maven.plugin.MojoExecutionException; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 import java.nio.MappedByteBuffer ; 29 import java.nio.channels.FileChannel ; 30 31 37 public class BrokerMojo 38 extends AbstractMojo { 39 45 private File outputDirectory; 46 47 52 private File configFile; 53 54 59 private String url; 60 61 public void execute() 62 throws MojoExecutionException { 63 64 File out = outputDirectory; 65 66 if (!out.exists()) { 68 out.mkdirs(); 69 } 70 71 String [] args = new String [2]; 72 if (configFile != null) { 73 File config; 74 try { 75 config = copy(configFile); 76 } catch (IOException e) { 77 throw new MojoExecutionException(e.getMessage()); 78 } 79 80 args[0] = "start"; 81 args[1] = "xbean:" + (config.toURI()).toString(); 82 } else { 83 args[0] = "start"; 84 args[1] = url; 85 } 86 87 Main.main(args); 88 } 89 90 97 public File copy(File source) throws IOException { 98 FileChannel in = null, out = null; 99 File dest = new File (outputDirectory.getAbsolutePath() + File.separator + source.getName()); 100 101 try { 102 in = new FileInputStream (source).getChannel(); 103 out = new FileOutputStream (dest).getChannel(); 104 105 long size = in.size(); 106 MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size); 107 108 out.write(buf); 109 110 } finally { 111 if (in != null) in.close(); 112 if (out != null) out.close(); 113 } 114 115 return dest; 116 } 117 } 118 | Popular Tags |