Search in sources :

Example 1 with MkdirScmResult

use of org.apache.maven.scm.command.mkdir.MkdirScmResult in project maven-scm by apache.

the class SvnMkdirCommand method executeMkdirCommand.

/**
 * {@inheritDoc}
 */
protected MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
    File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
    try {
        FileUtils.fileWrite(messageFile.getAbsolutePath(), message);
    } catch (IOException ex) {
        return new MkdirScmResult(null, "Error while making a temporary file for the mkdir message: " + ex.getMessage(), null, false);
    }
    Commandline cl = createCommandLine((SvnScmProviderRepository) repository, fileSet, messageFile, createInLocal);
    SvnMkdirConsumer consumer = new SvnMkdirConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    } finally {
        try {
            FileUtils.forceDelete(messageFile);
        } catch (IOException ex) {
        // ignore
        }
    }
    if (exitCode != 0) {
        return new MkdirScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    if (createInLocal) {
        return new MkdirScmResult(cl.toString(), consumer.getCreatedDirs());
    } else {
        return new MkdirScmResult(cl.toString(), Integer.toString(consumer.getRevision()));
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) IOException(java.io.IOException) File(java.io.File) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 2 with MkdirScmResult

use of org.apache.maven.scm.command.mkdir.MkdirScmResult 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 3 with MkdirScmResult

use of org.apache.maven.scm.command.mkdir.MkdirScmResult 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 4 with MkdirScmResult

use of org.apache.maven.scm.command.mkdir.MkdirScmResult in project maven-scm by apache.

the class LocalScmProvider method mkdir.

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

Example 5 with MkdirScmResult

use of org.apache.maven.scm.command.mkdir.MkdirScmResult in project maven-scm by apache.

the class IntegrityMkdirCommand method executeMkdirCommand.

/**
 * Creates a subproject in the Integrity repository.
 * <br>However, since the subproject automatically creates a folder in
 * the local sandbox, the createInLocal argument will be ignored
 */
@Override
public MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
    String dirPath = "";
    Iterator<File> fit = fileSet.getFileList().iterator();
    if (fit.hasNext()) {
        dirPath = fit.next().getPath().replace('\\', '/');
    }
    if (null == dirPath || dirPath.length() == 0) {
        throw new ScmException("A relative directory path is required to execute this command!");
    }
    getLogger().info("Creating subprojects one per directory, as required for " + dirPath);
    MkdirScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        Response res = iRepo.getSandbox().createSubproject(dirPath);
        String subProject = res.getWorkItems().next().getResult().getField("resultant").getItem().getDisplayId();
        List<ScmFile> createdDirs = new ArrayList<ScmFile>();
        createdDirs.add(new ScmFile(subProject, ScmFileStatus.ADDED));
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        getLogger().info("Successfully created subproject " + subProject);
        result = new MkdirScmResult(createdDirs, new ScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success));
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
        result = new MkdirScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : ScmException(org.apache.maven.scm.ScmException) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) ScmResult(org.apache.maven.scm.ScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Aggregations

MkdirScmResult (org.apache.maven.scm.command.mkdir.MkdirScmResult)11 File (java.io.File)9 ScmFileSet (org.apache.maven.scm.ScmFileSet)5 ListScmResult (org.apache.maven.scm.command.list.ListScmResult)4 ArrayList (java.util.ArrayList)3 ScmFile (org.apache.maven.scm.ScmFile)3 CommandParameters (org.apache.maven.scm.CommandParameters)2 ScmException (org.apache.maven.scm.ScmException)2 ScmResult (org.apache.maven.scm.ScmResult)2 APIException (com.mks.api.response.APIException)1 Response (com.mks.api.response.Response)1 IOException (java.io.IOException)1 Command (org.apache.maven.scm.command.Command)1 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)1 AbstractMkdirCommand (org.apache.maven.scm.command.mkdir.AbstractMkdirCommand)1 ExceptionHandler (org.apache.maven.scm.provider.integrity.ExceptionHandler)1 IntegrityMkdirCommand (org.apache.maven.scm.provider.integrity.command.mkdir.IntegrityMkdirCommand)1 IntegrityScmProviderRepository (org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository)1 LocalAddCommand (org.apache.maven.scm.provider.local.command.add.LocalAddCommand)1 LocalMkdirCommand (org.apache.maven.scm.provider.local.command.mkdir.LocalMkdirCommand)1