Skip to content
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
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,22 @@ java -cp \$CLASSPATH us.kbase.sdk.ModuleBuilder \$@

// this is used in TypeGeneratorTest to supply dependencies for compiler tests
def genCodeLibDir = file("$buildDir/generated-code-libs")
def genCodeImplDir = new File(genCodeLibDir, "impl")
def genCodeTestDir = new File(genCodeLibDir, "test")

task resolveGeneratedCodeDeps {
inputs.files { configurations.generatedCodeClasspath }
inputs.files { configurations.generatedTestCodeClasspath }
outputs.dir genCodeLibDir
doLast {
delete genCodeLibDir
copy {
from configurations.generatedCodeClasspath
into genCodeLibDir
into genCodeImplDir
}
copy {
from configurations.generatedTestCodeClasspath
into genCodeTestDir
}
}
}
Expand Down Expand Up @@ -276,6 +283,7 @@ configurations {
testimpl.extendsFrom testImplementation
// isolate the sdk generated code dependencies from the standard dependencies
generatedCodeClasspath
generatedTestCodeClasspath
}

configurations.all {
Expand Down Expand Up @@ -369,9 +377,10 @@ dependencies {
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
}
generatedCodeClasspath('javax.annotation:javax.annotation-api:1.3.2')
generatedCodeClasspath('junit:junit:4.12')
generatedCodeClasspath('org.ini4j:ini4j:0.5.2')
generatedCodeClasspath('org.syslog4j:syslog4j:0.9.46')

generatedTestCodeClasspath('junit:junit:4.12')
}

