Skip to content

Commit

Permalink
Update Eclipse JDT/ECJ
Browse files Browse the repository at this point in the history
This raises runtime requirement to Java 17, but with a twist:
to support older Maven versions (3.6, 3.8) that use ancient
Eclipse Sisu that support gleaning of Java 14 bytecode (to
discover components), the plugin itself remains Java 11.
  • Loading branch information
cstamas committed Nov 18, 2024
1 parent b763e32 commit 60ce770
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 55 deletions.
19 changes: 15 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>io.takari</groupId>
<artifactId>takari</artifactId>
<version>60</version>
<version>63</version>
</parent>

<groupId>io.takari.maven.plugins</groupId>
Expand All @@ -36,16 +36,27 @@
</scm>

<properties>
<!--
Note: actual runtime requirement is Java 17+ due Eclipse JDT/ECJ!
But, to support Maven 3.6/3.8 that use ancient Eclipse Sisu, we cannot
create components having bytecode newer than Java 14.
So we cheat here: we create components having bytecode Java 11 to make them
discoverable, but takari-lifecycle due dependencies is in fact Java 17+
-->
<takari.javaSourceVersion>11</takari.javaSourceVersion>

<mavenVersion>3.9.9</mavenVersion>
<aetherVersion>1.9.22</aetherVersion>
<sisuVersion>0.9.0.M3</sisuVersion>
<incrementalbuild.version>1.0.3</incrementalbuild.version>
<guava.version>33.3.0-jre</guava.version>
<mavenPluginPluginVersion>3.15.0</mavenPluginPluginVersion>
<mavenPluginPluginVersion>3.15.1</mavenPluginPluginVersion>
<m2eWorkspaceVersion>0.4.0</m2eWorkspaceVersion>
<plexusUtilsVersion>4.0.1</plexusUtilsVersion>
<plexusUtilsVersion>4.0.2</plexusUtilsVersion>
<plexusXmlVersion>3.0.1</plexusXmlVersion>
<pluginTestingVersion>3.0.5</pluginTestingVersion>

<!-- UT and IT only! -->
<guava.version>33.3.1-jre</guava.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.junit.runner.RunWith;

@RunWith(MavenJUnitTestRunner.class)
@MavenVersions({"3.6.3", "3.8.8", "3.9.6"})
@MavenVersions({"3.6.3", "3.8.8", "3.9.9"})
public abstract class AbstractIntegrationTest {

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import static io.takari.maven.testing.TestResources.assertFilesPresent;

import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import io.takari.maven.testing.executor.MavenExecutionResult;
import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.junit.Assert;
Expand Down Expand Up @@ -106,7 +106,7 @@ private String readZipFileEntryUTF8(File zipFile, String entryPath) throws IOExc
}

