Skip to content

Commit

Permalink
Recreated test for the issue eclipse-xtext#2920 (#1)
Browse files Browse the repository at this point in the history
Test case that effectively demonstrates the problem

the customization happens at the level of the executable extension
factory
  • Loading branch information
LorenzoBettini authored Feb 3, 2024
1 parent b41d4c4 commit 5ee75f0
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 7 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.xtext.builder.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions org.eclipse.xtext.builder.tests/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,31 @@
type="buildertestlanguage">
</parser>
</extension>
<extension
point="org.eclipse.emf.ecore.extension_parser">
<parser
class="org.eclipse.xtext.builder.tests.ui.BuilderTestLanguageExecutableExtensionFactoryGH2920:org.eclipse.xtext.resource.IResourceFactory"
type="buildertestlanguageGH2920">
</parser>
</extension>
<extension point="org.eclipse.xtext.extension_resourceServiceProvider">
<resourceServiceProvider
class="org.eclipse.xtext.builder.tests.ui.BuilderTestLanguageExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
uriExtension="buildertestlanguage">
</resourceServiceProvider>
</extension>
<extension point="org.eclipse.xtext.extension_resourceServiceProvider">
<resourceServiceProvider
class="org.eclipse.xtext.builder.tests.ui.BuilderTestLanguageExecutableExtensionFactoryGH2920:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
uriExtension="buildertestlanguageGH2920">
</resourceServiceProvider>
</extension>
<extension point="org.eclipse.xtext.builder.participant">
<participant
class="org.eclipse.xtext.builder.tests.ui.BuilderTestLanguageExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant"/>
</extension>
<extension point="org.eclipse.xtext.builder.participant">
<participant
class="org.eclipse.xtext.builder.tests.ui.BuilderTestLanguageExecutableExtensionFactoryGH2920:org.eclipse.xtext.builder.IXtextBuilderParticipant"/>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> descriptionsInOutputFolder = new ArrayList<>();

@Before
public void createProjectUnderTest() throws Exception {
javaProject = createJavaProject("NoResourceFromOutput");
Expand All @@ -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);
}

Expand All @@ -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", " ", "")));
}
}
Original file line number Diff line number Diff line change
@@ -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<IJdtHelper> provideJdtHelper() {
return new Provider<>() {
@Override
public IJdtHelper get() {
return new JdtHelper() {
@Override
protected boolean computeJavaCoreAvailable() {
return false;
}
};
}
};
}
};
return super.getUiModule(grammar);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 5ee75f0

Please sign in to comment.