diff --git a/org.eclipse.xtext.builder.tests/META-INF/MANIFEST.MF b/org.eclipse.xtext.builder.tests/META-INF/MANIFEST.MF index ca063b9510e..e6db26378a6 100644 --- a/org.eclipse.xtext.builder.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.xtext.builder.tests/META-INF/MANIFEST.MF @@ -40,7 +40,7 @@ Import-Package: org.apache.log4j;version="1.2.24", org.junit.rules;version="4.13.2", org.junit.runner;version="4.13.2", org.junit.runners.model;version="4.13.2" -Bundle-Activator: org.eclipse.xtext.builder.tests.internal.TestsActivator +Bundle-Activator: org.eclipse.xtext.builder.tests.internal.TestsActivatorCustom Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.xtext.builder.tests;version="2.34.0", org.eclipse.xtext.builder.tests.builderTestLanguage;version="2.34.0", diff --git a/org.eclipse.xtext.builder.tests/plugin.xml b/org.eclipse.xtext.builder.tests/plugin.xml index 4286158cb06..6e883f0689e 100644 --- a/org.eclipse.xtext.builder.tests/plugin.xml +++ b/org.eclipse.xtext.builder.tests/plugin.xml @@ -132,14 +132,31 @@ type="buildertestlanguage"> + + + + + + + + + + + diff --git a/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/impl/GH2920Test.java b/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/impl/GH2920Test.java index 479a750959d..574c9c7f0a4 100644 --- a/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/impl/GH2920Test.java +++ b/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/impl/GH2920Test.java @@ -8,6 +8,12 @@ *******************************************************************************/ package org.eclipse.xtext.builder.impl; +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -21,18 +27,19 @@ import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertFalse; - import com.google.inject.Inject; /** * @author sherrmann - Initial contribution and API + * @author Lorenzo Bettini - make it appropriate for reproducing https://github.com/eclipse/xtext/issues/2920 */ public class GH2920Test extends AbstractParticipatingBuilderTest { private IJavaProject javaProject; - + @Inject private IResourceDescriptionsProvider descriptionsProvider; + private List descriptionsInOutputFolder = new ArrayList<>(); + @Before public void createProjectUnderTest() throws Exception { javaProject = createJavaProject("NoResourceFromOutput"); @@ -43,7 +50,12 @@ public void createProjectUnderTest() throws Exception { @Override public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException { IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(context.getResourceSet()); - resourceDescriptions.getAllResourceDescriptions().forEach(rd -> assertFalse(rd.getURI().toString().contains("bin"))); + resourceDescriptions.getAllResourceDescriptions().forEach( + rd -> { + String uriString = rd.getURI().toString(); + if (uriString.contains("bin")) + descriptionsInOutputFolder.add(uriString); + }); super.build(context, monitor); } @@ -54,14 +66,21 @@ public void testIncremental() throws Exception { build(); startLogging(); createSomeBuilderRelatedFile(project, "Bar"); + checkNoUrisInOutputFolder(); } private IFile createSomeBuilderRelatedFile(IProject project, String name) throws CoreException { IFolder folder = project.getProject().getFolder("src"); - IFile file = folder.getFile(name + F_EXT); + IFile file = folder.getFile(name + F_EXT + "GH2920"); file.create(new StringInputStream("object "+name), true, monitor()); build(); return file; } -} + private void checkNoUrisInOutputFolder() { + if (!descriptionsInOutputFolder.isEmpty()) + fail("unexpected resources in output folder:\n" + + descriptionsInOutputFolder.stream() + .collect(Collectors.joining("\n", " ", ""))); + } +} diff --git a/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/tests/internal/TestsActivatorCustom.java b/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/tests/internal/TestsActivatorCustom.java new file mode 100644 index 00000000000..c6d437d427d --- /dev/null +++ b/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/tests/internal/TestsActivatorCustom.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2024 itemis AG (http://www.itemis.eu) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.xtext.builder.tests.internal; + +import org.eclipse.xtext.Constants; +import org.eclipse.xtext.builder.tests.BuilderTestLanguageRuntimeModule; +import org.eclipse.xtext.builder.tests.ui.BuilderTestLanguageUiModule; +import org.eclipse.xtext.ui.shared.JdtHelper; +import org.eclipse.xtext.ui.util.IJdtHelper; + +import com.google.inject.Binder; +import com.google.inject.Module; +import com.google.inject.Provider; +import com.google.inject.name.Names; + +/** + * This allows customizations in the UI, specific for some test scenarions, without creating new languages. + * + * @author Lorenzo Bettini - Initial contribution and API + */ +public class TestsActivatorCustom extends TestsActivator { + + public static final String ORG_ECLIPSE_XTEXT_BUILDER_TESTS_BUILDERTESTLANGUAGE_GH2920 = ORG_ECLIPSE_XTEXT_BUILDER_TESTS_BUILDERTESTLANGUAGE + + "GH2920"; + + @Override + protected Module getRuntimeModule(String grammar) { + if (ORG_ECLIPSE_XTEXT_BUILDER_TESTS_BUILDERTESTLANGUAGE_GH2920.equals(grammar)) + return new BuilderTestLanguageRuntimeModule() { + @Override + public void configureFileExtensions(Binder binder) { + if (properties == null || properties.getProperty(Constants.FILE_EXTENSIONS) == null) + binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)) + .toInstance("buildertestlanguageGH2920"); + } + }; + return super.getRuntimeModule(grammar); + } + + @Override + protected Module getUiModule(String grammar) { + if (ORG_ECLIPSE_XTEXT_BUILDER_TESTS_BUILDERTESTLANGUAGE_GH2920.equals(grammar)) + return new BuilderTestLanguageUiModule(this) { + /** + * By default, the {@link IJdtHelper} is bound by the {@link org.eclipse.xtext.ui.shared.SharedStateModule}, but since the + * UI module is mixed as the last one in {@link TestsActivator}, we can "override" its binding here. + */ + @SuppressWarnings("unused") + public Provider provideJdtHelper() { + return new Provider<>() { + @Override + public IJdtHelper get() { + return new JdtHelper() { + @Override + protected boolean computeJavaCoreAvailable() { + return false; + } + }; + } + }; + } + }; + return super.getUiModule(grammar); + } +} diff --git a/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/tests/ui/BuilderTestLanguageExecutableExtensionFactoryGH2920.java b/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/tests/ui/BuilderTestLanguageExecutableExtensionFactoryGH2920.java new file mode 100644 index 00000000000..5ea6b04073f --- /dev/null +++ b/org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/tests/ui/BuilderTestLanguageExecutableExtensionFactoryGH2920.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2024 itemis AG (http://www.itemis.eu) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.xtext.builder.tests.ui; + +import org.eclipse.xtext.builder.tests.internal.TestsActivator; +import org.eclipse.xtext.builder.tests.internal.TestsActivatorCustom; + +import com.google.inject.Injector; + +/** + * This allows customizations in the UI, specific for some test scenarions, without creating new languages. + * + * @author Lorenzo Bettini - Initial contribution and API + */ +public class BuilderTestLanguageExecutableExtensionFactoryGH2920 extends BuilderTestLanguageExecutableExtensionFactory { + + @Override + protected Injector getInjector() { + TestsActivator activator = TestsActivator.getInstance(); + return activator != null ? activator.getInjector(TestsActivatorCustom.ORG_ECLIPSE_XTEXT_BUILDER_TESTS_BUILDERTESTLANGUAGE_GH2920) + : null; + } +}