From cb1cfd9eace6a06fa92533c7801e4f6c05e60e60 Mon Sep 17 00:00:00 2001 From: Ashley <73482956+ascopes@users.noreply.github.com> Date: Tue, 25 Oct 2022 07:03:24 +0100 Subject: [PATCH 1/3] Closes #119 - remove compiler single run mechanism --- .../jct/compilers/AbstractCompiler.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractCompiler.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractCompiler.java index 30671e812..bc0ab322b 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractCompiler.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractCompiler.java @@ -19,7 +19,6 @@ import static java.util.Objects.requireNonNull; import io.github.ascopes.jct.annotations.Nullable; -import io.github.ascopes.jct.ex.CompilerAlreadyUsedException; import io.github.ascopes.jct.pathwrappers.PathWrapper; import java.nio.charset.Charset; import java.util.ArrayList; @@ -27,7 +26,6 @@ import java.util.Locale; import java.util.Optional; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.processing.Processor; import javax.tools.JavaCompiler; import javax.tools.JavaFileManager.Location; @@ -41,10 +39,6 @@ *
Implementations should extend this class and override anything they require. * In most cases, you should not need to override anything other than the constructor. * - *
Each instance of this class should be considered to be single-use. Mutation does - * not produce a new instance, meaning that this class is not immutable by - * design. - * *
This class is not thread-safe. * *
If you wish to create a common set of configuration settings for instances of @@ -60,12 +54,6 @@ public abstract class AbstractCompiler> implements Compilable { - // Use atomics for this to ensure no race conditions - // if the user makes a mistake during parallel test runs. - // We do not enforce thread safety but this one will prevent - // flaky tests at zero cost, so we make an exception for this. - private final AtomicBoolean alreadyCompiled; - private final String name; private final JavaCompiler jsr199Compiler; private final FlagBuilder flagBuilder; @@ -100,8 +88,6 @@ protected AbstractCompiler( JavaCompiler jsr199Compiler, FlagBuilder flagBuilder ) { - alreadyCompiled = new AtomicBoolean(false); - this.name = requireNonNull(name, "name"); this.fileManagerBuilder = requireNonNull(fileManagerBuilder, "fileManagerTemplate"); this.jsr199Compiler = requireNonNull(jsr199Compiler, "jsr199Compiler"); @@ -156,10 +142,6 @@ public String getName() { @Override public CompilationImpl compile() { - if (alreadyCompiled.getAndSet(true)) { - throw new CompilerAlreadyUsedException(); - } - var factory = new CompilationFactory(); return factory.compile( From 0c05f264b6636e38eaafbddca2b0b64f5fd1ab3a Mon Sep 17 00:00:00 2001 From: Ashley <73482956+ascopes@users.noreply.github.com> Date: Tue, 25 Oct 2022 07:06:24 +0100 Subject: [PATCH 2/3] Delete CompilerAlreadyUsedException.java --- .../jct/ex/CompilerAlreadyUsedException.java | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 java-compiler-testing/src/main/java/io/github/ascopes/jct/ex/CompilerAlreadyUsedException.java diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/ex/CompilerAlreadyUsedException.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/ex/CompilerAlreadyUsedException.java deleted file mode 100644 index 62b720f14..000000000 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/ex/CompilerAlreadyUsedException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2022 - 2022 Ashley Scopes - * - * 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 io.github.ascopes.jct.ex; - -import org.apiguardian.api.API; -import org.apiguardian.api.API.Status; - -/** - * Exception that is thrown when reusing a compiler that was already used. - * - * @author Ashley Scopes - * @see CompilerException - * @since 0.0.1 - */ -@API(status = Status.EXPERIMENTAL, since = "0.0.1") -public class CompilerAlreadyUsedException extends CompilerException { - - public CompilerAlreadyUsedException() { - super("This compiler has already been used, create a new one to run another compilation"); - } -} From a771456cfc1218359ffe14a0204bbf62a04ee975 Mon Sep 17 00:00:00 2001 From: Ashley <73482956+ascopes@users.noreply.github.com> Date: Tue, 25 Oct 2022 07:11:58 +0100 Subject: [PATCH 3/3] Update Compilable.java --- .../main/java/io/github/ascopes/jct/compilers/Compilable.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/Compilable.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/Compilable.java index 9c2d6d6bc..d79a04555 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/Compilable.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/Compilable.java @@ -15,7 +15,6 @@ */ package io.github.ascopes.jct.compilers; -import io.github.ascopes.jct.ex.CompilerAlreadyUsedException; import io.github.ascopes.jct.ex.CompilerException; import io.github.ascopes.jct.pathwrappers.BasicPathWrapperImpl; import io.github.ascopes.jct.pathwrappers.PathWrapper; @@ -1176,8 +1175,6 @@ default C target(SourceVersion target) { * Invoke the compilation and return the compilation result. * * @return the compilation result. - * @throws CompilerAlreadyUsedException if the compiler was already used previously. Compilers are - * single-use only. * @throws CompilerException if the compiler threw an unhandled exception. This should * not occur for compilation failures generally. * @throws IllegalStateException if no compilation units were found.