Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent handling of files in an output folder - full vs. incremental build #2921

Merged
merged 4 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2024 GK Software SE 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.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;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.xtext.resource.IResourceDescriptions;
import org.eclipse.xtext.resource.IResourceDescriptionsProvider;
import org.eclipse.xtext.ui.XtextProjectHelper;
import org.eclipse.xtext.util.StringInputStream;
import org.junit.Before;
import org.junit.Test;

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");
addNature(javaProject.getProject(), XtextProjectHelper.NATURE_ID);
build();
}

@Override
public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephan-herrmann This test is not sufficient to validate that the fix actually fixes something. It's green when I run this on main. Do you plan to augment it somehow or would you like to merge this branch as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you seen this comment?

In essence we'd need an environment with XtextBuilder but without DefaultResourceUIServiceProvider.

I can confirm that one of our tests, which uses DefaultResourceServiceProvider instead, does trigger the problem. Do you want me to construct such a test for xtext? It looked like that would need jumping through some hoops.

That's why I was uncertain whether we should actually pursue this further...

IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(context.getResourceSet());
resourceDescriptions.getAllResourceDescriptions().forEach(
rd -> {
String uriString = rd.getURI().toString();
if (uriString.contains("bin"))
descriptionsInOutputFolder.add(uriString);
});
super.build(context, monitor);
}

@Test
public void testIncremental() throws Exception {
IProject project = javaProject.getProject();
createSomeBuilderRelatedFile(project, "Foo");
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 + "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,85 @@
/*******************************************************************************
* 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.core.resources.IStorage;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.xtext.Constants;
import org.eclipse.xtext.builder.tests.BuilderTestLanguageRuntimeModule;
import org.eclipse.xtext.builder.tests.ui.BuilderTestLanguageUiModule;
import org.eclipse.xtext.resource.impl.DefaultResourceServiceProvider;
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
import org.eclipse.xtext.ui.resource.IResourceUIServiceProvider;

import com.google.inject.Binder;
import com.google.inject.Module;
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) {
/**
* {@link IResourceUIServiceProvider} specifies its default implementation to be {@link org.eclipse.xtext.ui.resource.DefaultResourceUIServiceProvider}
* with no explicit binding in any module, so we can customize the binding here.
*/
@SuppressWarnings("unused")
public Class<? extends IResourceUIServiceProvider> bindIResourceUIServiceProvider() {
return ResourceNonUIServiceProvider.class;
}
};
return super.getUiModule(grammar);
}
/** A provider that essentially mimics the behavior of {@link DefaultResourceServiceProvider} in the guise of a {@link IResourceUIServiceProvider}. */
static class ResourceNonUIServiceProvider extends DefaultResourceServiceProvider implements IResourceUIServiceProvider {
@Override
public ILabelProvider getLabelProvider() {
return null;
}
@Override
public boolean canHandle(URI uri, IStorage storage) {
// if we wouldn't implement IResourceUIServiceProvider then this method would be invoked in the first place:
return canHandle(uri);
}
@Override
public IURIEditorOpener getURIEditorOpener() {
return null;
}
@SuppressWarnings({ "deprecation", "restriction" })
@Override
public org.eclipse.xtext.ui.refactoring.IReferenceUpdater getReferenceUpdater() {
return null;
}
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;

import org.apache.log4j.Logger;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
Expand Down Expand Up @@ -588,6 +589,8 @@ public boolean visit(IResourceDelta delta) throws CoreException {
} else if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) {
return toBeBuiltComputer.updateStorage(null, toBeBuilt, (IStorage) delta.getResource());
}
} else if (delta.getResource() instanceof IFolder) {
return toBeBuiltComputer.isHandled((IFolder) delta.getResource());
}
return true;
}
Expand Down
Loading