Skip to content

Commit

Permalink
Don't close URLClassLoader
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 committed Jan 15, 2025
1 parent 2407602 commit 6b17517
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 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);
}
}
}
7 changes: 2 additions & 5 deletions plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ object SbtAvro extends AutoPlugin {
val cacheStoreFactory = CacheStoreFactory(out.cacheDirectory / "avro")
val lastCache = { (action: Option[Set[File]] => Set[File]) =>
Tracked
.lastOutput[Unit, Set[File]](cacheStoreFactory.make("last-cache")) { case (_, l) =>
action(l)
.lastOutput[Unit, Set[File]](cacheStoreFactory.make("last-cache")) {
case (_, l) => action(l)
}
.apply(())
}
Expand All @@ -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 6b17517

Please sign in to comment.