From 58266a1beabbeb46186cc44e3625d35183727506 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 19 Feb 2021 15:41:24 -0500 Subject: [PATCH] Fix junit for "native" on Windows Windows doesn't like file names containing ":". Added code to replace ":" with "_", but only when the JVM is run on a Windows OS. Issue-ID: POLICY-3085 Change-Id: I1d3b6819bf564571eddda69e4c5fbd2bb807a3aa Signed-off-by: Jim Hahn --- .../pdp/xacml/application/common/XacmlPolicyUtils.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java index 1babe30c..a2ecf8c0 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.StringJoiner; +import java.util.function.Function; import java.util.stream.Collectors; import oasis.names.tc.xacml._3_0.core.schema.wd_17.IdReferenceType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; @@ -57,6 +58,15 @@ public class XacmlPolicyUtils { private static final String DOT_FILE_SUFFIX = ".file"; private static final String NOT_FOUND_MESSAGE = "NOT FOUND"; + /** + * Function that sanitizes a file name, if the OS is Windows, so that it's a valid + * file name. Does nothing for other OSs. + */ + private static final Function SANITIZE_FILE_NAME = + System.getProperty("os.name").startsWith("Windows") + ? filename -> filename.replace(':', '_') + : filename -> filename; + private XacmlPolicyUtils() { super(); } @@ -371,7 +381,7 @@ public class XacmlPolicyUtils { // // Construct the Path // - return Paths.get(path.toAbsolutePath().toString(), filename); + return Paths.get(path.toAbsolutePath().toString(), SANITIZE_FILE_NAME.apply(filename)); } /** -- 2.16.6