-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4397 from benkard/mulk/feature/devmode-compiler-f…
…lags Maven plugin: Support <compilerArgs/>, <source/>, <target/> in dev mode
- Loading branch information
Showing
9 changed files
with
327 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
core/devmode/src/main/java/io/quarkus/dev/CompilerFlags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.quarkus.dev; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import io.quarkus.runtime.util.StringUtil; | ||
|
||
/** | ||
* A set of compiler flags for javac. | ||
* | ||
* Can combine system-provided default flags with user-supplied flags and <code>-source</code> | ||
* and <code>-target</code> settings. | ||
*/ | ||
public class CompilerFlags { | ||
|
||
private final Set<String> defaultFlags; | ||
private final List<String> userFlags; | ||
private final String sourceJavaVersion; //can be null | ||
private final String targetJavaVersion; //can be null | ||
|
||
public CompilerFlags( | ||
Set<String> defaultFlags, | ||
Collection<String> userFlags, | ||
String sourceJavaVersion, | ||
String targetJavaVersion) { | ||
|
||
this.defaultFlags = defaultFlags == null ? new HashSet<>() : new HashSet<>(defaultFlags); | ||
this.userFlags = userFlags == null ? new ArrayList<>() : new ArrayList<>(userFlags); | ||
this.sourceJavaVersion = sourceJavaVersion; | ||
this.targetJavaVersion = targetJavaVersion; | ||
} | ||
|
||
public List<String> toList() { | ||
List<String> flagList = new ArrayList<>(); | ||
|
||
// The set of effective default flags is the set of default flags except the ones also | ||
// set by the user. This ensures that we do not needlessly pass the default flags twice. | ||
Set<String> effectiveDefaultFlags = new HashSet<>(this.defaultFlags); | ||
effectiveDefaultFlags.removeAll(userFlags); | ||
|
||
flagList.addAll(effectiveDefaultFlags); | ||
|
||
// Add -source and -target flags. | ||
if (sourceJavaVersion != null) { | ||
flagList.add("-source"); | ||
flagList.add(sourceJavaVersion); | ||
} | ||
if (targetJavaVersion != null) { | ||
flagList.add("-target"); | ||
flagList.add(targetJavaVersion); | ||
} | ||
|
||
flagList.addAll(userFlags); | ||
|
||
return flagList; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return toList().hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return obj instanceof CompilerFlags && toList().equals(((CompilerFlags) obj).toList()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CompilerFlags@{" + StringUtil.join(", ", toList().iterator()) + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
core/devmode/src/test/java/io/quarkus/dev/CompilerFlagsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package io.quarkus.dev; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class CompilerFlagsTest { | ||
|
||
@Test | ||
void nullHandling() { | ||
assertAll( | ||
() -> assertEquals( | ||
new CompilerFlags(null, null, null, null), | ||
new CompilerFlags(setOf(), listOf(), null, null))); | ||
} | ||
|
||
@Test | ||
void defaulting() { | ||
assertAll( | ||
() -> assertEquals( | ||
new CompilerFlags(setOf("-a", "-b"), listOf(), null, null), | ||
new CompilerFlags(setOf(), listOf("-a", "-b"), null, null)), | ||
() -> assertEquals( | ||
new CompilerFlags(setOf("-a", "-b"), listOf("-c", "-d"), null, null), | ||
new CompilerFlags(setOf(), listOf("-a", "-b", "-c", "-d"), null, null))); | ||
} | ||
|
||
@Test | ||
void redundancyReduction() { | ||
assertAll( | ||
() -> assertEquals( | ||
new CompilerFlags(setOf("-a", "-b"), listOf(), null, null), | ||
new CompilerFlags(setOf(), listOf("-a", "-b"), null, null)), | ||
() -> assertEquals( | ||
new CompilerFlags(setOf("-a", "-b", "-c"), listOf("-a", "-b"), null, null), | ||
new CompilerFlags(setOf("-c"), listOf("-a", "-b"), null, null))); | ||
} | ||
|
||
@Test | ||
void sourceAndTarget() { | ||
assertAll( | ||
() -> assertEquals( | ||
new CompilerFlags(setOf(), listOf(), "1", null), | ||
new CompilerFlags(setOf(), listOf("-source", "1"), null, null)), | ||
() -> assertEquals( | ||
new CompilerFlags(setOf(), listOf(), null, "2"), | ||
new CompilerFlags(setOf(), listOf("-target", "2"), null, null)), | ||
() -> assertEquals( | ||
new CompilerFlags(setOf(), listOf(), "1", "2"), | ||
new CompilerFlags(setOf(), listOf("-source", "1", "-target", "2"), null, null)), | ||
() -> assertEquals( | ||
new CompilerFlags(setOf(), listOf("-source", "3", "-target", "4"), "1", "2"), | ||
new CompilerFlags(setOf(), listOf("-source", "1", "-target", "2", "-source", "3", "-target", "4"), null, | ||
null))); | ||
} | ||
|
||
@Test | ||
void allFeatures() { | ||
assertAll( | ||
() -> assertEquals( | ||
new CompilerFlags(setOf("-b", "-c", "-d"), listOf("-a", "-b", "-c"), "1", "2"), | ||
new CompilerFlags(setOf(), listOf("-d", "-source", "1", "-target", "2", "-a", "-b", "-c"), null, | ||
null))); | ||
} | ||
|
||
@Test | ||
void listConversion() { | ||
assertAll( | ||
() -> assertEquals( | ||
new CompilerFlags(null, null, null, null).toList(), | ||
listOf()), | ||
() -> assertEquals( | ||
new CompilerFlags(setOf(), listOf("-a", "-b", "-c", "-d"), null, null).toList(), | ||
listOf("-a", "-b", "-c", "-d"))); | ||
} | ||
|
||
private List<String> listOf(String... strings) { | ||
return Arrays.asList(strings); | ||
} | ||
|
||
private Set<String> setOf(String... strings) { | ||
return new HashSet<>(Arrays.asList(strings)); | ||
} | ||
|
||
} |
Oops, something went wrong.