Search in sources :

Example 1 with JUnitVersion

use of org.eclipse.xtext.util.JUnitVersion in project xtext-core by eclipse.

the class JUnitFragment method generateExampleRuntimeTest.

protected JavaFileAccess generateExampleRuntimeTest() {
    String _testingPackage = this.getTestingPackage();
    String _plus = (_testingPackage + ".XtextRunner");
    final TypeReference xtextRunner = new TypeReference(_plus);
    final TypeReference runWith = new TypeReference("org.junit.runner.RunWith");
    String _testingPackage_1 = this.getTestingPackage();
    String _plus_1 = (_testingPackage_1 + ".InjectWith");
    final TypeReference injectWith = new TypeReference(_plus_1);
    final TypeReference extendWith = new TypeReference("org.junit.jupiter.api.^extension.ExtendWith");
    final TypeReference injectionExtension = new TypeReference("org.eclipse.xtext.testing.extensions.InjectionExtension");
    String _testingPackage_2 = this.getTestingPackage();
    String _plus_2 = (_testingPackage_2 + ".util.ParseHelper");
    final TypeReference parseHelper = new TypeReference(_plus_2);
    TypeReference _switchResult = null;
    final JUnitVersion junitVersion = this.junitVersion;
    if (junitVersion != null) {
        switch(junitVersion) {
            case JUNIT_4:
                _switchResult = new TypeReference("org.junit.Test");
                break;
            case JUNIT_5:
                _switchResult = new TypeReference("org.junit.jupiter.api.Test");
                break;
            default:
                break;
        }
    }
    final TypeReference test = _switchResult;
    TypeReference _switchResult_1 = null;
    final JUnitVersion junitVersion_1 = this.junitVersion;
    if (junitVersion_1 != null) {
        switch(junitVersion_1) {
            case JUNIT_4:
                _switchResult_1 = new TypeReference("org.junit.Assert");
                break;
            case JUNIT_5:
                _switchResult_1 = new TypeReference("org.junit.jupiter.api.Assertions");
                break;
            default:
                break;
        }
    }
    final TypeReference assert_ = _switchResult_1;
    EClassifier _classifier = IterableExtensions.<AbstractRule>head(this.getGrammar().getRules()).getType().getClassifier();
    ResourceSet _resourceSet = this.getGrammar().eResource().getResourceSet();
    final TypeReference rootType = new TypeReference(((EClass) _classifier), _resourceSet);
    TypeReference _exampleRuntimeTest = this.exampleRuntimeTest();
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            {
                boolean _equals = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_4);
                if (_equals) {
                    _builder.append("@");
                    _builder.append(runWith);
                    _builder.append("(");
                    _builder.append(xtextRunner);
                    _builder.append(")");
                    _builder.newLineIfNotEmpty();
                }
            }
            {
                boolean _equals_1 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_5);
                if (_equals_1) {
                    _builder.append("@");
                    _builder.append(extendWith);
                    _builder.append("(");
                    _builder.append(injectionExtension);
                    _builder.append(")");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("@");
            _builder.append(injectWith);
            _builder.append("(");
            TypeReference _injectorProvider = JUnitFragment.this.injectorProvider();
            _builder.append(_injectorProvider);
            _builder.append(")");
            _builder.newLineIfNotEmpty();
            _builder.append("class ");
            TypeReference _exampleRuntimeTest = JUnitFragment.this.exampleRuntimeTest();
            _builder.append(_exampleRuntimeTest);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(parseHelper, "\t");
            _builder.append("<");
            _builder.append(rootType, "\t");
            _builder.append("> parseHelper");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(test, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("def void loadModel() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("val result = parseHelper.parse(\'\'");
            _builder.append("\'");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("Hello Xtext!");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\'\'");
            _builder.append("\')");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append(assert_, "\t\t");
            _builder.append(".assertNotNull(result)");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("val errors = result.eResource.errors");
            _builder.newLine();
            {
                boolean _equals_2 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_4);
                if (_equals_2) {
                    _builder.append("\t\t");
                    _builder.append(assert_, "\t\t");
                    _builder.append(".assertTrue(\'\'");
                    _builder.append("\'Unexpected errors: ");
                    _builder.append("�", "\t\t");
                    _builder.append("errors.join(\", \")");
                    _builder.append("�", "\t\t");
                    _builder.append("\'\'");
                    _builder.append("\', errors.isEmpty)");
                    _builder.newLineIfNotEmpty();
                }
            }
            {
                boolean _equals_3 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_5);
                if (_equals_3) {
                    _builder.append("\t\t");
                    _builder.append(assert_, "\t\t");
                    _builder.append(".assertTrue(errors.isEmpty, \'\'");
                    _builder.append("\'Unexpected errors: ");
                    _builder.append("�", "\t\t");
                    _builder.append("errors.join(\", \")");
                    _builder.append("�", "\t\t");
                    _builder.append("\'\'");
                    _builder.append("\')");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createXtendFile(_exampleRuntimeTest, _client);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) JUnitVersion(org.eclipse.xtext.util.JUnitVersion) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EClassifier(org.eclipse.emf.ecore.EClassifier) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 2 with JUnitVersion

use of org.eclipse.xtext.util.JUnitVersion in project xtext-core by eclipse.

the class JUnitFragment method generateJavaExampleRuntimeTest.

protected JavaFileAccess generateJavaExampleRuntimeTest() {
    String _testingPackage = this.getTestingPackage();
    String _plus = (_testingPackage + ".XtextRunner");
    final TypeReference xtextRunner = new TypeReference(_plus);
    final TypeReference runWith = new TypeReference("org.junit.runner.RunWith");
    final TypeReference extendWith = new TypeReference("org.junit.jupiter.api.extension.ExtendWith");
    final TypeReference injectionExtension = new TypeReference("org.eclipse.xtext.testing.extensions.InjectionExtension");
    String _testingPackage_1 = this.getTestingPackage();
    String _plus_1 = (_testingPackage_1 + ".InjectWith");
    final TypeReference injectWith = new TypeReference(_plus_1);
    String _testingPackage_2 = this.getTestingPackage();
    String _plus_2 = (_testingPackage_2 + ".util.ParseHelper");
    final TypeReference parseHelper = new TypeReference(_plus_2);
    TypeReference _switchResult = null;
    final JUnitVersion junitVersion = this.junitVersion;
    if (junitVersion != null) {
        switch(junitVersion) {
            case JUNIT_4:
                _switchResult = new TypeReference("org.junit.Test");
                break;
            case JUNIT_5:
                _switchResult = new TypeReference("org.junit.jupiter.api.Test");
                break;
            default:
                break;
        }
    }
    final TypeReference test = _switchResult;
    TypeReference _switchResult_1 = null;
    final JUnitVersion junitVersion_1 = this.junitVersion;
    if (junitVersion_1 != null) {
        switch(junitVersion_1) {
            case JUNIT_4:
                _switchResult_1 = new TypeReference("org.junit.Assert");
                break;
            case JUNIT_5:
                _switchResult_1 = new TypeReference("org.junit.jupiter.api.Assertions");
                break;
            default:
                break;
        }
    }
    final TypeReference assert_ = _switchResult_1;
    EClassifier _classifier = IterableExtensions.<AbstractRule>head(this.getGrammar().getRules()).getType().getClassifier();
    ResourceSet _resourceSet = this.getGrammar().eResource().getResourceSet();
    final TypeReference rootType = new TypeReference(((EClass) _classifier), _resourceSet);
    final TypeReference list = new TypeReference("java.util.List");
    final TypeReference diagnostic = new TypeReference("org.eclipse.emf.ecore.resource", "Resource.Diagnostic");
    final TypeReference iterableExtensions = new TypeReference("org.eclipse.xtext.xbase.lib.IterableExtensions");
    TypeReference _exampleRuntimeTest = this.exampleRuntimeTest();
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            {
                boolean _equals = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_4);
                if (_equals) {
                    _builder.append("@");
                    _builder.append(runWith);
                    _builder.append("(");
                    _builder.append(xtextRunner);
                    _builder.append(".class)");
                    _builder.newLineIfNotEmpty();
                }
            }
            {
                boolean _equals_1 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_5);
                if (_equals_1) {
                    _builder.append("@");
                    _builder.append(extendWith);
                    _builder.append("(");
                    _builder.append(injectionExtension);
                    _builder.append(".class)");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("@");
            _builder.append(injectWith);
            _builder.append("(");
            TypeReference _injectorProvider = JUnitFragment.this.injectorProvider();
            _builder.append(_injectorProvider);
            _builder.append(".class)");
            _builder.newLineIfNotEmpty();
            _builder.append("public class ");
            TypeReference _exampleRuntimeTest = JUnitFragment.this.exampleRuntimeTest();
            _builder.append(_exampleRuntimeTest);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("private ");
            _builder.append(parseHelper, "\t");
            _builder.append("<");
            _builder.append(rootType, "\t");
            _builder.append("> parseHelper;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(test, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("public void loadModel() throws Exception {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("Model result = parseHelper.parse(\"Hello Xtext!\");");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append(assert_, "\t\t");
            _builder.append(".assertNotNull(result);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append(list, "\t\t");
            _builder.append("<");
            _builder.append(diagnostic, "\t\t");
            _builder.append("> errors = result.eResource().getErrors();");
            _builder.newLineIfNotEmpty();
            {
                boolean _equals_2 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_4);
                if (_equals_2) {
                    _builder.append("\t\t");
                    _builder.append(assert_, "\t\t");
                    _builder.append(".assertTrue(\"Unexpected errors: \" + ");
                    _builder.append(iterableExtensions, "\t\t");
                    _builder.append(".join(errors, \", \"), errors.isEmpty());");
                    _builder.newLineIfNotEmpty();
                }
            }
            {
                boolean _equals_3 = Objects.equal(JUnitFragment.this.junitVersion, JUnitVersion.JUNIT_5);
                if (_equals_3) {
                    _builder.append("\t\t");
                    _builder.append(assert_, "\t\t");
                    _builder.append(".assertTrue(errors.isEmpty(), \"Unexpected errors: \" + ");
                    _builder.append(iterableExtensions, "\t\t");
                    _builder.append(".join(errors, \", \"));");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_exampleRuntimeTest, _client);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) JUnitVersion(org.eclipse.xtext.util.JUnitVersion) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EClassifier(org.eclipse.emf.ecore.EClassifier) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 3 with JUnitVersion

use of org.eclipse.xtext.util.JUnitVersion in project xtext-core by eclipse.

the class TargetPlatformProject method target.

public CharSequence target() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
    _builder.newLine();
    _builder.append("<?pde version=\"3.8\"?>");
    _builder.newLine();
    _builder.append("<target name=\"");
    String _name = this.getName();
    _builder.append(_name);
    _builder.append("\" sequenceNumber=\"1\">");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("<locations>");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("<location includeAllPlatforms=\"false\" includeConfigurePhase=\"false\" includeMode=\"planner\" includeSource=\"true\" type=\"InstallableUnit\">");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("<unit id=\"org.eclipse.jdt.feature.group\" version=\"0.0.0\"/>");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("<unit id=\"org.eclipse.platform.feature.group\" version=\"0.0.0\"/>");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("<unit id=\"org.eclipse.pde.feature.group\" version=\"0.0.0\"/>");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("<unit id=\"org.eclipse.draw2d.feature.group\" version=\"0.0.0\"/>");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("<unit id=\"org.eclipse.emf.sdk.feature.group\" version=\"0.0.0\"/>");
    _builder.newLine();
    {
        boolean _isAtLeast = this.getConfig().getJavaVersion().isAtLeast(JavaVersion.JAVA11);
        if (_isAtLeast) {
            _builder.append("\t\t\t");
            _builder.append("<repository location=\"https://download.eclipse.org/releases/2022-03\"/>");
            _builder.newLine();
        } else {
            _builder.append("\t\t\t");
            _builder.append("<!-- newer Eclipse versions need Java 11 to run the Maven Tycho build -->");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("<repository location=\"https://download.eclipse.org/releases/2020-06\"/>");
            _builder.newLine();
        }
    }
    _builder.append("\t\t");
    _builder.append("</location>");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("<location includeAllPlatforms=\"false\" includeConfigurePhase=\"false\" includeMode=\"planner\" includeSource=\"true\" type=\"InstallableUnit\">");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("<unit id=\"org.eclipse.emf.mwe2.launcher.feature.group\" version=\"0.0.0\"/>");
    _builder.newLine();
    {
        boolean _matches = this.getConfig().getXtextVersion().getMweVersion().matches("\\d+\\.\\d+(\\.\\d+)+");
        if (_matches) {
            _builder.append("\t\t\t");
            _builder.append("<repository location=\"https://download.eclipse.org/modeling/emft/mwe/updates/releases/");
            String _mweVersion = this.getConfig().getXtextVersion().getMweVersion();
            _builder.append(_mweVersion, "\t\t\t");
            _builder.append("/\"/>");
            _builder.newLineIfNotEmpty();
        } else {
            _builder.append("\t\t\t");
            _builder.append("<repository location=\"https://download.eclipse.org/modeling/emft/mwe/updates/milestones/");
            String _mweBuildNumber = this.getConfig().getXtextVersion().getMweBuildNumber();
            _builder.append(_mweBuildNumber, "\t\t\t");
            _builder.append("/\"/>");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t\t");
    _builder.append("</location>");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("<location includeAllPlatforms=\"false\" includeConfigurePhase=\"false\" includeMode=\"planner\" includeSource=\"true\" type=\"InstallableUnit\">");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("<unit id=\"org.eclipse.xtext.sdk.feature.group\" version=\"0.0.0\"/>");
    _builder.newLine();
    {
        boolean _isSnapshot = this.getConfig().getXtextVersion().isSnapshot();
        if (_isSnapshot) {
            _builder.append("\t\t\t");
            _builder.append("<repository location=\"https://download.eclipse.org/modeling/tmf/xtext/updates/nightly/\"/>");
            _builder.newLine();
        } else {
            boolean _isStable = this.getConfig().getXtextVersion().isStable();
            if (_isStable) {
                _builder.append("\t\t\t");
                _builder.append("<repository location=\"https://download.eclipse.org/modeling/tmf/xtext/updates/milestones/\"/>");
                _builder.newLine();
            } else {
                _builder.append("\t\t\t");
                _builder.append("<repository location=\"https://download.eclipse.org/modeling/tmf/xtext/updates/releases/");
                XtextVersion _xtextVersion = this.getConfig().getXtextVersion();
                _builder.append(_xtextVersion, "\t\t\t");
                _builder.append("/\"/>");
                _builder.newLineIfNotEmpty();
            }
        }
    }
    _builder.append("\t\t");
    _builder.append("</location>");
    _builder.newLine();
    {
        boolean _isAtLeast_1 = this.getConfig().getJavaVersion().isAtLeast(JavaVersion.JAVA11);
        if (_isAtLeast_1) {
            _builder.append("\t\t");
            _builder.append("<location includeAllPlatforms=\"false\" includeConfigurePhase=\"false\" includeMode=\"planner\" includeSource=\"true\" type=\"InstallableUnit\">");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"com.google.gson\" version=\"2.8.9.v20220111-1409\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"com.google.inject\" version=\"5.0.1.v20210324-2015\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"javax.inject\" version=\"1.0.0.v20091030\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"org.antlr.runtime\" version=\"3.2.0.v201101311130\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"org.junit\" version=\"4.13.2.v20211018-1956\"/>");
            _builder.newLine();
            {
                JUnitVersion _junitVersion = this.getConfig().getJunitVersion();
                boolean _equals = Objects.equal(_junitVersion, JUnitVersion.JUNIT_5);
                if (_equals) {
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.apiguardian\" version=\"1.1.2.v20211018-1956\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.jupiter.api\" version=\"5.8.1.v20211018-1956\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.jupiter.engine\" version=\"5.8.1.v20211018-1956\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.commons\" version=\"1.8.1.v20211018-1956\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.engine\" version=\"1.8.1.v20211018-1956\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.launcher\" version=\"1.8.1.v20211018-1956\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.runner\" version=\"1.8.1.v20211018-1956\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.suite.commons\" version=\"1.8.1.v20211018-1956\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.opentest4j\" version=\"1.2.0.v20211018-1956\"/>");
                    _builder.newLine();
                }
            }
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"org.objectweb.asm\" version=\"9.2.0.v20210813-1119\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"org.objectweb.asm.tree\" version=\"9.2.0.v20210813-1119\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"io.github.classgraph\" version=\"4.8.138.v20211212-1642\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<repository location=\"https://download.eclipse.org/tools/orbit/downloads/2022-03\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("</location>");
            _builder.newLine();
        } else {
            _builder.append("\t\t");
            _builder.append("<location includeAllPlatforms=\"false\" includeConfigurePhase=\"false\" includeMode=\"planner\" includeSource=\"true\" type=\"InstallableUnit\">");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"com.google.gson\" version=\"2.8.9.v20220111-1409\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"com.google.inject\" version=\"5.0.1.v20210324-2015\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"javax.inject\" version=\"1.0.0.v20091030\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"org.antlr.runtime\" version=\"3.2.0.v201101311130\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"org.junit\" version=\"4.12.0.v201504281640\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"org.objectweb.asm\" version=\"9.2.0.v20210813-1119\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"org.objectweb.asm.tree\" version=\"9.2.0.v20210813-1119\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<unit id=\"io.github.classgraph\" version=\"4.8.138.v20211212-1642\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("<repository location=\"https://download.eclipse.org/tools/orbit/downloads/2022-03\"/>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("</location>");
            _builder.newLine();
            {
                JUnitVersion _junitVersion_1 = this.getConfig().getJunitVersion();
                boolean _equals_1 = Objects.equal(_junitVersion_1, JUnitVersion.JUNIT_5);
                if (_equals_1) {
                    _builder.append("\t\t");
                    _builder.append("<location includeAllPlatforms=\"false\" includeConfigurePhase=\"false\" includeMode=\"planner\" includeSource=\"true\" type=\"InstallableUnit\">");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.jupiter.api\" version=\"5.7.1.v20210222-1948\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.jupiter.engine\" version=\"5.7.1.v20210222-1948\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.commons\" version=\"1.7.1.v20210222-1948\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.engine\" version=\"1.7.1.v20210222-1948\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.launcher\" version=\"1.7.1.v20210222-1948\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.junit.platform.runner\" version=\"1.7.1.v20210222-1948\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<unit id=\"org.opentest4j\" version=\"1.2.0.v20190826-0900\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("<repository location=\"https://download.eclipse.org/tools/orbit/downloads/2021-09\"/>");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("</location>");
                    _builder.newLine();
                }
            }
        }
    }
    _builder.append("\t");
    _builder.append("</locations>");
    _builder.newLine();
    _builder.append("</target>");
    _builder.newLine();
    return _builder;
}
Also used : JUnitVersion(org.eclipse.xtext.util.JUnitVersion) XtextVersion(org.eclipse.xtext.util.XtextVersion) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 4 with JUnitVersion

use of org.eclipse.xtext.util.JUnitVersion in project xtext-core by eclipse.

the class RuntimeProjectDescriptor method workflow.

public CharSequence workflow() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("module ");
    String _basePackagePath = this.getConfig().getLanguage().getBasePackagePath();
    String _plus = (_basePackagePath + "/Generate");
    String _simpleName = this.getConfig().getLanguage().getSimpleName();
    String _replaceAll = (_plus + _simpleName).replaceAll("/", ".");
    _builder.append(_replaceAll);
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.xtext.generator.*");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.xtext.generator.model.project.*");
    _builder.newLine();
    _builder.newLine();
    _builder.append("var rootPath = \"..\"");
    _builder.newLine();
    _builder.newLine();
    _builder.append("Workflow {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("component = XtextGenerator {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("configuration = {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("project = StandardProjectConfig {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("baseName = \"");
    String _name = this.getName();
    _builder.append(_name, "\t\t\t\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t\t");
    _builder.append("rootPath = rootPath");
    _builder.newLine();
    {
        boolean _isEnabled = this.testProject.isEnabled();
        if (_isEnabled) {
            _builder.append("\t\t\t\t");
            _builder.append("runtimeTest = {");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("\t");
            _builder.append("enabled = true");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    {
        if ((this.getConfig().getIdeProject().isEnabled() && (!IterableExtensions.exists(Collections.<ProjectDescriptor>unmodifiableList(CollectionLiterals.<ProjectDescriptor>newArrayList(this.getConfig().getWebProject(), this.getConfig().getUiProject())), ((Function1<ProjectDescriptor, Boolean>) (ProjectDescriptor it) -> {
            return Boolean.valueOf(it.isEnabled());
        }))))) {
            _builder.append("\t\t\t\t");
            _builder.append("genericIde = {");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("\t");
            _builder.append("enabled = true");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    {
        boolean _isEnabled_1 = this.getConfig().getUiProject().isEnabled();
        if (_isEnabled_1) {
            _builder.append("\t\t\t\t");
            _builder.append("eclipsePlugin = {");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("\t");
            _builder.append("enabled = true");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    {
        boolean _isEnabled_2 = this.getConfig().getUiProject().getTestProject().isEnabled();
        if (_isEnabled_2) {
            _builder.append("\t\t\t\t");
            _builder.append("eclipsePluginTest = {");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("\t");
            _builder.append("enabled = true");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    {
        boolean _isEnabled_3 = this.getConfig().getWebProject().isEnabled();
        if (_isEnabled_3) {
            _builder.append("\t\t\t\t");
            _builder.append("web = {");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("\t");
            _builder.append("enabled = true");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    {
        SourceLayout _sourceLayout = this.getConfig().getSourceLayout();
        boolean _equals = Objects.equal(_sourceLayout, SourceLayout.MAVEN);
        if (_equals) {
            _builder.append("\t\t\t\t");
            _builder.append("mavenLayout = true");
            _builder.newLine();
        }
    }
    {
        boolean _isEclipsePluginProject = this.isEclipsePluginProject();
        if (_isEclipsePluginProject) {
            _builder.append("\t\t\t\t");
            _builder.append("createEclipseMetaData = true");
            _builder.newLine();
        }
    }
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("code = {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("encoding = \"");
    Charset _encoding = this.getConfig().getEncoding();
    _builder.append(_encoding, "\t\t\t\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t\t");
    _builder.append("lineDelimiter = \"");
    String _convertToJavaString = Strings.convertToJavaString(this.getConfig().getLineDelimiter());
    _builder.append(_convertToJavaString, "\t\t\t\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t\t");
    _builder.append("fileHeader = \"/*\\n * generated by Xtext \\${version}\\n */\"");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("preferXtendStubs = false");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("language = StandardLanguage {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("name = \"");
    String _name_1 = this.getConfig().getLanguage().getName();
    _builder.append(_name_1, "\t\t\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("fileExtensions = \"");
    LanguageDescriptor.FileExtensions _fileExtensions = this.getConfig().getLanguage().getFileExtensions();
    _builder.append(_fileExtensions, "\t\t\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    {
        boolean _isEmpty = this.getConfig().getEcore2Xtext().getEPackageInfos().isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            {
                final Function1<EPackageInfo, String> _function = (EPackageInfo it) -> {
                    return it.getGenmodelURI().toString();
                };
                Set<String> _set = IterableExtensions.<String>toSet(IterableExtensions.<EPackageInfo, String>map(this.getConfig().getEcore2Xtext().getEPackageInfos(), _function));
                for (final String genmodelURI : _set) {
                    _builder.append("\t\t\t");
                    _builder.append("referencedResource = \"");
                    _builder.append(genmodelURI, "\t\t\t");
                    _builder.append("\"");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        boolean _isFromExistingEcoreModels = this.isFromExistingEcoreModels();
        if (_isFromExistingEcoreModels) {
            _builder.append("\t\t\t");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("fragment = ecore2xtext.Ecore2XtextValueConverterServiceFragment2 auto-inject {}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("formatter = {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("generateStub = true");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("generateXtendStub = true");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("serializer = {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("generateStub = false");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("validator = {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("// composedCheck = \"org.eclipse.xtext.validation.NamesAreUniqueValidator\"");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("// Generates checks for @Deprecated grammar annotations, an IssueProvider and a corresponding PropertyPage");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("generateDeprecationValidation = true");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("generator = {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("generateXtendStub = true");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    {
        JUnitVersion _junitVersion = this.getConfig().getJunitVersion();
        boolean _equals_1 = Objects.equal(_junitVersion, JUnitVersion.JUNIT_5);
        if (_equals_1) {
            _builder.append("\t\t\t");
            _builder.append("junitSupport = {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("junitVersion = \"5\"");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : JUnitVersion(org.eclipse.xtext.util.JUnitVersion) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Charset(java.nio.charset.Charset) LanguageDescriptor(org.eclipse.xtext.xtext.wizard.LanguageDescriptor)

Example 5 with JUnitVersion

use of org.eclipse.xtext.util.JUnitVersion in project xtext-core by eclipse.

the class TestProjectDescriptor method buildGradle.

@Override
public GradleBuildFile buildGradle() {
    GradleBuildFile _buildGradle = super.buildGradle();
    final Procedure1<GradleBuildFile> _function = (GradleBuildFile it) -> {
        JUnitVersion _junitVersion = this.getConfig().getJunitVersion();
        boolean _equals = Objects.equal(_junitVersion, JUnitVersion.JUNIT_5);
        if (_equals) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("test {");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("useJUnitPlatform()");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
            it.setAdditionalContent(_builder.toString());
        }
    };
    return ObjectExtensions.<GradleBuildFile>operator_doubleArrow(_buildGradle, _function);
}
Also used : JUnitVersion(org.eclipse.xtext.util.JUnitVersion) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

JUnitVersion (org.eclipse.xtext.util.JUnitVersion)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 EClass (org.eclipse.emf.ecore.EClass)2 EClassifier (org.eclipse.emf.ecore.EClassifier)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)2 AbstractRule (org.eclipse.xtext.AbstractRule)2 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)2 Charset (java.nio.charset.Charset)1 Path (org.eclipse.core.runtime.Path)1 IAccessRule (org.eclipse.jdt.core.IAccessRule)1 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)1 XtextVersion (org.eclipse.xtext.util.XtextVersion)1 LanguageDescriptor (org.eclipse.xtext.xtext.wizard.LanguageDescriptor)1 SourceFolderDescriptor (org.eclipse.xtext.xtext.wizard.SourceFolderDescriptor)1