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

[1.5.z] Backport 23/10/2024 #1381

Merged
merged 4 commits into from
Oct 23, 2024
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 @@ -196,8 +196,10 @@ public static Properties readPropertiesYamlFile(QuarkusCliRestService app) throw

public static Properties loadPropertiesFromFile(File file) throws IOException {
Properties properties = new Properties();
properties.load(new FileInputStream(file));
return properties;
try (FileInputStream is = new FileInputStream(file)) {
properties.load(is);
return properties;
}
}

public static File getPropertiesFile(QuarkusCliRestService app) {
Expand Down Expand Up @@ -312,13 +314,15 @@ public static Model getPom(QuarkusCliRestService app) throws XmlPullParserExcept
public static Model getPom(QuarkusCliRestService app, String subdir) throws IOException, XmlPullParserException {
File pomfile = app.getFileFromApplication(subdir, POM_FILE);
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
XmlStreamReader streamReader = new XmlStreamReader(pomfile);
return mavenReader.read(streamReader);
try (XmlStreamReader streamReader = new XmlStreamReader(pomfile)) {
Copy link
Member

@michalvavrik michalvavrik Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I might have a MavenXpp3Reader were I made mistake. I have to revise what I do.

return mavenReader.read(streamReader);
}
}

public static void savePom(QuarkusCliRestService app, Model model) throws IOException {
OutputStream output = new FileOutputStream(app.getFileFromApplication(POM_FILE));
new MavenXpp3Writer().write(output, model);
try (OutputStream output = new FileOutputStream(app.getFileFromApplication(POM_FILE))) {
new MavenXpp3Writer().write(output, model);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collection;
Expand All @@ -22,14 +21,16 @@ public static void writePropertiesIntoYaml(File yamlFile, Properties properties)
yaml.dump(properties, new FileWriter(yamlFile));
}

public static Properties readYamlFileIntoProperties(File yamlFile) throws FileNotFoundException {
public static Properties readYamlFileIntoProperties(File yamlFile) throws IOException {
Yaml yaml = new Yaml();
Map<String, Object> obj = yaml.load(new FileInputStream(yamlFile));
try (FileInputStream is = new FileInputStream(yamlFile)) {
Map<String, Object> obj = yaml.load(is);

Properties properties = new Properties();
properties.putAll(getFlattenedMap(obj));
Properties properties = new Properties();
properties.putAll(getFlattenedMap(obj));

return properties;
return properties;
}
}

private static Map<String, Object> getFlattenedMap(Map<String, Object> source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@Inherited
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(DisabledOnFipsAndJava17Condition.class)
public @interface DisabledOnFipsAndJava17 {
@ExtendWith(DisabledOnFipsAndNativeCondition.class)
public @interface DisabledOnFipsAndNative {
/**
* Why is the annotated test class or test method disabled.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package io.quarkus.test.scenarios.annotations;

import static io.quarkus.test.services.quarkus.model.QuarkusProperties.isNativeEnabled;

import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

public class DisabledOnFipsAndJava17Condition implements ExecutionCondition {
public class DisabledOnFipsAndNativeCondition implements ExecutionCondition {

/**
* We set environment variable "FIPS" to "fips" in our Jenkins jobs when FIPS are enabled.
*/
private static final String FIPS_ENABLED = "fips";
private static final int JAVA_17 = 17;

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
if (isFipsEnabledEnvironment() && isJava17()) {
return ConditionEvaluationResult.disabled("The test is running in FIPS enabled environment with Java 17");
if (isFipsEnabledEnvironment() && isNativeEnabled()) {
return ConditionEvaluationResult.disabled("The test is running in FIPS enabled environment in native mode");
}

return ConditionEvaluationResult.enabled("The test is not running in FIPS enabled environment with Java 17");
return ConditionEvaluationResult.enabled("The test is not running in FIPS enabled environment in native mode");
}

private static boolean isFipsEnabledEnvironment() {
return FIPS_ENABLED.equals(System.getenv().get("FIPS"));
return FIPS_ENABLED.equalsIgnoreCase(System.getenv().get("FIPS"));
}

private static boolean isJava17() {
return JAVA_17 == Runtime.version().feature();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.test.scenarios.annotations;

import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

import io.quarkus.test.services.quarkus.model.QuarkusProperties;
import io.smallrye.common.os.OS;

public class DisabledOnRHBQWindowsConditions implements ExecutionCondition {

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
boolean isWindows = OS.current().equals(OS.WINDOWS);
if (QuarkusProperties.isRHBQ() && isWindows) {
return ConditionEvaluationResult.disabled("It is RHBQ on Windows");
} else {
return ConditionEvaluationResult.enabled("It is not RHBQ on Windows");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.test.scenarios.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;

@Inherited
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(DisabledOnRHBQWindowsConditions.class)
public @interface DisabledOnRHBQandWindows {

/**
* Why is the annotated test class or test method disabled.
*/
String reason();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static io.quarkus.test.services.quarkus.model.QuarkusProperties.getPluginVersion;
import static io.quarkus.test.services.quarkus.model.QuarkusProperties.getVersion;
import static io.quarkus.test.utils.FileUtils.findTargetFile;
import static io.quarkus.test.utils.MavenUtils.MVN_REPOSITORY_LOCAL;
import static io.quarkus.test.utils.PropertiesUtils.SLASH;
import static io.quarkus.test.utils.PropertiesUtils.toMvnSystemProperty;
import static java.util.stream.Collectors.toSet;
Expand Down Expand Up @@ -237,6 +238,12 @@ private String[] getBuildCmd(Mode mode) {
toMvnSystemProperty(PLATFORM_VERSION.getPropertyKey(), getVersion()),
toMvnSystemProperty(PLATFORM_GROUP_ID.getPropertyKey(), PLATFORM_GROUP_ID.get()),
toMvnSystemProperty(PLUGIN_VERSION.getPropertyKey(), getPluginVersion())));

// Need to add local maven repo due to differences in `getCmdLineBuildArgs` as by default it's not picked on Windows
if (OS.WINDOWS.isCurrent() && System.getProperty(MVN_REPOSITORY_LOCAL) != null) {
cmdStream = Stream.concat(cmdStream,
Stream.of(toMvnSystemProperty(MVN_REPOSITORY_LOCAL, System.getProperty(MVN_REPOSITORY_LOCAL))));
}
var cmdLineBuildArgs = getCmdLineBuildArgs();
if (!cmdLineBuildArgs.isEmpty()) {
cmdStream = Stream.concat(cmdStream, cmdLineBuildArgs.stream());
Expand Down