1 package org.andromda.ant.task;
2
3 import java.io.FileNotFoundException;
4 import java.net.URL;
5 import org.andromda.core.AndroMDAServer;
6 import org.andromda.core.configuration.Configuration;
7 import org.apache.commons.lang.exception.ExceptionUtils;
8 import org.apache.tools.ant.BuildException;
9 import org.apache.tools.ant.taskdefs.MatchingTask;
10
11
12
13
14
15
16
17
18
19
20 public class AndroMDAServerStopTask
21 extends MatchingTask
22 {
23
24
25
26 static
27 {
28 initializeContextClassLoader();
29 }
30
31
32
33
34 private URL configurationUri;
35
36
37
38
39
40
41 public void setConfigurationUri(final URL configurationUri)
42 {
43 this.configurationUri = configurationUri;
44 }
45
46
47
48
49
50
51
52
53
54
55
56
57
58 public void execute()
59 throws BuildException
60 {
61
62
63 initializeContextClassLoader();
64 try
65 {
66 if (this.configurationUri == null)
67 {
68 throw new BuildException("Configuration is not a valid URI --> '" + this.configurationUri + '\'');
69 }
70
71
72 final Configuration configuration = Configuration.getInstance(this.configurationUri);
73
74 final AndroMDAServer andromdaServer = AndroMDAServer.newInstance();
75 if (andromdaServer != null)
76 {
77 andromdaServer.stop(configuration);
78 }
79 }
80 catch (Throwable throwable)
81 {
82 final Throwable cause = ExceptionUtils.getCause(throwable);
83 if (cause != null)
84 {
85 throwable = cause;
86 }
87 if (throwable instanceof FileNotFoundException)
88 {
89 throw new BuildException("No configuration could be loaded from --> '" + configurationUri + '\'');
90 }
91 throw new BuildException(throwable);
92 }
93 finally
94 {
95
96
97
98 Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
99 }
100 }
101
102
103
104
105
106 private static void initializeContextClassLoader()
107 {
108 Thread.currentThread().setContextClassLoader(AndroMDAServerStopTask.class.getClassLoader());
109 }
110 }