1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.tools.anttasks; |
11 | |
|
12 | |
import org.apache.tools.ant.BuildException; |
13 | |
import org.apache.tools.ant.Task; |
14 | |
import org.apache.tools.ant.util.FileUtils; |
15 | |
|
16 | |
import java.io.File; |
17 | |
import java.io.IOException; |
18 | |
import java.text.MessageFormat; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class MuleDeploy extends Task |
32 | |
{ |
33 | |
|
34 | |
private static final String MULE_HOME_PROPERTY = "dir.mule.home"; |
35 | |
|
36 | |
|
37 | |
private File applicationFile; |
38 | |
|
39 | |
|
40 | |
private File muleHome; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public void setApplicationFile(File applicationFile) |
46 | |
{ |
47 | 0 | this.applicationFile = applicationFile; |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
@Override |
54 | |
public void execute() throws BuildException |
55 | |
{ |
56 | 0 | FileChecker checker = new FileChecker(getLocation()); |
57 | 0 | checker.checkFile(applicationFile, "application file", false, false); |
58 | 0 | File home = getMuleHome(); |
59 | 0 | checker.checkFile(home, "mule home directory", true, false); |
60 | 0 | File appsDir = new File(home, "apps"); |
61 | 0 | checker.checkFile(appsDir, "mule apps directory", true, true); |
62 | |
try |
63 | |
{ |
64 | 0 | File destFile = new File(appsDir, applicationFile.getName()); |
65 | 0 | FileUtils.getFileUtils().copyFile(applicationFile, destFile, null, true); |
66 | |
} |
67 | 0 | catch (IOException ex) |
68 | |
{ |
69 | 0 | throw new BuildException( |
70 | |
MessageFormat.format("Problem copying Mule application file {0} to {1}", applicationFile, appsDir), |
71 | |
ex, getLocation()); |
72 | 0 | } |
73 | 0 | } |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public File getMuleHome() |
79 | |
{ |
80 | 0 | if (muleHome != null) |
81 | |
{ |
82 | 0 | return muleHome; |
83 | |
} |
84 | 0 | String home = getProject().getProperty(MULE_HOME_PROPERTY); |
85 | 0 | return home == null ? null : new File(home); |
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void setMuleHome(File muleHome) |
92 | |
{ |
93 | 0 | this.muleHome = muleHome; |
94 | 0 | } |
95 | |
} |
96 | |
|