Skip to content

Commit

Permalink
Rebase me
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Zarnekow <sebastian.zarnekow@gmail.com>
  • Loading branch information
szarnekow committed Sep 1, 2023
1 parent c0ad65d commit e13b4b7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void testWriteClassPathConfiguration() throws IOException {

File configFile = new File(TMP_DIR, "classpath.config");
assertFalse(configFile.exists());
testBuilder.setClassPathConfigurationLocation(configFile.getAbsolutePath(), "prod");
testBuilder.setClasspathConfigurationLocation(configFile.getAbsolutePath(), "prod", "prod-out");

assertTrue("Builder launch returned false", testBuilder.launch());
assertTrue(configFile.exists());
Expand All @@ -193,7 +193,7 @@ public void testWriteClassPathConfiguration() throws IOException {

testBuilder.setClassPathEntries(ImmutableList.of("test-data/standalone.with.reference/target/classes/",
"test-data/missing.jar"));
testBuilder.setClassPathConfigurationLocation(configFile.getAbsolutePath(), "test");
testBuilder.setClasspathConfigurationLocation(configFile.getAbsolutePath(), "test", "test-out");

assertFalse("Builder launch returned true", testBuilder.launch());

Expand All @@ -208,7 +208,7 @@ public void testWriteClassPathConfiguration() throws IOException {
assertEquals(10, alsoTest.size());

testBuilder.setClassPathEntries(ImmutableList.of("test-data/standalone.with.reference/target/classes/"));
testBuilder.setClassPathConfigurationLocation(configFile.getAbsolutePath(), "prod");
testBuilder.setClasspathConfigurationLocation(configFile.getAbsolutePath(), "prod", "prod-out");

assertFalse("Builder launch returned true", testBuilder.launch());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ public class StandaloneBuilder {

/**
* Location to which the class-path configuration shall be written. The file format is internal.
* Must be configured along with the {@link #classPathKey}.
* Must be configured along with the {@link #classpathKey}.
*/
private String classPathConfigurationLocation;
private String classPathKey;

private String classpathConfigurationLocation;
private String classpathKey;
private String classOutputDirectory;

public StandaloneBuilder() {
try {
Expand All @@ -210,10 +210,11 @@ public void setIncrementalBuild(boolean enable) {
incremental = enable;
}

public void setClassPathConfigurationLocation(String location, String key) {
this.classPathConfigurationLocation = location;
public void setClasspathConfigurationLocation(String location, String key, String outputDirectory) {
this.classpathConfigurationLocation = location;
if (location != null) {
this.classPathKey = Objects.requireNonNull(key);
this.classpathKey = Objects.requireNonNull(key);
this.classOutputDirectory = Objects.requireNonNull(outputDirectory);
}
}

Expand Down Expand Up @@ -254,7 +255,7 @@ public boolean launch() {

forceDebugLog("Collected source models. Took: " + rootStopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms.");

if (classPathConfigurationLocation != null) {
if (classpathConfigurationLocation != null) {
writeClassPathConfiguration(rootsToTravers, stubsDirectory != null);
}

Expand Down Expand Up @@ -342,21 +343,22 @@ public boolean launch() {

private void writeClassPathConfiguration(Iterable<String> modelRoots, boolean classpath) {
try {
File file = new File(classPathConfigurationLocation);
File file = new File(classpathConfigurationLocation);
Properties properties = new Properties();
if (file.exists()) {
try (FileReader reader = new FileReader(file, StandardCharsets.UTF_8)) {
properties.load(reader);
}
}
String prefix = classPathKey + ".";
String prefix = classpathKey + ".";
properties.entrySet().removeIf(existing -> {
String key = String.valueOf(existing.getKey());
return key.startsWith(prefix);
});
intoProperties(modelRoots, prefix + "model.", properties);
intoProperties(sourceDirs, prefix + "src.", properties);
if (classpath) {
intoProperties(List.of(classOutputDirectory), prefix + "bin.", properties);
intoProperties(classPathEntries, prefix + "cp.", properties);
}
try (Writer writer = new TailWriter(new FileWriter(file, StandardCharsets.UTF_8), 1)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ public String getEncoding() {
* @see #writeClassPathConfigurationLocation
*/
@Parameter(defaultValue = "${project.build.directory}/xtext.classpath")
private String classPathConfigurationLocation;
private String classpathConfigurationLocation;

/**
* Allows to write the class-path configuration to a file. The file format is internal
* to the {@link StandaloneBuilder}.
* @see #classPathConfigurationLocation
* @see #classpathConfigurationLocation
*/
@Parameter(defaultValue = "false")
private boolean writeClassPathConfiguration = false;
private boolean writeClasspathConfiguration = false;

@Parameter( defaultValue = "${mojoExecution}", readonly = true )
private MojoExecution mojoExecution;
Expand Down Expand Up @@ -204,8 +204,8 @@ protected void internalExecute() throws MojoExecutionException {
builder.setTempDir(createTempDir().getAbsolutePath());
builder.setDebugLog(getLog().isDebugEnabled());
builder.setIncrementalBuild(incrementalXtextBuild);
if (writeClassPathConfiguration) {
builder.setClassPathConfigurationLocation(classPathConfigurationLocation, mojoExecution.getGoal());
if (writeClasspathConfiguration) {
builder.setClasspathConfigurationLocation(classpathConfigurationLocation, mojoExecution.getGoal(), getClassOutputDirectory());
}
if (clusteringConfig != null) {
builder.setClusteringConfig(clusteringConfig.convertToStandaloneConfig());
Expand All @@ -218,6 +218,8 @@ protected void internalExecute() throws MojoExecutionException {
}
}

protected abstract String getClassOutputDirectory();

protected abstract List<String> getSourceRoots();

private void configureCompiler(IJavaCompiler compiler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class XtextGenerateMojo extends AbstractXtextGeneratorMojo {
public Set<String> getClasspathElements() {
Set<String> classpathElements = newLinkedHashSet();
classpathElements.addAll(this.classpathElements);
classpathElements.remove(getProject().getBuild().getOutputDirectory());
classpathElements.remove(getClassOutputDirectory());
classpathElements.remove(getProject().getBuild().getTestOutputDirectory());
Set<String> nonEmptyElements = newLinkedHashSet(filter(classpathElements, emptyStringFilter()));
return nonEmptyElements;
Expand All @@ -51,6 +51,11 @@ protected void configureMavenOutputs() {
}
}

@Override
protected String getClassOutputDirectory() {
return getProject().getBuild().getOutputDirectory();
}

/**
* Project source roots. List of folders, where the source models are
* located.<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class XtextTestGenerateMojo extends AbstractXtextGeneratorMojo {
public Set<String> getClasspathElements() {
Set<String> classpathElementSet = newLinkedHashSet();
classpathElementSet.addAll(this.classpathElements);
classpathElementSet.remove(getProject().getBuild().getTestOutputDirectory());
classpathElementSet.remove(getClassOutputDirectory());
return newLinkedHashSet(filter(classpathElementSet, emptyStringFilter()));
}

Expand All @@ -53,6 +53,11 @@ protected String tmpDirSuffix() {
return "-test";
}

@Override
protected String getClassOutputDirectory() {
return getProject().getBuild().getTestOutputDirectory();
}

/**
* Project test source roots. List of folders, where the test source models are
* located.<br>
Expand Down

0 comments on commit e13b4b7

Please sign in to comment.