Search in sources :

Example 1 with CheckOutScmResult

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

the class AccuRevCheckOutCommandTest method testReCheckoutExistingWorkspaceSameBasis.

@Test
public void testReCheckoutExistingWorkspaceSameBasis() throws Exception {
    // Set the info result to return a workspace that already exists
    info.setWorkSpace("someOldStream_someUser");
    info.setBasis("myStream");
    info.setTop(basedir.getAbsolutePath());
    List<File> emptyList = Collections.emptyList();
    when(accurev.pop(basedir, null)).thenReturn(emptyList);
    List<File> updatedFiles = Collections.singletonList(new File("updated/file"));
    when(accurev.update(basedir, null)).thenReturn(updatedFiles);
    AccuRevCheckOutCommand command = new AccuRevCheckOutCommand(getLogger());
    CheckOutScmResult result = command.checkout(repo, new ScmFileSet(basedir), new CommandParameters());
    verify(accurev).pop(basedir, null);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.getRelativePathProjectDirectory(), is("/project/dir"));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 2 with CheckOutScmResult

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

the class AccuRevCheckOutCommandTest method testCheckoutToVersionExistingWorkspace.

@Test
public void testCheckoutToVersionExistingWorkspace() throws Exception {
    // Set the info result to return a workspace that already exists
    info.setWorkSpace("someOldStream_someUser");
    info.setBasis("myStream");
    info.setTop(basedir.getAbsolutePath());
    List<File> emptyList = Collections.emptyList();
    when(accurev.pop(basedir, null)).thenReturn(emptyList);
    List<File> updatedFiles = Collections.singletonList(new File("updated/file"));
    when(accurev.update(basedir, "12")).thenReturn(updatedFiles);
    AccuRevCheckOutCommand command = new AccuRevCheckOutCommand(getLogger());
    CommandParameters parameters = new CommandParameters();
    parameters.setScmVersion(CommandParameter.SCM_VERSION, new ScmRevision("myStream/12"));
    CheckOutScmResult result = command.checkout(repo, new ScmFileSet(basedir), parameters);
    verify(accurev).pop(basedir, null);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.getCheckedOutFiles().size(), is(1));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmRevision(org.apache.maven.scm.ScmRevision) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 3 with CheckOutScmResult

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

the class AccuRevExportCommandTest method testNonPersistentCheckoutUsesExport.

@Test
public void testNonPersistentCheckoutUsesExport() throws // This is same expectations as above, but using checkout method with setPersist = false.
AccuRevException, ScmException {
    // Setup info to return a stream rooted somewhere around here...
    info.setWorkSpace("myStream_me");
    info.setBasis("someStream");
    info.setTop(basedir.getParent());
    when(accurev.info(basedir)).thenReturn(info);
    when(accurev.stat(basedir)).thenReturn(null);
    when(accurev.rmws("myStream_me")).thenReturn(Boolean.TRUE);
    List<File> poppedFiles = Collections.singletonList(new File("exported/file"));
    when(accurev.popExternal(eq(basedir), eq("mySnapShot"), eq("now"), (Collection<File>) argThat(hasItem(new File("/./project/dir"))))).thenReturn(poppedFiles);
    when(accurev.reactivate("myStream_me")).thenReturn(Boolean.TRUE);
    repo.setPersistCheckout(false);
    ScmRepository scmRepo = new ScmRepository("accurev", repo);
    AccuRevScmProvider provider = new AccuRevScmProvider();
    CheckOutScmResult result = provider.checkOut(scmRepo, new ScmFileSet(basedir), new ScmTag("mySnapShot"));
    verify(accurev).rmws("myStream_me");
    verify(accurev).reactivate("myStream_me");
    assertTrue(result.isSuccess());
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) AccuRevScmProvider(org.apache.maven.scm.provider.accurev.AccuRevScmProvider) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) File(java.io.File) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 4 with CheckOutScmResult

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

