use of org.apache.maven.scm.ScmFileSet 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.ScmFileSet 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.ScmFileSet 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.ScmFileSet in project maven-plugins by apache.
the class ChangeLogReport method generateChangeSetsFromSCM.
/**
* creates a ChangeLog object and then connects to the SCM to generate the changed sets
*
* @return changedlogsets generated from the SCM
* @throws MavenReportException
*/
protected List<ChangeLogSet> generateChangeSetsFromSCM() throws MavenReportException {
try {
List<ChangeLogSet> changeSets = new ArrayList<ChangeLogSet>();
ScmRepository repository = getScmRepository();
ScmProvider provider = manager.getProviderByRepository(repository);
ChangeLogScmResult result;
if ("range".equals(type)) {
result = provider.changeLog(repository, new ScmFileSet(basedir), null, null, range, (ScmBranch) null, dateFormat);
checkResult(result);
changeSets.add(result.getChangeLog());
} else if ("tag".equals(type)) {
Iterator<String> tagsIter = tags.iterator();
String startTag = tagsIter.next();
String endTag = null;
if (tagsIter.hasNext()) {
while (tagsIter.hasNext()) {
endTag = tagsIter.next();
String endRevision = getRevisionForTag(endTag, repository, provider);
String startRevision = getRevisionForTag(startTag, repository, provider);
result = provider.changeLog(repository, new ScmFileSet(basedir), new ScmRevision(startRevision), new ScmRevision(endRevision));
checkResult(result);
result.getChangeLog().setStartVersion(new ScmRevision(startTag));
result.getChangeLog().setEndVersion(new ScmRevision(endTag));
changeSets.add(result.getChangeLog());
startTag = endTag;
}
} else {
String startRevision = getRevisionForTag(startTag, repository, provider);
String endRevision = getRevisionForTag(endTag, repository, provider);
result = provider.changeLog(repository, new ScmFileSet(basedir), new ScmRevision(startRevision), new ScmRevision(endRevision));
checkResult(result);
result.getChangeLog().setStartVersion(new ScmRevision(startTag));
result.getChangeLog().setEndVersion(null);
changeSets.add(result.getChangeLog());
}
} else if ("date".equals(type)) {
Iterator<String> dateIter = dates.iterator();
String startDate = dateIter.next();
String endDate = null;
if (dateIter.hasNext()) {
while (dateIter.hasNext()) {
endDate = dateIter.next();
result = provider.changeLog(repository, new ScmFileSet(basedir), parseDate(startDate), parseDate(endDate), 0, (ScmBranch) null);
checkResult(result);
changeSets.add(result.getChangeLog());
startDate = endDate;
}
} else {
result = provider.changeLog(repository, new ScmFileSet(basedir), parseDate(startDate), parseDate(endDate), 0, (ScmBranch) null);
checkResult(result);
changeSets.add(result.getChangeLog());
}
} else {
throw new MavenReportException("The type '" + type + "' isn't supported.");
}
filter(changeSets);
return changeSets;
} catch (ScmException e) {
throw new MavenReportException("Cannot run changelog command : ", e);
} catch (MojoExecutionException e) {
throw new MavenReportException("An error has occurred during changelog command : ", e);
}
}
use of org.apache.maven.scm.ScmFileSet in project maven-plugins by apache.
the class AbstractScmPublishMojo method deleteFiles.
protected void deleteFiles(Collection<File> deleted) throws MojoExecutionException {
if (skipDeletedFiles) {
logInfo("Deleting files is skipped.");
return;
}
List<File> deletedList = new ArrayList<File>();
for (File f : deleted) {
deletedList.add(relativize(checkoutDirectory, f));
}
ScmFileSet deletedFileSet = new ScmFileSet(checkoutDirectory, deletedList);
try {
getLog().info("Deleting files: " + deletedList);
checkScmResult(scmProvider.remove(scmRepository, deletedFileSet, "Deleting obsolete site files."), "delete files from SCM");
} catch (ScmException e) {
throw new MojoExecutionException("Failed to delete removed files to SCM", e);
}
}
Aggregations