Skip to content

Commit

Permalink
Use java.specification.version when no source and target version is …
Browse files Browse the repository at this point in the history
…available (#594)
  • Loading branch information
fabapp2 authored Jul 7, 2023
1 parent 59e15aa commit f38d156
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private SourceFile logParseErrors(SourceFile source) {

public List<Marker> generateProvenance(MavenProject mavenProject) {

String javaRuntimeVersion = System.getProperty("java.runtime.version");
String javaRuntimeVersion = System.getProperty("java.specification.version");
String javaVendor = System.getProperty("java.vm.vendor");

String sourceCompatibility = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.openrewrite.maven;

import it.unimi.dsi.fastutil.ints.IntSets;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.logging.SystemStreamLog;
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.internal.DefaultRuntimeInformation;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openrewrite.java.marker.JavaVersion;
import org.openrewrite.marker.Marker;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Fabian Krüger
*/
class MavenMojoProjectParserTest {
@Test
@DisplayName("Given No Java version information exists in Maven Then java.specification.version should be used")
void givenNoJavaVersionInformationExistsInMavenThenJavaSpecificationVersionShouldBeUsed() {
MavenMojoProjectParser sut = new MavenMojoProjectParser(new SystemStreamLog(), null, false, null, new DefaultRuntimeInformation(), false, Collections.EMPTY_LIST, Collections.EMPTY_LIST, -1, null, null, false);
List<Marker> markers = sut.generateProvenance(new MavenProject());
JavaVersion marker = markers.stream().filter(JavaVersion.class::isInstance).map(JavaVersion.class::cast).findFirst().get();
assertThat(marker.getSourceCompatibility()).isEqualTo(System.getProperty("java.specification.version"));
assertThat(marker.getTargetCompatibility()).isEqualTo(System.getProperty("java.specification.version"));
}
}

0 comments on commit f38d156

Please sign in to comment.