the class JGitCheckOutCommand 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/>
 * {@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");
    }
    Git git = null;
    try {
        ProgressMonitor monitor = JGitUtils.getMonitor(getLogger());
        String branch = version != null ? version.getName() : null;
        if (StringUtils.isBlank(branch)) {
            branch = Constants.MASTER;
        }
        getLogger().debug("try checkout of branch: " + branch);
        if (!fileSet.getBasedir().exists() || !(new File(fileSet.getBasedir(), ".git").exists())) {
            if (fileSet.getBasedir().exists()) {
                // git refuses to clone otherwise
                fileSet.getBasedir().delete();
            }
            // FIXME only if windauze
            WindowCacheConfig cfg = new WindowCacheConfig();
            cfg.setPackedGitMMAP(false);
            cfg.install();
            // no git repo seems to exist, let's clone the original repo
            CredentialsProvider credentials = JGitUtils.getCredentials((GitScmProviderRepository) repo);
            getLogger().info("cloning [" + branch + "] to " + fileSet.getBasedir());
            CloneCommand command = Git.cloneRepository().setURI(repository.getFetchUrl());
            command.setCredentialsProvider(credentials).setBranch(branch).setDirectory(fileSet.getBasedir());
            command.setProgressMonitor(monitor);
            git = command.call();
        }
        JGitRemoteInfoCommand remoteInfoCommand = new JGitRemoteInfoCommand();
        remoteInfoCommand.setLogger(getLogger());
        RemoteInfoScmResult result = remoteInfoCommand.executeRemoteInfoCommand(repository, fileSet, null);
        if (git == null) {
            // deliberately not using JGitUtils.openRepo(), the caller told us exactly where to checkout
            git = Git.open(fileSet.getBasedir());
        }
        if (fileSet.getBasedir().exists() && new File(fileSet.getBasedir(), ".git").exists() && result.getBranches().size() > 0) {
            // git repo exists, so we must git-pull the changes
            CredentialsProvider credentials = JGitUtils.prepareSession(getLogger(), git, repository);
            if (version != null && StringUtils.isNotEmpty(version.getName()) && (version instanceof ScmTag)) {
                // A tag will not be pulled but we only fetch all the commits from the upstream repo
                // This is done because checking out a tag might not happen on the current branch
                // but create a 'detached HEAD'.
                // In fact, a tag in git may be in multiple branches. This occurs if
                // you create a branch after the tag has been created
                getLogger().debug("fetch...");
                git.fetch().setCredentialsProvider(credentials).setProgressMonitor(monitor).call();
            } else {
                getLogger().debug("pull...");
                git.pull().setCredentialsProvider(credentials).setProgressMonitor(monitor).call();
            }
        }
        Set<String> localBranchNames = JGitBranchCommand.getShortLocalBranchNames(git);
        if (version instanceof ScmTag) {
            getLogger().info("checkout tag [" + branch + "] at " + fileSet.getBasedir());
            git.checkout().setName(branch).call();
        } else if (localBranchNames.contains(branch)) {
            getLogger().info("checkout [" + branch + "] at " + fileSet.getBasedir());
            git.checkout().setName(branch).call();
        } else {
            getLogger().info("checkout remote branch [" + branch + "] at " + fileSet.getBasedir());
            git.checkout().setName(branch).setCreateBranch(true).setStartPoint(Constants.DEFAULT_REMOTE_NAME + "/" + branch).call();
        }
        RevWalk revWalk = new RevWalk(git.getRepository());
        RevCommit commit = revWalk.parseCommit(git.getRepository().resolve(Constants.HEAD));
        revWalk.release();
        final TreeWalk walk = new TreeWalk(git.getRepository());
        // drop the first empty tree, which we do not need here
        walk.reset();
        walk.setRecursive(true);
        walk.addTree(commit.getTree());
        List<ScmFile> listedFiles = new ArrayList<ScmFile>();
        while (walk.next()) {
            listedFiles.add(new ScmFile(walk.getPathString(), ScmFileStatus.CHECKED_OUT));
        }
        walk.release();
        getLogger().debug("current branch: " + git.getRepository().getBranch());
        return new CheckOutScmResult("checkout via JGit", listedFiles);
    } catch (Exception e) {
        throw new ScmException("JGit checkout failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) ScmException(org.apache.maven.scm.ScmException) WindowCacheConfig(org.eclipse.jgit.storage.file.WindowCacheConfig) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) ArrayList(java.util.ArrayList) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) RevWalk(org.eclipse.jgit.revwalk.RevWalk) JGitRemoteInfoCommand(org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand) RemoteInfoScmResult(org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile) ProgressMonitor(org.eclipse.jgit.lib.ProgressMonitor) Git(org.eclipse.jgit.api.Git) ScmTag(org.apache.maven.scm.ScmTag) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with CheckOutScmResult

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

the class ScmTckTestCase method checkOut.

/**
 * Convenience method to check out files from the repository
 */
protected CheckOutScmResult checkOut(File workingDirectory, ScmRepository repository) throws Exception {
    CheckOutScmResult result = getScmManager().getProviderByUrl(getScmUrl()).checkOut(repository, new ScmFileSet(workingDirectory), (ScmVersion) null);
    assertTrue("Check result was successful, output: " + result.getCommandOutput(), result.isSuccess());
    return result;
}
Also used : CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

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