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 |
import java.util.ArrayList;
|
|
22 |
import java.util.List;
|
|
23 |
|
|
24 |
import org.apache.maven.scm.ScmException;
|
|
25 |
import org.apache.maven.scm.ScmTag;
|
|
26 |
import org.apache.maven.scm.command.export.ExportScmResult;
|
|
27 |
import org.apache.maven.scm.manager.ScmManager;
|
|
28 |
import org.apache.maven.scm.repository.ScmRepository;
|
|
29 |
import org.apache.tools.ant.BuildException;
|
|
30 |
|
|
31 |
import com.nokia.helium.scm.ant.types.Tag;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Get a snapshot of a particular revision into a folder.
|
|
35 |
*
|
|
36 |
* <pre>
|
|
37 |
* <hlm:scm verbose="true" scmUrl="scm:${repo.type}:${repo.dir}/test2">
|
|
38 |
* <hlm:export basedir="${repo.dir}/test2" destpath="${repo.dir}/export" />
|
|
39 |
* </hlm:scm>
|
|
40 |
* </pre>
|
|
41 |
*
|
|
42 |
* @ant.type name="export" category="SCM"
|
|
43 |
*/
|
|
44 |
public class ExportAction extends BaseDirectoryScmAction {
|
|
45 |
|
|
46 |
private File destPath;
|
|
47 |
private List<Tag> tags = new ArrayList<Tag>();
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Create a tag sub-element.
|
|
51 |
* @return the tag element.
|
|
52 |
*/
|
|
53 |
public Tag createTag() {
|
|
54 |
Tag tag = new Tag();
|
|
55 |
add(tag);
|
|
56 |
return tag;
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Add a tag.
|
|
61 |
* @param tag
|
|
62 |
*/
|
|
63 |
public void add(Tag tag) {
|
|
64 |
tags.add(tag);
|
|
65 |
}
|
|
66 |
|
|
67 |
/**
|
|
68 |
* {@inheritDoc}
|
|
69 |
*/
|
|
70 |
@Override
|
|
71 |
public void execute(ScmRepository repository) throws ScmException {
|
|
72 |
ScmManager scmManager = getTask().getScmManager();
|
|
73 |
|
628
|
74 |
if (getDestPath() == null) {
|
588
|
75 |
throw new ScmException("destPath attribute has not been provided.");
|
628
|
76 |
}
|
|
77 |
|
|
78 |
if (tags.size() > 1) {
|
588
|
79 |
throw new ScmException(
|
|
80 |
"You can only specify one tag nested element.");
|
628
|
81 |
}
|
|
82 |
|
588
|
83 |
ExportScmResult result;
|
|
84 |
try {
|
|
85 |
if (tags.size() == 0) {
|
|
86 |
getTask().log(
|
|
87 |
"Exporting " + getScmFileSet().getBasedir() + " under "
|
|
88 |
+ getDestPath().getAbsolutePath() + ".");
|
|
89 |
result = scmManager.export(repository, getScmFileSet(),
|
|
90 |
getDestPath().getAbsolutePath());
|
|
91 |
} else {
|
|
92 |
String tagName = tags.get(0).getName();
|
|
93 |
getTask().log(
|
|
94 |
"Exporting revision " + tagName + " of "
|
|
95 |
+ getScmFileSet().getBasedir() + " under "
|
|
96 |
+ getDestPath().getAbsolutePath() + ".");
|
|
97 |
result = scmManager.export(repository, getScmFileSet(),
|
|
98 |
new ScmTag(tagName), getDestPath().getAbsolutePath());
|
|
99 |
}
|
|
100 |
} catch (ScmException e) {
|
|
101 |
throw new BuildException("SCM export action failed: " + e);
|
|
102 |
}
|
|
103 |
if (!result.isSuccess()) {
|
|
104 |
throw new BuildException("SCM export action failed: "
|
|
105 |
+ result.getProviderMessage());
|
|
106 |
}
|
|
107 |
// Dump created files.
|
|
108 |
for (Object file : result.getExportedFiles().toArray()) {
|
|
109 |
getTask().log(file.toString());
|
|
110 |
}
|
|
111 |
}
|
|
112 |
|
|
113 |
public File getDestPath() {
|
|
114 |
return destPath;
|
|
115 |
}
|
|
116 |
|
|
117 |
public void setDestPath(File destPath) {
|
|
118 |
this.destPath = destPath;
|
|
119 |
}
|
|
120 |
|
|
121 |
}
|