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.io.File;
|
|
21 |
|
|
22 |
import org.apache.maven.scm.ScmException;
|
|
23 |
import org.apache.maven.scm.ScmFileSet;
|
|
24 |
import org.apache.maven.scm.command.tag.TagScmResult;
|
|
25 |
import org.apache.maven.scm.repository.ScmRepository;
|
|
26 |
import org.apache.tools.ant.BuildException;
|
|
27 |
|
|
28 |
import com.nokia.maven.scm.manager.ExtendedScmManager;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* This action will tag current repository revision using a specific name.
|
|
32 |
*
|
|
33 |
* <pre>
|
|
34 |
* <hlm:scm verbose="true" scmUrl="scm:${repo.type}:${repo.dir}/test1">
|
|
35 |
* <hlm:tag baseDir="${repo.dir}/test1" name="0.0.1" />
|
|
36 |
* </hlm:scm>
|
|
37 |
* </pre>
|
|
38 |
*
|
|
39 |
* @ant.type name="tag" category="SCM"
|
|
40 |
*/
|
|
41 |
public class TagAction extends BaseDirectoryScmAction {
|
|
42 |
private String name;
|
|
43 |
private String level = "normal";
|
|
44 |
|
|
45 |
/**
|
|
46 |
* String that will be used to tag the current revision.
|
|
47 |
*
|
|
48 |
* @param name
|
|
49 |
* Name of the tag
|
|
50 |
* @ant.required
|
|
51 |
*/
|
|
52 |
public void setName(String name) {
|
|
53 |
this.name = name;
|
|
54 |
}
|
|
55 |
|
|
56 |
/**
|
|
57 |
* String that will be used to determine tag types, eg. local.
|
|
58 |
*
|
|
59 |
* @param level
|
|
60 |
* Level of the tag eg.local
|
|
61 |
* @ant.not-required
|
|
62 |
*/
|
|
63 |
public void setLevel(String level) {
|
|
64 |
this.level = level;
|
|
65 |
}
|
|
66 |
|
|
67 |
@Override
|
|
68 |
public void execute(ScmRepository repository) throws ScmException {
|
|
69 |
TagScmResult result;
|
|
70 |
|
628
|
71 |
if (name == null) {
|
588
|
72 |
throw new BuildException("'name' attribute is not defined.");
|
628
|
73 |
}
|
588
|
74 |
|
628
|
75 |
if (getBasedir() == null) {
|
588
|
76 |
throw new BuildException("'basedir' attribute is not defined.");
|
628
|
77 |
}
|
588
|
78 |
|
|
79 |
try {
|
|
80 |
ExtendedScmManager scmManager = (ExtendedScmManager) getTask()
|
|
81 |
.getScmManager();
|
|
82 |
if (level.equals(new String("local"))) {
|
|
83 |
result = scmManager.tag(repository, new ScmFileSet(new File(
|
|
84 |
getBasedir())), name, level);
|
|
85 |
} else {
|
|
86 |
result = scmManager.tag(repository, new ScmFileSet(new File(
|
|
87 |
getBasedir())), name);
|
|
88 |
}
|
|
89 |
|
|
90 |
if (!result.isSuccess()) {
|
|
91 |
throw new BuildException("SCM tag action error: "
|
|
92 |
+ result.getProviderMessage());
|
|
93 |
}
|
|
94 |
getTask().log("Tag '" + name + "' has been created successfully.");
|
|
95 |
} catch (ScmException e) {
|
|
96 |
throw new BuildException("SCM tag action failed: " + e.toString());
|
|
97 |
}
|
|
98 |
|
|
99 |
}
|
|
100 |
}
|