628
|
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 |
package com.nokia.maven.scm.provider.hg;
|
|
18 |
|
|
19 |
import java.io.File;
|
|
20 |
|
|
21 |
import org.apache.maven.scm.ScmException;
|
|
22 |
import org.apache.maven.scm.ScmFileStatus;
|
|
23 |
import org.apache.maven.scm.log.ScmLogger;
|
|
24 |
import org.apache.maven.scm.provider.hg.HgUtils;
|
|
25 |
import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
|
|
26 |
import org.apache.maven.scm.provider.hg.command.HgConsumer;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Custom version of the HgUtils helper
|
|
30 |
* class.
|
|
31 |
* It currently implement a fix function
|
|
32 |
* to get the current revision
|
|
33 |
* number.
|
|
34 |
*
|
|
35 |
*/
|
|
36 |
public final class HgUtilsInternal {
|
|
37 |
|
|
38 |
private HgUtilsInternal() {
|
|
39 |
}
|
|
40 |
|
|
41 |
public static long getCurrentRevisionNumber(ScmLogger logger, File workingDir)
|
|
42 |
throws ScmException {
|
|
43 |
|
|
44 |
String[] revCmd = new String[] { HgCommandConstants.REVNO_CMD };
|
|
45 |
HgRevNoConsumer consumer = new HgRevNoConsumer(logger);
|
|
46 |
HgUtils.execute(consumer, logger, workingDir, revCmd);
|
|
47 |
|
|
48 |
return consumer.getCurrentRevisionNumber();
|
|
49 |
}
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Get current (working) revision.
|
|
53 |
* <p/>
|
|
54 |
* Resolve revision to the last integer found in the command output.
|
|
55 |
*/
|
|
56 |
private static class HgRevNoConsumer extends HgConsumer {
|
|
57 |
|
|
58 |
private long revNo;
|
|
59 |
|
|
60 |
HgRevNoConsumer(ScmLogger logger) {
|
|
61 |
super(logger);
|
|
62 |
}
|
|
63 |
|
|
64 |
/**
|
|
65 |
* {@inheritDoc}
|
|
66 |
* Parse the output of the ID command
|
|
67 |
* line will be split by space and first parameter
|
|
68 |
*/
|
|
69 |
@Override
|
|
70 |
public void doConsume(ScmFileStatus status, String line) {
|
|
71 |
String[] elements = line.split("\\s+");
|
|
72 |
if (elements.length > 0) {
|
|
73 |
// If the clone is modified then the id contains the character '+'
|
|
74 |
String strId = elements[0].trim().replace("+", "");
|
|
75 |
if (this.getLogger().isDebugEnabled()) {
|
|
76 |
this.getLogger().debug("Parsing: " + strId);
|
|
77 |
}
|
|
78 |
try {
|
|
79 |
revNo = Long.parseLong(strId, 16);
|
|
80 |
} catch (NumberFormatException e) {
|
|
81 |
this.getLogger().error(e);
|
|
82 |
}
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
long getCurrentRevisionNumber() {
|
|
87 |
return revNo;
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
}
|