Search in sources :

Example 6 with BuildRequest

use of org.eclipse.xtext.build.BuildRequest in project xtext-core by eclipse.

the class IncrementalBuilderTest method testSimpleFullBuild.

@Test
public void testSimpleFullBuild() {
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("entity B {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("entity A { foo.B myReference }");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        URI _minus = this.operator_minus("src/MyFile.indextestlanguage", _builder.toString());
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus)));
    };
    final BuildRequest buildRequest = this.newBuildRequest(_function);
    this.build(buildRequest);
    Assert.assertTrue(this.issues.toString(), this.issues.isEmpty());
    Assert.assertEquals(2, this.generated.size());
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "src-gen/B.txt"));
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "src-gen/A.txt"));
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) AbstractIncrementalBuilderTest(org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest) Test(org.junit.Test)

Example 7 with BuildRequest

use of org.eclipse.xtext.build.BuildRequest in project xtext-core by eclipse.

the class IncrementalBuilderTest method testDelete_01.

@Test
public void testDelete_01() {
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("entity A {foo.B references}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        URI _minus = this.operator_minus("src/A.indextestlanguage", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("foo {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("entity B");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        URI _minus_1 = this.operator_minus("src/B.indextestlanguage", _builder_1.toString());
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus, _minus_1)));
    };
    this.build(this.newBuildRequest(_function));
    final AtomicBoolean validateCalled = new AtomicBoolean(false);
    final Procedure1<BuildRequest> _function_1 = (BuildRequest it) -> {
        URI _uri = this.uri("src/B.indextestlanguage");
        it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_uri)));
        final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
            Assert.assertEquals(this.uri("src/A.indextestlanguage"), uri);
            Assert.assertTrue(issues.toString(), IterableExtensions.<Issue>head(issues).getMessage().contains("Couldn\'t resolve reference to Type \'foo.B\'"));
            validateCalled.set(true);
            return false;
        };
        it.setAfterValidate(_function_2);
    };
    this.build(this.newBuildRequest(_function_1));
    Assert.assertTrue(validateCalled.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) AbstractIncrementalBuilderTest(org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest) Test(org.junit.Test)

Example 8 with BuildRequest

use of org.eclipse.xtext.build.BuildRequest in project xtext-core by eclipse.

the class IncrementalBuilderTest method testCancellation.

@Test(expected = OperationCanceledException.class)
public void testCancellation() {
    final IncrementalBuilderTest.CancelOnFirstModel cancelOnFirstModel = new IncrementalBuilderTest.CancelOnFirstModel();
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("entity A { foo.B myReference }");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        URI _minus = this.operator_minus("src/MyFile.indextestlanguage", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("foo {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("entity B {}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        URI _minus_1 = this.operator_minus("src/MyFile2.indextestlanguage", _builder_1.toString());
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus, _minus_1)));
        it.setCancelIndicator(cancelOnFirstModel);
        it.setAfterValidate(cancelOnFirstModel);
    };
    final BuildRequest buildRequest = this.newBuildRequest(_function);
    this.build(buildRequest);
}
Also used : AbstractIncrementalBuilderTest(org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) AbstractIncrementalBuilderTest(org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest) Test(org.junit.Test)

Example 9 with BuildRequest

use of org.eclipse.xtext.build.BuildRequest in project xtext-core by eclipse.

the class IncrementalBuilderTest method testDeleteClearsReusedResourceSet.

@Test
public void testDeleteClearsReusedResourceSet() {
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("foo {");
        _builder.newLine();
        _builder.append("    ");
        _builder.append("entity A {foo.B references}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        URI _minus = this.operator_minus("src/A.indextestlanguage", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("foo {");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("entity B");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        URI _minus_1 = this.operator_minus("src/B.indextestlanguage", _builder_1.toString());
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus, _minus_1)));
    };
    final BuildRequest req = this.newBuildRequest(_function);
    final XtextResourceSet resourceSet = req.getResourceSet();
    this.build(req);
    final AtomicBoolean validateCalled = new AtomicBoolean(false);
    final Procedure1<BuildRequest> _function_1 = (BuildRequest it) -> {
        URI _uri = this.uri("src/B.indextestlanguage");
        it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_uri)));
        final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
            Assert.assertEquals(this.uri("src/A.indextestlanguage"), uri);
            String _string = issues.toString();
            Assert.assertTrue(_string, ((!IterableExtensions.isEmpty(issues)) && IterableExtensions.<Issue>head(issues).getMessage().contains("Couldn\'t resolve reference to Type \'foo.B\'")));
            validateCalled.set(true);
            return false;
        };
        it.setAfterValidate(_function_2);
        it.setResourceSet(resourceSet);
        final ChunkedResourceDescriptions desc = ChunkedResourceDescriptions.findInEmfObject(it.getResourceSet());
        desc.setContainer("test-project", it.getState().getResourceDescriptions());
    };
    this.build(this.newBuildRequest(_function_1));
    Assert.assertTrue(validateCalled.get());
    Assert.assertNull(resourceSet.getResource(this.uri("src/B.indextestlanguage"), false));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) AbstractIncrementalBuilderTest(org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest) Test(org.junit.Test)

