1
16package org.tp23.antinstaller.runtime.exe;
17
18import java.util.List;
19import java.util.Map;
20
21import org.tp23.antinstaller.InstallException;
22import org.tp23.antinstaller.InstallerContext;
23import org.tp23.antinstaller.ResourceBundleHelper;
24import org.tp23.antinstaller.antmod.Launcher;
25
26
38public class AntLauncherFilter implements ExecuteFilter {
39
40 private static final ResourceBundleHelper resHelper = new ResourceBundleHelper("org.tp23.antinstaller.renderer.Res");
41
42
43 public AntLauncherFilter() {
44 }
45
46 public void exec(InstallerContext ctx) throws InstallException {
47 if(ctx.getInstaller().isVerbose())ctx.log("Starting Ant Launcher");
48
49 try {
50
51 List argsList = ctx.getInstaller().getTargets(ctx);
53
54 String[] argsArr = new String[argsList.size() + 4];
55 argsList.toArray(argsArr);
56
57 if (ctx.getInstaller().isVerbose()) {
58 ctx.log("Running targets:" + printArray(argsArr));
59 }
60 System.out.println("Targets:"+printArray(argsArr));
61
62 argsArr[argsArr.length-2] = "-lib";
63 argsArr[argsArr.length-1] = "antlib";
64
65 argsArr[argsArr.length-4] = "-buildfile";
66 argsArr[argsArr.length - 3] = ctx.getFileRoot().getAbsolutePath() +
67 System.getProperty("file.separator") +
68 ctx.getAntBuildFile();
69
70 System.setOut(ctx.getAntOutputRenderer().getOut());
72 System.setErr(ctx.getAntOutputRenderer().getErr());
73
74 Map properties = ctx.getInstaller().getResultContainer().getAllProperties();
75 Launcher launcher = new Launcher(properties);
76 int ok = launcher.run(argsArr, ctx);
77 if(ok!=0) {
78 throw new InstallException( resHelper.getMessage( "ant.failure" ) );
79 }
81 else {
82 ctx.setInstallSucceded(true);
83 }
84 ctx.log("Ant finished");
85 ctx.getRunner().antFinished();
86 }
87 catch (Throwable ex) {
88 throw new InstallException("Error running the install, " + ex.getMessage(), ex);
89 }
90 }
91
96 private String printArray(Object[] args){
97 StringBuffer sb = new StringBuffer();
98 for (int i = 0; i < args.length-4; i++) {
99 if (i > 0) {
00 sb.append(',');
01 }
02 sb.append(args[i]);
03 }
04 return sb.toString();
05 }
06}
07