forked from veraPDF/veraPDF-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MaximPlusov/verapdf_examples
Verapdf examples
- Loading branch information
Showing
29 changed files
with
1,452 additions
and
47 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,35 @@ | ||
name: PR QA | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
build: | ||
name: Checkout and Build | ||
runs-on: ubuntu-20.04 | ||
|
||
strategy: | ||
matrix: | ||
java-version: [8, 11, 16, 17] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: JDK setup | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: ${{ matrix.java-version }} | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Build with Maven | ||
run: mvn --batch-mode --update-snapshots verify | ||
|
||
coverage: | ||
name: Quality Assurance | ||
runs-on: ubuntu-20.04 | ||
needs: [ build ] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Codacy analysis reporting | ||
uses: codacy/codacy-analysis-cli-action@master |
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,23 @@ | ||
name: Test | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
build: | ||
name: Checkout and Build | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: JDK setup | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: 11 | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Test | ||
run: cd policy-generator | ||
mvn clean package | ||
cd target | ||
java -jar policy-generator.jar |
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,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>verapdf-tools</artifactId> | ||
<groupId>org.verapdf</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>org.verapdf</groupId> | ||
<artifactId>corpus-wiki-generator</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.verapdf</groupId> | ||
<artifactId>validation-model</artifactId> | ||
<version>${verapdf.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.pdfbox</groupId> | ||
<artifactId>pdfbox</artifactId> | ||
<version>2.0.26</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>org.verapdf.tools.CorpusWikiGenerator</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> <!-- this is used for inheritance merges --> | ||
<phase>package</phase> <!-- bind to the packaging phase --> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
</project> |
78 changes: 78 additions & 0 deletions
78
corpus-wiki-generation/src/main/java/org/verapdf/tools/CorpusDownload.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,78 @@ | ||
package org.verapdf.tools; | ||
|
||
|
||
import java.io.*; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.net.URLDecoder; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
//code from integration-tests | ||
public class CorpusDownload { | ||
|
||
public static File createTempFileFromCorpus(final URL downloadLoc, final String prefix) throws IOException { | ||
File tempFile = File.createTempFile(prefix, ".zip"); | ||
System.out.println("Downloading: " + downloadLoc + ", to temp:" + tempFile); | ||
int totalBytes = 0; | ||
try (OutputStream output = new FileOutputStream(tempFile); | ||
InputStream corpusInput = handleRedirects(downloadLoc)) { | ||
byte[] buffer = new byte[8 * 1024]; | ||
int bytesRead; | ||
while ((bytesRead = corpusInput.read(buffer)) != -1) { | ||
output.write(buffer, 0, bytesRead); | ||
totalBytes += bytesRead; | ||
} | ||
} | ||
System.out.println("Downloaded: " + totalBytes + " bytes"); | ||
tempFile.deleteOnExit(); | ||
return tempFile; | ||
} | ||
|
||
static InputStream handleRedirects(URL url) throws IOException { | ||
if (!url.getProtocol().startsWith("http")) { | ||
return url.openStream(); | ||
} | ||
System.err.println("Prot:" + url.getProtocol()); | ||
URL resourceUrl; | ||
URL base; | ||
URL next; | ||
Map<String, Integer> visited; | ||
HttpURLConnection conn; | ||
String location; | ||
String urlString = url.toExternalForm(); | ||
int times; | ||
|
||
visited = new HashMap<>(); | ||
|
||
while (true) { | ||
times = visited.compute(urlString, (key, count) -> count == null ? 1 : count + 1); | ||
|
||
if (times > 3) | ||
throw new IOException("Stuck in redirect loop"); | ||
|
||
resourceUrl = new URL(urlString); | ||
conn = (HttpURLConnection) resourceUrl.openConnection(); | ||
|
||
conn.setConnectTimeout(15000); | ||
conn.setReadTimeout(15000); | ||
conn.setInstanceFollowRedirects(false); // Make the logic below easier to detect redirections | ||
conn.setRequestProperty("User-Agent", "Mozilla/5.0..."); | ||
|
||
switch (conn.getResponseCode()) { | ||
case HttpURLConnection.HTTP_MOVED_PERM: | ||
case HttpURLConnection.HTTP_MOVED_TEMP: | ||
location = conn.getHeaderField("Location"); | ||
location = URLDecoder.decode(location, "UTF-8"); | ||
base = new URL(urlString); | ||
next = new URL(base, location); // Deal with relative URLs | ||
urlString = next.toExternalForm(); | ||
continue; | ||
} | ||
|
||
break; | ||
} | ||
|
||
return conn.getInputStream(); | ||
} | ||
} |
Oops, something went wrong.