Search in sources :

Example 51 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class GitCheckOutCommand method executeCheckOutCommand.

/**
 * For git, the given repository is a remote one.
 * We have to clone it first if the working directory does not contain a git repo yet,
 * otherwise we have to git-pull it.
 * <p/>
 * TODO We currently assume a '.git' directory, so this does not work for --bare repos
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) throws ScmException {
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;
    if (GitScmProviderRepository.PROTOCOL_FILE.equals(repository.getFetchInfo().getProtocol()) && repository.getFetchInfo().getPath().indexOf(fileSet.getBasedir().getPath()) >= 0) {
        throw new ScmException("remote repository must not be the working directory");
    }
    int exitCode;
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    String lastCommandLine = "git-nothing-to-do";
    if (!fileSet.getBasedir().exists() || !(new File(fileSet.getBasedir(), ".git").exists())) {
        if (fileSet.getBasedir().exists()) {
            // git refuses to clone otherwise
            fileSet.getBasedir().delete();
        }
        // no git repo seems to exist, let's clone the original repo
        Commandline clClone = createCloneCommand(repository, fileSet.getBasedir(), version, shallow);
        exitCode = GitCommandLineUtils.execute(clClone, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new CheckOutScmResult(clClone.toString(), "The git-clone command failed.", stderr.getOutput(), false);
        }
        lastCommandLine = clClone.toString();
    }
    GitRemoteInfoCommand gitRemoteInfoCommand = new GitRemoteInfoCommand();
    gitRemoteInfoCommand.setLogger(getLogger());
    RemoteInfoScmResult result = gitRemoteInfoCommand.executeRemoteInfoCommand(repository, null, null);
    if (fileSet.getBasedir().exists() && new File(fileSet.getBasedir(), ".git").exists() && result.getBranches().size() > 0) {
        // git repo exists, so we must git-pull the changes
        Commandline clPull = createPullCommand(repository, fileSet.getBasedir(), version);
        exitCode = GitCommandLineUtils.execute(clPull, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new CheckOutScmResult(clPull.toString(), "The git-pull command failed.", stderr.getOutput(), false);
        }
        lastCommandLine = clPull.toString();
        // and now lets do the git-checkout itself
        Commandline clCheckout = createCommandLine(repository, fileSet.getBasedir(), version);
        exitCode = GitCommandLineUtils.execute(clCheckout, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new CheckOutScmResult(clCheckout.toString(), "The git-checkout command failed.", stderr.getOutput(), false);
        }
        lastCommandLine = clCheckout.toString();
    }
    // and now search for the files
    GitListConsumer listConsumer = new GitListConsumer(getLogger(), fileSet.getBasedir(), ScmFileStatus.CHECKED_IN);
    Commandline clList = GitListCommand.createCommandLine(repository, fileSet.getBasedir());
    exitCode = GitCommandLineUtils.execute(clList, listConsumer, stderr, getLogger());
    if (exitCode != 0) {
        return new CheckOutScmResult(clList.toString(), "The git-ls-files command failed.", stderr.getOutput(), false);
    }
    return new CheckOutScmResult(lastCommandLine, listConsumer.getListedFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) GitRemoteInfoCommand(org.apache.maven.scm.provider.git.gitexe.command.remoteinfo.GitRemoteInfoCommand) RemoteInfoScmResult(org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) GitListConsumer(org.apache.maven.scm.provider.git.gitexe.command.list.GitListConsumer) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) File(java.io.File)

Example 52 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class GitCheckInCommandNoBranchTest method testCheckinNoBranch.

public void testCheckinNoBranch() throws Exception {
    if (!ScmTestCase.isSystemCmd("git")) {
        System.out.println("skip test which git native executable in path");
        return;
    }
    File repo_orig = new File("src/test/resources/repository_no_branch");
    File repo = getTestFile("target/git_copy");
    FileUtils.deleteDirectory(repo);
    FileUtils.copyDirectoryStructure(repo_orig, repo);
    ScmRepository scmRepository = getScmManager().makeScmRepository("scm:git:file:///" + repo.getAbsolutePath());
    CheckOutScmResult checkOutScmResult = checkoutRepo(scmRepository);
    assertEquals(0, checkOutScmResult.getCheckedOutFiles().size());
    File f = new File(workingDirectory.getAbsolutePath() + File.separator + "pom.xml");
    FileUtils.fileWrite(f.getAbsolutePath(), "toto");
    ScmFileSet scmFileSet = new ScmFileSet(workingDirectory, new File("pom.xml"));
    AddScmResult addResult = getScmManager().add(scmRepository, scmFileSet);
    assertResultIsSuccess(addResult);
    CheckInScmResult checkInScmResult = getScmManager().checkIn(scmRepository, scmFileSet, "commit");
    assertResultIsSuccess(checkInScmResult);
    assertEquals(1, checkInScmResult.getCheckedInFiles().size());
    assertEquals("pom.xml", checkInScmResult.getCheckedInFiles().get(0).getPath());
    checkOutScmResult = checkoutRepo(scmRepository);
    assertResultIsSuccess(checkOutScmResult);
    assertEquals(1, checkOutScmResult.getCheckedOutFiles().size());
    assertEquals("pom.xml", checkOutScmResult.getCheckedOutFiles().get(0).getPath());
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 53 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class GitCheckInCommandTest method checkoutRepoInto.

// ----------------------------------------------------------------------
// 
// ----------------------------------------------------------------------
private CheckOutScmResult checkoutRepoInto(File workingCopy, ScmRepository scmRepository) throws Exception {
    FileUtils.deleteDirectory(workingCopy);
    workingCopy.mkdir();
    CheckOutScmResult result = getScmManager().checkOut(scmRepository, new ScmFileSet(workingCopy), (ScmVersion) null);
    assertResultIsSuccess(result);
    return result;
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Example 54 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class GitExeCheckOutCommandNoBranchTest method checkoutRepo.

protected CheckOutScmResult checkoutRepo() throws Exception {
    CheckOutScmResult result = getScmManager().checkOut(scmRepository, new ScmFileSet(workingDirectory), (ScmVersion) null);
    assertResultIsSuccess(result);
    return result;
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Example 55 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project plugin-compat-tester by jenkinsci.

the class ExampleMultiParent method action.

/*
     * No check implementation is required because transformedPlugins
     * returns your specific list.
     */
