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;
}
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);
}
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);
}
}
}
}
Aggregations