-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
577 additions
and
0 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,58 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.deegree</groupId> | ||
<artifactId>deegree-jaxb-util</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>deegree-jaxb-util</name> | ||
<packaging>jar</packaging> | ||
<description>JAXB util to manipulate source tree related to deegree schema files</description> | ||
|
||
<repositories> | ||
<repository> | ||
<id>deegree-repo</id> | ||
<url>http://repo.deegree.org/content/groups/public</url> | ||
<releases> | ||
<updatePolicy>never</updatePolicy> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
<encoding>${project.build.sourceEncoding}</encoding> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<buildTimestamp>${maven.build.timestamp}</buildTimestamp> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.7.30</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>info.picocli</groupId> | ||
<artifactId>picocli</artifactId> | ||
<version>4.6.1</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
113 changes: 113 additions & 0 deletions
113
...upled/deegree-jaxb-util/src/main/java/org/deegree/uncoupled/jaxbutil/AbstractScanner.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,113 @@ | ||
package org.deegree.uncoupled.jaxbutil; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.PathMatcher; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import picocli.CommandLine.Option; | ||
|
||
public abstract class AbstractScanner { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(AbstractScanner.class); | ||
|
||
protected static final Pattern PAT_VERSION = Pattern.compile("^(VERSION|V|)[0-9]([._-][0-9]+)*(|-SNAPSHOT)$", | ||
Pattern.CASE_INSENSITIVE); | ||
|
||
@Option(names = { "-b", "--base" }, description = "Base path (where to start scanning)") | ||
protected String path = "../../"; | ||
|
||
@Option(names = { "--schemas" }, // | ||
description = "Location where to find schemas, default to http://schemas.deegree.org") | ||
protected String schemasUrl = "http://schemas.deegree.org"; | ||
|
||
public static List<Path> getFilesMatching(Path basePath, String glob) throws IOException { | ||
if (!Files.isDirectory(basePath)) { | ||
return emptyList(); | ||
} | ||
|
||
final PathMatcher mext = FileSystems.getDefault().getPathMatcher(glob); | ||
final List<Path> res = new LinkedList<Path>(); | ||
|
||
Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() { | ||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | ||
|
||
if (!attrs.isDirectory() && mext.matches(file.getFileName())) { | ||
LOG.trace("Lookup Soruce file {} for test", file); | ||
res.add(file); | ||
} | ||
|
||
return FileVisitResult.CONTINUE; | ||
} | ||
}); | ||
|
||
return res; | ||
} | ||
|
||
public static List<Path> getFilesMatchingCompletePath(Path basePath, String glob, String... excludes) | ||
throws IOException { | ||
if (!Files.isDirectory(basePath)) { | ||
return emptyList(); | ||
} | ||
FileSystem fs = FileSystems.getDefault(); | ||
final PathMatcher mext = fs.getPathMatcher(glob); | ||
List<PathMatcher> mexcludes = Arrays.stream(excludes) // | ||
.map(fs::getPathMatcher) // | ||
.collect(Collectors.toList()); | ||
final List<Path> res = new LinkedList<Path>(); | ||
|
||
Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() { | ||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | ||
boolean exclude = false; | ||
for (PathMatcher mexclude : mexcludes) { | ||
if (mexclude.matches(file)) { | ||
exclude = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!attrs.isDirectory() && !exclude && mext.matches(file)) { | ||
LOG.trace("Lookup Soruce file {} for test", file); | ||
res.add(file); | ||
} | ||
|
||
return FileVisitResult.CONTINUE; | ||
} | ||
}); | ||
|
||
return res; | ||
} | ||
|
||
protected Path removeVersion(Path p) { | ||
Path res = null; | ||
for (int i = 0, len = p.getNameCount(); i < len; i++) { | ||
String seg = p.getName(i).toString(); | ||
if (PAT_VERSION.matcher(seg).matches()) { | ||
continue; | ||
} | ||
if (res == null) { | ||
res = p.getName(i); | ||
} else { | ||
res = res.resolve(p.getName(i)); | ||
} | ||
} | ||
return res; | ||
} | ||
} |
Oops, something went wrong.