Skip to content

Commit

Permalink
Made possible to disable partial on goal
Browse files Browse the repository at this point in the history
  • Loading branch information
velo committed Jul 17, 2019
1 parent a397fc4 commit 2f0a67a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/it/projects/disabled-for-goal/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.name = TEST for goal
invoker.goals = -e generate-sources -D partial.disableOnGoal=generate-sources
39 changes: 39 additions & 0 deletions src/it/projects/disabled-for-goal/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<modules>
<module>child1</module>
<module>child2</module>
<module>child3</module>
<module>child4</module>
<module>child5</module>
<module>child6</module>
<module>child7</module>
</modules>

<groupId>parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>com.lesfurets</groupId>
<artifactId>partial-build-plugin</artifactId>
<version>@project.version@</version>
<extensions>true</extensions>
<configuration>
<enabled>true</enabled>
<uncommited>false</uncommited>
<referenceBranch>refs/heads/develop</referenceBranch>
<baseBranch>refs/heads/feature/1</baseBranch>
</configuration>
</plugin>
</plugins>
</build>

</project>
8 changes: 8 additions & 0 deletions src/it/projects/disabled-for-goal/setup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import com.lesfurets.maven.partial.mocks.ITHelper

def testProjectBasedir = basedir as File
def pbpBaseDir = sourceDir as String
def pbpVersion = projectVersion as String
new ITHelper(testProjectBasedir, pbpBaseDir, pbpVersion).setupTest()

return true
23 changes: 23 additions & 0 deletions src/it/projects/disabled-for-goal/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import org.codehaus.plexus.util.FileUtils

def file = new File(basedir, "build.log")
String buildLog = FileUtils.fileRead(file)

boolean verified = true
verified &= buildLog.contains(" subchild2")
verified &= buildLog.contains(" child3")
verified &= buildLog.contains(" child4")
verified &= buildLog.contains(" subchild41")

verified &= buildLog.contains(" child1")
verified &= buildLog.contains(" child2")
verified &= buildLog.contains(" child5")
verified &= buildLog.contains(" child6")
verified &= buildLog.contains(" child7")
verified &= buildLog.contains(" subchild1")
verified &= buildLog.contains(" subchild42")
verified &= buildLog.contains(" parent")

verified &= buildLog.contains("Partial build was disable for goal: [generate-sources]")

return verified;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class Configuration {
public final boolean ignoreAllReactorProjects;
public final boolean useNativeGit;
public final String rootDirectory;
public final List<String> disabledOnGoals;

@Inject
public Configuration(MavenSession session) throws IOException {
Expand Down Expand Up @@ -83,6 +84,7 @@ public Configuration(MavenSession session) throws IOException {
buildAnywaysPattern = Property.buildAnyways.getValue();
buildAnywaysProjects = getBuildAnywaysProjects(session, buildAnywaysPattern);
useNativeGit = Boolean.valueOf(Property.useNativeGit.getValue());
disabledOnGoals = separatePattern(Property.disableOnGoal.getValue());
rootDirectory = session.getExecutionRootDirectory();
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum Property {

enabled("true"),
disableOnGoal(""),
repositorySshKey(""),
referenceBranch("refs/remotes/origin/develop"),
baseBranch("HEAD"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
logger.info(configuration.toString());

try {
if (configuration.enabled) {
if (configuration.disabledOnGoals.stream().anyMatch(disableForGoal -> session.getRequest().getGoals().contains(disableForGoal))) {
logger.info("Partial build was disable for goal: " + configuration.disabledOnGoals);
} else if (configuration.enabled) {
logger.info("Starting Partial build...");
injector.getInstance(UnchangedProjectsRemover.class).act();
} else {
Expand Down

0 comments on commit 2f0a67a

Please sign in to comment.