use of org.apache.maven.scm.ScmException in project wagon-git by synergian.
the class GitBackend method run.
private synchronized boolean run(String command, String[] args) throws GitException {
try {
Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(workDir, command);
if (args != null) {
for (int i = 0; i < args.length; i++) cl.createArgument().setValue(args[i]);
}
StringBuffer sb = new StringBuffer();
sb.append("git ").append(command);
if (args != null) {
for (int i = 0; i < args.length; i++) sb.append(" ").append(args[i]);
}
int exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, log);
log.debug("RAN: " + sb.toString() + " / $? = " + exitCode);
return exitCode == 0;
} catch (ScmException e) {
throw new GitException("Couldn't run command " + command + ": " + e.getMessage(), e);
}
}
use of org.apache.maven.scm.ScmException in project maven-plugins by apache.
the class AbstractScmPublishMojo method checkinFiles.
/**
* Check-in content from scm checkout.
*
* @throws MojoExecutionException
*/
protected void checkinFiles() throws MojoExecutionException {
if (skipCheckin) {
return;
}
ScmFileSet updatedFileSet = new ScmFileSet(checkoutDirectory);
try {
long start = System.currentTimeMillis();
CheckInScmResult checkinResult = checkScmResult(scmProvider.checkIn(scmRepository, updatedFileSet, new ScmBranch(scmBranch), checkinComment), "check-in files to SCM");
logInfo("Checked in %d file(s) to revision %s in %s", checkinResult.getCheckedInFiles().size(), checkinResult.getScmRevision(), DurationFormatUtils.formatPeriod(start, System.currentTimeMillis(), "H' h 'm' m 's' s'"));
} catch (ScmException e) {
throw new MojoExecutionException("Failed to perform SCM checkin", e);
}
}
use of org.apache.maven.scm.ScmException in project maven-plugins by apache.
the class AbstractScmPublishMojo method addFiles.
/**
* Add files to scm.
*
* @param added files to be added
* @throws MojoFailureException
* @throws MojoExecutionException
*/
protected void addFiles(Collection<File> added) throws MojoFailureException, MojoExecutionException {
List<File> addedList = new ArrayList<File>();
Set<File> createdDirs = new HashSet<File>();
Set<File> dirsToAdd = new TreeSet<File>();
createdDirs.add(relativize(checkoutDirectory, checkoutDirectory));
for (File f : added) {
for (File dir = f.getParentFile(); !dir.equals(checkoutDirectory); dir = dir.getParentFile()) {
File relativized = relativize(checkoutDirectory, dir);
// we do the best we can with the directories
if (createdDirs.add(relativized)) {
dirsToAdd.add(relativized);
} else {
break;
}
}
addedList.add(relativize(checkoutDirectory, f));
}
if (addUniqueDirectory) {
// add one directory at a time
for (File relativized : dirsToAdd) {
try {
ScmFileSet fileSet = new ScmFileSet(checkoutDirectory, relativized);
getLog().info("scm add directory: " + relativized);
AddScmResult addDirResult = scmProvider.add(scmRepository, fileSet, "Adding directory");
if (!addDirResult.isSuccess()) {
getLog().warn(" Error adding directory " + relativized + ": " + addDirResult.getCommandOutput());
}
} catch (ScmException e) {
//
}
}
} else {
// add all directories in one command
try {
List<File> dirs = new ArrayList<File>(dirsToAdd);
ScmFileSet fileSet = new ScmFileSet(checkoutDirectory, dirs);
getLog().info("scm add directories: " + dirs);
AddScmResult addDirResult = scmProvider.add(scmRepository, fileSet, "Adding directories");
if (!addDirResult.isSuccess()) {
getLog().warn(" Error adding directories " + dirs + ": " + addDirResult.getCommandOutput());
}
} catch (ScmException e) {
//
}
}
// remove directories already added !
addedList.removeAll(dirsToAdd);
ScmFileSet addedFileSet = new ScmFileSet(checkoutDirectory, addedList);
getLog().info("scm add files: " + addedList);
try {
CommandParameters commandParameters = new CommandParameters();
commandParameters.setString(CommandParameter.MESSAGE, "Adding new site files.");
commandParameters.setString(CommandParameter.FORCE_ADD, Boolean.TRUE.toString());
checkScmResult(scmProvider.add(scmRepository, addedFileSet, commandParameters), "add new files to SCM");
} catch (ScmException e) {
throw new MojoExecutionException("Failed to add new files to SCM", e);
}
}
use of org.apache.maven.scm.ScmException in project maven-plugins by apache.
the class ChangeLogReport method getRevisionForTag.
/**
* Resolves the given tag to the revision number.
*
* @param tag
* @param repository
* @param provider
* @return
* @throws ScmException
*/
private String getRevisionForTag(final String tag, final ScmRepository repository, final ScmProvider provider) throws ScmException {
if (repository.getProvider().equals("svn")) {
if (tag == null) {
return "HEAD";
}
SvnInfoCommandExpanded infoCommand = new SvnInfoCommandExpanded();
infoCommand.setLogger(new DefaultLog());
InfoScmResult infoScmResult = infoCommand.executeInfoTagCommand((SvnScmProviderRepository) repository.getProviderRepository(), new ScmFileSet(basedir), tag, null, false, null);
if (infoScmResult.getInfoItems().size() == 0) {
throw new ScmException("There is no tag named '" + tag + "' in the Subversion repository.");
}
InfoItem infoItem = infoScmResult.getInfoItems().get(0);
String revision = infoItem.getLastChangedRevision();
getLog().info(String.format("Resolved tag '%s' to revision '%s'", tag, revision));
return revision;
}
return tag;
}
use of org.apache.maven.scm.ScmException in project maven-plugins by apache.
the class ChangeLogReport method getScmRepository.
public ScmRepository getScmRepository() throws ScmException {
ScmRepository repository;
try {
repository = manager.makeScmRepository(getConnection());
ScmProviderRepository providerRepo = repository.getProviderRepository();
if (!StringUtils.isEmpty(username)) {
providerRepo.setUser(username);
}
if (!StringUtils.isEmpty(password)) {
providerRepo.setPassword(password);
}
if (repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost) {
ScmProviderRepositoryWithHost repo = (ScmProviderRepositoryWithHost) repository.getProviderRepository();
loadInfosFromSettings(repo);
if (!StringUtils.isEmpty(username)) {
repo.setUser(username);
}
if (!StringUtils.isEmpty(password)) {
repo.setPassword(password);
}
if (!StringUtils.isEmpty(privateKey)) {
repo.setPrivateKey(privateKey);
}
if (!StringUtils.isEmpty(passphrase)) {
repo.setPassphrase(passphrase);
}
}
if (!StringUtils.isEmpty(tagBase) && repository.getProvider().equals("svn")) {
SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) repository.getProviderRepository();
svnRepo.setTagBase(tagBase);
}
} catch (Exception e) {
throw new ScmException("Can't load the scm provider.", e);
}
return repository;
}
Aggregations