1 18 package org.apache.activemq.maven; 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 ServerMojo extends AbstractMojo { 38 44 private File outputDirectory; 45 46 52 private String configDirectory; 53 54 60 private String configType; 61 62 67 private File configFile; 68 69 74 private String url; 75 76 public void execute() 77 throws MojoExecutionException { 78 79 File out = outputDirectory; 80 81 if (!out.exists()) { 83 out.mkdirs(); 84 } 85 86 String [] args = new String [2]; 87 if (url != null) { 88 args[0] = "start"; 89 args[1] = url; 90 } else { 91 File config; 92 if (configFile != null) { 93 config = configFile; 94 } else { 95 96 config = new File (configDirectory + File.separator + configType + ".xml"); 97 } 98 99 try { 100 config = copy(config); 101 } catch (IOException e) { 102 throw new MojoExecutionException(e.getMessage()); 103 } 104 args[0] = "start"; 105 args[1] = "xbean:" + (config.toURI()).toString(); 106 } 107 108 109 Main.main(args); 110 } 111 112 119 public File copy(File source) throws IOException { 120 FileChannel in = null, out = null; 121 122 File dest = new File (outputDirectory.getAbsolutePath() + File.separator + "activemq.xml"); 123 124 try { 125 in = new FileInputStream (source).getChannel(); 126 out = new FileOutputStream (dest).getChannel(); 127 128 long size = in.size(); 129 MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size); 130 131 out.write(buf); 132 133 } finally { 134 if (in != null) in.close(); 135 if (out != null) out.close(); 136 } 137 138 return dest; 139 } 140 } 141 | Popular Tags |