Search in sources :

Example 6 with ExportScmResult

use of org.apache.maven.scm.command.export.ExportScmResult in project maven-scm by apache.

the class AccuRevScmProvider method checkout.

@Override
protected CheckOutScmResult checkout(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    // workaround deprecated behaviour
    // TODO pull up to AbstractScmProvider
    AccuRevScmProviderRepository accuRevRepo = (AccuRevScmProviderRepository) repository;
    if (!repository.isPersistCheckout() && accuRevRepo.shouldUseExportForNonPersistentCheckout()) {
        ExportScmResult result = export(repository, fileSet, parameters);
        if (result.isSuccess()) {
            return new CheckOutScmResult(result.getCommandLine(), result.getExportedFiles(), accuRevRepo.getExportRelativePath());
        } else {
            return new CheckOutScmResult(result.getCommandLine(), result.getProviderMessage(), result.getCommandOutput(), false);
        }
    }
    AccuRevCheckOutCommand command = new AccuRevCheckOutCommand(getLogger());
    return command.checkout(repository, fileSet, parameters);
}
Also used : AccuRevCheckOutCommand(org.apache.maven.scm.provider.accurev.command.checkout.AccuRevCheckOutCommand) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Example 7 with ExportScmResult

use of org.apache.maven.scm.command.export.ExportScmResult in project maven-scm by apache.

the class ExportMojo method export.

protected void export() throws MojoExecutionException {
    if (this.exportDirectory.getPath().contains("${project.basedir}")) {
        // project.basedir is not set under maven 3.x when run without a project
        this.exportDirectory = new File(this.getBasedir(), "target/export");
    }
    try {
        ScmRepository repository = getScmRepository();
        try {
            if (this.exportDirectory.exists()) {
                this.getLog().info("Removing " + this.exportDirectory);
                FileUtils.deleteDirectory(this.exportDirectory);
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot remove " + getExportDirectory());
        }
        if (!this.exportDirectory.mkdirs()) {
            throw new MojoExecutionException("Cannot create " + this.exportDirectory);
        }
        ExportScmResult result = getScmManager().export(repository, new ScmFileSet(this.exportDirectory.getAbsoluteFile()), getScmVersion(scmVersionType, scmVersion));
        checkResult(result);
        handleExcludesIncludesAfterCheckoutAndExport(this.exportDirectory);
    } catch (ScmException e) {
        throw new MojoExecutionException("Cannot run export command : ", e);
    }
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) IOException(java.io.IOException) File(java.io.File)

Example 8 with ExportScmResult

use of org.apache.maven.scm.command.export.ExportScmResult in project maven-scm by apache.

the class IntegrityExportCommand method executeExportCommand.

/**
 * {@inheritDoc}
 */
@Override
public ExportScmResult executeExportCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, String outputDirectory) throws ScmException {
    // First lets figure out where we need to export files to...
    String exportDir = outputDirectory;
    exportDir = ((null != exportDir && exportDir.length() > 0) ? exportDir : fileSet.getBasedir().getAbsolutePath());
    // Let the user know where we're going to be exporting the files...
    getLogger().info("Attempting to export files to " + exportDir);
    ExportScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        // Lets set our overall export success flag
        boolean exportSuccess = true;
        // Perform a fresh checkout of each file in the member list...
        List<Member> projectMembers = iRepo.getProject().listFiles(exportDir);
        // Initialize the list of files we actually exported...
        List<ScmFile> scmFileList = new ArrayList<ScmFile>();
        for (Iterator<Member> it = projectMembers.iterator(); it.hasNext(); ) {
            Member siMember = it.next();
            try {
                getLogger().info("Attempting to export file: " + siMember.getTargetFilePath() + " at revision " + siMember.getRevision());
                siMember.checkout(iRepo.getAPISession());
                scmFileList.add(new ScmFile(siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN));
            } catch (APIException ae) {
                exportSuccess = false;
                ExceptionHandler eh = new ExceptionHandler(ae);
                getLogger().error("MKS API Exception: " + eh.getMessage());
                getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
            }
        }
        // Lets advice the user that we've checked out all the members
        getLogger().info("Exported " + scmFileList.size() + " files out of a total of " + projectMembers.size() + " files!");
        if (exportSuccess) {
            result = new ExportScmResult("si co", scmFileList);
        } else {
            result = new ExportScmResult("si co", "Failed to export all files!", "", exportSuccess);
        }
    } 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 ExportScmResult(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) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) Member(org.apache.maven.scm.provider.integrity.Member) ScmFile(org.apache.maven.scm.ScmFile)

Example 9 with ExportScmResult

use of org.apache.maven.scm.command.export.ExportScmResult in project maven-scm by apache.

the class AccuRevExportCommandTest method testExportToVersionPre490.

@Test
public void testExportToVersionPre490() throws Exception {
    // info defaults to no workspace...
    info.setWorkSpace(null);
    when(accurev.info(basedir)).thenReturn(info);
    // A version that does not support pop -t
    when(accurev.getClientVersion()).thenReturn("4.7.4b");
    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);
    AccuRevExportCommand command = new AccuRevExportCommand(getLogger());
    CommandParameters params = new CommandParameters();
    params.setScmVersion(CommandParameter.SCM_VERSION, new ScmTag("mySnapShot/676"));
    ExportScmResult result = command.export(repo, new ScmFileSet(basedir), params);
    assertTrue(result.isSuccess());
    assertHasScmFile(result.getExportedFiles(), "exported/file", ScmFileStatus.CHECKED_OUT);
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) 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 10 with ExportScmResult

use of org.apache.maven.scm.command.export.ExportScmResult in project maven-scm by apache.

the class AccuRevExportCommandTest method testExportToVersion490.

@Test
public void testExportToVersion490() throws Exception {
    // info defaults to no workspace...
    info.setWorkSpace(null);
    when(accurev.info(basedir)).thenReturn(info);
    // A version that does not support pop -t
    when(accurev.getClientVersion()).thenReturn("4.9.0");
    List<File> poppedFiles = Collections.singletonList(new File("exported/file"));
    when(accurev.popExternal(eq(basedir), eq("mySnapShot"), eq("676"), (Collection<File>) argThat(hasItem(new File("/./project/dir"))))).thenReturn(poppedFiles);
    AccuRevExportCommand command = new AccuRevExportCommand(getLogger());
    CommandParameters params = new CommandParameters();
    params.setScmVersion(CommandParameter.SCM_VERSION, new ScmTag("mySnapShot/676"));
    ExportScmResult result = command.export(repo, new ScmFileSet(basedir), params);
    assertTrue(result.isSuccess());
    assertHasScmFile(result.getExportedFiles(), "exported/file", ScmFileStatus.CHECKED_OUT);
    verify(accurev).syncReplica();
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) 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)

Aggregations

ExportScmResult (org.apache.maven.scm.command.export.ExportScmResult)12 File (java.io.File)6 ScmFileSet (org.apache.maven.scm.ScmFileSet)6 ScmTag (org.apache.maven.scm.ScmTag)6 CommandParameters (org.apache.maven.scm.CommandParameters)5 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)5 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)5 Test (org.junit.Test)5 ScmException (org.apache.maven.scm.ScmException)4 CvsUpdateConsumer (org.apache.maven.scm.provider.cvslib.command.update.CvsUpdateConsumer)2 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)2 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)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 ArrayList (java.util.ArrayList)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 ScmBranch (org.apache.maven.scm.ScmBranch)1