Skip to content

Fix compitability with all java from 8 to 12 #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
sudo: required
language: java

services:
Expand Down Expand Up @@ -32,6 +31,17 @@ env:
- UTPLSQL_VERSION="develop"
UTPLSQL_FILE="utPLSQL"

matrix:
include:
- env: UTPLSQL_VERSION="v3.1.6"
jdk: openjdk9
- env: UTPLSQL_VERSION="v3.1.6"
jdk: openjdk10
- env: UTPLSQL_VERSION="v3.1.6"
jdk: openjdk11
- env: UTPLSQL_VERSION="v3.1.6"
jdk: openjdk12

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand Down
23 changes: 22 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = if (tag != null && "^[0-9.]+$".toRegex().matches(tag)) tag else baseVe

val coverageResourcesVersion = "1.0.1"
val ojdbcVersion = "12.2.0.1"
val junitVersion = "5.4.1"
val junitVersion = "5.4.2"

val deployerJars by configurations.creating

Expand Down Expand Up @@ -70,6 +70,26 @@ tasks {
}
}

// run tests using compiled jar + dependencies and tests classes
val binaryTest = create<Test>("binaryTest") {
dependsOn(jar, testClasses)

doFirst {
classpath = project.files("$buildDir/libs/java-api-$baseVersion.jar", "$buildDir/classes/java/test", configurations.testRuntimeClasspath)
testClassesDirs = sourceSets.getByName("test").output.classesDirs
}

useJUnitPlatform {
includeTags("binary")
}
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
showStackTraces = true
showStandardStreams = true
}
}

