Skip to content

Commit

Permalink
Merge pull request #2986 from eclipse/lb_java_21
Browse files Browse the repository at this point in the history
Initial preparation for Java 21
  • Loading branch information
LorenzoBettini committed May 14, 2024
2 parents 9964dba + d3c35d7 commit aa5fb22
Show file tree
Hide file tree
Showing 42 changed files with 731 additions and 381 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,32 @@ jobs:
strategy:
matrix: # 'macos-14' is arm64
os: ['ubuntu-22.04', 'macos-14', 'windows-2022']
java: [ 17 ]
include:
- os: ubuntu-22.04
java: 21
fail-fast: false
runs-on: ${{ matrix.os }}

steps:
- name: 'Check out repository'
uses: actions/checkout@v4

- name: 'Set up Java'
- name: 'Set up Java ${{ matrix.java }}'
uses: actions/setup-java@v4
with:
java-version: 17
java-version: ${{ matrix.java }}
distribution: 'temurin'

- name: Copy toolchains.xml
run: cat ~/.m2/toolchains.xml | tee toolchains.xml

- name: 'Cache Maven packages'
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml', '**/*.target') }}
restore-keys: ${{ runner.os }}-m2
key: ${{ runner.os }}-m2-${{ matrix.java }}-${{ hashFiles('**/pom.xml', '**/*.target') }}
restore-keys: ${{ runner.os }}-m2-${{ matrix.java }}

- name: Set Maven Home environment variable
run: echo "MAVEN_WRAPPER_HOME=$(./mvnw --version | grep "Maven home:" | cut -c 13-)" >> "$GITHUB_ENV"
Expand All @@ -46,7 +53,7 @@ jobs:
- name: Build and test
uses: coactions/setup-xvfb@v1.0.1
with:
run: ./mvnw clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.full.releng
run: ./mvnw --toolchains toolchains.xml clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.full.releng

- name: Archive Test Results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -75,6 +82,9 @@ jobs:
java-version: 17
distribution: 'temurin'

- name: Copy toolchains.xml
run: cat ~/.m2/toolchains.xml | tee toolchains.xml

- name: 'Cache Maven packages'
uses: actions/cache@v4
with:
Expand All @@ -86,7 +96,7 @@ jobs:
run: echo "MAVEN_WRAPPER_HOME=$(./mvnw --version | grep "Maven home:" | cut -c 13-)" >> "$GITHUB_ENV"

- name: Build Maven artifacts
run: ./mvnw clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.maven.releng
run: ./mvnw --toolchains toolchains.xml clean verify "-Dmaven.home=${{ env.MAVEN_WRAPPER_HOME }}" -PuseJenkinsSnapshots -f org.eclipse.xtext.maven.releng

- name: Archive Test Results
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pipeline {
MAVEN_OPTS = "-Xmx1500m"
JAVA_HOME_11_X64 = tool(type:'jdk', name:'temurin-jdk11-latest')
JAVA_HOME_17_X64 = tool(type:'jdk', name:'temurin-jdk17-latest')
JAVA_HOME_21_X64 = tool(type:'jdk', name:'temurin-jdk21-latest')
}
steps {
xvnc(useXauthority: true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest {
result += new WhitespaceData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange,
if (trace) new RuntimeException(), if (leaf.offset == 0) "" else if(leafs.containsComment) null else " ")
else
if(equalIndentationChange && leafs.leafs.last != leaf)
if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)
result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)
else
result += new NewLineData(leaf.offset, leaf.length, if(equalIndentationChange) 0 else increaseIndentationChange, if(equalIndentationChange) 0 else decreaseIndentationChange, if (trace) new RuntimeException(), newLines)
Expand All @@ -1023,7 +1023,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest {
var newLines = 1
if (leaf.leadingComment?.endsWithNewLine)
newLines = newLines - 1
if(equalIndentationChange && leafs.leafs.last != leaf)
if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)
result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)
else
result += new NewLineData(leaf.offset, leaf.length, 0, 0, if (trace) new RuntimeException(), newLines)
Expand Down Expand Up @@ -1472,7 +1472,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest {
WhitespaceData _whitespaceData_1 = new WhitespaceData(_offset_2, _length_1, increaseIndentationChange, decreaseIndentationChange, _xifexpression_3, _xifexpression_4);
result.add(_whitespaceData_1);
} else {
if ((equalIndentationChange && (!Objects.equals(IterableExtensions.<LeafInfo>last(leafs.getLeafs()), leaf)))) {
if ((equalIndentationChange && (!Objects.equals(IterableExtensions.<LeafInfo>lastOrNull(leafs.getLeafs()), leaf)))) {
int _offset_4 = ((WhitespaceInfo)leaf).getOffset();
int _length_2 = ((WhitespaceInfo)leaf).getLength();
RuntimeException _xifexpression_6 = null;
Expand Down Expand Up @@ -1515,7 +1515,7 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest {
if (_endsWithNewLine_2) {
newLines_1 = (newLines_1 - 1);
}
if ((equalIndentationChange && (!Objects.equals(IterableExtensions.<LeafInfo>last(leafs.getLeafs()), leaf)))) {
if ((equalIndentationChange && (!Objects.equals(IterableExtensions.<LeafInfo>lastOrNull(leafs.getLeafs()), leaf)))) {
int _offset_6 = ((WhitespaceInfo)leaf).getOffset();
int _length_4 = ((WhitespaceInfo)leaf).getLength();
RuntimeException _xifexpression_10 = null;
Expand Down Expand Up @@ -1672,5 +1672,5 @@ class CompilerBug427637Test extends AbstractXtendCompilerTest {
}
}
''')
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil
result += new WhitespaceData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange,
if (trace) new RuntimeException(), if (leaf.offset == 0) "" else if(leafs.containsComment) null else " ")
else
if(equalIndentationChange && leafs.leafs.last != leaf)
if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)
result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)
else
result += new NewLineData(leaf.offset, leaf.length, if(equalIndentationChange) 0 else increaseIndentationChange, if(equalIndentationChange) 0 else decreaseIndentationChange, if (trace) new RuntimeException(), newLines)
Expand All @@ -977,7 +977,7 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil
var newLines = 1
if (leaf.leadingComment?.endsWithNewLine)
newLines = newLines - 1
if(equalIndentationChange && leafs.leafs.last != leaf)
if(equalIndentationChange && leafs.leafs.lastOrNull != leaf)
result += new NewLineData(leaf.offset, leaf.length, increaseIndentationChange, decreaseIndentationChange, if (trace) new RuntimeException(), newLines)
else
result += new NewLineData(leaf.offset, leaf.length, 0, 0, if (trace) new RuntimeException(), newLines)
Expand Down Expand Up @@ -1417,7 +1417,7 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil
WhitespaceData _whitespaceData_1 = new WhitespaceData(_offset_2, _length_1, increaseIndentationChange, decreaseIndentationChange, _xifexpression_3, _xifexpression_4);
result.add(_whitespaceData_1);
} else {
if ((equalIndentationChange && (!Objects.equals(IterableExtensions.<LeafInfo>last(leafs.getLeafs()), leaf)))) {
if ((equalIndentationChange && (!Objects.equals(IterableExtensions.<LeafInfo>lastOrNull(leafs.getLeafs()), leaf)))) {
int _offset_4 = ((WhitespaceInfo)leaf).getOffset();
int _length_2 = ((WhitespaceInfo)leaf).getLength();
RuntimeException _xifexpression_6 = null;
Expand Down Expand Up @@ -1460,7 +1460,7 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil
if (_endsWithNewLine_2) {
newLines_1 = (newLines_1 - 1);
}
if ((equalIndentationChange && (!Objects.equals(IterableExtensions.<LeafInfo>last(leafs.getLeafs()), leaf)))) {
if ((equalIndentationChange && (!Objects.equals(IterableExtensions.<LeafInfo>lastOrNull(leafs.getLeafs()), leaf)))) {
int _offset_6 = ((WhitespaceInfo)leaf).getOffset();
int _length_4 = ((WhitespaceInfo)leaf).getLength();
RuntimeException _xifexpression_10 = null;
Expand Down Expand Up @@ -1613,5 +1613,5 @@ class CompilerBug427637Test extends org.eclipse.xtend.core.tests.compiler.Compil
}
}
''')
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DeclarationsTest extends AbstractXtendTestCase {

@Test def testAnnotation() {
validFile('''
@SuppressWarnings("unused")
@testdata.stubs.StubbedSuppressWarnings("unused")
class MyClass {
@com.google.inject.Inject(optional=true) MyClass foo
}
Expand All @@ -44,10 +44,12 @@ class DeclarationsTest extends AbstractXtendTestCase {
assertEquals('MyClass', clazz.qualifiedName)
val suppressWarning = clazz.annotations.head
val supressWarningsDeclaration = suppressWarning.annotationTypeDeclaration
assertEquals('java.lang.SuppressWarnings', supressWarningsDeclaration.qualifiedName)
assertEquals('testdata.stubs.StubbedSuppressWarnings', supressWarningsDeclaration.qualifiedName)
assertEquals('unused', suppressWarning.getStringArrayValue('value').get(0))

assertEquals(2, supressWarningsDeclaration.annotations.size)
val annotations = supressWarningsDeclaration.annotations
assertEquals(annotations.map[it.annotationTypeDeclaration].toString,
2, annotations.size)

val valueProperty = supressWarningsDeclaration.declaredMembers.filter(typeof(AnnotationTypeElementDeclaration)).head
assertEquals("String[]", valueProperty.type.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
package org.eclipse.xtend.core.tests.resource

import com.google.inject.Inject
import java.util.Comparator
import org.eclipse.xtend.core.tests.AbstractXtendTestCase
import org.eclipse.xtext.resource.IResourceDescription
import org.junit.Test
import org.junit.Assert
import java.util.Arrays
import java.util.Comparator
import org.junit.Test

class ImportedNamesTest extends AbstractXtendTestCase {
@Inject
Expand Down Expand Up @@ -138,37 +137,37 @@ class ImportedNamesTest extends AbstractXtendTestCase {
import java.util.AbstractMap.*;
class C {
val list = new java.util.ArrayList<Map.Entry>
val list = new testdata.stubs.StubbedArrayList<Map.Entry>
val entry = new SimpleEntry(null, null)
val int i = 0
}
''', true)
val description = resourceDescriptionManager.getResourceDescription(file.eResource)
val importedNames = description.importedNames
Assert.assertEquals(Arrays.asList(
"java.io.serializable",
"java.lang.cloneable",
"java.lang.iterable",
"java.lang.java$util$arraylist",
"java.lang.object",
"java.util.abstractcollection",
"java.util.abstractlist",
"java.util.abstractmap",
"java.util.abstractmap.java$util$arraylist",
"java.util.abstractmap.simpleentry",
"java.util.abstractmap$java$util$arraylist",
"java.util.abstractmap$simpleentry",
"java.util.arraylist",
"java.util.collection",
"java.util.list",
"java.util.map",
"java.util.map$entry",
"java.util.randomaccess",
"java.util$abstractmap$java$util$arraylist",
"java$util$abstractmap$java$util$arraylist",
"my.pack.c",
"my.pack.java$util$arraylist",
"org.eclipse.xtext.xbase.lib.java$util$arraylist").join("\n"),
Assert.assertEquals('''
java.io.serializable
java.lang.cloneable
java.lang.iterable
java.lang.object
java.lang.testdata$stubs$stubbedarraylist
java.util.abstractcollection
java.util.abstractmap
java.util.abstractmap.simpleentry
java.util.abstractmap.testdata$stubs$stubbedarraylist
java.util.abstractmap$simpleentry
java.util.abstractmap$testdata$stubs$stubbedarraylist
java.util.collection
java.util.map
java.util.map$entry
java.util.randomaccess
java.util$abstractmap$testdata$stubs$stubbedarraylist
java$util$abstractmap$testdata$stubs$stubbedarraylist
my.pack.c
my.pack.testdata$stubs$stubbedarraylist
org.eclipse.xtext.xbase.lib.testdata$stubs$stubbedarraylist
testdata.stubs.stubbedabstractlist
testdata.stubs.stubbedarraylist
testdata.stubs.stubbedlist'''.toString.replace("\r", ""),
importedNames.toList.sortWith(Comparator.naturalOrder).join("\n"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import com.google.inject.Inject
import java.io.Serializable
import java.util.Collection
import java.util.Collections
import java.util.List
import org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations
import org.eclipse.xtext.util.JavaRuntimeVersion
import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
import org.junit.Ignore
import org.junit.Test
import org.eclipse.xtext.util.JavaRuntimeVersion
import testdata.stubs.StubbedList

/**
* @author Sebastian Zarnekow
Expand Down Expand Up @@ -167,12 +167,12 @@ class SuperTypesTest extends AbstractSuperTypesTest {

@Test
override void testRawList() {
typeof(List).assertSuperTypes("Collection")
typeof(StubbedList).assertSuperTypes("Collection")
}

@Test
override void testStringList() {
"java.util.List<String>".assertSuperTypes("Collection<String>")
"testdata.stubs.StubbedList<String>".assertSuperTypes("Collection<String>")
}

@Test
Expand Down Expand Up @@ -277,23 +277,23 @@ class AllSuperTypesTest extends AbstractSuperTypesTest {

@Test
override void testRawList() {
typeof(List).assertSuperTypes("Collection", "Iterable", "Object")
typeof(StubbedList).assertSuperTypes("Collection", "Iterable", "Object")
}

@Test
override void testStringList() {
"java.util.List<String>".assertSuperTypes("Collection<String>", "Iterable<String>", "Object")
"testdata.stubs.StubbedList<String>".assertSuperTypes("Collection<String>", "Iterable<String>", "Object")
}

@Test
override void testStringArrayArrayList() {
"java.util.ArrayList<? extends String[]>".assertSuperTypes(
"AbstractList<? extends String[]>",
"testdata.stubs.StubbedArrayList<? extends String[]>".assertSuperTypes(
"StubbedAbstractList<? extends String[]>",
"RandomAccess",
"Cloneable",
"Serializable",
"AbstractCollection<? extends String[]>",
"List<? extends String[]>",
"StubbedList<? extends String[]>",
"Collection<? extends String[]>",
"Iterable<? extends String[]>",
"Object")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Lorenzo Bettini 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 testdata.stubs;

import java.util.AbstractCollection;

/**
* A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see,
* e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html).
*
* @author Lorenzo Bettini - Initial contribution and API
*/
public abstract class StubbedAbstractList<E> extends AbstractCollection<E> implements StubbedList<E> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2024 Lorenzo Bettini 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 testdata.stubs;

import java.util.Iterator;
import java.util.RandomAccess;

/**
* A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see,
* e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html).
*
* @author Lorenzo Bettini - Initial contribution and API
*/
@SuppressWarnings("serial")
public class StubbedArrayList<E> extends StubbedAbstractList<E>
implements RandomAccess, Cloneable, java.io.Serializable {

@Override
public Iterator<E> iterator() {
return null;
}

@Override
public int size() {
return 0;
}

}

0 comments on commit aa5fb22

Please sign in to comment.