Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use java.specification.version when no source and target version exists #594

Merged
merged 1 commit into from
Jul 7, 2023
Merged
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
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;
knutwannheden marked this conversation as resolved.
Show resolved Hide resolved

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"));
}
}