Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit 8836b59

Browse files
committed
New configuration that allow to build changed projects first
1 parent a397fc4 commit 8836b59

7 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.name = TEST build changed first
2+
invoker.goals = -e clean install -Dpartial.buildAll=true -Dpartial.buildChangedFirst=true
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<modules>
8+
<module>child1</module>
9+
<module>child2</module>
10+
<module>child3</module>
11+
<module>child4</module>
12+
<module>child5</module>
13+
<module>child6</module>
14+
<module>child7</module>
15+
</modules>
16+
17+
<groupId>parent</groupId>
18+
<artifactId>parent</artifactId>
19+
<version>1.0-SNAPSHOT</version>
20+
<packaging>pom</packaging>
21+
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<groupId>com.lesfurets</groupId>
26+
<artifactId>partial-build-plugin</artifactId>
27+
<version>@project.version@</version>
28+
<extensions>true</extensions>
29+
<configuration>
30+
<enabled>true</enabled>
31+
<uncommited>false</uncommited>
32+
<referenceBranch>refs/heads/develop</referenceBranch>
33+
<baseBranch>refs/heads/feature/1</baseBranch>
34+
</configuration>
35+
</plugin>
36+
</plugins>
37+
</build>
38+
39+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import com.lesfurets.maven.partial.mocks.ITHelper
2+
3+
def testProjectBasedir = basedir as File
4+
def pbpBaseDir = sourceDir as String
5+
def pbpVersion = projectVersion as String
6+
new ITHelper(testProjectBasedir, pbpBaseDir, pbpVersion).setupTest()
7+
8+
return true
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import org.codehaus.plexus.util.FileUtils
2+
3+
def file = new File(basedir, "build.log")
4+
String buildLog = FileUtils.fileRead(file)
5+
6+
boolean verified = true
7+
verified &= buildLog.contains("Sorting reactor so changed project are built first.")
8+
verified &= buildLog.contains(" subchild2")
9+
verified &= buildLog.contains(" child3")
10+
verified &= buildLog.contains(" child4")
11+
verified &= buildLog.contains(" subchild41")
12+
13+
verified &= buildLog.contains(" child1")
14+
verified &= buildLog.contains(" child2")
15+
verified &= buildLog.contains(" child5")
16+
verified &= buildLog.contains(" child6")
17+
verified &= buildLog.contains(" child7")
18+
verified &= buildLog.contains(" subchild1")
19+
verified &= buildLog.contains(" subchild42")
20+
verified &= buildLog.contains(" parent")
21+
22+
verified &= buildLog.contains(" BUILD SUCCESS")
23+
24+
return verified;

src/main/java/com/lesfurets/maven/partial/core/Configuration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Configuration {
3535
public final boolean makeUpstream;
3636
public final boolean skipTestsForNotImpactedModules;
3737
public final boolean buildAll;
38+
public final boolean buildChangedFirst;
3839
public final boolean compareToMergeBase;
3940
public final boolean fetchBaseBranch;
4041
public final boolean fetchReferenceBranch;
@@ -70,6 +71,7 @@ public Configuration(MavenSession session) throws IOException {
7071
untracked = Boolean.valueOf(Property.untracked.getValue());
7172
skipTestsForNotImpactedModules = Boolean.valueOf(Property.skipTestsForNotImpactedModules.getValue());
7273
buildAll = Boolean.valueOf(Property.buildAll.getValue());
74+
buildChangedFirst = Boolean.valueOf(Property.buildChangedFirst.getValue());
7375
compareToMergeBase = Boolean.valueOf(Property.compareToMergeBase.getValue());
7476
fetchReferenceBranch = Boolean.valueOf(Property.fetchReferenceBranch.getValue());
7577
fetchBaseBranch = Boolean.valueOf(Property.fetchBaseBranch.getValue());
@@ -166,6 +168,7 @@ public String toString() {
166168
.append("makeUpstream", makeUpstream)
167169
.append("skipTestsForNotImpactedModules", skipTestsForNotImpactedModules)
168170
.append("buildAll", buildAll)
171+
.append("buildChangedFirst", buildChangedFirst)
169172
.append("compareToMergeBase", compareToMergeBase)
170173
.append("fetchBaseBranch", fetchBaseBranch)
171174
.append("fetchReferenceBranch", fetchReferenceBranch)

src/main/java/com/lesfurets/maven/partial/core/Property.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum Property {
1010
untracked("false"),
1111
skipTestsForNotImpactedModules("false"),
1212
buildAll("false"),
13+
buildChangedFirst("false"),
1314
compareToMergeBase("true"),
1415
fetchBaseBranch("false"),
1516
fetchReferenceBranch("false"),

src/main/java/com/lesfurets/maven/partial/core/RebuildProjects.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.ArrayList;
99
import java.util.Collection;
10+
import java.util.Comparator;
1011
import java.util.stream.Collectors;
1112
import java.util.stream.Stream;
1213

@@ -34,6 +35,30 @@ public void setUpSession(Collection<MavenProject> changedProjects) {
3435
final Collection<MavenProject> changed = new ArrayList<>(changedProjects);
3536
changed.addAll(configuration.ignoredProjects);
3637
changed.addAll(configuration.buildAnywaysProjects);
38+
39+
Comparator<MavenProject> comparator;
40+
if (configuration.buildChangedFirst)
41+
{
42+
logger.info("Sorting reactor so changed project are built first.");
43+
44+
comparator = (project1, project2) -> {
45+
if (changedProjects.contains(project1)
46+
&& changedProjects.contains(project2))
47+
// both projects are changed, keep order
48+
return 0;
49+
50+
if (changedProjects.contains(project1))
51+
return -1;
52+
if (changedProjects.contains(project2))
53+
return 1;
54+
55+
return 0;
56+
};
57+
} else {
58+
// do not reshuffle projects
59+
comparator = (project1, project2) -> 0;
60+
}
61+
3762
if (!configuration.buildAll) {
3863
Collection<MavenProject> rebuildProjects = changed;
3964
if (configuration.makeUpstream) {
@@ -47,6 +72,7 @@ public void setUpSession(Collection<MavenProject> changedProjects) {
4772
} else {
4873
mavenSession.setProjects(mavenSession.getProjects().stream()
4974
.filter(rebuildProjects::contains)
75+
.sorted(comparator)
5076
.collect(Collectors.toList()));
5177
}
5278
} else {
@@ -56,6 +82,10 @@ public void setUpSession(Collection<MavenProject> changedProjects) {
5682
this.ifSkipDependenciesTest(p);
5783
this.ifSkipDependenciesSonar(p);
5884
});
85+
86+
mavenSession.setProjects(mavenSession.getProjects().stream()
87+
.sorted(comparator)
88+
.collect(Collectors.toList()));
5989
}
6090
}
6191

0 commit comments

Comments
 (0)