From fe032aa8e605fa811926d49ea35c0a00370afe5e Mon Sep 17 00:00:00 2001 From: Dain Sundstrom Date: Wed, 7 Aug 2024 20:18:50 -0700 Subject: [PATCH 1/4] Update to Airbase 160 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8af5d01..a387e66 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.airlift airbase - 156 + 160 bytecode From c451cd822fbab68ca3f1e6b59960c8108005e8f1 Mon Sep 17 00:00:00 2001 From: Dain Sundstrom Date: Wed, 7 Aug 2024 20:19:23 -0700 Subject: [PATCH 2/4] Update to ASM 9.7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a387e66..7193d2c 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ 17 8 - 9.4 + 9.7 From 569c43157c9044efc614d40010928f1d97e15cf3 Mon Sep 17 00:00:00 2001 From: Dain Sundstrom Date: Wed, 7 Aug 2024 21:00:57 -0700 Subject: [PATCH 3/4] Migrate to Junit and assertJ --- pom.xml | 4 +-- .../airlift/bytecode/TestBytecodeUtils.java | 16 ++++----- .../airlift/bytecode/TestClassGenerator.java | 9 +++-- .../bytecode/TestFastMethodHandleProxies.java | 30 ++++++++-------- .../bytecode/TestHiddenClassGenerator.java | 9 +++-- .../BytecodeExpressionAssertions.java | 12 +++---- .../TestArithmeticBytecodeExpression.java | 29 ++++++++-------- .../TestArrayBytecodeExpressions.java | 19 +++++------ .../TestCastBytecodeExpression.java | 34 ++++++++----------- .../TestComparisonBytecodeExpression.java | 16 ++++----- .../TestConstantBytecodeExpression.java | 4 +-- .../TestGetFieldBytecodeExpression.java | 8 ++--- .../TestInlineIfBytecodeExpression.java | 6 ++-- .../TestInvokeBytecodeExpression.java | 9 ++--- .../TestInvokeDynamicBytecodeExpression.java | 5 +-- .../TestLogicalBytecodeExpression.java | 13 ++++--- .../TestNewInstanceBytecodeExpression.java | 6 ++-- .../expression/TestPopBytecodeExpression.java | 13 ++++--- .../TestSetFieldBytecodeExpression.java | 18 +++++----- .../TestSetVariableBytecodeExpression.java | 20 +++++------ 20 files changed, 140 insertions(+), 140 deletions(-) diff --git a/pom.xml b/pom.xml index 7193d2c..6a5ecee 100644 --- a/pom.xml +++ b/pom.xml @@ -72,8 +72,8 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api test diff --git a/src/test/java/io/airlift/bytecode/TestBytecodeUtils.java b/src/test/java/io/airlift/bytecode/TestBytecodeUtils.java index 059711a..f58a090 100644 --- a/src/test/java/io/airlift/bytecode/TestBytecodeUtils.java +++ b/src/test/java/io/airlift/bytecode/TestBytecodeUtils.java @@ -13,19 +13,19 @@ */ package io.airlift.bytecode; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.airlift.bytecode.BytecodeUtils.toJavaIdentifierString; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; -public class TestBytecodeUtils +class TestBytecodeUtils { @Test - public void testToJavaIdentifierString() + void testToJavaIdentifierString() { - assertEquals(toJavaIdentifierString("HelloWorld"), "HelloWorld"); - assertEquals(toJavaIdentifierString("Hello$World"), "Hello$World"); - assertEquals(toJavaIdentifierString("Hello#World"), "Hello_World"); - assertEquals(toJavaIdentifierString("A^B^C"), "A_B_C"); + assertThat(toJavaIdentifierString("HelloWorld")).isEqualTo("HelloWorld"); + assertThat(toJavaIdentifierString("Hello$World")).isEqualTo("Hello$World"); + assertThat(toJavaIdentifierString("Hello#World")).isEqualTo("Hello_World"); + assertThat(toJavaIdentifierString("A^B^C")).isEqualTo("A_B_C"); } } diff --git a/src/test/java/io/airlift/bytecode/TestClassGenerator.java b/src/test/java/io/airlift/bytecode/TestClassGenerator.java index 6e25595..ef58560 100644 --- a/src/test/java/io/airlift/bytecode/TestClassGenerator.java +++ b/src/test/java/io/airlift/bytecode/TestClassGenerator.java @@ -14,7 +14,7 @@ package io.airlift.bytecode; import com.google.common.collect.ImmutableList; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.StringWriter; import java.lang.reflect.Method; @@ -32,12 +32,11 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.add; import static java.nio.file.Files.createTempDirectory; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; -public class TestClassGenerator +class TestClassGenerator { @Test - public void testGenerator() + void testGenerator() throws Exception { ClassDefinition classDefinition = new ClassDefinition( @@ -72,7 +71,7 @@ public void testGenerator() .defineClass(classDefinition, Object.class); Method add = clazz.getMethod("add", int.class, int.class); - assertEquals(add.invoke(null, 13, 42), 55); + assertThat(add.invoke(null, 13, 42)).isEqualTo(55); assertThat(writer.toString()) .contains("00002 I I : I I : IADD") diff --git a/src/test/java/io/airlift/bytecode/TestFastMethodHandleProxies.java b/src/test/java/io/airlift/bytecode/TestFastMethodHandleProxies.java index 5a42bdb..f47eb06 100644 --- a/src/test/java/io/airlift/bytecode/TestFastMethodHandleProxies.java +++ b/src/test/java/io/airlift/bytecode/TestFastMethodHandleProxies.java @@ -14,7 +14,7 @@ package io.airlift.bytecode; import com.google.common.base.VerifyException; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.lang.invoke.MethodHandle; @@ -28,19 +28,19 @@ import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodType.methodType; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.testng.Assert.assertEquals; -public class TestFastMethodHandleProxies +class TestFastMethodHandleProxies { @Test - public void testBasic() + void testBasic() throws ReflectiveOperationException { assertInterface( LongUnaryOperator.class, lookup().findStatic(getClass(), "increment", methodType(long.class, long.class)), - addOne -> assertEquals(addOne.applyAsLong(1), 2L)); + addOne -> assertThat(addOne.applyAsLong(1)).isEqualTo(2L)); } private static long increment(long x) @@ -49,13 +49,13 @@ private static long increment(long x) } @Test - public void testGeneric() + void testGeneric() throws ReflectiveOperationException { assertInterface( LongFunction.class, lookup().findStatic(getClass(), "incrementAndPrint", methodType(String.class, long.class)), - print -> assertEquals(print.apply(1), "2")); + print -> assertThat(print.apply(1)).isEqualTo("2")); } private static String incrementAndPrint(long x) @@ -64,15 +64,15 @@ private static String incrementAndPrint(long x) } @Test - public void testObjectAndDefaultMethods() + void testObjectAndDefaultMethods() throws ReflectiveOperationException { assertInterface( StringLength.class, lookup().findStatic(getClass(), "stringLength", methodType(int.class, String.class)), length -> { - assertEquals(length.length("abc"), 3); - assertEquals(length.theAnswer(), 42); + assertThat(length.length("abc")).isEqualTo(3); + assertThat(length.theAnswer()).isEqualTo(42); }); } @@ -95,7 +95,7 @@ default int theAnswer() } @Test - public void testUncheckedException() + void testUncheckedException() throws ReflectiveOperationException { assertInterface( @@ -111,7 +111,7 @@ private static void throwUncheckedException() } @Test - public void testCheckedException() + void testCheckedException() throws ReflectiveOperationException { assertInterface( @@ -129,7 +129,7 @@ private static void throwCheckedException() } @Test - public void testMutableCallSite() + void testMutableCallSite() throws ReflectiveOperationException { MethodHandle one = lookup().findStatic(getClass(), "one", methodType(int.class)); @@ -141,9 +141,9 @@ public void testMutableCallSite() callSite.dynamicInvoker(), supplier -> { callSite.setTarget(one); - assertEquals(supplier.getAsInt(), 1); + assertThat(supplier.getAsInt()).isEqualTo(1); callSite.setTarget(two); - assertEquals(supplier.getAsInt(), 2); + assertThat(supplier.getAsInt()).isEqualTo(2); }); } diff --git a/src/test/java/io/airlift/bytecode/TestHiddenClassGenerator.java b/src/test/java/io/airlift/bytecode/TestHiddenClassGenerator.java index 355968d..d4dc120 100644 --- a/src/test/java/io/airlift/bytecode/TestHiddenClassGenerator.java +++ b/src/test/java/io/airlift/bytecode/TestHiddenClassGenerator.java @@ -14,7 +14,7 @@ package io.airlift.bytecode; import com.google.common.collect.ImmutableList; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.StringWriter; import java.lang.reflect.Method; @@ -34,12 +34,11 @@ import static java.lang.invoke.MethodHandles.lookup; import static java.nio.file.Files.createTempDirectory; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; -public class TestHiddenClassGenerator +class TestHiddenClassGenerator { @Test - public void testGenerator() + void testGenerator() throws Exception { ClassDefinition classDefinition = new ClassDefinition( @@ -74,7 +73,7 @@ public void testGenerator() .defineHiddenClass(classDefinition, Object.class, Optional.of("class data")); Method add = clazz.getMethod("add", int.class, int.class); - assertEquals(add.invoke(null, 13, 42), 55); + assertThat(add.invoke(null, 13, 42)).isEqualTo(55); assertThat(writer.toString()) .contains("00002 I I : I I : IADD") diff --git a/src/test/java/io/airlift/bytecode/expression/BytecodeExpressionAssertions.java b/src/test/java/io/airlift/bytecode/expression/BytecodeExpressionAssertions.java index b413bf0..e35b6ba 100644 --- a/src/test/java/io/airlift/bytecode/expression/BytecodeExpressionAssertions.java +++ b/src/test/java/io/airlift/bytecode/expression/BytecodeExpressionAssertions.java @@ -31,17 +31,17 @@ import static io.airlift.bytecode.BytecodeUtils.uniqueClassName; import static io.airlift.bytecode.ClassGenerator.classGenerator; import static io.airlift.bytecode.ParameterizedType.type; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public final class BytecodeExpressionAssertions { - public static final AtomicBoolean DUMP_BYTECODE_TREE = new AtomicBoolean(); + private static final AtomicBoolean DUMP_BYTECODE_TREE = new AtomicBoolean(); private BytecodeExpressionAssertions() {} static void assertBytecodeExpressionType(BytecodeExpression expression, ParameterizedType type) { - assertEquals(expression.getType(), type); + assertThat(expression.getType()).isEqualTo(type); } public static void assertBytecodeExpression(BytecodeExpression expression, Object expected, String expectedRendering) @@ -53,7 +53,7 @@ public static void assertBytecodeExpression(BytecodeExpression expression, Objec public static void assertBytecodeExpression(BytecodeExpression expression, Object expected, String expectedRendering, Optional parentClassLoader) throws Exception { - assertEquals(expression.toString(), expectedRendering); + assertThat(expression.toString()).isEqualTo(expectedRendering); assertBytecodeNode(expression.ret(), expression.getType(), expected, parentClassLoader); } @@ -79,7 +79,7 @@ public static void assertBytecodeNode(BytecodeNode node, ParameterizedType retur public static void assertBytecodeNode(BytecodeNode node, ParameterizedType returnType, Object expected, Optional parentClassLoader) throws Exception { - assertEquals(execute(context -> node, returnType, parentClassLoader), expected); + assertThat(execute(context -> node, returnType, parentClassLoader)).isEqualTo(expected); } public static void assertBytecodeNode(Function nodeGenerator, ParameterizedType returnType, Object expected) @@ -91,7 +91,7 @@ public static void assertBytecodeNode(Function nodeGenerato public static void assertBytecodeNode(Function nodeGenerator, ParameterizedType returnType, Object expected, Optional parentClassLoader) throws Exception { - assertEquals(execute(nodeGenerator, returnType, parentClassLoader), expected); + assertThat(execute(nodeGenerator, returnType, parentClassLoader)).isEqualTo(expected); } public static Object execute(Function nodeGenerator, ParameterizedType returnType, Optional parentClassLoader) diff --git a/src/test/java/io/airlift/bytecode/expression/TestArithmeticBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestArithmeticBytecodeExpression.java index 77a38e6..589a2f6 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestArithmeticBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestArithmeticBytecodeExpression.java @@ -13,7 +13,7 @@ */ package io.airlift.bytecode.expression; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.airlift.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression; import static io.airlift.bytecode.expression.BytecodeExpressions.add; @@ -33,10 +33,10 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.shiftRightUnsigned; import static io.airlift.bytecode.expression.BytecodeExpressions.subtract; -public class TestArithmeticBytecodeExpression +class TestArithmeticBytecodeExpression { @Test - public void testAdd() + void testAdd() throws Exception { assertBytecodeExpression(add(constantInt(3), constantInt(7)), 3 + 7, "(3 + 7)"); @@ -46,7 +46,7 @@ public void testAdd() } @Test - public void testSubtract() + void testSubtract() throws Exception { assertBytecodeExpression(subtract(constantInt(3), constantInt(7)), 3 - 7, "(3 - 7)"); @@ -56,7 +56,7 @@ public void testSubtract() } @Test - public void testMultiply() + void testMultiply() throws Exception { assertBytecodeExpression(multiply(constantInt(3), constantInt(7)), 3 * 7, "(3 * 7)"); @@ -66,7 +66,7 @@ public void testMultiply() } @Test - public void testDivide() + void testDivide() throws Exception { assertBytecodeExpression(divide(constantInt(7), constantInt(3)), 7 / 3, "(7 / 3)"); @@ -76,7 +76,7 @@ public void testDivide() } @Test - public void testRemainder() + void testRemainder() throws Exception { assertBytecodeExpression(remainder(constantInt(7), constantInt(3)), 7 % 3, "(7 % 3)"); @@ -86,7 +86,7 @@ public void testRemainder() } @Test - public void testShiftLeft() + void testShiftLeft() throws Exception { assertBytecodeExpression(shiftLeft(constantInt(7), constantInt(3)), 7 << 3, "(7 << 3)"); @@ -94,7 +94,7 @@ public void testShiftLeft() } @Test - public void testShiftRight() + void testShiftRight() throws Exception { assertBytecodeExpression(shiftRight(constantInt(-7), constantInt(3)), -7 >> 3, "(-7 >> 3)"); @@ -102,7 +102,7 @@ public void testShiftRight() } @Test - public void testShiftRightUnsigned() + void testShiftRightUnsigned() throws Exception { assertBytecodeExpression(shiftRightUnsigned(constantInt(-7), constantInt(3)), -7 >>> 3, "(-7 >>> 3)"); @@ -110,7 +110,7 @@ public void testShiftRightUnsigned() } @Test - public void testBitwiseAnd() + void testBitwiseAnd() throws Exception { assertBytecodeExpression(bitwiseAnd(constantInt(101), constantInt(37)), 101 & 37, "(101 & 37)"); @@ -118,7 +118,7 @@ public void testBitwiseAnd() } @Test - public void testBitwiseOr() + void testBitwiseOr() throws Exception { assertBytecodeExpression(bitwiseOr(constantInt(101), constantInt(37)), 101 | 37, "(101 | 37)"); @@ -126,15 +126,16 @@ public void testBitwiseOr() } @Test - public void testBitwiseXor() + void testBitwiseXor() throws Exception { assertBytecodeExpression(bitwiseXor(constantInt(101), constantInt(37)), 101 ^ 37, "(101 ^ 37)"); assertBytecodeExpression(bitwiseXor(constantLong(101), constantLong(37)), 101L ^ 37L, "(101L ^ 37L)"); } + @SuppressWarnings("UnnecessaryUnaryMinus") @Test - public void testNegate() + void testNegate() throws Exception { assertBytecodeExpression(negate(constantInt(3)), -3, "-(3)"); diff --git a/src/test/java/io/airlift/bytecode/expression/TestArrayBytecodeExpressions.java b/src/test/java/io/airlift/bytecode/expression/TestArrayBytecodeExpressions.java index 9f08c19..6c23e6a 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestArrayBytecodeExpressions.java +++ b/src/test/java/io/airlift/bytecode/expression/TestArrayBytecodeExpressions.java @@ -18,8 +18,7 @@ import io.airlift.bytecode.DynamicClassLoader; import io.airlift.bytecode.MethodDefinition; import io.airlift.bytecode.Parameter; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; @@ -47,12 +46,10 @@ public class TestArrayBytecodeExpressions { private final DynamicClassLoader classLoader = new DynamicClassLoader(TestArrayBytecodeExpressions.class.getClassLoader()); - private static final ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), "DummyClass", type(Object.class)); + private final ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), "DummyClass", type(Object.class)); private final Map, MethodDefinition> typeMethodMap = new HashMap<>(); - @BeforeClass - public void setUp() - throws Exception + TestArrayBytecodeExpressions() { for (Class aClass : ImmutableList.of(boolean[].class, char[].class, float[].class, double[].class, byte[].class, short[].class, int[].class, long[].class, String[].class)) { MethodDefinition methodDefinition = defineSetAndGetMethod(aClass); @@ -63,7 +60,7 @@ public void setUp() } @Test - public void testNewArray() + void testNewArray() throws Exception { assertBytecodeExpressionType(newArray(type(boolean[].class), 5), type(boolean[].class)); @@ -95,7 +92,7 @@ public void testNewArray() } @Test - public void testNewArrayPrefilled() + void testNewArrayPrefilled() throws Exception { assertBytecodeExpressionType(newArray(type(boolean[].class), ImmutableList.of(constantTrue(), constantFalse(), constantTrue())), type(boolean[].class)); @@ -124,7 +121,7 @@ public void testNewArrayPrefilled() } @Test - public void testSetElement() + void testSetElement() throws Exception { BytecodeExpression stringArray = constantString("foo bar baz").invoke("split", String[].class, constantString(" ")); @@ -143,14 +140,14 @@ public void testSetElement() } @Test - public void testGetElement() + void testGetElement() throws Exception { assertBytecodeExpression(constantString("abc").invoke("getBytes", byte[].class).getElement(1), "abc".getBytes()[1], "\"abc\".getBytes()[1]"); assertBytecodeExpression(constantString("abc").invoke("getBytes", byte[].class).getElement(constantInt(1)), "abc".getBytes()[1], "\"abc\".getBytes()[1]"); } - private static MethodDefinition defineSetAndGetMethod(Class aClass) + private MethodDefinition defineSetAndGetMethod(Class aClass) { Parameter arr = arg("arr", type(aClass)); Parameter index = arg("index", type(int.class)); diff --git a/src/test/java/io/airlift/bytecode/expression/TestCastBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestCastBytecodeExpression.java index 8a5a85f..82aff0c 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestCastBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestCastBytecodeExpression.java @@ -14,12 +14,12 @@ package io.airlift.bytecode.expression; import com.google.common.primitives.Primitives; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.airlift.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression; import static io.airlift.bytecode.expression.BytecodeExpressions.getStatic; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class TestCastBytecodeExpression { @@ -34,7 +34,7 @@ public class TestCastBytecodeExpression public static final double DOUBLE_FIELD = 4.4; @Test - public void testDownCastObject() + void testDownCastObject() throws Exception { assertBytecodeExpression(getStatic(getClass(), "OBJECT_FIELD").cast(String.class).invoke("length", int.class), @@ -43,7 +43,7 @@ public void testDownCastObject() } @Test - public void testCastBetweenObjectAndPrimitive() + void testCastBetweenObjectAndPrimitive() throws Exception { assertCast(getStatic(getClass(), "INT_FIELD"), 33, Object.class); @@ -51,7 +51,7 @@ public void testCastBetweenObjectAndPrimitive() } @Test - public void testInvalildCast() + void testInvalildCast() { // Cast between a boxed primitive and a primitive that are different assertInvalidCast(getStatic(getClass(), "INT_FIELD"), Double.class); @@ -66,7 +66,7 @@ public void testInvalildCast() } @Test - public void testCastPrimitive() + void testCastPrimitive() throws Exception { assertPrimitiveCast("BOOLEAN_FIELD", boolean.class, BOOLEAN_FIELD); @@ -128,7 +128,7 @@ public void testCastPrimitive() assertPrimitiveCast("DOUBLE_FIELD", double.class, DOUBLE_FIELD); } - public void assertPrimitiveCast(String fieldName, Class castToType, Object expected) + void assertPrimitiveCast(String fieldName, Class castToType, Object expected) throws Exception { // simple cast @@ -145,27 +145,21 @@ public void assertPrimitiveCast(String fieldName, Class castToType, Object ex assertCast(baseExpression, expected, castToType); } - public static void assertCast(BytecodeExpression expression, Object expectedValue, Class castToType) + static void assertCast(BytecodeExpression expression, Object expectedValue, Class castToType) throws Exception { BytecodeExpression castExpression = expression.cast(castToType); assertBytecodeExpression(castExpression, expectedValue, expectedCastRendering(expression.toString(), castToType)); - assertEquals(castExpression.getType().getJavaClassName(), castToType.getName()); + assertThat(castExpression.getType().getJavaClassName()).isEqualTo(castToType.getName()); } - public static void assertInvalidCast(BytecodeExpression expression, Class castToType) + static void assertInvalidCast(BytecodeExpression expression, Class castToType) { - try { - // Exception must be thrown here. - // An exception that is thrown at actual byte code generation time is too late. At that point, stack trace is generally not useful. - expression.cast(castToType); - fail(); - } - catch (IllegalArgumentException ignored) { - } + assertThatThrownBy(() -> expression.cast(castToType)) + .isInstanceOf(IllegalArgumentException.class); } - public static String expectedCastRendering(String expectedRendering, Class castToType) + static String expectedCastRendering(String expectedRendering, Class castToType) { return "((" + castToType.getSimpleName() + ") " + expectedRendering + ")"; } diff --git a/src/test/java/io/airlift/bytecode/expression/TestComparisonBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestComparisonBytecodeExpression.java index 790c242..0a54994 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestComparisonBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestComparisonBytecodeExpression.java @@ -13,7 +13,7 @@ */ package io.airlift.bytecode.expression; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.airlift.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression; import static io.airlift.bytecode.expression.BytecodeExpressions.constantDouble; @@ -28,10 +28,10 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.lessThanOrEqual; import static io.airlift.bytecode.expression.BytecodeExpressions.notEqual; -public class TestComparisonBytecodeExpression +class TestComparisonBytecodeExpression { @Test - public void testLessThan() + void testLessThan() throws Exception { assertBytecodeExpression(lessThan(constantInt(3), constantInt(7)), 3 < 7, "(3 < 7)"); @@ -56,7 +56,7 @@ public void testLessThan() } @Test - public void testGreaterThan() + void testGreaterThan() throws Exception { assertBytecodeExpression(greaterThan(constantInt(3), constantInt(7)), 3 > 7, "(3 > 7)"); @@ -81,7 +81,7 @@ public void testGreaterThan() } @Test - public void testLessThanOrEqual() + void testLessThanOrEqual() throws Exception { assertBytecodeExpression(lessThanOrEqual(constantInt(3), constantInt(7)), 3 <= 7, "(3 <= 7)"); @@ -106,7 +106,7 @@ public void testLessThanOrEqual() } @Test - public void testGreaterThanOrEqual() + void testGreaterThanOrEqual() throws Exception { assertBytecodeExpression(greaterThanOrEqual(constantInt(3), constantInt(7)), 3 >= 7, "(3 >= 7)"); @@ -132,7 +132,7 @@ public void testGreaterThanOrEqual() @SuppressWarnings({"FloatingPointEquality", "ComparisonToNaN", "EqualsNaN", "EqualsWithItself"}) @Test - public void testEqual() + void testEqual() throws Exception { assertBytecodeExpression(equal(constantInt(7), constantInt(3)), 7 == 3, "(7 == 3)"); @@ -159,7 +159,7 @@ public void testEqual() @SuppressWarnings({"FloatingPointEquality", "ComparisonToNaN", "EqualsNaN", "EqualsWithItself"}) @Test - public void testNotEqual() + void testNotEqual() throws Exception { assertBytecodeExpression(notEqual(constantInt(7), constantInt(3)), 7 != 3, "(7 != 3)"); diff --git a/src/test/java/io/airlift/bytecode/expression/TestConstantBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestConstantBytecodeExpression.java index f365559..4f67a0b 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestConstantBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestConstantBytecodeExpression.java @@ -14,7 +14,7 @@ package io.airlift.bytecode.expression; import com.google.common.collect.ImmutableList; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.lang.invoke.MethodHandles.Lookup; import java.lang.reflect.Method; @@ -36,7 +36,7 @@ public class TestConstantBytecodeExpression { @Test - public void test() + void test() throws Exception { assertBytecodeExpression(constantNull(List.class), null, "null"); diff --git a/src/test/java/io/airlift/bytecode/expression/TestGetFieldBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestGetFieldBytecodeExpression.java index ab320ca..ac95a95 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestGetFieldBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestGetFieldBytecodeExpression.java @@ -13,7 +13,7 @@ */ package io.airlift.bytecode.expression; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.awt.Point; @@ -23,10 +23,10 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.getStatic; import static io.airlift.bytecode.expression.BytecodeExpressions.newInstance; -public class TestGetFieldBytecodeExpression +class TestGetFieldBytecodeExpression { @Test - public void testGetField() + void testGetField() throws Exception { assertBytecodeExpression(newInstance(Point.class, constantInt(3), constantInt(7)).getField("x", int.class), new Point(3, 7).x, "new Point(3, 7).x"); @@ -35,7 +35,7 @@ public void testGetField() } @Test - public void testGetStaticField() + void testGetStaticField() throws Exception { assertBytecodeExpression(getStatic(Long.class, "MIN_VALUE"), Long.MIN_VALUE, "Long.MIN_VALUE"); diff --git a/src/test/java/io/airlift/bytecode/expression/TestInlineIfBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestInlineIfBytecodeExpression.java index cfec8cc..9e67366 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestInlineIfBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestInlineIfBytecodeExpression.java @@ -13,7 +13,7 @@ */ package io.airlift.bytecode.expression; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.airlift.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression; import static io.airlift.bytecode.expression.BytecodeExpressions.constantFalse; @@ -21,10 +21,10 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.constantTrue; import static io.airlift.bytecode.expression.BytecodeExpressions.inlineIf; -public class TestInlineIfBytecodeExpression +class TestInlineIfBytecodeExpression { @Test - public void testInlineIf() + void testInlineIf() throws Exception { assertBytecodeExpression(inlineIf(constantTrue(), constantString("T"), constantString("F")), true ? "T" : "F", "(true ? \"T\" : \"F\")"); diff --git a/src/test/java/io/airlift/bytecode/expression/TestInvokeBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestInvokeBytecodeExpression.java index 79bae81..5a72980 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestInvokeBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestInvokeBytecodeExpression.java @@ -14,7 +14,7 @@ package io.airlift.bytecode.expression; import com.google.common.collect.ImmutableList; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.airlift.bytecode.ParameterizedType.type; import static io.airlift.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression; @@ -22,10 +22,11 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.constantString; import static io.airlift.bytecode.expression.BytecodeExpressions.invokeStatic; -public class TestInvokeBytecodeExpression +class TestInvokeBytecodeExpression { + @SuppressWarnings("CallToStringConcatCanBeReplacedByOperator") @Test - public void testInvokeMethod() + void testInvokeMethod() throws Exception { assertBytecodeExpression(constantString("foo").invoke("length", int.class), "foo".length(), "\"foo\".length()"); @@ -41,7 +42,7 @@ public void testInvokeMethod() } @Test - public void testInvokeStaticMethod() + void testInvokeStaticMethod() throws Exception { assertBytecodeExpression(invokeStatic(System.class, "lineSeparator", String.class), System.lineSeparator(), "System.lineSeparator()"); diff --git a/src/test/java/io/airlift/bytecode/expression/TestInvokeDynamicBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestInvokeDynamicBytecodeExpression.java index 89e7a23..65296f7 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestInvokeDynamicBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestInvokeDynamicBytecodeExpression.java @@ -14,7 +14,7 @@ package io.airlift.bytecode.expression; import com.google.common.collect.ImmutableList; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.lang.invoke.CallSite; import java.lang.invoke.ConstantCallSite; @@ -30,7 +30,7 @@ public class TestInvokeDynamicBytecodeExpression { @Test - public void testInvokeStaticMethod() + void testInvokeStaticMethod() throws Exception { assertBytecodeExpression( @@ -39,6 +39,7 @@ public void testInvokeStaticMethod() "[bootstrap(\"bar\")]=>foo(\"baz\")"); } + @SuppressWarnings("WeakerAccess") public static final Method TEST_BOOTSTRAP_METHOD; static { diff --git a/src/test/java/io/airlift/bytecode/expression/TestLogicalBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestLogicalBytecodeExpression.java index 24cf6d5..27ce8d4 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestLogicalBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestLogicalBytecodeExpression.java @@ -13,7 +13,7 @@ */ package io.airlift.bytecode.expression; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.airlift.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression; import static io.airlift.bytecode.expression.BytecodeExpressions.and; @@ -22,10 +22,11 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.not; import static io.airlift.bytecode.expression.BytecodeExpressions.or; -public class TestLogicalBytecodeExpression +class TestLogicalBytecodeExpression { + @SuppressWarnings("PointlessBooleanExpression") @Test - public void testAnd() + void testAnd() throws Exception { assertBytecodeExpression(and(constantTrue(), constantTrue()), true && true, "(true && true)"); @@ -34,8 +35,9 @@ public void testAnd() assertBytecodeExpression(and(constantFalse(), constantFalse()), false && false, "(false && false)"); } + @SuppressWarnings("PointlessBooleanExpression") @Test - public void testOr() + void testOr() throws Exception { assertBytecodeExpression(or(constantTrue(), constantTrue()), true || true, "(true || true)"); @@ -44,8 +46,9 @@ public void testOr() assertBytecodeExpression(or(constantFalse(), constantFalse()), false || false, "(false || false)"); } + @SuppressWarnings("PointlessBooleanExpression") @Test - public void testNot() + void testNot() throws Exception { assertBytecodeExpression(not(constantTrue()), !true, "(!true)"); diff --git a/src/test/java/io/airlift/bytecode/expression/TestNewInstanceBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestNewInstanceBytecodeExpression.java index b2363e1..5ae73f4 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestNewInstanceBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestNewInstanceBytecodeExpression.java @@ -14,7 +14,7 @@ package io.airlift.bytecode.expression; import com.google.common.collect.ImmutableList; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.UUID; @@ -22,10 +22,10 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.constantLong; import static io.airlift.bytecode.expression.BytecodeExpressions.newInstance; -public class TestNewInstanceBytecodeExpression +class TestNewInstanceBytecodeExpression { @Test - public void testNewInstance() + void testNewInstance() throws Exception { assertBytecodeExpression(newInstance(UUID.class, constantLong(3), constantLong(7)), new UUID(3L, 7L), "new UUID(3L, 7L)"); diff --git a/src/test/java/io/airlift/bytecode/expression/TestPopBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestPopBytecodeExpression.java index 6cf3ce9..5ec550c 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestPopBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestPopBytecodeExpression.java @@ -13,28 +13,30 @@ */ package io.airlift.bytecode.expression; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.airlift.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression; import static io.airlift.bytecode.expression.BytecodeExpressions.invokeStatic; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestPopBytecodeExpression { + @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") @Test - public void testGetField() + void testGetField() throws Exception { intCount = 0; assertBytecodeExpression(invokeStatic(getClass(), "incrementAndGetIntCount", int.class).pop(), null, getClass().getSimpleName() + ".incrementAndGetIntCount();"); - assertEquals(intCount, 1); + assertThat(intCount).isEqualTo(1); longCount = 0; assertBytecodeExpression(invokeStatic(getClass(), "incrementAndGetLongCount", long.class).pop(), null, getClass().getSimpleName() + ".incrementAndGetLongCount();"); - assertEquals(longCount, 1); + assertThat(longCount).isEqualTo(1); } private static int intCount; + @SuppressWarnings("unused") public static int incrementAndGetIntCount() { return intCount++; @@ -42,6 +44,7 @@ public static int incrementAndGetIntCount() private static long longCount; + @SuppressWarnings("unused") public static long incrementAndGetLongCount() { return longCount++; diff --git a/src/test/java/io/airlift/bytecode/expression/TestSetFieldBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestSetFieldBytecodeExpression.java index b8e7d56..df0b8fd 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestSetFieldBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestSetFieldBytecodeExpression.java @@ -17,7 +17,7 @@ import io.airlift.bytecode.BytecodeNode; import io.airlift.bytecode.Scope; import io.airlift.bytecode.Variable; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.awt.Point; import java.lang.reflect.Field; @@ -30,28 +30,29 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.constantString; import static io.airlift.bytecode.expression.BytecodeExpressions.newInstance; import static io.airlift.bytecode.expression.BytecodeExpressions.setStatic; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestSetFieldBytecodeExpression { + @SuppressWarnings({"WeakerAccess", "PublicField"}) public static String testField; @Test - public void testSetField() + void testSetField() throws Exception { assertSetPoint(point -> point.setField("x", constantInt(42))); assertSetPoint(point -> point.setField(field(Point.class, "x"), constantInt(42))); } - public static void assertSetPoint(Function setX) + private static void assertSetPoint(Function setX) throws Exception { Function nodeGenerator = scope -> { Variable point = scope.declareVariable(Point.class, "point"); BytecodeExpression setExpression = setX.apply(point); - assertEquals(setExpression.toString(), "point.x = 42;"); + assertThat(setExpression.toString()).isEqualTo("point.x = 42;"); return new BytecodeBlock() .append(point.set(newInstance(Point.class, constantInt(3), constantInt(7)))) @@ -63,7 +64,7 @@ public static void assertSetPoint(Function clazz, String name) diff --git a/src/test/java/io/airlift/bytecode/expression/TestSetVariableBytecodeExpression.java b/src/test/java/io/airlift/bytecode/expression/TestSetVariableBytecodeExpression.java index 44a6cc5..9d32d99 100644 --- a/src/test/java/io/airlift/bytecode/expression/TestSetVariableBytecodeExpression.java +++ b/src/test/java/io/airlift/bytecode/expression/TestSetVariableBytecodeExpression.java @@ -17,7 +17,7 @@ import io.airlift.bytecode.BytecodeNode; import io.airlift.bytecode.Scope; import io.airlift.bytecode.Variable; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.awt.Point; import java.util.function.Function; @@ -27,17 +27,17 @@ import static io.airlift.bytecode.expression.BytecodeExpressions.constantInt; import static io.airlift.bytecode.expression.BytecodeExpressions.constantLong; import static io.airlift.bytecode.expression.BytecodeExpressions.newInstance; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; -public class TestSetVariableBytecodeExpression +class TestSetVariableBytecodeExpression { @Test - public void testIncrement() + void testIncrement() throws Exception { assertBytecodeNode(scope -> { Variable byteValue = scope.declareVariable(byte.class, "byte"); - assertEquals(byteValue.increment().toString(), "byte++;"); + assertThat(byteValue.increment().toString()).isEqualTo("byte++;"); return new BytecodeBlock() .append(byteValue.set(constantInt(0))) .append(byteValue.increment()) @@ -46,7 +46,7 @@ public void testIncrement() assertBytecodeNode(scope -> { Variable shortValue = scope.declareVariable(short.class, "short"); - assertEquals(shortValue.increment().toString(), "short++;"); + assertThat(shortValue.increment().toString()).isEqualTo("short++;"); return new BytecodeBlock() .append(shortValue.set(constantInt(0))) .append(shortValue.increment()) @@ -55,7 +55,7 @@ public void testIncrement() assertBytecodeNode(scope -> { Variable intValue = scope.declareVariable(int.class, "int"); - assertEquals(intValue.increment().toString(), "int++;"); + assertThat(intValue.increment().toString()).isEqualTo("int++;"); return new BytecodeBlock() .append(intValue.set(constantInt(0))) .append(intValue.increment()) @@ -64,7 +64,7 @@ public void testIncrement() assertBytecodeNode(scope -> { Variable longValue = scope.declareVariable(long.class, "long"); - assertEquals(longValue.increment().toString(), "long = (long + 1L);"); + assertThat(longValue.increment().toString()).isEqualTo("long = (long + 1L);"); return new BytecodeBlock() .append(longValue.set(constantLong(0))) .append(longValue.increment()) @@ -73,14 +73,14 @@ public void testIncrement() } @Test - public void testGetField() + void testGetField() throws Exception { Function nodeGenerator = scope -> { Variable point = scope.declareVariable(Point.class, "point"); BytecodeExpression setPoint = point.set(newInstance(Point.class, constantInt(3), constantInt(7))); - assertEquals(setPoint.toString(), "point = new Point(3, 7);"); + assertThat(setPoint.toString()).isEqualTo("point = new Point(3, 7);"); return new BytecodeBlock() .append(setPoint) From 5606b9db0cfd0d132a485e16029c1aca0f6aae43 Mon Sep 17 00:00:00 2001 From: Dain Sundstrom Date: Wed, 7 Aug 2024 21:06:53 -0700 Subject: [PATCH 4/4] Update CI build --- .github/workflows/ci.yml | 19 +- .mvn/wrapper/maven-wrapper.properties | 19 ++ mvnw | 259 ++++++++++++++++++++++++++ 3 files changed, 288 insertions(+), 9 deletions(-) create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100755 mvnw diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5750c5..c16216c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,16 +8,17 @@ jobs: build: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - java: + java-version: - 17 steps: - - uses: actions/checkout@v2 - - name: Setup JDK ${{ matrix.java }} - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: - java-version: ${{ matrix.java }} - - name: Maven Install Dependencies - run: mvn install -B -V -DskipTests -Dair.check.skip-all - - name: Maven Test - run: mvn install -B + distribution: 'temurin' + java-version: ${{ matrix.java-version }} + - name: Maven Install + run: ./mvnw install -B -V -DskipTests -Dair.check.skip-all + - name: Maven Tests + run: ./mvnw install -B -P ci \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..f95f1ee --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..3a28521 --- /dev/null +++ b/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" \ No newline at end of file