Skip to content

Commit a9c09e5

Browse files
authored
Merge pull request #83 from utPLSQL/fix-java9-plus
Fix compitability with all java from 8 to 12
2 parents 7f22e43 + f0e7142 commit a9c09e5

File tree

8 files changed

+121
-174
lines changed

8 files changed

+121
-174
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
sudo: required
21
language: java
32

43
services:
@@ -32,6 +31,17 @@ env:
3231
- UTPLSQL_VERSION="develop"
3332
UTPLSQL_FILE="utPLSQL"
3433

34+
matrix:
35+
include:
36+
- env: UTPLSQL_VERSION="v3.1.6"
37+
jdk: openjdk9
38+
- env: UTPLSQL_VERSION="v3.1.6"
39+
jdk: openjdk10
40+
- env: UTPLSQL_VERSION="v3.1.6"
41+
jdk: openjdk11
42+
- env: UTPLSQL_VERSION="v3.1.6"
43+
jdk: openjdk12
44+
3545
before_cache:
3646
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
3747
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

build.gradle.kts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ version = if (tag != null && "^[0-9.]+$".toRegex().matches(tag)) tag else baseVe
1111

1212
val coverageResourcesVersion = "1.0.1"
1313
val ojdbcVersion = "12.2.0.1"
14-
val junitVersion = "5.4.1"
14+
val junitVersion = "5.4.2"
1515

1616
val deployerJars by configurations.creating
1717

@@ -70,6 +70,26 @@ tasks {
7070
}
7171
}
7272

