588
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.ccmtask.ant.taskdefs;
|
|
19 |
|
|
20 |
import java.io.File;
|
|
21 |
import java.io.IOException;
|
|
22 |
import java.net.MalformedURLException;
|
|
23 |
import java.net.URL;
|
|
24 |
import java.util.ArrayList;
|
|
25 |
import java.util.List;
|
|
26 |
import java.util.Vector;
|
|
27 |
import java.util.jar.JarFile;
|
|
28 |
import java.util.zip.ZipEntry;
|
|
29 |
|
628
|
30 |
import org.apache.tools.ant.BuildException;
|
|
31 |
import org.apache.tools.ant.Task;
|
588
|
32 |
import org.python.util.PythonInterpreter;
|
|
33 |
|
|
34 |
import com.nokia.helium.ccmtask.ant.commands.AddTask;
|
|
35 |
import com.nokia.helium.ccmtask.ant.commands.CcmCommand;
|
|
36 |
import com.nokia.helium.ccmtask.ant.commands.ChangeReleaseTag;
|
|
37 |
import com.nokia.helium.ccmtask.ant.commands.Checkout;
|
|
38 |
import com.nokia.helium.ccmtask.ant.commands.Close;
|
628
|
39 |
import com.nokia.helium.ccmtask.ant.commands.CreateReleaseTag;
|
|
40 |
import com.nokia.helium.ccmtask.ant.commands.DeleteReleaseTag;
|
588
|
41 |
import com.nokia.helium.ccmtask.ant.commands.Reconcile;
|
|
42 |
import com.nokia.helium.ccmtask.ant.commands.Role;
|
|
43 |
import com.nokia.helium.ccmtask.ant.commands.Snapshot;
|
|
44 |
import com.nokia.helium.ccmtask.ant.commands.Synchronize;
|
|
45 |
import com.nokia.helium.ccmtask.ant.commands.Update;
|
|
46 |
import com.nokia.helium.ccmtask.ant.commands.Workarea;
|
|
47 |
import com.nokia.helium.ccmtask.ant.types.SessionSet;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Synergy task.
|
|
51 |
* <pre>
|
|
52 |
* <hlm:createSessionMacro database="to1tobet" reference="test.session" />
|
|
53 |
* <hlm:ccm verbose="false">
|
|
54 |
* <hlm:sessionset refid="test.session" />
|
|
55 |
* <hlm:addtask folder="tr1test1#2079">
|
|
56 |
* <task name="tr1test1#5310" />
|
|
57 |
* </hlm:addtask>
|
|
58 |
* <hlm:snapshot project="helium-to1tobet#helium_3.0:project:vc1s60p1#1" dir="c:\test" fast="true" recursive="true" />
|
|
59 |
* <hlm:synchronize project="helium-to1tobet#helium_3.0:project:vc1s60p1#1" recursive="true" />
|
|
60 |
* <hlm:close />
|
|
61 |
* </hlm:ccm>
|
|
62 |
* </pre>
|
|
63 |
* @ant.task category="SCM"
|
|
64 |
*/
|
|
65 |
public class CcmTask extends Task
|
|
66 |
{
|
|
67 |
private String username;
|
|
68 |
|
|
69 |
private String password;
|
|
70 |
|
|
71 |
private List<CcmCommand> commands = new ArrayList<CcmCommand>();
|
|
72 |
private Vector<SessionSet> sessionSets = new Vector<SessionSet>();
|
|
73 |
private boolean verbose;
|
|
74 |
|
|
75 |
public void setVerbose(boolean value) {
|
|
76 |
verbose = value;
|
|
77 |
}
|
|
78 |
|
|
79 |
public boolean getVerbose() {
|
|
80 |
return verbose;
|
|
81 |
}
|
|
82 |
|
|
83 |
public String getUsername()
|
|
84 |
{
|
|
85 |
return username;
|
|
86 |
}
|
|
87 |
|
|
88 |
public final void setUsername(final String username)
|
|
89 |
{
|
|
90 |
this.username = username;
|
|
91 |
}
|
|
92 |
|
|
93 |
public String getPassword()
|
|
94 |
{
|
|
95 |
return password;
|
|
96 |
}
|
|
97 |
|
|
98 |
public final void setPassword(final String password)
|
|
99 |
{
|
|
100 |
this.password = password;
|
|
101 |
}
|
|
102 |
|
|
103 |
public CcmCommand[] getCommands()
|
|
104 |
{
|
|
105 |
return commands.toArray(new CcmCommand[commands.size()]);
|
|
106 |
}
|
|
107 |
|
|
108 |
public void addUpdate(Update a)
|
|
109 |
{
|
|
110 |
addCommand(a);
|
|
111 |
}
|
|
112 |
|
|
113 |
public void addSynchronize(Synchronize a)
|
|
114 |
{
|
|
115 |
addCommand(a);
|
|
116 |
}
|
|
117 |
|
|
118 |
public void addReconcile(Reconcile a)
|
|
119 |
{
|
|
120 |
addCommand(a);
|
|
121 |
}
|
|
122 |
|
|
123 |
public void addSnapshot(Snapshot a)
|
|
124 |
{
|
|
125 |
addCommand(a);
|
|
126 |
}
|
|
127 |
|
|
128 |
public void addChangeReleaseTag(ChangeReleaseTag a)
|
|
129 |
{
|
|
130 |
addCommand(a);
|
|
131 |
}
|
|
132 |
|
|
133 |
public void addCreateReleaseTag(CreateReleaseTag a)
|
|
134 |
{
|
|
135 |
addCommand(a);
|
|
136 |
}
|
|
137 |
|
|
138 |
public void addDeleteReleaseTag(DeleteReleaseTag a)
|
|
139 |
{
|
|
140 |
addCommand(a);
|
|
141 |
}
|
|
142 |
|
|
143 |
public void addCheckout(Checkout a)
|
|
144 |
{
|
|
145 |
addCommand(a);
|
|
146 |
}
|
|
147 |
|
|
148 |
public void addWorkarea(Workarea a)
|
|
149 |
{
|
|
150 |
addCommand(a);
|
|
151 |
}
|
|
152 |
|
|
153 |
public void addRole(Role a)
|
|
154 |
{
|
|
155 |
addCommand(a);
|
|
156 |
}
|
|
157 |
|
|
158 |
private void addCommand(CcmCommand cmd)
|
|
159 |
{
|
|
160 |
cmd.setTask(this);
|
|
161 |
commands.add(cmd);
|
|
162 |
}
|
|
163 |
|
|
164 |
public AddTask createAddTask()
|
|
165 |
{
|
|
166 |
AddTask cmd = new AddTask();
|
|
167 |
addCommand(cmd);
|
|
168 |
return cmd;
|
|
169 |
}
|
|
170 |
|
|
171 |
public Role createRole()
|
|
172 |
{
|
|
173 |
Role cmd = new Role();
|
|
174 |
addCommand(cmd);
|
|
175 |
return cmd;
|
|
176 |
}
|
|
177 |
|
|
178 |
public Close createClose()
|
|
179 |
{
|
|
180 |
Close cmd = new Close();
|
|
181 |
addCommand(cmd);
|
|
182 |
return cmd;
|
|
183 |
}
|
|
184 |
|
|
185 |
public SessionSet createSessionSet()
|
|
186 |
{
|
|
187 |
SessionSet sessionSet = new SessionSet();
|
|
188 |
sessionSets.add(sessionSet);
|
|
189 |
return sessionSet;
|
|
190 |
}
|
|
191 |
|
|
192 |
public SessionSet[] getSessionSets() {
|
|
193 |
SessionSet[] result = new SessionSet[sessionSets.size()];
|
|
194 |
sessionSets.copyInto(result);
|
|
195 |
return result;
|
|
196 |
}
|
|
197 |
|
|
198 |
public final void execute()
|
|
199 |
{
|
|
200 |
File jar = getJarFile();
|
|
201 |
if (jar == null) {
|
|
202 |
throw new BuildException("Could not find the jar file for class " + this.getClass().getCanonicalName());
|
|
203 |
}
|
|
204 |
try {
|
|
205 |
JarFile jarFile = new JarFile(jar);
|
|
206 |
String entryName = this.getClass().getPackage().getName().replace('.', '/') + "/ccmtask.py";
|
|
207 |
ZipEntry entry = jarFile.getEntry(entryName);
|
|
208 |
if (entry == null) {
|
|
209 |
throw new BuildException("CcmTask internal error: Could not find the following entry: " + entryName);
|
|
210 |
}
|
|
211 |
PythonInterpreter pi = new PythonInterpreter();
|
|
212 |
pi.set("java_ccmtask", this);
|
|
213 |
pi.set("project", getProject());
|
|
214 |
pi.execfile(jarFile.getInputStream(entry), "ccmtask.py");
|
|
215 |
} catch (IOException e) {
|
|
216 |
throw new BuildException(e.getMessage(), e);
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Returns the jar file name containing this class
|
|
222 |
* @return a File object or null if not found.
|
|
223 |
*/
|
|
224 |
protected File getJarFile() {
|
|
225 |
URL url = this.getClass().getClassLoader().getResource(this.getClass().getName().replace('.', '/') + ".class");
|
|
226 |
if (url.getProtocol().equals("jar") && url.getPath().contains("!/")) {
|
|
227 |
String fileUrl = url.getPath().split("!/")[0];
|
|
228 |
try {
|
|
229 |
return new File(new URL(fileUrl).getPath());
|
|
230 |
} catch (MalformedURLException e) {
|
|
231 |
throw new BuildException("Error determining the jar file where "
|
|
232 |
+ this.getClass().getName() + " is located.", e);
|
|
233 |
}
|
|
234 |
}
|
|
235 |
return null;
|
|
236 |
}
|
|
237 |
}
|