forked from WrenSecurity/wrenidm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Windows build incompatibilities. WrenSecurity#168
- Loading branch information
1 parent
a033c5e
commit 84b28d5
Showing
17 changed files
with
324 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Test resources sensitive to content length | ||
openidm-external-rest/src/test/resources/*.html text eol=lf | ||
openidm-external-rest/src/test/resources/*.xml text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
openidm-launcher/src/main/java/org/forgerock/commons/launcher/support/DirectoryScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* The contents of this file are subject to the terms of the Common Development and | ||
* Distribution License (the License). You may not use this file except in compliance with the | ||
* License. | ||
* | ||
* You can obtain a copy of the License at legal/CDDLv1.1.txt. See the License for the | ||
* specific language governing permission and limitations under the License. | ||
* | ||
* When distributing Covered Software, include this CDDL Header Notice in each file and include | ||
* the License file at legal/CDDLv1.1.txt. If applicable, add the following below the CDDL | ||
* Header, with the fields enclosed by brackets [] replaced by your own identifying | ||
* information: "Portions copyright [year] [name of copyright owner]". | ||
* | ||
* Copyright 2024 Wren Security | ||
*/ | ||
package org.forgerock.commons.launcher.support; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitOption; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.PathMatcher; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Simple file tree walker based on previously used Plexus Utils' {@code DirectoryScanner}. | ||
* | ||
* <p> | ||
* The implementation does not try to do anything clever to optimize path traversal (e.g. by prefix | ||
* matching to prevent walking into directories that can not contain matching files). | ||
*/ | ||
public class DirectoryScanner { | ||
|
||
private PathMatcher includes; | ||
|
||
private PathMatcher excludes; | ||
|
||
public DirectoryScanner(List<String> includes, List<String> excludes) { | ||
this(includes != null ? new GlobPathMatcher(includes) : null, | ||
excludes != null ? new GlobPathMatcher(excludes) : null); | ||
} | ||
|
||
public DirectoryScanner(PathMatcher includes, PathMatcher excludes) { | ||
this.includes = includes != null ? includes : new GlobPathMatcher("**"); | ||
this.excludes = excludes != null ? excludes : new GlobPathMatcher(); | ||
} | ||
|
||
public List<Path> scan(Path start) throws IOException { | ||
return Files.walk(start, FileVisitOption.FOLLOW_LINKS) | ||
.map(start::relativize) | ||
.filter(includes::matches) | ||
.filter(Predicate.not(excludes::matches)) | ||
.filter(Predicate.not(Files::isDirectory)) | ||
.map(start::resolve) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
openidm-launcher/src/main/java/org/forgerock/commons/launcher/support/GlobPathMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* The contents of this file are subject to the terms of the Common Development and | ||
* Distribution License (the License). You may not use this file except in compliance with the | ||
* License. | ||
* | ||
* You can obtain a copy of the License at legal/CDDLv1.1.txt. See the License for the | ||
* specific language governing permission and limitations under the License. | ||
* | ||
* When distributing Covered Software, include this CDDL Header Notice in each file and include | ||
* the License file at legal/CDDLv1.1.txt. If applicable, add the following below the CDDL | ||
* Header, with the fields enclosed by brackets [] replaced by your own identifying | ||
* information: "Portions copyright [year] [name of copyright owner]". | ||
* | ||
* Copyright 2024 Wren Security | ||
*/ | ||
package org.forgerock.commons.launcher.support; | ||
|
||
import java.nio.file.FileSystems; | ||
import java.nio.file.Path; | ||
import java.nio.file.PathMatcher; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Glob based path matcher that emulates behavior of previously used {@code MatchPattern} from Plexus Utils. | ||
* | ||
* <p> | ||
* Matcher uses native JRE's path matcher provided by default {@code FileSystem} implementation. This means that | ||
* the behavior might be platform dependent depending on the used patterns. | ||
* | ||
* <p> | ||
* <b>CAUTION:</b> Plexus Utils' {@code MatchPattern} was matching simple filename patterns even in subdirectories. | ||
* This implementation is not matching subdirectories without path traversal wildcard <code>**/</code>. | ||
*/ | ||
public class GlobPathMatcher implements PathMatcher { | ||
|
||
private final List<PathMatcher> matchers; | ||
|
||
public GlobPathMatcher(String... pattern) { | ||
this(List.of(pattern)); | ||
} | ||
|
||
public GlobPathMatcher(List<String> patterns) { | ||
var fileSystem = FileSystems.getDefault(); | ||
this.matchers = patterns.stream() | ||
// make directory wildcard pattern optional and the pattern case insensitive | ||
.map(pattern -> pattern.replace("**/", "{**/,}").toLowerCase()) | ||
.map(pattern -> fileSystem.getPathMatcher("glob:" + pattern)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public boolean matches(Path path) { | ||
var normalized = Path.of(path.toString().toLowerCase()); | ||
return matchers.stream().anyMatch(matcher -> matcher.matches(normalized)); | ||
} | ||
|
||
} |
Oops, something went wrong.