1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package nl.toolforge.karma.core.cmd.impl; |
20 |
|
|
21 |
|
import nl.toolforge.karma.core.cmd.Command; |
22 |
|
import nl.toolforge.karma.core.cmd.CommandDescriptor; |
23 |
|
import nl.toolforge.karma.core.cmd.CommandException; |
24 |
|
import nl.toolforge.karma.core.cmd.CommandFactory; |
25 |
|
import nl.toolforge.karma.core.cmd.CommandLoadException; |
26 |
|
import nl.toolforge.karma.core.cmd.CommandResponse; |
27 |
|
import nl.toolforge.karma.core.cmd.event.ExceptionEvent; |
28 |
|
import nl.toolforge.karma.core.cmd.event.MessageEvent; |
29 |
|
import nl.toolforge.karma.core.cmd.event.SimpleMessage; |
30 |
|
import nl.toolforge.karma.core.cmd.util.DependencyException; |
31 |
|
import nl.toolforge.karma.core.cmd.util.DependencyHelper; |
32 |
|
import nl.toolforge.karma.core.manifest.ManifestException; |
33 |
|
import nl.toolforge.karma.core.module.Module; |
34 |
|
import nl.toolforge.karma.core.module.ModuleTypeException; |
35 |
|
import org.apache.commons.logging.Log; |
36 |
|
import org.apache.commons.logging.LogFactory; |
37 |
|
import org.apache.tools.ant.BuildException; |
38 |
|
import org.apache.tools.ant.DirectoryScanner; |
39 |
|
import org.apache.tools.ant.Project; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
public class BuildModule extends AbstractBuildCommand { |
64 |
|
|
65 |
0 |
private static final Log logger = LogFactory.getLog(BuildModule.class); |
66 |
|
|
67 |
0 |
private CommandResponse commandResponse = new CommandResponse(); |
68 |
|
|
69 |
|
public BuildModule(CommandDescriptor descriptor) { |
70 |
0 |
super(descriptor); |
71 |
0 |
} |
72 |
|
|
73 |
|
public void execute() throws CommandException { |
74 |
|
|
75 |
0 |
super.execute(); |
76 |
|
|
77 |
|
|
78 |
0 |
if (!getBuildEnvironment().getModuleSourceDirectory().exists()) { |
79 |
|
|
80 |
|
|
81 |
0 |
throw new CommandException(CommandException.NO_SRC_DIR, class="keyword">new Object[] {getCurrentModule().getName()}); |
82 |
|
} |
83 |
0 |
DirectoryScanner scanner = new DirectoryScanner(); |
84 |
0 |
scanner.setBasedir(getBuildEnvironment().getModuleSourceDirectory()); |
85 |
0 |
scanner.setIncludes(new String[]{"**/*.java"}); |
86 |
0 |
scanner.scan(); |
87 |
0 |
if (scanner.getIncludedFiles().length == 0) { |
88 |
|
|
89 |
|
|
90 |
0 |
throw new CommandException(CommandException.NO_SRC_DIR, class="keyword">new Object[] {getCurrentModule().getName()}); |
91 |
|
} |
92 |
|
|
93 |
0 |
DependencyHelper helper = new DependencyHelper(getCurrentManifest()); |
94 |
|
|
95 |
0 |
Project project = getAntProject("build-module.xml"); |
96 |
|
|
97 |
|
try { |
98 |
0 |
boolean dependenciesChecked = false; |
99 |
0 |
while (!dependenciesChecked) { |
100 |
|
try { |
101 |
0 |
project.setProperty("classpath", helper.getClassPath(getCurrentModule())); |
102 |
0 |
dependenciesChecked = true; |
103 |
0 |
} catch (DependencyException de) { |
104 |
0 |
if ( !getCommandLine().hasOption("n") || |
105 |
|
de.getErrorCode().equals(DependencyException.DEPENDENCY_NOT_FOUND)) { |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
0 |
String dep = (String) de.getMessageArguments()[0]; |
110 |
|
try { |
111 |
0 |
Module module = getCurrentManifest().getModule(dep); |
112 |
|
|
113 |
0 |
Command command = null; |
114 |
|
try { |
115 |
0 |
getCommandResponse().addEvent(new MessageEvent(this, class="keyword">new SimpleMessage("Module `{0}` is needed, but is not built yet. Doing that now.", new Object[]{module.getName()}))); |
116 |
0 |
String commandLineString = "bm -m " + module.getName(); |
117 |
0 |
logger.info("Going to: "+commandLineString); |
118 |
0 |
command = CommandFactory.getInstance().getCommand(commandLineString); |
119 |
0 |
command.setContext(getContext()); |
120 |
0 |
command.registerCommandResponseListener(getResponseListener()); |
121 |
0 |
command.execute(); |
122 |
|
|
123 |
|
|
124 |
0 |
} catch (CommandLoadException e) { |
125 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
126 |
|
} finally { |
127 |
0 |
if ( command != null ) { |
128 |
0 |
command.deregisterCommandResponseListener(getResponseListener()); |
129 |
|
} |
130 |
0 |
} |
131 |
0 |
} catch (ManifestException me) { |
132 |
|
|
133 |
0 |
throw de; |
134 |
0 |
} |
135 |
|
} else { |
136 |
|
|
137 |
0 |
throw de; |
138 |
|
} |
139 |
0 |
} |
140 |
|
} |
141 |
0 |
project.setProperty("module-build-dir", getBuildEnvironment().getModuleBuildDirectory().getPath()); |
142 |
0 |
project.setProperty("module-source-dir", getBuildEnvironment().getModuleSourceDirectory().getPath()); |
143 |
0 |
project.setProperty("java.compiler", getWorkingContext().getProperties().getProperty("java.compiler", "modern")); |
144 |
0 |
project.setProperty("java.source", getWorkingContext().getProperties().getProperty("java.source", "1.4")); |
145 |
0 |
project.setProperty("java.target", getWorkingContext().getProperties().getProperty("java.target", "1.4")); |
146 |
0 |
project.setProperty("java.debug", getWorkingContext().getProperties().getProperty("java.debug", "off")); |
147 |
0 |
project.setProperty("java.debuglevel", getWorkingContext().getProperties().getProperty("java.debuglevel", "none")); |
148 |
0 |
project.setProperty("javac.nowarn", getWorkingContext().getProperties().getProperty("javac.nowarn", "off")); |
149 |
0 |
project.setProperty("javac.optimize", getWorkingContext().getProperties().getProperty("javac.optimize", "off")); |
150 |
0 |
project.setProperty("javac.deprecation", getWorkingContext().getProperties().getProperty("javac.deprecation", "off")); |
151 |
0 |
project.setProperty("javac.verbose", getWorkingContext().getProperties().getProperty("javac.verbose", "no")); |
152 |
0 |
project.setProperty("javac.depend", getWorkingContext().getProperties().getProperty("javac.depend", "off")); |
153 |
|
|
154 |
0 |
project.executeTarget("run"); |
155 |
|
|
156 |
0 |
} catch (DependencyException e) { |
157 |
0 |
logger.error(e); |
158 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
159 |
0 |
} catch (BuildException e) { |
160 |
0 |
logger.error(e); |
161 |
0 |
commandResponse.addEvent(new ExceptionEvent(this, e)); |
162 |
0 |
throw new CommandException(e, CommandException.BUILD_FAILED, class="keyword">new Object[] {getCurrentModule().getName()}); |
163 |
0 |
} catch (ModuleTypeException e) { |
164 |
0 |
logger.error(e); |
165 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
166 |
0 |
} |
167 |
|
|
168 |
0 |
SimpleMessage message = new SimpleMessage(getFrontendMessages().getString("message.MODULE_BUILT"), new Object[] {getCurrentModule().getName()}); |
169 |
0 |
commandResponse.addEvent(new MessageEvent(this, message)); |
170 |
0 |
} |
171 |
|
|
172 |
|
public CommandResponse getCommandResponse() { |
173 |
0 |
return this.commandResponse; |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
} |