Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
Add windows workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-duck committed Mar 26, 2019
1 parent 9b42ab4 commit 5dc636e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/net/ossindex/gradle/output/JunitXmlReportWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -300,12 +302,20 @@ private Boolean parentDirIsWritable(File path) throws IOException {
parentDir.mkdirs();
}
if (parentDir.exists()) {
Set<PosixFilePermission> 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<PosixFilePermission> 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;
}
Expand Down

0 comments on commit 5dc636e

Please sign in to comment.