73+
// run tests using compiled jar + dependencies and tests classes
74+
val binaryTest = create<Test>("binaryTest") {
75+
dependsOn(jar, testClasses)
76+
77+
doFirst {
78+
classpath = project.files("$buildDir/libs/java-api-$baseVersion.jar", "$buildDir/classes/java/test", configurations.testRuntimeClasspath)
79+
testClassesDirs = sourceSets.getByName("test").output.classesDirs
80+
}
81+
82+
useJUnitPlatform {
83+
includeTags("binary")
84+
}
85+
testLogging {
86+
events("passed", "skipped", "failed")
87+
exceptionFormat = TestExceptionFormat.FULL
88+
showStackTraces = true
89+
showStandardStreams = true
90+
}
91+
}
92+
7393
val intTest = create<Test>("intTest") {
7494
dependsOn(test)
7595
doFirst {
@@ -91,6 +111,7 @@ tasks {
91111
// add integration tests to the whole check
92112
named("check") {
93113
dependsOn(intTest)
114+
dependsOn(binaryTest)
94115
}
95116

96117
val coverageResourcesDirectory = "${project.buildDir}/resources/main/CoverageHTMLReporter"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
package org.utplsql.api;
22

3-
import com.sun.nio.zipfs.ZipPath;
4-
import org.utplsql.api.reporter.CoverageHTMLReporter;
5-
63
import java.io.IOException;
74
import java.net.URI;
85
import java.net.URISyntaxException;
96
import java.nio.file.*;
10-
import java.util.ArrayList;
7+
import java.nio.file.attribute.BasicFileAttributes;
118
import java.util.Collections;
12-
import java.util.Enumeration;
13-
import java.util.List;
14-
import java.util.zip.ZipEntry;
15-
import java.util.zip.ZipFile;
169

1710
/**
1811
* Helper class for dealing with Resources
@@ -25,63 +18,50 @@ private ResourceUtil() {
2518
}
2619

2720
/**
28-
* Returns the Path to a resource so it is walkable no matter if it's inside a jar or on the file system
21+
* Copy directory from a jar file to the destination folder
2922
*
30-
* @param resourceName The name of the resource
31-
* @return Path to the resource, either in JAR or on file system
32-
* @throws IOException
33-
* @throws URISyntaxException
23+
* @param resourceAsPath The resource to get children from
24+
* @param targetDirectory If set to true it will only return files, not directories
3425
*/
35-
public static Path getPathToResource(String resourceName) throws IOException, URISyntaxException {
36-
URI uri = CoverageHTMLReporter.class.getResource(resourceName).toURI();
37-
Path myPath;
38-
if (uri.getScheme().equalsIgnoreCase("jar")) {
39-
FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
40-
myPath = fileSystem.getPath(resourceName);
41-
} else {
42-
myPath = Paths.get(uri);
26+
public static void copyResources(Path resourceAsPath, Path targetDirectory) {
27+
String resourceName = "/" + resourceAsPath.toString();
28+
try {
29+
Files.createDirectories(targetDirectory);
30+
URI uri = ResourceUtil.class.getResource(resourceName).toURI();
31+
Path myPath;
32+
if (uri.getScheme().equalsIgnoreCase("jar")) {
33+
try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
34+
myPath = fileSystem.getPath(resourceName);
35+
copyRecursive(myPath, targetDirectory);
36+
}
37+
} else {
38+
myPath = Paths.get(uri);
39+
copyRecursive(myPath, targetDirectory);
40+
}
41+
} catch (IOException | URISyntaxException e) {
42+
throw new RuntimeException(e);
4343
}
44-
45-
return myPath;
4644
}
4745

48-
/**
49-
* Returns the relative paths of all children of the given resource. Relative path begins from the first atom of the given path.
50-
*
51-
* @param resourceAsPath The resource to get children from
52-
* @param filesOnly If set to true it will only return files, not directories
53-
* @return List of relative Paths to the children
54-
* @throws IOException
55-
* @throws URISyntaxException
56-
*/
57-
public static List<Path> getListOfChildren(Path resourceAsPath, boolean filesOnly) throws IOException, URISyntaxException {
58-
59-
Path resourcePath = getPathToResource("/" + resourceAsPath.toString());
60-
int relativeStartIndex = resourcePath.getNameCount() - resourceAsPath.getNameCount();
61-
62-
final List<Path> result = new ArrayList<>();
46+
private static void copyRecursive(Path from, Path targetDirectory) throws IOException {
47+
Files.walkFileTree(from, new SimpleFileVisitor<Path>() {
6348

64-
if (resourcePath instanceof ZipPath) {
65-
try (ZipFile zf = new ZipFile(resourcePath.getFileSystem().toString())) {
49+
private Path currentTarget;
6650

67-
for (Enumeration list = zf.entries(); list.hasMoreElements(); ) {
68-
ZipEntry entry = (ZipEntry) list.nextElement();
69-
// Get entry-path with root element so we can compare it
70-
Path entryPath = resourcePath.getRoot().resolve(resourcePath.getFileSystem().getPath(entry.toString()));
71-
72-
if (entryPath.startsWith(resourcePath) && (!filesOnly || !entry.isDirectory())) {
73-
result.add(entryPath.subpath(relativeStartIndex, entryPath.getNameCount()));
74-
}
75-
}
51+
@Override
52+
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
53+
super.preVisitDirectory(dir, attrs);
54+
currentTarget = targetDirectory.resolve(from.relativize(dir).toString());
55+
Files.createDirectories(currentTarget);
56+
return FileVisitResult.CONTINUE;
7657
}
77-
resourcePath.getFileSystem().close();
78-
} else {
79-
Files.walk(resourcePath)
80-
.filter(p -> !filesOnly || p.toFile().isFile())
81-
.forEach(p -> result.add(p.subpath(relativeStartIndex, p.getNameCount())));
8258

83-
}
84-
85-
return result;
59+
@Override
60+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
61+
super.visitFile(file, attrs);
62+
Files.copy(file, targetDirectory.resolve(from.relativize(file).toString()), StandardCopyOption.REPLACE_EXISTING);
63+
return FileVisitResult.CONTINUE;
64+
}
65+
});
8666
}
8767
}

src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22

33
import org.utplsql.api.ResourceUtil;
44

5-
import java.io.IOException;
6-
import java.io.InputStream;
7-
import java.net.URISyntaxException;
8-
import java.nio.file.Files;
95
import java.nio.file.Path;
106
import java.nio.file.Paths;
11-
import java.nio.file.StandardCopyOption;
12-
import java.util.List;
13-
import java.util.function.Consumer;
147

158
public class CoverageHTMLReporter extends DefaultReporter {
169

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

32-
/**
33-
* Copies files from Classpath to a target directory.
34-
* Can omit the first x folders of the asset-path when copying to the target directory
35-
*
36-
* @param assetPath Path of the asset in the classpath
37-
* @param targetDirectory Target directory to copy the asset to
38-
* @param filterNumOfFolders Omits the first x folders of the path when copying the asset to the target directory
39-
* @throws IOException
40-
*/
41-
private static void copyFileFromClasspath(Path assetPath, Path targetDirectory, int filterNumOfFolders) throws IOException {
42-
43-
Path assetStartPath = assetPath.subpath(filterNumOfFolders, assetPath.getNameCount());
44-
Path targetAssetPath = targetDirectory.resolve(Paths.get(assetStartPath.toString()));
45-
46-
Files.createDirectories(targetAssetPath.getParent());
47-
48-
try (InputStream is = CoverageHTMLReporter.class.getClassLoader()
49-
.getResourceAsStream(assetPath.toString())
50-
) {
51-
Files.copy(is, targetAssetPath, StandardCopyOption.REPLACE_EXISTING);
52-
}
53-
}
54-
5525
/**
5626
* Write the bundled assets necessary for the HTML Coverage report to a given targetPath
5727
*
5828
* @param targetDirectory Directory where the assets should be stored
5929
* @throws RuntimeException
6030
*/
61-
public static void writeReportAssetsTo(Path targetDirectory) throws RuntimeException {
62-
63-
try {
64-
Files.createDirectories(targetDirectory);
65-
66-
List<Path> paths = ResourceUtil.getListOfChildren(Paths.get("CoverageHTMLReporter"), true);
67-
68-
paths.forEach((ThrowingConsumer<Path>) p -> copyFileFromClasspath(p, targetDirectory, 1));
69-
} catch (IOException | URISyntaxException e) {
70-
throw new RuntimeException(e);
71-
}
31+
static void writeReportAssetsTo(Path targetDirectory) throws RuntimeException {
32+
ResourceUtil.copyResources(Paths.get("CoverageHTMLReporter"), targetDirectory);
7233
}
7334

7435
@Override
@@ -116,23 +77,4 @@ public void setAssetsPath(String assetsPath) {
11677
this.assetsPath = assetsPath;
11778
}
11879

119-
/**
120-
* Functional Interface just to throw Exception from Consumer
121-
*
122-
* @param <T>
123-
*/
124-
@FunctionalInterface
125-
public interface ThrowingConsumer<T> extends Consumer<T> {
126-
127-
@Override
128-
default void accept(final T elem) {
129-
try {
130-
acceptThrows(elem);
131-
} catch (final Exception e) {
132-
throw new RuntimeException(e);
133-
}
134-
}
135-
136-
void acceptThrows(T t) throws IOException;
137-
}
13880
}

src/main/java/org/utplsql/api/reporter/Reporter.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.utplsql.api.compatibility.CompatibilityProxy;
1111
import org.utplsql.api.outputBuffer.OutputBuffer;
1212

13-
import javax.xml.bind.DatatypeConverter;
1413
import java.sql.Connection;
1514
import java.sql.SQLException;
1615

@@ -114,4 +113,17 @@ public Datum toDatum(Connection c) throws SQLException {
114113
public OutputBuffer getOutputBuffer() {
115114
return outputBuffer;
116115
}
116+
117+
private static class DatatypeConverter {
118+
private static final char[] hexCode = "0123456789ABCDEF".toCharArray();
119+
120+
static String printHexBinary(byte[] data) {
121+
StringBuilder r = new StringBuilder(data.length * 2);
122+
for (byte b : data) {
123+
r.append(hexCode[(b >> 4) & 0xF]);
124+
r.append(hexCode[(b & 0xF)]);
125+
}
126+
return r.toString();
127+
}
128+
}
117129
}

src/test/java/org/utplsql/api/OptionalFeaturesIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.utplsql.api;
22

33
import org.junit.jupiter.api.Test;
4-
import org.omg.CORBA.DynAnyPackage.Invalid;
54
import org.utplsql.api.compatibility.CompatibilityProxy;
65
import org.utplsql.api.compatibility.OptionalFeatures;
76
import org.utplsql.api.exception.InvalidVersionException;

0 commit comments

Comments
 (0)