KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > loadgenerator > ant > StartLoadgenTask


1 /*
2  * TestTask.java
3  *
4  * Created on July 29, 2006, 11:33 PM
5  */

6
7 package org.netbeans.modules.loadgenerator.ant;
8
9 // IMPORTANT! You need to compile this class against ant.jar. So add the
10
// JAR ide5/ant/lib/ant.jar from your IDE installation directory (or any
11
// other version of Ant you wish to use) to your classpath. Or if
12
// writing your own build target, use e.g.:
13
// <classpath>
14
// <pathelement location="${ant.home}/lib/ant.jar"/>
15
// </classpath>
16

17 import java.util.Collection JavaDoc;
18 import org.apache.tools.ant.BuildException;
19 import org.apache.tools.ant.Task;
20 import org.netbeans.api.project.FileOwnerQuery;
21 import org.netbeans.modules.loadgenerator.api.EngineManager;
22 import org.netbeans.modules.loadgenerator.spi.Engine;
23 import org.openide.filesystems.FileObject;
24 import org.openide.filesystems.FileUtil;
25 import org.openide.util.Lookup;
26
27 /**
28  * @author Jaroslav Bachorik
29  */

30 public class StartLoadgenTask extends Task {
31   private String JavaDoc scriptPath;
32   
33   public void setPath(final String JavaDoc value) {
34     scriptPath = value;
35   }
36   
37   public void execute() throws BuildException {
38     try {
39       FileObject fob = FileUtil.toFileObject(getProject().getBaseDir());
40       System.out.println("FileObject: " + fob.getPath());
41       Lookup lookup = FileOwnerQuery.getOwner(fob).getLookup();
42       EngineManager manager = Lookup.getDefault().lookup(EngineManager.class);
43       
44       Collection JavaDoc<Engine> engines = manager.findEngines(FileUtil.getExtension(scriptPath));
45       for(Engine engine : engines) {
46         manager.startProcess(engine.createProcess(scriptPath));
47       }
48     } catch (Exception JavaDoc e) {
49       e.printStackTrace();
50     }
51     // To log something:
52
// log("Some message");
53
// log("Serious message", Project.MSG_WARN);
54
// log("Minor message", Project.MSG_VERBOSE);
55

56     // To signal an error:
57
// throw new BuildException("Problem", location);
58
// throw new BuildException(someThrowable, location);
59
// throw new BuildException("Problem", someThrowable, location);
60

61     // You can call other tasks too:
62
// Zip zip = (Zip)project.createTask("zip");
63
// zip.setZipfile(zipFile);
64
// FileSet fs = new FileSet();
65
// fs.setDir(baseDir);
66
// zip.addFileset(fs);
67
// zip.init();
68
// zip.setLocation(location);
69
// zip.execute();
70
}
71   
72 }
73
Popular Tags