01: /*
02: * Spoon - http://spoon.gforge.inria.fr/
03: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
04: *
05: * This software is governed by the CeCILL-C License under French law and
06: * abiding by the rules of distribution of free software. You can use, modify
07: * and/or redistribute the software under the terms of the CeCILL-C license as
08: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
09: *
10: * This program is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
13: *
14: * The fact that you are presently reading this means that you have had
15: * knowledge of the CeCILL-C license and that you accept its terms.
16: */
17:
18: package spoon;
19:
20: import java.io.File;
21: import java.util.ArrayList;
22: import java.util.List;
23:
24: import org.apache.tools.ant.BuildException;
25:
26: /**
27: * This class implements an Ant task for Spoon that encapsulates
28: * {@link spoon.LtLauncher}.
29: */
30: public class LtSpoonTask extends SpoonTask {
31:
32: String sourcepath;
33:
34: List<ProcessorType> ltprocessorTypes = new ArrayList<ProcessorType>();
35:
36: /**
37: * Default constructor.
38: */
39: public LtSpoonTask() {
40: setClassname(LtLauncher.class.getName());
41: setFailonerror(true);
42: }
43:
44: /**
45: * Adds a new processor type to be instantiated and used by Spoon when
46: * processing the code.
47: */
48: public void addLtProcessor(ProcessorType processorType) {
49: this .ltprocessorTypes.add(processorType);
50: }
51:
52: /**
53: * Executes the task.
54: */
55: @Override
56: public void execute() throws BuildException {
57: if (classname == null) {
58: throw new BuildException("classname is mandatory");
59: }
60:
61: if (sourcepath != null) {
62: createArg().setValue("-i");
63: createArg().setValue(sourcepath);
64: }
65:
66: // lt processors
67: if (ltprocessorTypes != null && ltprocessorTypes.size() > 0) {
68: createArg().setValue("-l");
69: String processor = "";
70: for (ProcessorType t : ltprocessorTypes)
71: processor += t.getType() + File.pathSeparator;
72: createArg().setValue(processor);
73: }
74:
75: super .execute();
76: }
77:
78: /**
79: * Sets the source path.
80: */
81: public void setSourcepath(String sourcepath) {
82: this.sourcepath = sourcepath;
83: }
84:
85: }
|