587
|
1 |
/*
|
|
2 |
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3 |
* or more contributor license agreements. See the NOTICE file
|
|
4 |
* distributed with this work for additional information
|
|
5 |
* regarding copyright ownership. The ASF licenses this file
|
|
6 |
* to you under the Apache License, Version 2.0 (the
|
|
7 |
* "License"); you may not use this file except in compliance
|
|
8 |
* with the License. You may obtain a copy of the License at
|
|
9 |
*
|
|
10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11 |
*
|
|
12 |
* Unless required by applicable law or agreed to in writing,
|
|
13 |
* software distributed under the License is distributed on an
|
|
14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15 |
* KIND, either express or implied. See the License for the
|
|
16 |
* specific language governing permissions and limitations
|
|
17 |
* under the License.
|
|
18 |
*/
|
|
19 |
|
|
20 |
/* Portion Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
|
|
21 |
|
|
22 |
package com.nokia.maven.scm.provider.hg.command.tag;
|
|
23 |
|
|
24 |
import java.io.File;
|
|
25 |
import java.util.ArrayList;
|
|
26 |
import java.util.List;
|
|
27 |
|
|
28 |
import org.apache.maven.scm.ScmException;
|
|
29 |
import org.apache.maven.scm.ScmFile;
|
|
30 |
import org.apache.maven.scm.ScmFileSet;
|
|
31 |
import org.apache.maven.scm.ScmFileStatus;
|
|
32 |
import org.apache.maven.scm.ScmResult;
|
|
33 |
import org.apache.maven.scm.command.Command;
|
|
34 |
import org.apache.maven.scm.command.tag.AbstractTagCommand;
|
|
35 |
import org.apache.maven.scm.command.tag.TagScmResult;
|
|
36 |
import org.apache.maven.scm.provider.ScmProviderRepository;
|
|
37 |
import org.apache.maven.scm.provider.hg.HgUtils;
|
|
38 |
import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
|
|
39 |
import org.apache.maven.scm.provider.hg.command.HgConsumer;
|
|
40 |
import org.apache.maven.scm.provider.hg.command.inventory.HgListConsumer;
|
|
41 |
import org.apache.maven.scm.provider.hg.command.tag.HgTagConsumer;
|
|
42 |
import org.codehaus.plexus.util.StringUtils;
|
|
43 |
|
628
|
44 |
import com.nokia.maven.scm.provider.hg.repository.HgScmProviderRepository;
|
|
45 |
|
587
|
46 |
/**
|
|
47 |
* Tag
|
|
48 |
*
|
|
49 |
* @author <a href="mailto:ryan@darksleep.com">ryan daum</a>
|
|
50 |
* @version $Id: HgTagCommand.java 686566 2008-08-16 21:52:46Z olamy $
|
|
51 |
*/
|
|
52 |
public class HgTagCommand extends AbstractTagCommand implements Command {
|
|
53 |
/** {@inheritDoc} */
|
|
54 |
@SuppressWarnings("unchecked")
|
628
|
55 |
protected ScmResult executeTagCommand(ScmProviderRepository scmProviderRepository,
|
|
56 |
ScmFileSet fileSet, String tag, String level) throws ScmException {
|
587
|
57 |
if (tag == null || StringUtils.isEmpty(tag.trim())) {
|
|
58 |
throw new ScmException("tag must be specified");
|
|
59 |
}
|
|
60 |
|
|
61 |
if (fileSet.getFileList().size() != 0) {
|
628
|
62 |
throw new ScmException("This provider doesn't support tagging subsets of a directory");
|
587
|
63 |
}
|
|
64 |
|
|
65 |
File workingDir = fileSet.getBasedir();
|
|
66 |
|
|
67 |
// build the command
|
|
68 |
String[] tagCmd;
|
|
69 |
if (level.equals(new String("local"))) {
|
|
70 |
tagCmd = new String[] { HgCommandConstants.TAG_CMD, "--local",
|
628
|
71 |
HgCommandConstants.MESSAGE_OPTION, "[maven-scm] copy for tag " + tag, tag };
|
|
72 |
}
|
|
73 |
else {
|
|
74 |
tagCmd = new String[] { HgCommandConstants.TAG_CMD, HgCommandConstants.MESSAGE_OPTION,
|
|
75 |
"[maven-scm] copy for tag " + tag, tag };
|
587
|
76 |
}
|
|
77 |
// keep the command about in string form for reporting
|
|
78 |
StringBuffer cmd = joinCmd(tagCmd);
|
|
79 |
|
|
80 |
HgTagConsumer consumer = new HgTagConsumer(getLogger());
|
628
|
81 |
ScmResult result = HgUtils.execute(consumer, getLogger(), workingDir, tagCmd);
|
587
|
82 |
HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
|
|
83 |
if (result.isSuccess()) {
|
|
84 |
// now push
|
|
85 |
// Push to parent branch if any
|
628
|
86 |
if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
|
|
87 |
String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, repository.getURI() };
|
|
88 |
result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
|
587
|
89 |
}
|
628
|
90 |
}
|
|
91 |
else {
|
|
92 |
throw new ScmException("Error while executing command " + cmd.toString());
|
587
|
93 |
}
|
|
94 |
|
|
95 |
// do an inventory to return the files tagged (all of them)
|
|
96 |
String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
|
|
97 |
HgListConsumer listconsumer = new HgListConsumer(getLogger());
|
628
|
98 |
result = HgUtils.execute(listconsumer, getLogger(), fileSet.getBasedir(), listCmd);
|
587
|
99 |
if (result.isSuccess()) {
|
|
100 |
List<ScmFile> files = listconsumer.getFiles();
|
|
101 |
ArrayList<ScmFile> fileList = new ArrayList<ScmFile>();
|
|
102 |
for (ScmFile scmFile : files) {
|
628
|
103 |
|
587
|
104 |
if (!scmFile.getPath().endsWith(".hgtags")) {
|
628
|
105 |
fileList.add(new ScmFile(scmFile.getPath(), ScmFileStatus.TAGGED));
|
587
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
return new TagScmResult(fileList, result);
|
628
|
110 |
}
|
|
111 |
else {
|
|
112 |
throw new ScmException("Error while executing command " + cmd.toString());
|
587
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
private StringBuffer joinCmd(String[] cmds) {
|
|
117 |
StringBuffer result = new StringBuffer();
|
|
118 |
int i = 0;
|
|
119 |
for (String cmd : cmds) {
|
588
|
120 |
String cmdStr = cmd;
|
|
121 |
result.append(cmdStr);
|
587
|
122 |
if (i < cmds.length - 1) {
|
|
123 |
result.append(" ");
|
|
124 |
}
|
|
125 |
i += 1;
|
|
126 |
}
|
|
127 |
return result;
|
|
128 |
}
|
|
129 |
}
|