Search in sources :

Example 6 with ListScmResult

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

the class HgListCommand method executeListCommand.

/**
 * {@inheritDoc}
 */
protected ListScmResult executeListCommand(ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion scmVersion) throws ScmException {
    // 
    File workingDir = fileSet.getBasedir();
    // build the command
    String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
    // keep the command about in string form for reporting
    StringBuilder cmd = new StringBuilder();
    for (int i = 0; i < listCmd.length; i++) {
        String s = listCmd[i];
        cmd.append(s);
        if (i < listCmd.length - 1) {
            cmd.append(" ");
        }
    }
    HgListConsumer consumer = new HgListConsumer(getLogger());
    ScmResult result = HgUtils.execute(consumer, getLogger(), workingDir, listCmd);
    if (result.isSuccess()) {
        return new ListScmResult(consumer.getFiles(), result);
    } else {
        throw new ScmException("Error while executing command " + cmd.toString());
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) ScmResult(org.apache.maven.scm.ScmResult) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) File(java.io.File)

Example 7 with ListScmResult

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

the class CvsJavaListCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected ListScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsLogListener logListener = new CvsLogListener();
    CvsListConsumer consumer = new CvsListConsumer(getLogger());
    try {
        boolean isSuccess = CvsConnection.processCommand(cl.getArguments(), cl.getWorkingDirectory().getAbsolutePath(), logListener, getLogger());
        if (!isSuccess) {
            return new ListScmResult(cl.toString(), "The cvs command failed.", logListener.getStderr().toString(), false);
        }
        BufferedReader stream = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(logListener.getStdout().toString().getBytes())));
        String line;
        while ((line = stream.readLine()) != null) {
            consumer.consumeLine(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return new ListScmResult(cl.toString(), "The cvs command failed.", logListener.getStderr().toString(), false);
    }
    return new ListScmResult(cl.toString(), consumer.getEntries());
}
Also used : CvsLogListener(org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener) InputStreamReader(java.io.InputStreamReader) CvsListConsumer(org.apache.maven.scm.provider.cvslib.command.list.CvsListConsumer) ByteArrayInputStream(java.io.ByteArrayInputStream) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) BufferedReader(java.io.BufferedReader) ScmException(org.apache.maven.scm.ScmException)

Example 8 with ListScmResult

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

the class ListMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException {
    super.execute();
    try {
        ScmRepository repository = getScmRepository();
        ListScmResult result = getScmManager().list(repository, getFileSet(), recursive, getScmVersion(scmVersionType, scmVersion));
        checkResult(result);
        if (result.getFiles() != null) {
            for (ScmFile scmFile : result.getFiles()) {
                getLog().info(scmFile.getPath());
            }
        }
    } catch (ScmException e) {
        throw new MojoExecutionException("Cannot run list command : ", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot run list command : ", e);
    }
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) IOException(java.io.IOException) ScmFile(org.apache.maven.scm.ScmFile)

Example 9 with ListScmResult

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

the class IntegrityListCommand method executeListCommand.

/**
 * {@inheritDoc}
 */
@Override
public ListScmResult executeListCommand(ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion scmVersion) throws ScmException {
    ListScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    getLogger().info("Listing all files in project " + iRepo.getConfigruationPath());
    try {
        // Get a listing for all the members in the project...
        List<Member> projectMembers = iRepo.getProject().listFiles(fileSet.getBasedir().getAbsolutePath());
        // Initialize the list of ScmFile objects for the ListScmResult
        List<ScmFile> scmFileList = new ArrayList<ScmFile>();
        for (Iterator<Member> it = projectMembers.iterator(); it.hasNext(); ) {
            Member siMember = it.next();
            scmFileList.add(new ScmFile(siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN));
        }
        result = new ListScmResult(scmFileList, new ScmResult("si viewproject", "", "", true));
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
        result = new ListScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) ScmResult(org.apache.maven.scm.ScmResult) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) ArrayList(java.util.ArrayList) Member(org.apache.maven.scm.provider.integrity.Member) ScmFile(org.apache.maven.scm.ScmFile)

Example 10 with ListScmResult

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

the class ListCommandTckTest method testListCommandUnexistantFileTest.

public void testListCommandUnexistantFileTest() throws Exception {
    ScmFileSet fileSet = new ScmFileSet(new File("."), new File("/void"));
    ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
    ListScmResult result = provider.list(getScmRepository(), fileSet, false, (ScmVersion) null);
    assertFalse("Found file when shouldn't", result.isSuccess());
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmFileSet(org.apache.maven.scm.ScmFileSet) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

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