From 5dc636ea21b05eee8deae776be5cac4eb168f95b Mon Sep 17 00:00:00 2001 From: Ken Duck Date: Tue, 26 Mar 2019 01:23:04 -0300 Subject: [PATCH] Add windows workaround --- build.gradle | 3 ++- .../gradle/output/JunitXmlReportWriter.java | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 0a7986f..93649be 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { } group 'net.ossindex' -version '0.4.9' +version '0.4.10' apply plugin: "com.gradle.plugin-publish" apply plugin: 'java' @@ -54,6 +54,7 @@ dependencies { implementation 'org.mockito:mockito-core:2.18.0' implementation 'org.slf4j:slf4j-api:1.7.25' implementation 'org.slf4j:slf4j-simple:1.7.25' + implementation 'org.apache.commons:commons-lang3:3.8.1' // Use our shadow copy of mapdb compile files ('ossi-mapdb/build/libs/ossi-mapdb-3.0.7.jar') diff --git a/src/main/java/net/ossindex/gradle/output/JunitXmlReportWriter.java b/src/main/java/net/ossindex/gradle/output/JunitXmlReportWriter.java index d13b501..faa602d 100644 --- a/src/main/java/net/ossindex/gradle/output/JunitXmlReportWriter.java +++ b/src/main/java/net/ossindex/gradle/output/JunitXmlReportWriter.java @@ -25,6 +25,8 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.commons.lang3.SystemUtils; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Attr; @@ -300,12 +302,20 @@ private Boolean parentDirIsWritable(File path) throws IOException { parentDir.mkdirs(); } if (parentDir.exists()) { - Set permissions = Files - .getPosixFilePermissions(Paths.get(parentDir.getAbsolutePath()), LinkOption.NOFOLLOW_LINKS); - return (permissions.contains(PosixFilePermission.OTHERS_WRITE) || - permissions.contains(PosixFilePermission.GROUP_WRITE) || - permissions.contains(PosixFilePermission.OWNER_WRITE) - ); + if (SystemUtils.IS_OS_WINDOWS) { + // Special code for windows + return Files.isWritable(parentDir.toPath()); + } + else { + // Leave the fancy code for unix based systems. We don't want to disturb any magic that + // may be running here, so don't remove for now. + Set permissions = Files + .getPosixFilePermissions(Paths.get(parentDir.getAbsolutePath()), LinkOption.NOFOLLOW_LINKS); + return (permissions.contains(PosixFilePermission.OTHERS_WRITE) || + permissions.contains(PosixFilePermission.GROUP_WRITE) || + permissions.contains(PosixFilePermission.OWNER_WRITE) + ); + } } return false; }