Example 10 with BuildRequest

use of org.eclipse.xtext.build.BuildRequest in project xtext-xtend by eclipse.

the class XtendIncrementalBuilderTest method testIncrementalBuild.

@Test
public void testIncrementalBuild() {
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class A extends B {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        URI _minus = this.operator_minus("src/A.xtend", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("class B { ");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("public A myReference");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        URI _minus_1 = this.operator_minus("src/B.xtend", _builder_1.toString());
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus, _minus_1)));
    };
    this.build(this.newBuildRequest(_function));
    Assert.assertTrue(this.issues.toString(), this.issues.isEmpty());
    Assert.assertEquals(4, this.generated.size());
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/B.java"));
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/A.java"));
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/.B.java._trace"));
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/.A.java._trace"));
    final Procedure1<BuildRequest> _function_1 = (BuildRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("// some comment");
        _builder.newLine();
        _builder.append("class A extends B { }");
        _builder.newLine();
        URI _minus = this.operator_minus("src/A.xtend", _builder.toString());
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus)));
    };
    this.build(this.newBuildRequest(_function_1));
    Assert.assertTrue(this.issues.toString(), this.issues.isEmpty());
    Assert.assertEquals(4, this.generated.size());
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/B.java"));
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/A.java"));
    final Procedure1<BuildRequest> _function_2 = (BuildRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class X extends B { }");
        _builder.newLine();
        URI _minus = this.operator_minus("src/A.xtend", _builder.toString());
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus)));
    };
    this.build(this.newBuildRequest(_function_2));
    Assert.assertEquals(this.issues.toString(), 1, this.issues.size());
    Assert.assertEquals(2, this.generated.size());
    Assert.assertFalse(this.containsSuffix(this.generated.values(), "xtend-gen/B.java"));
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/X.java"));
    Assert.assertTrue(IterableExtensions.<URI>toSet(this.indexState.getFileMappings().getGenerated(this.uri("src/A.xtend"))).contains(this.uri("xtend-gen/X.java")));
    Assert.assertEquals(2, this.deleted.size());
    Assert.assertTrue(this.containsSuffix(this.deleted, "xtend-gen/A.java"));
    Assert.assertTrue(this.containsSuffix(this.deleted, "xtend-gen/.A.java._trace"));
    final Procedure1<BuildRequest> _function_3 = (BuildRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class A extends B {\t}");
        _builder.newLine();
        URI _minus = this.operator_minus("src/A.xtend", _builder.toString());
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus)));
    };
    this.build(this.newBuildRequest(_function_3));
    Assert.assertTrue(this.issues.toString(), this.issues.isEmpty());
    Assert.assertEquals(4, this.generated.size());
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/B.java"));
    Assert.assertTrue(this.containsSuffix(this.generated.values(), "xtend-gen/A.java"));
    Assert.assertTrue(this.containsSuffix(this.deleted, "xtend-gen/X.java"));
    final Procedure1<BuildRequest> _function_4 = (BuildRequest it) -> {
        URI _delete = this.delete(this.uri("src/A.xtend"));
        it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_delete)));
    };
    this.build(this.newBuildRequest(_function_4));
    Assert.assertEquals(this.issues.toString(), 1, this.issues.size());
    Assert.assertEquals(0, this.generated.size());
    Assert.assertEquals(2, this.deleted.size());
    Assert.assertTrue(this.containsSuffix(this.deleted, "xtend-gen/A.java"));
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) AbstractIncrementalBuilderTest(org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest) Test(org.junit.Test)

Aggregations

URI (org.eclipse.emf.common.util.URI)24 BuildRequest (org.eclipse.xtext.build.BuildRequest)24 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)20 AbstractIncrementalBuilderTest (org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest)20 Test (org.junit.Test)20 IndexState (org.eclipse.xtext.build.IndexState)4 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)4 Procedure2 (org.eclipse.xtext.xbase.lib.Procedures.Procedure2)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Source2GeneratedMapping (org.eclipse.xtext.build.Source2GeneratedMapping)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 ChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions)3 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)3 Issue (org.eclipse.xtext.validation.Issue)3 URIHandler (org.eclipse.emf.ecore.resource.URIHandler)2 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)2 ProjectDescription (org.eclipse.xtext.resource.impl.ProjectDescription)2 IncrementalBuilder (org.eclipse.xtext.build.IncrementalBuilder)1 InMemoryURIHandler (org.eclipse.xtext.junit4.util.InMemoryURIHandler)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1