diff --git a/tools/core/src/main/java/org/teavm/tooling/builder/ClassLoaderFactory.java b/tools/core/src/main/java/org/teavm/tooling/builder/ClassLoaderFactory.java deleted file mode 100644 index ac62b7d10..000000000 --- a/tools/core/src/main/java/org/teavm/tooling/builder/ClassLoaderFactory.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2018 Alexey Andreev. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.teavm.tooling.builder; - -import java.net.URL; - -public interface ClassLoaderFactory { - ClassLoader create(URL[] urls, ClassLoader innerClassLoader); -} diff --git a/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java b/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java index ff45d55b7..241109968 100644 --- a/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java +++ b/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java @@ -16,14 +16,15 @@ package org.teavm.tooling.builder; import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Properties; -import java.util.Set; import java.util.stream.Collectors; import org.teavm.backend.wasm.render.WasmBinaryVersion; import org.teavm.callgraph.CallGraph; @@ -40,7 +41,6 @@ import org.teavm.vm.TeaVMOptimizationLevel; import org.teavm.vm.TeaVMProgressListener; public class InProcessBuildStrategy implements BuildStrategy { - private final ClassLoaderFactory classLoaderFactory; private List classPathEntries = new ArrayList<>(); private TeaVMTargetType targetType; private String mainClass; @@ -71,10 +71,6 @@ public class InProcessBuildStrategy implements BuildStrategy { private boolean shortFileNames; private boolean assertionsRemoved; - public InProcessBuildStrategy(ClassLoaderFactory classLoaderFactory) { - this.classLoaderFactory = classLoaderFactory; - } - @Override public void init() { sourceFileProviders.clear(); @@ -242,7 +238,8 @@ public class InProcessBuildStrategy implements BuildStrategy { tool.setEntryPointName(entryPointName); tool.setTargetDirectory(new File(targetDirectory)); tool.setTargetFileName(targetFileName); - tool.setClassLoader(buildClassLoader()); + var classLoader = buildClassLoader(); + tool.setClassLoader(classLoader); tool.setOptimizationLevel(optimizationLevel); tool.setFastDependencyAnalysis(fastDependencyAnalysis); @@ -273,11 +270,12 @@ public class InProcessBuildStrategy implements BuildStrategy { try { tool.generate(); - } catch (TeaVMToolException | RuntimeException | Error e) { + classLoader.close(); + } catch (TeaVMToolException | RuntimeException | Error | IOException e) { throw new BuildException(e); } - Set generatedFiles = tool.getGeneratedFiles().stream() + var generatedFiles = tool.getGeneratedFiles().stream() .map(File::getAbsolutePath) .collect(Collectors.toSet()); @@ -285,7 +283,7 @@ public class InProcessBuildStrategy implements BuildStrategy { tool.getProblemProvider(), tool.getClasses(), tool.getUsedResources(), generatedFiles); } - private ClassLoader buildClassLoader() { + private URLClassLoader buildClassLoader() { URL[] urls = classPathEntries.stream().map(entry -> { try { return new File(entry).toURI().toURL(); @@ -294,7 +292,7 @@ public class InProcessBuildStrategy implements BuildStrategy { } }).toArray(URL[]::new); - return classLoaderFactory.create(urls, InProcessBuildStrategy.class.getClassLoader()); + return new URLClassLoader(urls, InProcessBuildStrategy.class.getClassLoader()); } static class InProcessBuildResult implements BuildResult { diff --git a/tools/gradle/src/main/java/org/teavm/gradle/tasks/TeaVMTask.java b/tools/gradle/src/main/java/org/teavm/gradle/tasks/TeaVMTask.java index dd1e55fea..8596b105e 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/tasks/TeaVMTask.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/tasks/TeaVMTask.java @@ -17,7 +17,6 @@ package org.teavm.gradle.tasks; import java.io.File; import java.io.IOException; -import java.net.URLClassLoader; import java.rmi.NotBoundException; import java.rmi.registry.LocateRegistry; import java.util.ArrayList; @@ -104,7 +103,7 @@ public abstract class TeaVMTask extends DefaultTask { if (getOutOfProcess().get()) { executeInSeparateProcess(); } else { - executeWithBuilder(new InProcessBuildStrategy(URLClassLoader::new)); + executeWithBuilder(new InProcessBuildStrategy()); } } diff --git a/tools/maven/plugin/src/main/java/org/teavm/maven/TeaVMCompileMojo.java b/tools/maven/plugin/src/main/java/org/teavm/maven/TeaVMCompileMojo.java index d57b1a0bb..c574baf62 100644 --- a/tools/maven/plugin/src/main/java/org/teavm/maven/TeaVMCompileMojo.java +++ b/tools/maven/plugin/src/main/java/org/teavm/maven/TeaVMCompileMojo.java @@ -16,7 +16,6 @@ package org.teavm.maven; import java.io.File; -import java.net.URLClassLoader; import java.rmi.NotBoundException; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; @@ -251,7 +250,7 @@ public class TeaVMCompileMojo extends AbstractMojo { if (outOfProcess) { executeInSeparateProcess(); } else { - executeWithBuilder(new InProcessBuildStrategy(URLClassLoader::new)); + executeWithBuilder(new InProcessBuildStrategy()); } }