Skip to content

Commit 8625923

Browse files
authored
Merge pull request #125 from kbase/sdkdev
Isolate SDK generated code test deps from SDK test deps proper
2 parents e433385 + f6b22e4 commit 8625923

File tree

2 files changed

+88
-65
lines changed

2 files changed

+88
-65
lines changed

build.gradle

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'application'
33
id 'jacoco'
44
id 'org.ajoberstar.grgit' version '4.1.1'
5-
id 'org.graalvm.buildtools.native' version "0.10.6"
5+
id 'org.graalvm.buildtools.native' version '0.10.6'
66
}
77

88
// TODO BUILD look into GraalVM native compilation vs. dockerizing kb-sdk
@@ -22,11 +22,11 @@ group = 'us.kbase.sdk'
2222
repositories {
2323
mavenCentral()
2424
maven { // for syslog4j
25-
name = "Clojars"
26-
url = "https://repo.clojars.org/"
25+
name = 'Clojars'
26+
url = 'https://repo.clojars.org/'
2727
}
2828
maven {
29-
name = "Jitpack"
29+
name = 'Jitpack'
3030
url = 'https://jitpack.io'
3131
}
3232
}
@@ -66,7 +66,7 @@ task kb_sdk_plusScript {
6666
}
6767

6868
def buildjar = "$buildDir/libs/${project.name}.jar"
69-
def classpath = buildjar + ":" + dependencies.join(':')
69+
def classpath = buildjar + ':' + dependencies.join(':')
7070

