use of org.apache.maven.shared.release.scm.ScmTranslator in project maven-release by apache.
the class ScmCheckModificationsPhase method execute.
@Override
public ReleaseResult execute(ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, List<MavenProject> reactorProjects) throws ReleaseExecutionException, ReleaseFailureException {
ReleaseResult relResult = new ReleaseResult();
List<String> additionalExcludes = releaseDescriptor.getCheckModificationExcludes();
if (additionalExcludes != null) {
// SelectorUtils expects OS-specific paths and patterns
for (String additionalExclude : additionalExcludes) {
exclusionPatterns.add(additionalExclude.replace("\\", File.separator).replace("/", File.separator));
}
}
logInfo(relResult, "Verifying that there are no local modifications...");
logInfo(relResult, " ignoring changes on: " + StringUtils.join(exclusionPatterns.toArray(), ", "));
ScmRepository repository;
ScmProvider provider;
try {
repository = scmRepositoryConfigurator.getConfiguredRepository(releaseDescriptor, releaseEnvironment.getSettings());
provider = scmRepositoryConfigurator.getRepositoryProvider(repository);
} catch (ScmRepositoryException e) {
throw new ReleaseScmRepositoryException(e.getMessage() + " for URL: " + releaseDescriptor.getScmSourceUrl(), e.getValidationMessages());
} catch (NoSuchScmProviderException e) {
throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e);
}
StatusScmResult result;
try {
result = provider.status(repository, new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory())));
} catch (ScmException e) {
throw new ReleaseExecutionException("An error occurred during the status check process: " + e.getMessage(), e);
}
if (!result.isSuccess()) {
throw new ReleaseScmCommandException("Unable to check for local modifications", result);
}
List<ScmFile> changedFiles = result.getChangedFiles();
if (!changedFiles.isEmpty()) {
ScmTranslator scmTranslator = scmTranslators.get(repository.getProvider());
// TODO: would be nice for SCM status command to do this for me.
for (Iterator<ScmFile> i = changedFiles.iterator(); i.hasNext(); ) {
ScmFile f = i.next();
String path;
if (scmTranslator != null) {
path = scmTranslator.toRelativePath(f.getPath());
} else {
path = f.getPath();
}
// SelectorUtils expects File.separator, don't standardize!
String fileName = path.replace("\\", File.separator).replace("/", File.separator);
for (String exclusionPattern : exclusionPatterns) {
if (SelectorUtils.matchPath(exclusionPattern, fileName)) {
logDebug(relResult, "Ignoring changed file: " + fileName);
i.remove();
break;
}
}
}
}
if (!changedFiles.isEmpty()) {
StringBuilder message = new StringBuilder();
for (ScmFile file : changedFiles) {
message.append(file.toString());
message.append("\n");
}
throw new ReleaseFailureException("Cannot prepare the release because you have local modifications : \n" + message);
}
relResult.setResultCode(ReleaseResult.SUCCESS);
return relResult;
}
use of org.apache.maven.shared.release.scm.ScmTranslator in project maven-release by apache.
the class RewritePomsForBranchPhase method translateScm.
private boolean translateScm(MavenProject project, ReleaseDescriptor releaseDescriptor, Scm scmTarget, ScmRepository scmRepository, ReleaseResult relResult) throws IOException {
ScmTranslator translator = getScmTranslators().get(scmRepository.getProvider());
boolean result = false;
if (translator != null) {
Scm scm = project.getOriginalModel().getScm();
if (scm == null) {
scm = project.getScm();
}
String branchName = releaseDescriptor.getScmReleaseLabel();
String branchBase = releaseDescriptor.getScmBranchBase();
// TODO: svn utils should take care of prepending this
if (branchBase != null) {
branchBase = "scm:svn:" + branchBase;
}
Path projectBasedir = project.getBasedir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS);
Path workingDirectory = Paths.get(releaseDescriptor.getWorkingDirectory());
int count = ReleaseUtil.getBaseWorkingDirectoryParentCount(workingDirectory, projectBasedir);
if (scm.getConnection() != null) {
String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getConnection());
String subDirectoryBranch = scm.getConnection().substring(rootUrl.length());
if (!subDirectoryBranch.startsWith("/")) {
subDirectoryBranch = "/" + subDirectoryBranch;
}
String scmConnectionBranch = branchBase;
if (scmConnectionBranch != null) {
String trunkUrl = scm.getDeveloperConnection();
if (trunkUrl == null) {
trunkUrl = scm.getConnection();
}
scmConnectionBranch = translateUrlPath(trunkUrl, branchBase, scm.getConnection());
}
String value = translator.translateBranchUrl(scm.getConnection(), branchName + subDirectoryBranch, scmConnectionBranch);
if (!value.equals(scm.getConnection())) {
scmTarget.setConnection(value);
result = true;
}
}
if (scm.getDeveloperConnection() != null) {
String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getDeveloperConnection());
String subDirectoryBranch = scm.getDeveloperConnection().substring(rootUrl.length());
if (!subDirectoryBranch.startsWith("/")) {
subDirectoryBranch = "/" + subDirectoryBranch;
}
String value = translator.translateBranchUrl(scm.getDeveloperConnection(), branchName + subDirectoryBranch, branchBase);
if (!value.equals(scm.getDeveloperConnection())) {
scmTarget.setDeveloperConnection(value);
result = true;
}
}
if (scm.getUrl() != null) {
String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getUrl());
String subDirectoryBranch = scm.getUrl().substring(rootUrl.length());
if (!subDirectoryBranch.startsWith("/")) {
subDirectoryBranch = "/" + subDirectoryBranch;
}
String tagScmUrl = branchBase;
if (tagScmUrl != null) {
String trunkUrl = scm.getDeveloperConnection();
if (trunkUrl == null) {
trunkUrl = scm.getConnection();
}
tagScmUrl = translateUrlPath(trunkUrl, branchBase, scm.getUrl());
}
// use original branch base without protocol
String value = translator.translateBranchUrl(scm.getUrl(), branchName + subDirectoryBranch, tagScmUrl);
if (!value.equals(scm.getUrl())) {
scmTarget.setUrl(value);
result = true;
}
}
if (branchName != null) {
String value = translator.resolveTag(branchName);
if (value != null && !value.equals(scm.getTag())) {
scmTarget.setTag(value);
result = true;
}
}
} else {
String message = "No SCM translator found - skipping rewrite";
relResult.appendDebug(message);
getLogger().debug(message);
}
return result;
}
use of org.apache.maven.shared.release.scm.ScmTranslator in project maven-release by apache.
the class GenerateReleasePomsPhase method createReleaseModel.
private Model createReleaseModel(MavenProject project, ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, ReleaseResult result) throws ReleaseFailureException, ReleaseExecutionException {
MavenProject releaseProject = project.clone();
Model releaseModel = releaseProject.getModel();
// the release POM should reflect bits of these which were injected at build time...
// we don't need these polluting the POM.
releaseModel.setParent(null);
releaseModel.setProfiles(Collections.emptyList());
releaseModel.setDependencyManagement(null);
releaseProject.getBuild().setPluginManagement(null);
// update project version
String projectVersion = releaseModel.getVersion();
String releaseVersion = getNextVersion(releaseDescriptor, project.getGroupId(), project.getArtifactId());
releaseModel.setVersion(releaseVersion);
String originalFinalName = releaseModel.getBuild().getFinalName();
// update final name if implicit
if (!FINALNAME_EXPRESSION.equals(originalFinalName)) {
originalFinalName = findOriginalFinalName(project);
if (originalFinalName == null) {
// as defined in super-pom
originalFinalName = FINALNAME_EXPRESSION;
}
}
// make finalName always explicit
String finalName = ReleaseUtil.interpolate(originalFinalName, releaseModel);
// still required?
if (finalName.contains(Artifact.SNAPSHOT_VERSION)) {
throw new ReleaseFailureException("Cannot reliably adjust the finalName of project: " + releaseProject.getId());
}
releaseModel.getBuild().setFinalName(finalName);
// update scm
Scm scm = releaseModel.getScm();
if (scm != null) {
ScmRepository scmRepository = getScmRepository(releaseDescriptor, releaseEnvironment);
ScmTranslator scmTranslator = getScmTranslator(scmRepository);
if (scmTranslator != null) {
releaseModel.setScm(createReleaseScm(releaseModel.getScm(), scmTranslator, releaseDescriptor));
} else {
String message = "No SCM translator found - skipping rewrite";
result.appendDebug(message);
getLogger().debug(message);
}
}
// rewrite dependencies
releaseModel.setDependencies(createReleaseDependencies(releaseDescriptor, releaseProject));
// rewrite plugins
releaseModel.getBuild().setPlugins(createReleasePlugins(releaseDescriptor, releaseProject));
// rewrite reports
releaseModel.getReporting().setPlugins(createReleaseReportPlugins(releaseDescriptor, releaseProject));
// rewrite extensions
releaseModel.getBuild().setExtensions(createReleaseExtensions(releaseDescriptor, releaseProject));
unalignFromBaseDirectory(releaseModel, project.getBasedir());
return releaseModel;
}
use of org.apache.maven.shared.release.scm.ScmTranslator in project maven-release by apache.
the class RewritePomsForDevelopmentPhase method transformScm.
@Override
protected void transformScm(MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor, String projectId, ScmRepository scmRepository, ReleaseResult result) {
// If SCM is null in original model, it is inherited, no mods needed
if (project.getScm() != null) {
Scm scmRoot = modelTarget.getScm();
if (scmRoot != null) {
ScmTranslator translator = getScmTranslators().get(scmRepository.getProvider());
if (translator != null) {
Scm scm = releaseDescriptor.getOriginalScmInfo(projectId);
if (scm != null) {
scmRoot.setConnection(scm.getConnection());
scmRoot.setDeveloperConnection(scm.getDeveloperConnection());
scmRoot.setUrl(scm.getUrl());
scmRoot.setTag(translator.resolveTag(scm.getTag()));
} else {
// cleanly remove the SCM element
modelTarget.setScm(null);
}
} else {
String message = "No SCM translator found - skipping rewrite";
result.appendDebug(message);
getLogger().debug(message);
}
}
}
}
use of org.apache.maven.shared.release.scm.ScmTranslator in project maven-release by apache.
the class RewritePomsForReleasePhase method translateScm.
private boolean translateScm(MavenProject project, ReleaseDescriptor releaseDescriptor, Scm scmTarget, ScmRepository scmRepository, ReleaseResult relResult) throws IOException {
ScmTranslator translator = getScmTranslators().get(scmRepository.getProvider());
boolean result = false;
if (translator != null) {
Scm scm = project.getOriginalModel().getScm();
if (scm == null) {
scm = project.getScm();
}
String tag = releaseDescriptor.getScmReleaseLabel();
String tagBase = releaseDescriptor.getScmTagBase();
// TODO: svn utils should take care of prepending this
if (tagBase != null) {
tagBase = "scm:svn:" + tagBase;
}
Path projectBasedir = project.getBasedir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS);
Path workingDirectory = Paths.get(releaseDescriptor.getWorkingDirectory());
int count = ReleaseUtil.getBaseWorkingDirectoryParentCount(workingDirectory, projectBasedir);
if (scm.getConnection() != null) {
String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getConnection());
String subDirectoryTag = scm.getConnection().substring(rootUrl.length());
if (!subDirectoryTag.startsWith("/")) {
subDirectoryTag = "/" + subDirectoryTag;
}
String scmConnectionTag = tagBase;
if (scmConnectionTag != null) {
String trunkUrl = scm.getDeveloperConnection();
if (trunkUrl == null) {
trunkUrl = scm.getConnection();
}
scmConnectionTag = translateUrlPath(trunkUrl, tagBase, scm.getConnection());
}
String value = translator.translateTagUrl(scm.getConnection(), tag + subDirectoryTag, scmConnectionTag);
if (!value.equals(scm.getConnection())) {
scmTarget.setConnection(value);
result = true;
}
}
if (scm.getDeveloperConnection() != null) {
String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getDeveloperConnection());
String subDirectoryTag = scm.getDeveloperConnection().substring(rootUrl.length());
if (!subDirectoryTag.startsWith("/")) {
subDirectoryTag = "/" + subDirectoryTag;
}
String value = translator.translateTagUrl(scm.getDeveloperConnection(), tag + subDirectoryTag, tagBase);
if (!value.equals(scm.getDeveloperConnection())) {
scmTarget.setDeveloperConnection(value);
result = true;
}
}
if (scm.getUrl() != null) {
String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getUrl());
String subDirectoryTag = scm.getUrl().substring(rootUrl.length());
if (!subDirectoryTag.startsWith("/")) {
subDirectoryTag = "/" + subDirectoryTag;
}
String tagScmUrl = tagBase;
if (tagScmUrl != null) {
String trunkUrl = scm.getDeveloperConnection();
if (trunkUrl == null) {
trunkUrl = scm.getConnection();
}
tagScmUrl = translateUrlPath(trunkUrl, tagBase, scm.getUrl());
}
// use original tag base without protocol
String value = translator.translateTagUrl(scm.getUrl(), tag + subDirectoryTag, tagScmUrl);
if (!value.equals(scm.getUrl())) {
scmTarget.setUrl(value);
result = true;
}
}
if (tag != null) {
String value = translator.resolveTag(tag);
if (value != null && !value.equals(scm.getTag())) {
scmTarget.setTag(value);
result = true;
}
}
} else {
String message = "No SCM translator found - skipping rewrite";
relResult.appendDebug(message);
getLogger().debug(message);
}
return result;
}
Aggregations