587
|
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.maven.scm.provider.hg.command.update;
|
|
19 |
|
628
|
20 |
import java.io.File;
|
|
21 |
import java.util.ArrayList;
|
|
22 |
import java.util.List;
|
|
23 |
import java.util.Map;
|
|
24 |
|
|
25 |
import org.apache.maven.scm.ScmException;
|
|
26 |
import org.apache.maven.scm.ScmFile;
|
|
27 |
import org.apache.maven.scm.ScmFileSet;
|
|
28 |
import org.apache.maven.scm.ScmFileStatus;
|
|
29 |
import org.apache.maven.scm.ScmResult;
|
|
30 |
import org.apache.maven.scm.ScmVersion;
|
|
31 |
import org.apache.maven.scm.command.update.UpdateScmResult;
|
|
32 |
import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
|
587
|
33 |
import org.apache.maven.scm.provider.ScmProviderRepository;
|
|
34 |
import org.apache.maven.scm.provider.hg.HgUtils;
|
|
35 |
import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
|
|
36 |
import org.apache.maven.scm.provider.hg.command.HgConsumer;
|
|
37 |
import org.apache.maven.scm.provider.hg.command.diff.HgDiffConsumer;
|
|
38 |
import org.codehaus.plexus.util.StringUtils;
|
|
39 |
|
628
|
40 |
import com.nokia.maven.scm.provider.hg.HgUtilsInternal;
|
587
|
41 |
|
|
42 |
/**
|
|
43 |
*/
|
|
44 |
public class HgUpdateCommand extends
|
628
|
45 |
org.apache.maven.scm.provider.hg.command.update.HgUpdateCommand {
|
587
|
46 |
|
|
47 |
/** {@inheritDoc} */
|
|
48 |
@SuppressWarnings("unchecked")
|
628
|
49 |
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet,
|
|
50 |
ScmVersion tag) throws ScmException {
|
587
|
51 |
File workingDir = fileSet.getBasedir();
|
|
52 |
|
|
53 |
// Find changes from last revision
|
628
|
54 |
long previousRevision = HgUtilsInternal.getCurrentRevisionNumber(getLogger(), workingDir);
|
587
|
55 |
// Update branch
|
628
|
56 |
String[] updateCmd = new String[] { "update", HgCommandConstants.REVISION_OPTION,
|
|
57 |
tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip" };
|
|
58 |
ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, updateCmd);
|
587
|
59 |
|
|
60 |
if (!updateResult.isSuccess()) {
|
|
61 |
return new UpdateScmResult(null, null, updateResult);
|
|
62 |
}
|
|
63 |
|
|
64 |
// Find changes from last revision
|
628
|
65 |
long currentRevision = HgUtilsInternal.getCurrentRevisionNumber(getLogger(),
|
587
|
66 |
workingDir);
|
628
|
67 |
|
|
68 |
// No point of calculating a delta if nothing has been updated.
|
|
69 |
getLogger().debug("Changeset before update: " + String.format("%012x", previousRevision));
|
|
70 |
getLogger().debug("Changeset after update: " + String.format("%012x", currentRevision));
|
|
71 |
if (previousRevision == currentRevision) {
|
|
72 |
return new UpdateScmResultWithRevision(new ArrayList<ScmFile>(), new ArrayList(), String
|
|
73 |
.valueOf(currentRevision), updateResult);
|
|
74 |
}
|
|
75 |
|
587
|
76 |
List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
|
|
77 |
List changes = new ArrayList();
|
|
78 |
String[] diffCmd = null;
|
|
79 |
if (currentRevision == 0) {
|
628
|
80 |
diffCmd = new String[] { HgCommandConstants.DIFF_CMD, "-c", "" + String.format("%012x", currentRevision)};
|
587
|
81 |
} else {
|
|
82 |
diffCmd = new String[] { HgCommandConstants.DIFF_CMD,
|
628
|
83 |
HgCommandConstants.REVISION_OPTION, "" + String.format("%012x", previousRevision),
|
|
84 |
HgCommandConstants.REVISION_OPTION, "" + String.format("%012x", currentRevision)};
|
587
|
85 |
}
|
628
|
86 |
HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(), workingDir);
|
|
87 |
updateResult = HgUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
|
587
|
88 |
|
|
89 |
// Now translate between diff and update file status
|
|
90 |
List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
|
|
91 |
Map diffChanges = diffConsumer.getDifferences();
|
|
92 |
for (ScmFile diffFile : diffFiles) {
|
|
93 |
changes.add(diffChanges.get(diffFile.getPath()));
|
|
94 |
if (diffFile.getStatus() == ScmFileStatus.MODIFIED) {
|
|
95 |
updatedFiles.add(new ScmFile(diffFile.getPath(), ScmFileStatus.PATCHED));
|
|
96 |
} else {
|
|
97 |
updatedFiles.add(diffFile);
|
|
98 |
}
|
|
99 |
}
|
628
|
100 |
|
587
|
101 |
return new UpdateScmResultWithRevision(updatedFiles, changes, String
|
628
|
102 |
.valueOf(currentRevision), new ScmResult(updateResult.getCommandLine(),
|
|
103 |
updateResult.getCommandOutput(), updateResult.getProviderMessage(), true));
|
587
|
104 |
}
|
|
105 |
|
|
106 |
}
|