Search in sources :

Example 11 with MkdirScmResult

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

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