Search in sources :

Example 66 with CommandParameters

use of org.apache.maven.scm.CommandParameters in project maven-scm by apache.

the class AbstractSvnScmProvider method makeProviderScmRepository.

/**
 * {@inheritDoc}
 */
public ScmProviderRepository makeProviderScmRepository(String scmSpecificUrl, char delimiter) throws ScmRepositoryException {
    ScmUrlParserResult result = parseScmUrl(scmSpecificUrl);
    if (checkWorkingDirectoryUrl()) {
        getLogger().debug("Checking svn info 'URL:' field matches current sources directory");
        try {
            String workingDir = System.getProperty("scmCheckWorkingDirectoryUrl.currentWorkingDirectory");
            InfoScmResult info = info(result.repository, new ScmFileSet(new File(workingDir)), new CommandParameters());
            String url = findUrlInfoItem(info);
            String comparison = "'" + url + "' vs. '" + scmSpecificUrl + "'";
            getLogger().debug("Comparing : " + comparison);
            if (url != null && !url.equals(scmSpecificUrl)) {
                result.messages.add("Scm url does not match the value returned by svn info (" + comparison + ")");
            }
        } catch (ScmException e) {
            throw new ScmRepositoryException("An error occurred while trying to svn info", e);
        }
    }
    if (result.messages.size() > 0) {
        throw new ScmRepositoryException("The scm url is invalid.", result.messages);
    }
    return result.repository;
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) ScmRepositoryException(org.apache.maven.scm.repository.ScmRepositoryException) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File)

Example 67 with CommandParameters

use of org.apache.maven.scm.CommandParameters 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)

Example 68 with CommandParameters

use of org.apache.maven.scm.CommandParameters in project maven-plugins by apache.

the class AbstractScmPublishMojo method checkCreateRemoteSvnPath.

private void checkCreateRemoteSvnPath() throws MojoExecutionException {
    getLog().debug("AbstractSvnScmProvider used, so we can check if remote url exists and eventually create it.");
    AbstractSvnScmProvider svnScmProvider = (AbstractSvnScmProvider) scmProvider;
    try {
        boolean remoteExists = svnScmProvider.remoteUrlExist(scmRepository.getProviderRepository(), null);
        if (remoteExists) {
            return;
        }
    } catch (ScmException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    String remoteUrl = ((SvnScmProviderRepository) scmRepository.getProviderRepository()).getUrl();
    if (!automaticRemotePathCreation) {
        // olamy: return ?? that will fail during checkout IMHO :-)
        logWarn("Remote svn url %s does not exist and automatic remote path creation disabled.", remoteUrl);
        return;
    }
    logInfo("Remote svn url %s does not exist: creating.", remoteUrl);
    File baseDir = null;
    try {
        // create a temporary directory for svnexec
        baseDir = File.createTempFile("scm", "tmp");
        baseDir.delete();
        baseDir.mkdirs();
        // to prevent fileSet cannot be empty
        ScmFileSet scmFileSet = new ScmFileSet(baseDir, new File(""));
        CommandParameters commandParameters = new CommandParameters();
        commandParameters.setString(CommandParameter.SCM_MKDIR_CREATE_IN_LOCAL, Boolean.FALSE.toString());
        commandParameters.setString(CommandParameter.MESSAGE, "Automatic svn path creation: " + remoteUrl);
        svnScmProvider.mkdir(scmRepository.getProviderRepository(), scmFileSet, commandParameters);
        // new remote url so force checkout!
        if (checkoutDirectory.exists()) {
            FileUtils.deleteDirectory(checkoutDirectory);
        }
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ScmException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        if (baseDir != null) {
            try {
                FileUtils.forceDeleteOnExit(baseDir);
            } catch (IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractSvnScmProvider(org.apache.maven.scm.provider.svn.AbstractSvnScmProvider) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) IOException(java.io.IOException) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File)

Aggregations

CommandParameters (org.apache.maven.scm.CommandParameters)68 ScmFileSet (org.apache.maven.scm.ScmFileSet)44 File (java.io.File)39 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)38 Test (org.junit.Test)38 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)23 ScmFile (org.apache.maven.scm.ScmFile)8 ScmTag (org.apache.maven.scm.ScmTag)7 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)7 Date (java.util.Date)6 ChangeFile (org.apache.maven.scm.ChangeFile)5 ChangeFileMatcher.changeFile (org.apache.maven.scm.ChangeFileMatcher.changeFile)5 ScmRevision (org.apache.maven.scm.ScmRevision)5 ExportScmResult (org.apache.maven.scm.command.export.ExportScmResult)5 InfoScmResult (org.apache.maven.scm.command.info.InfoScmResult)5 LoginScmResult (org.apache.maven.scm.command.login.LoginScmResult)5 AccuRevInfo (org.apache.maven.scm.provider.accurev.AccuRevInfo)5 Transaction (org.apache.maven.scm.provider.accurev.Transaction)5 ArrayList (java.util.ArrayList)4 ScmException (org.apache.maven.scm.ScmException)4