-
Notifications
You must be signed in to change notification settings - Fork 320
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d8c30d1
Inconsistent handling of files in an output folder - full vs.
stephan-herrmann b41d4c4
Test case that "almost" demonstrates the problem
stephan-herrmann 5ee75f0
Recreated test for the issue https://github.com/eclipse/xtext/issues/…
LorenzoBettini 4b43a21
Modify the test customization to be even closer to the original problem
stephan-herrmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
org.eclipse.xtext.builder.tests/src/org/eclipse/xtext/builder/impl/GH2920Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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", " ", ""))); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...text.builder.tests/src/org/eclipse/xtext/builder/tests/internal/TestsActivatorCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...g/eclipse/xtext/builder/tests/ui/BuilderTestLanguageExecutableExtensionFactoryGH2920.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 withoutDefaultResourceUIServiceProvider
.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...