1 package org.whatsitcalled.maven.plugins;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.OutputStream;
9 import java.io.PrintStream;
10 import java.util.Properties;
11
12 import net.grinder.TCPProxy;
13 import net.grinder.common.GrinderException;
14
15 import org.apache.maven.plugin.AbstractMojo;
16 import org.apache.maven.plugin.MojoExecutionException;
17 import org.apache.maven.plugin.MojoFailureException;
18
19
20
21
22
23 public class GrinderProxyPlugin extends AbstractMojo {
24
25
26
27
28
29
30 private String port;
31
32
33
34
35 private File dir;
36
37
38
39
40 private String scriptName;
41
42
43
44
45 private String propertiesName;
46
47 public void execute() throws MojoExecutionException, MojoFailureException {
48 dir.mkdirs();
49
50
51 InputStream is = getClass().getClassLoader().getResourceAsStream(
52 "grinder.properties");
53 Properties p = new Properties();
54 try {
55 p.load(is);
56 } catch (IOException e) {
57 getLog().error(e);
58 }
59 try {
60 p.store(new FileOutputStream(new File(dir, propertiesName)),
61 "Created by GrinderProxyPlugin");
62 } catch (FileNotFoundException e) {
63 getLog().error(e);
64 } catch (IOException e) {
65 getLog().error(e);
66 }
67
68
69 String[] args = { "-http", "-localport", port };
70
71 File file = new File(dir, scriptName);
72
73 try {
74 System.setOut(new PrintStream(file));
75 } catch (FileNotFoundException e1) {
76 getLog().error(e1);
77 }
78
79 try {
80 TCPProxy.main(args);
81 } catch (GrinderException e) {
82 getLog().error(e);
83 }
84
85 }
86
87 }