task showTestClassPath {
Expand Down
58 changes: 23 additions & 35 deletions src/test/java/us/kbase/test/sdk/scripts/TypeGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -27,6 +26,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

Expand Down Expand Up @@ -82,7 +82,9 @@ public class TypeGeneratorTest {
private static final String SERVICE_WIZARD = "ServiceWizard";

// specified in the build.gradle file
private static final Path BUILD_LIB_DIR = Paths.get("build/generated-code-libs")
private static final Path BUILD_LIB_IMPL_DIR = Paths.get("build/generated-code-libs/impl")
.toAbsolutePath();
private static final Path BUILD_LIB_TEST_DIR = Paths.get("build/generated-code-libs/test")
.toAbsolutePath();

private static boolean debugClientTimes = false;
Expand Down Expand Up @@ -176,7 +178,7 @@ public void testSyslog() throws Exception {
File binDir = new File(workDir, "bin");
JavaData parsingData = prepareJavaCode(testNum, workDir, testPackage, libDir, binDir, null, true);
javaServerCorrectionForTestCallback(srcDir, testPackage, parsingData, testPackage + ".Test" + testNum);
String classPath = prepareClassPath(libDir, new ArrayList<URL>());
String classPath = buildClassPath(libDir, new ArrayList<URL>());
runJavac(workDir, srcDir, classPath, binDir, "src/us/kbase/test5/syslogtest/SyslogTestServer.java");
int portNum = findFreePort();
runJavaServerTest(testNum, true, workDir, testPackage, libDir, binDir, parsingData, null, portNum);
Expand Down Expand Up @@ -224,7 +226,7 @@ public void testServerCodeStoring() throws Exception {
serverJavaFile.createNewFile();
File libDir = new File(workDir, "lib");
// Test for empty server file
setUpTestJars(new DiskFileSaver(libDir));
setUpJars(new DiskFileSaver(libDir));
try {
JavaTypeGenerator.processSpec(new File(workDir, testFileName),
srcDir, testPackage, true, null);
Expand All @@ -245,7 +247,7 @@ public void testServerCodeStoring() throws Exception {
new File(workDir, testFileName), srcDir, testPackage, true, null
);
List<URL> cpUrls = new ArrayList<URL>();
String classPath = prepareClassPath(libDir, cpUrls);
String classPath = buildClassPath(libDir, cpUrls);
File binDir = new File(workDir, "bin");
cpUrls.add(binDir.toURI().toURL());
compileModulesIntoBin(workDir, srcDir, testPackage, parsingData, classPath, binDir);
Expand Down Expand Up @@ -827,7 +829,7 @@ protected static JavaData prepareJavaCode(
parsingData = processSpec(workDir, testPackage, libDir, testFileName,
srcDir, defaultUrl, isDynamic, isAsync);
List<URL> cpUrls = new ArrayList<URL>();
String classPath = prepareClassPath(libDir, cpUrls);
String classPath = buildClassPath(libDir, cpUrls);
cpUrls.add(binDir.toURI().toURL());
compileModulesIntoBin(workDir, srcDir, testPackage, parsingData, classPath, binDir);
String testJavaFileName = "Test" + testNum + ".java";
Expand Down Expand Up @@ -860,7 +862,7 @@ private static JavaData processSpec(
final boolean isDynamic,
final boolean isAsync
) throws Exception {
setUpTestJars(new DiskFileSaver(libDir));
setUpJars(new DiskFileSaver(libDir));
File specFile = new File(workDir, testFileName);
List<KbService> services = KidlParser.parseSpec(specFile, null);
JavaData parsingData = JavaTypeGenerator.processSpec(services, new DiskFileSaver(srcDir),
Expand All @@ -869,32 +871,20 @@ private static JavaData processSpec(
return parsingData;
}

private static void setUpTestJars(final FileSaver libOutDir) throws Exception {
// TODO TEST CLEANUP remove this method and figure out some other way of handling test deps
// maybe mark deps in gradle?
checkLib(libOutDir, "jackson-annotations-2.2.3");
checkLib(libOutDir, "jackson-core-2.2.3");
checkLib(libOutDir, "jackson-databind-2.2.3");
checkLib(libOutDir, "auth2_client_java-0.5.0");
checkLib(libOutDir, "java_common-0.3.1");
checkLib(libOutDir, "javax.annotation-api-1.3.2");
checkLib(libOutDir, "servlet-api-2.5");
checkLib(libOutDir, "jetty-all-7.0.0.v20091005");
checkLib(libOutDir, "ini4j-0.5.2");
checkLib(libOutDir, "syslog4j-0.9.46");
checkLib(libOutDir, "jna-3.4.0");
checkLib(libOutDir, "joda-time-2.2");
checkLib(libOutDir, "logback-core-1.1.2");
checkLib(libOutDir, "logback-classic-1.1.2");
checkLib(libOutDir, "slf4j-api-1.7.7");
private static void setUpJars(final FileSaver libOutDir) throws Exception {
copyJarsFromDir(BUILD_LIB_IMPL_DIR, libOutDir);
copyJarsFromDir(BUILD_LIB_TEST_DIR, libOutDir);
}

private static void checkLib(FileSaver libDir, String libName) throws Exception {
// TODO TEST CLEANUP try to eliminate this method entirely
final Path lib = BUILD_LIB_DIR.resolve(libName + ".jar");
InputStream is = new FileInputStream(lib.toFile());
OutputStream os = libDir.openStream(lib.getFileName().toString());
TextUtils.copyStreams(is, os);
private static void copyJarsFromDir(final Path srcDir, final FileSaver dest) throws Exception {
try (final Stream<Path> jars = Files.list(srcDir)) {
for (final Path jar: jars.filter(p -> p.getFileName().toString().endsWith(".jar"))
.toList()) {
final InputStream is = Files.newInputStream(jar);
final OutputStream os = dest.openStream(jar.getFileName().toString());
TextUtils.copyStreams(is, os);
}
}
}

private static File findPythonServerScript(File dir) {
Expand All @@ -918,10 +908,8 @@ private static void compileModulesIntoBin(File workDir, File srcDir, String test
}
}

private static String prepareClassPath(File libDir, List<URL> cpUrls)
private static String buildClassPath(File libDir, List<URL> cpUrls)
throws Exception {
checkLib(new DiskFileSaver(libDir), "junit-4.12");
checkLib(new DiskFileSaver(libDir), "hamcrest-core-1.3");
StringBuilder classPathSB = new StringBuilder();
for (File jarFile : libDir.listFiles()) {
if (!jarFile.getName().endsWith(".jar"))
Expand All @@ -943,7 +931,7 @@ private static Class<?> createServerServletInstance(JavaModule module,
private static URLClassLoader prepareUrlClassLoader(File libDir, File binDir)
throws Exception, MalformedURLException {
List<URL> cpUrls = new ArrayList<URL>();
prepareClassPath(libDir, cpUrls);
buildClassPath(libDir, cpUrls);
cpUrls.add(binDir.toURI().toURL());
URLClassLoader urlcl = URLClassLoader.newInstance(cpUrls.toArray(new URL[cpUrls.size()]));
return urlcl;
Expand Down
Loading