Run Designer previews with application-owned DI adapters

This commit is contained in:
2026-11-26 16:01:19 +01:00
parent e49d586916
commit 6126967fdc
56 changed files with 2131 additions and 50 deletions
@@ -0,0 +1,66 @@
package qualification;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import javafx.application.Platform;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.stage.Window;
/** Test-only observer of the actual interactive window, inside the target JVM. */
public final class SpringTargetProbe {
public static void premain(String output) {
var command = System.getProperty("sun.java.command", "").split(" ", 2)[0];
if (command.endsWith(".WorkerMain"))
Thread.ofPlatform().daemon().name("spring-preview-probe").start(() -> Observer.observe(Path.of(output)));
}
private static class Observer {
private static void observe(Path output) {
try {
while (true) {
Thread.sleep(100);
var inspect = new FutureTask<>(() -> inspect(output));
try {
Platform.runLater(inspect);
} catch (IllegalStateException toolkitStarting) {
continue;
}
if (inspect.get(10, TimeUnit.SECONDS)) return;
}
} catch (InterruptedException stopped) {
Thread.currentThread().interrupt();
} catch (Throwable error) {
try {
Files.writeString(output.resolve("target-error.txt"), error.toString());
} catch (Exception writeFailure) {
error.addSuppressed(writeFailure);
error.printStackTrace();
}
}
}
private static boolean inspect(Path output) throws Exception {
var stage = Window.getWindows().stream()
.filter(w -> w instanceof Stage window && window.isShowing() && window.getOpacity() > 0
&& window.getTitle() != null && window.getTitle().startsWith("Neitzel preview"))
.findFirst();
if (stage.isEmpty()) return false;
String attempt = Files.readString(output.resolve("spring-attempt"));
boolean book = attempt.startsWith("book-");
var scene = stage.get().getScene();
var field = (TextField) scene.lookup(book ? "#bookName" : "#entryName");
String expected = book ? "Preview contact book" : "Preview entry";
if (field == null || !expected.equals(field.getText()))
throw new AssertionError("Expected fresh " + expected + " in " + attempt);
field.setText("Edited in preview");
if (book && !"[Edited in preview]".equals(((Label) scene.lookup("#convertedName")).getText()))
throw new AssertionError("Spring Converter did not update the live interactive View");
Files.writeString(output.resolve(attempt + ".txt"), expected);
return true;
}
}
}
@@ -0,0 +1,44 @@
package qualification;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.vfs.LocalFileSystem;
import de.neitzel.fxdesigner.kit.SpringPreviewHostChecks;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import static qualification.WorkflowProbe.edt;
import static qualification.WorkflowProbe.openDesigner;
import static qualification.WorkflowProbe.output;
public final class SpringWorkflowProbe implements StartupActivity.DumbAware {
public void runActivity(Project project) {
if (!WorkflowProbe.started.compareAndSet(false, true)) return;
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
var path = Path.of(project.getBasePath(), "app/src/main/resources/fixture/spring/ui");
verify(project, path.resolve("Book.fxml"), "Spring contact book", true);
verify(project, path.resolve("EntryCard.fxml"), "Spring entry", false);
Files.writeString(output.resolve("SUCCESS.txt"),
"PASS Spring canvas, form and interactive previews in the registered IntelliJ editor");
} catch (Throwable failure) {
var trace = new StringWriter();
failure.printStackTrace(new PrintWriter(trace));
try {
Files.writeString(output.resolve("FAILURE.txt"), trace.toString());
} catch (Exception writeFailure) {
failure.addSuppressed(writeFailure);
failure.printStackTrace();
}
}
});
}
private static void verify(Project project, Path path, String label, boolean book) throws Exception {
var file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
SpringPreviewHostChecks.verify(openDesigner(project, file), label, book, output);
}
}