/**
 * Point to the shared location.  Check if this needs to be downloaded.
 */
public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception {
    PluginCompatTesterConfig config = (PluginCompatTesterConfig) moreInfo.get("config");
    Plugin currentPlugin = (Plugin) moreInfo.get("plugin");
    // Determine if we need to run the download; only run for first identified plugin in the series
    if (firstRun) {
        System.out.println("Preparing for Multimodule checkout.");
        // Checkout to the parent directory. All other processes will be on the child directory
        File parentPath = new File(config.workDirectory.getAbsolutePath() + "/" + parentName);
        System.out.println("Checking out from SCM connection URL : " + parentUrl + " (" + parentName + "-" + currentPlugin.version + ")");
        ScmManager scmManager = SCMManagerFactory.getInstance().createScmManager();
        ScmRepository repository = scmManager.makeScmRepository(parentUrl);
        CheckOutScmResult result = scmManager.checkOut(repository, new ScmFileSet(parentPath), new ScmTag(parentName + "-" + currentPlugin.version));
        if (!result.isSuccess()) {
            throw new RuntimeException(result.getProviderMessage() + "||" + result.getCommandOutput());
        }
    }
    // Checkout already happened, don't run through again
    moreInfo.put("runCheckout", false);
    firstRun = false;
    // Change the "download"" directory; after download, it's simply used for reference
    File childPath = new File(config.workDirectory.getAbsolutePath() + "/" + parentName + "/" + currentPlugin.name);
    moreInfo.put("checkoutDir", childPath);
    return moreInfo;
}
Also used : PluginCompatTesterConfig(org.jenkins.tools.test.model.PluginCompatTesterConfig) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) ScmManager(org.apache.maven.scm.manager.ScmManager) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) File(java.io.File) Plugin(hudson.model.UpdateSite.Plugin)

Aggregations

CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)57 File (java.io.File)24 ScmFileSet (org.apache.maven.scm.ScmFileSet)20 ScmFile (org.apache.maven.scm.ScmFile)14 ScmException (org.apache.maven.scm.ScmException)11 ScmTag (org.apache.maven.scm.ScmTag)9 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)9 Commandline (org.codehaus.plexus.util.cli.Commandline)8 Test (org.junit.Test)8 CommandParameters (org.apache.maven.scm.CommandParameters)7 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)7 IOException (java.io.IOException)6 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)6 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)6 ScmManager (org.apache.maven.scm.manager.ScmManager)5 ScmRepository (org.apache.maven.scm.repository.ScmRepository)5 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)5 ArrayList (java.util.ArrayList)4 ScmResult (org.apache.maven.scm.ScmResult)4 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)3