diff --git a/src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java b/src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java index 70fc3d03..c09c8efb 100644 --- a/src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java +++ b/src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java @@ -10,7 +10,6 @@ import static net.sourceforge.pmd.util.fxdesigner.util.reactfx.ReactfxUtil.latestValue; import java.io.File; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.Collections; @@ -28,7 +27,6 @@ import org.reactfx.value.Val; import org.reactfx.value.Var; -import net.sourceforge.pmd.internal.util.ClasspathClassLoader; // NOPMD import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.ast.Node; @@ -89,14 +87,6 @@ public class SourceEditorController extends AbstractController { private static final Duration AST_REFRESH_DELAY = Duration.ofMillis(100); private final ASTManager astManager; private final Var> auxclasspathFiles = Var.newSimpleVar(emptyList()); - private final Val auxclasspathClassLoader = auxclasspathFiles.map(fileList -> { - try { - return new ClasspathClassLoader(fileList, SourceEditorController.class.getClassLoader()); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - }).orElseConst(SourceEditorController.class.getClassLoader()); @FXML private Button searchButton; @@ -193,7 +183,7 @@ protected void beforeParentInit() { .distinct() .subscribe(nodeEditionCodeArea::updateSyntaxHighlighter); - ((ASTManagerImpl) astManager).classLoaderProperty().bind(auxclasspathClassLoader); + ((ASTManagerImpl) astManager).classpathProperty().bind(auxclasspathFiles); // default text, will be overwritten by settings restore setText(getDefaultText()); diff --git a/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/ASTManager.java b/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/ASTManager.java index d7faed88..f1665b57 100644 --- a/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/ASTManager.java +++ b/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/ASTManager.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.util.fxdesigner.app.services; +import java.io.File; +import java.util.List; import java.util.Map; import org.reactfx.value.SuspendableVar; @@ -50,7 +52,7 @@ public interface ASTManager extends ApplicationComponent, SettingsOwner { Val compilationUnitProperty(); - Val classLoaderProperty(); + Val> classpathProperty(); Val currentExceptionProperty(); diff --git a/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/ASTManagerImpl.java b/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/ASTManagerImpl.java index fd197099..d332929f 100644 --- a/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/ASTManagerImpl.java +++ b/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/ASTManagerImpl.java @@ -4,15 +4,19 @@ package net.sourceforge.pmd.util.fxdesigner.app.services; +import static java.util.Collections.emptyList; import static net.sourceforge.pmd.util.fxdesigner.util.reactfx.ReactfxUtil.latestValue; import static net.sourceforge.pmd.util.fxdesigner.util.reactfx.VetoableEventStream.vetoableNull; +import java.io.File; import java.time.Duration; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.NonNull; @@ -55,7 +59,7 @@ public class ASTManagerImpl implements ASTManager { private final DesignerRoot designerRoot; - private final Var auxclasspathClassLoader = Var.newSimpleVar(null); + private final Var> auxclasspathFiles = Var.newSimpleVar(emptyList()); /** * Most up-to-date compilation unit. Is null if the current source cannot be parsed. @@ -81,18 +85,18 @@ public ASTManagerImpl(DesignerRoot owner) { // Refresh the AST anytime the text, classloader, or language version changes sourceCode.values() - .or(classLoaderProperty().values()) + .or(classpathProperty().values()) .or(languageVersionProperty().values()) .subscribe(tick -> { - // note: if either of these values would be null (e.g. classloader _is_ null at some point) + // note: if either of these values would be null // the optional is empty. - Optional changedClassLoader = tick.asLeft().filter(Either::isRight).map(Either::getRight); + Optional> changedClasspath = tick.asLeft().filter(Either::isRight).map(Either::getRight); Optional changedLanguageVersion = Optional.of(tick).filter(Either::isRight).map(Either::getRight); Node updated; try { updated = refreshAST(this, getSourceCode(), getLanguageVersion(), - refreshRegistry(changedLanguageVersion.isPresent(), changedClassLoader.isPresent())).orElse(null); + refreshRegistry(changedLanguageVersion.isPresent(), changedClasspath.isPresent())).orElse(null); currentException.setValue(null); } catch (ParseAbortedException e) { updated = null; @@ -144,8 +148,8 @@ public void setSourceCode(String sourceCode) { } @Override - public Var classLoaderProperty() { - return auxclasspathClassLoader; + public Var> classpathProperty() { + return auxclasspathFiles; } @Override @@ -199,12 +203,15 @@ public Var currentExceptionProperty() { return currentException; } - private LanguageProcessorRegistry createNewRegistry(LanguageVersion version, ClassLoader classLoader) { + private LanguageProcessorRegistry createNewRegistry(LanguageVersion version, List classpath) { Map langProperties = new HashMap<>(); LanguagePropertyBundle bundle = version.getLanguage().newPropertyBundle(); bundle.setLanguageVersion(version.getVersion()); if (bundle instanceof JvmLanguagePropertyBundle) { - ((JvmLanguagePropertyBundle) bundle).setClassLoader(classLoader); + bundle.setProperty(JvmLanguagePropertyBundle.AUX_CLASSPATH, + classpath.stream() + .map(File::getAbsolutePath) + .collect(Collectors.joining(File.pathSeparator))); } langProperties.put(version.getLanguage(), bundle); @@ -230,7 +237,7 @@ private LanguageProcessorRegistry refreshRegistry(boolean changedLanguageVersion current.close(); } - LanguageProcessorRegistry newRegistry = createNewRegistry(getLanguageVersion(), classLoaderProperty().getValue()); + LanguageProcessorRegistry newRegistry = createNewRegistry(getLanguageVersion(), classpathProperty().getValue()); lpRegistry.setValue(newRegistry); return newRegistry; }