From 10c2be6a95fe733d07a790277e47c7530d556d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Sat, 28 Nov 2026 14:24:09 +0100 Subject: [PATCH 1/2] fix(check): declare the check configuration scope only when its class exists The Check builder added a checkcfgproject preference scope, implemented by com.avaloq.tools.targetdefinition.check.configuration.CheckConfigurationPreferences, to the preferences extension of every catalog. DDK has no such class, so a clean build put an unresolvable scope back into the plugin.xml of check.test.runtime and sample.helloworld, which efabc6fbf had removed by hand. The scope is now declared only if the class is on the Java build path of the catalog's project, as the old TODO asked, and an update removes a scope whose class is not available. Projects that have the class keep it. Part of #1673 Co-Authored-By: Claude Opus 5.5 --- .../CheckPreferencesExtensionTest.java | 109 ++++++++++++++++++ .../util/CheckPreferencesExtensionHelper.java | 48 ++++++-- 2 files changed, 149 insertions(+), 8 deletions(-) create mode 100644 com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/builder/CheckPreferencesExtensionTest.java diff --git a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/builder/CheckPreferencesExtensionTest.java b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/builder/CheckPreferencesExtensionTest.java new file mode 100644 index 0000000000..3593321b74 --- /dev/null +++ b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/builder/CheckPreferencesExtensionTest.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2026 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ +package com.avaloq.tools.ddk.check.ui.test.builder; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.pde.core.plugin.IPluginElement; +import org.eclipse.pde.core.plugin.IPluginExtension; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.internal.core.plugin.WorkspacePluginModel; +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.extensions.InjectionExtension; +import org.eclipse.xtext.testing.util.ParseHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.avaloq.tools.ddk.check.check.CheckCatalog; +import com.avaloq.tools.ddk.check.ui.builder.util.CheckPreferencesExtensionHelper; +import com.avaloq.tools.ddk.check.ui.builder.util.ExtensionType; +import com.avaloq.tools.ddk.check.ui.test.internal.CheckWizardUiTestInjectorProvider; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.inject.Inject; + + +/** + * Tests that the preferences extension declares the check configuration scope only when its class is available. + */ +@SuppressWarnings({"restriction", "nls"}) +@InjectWith(CheckWizardUiTestInjectorProvider.class) +@ExtendWith(InjectionExtension.class) +public class CheckPreferencesExtensionTest { + + private static final String CATALOG = "package com.test catalog c for grammar g { live error \"First Check\"{ for g { issue }}}"; + private static final String INITIALIZER = "initializer"; + + private CheckCatalog catalog; + private IPluginModelBase pluginModel; + + @Inject + private ParseHelper parser; + @Inject + private CheckPreferencesExtensionHelper preferencesUtil; + @Inject + private IWorkspace workspace; + + @BeforeEach + public void setUp() { + try { + catalog = parser.parse(CATALOG); + } catch (Exception e) { + throw new AssertionError(e); + } + IFile pluginxml = workspace.getRoot().getFile(new Path("/test/plugin.xml")); + pluginModel = new WorkspacePluginModel(pluginxml, false); + } + + /** + * Without the check configuration scope class, the extension has only the initializer, and needs no update. + * + * @throws CoreException + * core exception + */ + @Test + public void testCreateExtensionWithoutScope() throws CoreException { + IPluginExtension extension = preferencesUtil.addExtensionToPluginBase(pluginModel, catalog, ExtensionType.PREFERENCE_INITIALIZER, null); + assertEquals(1, extension.getChildCount(), "only the initializer"); + assertEquals(INITIALIZER, extension.getChildren()[0].getName(), "initializer element"); + assertFalse(preferencesUtil.isExtensionUpdateRequired(catalog, extension, elements(extension)), "no update required"); + } + + /** + * An extension with a scope whose class is not available is updated to drop the scope. + * + * @throws CoreException + * core exception + */ + @Test + public void testUpdateRemovesUnavailableScope() throws CoreException { + IPluginExtension extension = preferencesUtil.addExtensionToPluginBase(pluginModel, catalog, ExtensionType.PREFERENCE_INITIALIZER, null); + IPluginElement scope = extension.getModel().getFactory().createElement(extension); + scope.setName("scope"); + scope.setAttribute("name", "checkcfgproject"); + extension.add(scope); + assertTrue(preferencesUtil.isExtensionUpdateRequired(catalog, extension, elements(extension)), "update required"); + preferencesUtil.updateExtension(catalog, extension); + assertEquals(1, extension.getChildCount(), "scope removed"); + assertEquals(INITIALIZER, extension.getChildren()[0].getName(), "initializer kept"); + } + + private static Iterable elements(final IPluginExtension extension) { + return Iterables.filter(Lists.newArrayList(extension.getChildren()), IPluginElement.class); + } +} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java index fc54260f59..73fe692e7f 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java @@ -12,7 +12,13 @@ import java.util.List; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.emf.common.util.URI; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.pde.core.plugin.IPluginElement; import org.eclipse.pde.core.plugin.IPluginExtension; import org.eclipse.xtext.util.Strings; @@ -62,11 +68,39 @@ protected String getExtensionEnablementPreferenceName() { */ @Override protected void doUpdateExtension(final CheckCatalog catalog, final IPluginExtension extension, final Iterable elements) throws CoreException { - // The preference extension must define an initializer and a scope plugin element + // The preference extension defines an initializer, and the check configuration scope if its class is available extension.setName(getExtensionPointName(catalog)); updateInitializerElement(catalog, Iterables.get(elements, 0)); + boolean scopeAvailable = isScopeAvailable(catalog); if (Iterables.size(elements) == 2) { - updateScopeElement(Iterables.get(elements, 1)); + if (scopeAvailable) { + updateScopeElement(Iterables.get(elements, 1)); + } else { + extension.remove(Iterables.get(elements, 1)); + } + } else if (scopeAvailable) { + extension.add(updateScopeElement(extension.getModel().getFactory().createElement(extension))); + } + } + + /** + * Whether the check configuration scope class is on the Java build path of the catalog's project. + * + * @param catalog + * the check catalog + * @return {@code true} if the preferences extension can declare the check configuration scope + */ + private boolean isScopeAvailable(final CheckCatalog catalog) { + URI uri = catalog.eResource() == null ? null : catalog.eResource().getURI(); + if (uri == null || !uri.isPlatformResource()) { + return false; + } + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(URI.decode(uri.segment(1))); + IJavaProject javaProject = JavaCore.create(project); + try { + return javaProject.exists() && javaProject.findType(CHECK_CONFIGURATION_PREFS) != null; + } catch (JavaModelException e) { + return false; } } @@ -134,11 +168,9 @@ protected boolean extensionNameMatches(final IPluginExtension extension, final C public Iterable getElements(final CheckCatalog catalog, final IPluginExtension extension) throws CoreException { List result = Lists.newArrayList(); result.add(updateInitializerElement(catalog, extension.getModel().getFactory().createElement(extension))); - - // if (CheckProjectUtil.typeExists(catalog, CHECK_CONFIGURATION_PREFS)) { - // TODO should only use the check configuration scope if corresponding class is available - result.add(updateScopeElement(extension.getModel().getFactory().createElement(extension))); - // } + if (isScopeAvailable(catalog)) { + result.add(updateScopeElement(extension.getModel().getFactory().createElement(extension))); + } return result; } @@ -186,7 +218,7 @@ public boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPlug // @Format-Off return PREFERENCES_EXTENSION_POINT_ID.equals(extension.getPoint()) && (!extensionNameMatches(extension, catalog) - || Iterables.size(elements) != 2 + || Iterables.size(elements) != (isScopeAvailable(catalog) ? 2 : 1) || !initializerClassMatches(getInitializerElement(elements), getTargetClassName(catalog))); // @Format-On } From 8c7eae4eb0f098353f9ae5c6e2346ea81593aff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Sat, 28 Nov 2026 14:24:17 +0100 Subject: [PATCH 2/2] ci: check the Check builder's output of the repository's catalogs com.avaloq.tools.ddk.check.regenerate is an unpublished test bundle whose test regenerates the Check output as Eclipse does: it imports every project with Check settings (check.test.runtime and sample.helloworld) into a workbench at its location in the repository, cleans and builds it, and fails on build errors. The output is the IDE builder's own, so there is no second Check generator to keep in line with it. regenerate.sh runs it after the MWE2 workflows, and the generated-sources job runs the script under xvfb-run, so the job also fails when a catalog's Java, documentation pages, service registry or plugin.xml extensions differ from what the builder writes. The test is skipped unless check.regenerate.skip=false, which only the script sets, so check-surefire-reports.sh leaves it out. Fixes #1673 Co-Authored-By: Claude Opus 5.5 --- .github/scripts/check-surefire-reports.sh | 4 + .github/scripts/regenerate.sh | 11 +- .github/workflows/verify.yml | 3 +- AGENTS.md | 2 + .../.classpath | 7 + .../.project | 75 ++++++++++ .../.settings/.gitignore | 0 .../META-INF/MANIFEST.MF | 31 +++++ .../build.properties | 4 + com.avaloq.tools.ddk.check.regenerate/pom.xml | 36 +++++ .../regenerate/RegenerateCheckOutputTest.java | 129 ++++++++++++++++++ ddk-parent/pom.xml | 1 + 12 files changed, 300 insertions(+), 3 deletions(-) create mode 100644 com.avaloq.tools.ddk.check.regenerate/.classpath create mode 100644 com.avaloq.tools.ddk.check.regenerate/.project create mode 100644 com.avaloq.tools.ddk.check.regenerate/.settings/.gitignore create mode 100644 com.avaloq.tools.ddk.check.regenerate/META-INF/MANIFEST.MF create mode 100644 com.avaloq.tools.ddk.check.regenerate/build.properties create mode 100644 com.avaloq.tools.ddk.check.regenerate/pom.xml create mode 100644 com.avaloq.tools.ddk.check.regenerate/src/com/avaloq/tools/ddk/check/regenerate/RegenerateCheckOutputTest.java diff --git a/.github/scripts/check-surefire-reports.sh b/.github/scripts/check-surefire-reports.sh index 139ca49cbe..a51d97bb0a 100644 --- a/.github/scripts/check-surefire-reports.sh +++ b/.github/scripts/check-surefire-reports.sh @@ -12,6 +12,10 @@ while IFS= read -r source; do if grep -qE 'abstract[[:space:]]+class|@interface' "$source"; then continue fi + # Runs only from regenerate.sh, as it rewrites committed Check output. + if [[ $source == com.avaloq.tools.ddk.check.regenerate/* ]]; then + continue + fi expected=$((expected + 1)) module=${source%%/*} class=${source#*/src/} diff --git a/.github/scripts/regenerate.sh b/.github/scripts/regenerate.sh index 31336cba43..03cd6fb15f 100755 --- a/.github/scripts/regenerate.sh +++ b/.github/scripts/regenerate.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash # Checks that every tracked MWE2 workflow has an Eclipse launch, then runs the workflows headless, without Eclipse, -# except those listed below. In Eclipse, run a workflow's launch instead; this script must reproduce its output. +# except those listed below, then the Check builder: a clean build, in an Eclipse workbench started by Maven, of the projects +# with Check settings (com.avaloq.tools.ddk.check.regenerate). In Eclipse, run a workflow's launch, or clean the projects +# in a runtime workbench, instead; this script must reproduce their output. On Linux without a display, use xvfb-run. # Build first, on JDK 21, and again after changing a grammar or generator: # ./mvnw install -DskipTests -f ddk-parent/pom.xml -pl ":ddk-target,$(.github/scripts/regenerate.sh --owners)" -am -Dtycho.baseline=disable -Dtycho.baseline.replace=none # Arguments are passed to Maven, e.g. -Dmaven.repo.local=...; --owners prints the owning bundles as a -pl list, --list the workflows it runs. @@ -57,8 +59,9 @@ for wf in "${WORKFLOWS[@]}"; do done projects=$(printf ',:%s' "${bundles[@]}") +check_build=com.avaloq.tools.ddk.check.regenerate if [[ ${1-} == --owners ]]; then - echo "${projects:1}" + echo "${projects:1},:$check_build" exit 0 fi if [[ ${1-} == --list ]]; then @@ -103,3 +106,7 @@ if (( ${#failed[@]} )); then printf 'regenerate.sh: workflow failed: %s\n' "${failed[@]}" >&2 exit 1 fi + +# Runs after the workflows, as the Check output depends on the grammars, so the tree may already be dirty. +./mvnw -f ddk-parent/pom.xml --batch-mode -pl ":$check_build" "$@" \ + -Dcheck.regenerate.skip=false -Djgit.dirtyWorkingTree=warning verify diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 187a730c36..efa475cd61 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -122,7 +122,8 @@ jobs: # Maven must finish before the workflows dirty the tree. run: ./mvnw install -DskipTests -f ./ddk-parent/pom.xml -pl ":ddk-target,$(bash .github/scripts/regenerate.sh --owners)" -am --batch-mode -T 2 -Dtycho.baseline=disable -Dtycho.baseline.replace=none - name: Regenerate sources - run: bash .github/scripts/regenerate.sh + # The Check builder runs in an Eclipse workbench, which needs a display. + run: xvfb-run bash .github/scripts/regenerate.sh - name: Fail on generated sources out of sync run: | git status --porcelain --untracked-files=all diff --git a/AGENTS.md b/AGENTS.md index 50b1648369..d070c2c4e4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -156,6 +156,8 @@ git status ``` A new workflow is checked automatically, and the job builds its owning bundle from `--owners`. Add to `KNOWN_DRIFT` only with an issue that removes the entry again. +The Check builder writes the output of `.check` catalogs (Java in `dsl-gen/`, `docs/content/`, `META-INF/services/`, `plugin.xml` extensions) when Eclipse builds a project with the Xtext nature. Regenerate it in a runtime workbench (`ddk-configuration/launches/devkit-run.launch`): import the project and clean it. `regenerate.sh` reproduces this after the workflows: the test of `com.avaloq.tools.ddk.check.regenerate` imports every project with `.settings/com.avaloq.tools.ddk.check.Check.prefs` into a workbench at its location in the repository, cleans and builds it, and fails on build errors. It needs a display (`xvfb-run` on Linux) and runs only with `-Dcheck.regenerate.skip=false`, which the script sets. A project with Check catalogs needs the Xtext nature and builder, and the bundles it requires in that module's manifest. + ### Bumping Versions CI fails with "Only qualifier changed" when a published bundle or feature differs from the last release (`p2/releases/latest`) but keeps its version. 1. Changing a published bundle (one included in the features, incl. `test.core`, `test.ui`, `xtext.test.core`): its version on `master` must reflect the strongest change since the last release, so it is bumped at most once per level between releases, not once per PR. diff --git a/com.avaloq.tools.ddk.check.regenerate/.classpath b/com.avaloq.tools.ddk.check.regenerate/.classpath new file mode 100644 index 0000000000..dc300921a0 --- /dev/null +++ b/com.avaloq.tools.ddk.check.regenerate/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/com.avaloq.tools.ddk.check.regenerate/.project b/com.avaloq.tools.ddk.check.regenerate/.project new file mode 100644 index 0000000000..558667b71a --- /dev/null +++ b/com.avaloq.tools.ddk.check.regenerate/.project @@ -0,0 +1,75 @@ + + + com.avaloq.tools.ddk.check.regenerate + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + + + .checkstyle + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.checkstyle + + + .fbprefs + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.fbprefs + + + .pmd + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.pmd + + + .settings/edu.umd.cs.findbugs.plugin.eclipse.prefs + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.settings/edu.umd.cs.findbugs.plugin.eclipse.prefs + + + .settings/org.eclipse.core.resources.prefs + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.settings/org.eclipse.core.resources.prefs + + + .settings/org.eclipse.core.runtime.prefs + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.settings/org.eclipse.core.runtime.prefs + + + .settings/org.eclipse.jdt.core.prefs + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.settings/org.eclipse.jdt.core.prefs + + + .settings/org.eclipse.jdt.ui.prefs + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.settings/org.eclipse.jdt.ui.prefs + + + .settings/org.eclipse.pde.core.prefs + 1 + PARENT-1-PROJECT_LOC/ddk-configuration/.settings/org.eclipse.pde.core.prefs + + + diff --git a/com.avaloq.tools.ddk.check.regenerate/.settings/.gitignore b/com.avaloq.tools.ddk.check.regenerate/.settings/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/com.avaloq.tools.ddk.check.regenerate/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.check.regenerate/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..a2da894b7d --- /dev/null +++ b/com.avaloq.tools.ddk.check.regenerate/META-INF/MANIFEST.MF @@ -0,0 +1,31 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: com.avaloq.tools.ddk.check.regenerate +Bundle-SymbolicName: com.avaloq.tools.ddk.check.regenerate +Bundle-Version: 17.3.1.qualifier +Bundle-Vendor: Avaloq Group AG +Bundle-RequiredExecutionEnvironment: JavaSE-21 +Require-Bundle: org.eclipse.core.resources, + org.eclipse.core.runtime, + org.eclipse.jdt.core, + org.eclipse.pde.core, + org.eclipse.xtext.builder, + org.eclipse.xtext.ui.shared, + com.avaloq.tools.ddk.check.ui, + com.avaloq.tools.ddk.check.core, + com.avaloq.tools.ddk.check.lib, + com.avaloq.tools.ddk.check.runtime.core, + com.avaloq.tools.ddk.xtext, + com.avaloq.tools.ddk.xtext.generator, + org.eclipse.xtext.xtext.generator, + org.eclipse.xtext.ide, + org.eclipse.xtext.xbase, + org.eclipse.xtext.common.types, + org.eclipse.emf.codegen.ecore, + org.eclipse.emf.mwe.utils, + org.eclipse.emf.mwe2.launch, + org.antlr.runtime, + junit-jupiter-api +Import-Package: org.apache.log4j, + org.apache.logging.log4j +Automatic-Module-Name: com.avaloq.tools.ddk.check.regenerate diff --git a/com.avaloq.tools.ddk.check.regenerate/build.properties b/com.avaloq.tools.ddk.check.regenerate/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/com.avaloq.tools.ddk.check.regenerate/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/com.avaloq.tools.ddk.check.regenerate/pom.xml b/com.avaloq.tools.ddk.check.regenerate/pom.xml new file mode 100644 index 0000000000..b6e3bb81f9 --- /dev/null +++ b/com.avaloq.tools.ddk.check.regenerate/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + ddk-parent + com.avaloq.tools.ddk + 18.0.1-SNAPSHOT + ../ddk-parent + + 17.3.1-SNAPSHOT + + com.avaloq.tools.ddk.check.regenerate + eclipse-test-plugin + + + true + 1 + + true + + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho.version} + + ${check.regenerate.skip} + + ${project.basedir}/.. + + + + + + diff --git a/com.avaloq.tools.ddk.check.regenerate/src/com/avaloq/tools/ddk/check/regenerate/RegenerateCheckOutputTest.java b/com.avaloq.tools.ddk.check.regenerate/src/com/avaloq/tools/ddk/check/regenerate/RegenerateCheckOutputTest.java new file mode 100644 index 0000000000..4f1466dd75 --- /dev/null +++ b/com.avaloq.tools.ddk.check.regenerate/src/com/avaloq/tools/ddk/check/regenerate/RegenerateCheckOutputTest.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2026 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ +package com.avaloq.tools.ddk.check.regenerate; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.jobs.Job; +import org.junit.jupiter.api.Test; + + +/** + * Regenerates the Check builder's output of the repository's projects in place, as a clean build of them in an Eclipse + * workbench does. Projects with Check settings are imported, cleaned and built; build errors fail the run. + *

+ * Skipped unless {@code check.regenerate.skip=false}, which {@code .github/scripts/regenerate.sh} sets. + */ +@SuppressWarnings("nls") +public class RegenerateCheckOutputTest { + + private static final String CHECK_SETTINGS = ".settings/com.avaloq.tools.ddk.check.Check.prefs"; + private static final IPath MAVEN_OUTPUT = IPath.fromOSString("target"); + private static final long IDLE_TIMEOUT_MILLIS = 600_000; + private static final long IDLE_POLL_MILLIS = 100; + + /** + * Cleans and builds the projects with Check settings. + * + * @throws CoreException + * if a project cannot be imported or built + * @throws IOException + * if the repository cannot be listed + * @throws InterruptedException + * if interrupted while waiting for the build + */ + @Test + public void testRegenerate() throws CoreException, IOException, InterruptedException { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + List projects = importProjects(workspace, Path.of(System.getProperty("ddk.root"))); + assertFalse(projects.isEmpty(), "projects with Check settings"); + try { + waitUntilIdle(); + workspace.build(IncrementalProjectBuilder.CLEAN_BUILD, null); + waitUntilIdle(); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, null); + waitUntilIdle(); + List errors = new ArrayList<>(); + for (IProject project : projects) { + for (IMarker marker : project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)) { + // Maven's copies of the sources under target/ are not the project's sources. + if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR + && !MAVEN_OUTPUT.isPrefixOf(marker.getResource().getProjectRelativePath())) { + errors.add(marker.getResource().getFullPath() + ":" + marker.getAttribute(IMarker.LINE_NUMBER, -1) + ": " + marker.getAttribute(IMarker.MESSAGE, "")); + } + } + } + assertTrue(errors.isEmpty(), "build errors:\n" + String.join("\n", errors)); + } finally { + for (IProject project : projects) { + project.delete(false, true, null); + } + } + } + + /** + * Imports the repository's projects with Check settings into the workspace, at their location in the repository. + * + * @param workspace + * the workspace + * @param root + * the repository root + * @return the imported projects + * @throws CoreException + * if a project cannot be imported + * @throws IOException + * if the repository cannot be listed + */ + private static List importProjects(final IWorkspace workspace, final Path root) throws CoreException, IOException { + List projects = new ArrayList<>(); + try (Stream children = Files.list(root)) { + for (Path dir : children.filter(d -> Files.isRegularFile(d.resolve(CHECK_SETTINGS))).sorted().toList()) { + IProjectDescription description = workspace.loadProjectDescription(IPath.fromPath(dir.resolve(".project"))); + IProject project = workspace.getRoot().getProject(description.getName()); + project.create(description, null); + project.open(null); + projects.add(project); + } + } + return projects; + } + + /** + * Waits until no jobs run, so that classpath containers are resolved and builds are finished. + * + * @throws InterruptedException + * if interrupted while waiting + */ + private static void waitUntilIdle() throws InterruptedException { + long deadline = System.currentTimeMillis() + IDLE_TIMEOUT_MILLIS; + while (!Job.getJobManager().isIdle()) { + assertTrue(System.currentTimeMillis() < deadline, "jobs still running after " + IDLE_TIMEOUT_MILLIS + " ms"); + Thread.sleep(IDLE_POLL_MILLIS); + } + } +} diff --git a/ddk-parent/pom.xml b/ddk-parent/pom.xml index ff72c619c1..a534954448 100644 --- a/ddk-parent/pom.xml +++ b/ddk-parent/pom.xml @@ -121,6 +121,7 @@ ../com.avaloq.tools.ddk.check.core.test ../com.avaloq.tools.ddk.check.runtime.core.test ../com.avaloq.tools.ddk.check.ui.test + ../com.avaloq.tools.ddk.check.regenerate ../com.avaloq.tools.ddk.check.test.runtime ../com.avaloq.tools.ddk.check.test.runtime.ide ../com.avaloq.tools.ddk.check.test.runtime.tests