Search in sources :

Example 1 with ListScmResult

use of org.apache.maven.scm.command.list.ListScmResult in project maven-scm by apache.

the class JGitListCommand method executeListCommand.

@Override
protected ListScmResult executeListCommand(ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive, ScmVersion scmVersion) throws ScmException {
    Git git = null;
    try {
        git = JGitUtils.openRepo(fileSet.getBasedir());
        CredentialsProvider credentials = JGitUtils.prepareSession(getLogger(), git, (GitScmProviderRepository) repo);
        List<ScmFile> list = new ArrayList<ScmFile>();
        Collection<Ref> lsResult = git.lsRemote().setCredentialsProvider(credentials).call();
        for (Ref ref : lsResult) {
            getLogger().debug(ref.getObjectId().getName() + "  " + ref.getTarget().getName());
            list.add(new ScmFile(ref.getName(), ScmFileStatus.CHECKED_IN));
        }
        return new ListScmResult("JGit ls-remote", list);
    } catch (Exception e) {
        throw new ScmException("JGit ls-remote failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ScmException(org.apache.maven.scm.ScmException) Git(org.eclipse.jgit.api.Git) ArrayList(java.util.ArrayList) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile)

Example 2 with ListScmResult

use of org.apache.maven.scm.command.list.ListScmResult in project maven-scm by apache.

the class LocalListCommand method executeListCommand.

/**
 * {@inheritDoc}
 */
protected ListScmResult executeListCommand(ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive, ScmVersion version) throws ScmException {
    if (version != null) {
        throw new ScmException("The local scm doesn't support tags.");
    }
    LocalScmProviderRepository repository = (LocalScmProviderRepository) repo;
    File root = new File(repository.getRoot());
    String module = repository.getModule();
    File source = new File(root, module);
    if (!root.exists()) {
        throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
    }
    if (!source.exists()) {
        throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
    }
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Listing files of '" + source.getAbsolutePath() + "'.");
    }
    try {
        if (fileSet.getFileList() == null || fileSet.getFileList().isEmpty()) {
            return new LocalListScmResult(null, getFiles(source, source, recursive));
        } else {
            List<ScmFile> files = new ArrayList<ScmFile>();
            Iterator<File> it = fileSet.getFileList().iterator();
            while (it.hasNext()) {
                File file = (File) it.next();
                files.addAll(getFiles(source, new File(source, file.getPath()), recursive));
            }
            return new LocalListScmResult(null, files);
        }
    } catch (Exception e) {
        return new ListScmResult(null, "The svn command failed.", e.getMessage(), false);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) ArrayList(java.util.ArrayList) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile)

Example 3 with ListScmResult

use of org.apache.maven.scm.command.list.ListScmResult in project maven-scm by apache.

the class LocalMkdirCommandTckTest method testMkdirCommandMkdirUrl.

public void testMkdirCommandMkdirUrl() throws Exception {
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy(), new File(getMissingDirectory()));
    MkdirScmResult result = getScmManager().mkdir(getScmRepository(), fileSet, "Mkdir message", false);
    assertResultIsSuccess(result);
    ListScmResult listResult = getScmManager().list(getScmRepository(), fileSet, true, null);
    assertTrue("Directory should have been found.", listResult.isSuccess());
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) File(java.io.File)

Example 4 with ListScmResult

use of org.apache.maven.scm.command.list.ListScmResult in project maven-scm by apache.

the class LocalMkdirCommandTckTest method testMkdirCommandDirAlreadyAdded.

public void testMkdirCommandDirAlreadyAdded() throws Exception {
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy(), new File(getMissingDirectory()));
    MkdirScmResult result = getScmManager().mkdir(getScmRepository(), fileSet, "Mkdir message", false);
    assertResultIsSuccess(result);
    ListScmResult listResult = getScmManager().list(getScmRepository(), fileSet, true, null);
    assertTrue("Directory should have been found.", listResult.isSuccess());
    // add the directory again
    result = getScmManager().mkdir(getScmRepository(), fileSet, "Mkdir message", false);
    assertFalse(result.isSuccess());
    printOutputError(result);
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) File(java.io.File)

Example 5 with ListScmResult

use of org.apache.maven.scm.command.list.ListScmResult in project maven-scm by apache.

the class LocalScmProvider method list.

/**
 * {@inheritDoc}
 */
protected ListScmResult list(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    LocalListCommand command = new LocalListCommand();
    command.setLogger(getLogger());
    return (ListScmResult) command.execute(repository, fileSet, parameters);
}
Also used : LocalListCommand(org.apache.maven.scm.provider.local.command.list.LocalListCommand) ListScmResult(org.apache.maven.scm.command.list.ListScmResult)

Aggregations

ListScmResult (org.apache.maven.scm.command.list.ListScmResult)22 ScmException (org.apache.maven.scm.ScmException)8 File (java.io.File)7 ScmFile (org.apache.maven.scm.ScmFile)5 ScmFileSet (org.apache.maven.scm.ScmFileSet)5 MkdirScmResult (org.apache.maven.scm.command.mkdir.MkdirScmResult)4 ArrayList (java.util.ArrayList)3 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)3 ScmResult (org.apache.maven.scm.ScmResult)2 ScmProvider (org.apache.maven.scm.provider.ScmProvider)2 CvsListConsumer (org.apache.maven.scm.provider.cvslib.command.list.CvsListConsumer)2 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)2 Commandline (org.codehaus.plexus.util.cli.Commandline)2 APIException (com.mks.api.response.APIException)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 CvsLogListener (org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener)1