Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 88 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,91 @@
*.iml
/tmp
/src/test/resources/template
/src/test/resources/template.zip
/src/test/resources/template.zip


# Created by https://www.gitignore.io/api/m2e,maven,eclipse
# Edit at https://www.gitignore.io/?templates=m2e,maven,eclipse


### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# CDT- autotools
.autotools

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Annotation Processing
.apt_generated/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Annotation Processing
.apt_generated

.sts4-cache/

2 changes: 2 additions & 0 deletions src/it/projects/build-changed-first/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.name = TEST build changed first
invoker.goals = -e clean install -Dpartial.buildAll=true -Dpartial.buildChangedFirst=true
39 changes: 39 additions & 0 deletions src/it/projects/build-changed-first/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/build-changed-first/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
24 changes: 24 additions & 0 deletions src/it/projects/build-changed-first/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import org.codehaus.plexus.util.FileUtils

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

boolean verified = true
verified &= buildLog.contains("Sorting reactor so changed project are built first.")
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(" BUILD SUCCESS")

return verified;
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Configuration {
public final boolean makeUpstream;
public final boolean skipTestsForNotImpactedModules;
public final boolean buildAll;
public final boolean buildChangedFirst;
public final boolean compareToMergeBase;
public final boolean fetchBaseBranch;
public final boolean fetchReferenceBranch;
Expand Down Expand Up @@ -70,6 +71,7 @@ public Configuration(MavenSession session) throws IOException {
untracked = Boolean.valueOf(Property.untracked.getValue());
skipTestsForNotImpactedModules = Boolean.valueOf(Property.skipTestsForNotImpactedModules.getValue());
buildAll = Boolean.valueOf(Property.buildAll.getValue());
buildChangedFirst = Boolean.valueOf(Property.buildChangedFirst.getValue());
compareToMergeBase = Boolean.valueOf(Property.compareToMergeBase.getValue());
fetchReferenceBranch = Boolean.valueOf(Property.fetchReferenceBranch.getValue());
fetchBaseBranch = Boolean.valueOf(Property.fetchBaseBranch.getValue());
Expand Down Expand Up @@ -166,6 +168,7 @@ public String toString() {
.append("makeUpstream", makeUpstream)
.append("skipTestsForNotImpactedModules", skipTestsForNotImpactedModules)
.append("buildAll", buildAll)
.append("buildChangedFirst", buildChangedFirst)
.append("compareToMergeBase", compareToMergeBase)
.append("fetchBaseBranch", fetchBaseBranch)
.append("fetchReferenceBranch", fetchReferenceBranch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum Property {
untracked("false"),
skipTestsForNotImpactedModules("false"),
buildAll("false"),
buildChangedFirst("false"),
compareToMergeBase("true"),
fetchBaseBranch("false"),
fetchReferenceBranch("false"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -34,6 +35,30 @@ public void setUpSession(Collection<MavenProject> changedProjects) {
final Collection<MavenProject> changed = new ArrayList<>(changedProjects);
changed.addAll(configuration.ignoredProjects);
changed.addAll(configuration.buildAnywaysProjects);

Comparator<MavenProject> comparator;
if (configuration.buildChangedFirst)
{
logger.info("Sorting reactor so changed project are built first.");

comparator = (project1, project2) -> {
if (changedProjects.contains(project1)
&& changedProjects.contains(project2))
// both projects are changed, keep order
return 0;

if (changedProjects.contains(project1))
return -1;
if (changedProjects.contains(project2))
return 1;

return 0;
};
} else {
// do not reshuffle projects
comparator = (project1, project2) -> 0;
}

if (!configuration.buildAll) {
Collection<MavenProject> rebuildProjects = changed;
if (configuration.makeUpstream) {
Expand All @@ -47,6 +72,7 @@ public void setUpSession(Collection<MavenProject> changedProjects) {
} else {
mavenSession.setProjects(mavenSession.getProjects().stream()
.filter(rebuildProjects::contains)
.sorted(comparator)
.collect(Collectors.toList()));
}
} else {
Expand All @@ -56,6 +82,10 @@ public void setUpSession(Collection<MavenProject> changedProjects) {
this.ifSkipDependenciesTest(p);
this.ifSkipDependenciesSonar(p);
});

mavenSession.setProjects(mavenSession.getProjects().stream()
.sorted(comparator)
.collect(Collectors.toList()));
}
}

Expand Down