View Javadoc

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   * @author jpiasci
21   * @goal proxy
22   */
23  public class GrinderProxyPlugin extends AbstractMojo {
24  
25  	/**
26  	 * The port
27  	 * 
28  	 * @parameter expression="8001"
29  	 */
30  	private String port;
31  
32  	/**
33  	 * @parameter expression="${basedir}/src/test/grinder"
34  	 */
35  	private File dir;
36  
37  	/**
38  	 * @parameter expression="${project.artifactId}.py"
39  	 */
40  	private String scriptName;
41  
42  	/**
43  	 * @parameter expression="${project.artifactId}.properties"
44  	 */
45  	private String propertiesName;
46  
47  	public void execute() throws MojoExecutionException, MojoFailureException {
48  		dir.mkdirs();
49  
50  		// Copy the properties
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  		// Run the proxy
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  		//TODO we need another way to stop this, ctrl-c is a bad approach
79  		try {
80  			TCPProxy.main(args);
81  		} catch (GrinderException e) {
82  			getLog().error(e);
83  		}
84  
85  	}
86  
87  }