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.scm.ant.actions;
|
|
19 |
|
628
|
20 |
import java.util.ArrayList;
|
|
21 |
import java.util.List;
|
|
22 |
|
588
|
23 |
import org.apache.maven.scm.ScmException;
|
628
|
24 |
import org.apache.maven.scm.ScmRevision;
|
|
25 |
import org.apache.maven.scm.ScmTag;
|
588
|
26 |
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
|
|
27 |
import org.apache.maven.scm.manager.ScmManager;
|
|
28 |
import org.apache.maven.scm.repository.ScmRepository;
|
|
29 |
import org.apache.tools.ant.BuildException;
|
|
30 |
|
628
|
31 |
import com.nokia.helium.scm.ant.types.Revision;
|
588
|
32 |
import com.nokia.helium.scm.ant.types.Tag;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Checkout the defined project. Depending on the kind of repository used this
|
|
36 |
* can mean for example the cloning of a repository in the case of Mercurial or the copying of
|
|
37 |
* a repository in the case of SVN.
|
|
38 |
*
|
|
39 |
* <pre>
|
|
40 |
* <hlm:scm verbose="true" scmUrl="scm:${repo.type}:${repo.dir}/test3">
|
|
41 |
* <hlm:checkout baseDir="${repo.dir}/cloned" />
|
|
42 |
* </hlm:scm>
|
|
43 |
* </pre>
|
|
44 |
*
|
|
45 |
* @ant.type name="checkout" category="SCM"
|
|
46 |
*/
|
|
47 |
public class CheckoutAction extends BaseDirectoryScmAction {
|
|
48 |
private List<Tag> tags = new ArrayList<Tag>();
|
|
49 |
private List<Revision> revisions = new ArrayList<Revision>();
|
|
50 |
|
|
51 |
public Tag createTag() {
|
|
52 |
Tag tag = new Tag();
|
|
53 |
add(tag);
|
|
54 |
return tag;
|
|
55 |
}
|
|
56 |
|
|
57 |
public void add(Tag tag) {
|
|
58 |
tags.add(tag);
|
|
59 |
}
|
|
60 |
|
|
61 |
public Revision createRevision() {
|
|
62 |
Revision revision = new Revision();
|
|
63 |
add(revision);
|
|
64 |
return revision;
|
|
65 |
}
|
|
66 |
|
|
67 |
public void add(Revision revision) {
|
|
68 |
revisions.add(revision);
|
|
69 |
}
|
|
70 |
|
|
71 |
@Override
|
|
72 |
public void execute(ScmRepository repository) throws ScmException {
|
|
73 |
ScmManager scmManager = getTask().getScmManager();
|
|
74 |
|
628
|
75 |
if (tags.size() > 1) {
|
588
|
76 |
throw new ScmException(
|
|
77 |
"You can only specify one tag nested element.");
|
628
|
78 |
}
|
588
|
79 |
|
628
|
80 |
if (revisions.size() > 1) {
|
588
|
81 |
throw new ScmException(
|
|
82 |
"You can only specify one revision nested element.");
|
628
|
83 |
}
|
588
|
84 |
|
|
85 |
if ((tags.size() == 1) && (revisions.size() == 1)) {
|
|
86 |
throw new ScmException(
|
|
87 |
"You can not specify nested element 'revision' and 'tag' together.");
|
|
88 |
}
|
|
89 |
|
|
90 |
CheckOutScmResult result;
|
|
91 |
try {
|
|
92 |
if (tags.size() == 1) {
|
|
93 |
result = scmManager.checkOut(repository, getScmFileSet(),
|
|
94 |
new ScmTag(tags.get(0).getName()));
|
|
95 |
} else if (revisions.size() == 1) {
|
|
96 |
result = scmManager.checkOut(repository, getScmFileSet(),
|
|
97 |
new ScmRevision(revisions.get(0).getName()));
|
|
98 |
} else {
|
|
99 |
result = scmManager.checkOut(repository, getScmFileSet());
|
|
100 |
}
|
|
101 |
} catch (ScmException e) {
|
|
102 |
throw new BuildException("SCM checkout action failed: " + e);
|
|
103 |
}
|
|
104 |
|
|
105 |
if (!result.isSuccess()) {
|
|
106 |
throw new BuildException("SCM checkout action failed.");
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|