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 |
|
|
20 |
import java.util.List;
|
|
21 |
|
|
22 |
import org.apache.maven.scm.ScmException;
|
|
23 |
import org.apache.maven.scm.ScmFile;
|
628
|
24 |
import org.apache.maven.scm.ScmRevision;
|
588
|
25 |
import org.apache.maven.scm.ScmTag;
|
|
26 |
import org.apache.maven.scm.command.update.UpdateScmResult;
|
|
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 |
* Update the defined project for a specific revision or tag.
|
|
36 |
*
|
|
37 |
* <pre>
|
|
38 |
* <hlm:scm verbose="true" scmUrl="scm:${repo.type}:${repo.dir}/test1">
|
|
39 |
* <hlm:update basedir="${repo.dir}/test1" />
|
|
40 |
* </hlm:scm>
|
|
41 |
*</pre>
|
|
42 |
*
|
|
43 |
* @ant.type name="update" category="SCM"
|
|
44 |
*/
|
|
45 |
public class UpdateAction extends BaseDirectoryScmAction {
|
|
46 |
|
|
47 |
private Tag tag;
|
|
48 |
private Revision revision;
|
|
49 |
|
|
50 |
public void add(Tag tag) {
|
|
51 |
this.tag = tag;
|
|
52 |
}
|
|
53 |
|
|
54 |
public Tag createTag() {
|
|
55 |
this.tag = new Tag();
|
|
56 |
return this.tag;
|
|
57 |
}
|
|
58 |
|
|
59 |
public void add(Revision revision) {
|
|
60 |
this.revision = revision;
|
|
61 |
}
|
|
62 |
|
|
63 |
public Revision createRevision() {
|
|
64 |
this.revision = new Revision();
|
|
65 |
return this.revision;
|
|
66 |
}
|
|
67 |
|
|
68 |
@Override
|
|
69 |
@SuppressWarnings("unchecked")
|
|
70 |
public void execute(ScmRepository repository) throws ScmException {
|
|
71 |
ScmManager scmManager = getTask().getScmManager();
|
|
72 |
|
|
73 |
UpdateScmResult result;
|
|
74 |
if (tag != null) {
|
|
75 |
result = scmManager.update(repository, getScmFileSet(),
|
|
76 |
new ScmTag(tag.getName()));
|
|
77 |
} else if (revision != null) {
|
|
78 |
result = scmManager.update(repository, getScmFileSet(),
|
|
79 |
new ScmRevision(revision.getName()));
|
|
80 |
} else {
|
|
81 |
result = scmManager.update(repository, getScmFileSet());
|
|
82 |
}
|
|
83 |
|
|
84 |
if (!result.isSuccess()) {
|
|
85 |
throw new BuildException("SCM update action error: "
|
|
86 |
+ result.getProviderMessage());
|
|
87 |
}
|
|
88 |
|
|
89 |
List<ScmFile> files = result.getUpdatedFiles();
|
|
90 |
for (ScmFile scmFile : files) {
|
|
91 |
getTask().log(scmFile.toString());
|
|
92 |
}
|
|
93 |
|
|
94 |
}
|
|
95 |
|
|
96 |
}
|