Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

[#281] Improved interaction between Xtext builder and JDT #1156

Merged
merged 1 commit into from Aug 15, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion org.eclipse.xtext.builder.tests/META-INF/MANIFEST.MF
Expand Up @@ -34,7 +34,8 @@ Require-Bundle: org.eclipse.xtext,
org.eclipse.xtext.ui.testing,
org.eclipse.xtext.ui.codetemplates.ui,
org.eclipse.xtext.xbase.lib;bundle-version="2.14.0",
org.eclipse.compare;bundle-version="3.7.101"
org.eclipse.compare;bundle-version="3.7.101",
org.eclipse.xtext.common.types.eclipse.tests
Import-Package: org.apache.log4j;version="1.2.15",
org.eclipse.xtext.tests,
org.hamcrest.core;version="1.1.0",
Expand Down
Expand Up @@ -30,6 +30,7 @@
/**
* @author Knut Wannheden - Initial contribution and API
*/
@SuppressWarnings("restriction")
public class BuildCancellationTest extends AbstractParticipatingBuilderTest {

private OperationCanceledException cancelException;
Expand Down
Expand Up @@ -14,6 +14,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;

import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
Expand All @@ -22,6 +23,7 @@
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
Expand All @@ -36,6 +38,7 @@
import org.eclipse.xtext.resource.IReferenceDescription;
import org.eclipse.xtext.ui.XtextProjectHelper;
import org.eclipse.xtext.ui.resource.IResourceUIServiceProvider;
import org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil;
import org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile;
import org.eclipse.xtext.util.StringInputStream;
import org.junit.After;
Expand Down Expand Up @@ -209,8 +212,6 @@ protected String printMarkers(IMarker[] findMarkers) throws CoreException {
assertEquals(1, countMarkers(bar_file));
}

// TODO fix https://github.com/eclipse/xtext-eclipse/issues/400
@Ignore("TODO fix https://github.com/eclipse/xtext-eclipse/issues/400")
@Test public void testTwoFilesInTwoReferencedProjectsAddNature() throws Exception {
foo_project = createJavaProjectWithRootSrc("foo");
removeNature(foo_project.getProject(), XtextProjectHelper.NATURE_ID);
Expand Down Expand Up @@ -285,8 +286,6 @@ protected void createTwoFilesInTwoReferencedProjects() throws Exception {
assertEquals(printMarkers(bar_file), 0, countMarkers(bar_file));
}

// TODO fix https://github.com/eclipse/xtext-eclipse/issues/400
@Ignore("TODO fix https://github.com/eclipse/xtext-eclipse/issues/400")
@Test public void testChangeReferencedFile() throws Exception {
createTwoFilesInTwoReferencedProjects();

Expand All @@ -301,8 +300,6 @@ protected void createTwoFilesInTwoReferencedProjects() throws Exception {
assertEquals(0, countMarkers(bar_file));
}

// TODO fix https://github.com/eclipse/xtext-eclipse/issues/400
@Ignore("TODO fix https://github.com/eclipse/xtext-eclipse/issues/400")
@Test public void testDeleteReferencedFile() throws Exception {
createTwoFilesInTwoReferencedProjects();

Expand All @@ -317,6 +314,86 @@ protected void createTwoFilesInTwoReferencedProjects() throws Exception {
assertEquals(0, countMarkers(foo_file));
assertEquals(0, countMarkers(bar_file));
}

@SuppressWarnings("restriction")
@Test public void testBuildOrderIsCorrect() throws Exception {
foo_project = createJavaProjectWithRootSrc("foo");
bar_project = createJavaProjectWithRootSrc("bar");

org.eclipse.core.internal.resources.Workspace workspace =
(org.eclipse.core.internal.resources.Workspace) ResourcesPlugin.getWorkspace();
IBuildConfiguration[] buildOrder = workspace.getBuildOrder();
assertEquals(bar_project.getProject(), buildOrder[0].getProject());
assertEquals(foo_project.getProject(), buildOrder[1].getProject());
// add a classpath entry and a project reference
addProjectReference(bar_project, foo_project);

buildOrder = workspace.getBuildOrder();
assertEquals(foo_project.getProject(), buildOrder[0].getProject());
assertEquals(bar_project.getProject(), buildOrder[1].getProject());
}

@SuppressWarnings("restriction")
@Test public void testBuildOrderIsWrong() throws Exception {
foo_project = createJavaProjectWithRootSrc("foo");
bar_project = createJavaProjectWithRootSrc("bar");

org.eclipse.core.internal.resources.Workspace workspace =
(org.eclipse.core.internal.resources.Workspace) ResourcesPlugin.getWorkspace();
IBuildConfiguration[] buildOrder = workspace.getBuildOrder();
assertEquals(bar_project.getProject(), buildOrder[0].getProject());
assertEquals(foo_project.getProject(), buildOrder[1].getProject());
// here we do only add a classpath entry and no core.resources project reference
JavaProjectSetupUtil.addProjectReference(bar_project, foo_project);
szarnekow marked this conversation as resolved.
Show resolved Hide resolved

buildOrder = workspace.getBuildOrder();
assertEquals(bar_project.getProject(), buildOrder[0].getProject());
assertEquals(foo_project.getProject(), buildOrder[1].getProject());
}

@Test
public void testJavaChangeTriggersBuild() throws Exception {
foo_project = createJavaProject("foo");
IJavaProject zonkProject = createJavaProject("zonk");
bar_project = createJavaProjectWithRootSrc("bar");

addProjectReference(bar_project, zonkProject);
IClasspathEntry classpathEntry = JavaCore.newProjectEntry(foo_project.getPath(), true);
workspace.addToClasspath(zonkProject, classpathEntry);

IFolder javaPackage = foo_project.getProject().getFolder("src").getFolder("pack");
javaPackage.create(true, true, null);
IFile javaFile = javaPackage.getFile("Type.java");
javaFile.create(new StringInputStream("package pack; public class Type {}"), true, monitor());

IFolder dslFolder = bar_project.getProject().getFolder("src");
IFile dslFile = dslFolder.getFile("Dsl.typesAssistTest");
dslFile.create(new StringInputStream("default pack.Type"), true, monitor());

build();
assertEquals(printMarkers(dslFile), 0, countMarkers(dslFile));

javaFile.setContents(new StringInputStream("package pack; class X {}"), true, true, null);

build();
// Xtext proxy validation and EObjectValidator proxy validation
assertEquals(2, countMarkers(dslFile));

javaFile.setContents(new StringInputStream("package pack; public class Type {}"), true, true, null);

build();
assertEquals(0, countMarkers(dslFile));

workspace.removeClasspathEntry(zonkProject, classpathEntry);

build();
// Xtext proxy validation and EObjectValidator proxy validation
assertEquals(2, countMarkers(dslFile));

workspace.addToClasspath(zonkProject, classpathEntry);
build();
assertEquals(0, countMarkers(dslFile));
}

@Test public void testUpdateOfReferencedFile() throws Exception {
IJavaProject project = createJavaProject("foo");
Expand Down
Expand Up @@ -32,7 +32,6 @@
import org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile;
import org.eclipse.xtext.util.StringInputStream;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand Down Expand Up @@ -350,8 +349,6 @@ public void testReexportedSource() throws Exception {
assertEquals(BuilderTestLanguagePackage.Literals.ELEMENT__REFERENCES,next.getEReference());
}

// TODO fix https://github.com/eclipse/xtext-eclipse/issues/400
@Ignore("TODO fix https://github.com/eclipse/xtext-eclipse/issues/400")
@Test
public void testNewlyAddedReexportedSource() throws Exception {
IJavaProject foo = createJavaProject("foo");
Expand All @@ -374,8 +371,6 @@ public void testNewlyAddedReexportedSource() throws Exception {
assertEquals(0,countMarkers(bazFile));
}

// TODO fix https://github.com/eclipse/xtext-eclipse/issues/400
@Ignore("TODO fix https://github.com/eclipse/xtext-eclipse/issues/400")
@Test
public void testReexportedJarRemoved() throws Exception {
IJavaProject foo = createJavaProject("foo");
Expand Down
Expand Up @@ -7,9 +7,12 @@
*******************************************************************************/
package org.eclipse.xtext.builder.impl;

import java.util.Set;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

Expand Down Expand Up @@ -59,4 +62,17 @@ public interface IToBeBuiltComputerContribution {
* should not be processed by the Xtext builder.
*/
boolean isRejected(IFolder folder);

/**
* Add all the projects to the result, that may affect the resources in this projects.
* The XtextBuilder will return the collected set of projects as the interesting projects after
* each build round.
*
* @see IncrementalProjectBuilder#build
*
* @since 2.19
*/
default void addInterestingProjects(IProject thisProject, Set<IProject> result) {
szarnekow marked this conversation as resolved.
Show resolved Hide resolved
// per default nothing to do
}
}
Expand Up @@ -7,7 +7,10 @@
*******************************************************************************/
package org.eclipse.xtext.builder.impl;

import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
Expand All @@ -30,6 +33,7 @@
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.google.inject.Singleton;

Expand Down Expand Up @@ -154,6 +158,15 @@ public boolean isRejected(IFolder folder) {
return false;
}

/**
* @since 2.19
*/
@Override
public void addInterestingProjects(IProject thisProject, Set<IProject> result) {
for (int i = 0; i < contributions.size(); i++) {
contributions.get(i).addInterestingProjects(thisProject, result);
}
}
}

@Inject
Expand Down Expand Up @@ -358,4 +371,10 @@ protected boolean isValid(URI uri, IStorage storage) {
return uriValidator.canBuild(uri, storage);
}

protected Set<IProject> getInterestingProjects(IProject project) throws CoreException {
Set<IProject> result = new LinkedHashSet<>(Arrays.asList(project.getReferencedProjects()));
contribution.addInterestingProjects(project, result);
return result;
}

}