Search in sources :

Example 31 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class SynergyAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing add command...");
    }
    SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("basedir: " + fileSet.getBasedir());
    }
    if (message == null || message.equals("")) {
        message = "Maven SCM Synergy provider: adding file(s) to project " + repo.getProjectSpec();
    }
    String ccmAddr = SynergyUtil.start(getLogger(), repo.getUser(), repo.getPassword(), null);
    try {
        int taskNum = SynergyUtil.createTask(getLogger(), message, repo.getProjectRelease(), true, ccmAddr);
        String projectSpec = SynergyUtil.getWorkingProject(getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr);
        if (projectSpec == null) {
            throw new ScmException("You should checkout a working project first");
        }
        File waPath = SynergyUtil.getWorkArea(getLogger(), projectSpec, ccmAddr);
        File destPath = new File(waPath, repo.getProjectName());
        for (File source : fileSet.getFileList()) {
            File dest = new File(destPath, SynergyUtil.removePrefix(fileSet.getBasedir(), source));
            if (!source.equals(dest)) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Copy file [" + source + "] to Synergy Work Area [" + dest + "].");
                }
                try {
                    FileUtils.copyFile(source, dest);
                } catch (IOException e) {
                    throw new ScmException("Unable to copy file in Work Area", e);
                }
            }
            SynergyUtil.create(getLogger(), dest, message, ccmAddr);
        }
        SynergyUtil.checkinTask(getLogger(), taskNum, message, ccmAddr);
    } finally {
        SynergyUtil.stop(getLogger(), ccmAddr);
    }
    List<ScmFile> scmFiles = new ArrayList<ScmFile>(fileSet.getFileList().size());
    for (File f : fileSet.getFileList()) {
        scmFiles.add(new ScmFile(f.getPath(), ScmFileStatus.ADDED));
    }
    return new AddScmResult("", scmFiles);
}
Also used : ScmException(org.apache.maven.scm.ScmException) SynergyScmProviderRepository(org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 32 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class AccuRevAddCommand method executeAccurevCommand.

/**
 * Add.
 *
 * @todo handle the "binary" parameter. AccuRev does a reasonable job of detecting this itself.
 */
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    AccuRev accuRev = repository.getAccuRev();
    String message = parameters.getString(CommandParameter.MESSAGE, "");
    File basedir = fileSet.getBasedir();
    List<File> relativeFiles = fileSet.getFileList();
    List<File> addedFiles = accuRev.add(basedir, relativeFiles, message);
    if (addedFiles != null) {
        List<ScmFile> resultFiles = getScmFiles(addedFiles, ScmFileStatus.ADDED);
        return new AddScmResult(accuRev.getCommandLines(), resultFiles);
    } else {
        return new AddScmResult(accuRev.getCommandLines(), "AccuRev Error", accuRev.getErrorOutput(), false);
    }
}
Also used : AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 33 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class LocalScmProvider method add.

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

Example 34 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class LocalAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    LocalScmProviderRepository localRepo = (LocalScmProviderRepository) repository;
    List<ScmFile> fileList = new ArrayList<ScmFile>();
    for (File file : fileSet.getFileList()) {
        String path = file.getPath().replace('\\', '/');
        localRepo.addFile(path);
        fileList.add(new ScmFile(path, ScmFileStatus.ADDED));
    }
    // TODO: Also, ensure it is tested from the update test
    return new AddScmResult(null, fileList);
}
Also used : LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 35 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class LocalMkdirCommand method executeMkdirCommand.

protected MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
    LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
    List<ScmFile> createdDirs = new ArrayList<ScmFile>();
    // create/commit the directory directly in the repository
    if (!createInLocal) {
        File file = (File) fileSet.getFileList().get(0);
        File modulePath = new File(repo.getRoot(), repo.getModule());
        File dir = new File(modulePath, file.getName());
        if (dir.exists()) {
            return new MkdirScmResult(null, "Directory already exists!", "Directory already exists.", false);
        } else {
            if (getLogger().isInfoEnabled()) {
                getLogger().info("Creating directory in '" + modulePath.getAbsolutePath() + "'");
            }
            FileUtils.mkdir(dir.getAbsolutePath());
            createdDirs.add(new ScmFile(dir.getPath(), ScmFileStatus.ADDED));
        }
    } else {
        // add the directory, but not commit
        LocalAddCommand addCmd = new LocalAddCommand();
        addCmd.setLogger(getLogger());
        CommandParameters parameters = new CommandParameters();
        parameters.setString(CommandParameter.MESSAGE, message);
        parameters.setString(CommandParameter.BINARY, "false");
        String path = ((File) fileSet.getFileList().get(0)).getPath();
        if (repo.isFileAdded(path)) {
            return new MkdirScmResult(null, "Directory already exists!", "Directory already exists.", false);
        }
        AddScmResult result = (AddScmResult) addCmd.execute(repository, fileSet, parameters);
        createdDirs.addAll(result.getAddedFiles());
    }
    return new MkdirScmResult(null, createdDirs);
}
Also used : LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) LocalAddCommand(org.apache.maven.scm.provider.local.command.add.LocalAddCommand) CommandParameters(org.apache.maven.scm.CommandParameters) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

AddScmResult (org.apache.maven.scm.command.add.AddScmResult)39 File (java.io.File)18 ScmFile (org.apache.maven.scm.ScmFile)12 ScmFileSet (org.apache.maven.scm.ScmFileSet)9 ScmException (org.apache.maven.scm.ScmException)8 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)7 ArrayList (java.util.ArrayList)6 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)6 Commandline (org.codehaus.plexus.util.cli.Commandline)6 CommandParameters (org.apache.maven.scm.CommandParameters)4 ScmRepository (org.apache.maven.scm.repository.ScmRepository)4 ScmResult (org.apache.maven.scm.ScmResult)3 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)3 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)3 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)2 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)2 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)2 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)2