private String readFileUTF8(File file) throws IOException {
return Files.toString(file, StandardCharsets.UTF_8);
return Files.readString(file.toPath(), StandardCharsets.UTF_8);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -40,7 +41,7 @@ private Properties filter(MavenExecution verifierBuilder) throws Exception {

Properties properties = new Properties();
InputStream is = new FileInputStream(new File(result.getBasedir(), "target/classes/filtered.properties"));
Reader reader = new InputStreamReader(is, "UTF-8");
Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8);
try {
properties.load(reader);
} finally {
Expand Down
10 changes: 5 additions & 5 deletions takari-lifecycle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-java</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -136,7 +136,7 @@
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.33.0</version>
<version>3.39.0</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand All @@ -147,7 +147,7 @@
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.33.0</version>
<version>3.39.0</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand All @@ -158,7 +158,7 @@
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.18.600</version>
<version>3.21.0</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand Down Expand Up @@ -266,7 +266,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.7</version>
<version>9.7.1</version>
<scope>test</scope>
</dependency>
<!-- testing deploy -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public NameEnvironmentAnswer findType(String packageName, String typeName, Acces
if (classFile != null) {
try (InputStream is = Files.newInputStream(classFile)) {
return new NameEnvironmentAnswer(
ClassFileReader.read(is, classFile.getFileName().toString(), false), accessRestriction);
ClassFileReader.read(is, classFile.getFileName().toString()), accessRestriction);
}
}
} catch (ClassFormatException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.takari.resources.filtering.ResourcesProcessor;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -70,6 +71,10 @@ public abstract class AbstractProcessResourcesMojo extends TakariLifecycleMojo {
private BuildContext context;

protected void process(List<Resource> resources, File outputDirectory) throws MojoExecutionException {
if (encoding == null) {
getLog().warn("Using platform encoding to process resources, i.e. build is platform dependent!");
}
Charset charset = encoding == null ? Charset.defaultCharset() : Charset.forName(encoding);
for (Resource resource : resources) {
boolean filter = Boolean.parseBoolean(resource.getFiltering());
try {
Expand All @@ -86,7 +91,7 @@ protected void process(List<Resource> resources, File outputDirectory) throws Mo
targetDirectory = outputDirectory;
}
if (filter) {
Map<Object, Object> properties = new HashMap<Object, Object>(this.properties);
Map<Object, Object> properties = new HashMap<>(this.properties);
properties.putAll(sessionProperties); // command line parameters win over project properties
properties.put("project", project);
properties.put(
Expand All @@ -105,7 +110,7 @@ protected void process(List<Resource> resources, File outputDirectory) throws Mo
resource.getExcludes(),
properties,
filters,
encoding,
charset,
missingPropertyAction);
} else {
processor.process(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -51,7 +53,7 @@ public void process(
List<String> excludes,
Map<Object, Object> filterProperties,
List<File> filters,
String encoding,
Charset encoding,
MissingPropertyAction mpa)
throws IOException {
Map<Object, Object> effectiveProperties = new HashMap<>(filterProperties);
Expand Down Expand Up @@ -82,7 +84,7 @@ private void filterResource(
File sourceDirectory,
File targetDirectory,
Map<Object, Object> filterProperties,
String encoding,
Charset encoding,
MissingPropertyAction mpa)
throws IOException {
File outputFile = relativize(sourceDirectory, targetDirectory, input.getResource());
Expand All @@ -102,17 +104,17 @@ public void filter(
mustache.execute(writer, properties).close();
}

private Reader newReader(Resource<File> resource, String encoding) throws IOException {
private Reader newReader(Resource<File> resource, Charset encoding) throws IOException {
if (encoding == null) {
return new FileReader(resource.getResource());
return new FileReader(resource.getResource(), StandardCharsets.UTF_8);
} else {
return new InputStreamReader(new FileInputStream(resource.getResource()), encoding);
}
}

private Writer newWriter(Output<File> output, String encoding) throws IOException {
private Writer newWriter(Output<File> output, Charset encoding) throws IOException {
if (encoding == null) {
return new OutputStreamWriter(output.newOutputStream());
return new OutputStreamWriter(output.newOutputStream(), StandardCharsets.UTF_8);
} else {
return new OutputStreamWriter(output.newOutputStream(), encoding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -45,7 +46,7 @@ public void process(
List<String> includes,
List<String> excludes,
Map<Object, Object> filterProperties,
String encoding,
Charset encoding,
MissingPropertyAction mpa)
throws IOException {
filterProcessor.process(
Expand All @@ -66,7 +67,7 @@ public void process(
List<String> excludes,
Map<Object, Object> filterProperties,
List<File> filters,
String encoding,
Charset encoding,
MissingPropertyAction mpa)
throws IOException {
filterProcessor.process(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeTrue;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import io.takari.maven.plugins.compile.javac.CompilerJavac;
import io.takari.maven.plugins.compile.jdt.CompilerJdt;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -228,7 +228,8 @@ public void testClasspath_dependencySourceTypes_ignore() throws Exception {
// assert the compiler uses .class file when dependencySourceTypes=ignore

File dependency = compile("compile/basic");
Files.write("corrupted", new File(dependency, "target/classes/basic/Basic.java"), Charsets.UTF_8);
Files.writeString(
new File(dependency, "target/classes/basic/Basic.java").toPath(), "corrupted", StandardCharsets.UTF_8);
touch(new File(dependency, "target/classes/basic/Basic.java")); // javac will pick newer file by default

File basedir = resources.getBasedir("compile/classpath");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static io.takari.maven.testing.TestResources.create;

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import io.takari.maven.plugins.compile.CompilerBuildContext;
import io.takari.maven.plugins.compile.jdt.classpath.Classpath;
Expand All @@ -14,6 +13,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -45,7 +45,7 @@ public class FilerImplTest {

@Test
public void testGetResource_unsupportedLocation() throws Exception {
EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8);
EclipseFileManager fileManager = new EclipseFileManager(null, StandardCharsets.UTF_8);

FilerImpl filer = new FilerImpl(null /* context */, fileManager, null /* compiler */, null /* env */);

Expand All @@ -59,7 +59,7 @@ public void testGetResource_unsupportedLocation() throws Exception {

@Test
public void testGetResource_location_classpath() throws Exception {
EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8);
EclipseFileManager fileManager = new EclipseFileManager(null, StandardCharsets.UTF_8);

List<File> classpath = new ArrayList<>();
classpath.add(new File("src/test/projects/compile-jdt-proc/getresource-location-classpath/classes"));
Expand All @@ -78,13 +78,13 @@ public void testGetResource_location_classpath() throws Exception {

private static String toString(FileObject file) throws IOException {
try (InputStream is = file.openInputStream()) {
return CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8));
return CharStreams.toString(new InputStreamReader(is, StandardCharsets.UTF_8));
}
}

@Test
public void testRecreateSourceFile() throws Exception {
EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8);
EclipseFileManager fileManager = new EclipseFileManager(null, StandardCharsets.UTF_8);

File outputDir = temp.newFolder();
fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outputDir));
Expand All @@ -105,7 +105,7 @@ public void testRecreateSourceFile() throws Exception {

@Test
public void testRecreateResource() throws Exception {
EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8);
EclipseFileManager fileManager = new EclipseFileManager(null, StandardCharsets.UTF_8);

File outputDir = temp.newFolder();
fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outputDir));
Expand Down Expand Up @@ -149,7 +149,7 @@ public void testBinaryOriginatingElements() throws Exception {
Compiler compiler =
new Compiler(namingEnvironment, errorHandlingPolicy, compilerOptions, requestor, problemFactory);

EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8);
EclipseFileManager fileManager = new EclipseFileManager(null, StandardCharsets.UTF_8);
File outputDir = temp.newFolder();
fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outputDir));

Expand All @@ -167,7 +167,7 @@ public void testBinaryOriginatingElements() throws Exception {

@Test
public void testResourceDoesNotExist() throws Exception {
EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8);
EclipseFileManager fileManager = new EclipseFileManager(null, StandardCharsets.UTF_8);

File outputDir = temp.newFolder();
fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outputDir));
Expand Down
Loading

0 comments on commit 60ce770

Please sign in to comment.