587
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
|
2 |
<!--
|
|
3 |
============================================================================
|
|
4 |
Name : preparation.antlib.xml
|
|
5 |
Part of : Helium
|
|
6 |
|
|
7 |
Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
8 |
All rights reserved.
|
|
9 |
This component and the accompanying materials are made available
|
|
10 |
under the terms of the License "Eclipse Public License v1.0"
|
|
11 |
which accompanies this distribution, and is available
|
|
12 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
13 |
|
|
14 |
Initial Contributors:
|
|
15 |
Nokia Corporation - initial contribution.
|
|
16 |
|
|
17 |
Contributors:
|
|
18 |
|
|
19 |
Description:
|
|
20 |
|
|
21 |
============================================================================
|
|
22 |
-->
|
|
23 |
<!--* @package preparation -->
|
|
24 |
<antlib xmlns:hlm="http://www.nokia.com/helium">
|
|
25 |
|
|
26 |
<!--
|
|
27 |
This task will copy the content of the its nested fileset in parallel. The todir attribute defines
|
|
28 |
the output directory. 'threads' defines how many copy you would like in parallel, and verbose
|
|
29 |
defines if you want the copying to be logged.
|
|
30 |
-->
|
628
|
31 |
<scriptdef name="parallelCopy" language="beanshell" uri="http://www.nokia.com/helium">
|
587
|
32 |
<attribute name="todir" />
|
|
33 |
<attribute name="threads" />
|
|
34 |
<attribute name="verbose" />
|
|
35 |
<attribute name="overwrite" />
|
|
36 |
<element name="resourceset" type="http://www.nokia.com/helium:resourceSet"/>
|
|
37 |
<![CDATA[
|
|
38 |
import org.apache.tools.ant.taskdefs.Parallel;
|
|
39 |
import org.apache.tools.ant.taskdefs.Copy;
|
|
40 |
import org.apache.tools.ant.BuildException;
|
|
41 |
import org.apache.tools.ant.taskdefs.Mkdir;
|
|
42 |
import java.io.File;
|
|
43 |
|
|
44 |
int threads = 4;
|
|
45 |
String verbose = "false";
|
|
46 |
String overwrite = "false";
|
|
47 |
|
|
48 |
if (attributes.get("todir") == null) {
|
|
49 |
throw new BuildException("'todir' attribute is not defined.");
|
|
50 |
}
|
|
51 |
|
|
52 |
if (attributes.get("threads") != null) {
|
|
53 |
threads = Integer.parseInt(attributes.get("threads"));
|
|
54 |
if (threads < 0) {
|
|
55 |
throw new BuildException("Invalid thread number: " + threads);
|
|
56 |
}
|
|
57 |
}
|
|
58 |
if (attributes.get("verbose") != null) {
|
628
|
59 |
verbose = attributes.get("verbose");
|
587
|
60 |
}
|
|
61 |
if (attributes.get("overwrite") != null) {
|
628
|
62 |
overwrite = attributes.get("overwrite");
|
587
|
63 |
}
|
628
|
64 |
|
587
|
65 |
// Creating the output dir
|
|
66 |
Mkdir mkdir = new Mkdir();
|
|
67 |
mkdir.setProject(project);
|
|
68 |
mkdir.setTaskName(self.getTaskName());
|
|
69 |
mkdir.setDir(new File(attributes.get("todir")));
|
|
70 |
mkdir.execute();
|
|
71 |
|
|
72 |
Parallel pt = new Parallel();
|
|
73 |
pt.setProject(project);
|
|
74 |
pt.setTaskName(self.getTaskName());
|
|
75 |
pt.setThreadCount(threads);
|
|
76 |
if (elements.get("resourceset") != null) {
|
|
77 |
resourceSets = elements.get("resourceset");
|
|
78 |
for (int rsi = 0 ; rsi < resourceSets.size() ; rsi++) {
|
|
79 |
resourceCollections = resourceSets.get(rsi).getData();
|
|
80 |
for (int i = 0 ; i < resourceCollections.size() ; i++) {
|
|
81 |
self.log("Creating copy task...");
|
|
82 |
Copy copy = new Copy();
|
|
83 |
copy.setProject(project);
|
|
84 |
copy.setTaskName(self.getTaskName());
|
|
85 |
copy.setTodir(new File(attributes.get("todir")));
|
|
86 |
copy.add(resourceCollections.get(i));
|
|
87 |
copy.setVerbose(new Boolean(verbose).booleanValue());
|
|
88 |
copy.setOverwrite(new Boolean(overwrite).booleanValue());
|
|
89 |
pt.addTask(copy);
|
628
|
90 |
}
|
587
|
91 |
}
|
|
92 |
}
|
|
93 |
self.log("Starting parallel copying...");
|
|
94 |
pt.execute();
|
|
95 |
self.log("Copying completed.");
|
628
|
96 |
]]>
|
587
|
97 |
</scriptdef>
|
|
98 |
|
|
99 |
<!--
|
|
100 |
This task will unzip each group (represented as path element) in parallel. But the content of each
|
|
101 |
group will be unzipped sequentially.
|
|
102 |
-->
|
|
103 |
<scriptdef language="beanshell" name="parallelUnzip" uri="http://www.nokia.com/helium">
|
|
104 |
<attribute name="todir" />
|
|
105 |
<attribute name="threads" />
|
|
106 |
<attribute name="failonerror" />
|
|
107 |
<attribute name="logdir" />
|
|
108 |
<element name="resourceset" type="http://www.nokia.com/helium:resourceSet"/>
|
|
109 |
<![CDATA[
|
|
110 |
import org.apache.tools.ant.taskdefs.Sequential;
|
|
111 |
import org.apache.tools.ant.taskdefs.Parallel;
|
|
112 |
import org.apache.tools.ant.taskdefs.ExecTask;
|
|
113 |
import org.apache.tools.ant.BuildException;
|
|
114 |
import org.apache.tools.ant.taskdefs.Mkdir;
|
|
115 |
import java.io.File;
|
|
116 |
|
|
117 |
int threads = 4;
|
|
118 |
String failonerror = "true";
|
|
119 |
String logDir = attributes.get("logdir");
|
|
120 |
|
|
121 |
if (attributes.get("todir") == null) {
|
|
122 |
throw new BuildException("'todir' attribute is not defined.");
|
|
123 |
}
|
|
124 |
|
|
125 |
if (attributes.get("threads") != null) {
|
|
126 |
threads = Integer.parseInt(attributes.get("threads"));
|
|
127 |
if (threads < 0) {
|
|
128 |
throw new BuildException("Invalid thread number: " + threads);
|
|
129 |
}
|
|
130 |
}
|
|
131 |
if (attributes.get("failonerror") != null) {
|
|
132 |
failonerror = attributes.get("failonerror");
|
|
133 |
}
|
|
134 |
|
|
135 |
// Creating the output dir
|
|
136 |
Mkdir mkdir = new Mkdir();
|
|
137 |
mkdir.setProject(project);
|
|
138 |
mkdir.setTaskName(self.getTaskName());
|
|
139 |
mkdir.setDir(new File(attributes.get("todir")));
|
|
140 |
mkdir.execute();
|
|
141 |
|
|
142 |
if (logDir != null) {
|
|
143 |
Mkdir mkdir = new Mkdir();
|
|
144 |
mkdir.setProject(project);
|
|
145 |
mkdir.setTaskName(self.getTaskName());
|
|
146 |
mkdir.setDir(new File(logDir));
|
|
147 |
mkdir.execute();
|
|
148 |
}
|
|
149 |
|
|
150 |
// parallel
|
|
151 |
Parallel pt = new Parallel();
|
|
152 |
pt.setProject(project);
|
|
153 |
pt.setTaskName(self.getTaskName());
|
|
154 |
pt.setThreadCount(threads);
|
|
155 |
|
|
156 |
if (elements.get("resourceset") != null) {
|
|
157 |
resourceSets = elements.get("resourceset");
|
|
158 |
for (int rsi = 0 ; rsi < resourceSets.size() ; rsi++) {
|
|
159 |
resourceCollections = resourceSets.get(rsi).getData();
|
|
160 |
for (int i = 0 ; i < resourceCollections.size() ; i++) {
|
|
161 |
Sequential seq = new Sequential();
|
|
162 |
seq.setProject(project);
|
|
163 |
seq.setTaskName(self.getTaskName());
|
|
164 |
iterator = resourceCollections.get(i).iterator();
|
|
165 |
while (iterator.hasNext()) {
|
|
166 |
resource = iterator.next();
|
|
167 |
self.log("Creating 7zip task...");
|
|
168 |
ExecTask exec = new ExecTask();
|
|
169 |
exec.setProject(project);
|
|
170 |
exec.setTaskName(self.getTaskName());
|
|
171 |
exec.setExecutable("7za");
|
|
172 |
if (logDir != null) {
|
|
173 |
exec.setOutput(new File(logDir, new File(resource.toString()).getName() + ".log"));
|
|
174 |
}
|
|
175 |
exec.setDir(new File(attributes.get("todir")));
|
|
176 |
exec.setFailonerror(new Boolean(failonerror).booleanValue());
|
|
177 |
exec.createArg().setValue("x");
|
|
178 |
exec.createArg().setFile(new File(resource.toString()));
|
|
179 |
exec.createArg().setValue("-y");
|
|
180 |
seq.addTask(exec);
|
|
181 |
}
|
|
182 |
pt.addTask(seq);
|
|
183 |
}
|
|
184 |
}
|
|
185 |
}
|
|
186 |
self.log("Starting parallel unzipping...");
|
|
187 |
pt.execute();
|
|
188 |
self.log("Unzipping completed.");
|
628
|
189 |
]]>
|
587
|
190 |
</scriptdef>
|
|
191 |
|
628
|
192 |
</antlib>
|
|
193 |
|