Skip to content

Commit

Permalink
#10 - Check SNAPSHOT dependencies on releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-m committed Feb 11, 2016
1 parent 9bbad25 commit c210e68
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package com.amashchenko.maven.plugin.gitflow;

import java.io.FileReader;
import java.util.List;

import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -75,6 +78,10 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
@Parameter(property = "installProject", defaultValue = "false")
protected boolean installProject = false;

/** Whether to allow SNAPSHOT versions in dependencies. */
@Parameter(property = "allowSnapshots", defaultValue = "false")
protected boolean allowSnapshots = false;

/** Whether to print commands output into the console. */
@Parameter(property = "verbose", defaultValue = "false")
private boolean verbose = false;
Expand Down Expand Up @@ -169,6 +176,18 @@ protected void checkUncommittedChanges() throws MojoFailureException,
}
}

@SuppressWarnings("unchecked")
protected void checkSnapshotDependencies() throws MojoFailureException {
getLog().info("Checking for SNAPSHOT versions in dependencies.");
List<Dependency> list = project.getDependencies();
for (Dependency d : list) {
if (ArtifactUtils.isSnapshot(d.getVersion())) {
throw new MojoFailureException(
"There is some SNAPSHOT dependencies in the project. Change them or ignore with `allowSnapshots` property.");
}
}
}

/**
* Executes git commands to check for uncommitted changes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try {
// check uncommitted changes
checkUncommittedChanges();

// check snapshots dependencies
if (!allowSnapshots) {
checkSnapshotDependencies();
}

// git for-each-ref --format='%(refname:short)' refs/heads/release/*
final String releaseBranch = gitFindBranches(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// check uncommitted changes
checkUncommittedChanges();

// check snapshots dependencies
if (!allowSnapshots) {
checkSnapshotDependencies();
}

// git for-each-ref --count=1 refs/heads/release/*
final String releaseBranch = gitFindBranches(
gitFlowConfig.getReleaseBranchPrefix(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// check uncommitted changes
checkUncommittedChanges();

// check snapshots dependencies
if (!allowSnapshots) {
checkSnapshotDependencies();
}

// git for-each-ref --count=1 refs/heads/release/*
final String releaseBranch = gitFindBranches(
Expand Down

0 comments on commit c210e68

Please sign in to comment.