1 | /*
|
---|
2 | * Copyright 2001-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs.optional.ccm;
|
---|
19 |
|
---|
20 |
|
---|
21 | import org.apache.tools.ant.BuildException;
|
---|
22 | import org.apache.tools.ant.taskdefs.Execute;
|
---|
23 | import org.apache.tools.ant.types.Commandline;
|
---|
24 |
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Task allows to reconfigure a project, recursively or not
|
---|
28 | */
|
---|
29 | public class CCMReconfigure extends Continuus {
|
---|
30 |
|
---|
31 | private String project = null;
|
---|
32 | private boolean recurse = false;
|
---|
33 | private boolean verbose = false;
|
---|
34 |
|
---|
35 | public CCMReconfigure() {
|
---|
36 | super();
|
---|
37 | setCcmAction(COMMAND_RECONFIGURE);
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Executes the task.
|
---|
43 | * <p>
|
---|
44 | * Builds a command line to execute ccm and then calls Exec's run method
|
---|
45 | * to execute the command line.
|
---|
46 | * </p>
|
---|
47 | */
|
---|
48 | public void execute() throws BuildException {
|
---|
49 | Commandline commandLine = new Commandline();
|
---|
50 | int result = 0;
|
---|
51 |
|
---|
52 | // build the command line from what we got the format
|
---|
53 | // as specified in the CCM.EXE help
|
---|
54 | commandLine.setExecutable(getCcmCommand());
|
---|
55 | commandLine.createArgument().setValue(getCcmAction());
|
---|
56 |
|
---|
57 | checkOptions(commandLine);
|
---|
58 |
|
---|
59 | result = run(commandLine);
|
---|
60 | if (Execute.isFailure(result)) {
|
---|
61 | String msg = "Failed executing: " + commandLine.toString();
|
---|
62 | throw new BuildException(msg, getLocation());
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Check the command line options.
|
---|
69 | */
|
---|
70 | private void checkOptions(Commandline cmd) {
|
---|
71 |
|
---|
72 | if (isRecurse() == true) {
|
---|
73 | cmd.createArgument().setValue(FLAG_RECURSE);
|
---|
74 | } // end of if ()
|
---|
75 |
|
---|
76 | if (isVerbose() == true) {
|
---|
77 | cmd.createArgument().setValue(FLAG_VERBOSE);
|
---|
78 | } // end of if ()
|
---|
79 |
|
---|
80 | if (getCcmProject() != null) {
|
---|
81 | cmd.createArgument().setValue(FLAG_PROJECT);
|
---|
82 | cmd.createArgument().setValue(getCcmProject());
|
---|
83 | }
|
---|
84 |
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Get the value of project.
|
---|
89 | * @return value of project.
|
---|
90 | */
|
---|
91 | public String getCcmProject() {
|
---|
92 | return project;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Sets the ccm project on which the operation is applied.
|
---|
97 | * @param v Value to assign to project.
|
---|
98 | */
|
---|
99 | public void setCcmProject(String v) {
|
---|
100 | this.project = v;
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Get the value of recurse.
|
---|
106 | * @return value of recurse.
|
---|
107 | */
|
---|
108 | public boolean isRecurse() {
|
---|
109 | return recurse;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * If true, recurse on subproject (default false).
|
---|
114 | *
|
---|
115 | * @param v Value to assign to recurse.
|
---|
116 | */
|
---|
117 | public void setRecurse(boolean v) {
|
---|
118 | this.recurse = v;
|
---|
119 | }
|
---|
120 |
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Get the value of verbose.
|
---|
124 | * @return value of verbose.
|
---|
125 | */
|
---|
126 | public boolean isVerbose() {
|
---|
127 | return verbose;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * If true, do a verbose reconfigure operation (default false).
|
---|
132 | * @param v Value to assign to verbose.
|
---|
133 | */
|
---|
134 | public void setVerbose(boolean v) {
|
---|
135 | this.verbose = v;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * /recurse --
|
---|
141 | */
|
---|
142 | public static final String FLAG_RECURSE = "/recurse";
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * /recurse --
|
---|
146 | */
|
---|
147 | public static final String FLAG_VERBOSE = "/verbose";
|
---|
148 |
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * /project flag -- target project
|
---|
152 | */
|
---|
153 | public static final String FLAG_PROJECT = "/project";
|
---|
154 |
|
---|
155 | }
|
---|
156 |
|
---|