587
|
1 |
/*
|
628
|
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 |
*/
|
587
|
17 |
|
|
18 |
package com.nokia.maven.scm.provider.hg.command.init;
|
|
19 |
|
|
20 |
import java.io.File;
|
|
21 |
|
|
22 |
import org.apache.log4j.Logger;
|
|
23 |
import org.apache.maven.scm.CommandParameters;
|
|
24 |
import org.apache.maven.scm.ScmException;
|
|
25 |
import org.apache.maven.scm.ScmFileSet;
|
|
26 |
import org.apache.maven.scm.ScmResult;
|
|
27 |
import org.apache.maven.scm.command.AbstractCommand;
|
|
28 |
import org.apache.maven.scm.command.Command;
|
|
29 |
import org.apache.maven.scm.provider.ScmProviderRepository;
|
|
30 |
import org.apache.maven.scm.provider.hg.HgUtils;
|
|
31 |
import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
|
|
32 |
|
|
33 |
import com.nokia.maven.scm.command.init.InitScmResult;
|
628
|
34 |
import com.nokia.maven.scm.provider.hg.repository.HgScmProviderRepository;
|
587
|
35 |
|
|
36 |
/**
|
|
37 |
* 'hg init' command implementation.
|
|
38 |
*/
|
|
39 |
public class HgInitCommand extends AbstractCommand implements Command {
|
628
|
40 |
|
587
|
41 |
private static Logger log = Logger.getLogger(HgInitCommand.class);
|
|
42 |
|
|
43 |
@Override
|
628
|
44 |
protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet basedir,
|
|
45 |
CommandParameters args) throws ScmException {
|
587
|
46 |
return executeInitCommand(repository);
|
|
47 |
}
|
|
48 |
|
628
|
49 |
public InitScmResult executeInitCommand(ScmProviderRepository repository) throws ScmException {
|
587
|
50 |
// Get the directory in which to create a new repository. Only local
|
|
51 |
// filesystems supported.
|
|
52 |
log.info("executeInitCommand: " + repository);
|
|
53 |
HgScmProviderRepository hgRepo = (HgScmProviderRepository) repository;
|
|
54 |
String uri = hgRepo.getURI();
|
|
55 |
log.info(uri);
|
|
56 |
File hgRepoDir = new File(uri);
|
|
57 |
File hgRepoRootDir = hgRepoDir.getParentFile();
|
|
58 |
|
|
59 |
if (!hgRepoRootDir.exists()) {
|
|
60 |
boolean workingDirReady = hgRepoRootDir.mkdirs();
|
|
61 |
if (!workingDirReady) {
|
628
|
62 |
throw new ScmException("Could not initiate test branch at: " + hgRepoRootDir);
|
587
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
// Create and run the command
|
628
|
67 |
String[] initCmd = new String[] { HgCommandConstants.INIT_CMD, hgRepoDir.getName() };
|
587
|
68 |
ScmResult result = HgUtils.execute(hgRepoRootDir, initCmd);
|
628
|
69 |
return new InitScmResult(result.getCommandLine(), result.getProviderMessage(), result.getCommandOutput(), result.isSuccess());
|
587
|
70 |
}
|
|
71 |
}
|