7171
def scriptContent = """#!/bin/sh
7272
@@ -86,7 +86,7 @@ task prepareRunnableDir {
8686
// Note requires bash vs just sh
8787
dependsOn jar
8888
def runnableDir = file("$buildDir/runnable")
89-
def runnerScript = new File(runnableDir, "kb-sdk")
89+
def runnerScript = new File(runnableDir, 'kb-sdk')
9090

9191
doFirst {
9292
// Clean and recreate runnable dir
@@ -135,11 +135,24 @@ task pythonTest(type: Exec) {
135135
}
136136
}
137137

138+
// this is used in TypeGeneratorTest to supply dependencies for compiler tests
139+
def genCodeLibDir = file("$buildDir/generated-code-libs")
140+
141+
task resolveGeneratedCodeDeps {
142+
outputs.dir genCodeLibDir
143+
doLast {
144+
copy {
145+
from configurations.generatedCodeClasspath
146+
into genCodeLibDir
147+
}
148+
}
149+
}
150+
138151
test {
152+
dependsOn resolveGeneratedCodeDeps
139153
dependsOn kb_sdk_plusScript // tests use script to compile sdk modules
140154
dependsOn pythonTest
141155

142-
maxHeapSize = "3G"
143156
testLogging {
144157
exceptionFormat = 'full'
145158
showStandardStreams = true
@@ -158,10 +171,10 @@ jacocoTestReport {
158171
classDirectories.setFrom(
159172
files(classDirectories.files.collect {
160173
fileTree(dir: it, exclude: [
161-
"**/common/executionengine/**",
162-
"**/common/service/**",
163-
"**/catalog/**",
164-
"**/narrativemethodstore/**",
174+
'**/common/executionengine/**',
175+
'**/common/service/**',
176+
'**/catalog/**',
177+
'**/narrativemethodstore/**',
165178
])
166179
})
167180
)
@@ -171,10 +184,12 @@ jacocoTestReport {
171184
// TODO BUILD the other script tasks could possibly be made simpler with some of the
172185
// variables in this task
173186
tasks.register('generateNativeAgentScript') {
174-
description = "Generates a script to run the application with GraalVM native-image-agent. " +
175-
"Will init and test an SDK app called 'testapp', so run this in a location where " +
176-
"creating that directory is safe."
177-
group = "native-image"
187+
description = """
188+
Generates a script to run the application with the GraalVM native-image-agent.
189+
Will init and test an SDK app called 'testapp', so run this in a location where
190+
creating that directory is safe.
191+
"""
192+
group = 'native-image'
178193

179194
dependsOn jar
180195

@@ -257,13 +272,13 @@ echo "Edit manually if necessary."
257272

258273
graalvmNative {
259274
binaries {
260-
named("main") {
261-
imageName.set("kb-sdk")
275+
named('main') {
276+
imageName.set('kb-sdk')
262277
// Don't fall back to a jar based build
263278
buildArgs.addAll([
264-
"--no-fallback",
265-
"--enable-url-protocols=https,http",
266-
"-H:+AddAllCharsets"
279+
'--no-fallback',
280+
'--enable-url-protocols=https,http',
281+
'-H:+AddAllCharsets'
267282
])
268283
}
269284
}
@@ -272,6 +287,8 @@ graalvmNative {
272287
configurations {
273288
// can't directly access testImplementation, so extend and access
274289
testimpl.extendsFrom testImplementation
290+
// isolate the sdk generated code dependencies from the standard dependencies
291+
generatedCodeClasspath
275292
}
276293

277294
configurations.all {
@@ -288,10 +305,10 @@ dependencies {
288305
annotationProcessor 'info.picocli:picocli-codegen:4.7.7'
289306
compileOnly 'javax.servlet:servlet-api:2.5'
290307

291-
implementation("com.github.kbase:auth2_client_java:0.5.0") {
308+
implementation('com.github.kbase:auth2_client_java:0.5.0') {
292309
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
293310
}
294-
implementation("com.github.kbase:java_common:0.3.1") {
311+
implementation('com.github.kbase:java_common:0.3.1') {
295312
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
296313
exclude group: 'net.java.dev.jna' // don't include in runtime path
297314
}
@@ -302,8 +319,8 @@ dependencies {
302319
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
303320
exclude group: 'net.java.dev.jna' // don't include in runtime path
304321
}
305-
implementation "com.fasterxml.jackson.core:jackson-annotations:2.2.3"
306-
implementation "com.fasterxml.jackson.core:jackson-databind:2.2.3"
322+
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.2.3'
323+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
307324
implementation 'com.google.guava:guava:18.0'
308325
implementation 'com.googlecode.jsonschema2pojo:jsonschema2pojo-core:0.3.6'
309326
implementation('com.j2html:j2html:0.7') {
@@ -334,7 +351,7 @@ dependencies {
334351
// abandonware and has a ton of CVEs, even in the newer versions.
335352
// Note that the java SDK modules use syslog4j, so we'll need to figure something out
336353
// there. I doubt any of the apps actually use the logging code that triggers it though
337-
implementation "org.syslog4j:syslog4j:0.9.46"
354+
implementation 'org.syslog4j:syslog4j:0.9.46'
338355

339356
// needed for syslog4j. Used in java test modules and JsonServerServlet subclasses in tests
340357
// but not in SDK code proper.
@@ -345,6 +362,29 @@ dependencies {
345362
}
346363
testImplementation 'junit:junit:4.12'
347364
testImplementation 'org.hamcrest:hamcrest-core:1.3'
365+
366+
// isolate the sdk generated code dependencies from the standard dependencies
367+
368+
generatedCodeClasspath 'ch.qos.logback:logback-classic:1.1.2'
369+
generatedCodeClasspath 'com.fasterxml.jackson.core:jackson-annotations:2.2.3'
370+
generatedCodeClasspath 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
371+
generatedCodeClasspath('com.github.kbase:auth2_client_java:0.5.0') {
372+
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
373+
}
374+
generatedCodeClasspath('com.github.kbase:java_common:0.3.1') {
375+
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
376+
exclude group: 'net.java.dev.jna' // don't include in test path
377+
}
378+
generatedCodeClasspath 'javax.annotation:javax.annotation-api:1.3.2'
379+
generatedCodeClasspath 'javax.servlet:servlet-api:2.5'
380+
generatedCodeClasspath 'joda-time:joda-time:2.2'
381+
generatedCodeClasspath 'junit:junit:4.12'
382+
generatedCodeClasspath 'net.java.dev.jna:jna:3.4.0'
383+
generatedCodeClasspath 'org.eclipse.jetty.aggregate:jetty-all:7.0.0.v20091005'
384+
generatedCodeClasspath 'org.hamcrest:hamcrest-core:1.3'
385+
generatedCodeClasspath 'org.ini4j:ini4j:0.5.2'
386+
generatedCodeClasspath 'org.syslog4j:syslog4j:0.9.46'
387+
generatedCodeClasspath 'org.slf4j:slf4j-api:1.7.7'
348388
}
349389

350390
task showTestClassPath {

src/test/java/us/kbase/test/sdk/scripts/TypeGeneratorTest.java

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import us.kbase.common.service.UObject;
5050
import us.kbase.kidl.KbFuncdef;
5151
import us.kbase.kidl.KbService;
52-
import us.kbase.kidl.KidlParseException;
5352
import us.kbase.kidl.KidlParser;
5453
import us.kbase.sdk.compiler.JavaData;
5554
import us.kbase.sdk.compiler.JavaFunc;
@@ -79,6 +78,10 @@ public class TypeGeneratorTest extends Assert {
7978

8079
private static final String rootPackageName = "us.kbase";
8180
private static final String SERVICE_WIZARD = "ServiceWizard";
81+
82+
// specified in the build.gradle file
83+
private static final Path BUILD_LIB_DIR = Paths.get("build/generated-code-libs")
84+
.toAbsolutePath();
8285

8386
private static boolean debugClientTimes = false;
8487

@@ -224,7 +227,7 @@ public void testServerCodeStoring() throws Exception {
224227
serverJavaFile.createNewFile();
225228
File libDir = new File(workDir, "lib");
226229
// Test for empty server file
227-
setUpTestJars(new DiskFileSaver(libDir), true);
230+
setUpTestJars(new DiskFileSaver(libDir));
228231
try {
229232
JavaTypeGenerator.processSpec(new File(workDir, testFileName),
230233
srcDir, testPackage, true, null);
@@ -861,7 +864,7 @@ protected static JavaData prepareJavaCode(
861864
return parsingData;
862865
}
863866

864-
public static JavaData processSpec(
867+
private static JavaData processSpec(
865868
final File workDir,
866869
final String testPackage,
867870
final File libDir,
@@ -871,7 +874,7 @@ public static JavaData processSpec(
871874
final boolean isDynamic,
872875
final boolean isAsync
873876
) throws Exception {
874-
setUpTestJars(new DiskFileSaver(libDir), true);
877+
setUpTestJars(new DiskFileSaver(libDir));
875878
File specFile = new File(workDir, testFileName);
876879
List<KbService> services = KidlParser.parseSpec(specFile, null);
877880
JavaData parsingData = JavaTypeGenerator.processSpec(services, new DiskFileSaver(srcDir),
@@ -880,52 +883,32 @@ public static JavaData processSpec(
880883
return parsingData;
881884
}
882885

883-
private static void setUpTestJars(
884-
final FileSaver libOutDir,
885-
final boolean createServers
886-
) throws Exception {
886+
private static void setUpTestJars(final FileSaver libOutDir) throws Exception {
887887
// TODO TEST CLEANUP remove this method and figure out some other way of handling test deps
888888
// maybe mark deps in gradle?
889889
checkLib(libOutDir, "jackson-annotations-2.2.3");
890890
checkLib(libOutDir, "jackson-core-2.2.3");
891891
checkLib(libOutDir, "jackson-databind-2.2.3");
892-
checkLib(libOutDir, "auth2_client_java-0.5.0.jar");
893-
checkLib(libOutDir, "java_common-0.3.1.jar");
892+
checkLib(libOutDir, "auth2_client_java-0.5.0");
893+
checkLib(libOutDir, "java_common-0.3.1");
894894
checkLib(libOutDir, "javax.annotation-api-1.3.2");
895-
if (createServers) {
896-
checkLib(libOutDir, "servlet-api-2.5");
897-
checkLib(libOutDir, "jetty-all-7.0.0");
898-
checkLib(libOutDir, "ini4j-0.5.2");
899-
checkLib(libOutDir, "syslog4j-0.9.46");
900-
checkLib(libOutDir, "jna-3.4.0");
901-
checkLib(libOutDir, "joda-time-2.2");
902-
checkLib(libOutDir, "logback-core-1.1.2");
903-
checkLib(libOutDir, "logback-classic-1.1.2");
904-
checkLib(libOutDir, "slf4j-api-1.7.7");
905-
}
895+
checkLib(libOutDir, "servlet-api-2.5");
896+
checkLib(libOutDir, "jetty-all-7.0.0.v20091005");
897+
checkLib(libOutDir, "ini4j-0.5.2");
898+
checkLib(libOutDir, "syslog4j-0.9.46");
899+
checkLib(libOutDir, "jna-3.4.0");
900+
checkLib(libOutDir, "joda-time-2.2");
901+
checkLib(libOutDir, "logback-core-1.1.2");
902+
checkLib(libOutDir, "logback-classic-1.1.2");
903+
checkLib(libOutDir, "slf4j-api-1.7.7");
906904
}
907905

908-
private static String checkLib(FileSaver libDir, String libName) throws Exception {
906+
private static void checkLib(FileSaver libDir, String libName) throws Exception {
909907
// TODO TEST CLEANUP try to eliminate this method entirely
910-
File libFile = null;
911-
final String classpath = System.getProperty("java.class.path");
912-
final String sep = System.getProperty("path.separator");
913-
for (final String cp: classpath.split(sep)) {
914-
final File maybelibFile = new File(cp);
915-
if (maybelibFile.isFile()
916-
&& maybelibFile.getName().startsWith(libName)
917-
&& maybelibFile.getName().endsWith(".jar"))
918-
{
919-
libFile = maybelibFile;
920-
}
921-
}
922-
if (libFile == null) {
923-
throw new KidlParseException("Can't find lib-file for: " + libName);
924-
}
925-
InputStream is = new FileInputStream(libFile);
926-
OutputStream os = libDir.openStream(libFile.getName());
908+
final Path lib = BUILD_LIB_DIR.resolve(libName + ".jar");
909+
InputStream is = new FileInputStream(lib.toFile());
910+
OutputStream os = libDir.openStream(lib.getFileName().toString());
927911
TextUtils.copyStreams(is, os);
928-
return libFile.getCanonicalPath();
929912
}
930913

931914
private static File findPythonServerScript(File dir) {

0 commit comments

Comments
 (0)