Skip to content

Commit

Permalink
Don't close URLClassLoader (#233)
Browse files Browse the repository at this point in the history
Closing the URLClassLoader seems to create an issue due to concurrency
nature of sbt. When another ClassLoader accesses a resource, the stream
is closed unexpectedly.

Change schema logging to better represent concurrent execution.
  • Loading branch information
RustedBones authored Jan 15, 2025
1 parent 2407602 commit 132cd44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
11 changes: 3 additions & 8 deletions bridge/src/main/java/com/github/sbt/avro/AvroCompilerBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,11 @@ public void compileIdls(File[] idls, File target) throws Exception {

@Override
public void compileAvscs(File[] avscs, File target) throws Exception {
List<File> files = new ArrayList<>(avscs.length);
for (File schema : avscs) {
System.out.println("Compiling Avro schema: " + schema);
files.add(schema);
}
Map<File, Schema> schemas = parser.parseFiles(files);

Map<File, Schema> schemas = parser.parseFiles(Arrays.asList(avscs));
for (Map.Entry<File, Schema> entry: schemas.entrySet()) {
File file = entry.getKey();
Schema schema = entry.getValue();
System.out.println("Compiling Avro schema: " + file + ":" + schema.getFullName());
SpecificCompiler compiler = new SpecificCompiler(schema);
configureCompiler(compiler);
compiler.compileToDestination(file, target);
Expand All @@ -119,7 +114,7 @@ public void compileAvprs(File[] avprs, File target) throws Exception {
Protocol protocol = Protocol.parse(avpr);
SpecificCompiler compiler = new SpecificCompiler(protocol);
configureCompiler(compiler);
compiler.compileToDestination(null, target);
compiler.compileToDestination(avpr, target);
}
}
}
3 changes: 0 additions & 3 deletions plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ object SbtAvro extends AutoPlugin {
// - no previous cache and we have records to recompile
// - input files have changed
// - output files are missing

// TODO Cache class loader
val avroClassLoader = new AvroCompilerPluginClassLoader(
(AvroCompiler / dependencyClasspath).value
.map(toNioPath)
Expand Down Expand Up @@ -287,7 +285,6 @@ object SbtAvro extends AutoPlugin {
throw new AvroGenerateFailedException
} finally {
Thread.currentThread().setContextClassLoader(initLoader)
avroClassLoader.close()
}
} else {
outReport.checked
Expand Down

0 comments on commit 132cd44

Please sign in to comment.