Skip to content

Commit

Permalink
gate java tests on whether gradle is available
Browse files Browse the repository at this point in the history
  • Loading branch information
olynch committed Apr 8, 2024
1 parent 79e5a86 commit a540be1
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions test/intertypes/InterTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,43 +173,52 @@ end

# Java Integration Tests

java_dir = joinpath(@__DIR__, "java/lib/src/main/java")
generate_module(simpleast, JacksonTarget, java_dir)
generate_module(model, JacksonTarget, java_dir)
generate_module(wgraph, JacksonTarget, java_dir)
hasgradle = try
run(`which gradle`)
true
catch error
false
end

cd(joinpath(@__DIR__, "acsets4j"))
run(`gradle build`)
cd("..")
if hasgradle
java_dir = joinpath(@__DIR__, "java/lib/src/main/java")
generate_module(simpleast, JacksonTarget, java_dir)
generate_module(model, JacksonTarget, java_dir)
generate_module(wgraph, JacksonTarget, java_dir)

mkpath("java/libs")
cd(joinpath(@__DIR__, "acsets4j"))
run(`gradle build`)
cd("..")

jar_source = "acsets4j/lib/build/libs/acsets4j-0.1.jar"
jar_dest = "java/lib/deps/acsets4j-0.1.jar"
if isfile(jar_dest)
rm(jar_dest)
end
mkpath("java/lib/deps")
cp(jar_source, jar_dest)
mkpath("java/libs")

cd(joinpath(@__DIR__, "java"))
run(`gradle build`)
cd("..")
jar_source = "acsets4j/lib/build/libs/acsets4j-0.1.jar"
jar_dest = "java/lib/deps/acsets4j-0.1.jar"
if isfile(jar_dest)
rm(jar_dest)
end
mkpath("java/lib/deps")
cp(jar_source, jar_dest)

push!(JavaCall.cp, joinpath(@__DIR__, "java/lib/build/libs/lib.jar"))
cd(joinpath(@__DIR__, "java"))
run(`gradle build`)
cd("..")

JavaCall.init()
push!(JavaCall.cp, joinpath(@__DIR__, "java/lib/build/libs/lib.jar"))

ObjectMapper = @jimport com.fasterxml.jackson.databind.ObjectMapper
om = ObjectMapper(())
JavaCall.init()

function java_roundtrip(javatype, val)
java_val = jcall(om, "readValue", JObject, (JString, JClass), JSON3.write(val), classforname(javatype))
java_val_str = jcall(om, "writeValueAsString", JString, (JObject,), java_val)
JSON3.read(java_val_str, typeof(val)) == val
end
ObjectMapper = @jimport com.fasterxml.jackson.databind.ObjectMapper
om = ObjectMapper(())

@test java_roundtrip("simpleast.Term", t)
@test java_roundtrip("wgraph.EDWeightedGraph", g)
function java_roundtrip(javatype, val)
java_val = jcall(om, "readValue", JObject, (JString, JClass), JSON3.write(val), classforname(javatype))
java_val_str = jcall(om, "writeValueAsString", JString, (JObject,), java_val)
JSON3.read(java_val_str, typeof(val)) == val
end

@test java_roundtrip("simpleast.Term", t)
@test java_roundtrip("wgraph.EDWeightedGraph", g)
end

end

0 comments on commit a540be1

Please sign in to comment.