val intTest = create<Test>("intTest") {
dependsOn(test)
doFirst {
Expand All @@ -91,6 +111,7 @@ tasks {
// add integration tests to the whole check
named("check") {
dependsOn(intTest)
dependsOn(binaryTest)
}

val coverageResourcesDirectory = "${project.buildDir}/resources/main/CoverageHTMLReporter"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
94 changes: 37 additions & 57 deletions src/main/java/org/utplsql/api/ResourceUtil.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package org.utplsql.api;

import com.sun.nio.zipfs.ZipPath;
import org.utplsql.api.reporter.CoverageHTMLReporter;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.util.ArrayList;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
* Helper class for dealing with Resources
Expand All @@ -25,63 +18,50 @@ private ResourceUtil() {
}

/**
* Returns the Path to a resource so it is walkable no matter if it's inside a jar or on the file system
* Copy directory from a jar file to the destination folder
*
* @param resourceName The name of the resource
* @return Path to the resource, either in JAR or on file system
* @throws IOException
* @throws URISyntaxException
* @param resourceAsPath The resource to get children from
* @param targetDirectory If set to true it will only return files, not directories
*/
public static Path getPathToResource(String resourceName) throws IOException, URISyntaxException {
URI uri = CoverageHTMLReporter.class.getResource(resourceName).toURI();
Path myPath;
if (uri.getScheme().equalsIgnoreCase("jar")) {
FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
myPath = fileSystem.getPath(resourceName);
} else {
myPath = Paths.get(uri);
public static void copyResources(Path resourceAsPath, Path targetDirectory) {
String resourceName = "/" + resourceAsPath.toString();
try {
Files.createDirectories(targetDirectory);
URI uri = ResourceUtil.class.getResource(resourceName).toURI();
Path myPath;
if (uri.getScheme().equalsIgnoreCase("jar")) {
try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
myPath = fileSystem.getPath(resourceName);
copyRecursive(myPath, targetDirectory);
}
} else {
myPath = Paths.get(uri);
copyRecursive(myPath, targetDirectory);
}
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}

return myPath;
}

/**
* Returns the relative paths of all children of the given resource. Relative path begins from the first atom of the given path.
*
* @param resourceAsPath The resource to get children from
* @param filesOnly If set to true it will only return files, not directories
* @return List of relative Paths to the children
* @throws IOException
* @throws URISyntaxException
*/
public static List<Path> getListOfChildren(Path resourceAsPath, boolean filesOnly) throws IOException, URISyntaxException {

Path resourcePath = getPathToResource("/" + resourceAsPath.toString());
int relativeStartIndex = resourcePath.getNameCount() - resourceAsPath.getNameCount();

final List<Path> result = new ArrayList<>();
private static void copyRecursive(Path from, Path targetDirectory) throws IOException {
Files.walkFileTree(from, new SimpleFileVisitor<Path>() {

if (resourcePath instanceof ZipPath) {
try (ZipFile zf = new ZipFile(resourcePath.getFileSystem().toString())) {
private Path currentTarget;

for (Enumeration list = zf.entries(); list.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) list.nextElement();
// Get entry-path with root element so we can compare it
Path entryPath = resourcePath.getRoot().resolve(resourcePath.getFileSystem().getPath(entry.toString()));

if (entryPath.startsWith(resourcePath) && (!filesOnly || !entry.isDirectory())) {
result.add(entryPath.subpath(relativeStartIndex, entryPath.getNameCount()));
}
}
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
super.preVisitDirectory(dir, attrs);
currentTarget = targetDirectory.resolve(from.relativize(dir).toString());
Files.createDirectories(currentTarget);
return FileVisitResult.CONTINUE;
}
resourcePath.getFileSystem().close();
} else {
Files.walk(resourcePath)
.filter(p -> !filesOnly || p.toFile().isFile())
.forEach(p -> result.add(p.subpath(relativeStartIndex, p.getNameCount())));

}

return result;
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
super.visitFile(file, attrs);
Files.copy(file, targetDirectory.resolve(from.relativize(file).toString()), StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
});
}
}
62 changes: 2 additions & 60 deletions src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

import org.utplsql.api.ResourceUtil;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.function.Consumer;

public class CoverageHTMLReporter extends DefaultReporter {

Expand All @@ -29,46 +22,14 @@ public CoverageHTMLReporter(String selfType, Object[] attributes) {
super(selfType, attributes);
}

/**
* Copies files from Classpath to a target directory.
* Can omit the first x folders of the asset-path when copying to the target directory
*
* @param assetPath Path of the asset in the classpath
* @param targetDirectory Target directory to copy the asset to
* @param filterNumOfFolders Omits the first x folders of the path when copying the asset to the target directory
* @throws IOException
*/
private static void copyFileFromClasspath(Path assetPath, Path targetDirectory, int filterNumOfFolders) throws IOException {

Path assetStartPath = assetPath.subpath(filterNumOfFolders, assetPath.getNameCount());
Path targetAssetPath = targetDirectory.resolve(Paths.get(assetStartPath.toString()));

Files.createDirectories(targetAssetPath.getParent());

try (InputStream is = CoverageHTMLReporter.class.getClassLoader()
.getResourceAsStream(assetPath.toString())
) {
Files.copy(is, targetAssetPath, StandardCopyOption.REPLACE_EXISTING);
}
}

/**
* Write the bundled assets necessary for the HTML Coverage report to a given targetPath
*
* @param targetDirectory Directory where the assets should be stored
* @throws RuntimeException
*/
public static void writeReportAssetsTo(Path targetDirectory) throws RuntimeException {

try {
Files.createDirectories(targetDirectory);

List<Path> paths = ResourceUtil.getListOfChildren(Paths.get("CoverageHTMLReporter"), true);

paths.forEach((ThrowingConsumer<Path>) p -> copyFileFromClasspath(p, targetDirectory, 1));
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
static void writeReportAssetsTo(Path targetDirectory) throws RuntimeException {
ResourceUtil.copyResources(Paths.get("CoverageHTMLReporter"), targetDirectory);
}

@Override
Expand Down Expand Up @@ -116,23 +77,4 @@ public void setAssetsPath(String assetsPath) {
this.assetsPath = assetsPath;
}

/**
* Functional Interface just to throw Exception from Consumer
*
* @param <T>
*/
@FunctionalInterface
public interface ThrowingConsumer<T> extends Consumer<T> {

@Override
default void accept(final T elem) {
try {
acceptThrows(elem);
} catch (final Exception e) {
throw new RuntimeException(e);
}
}

void acceptThrows(T t) throws IOException;
}
}
14 changes: 13 additions & 1 deletion src/main/java/org/utplsql/api/reporter/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.outputBuffer.OutputBuffer;

import javax.xml.bind.DatatypeConverter;
import java.sql.Connection;
import java.sql.SQLException;

Expand Down Expand Up @@ -114,4 +113,17 @@ public Datum toDatum(Connection c) throws SQLException {
public OutputBuffer getOutputBuffer() {
return outputBuffer;
}

private static class DatatypeConverter {
private static final char[] hexCode = "0123456789ABCDEF".toCharArray();

static String printHexBinary(byte[] data) {
StringBuilder r = new StringBuilder(data.length * 2);
for (byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]);
r.append(hexCode[(b & 0xF)]);
}
return r.toString();
}
}
}
1 change: 0 additions & 1 deletion src/test/java/org/utplsql/api/OptionalFeaturesIT.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.utplsql.api;

import org.junit.jupiter.api.Test;
import org.omg.CORBA.DynAnyPackage.Invalid;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.compatibility.OptionalFeatures;
import org.utplsql.api.exception.InvalidVersionException;
Expand Down
Loading