From d75c84a1aa5535b084c61aa0428555a36621c0e2 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sat, 2 Dec 2023 12:19:14 +0100 Subject: [PATCH] Drop J2ObjC compiler - build requires MacOS and external software J2ObjC - J2ObjC support max JDK 11 - looks like not used feature - there is replacement https://developers.google.com/j2objc/guides/maven-plugin --- .github/workflows/maven.yml | 2 +- README.md | 4 - .../plexus-compiler-j2objc/README.md | 32 -- .../plexus-compiler-j2objc/pom.xml | 58 ---- .../j2objc/DefaultJ2ObjCCompilerParser.java | 51 --- .../compiler/j2objc/J2ObjCCompiler.java | 323 ------------------ .../plexus-compiler-j2objc/src/site/site.xml | 17 - .../compiler/j2objc/J2ObjCCompilerTest.java | 63 ---- .../src/test/resources/de/test/App.java | 13 - plexus-compilers/pom.xml | 1 - 10 files changed, 1 insertion(+), 563 deletions(-) delete mode 100644 plexus-compilers/plexus-compiler-j2objc/README.md delete mode 100644 plexus-compilers/plexus-compiler-j2objc/pom.xml delete mode 100644 plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/DefaultJ2ObjCCompilerParser.java delete mode 100644 plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java delete mode 100644 plexus-compilers/plexus-compiler-j2objc/src/site/site.xml delete mode 100644 plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java delete mode 100644 plexus-compilers/plexus-compiler-j2objc/src/test/resources/de/test/App.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 62df714a..46d3f25b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,5 +30,5 @@ jobs: jdk-matrix: '["11", "17", "21"]' jdk-distribution-matrix: '["zulu", "temurin", "microsoft", "liberica", "corretto"]' os-matrix: '["ubuntu-latest","windows-latest", "macOS-latest"]' - maven_args: 'verify javadoc:javadoc -e -B -V -fae -Pno-tests-if-not-on-osx' + maven_args: 'verify javadoc:javadoc -e -B -V -fae' diff --git a/README.md b/README.md index 9e91b9ff..072dfe01 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,3 @@ This component is an Compilation API used by Apache Maven Compiler plugin on the Please refer to [documentation](https://errorprone.info/docs/installation#maven) Or the project [it test](plexus-compiler-its/src/main/it/error-prone-compiler/pom.xml) - -### J2ObjC OSX - -To compile this project on OSX, you need to have J2ObjC installed: [J2ObjC Requirements](https://developers.google.com/j2objc#requirements). diff --git a/plexus-compilers/plexus-compiler-j2objc/README.md b/plexus-compilers/plexus-compiler-j2objc/README.md deleted file mode 100644 index 15c349f6..00000000 --- a/plexus-compilers/plexus-compiler-j2objc/README.md +++ /dev/null @@ -1,32 +0,0 @@ -J2ObjC Plexus compiler -=================== - - The J2ObjC Plexus compiler is a tool to compile java source files to objective-c by calling the j2objc tool. - - ``` - - - - maven-compiler-plugin - 3.6.1 - - true - j2objc - ${J2OBJC_DISTRIBUTION}/j2objc - - - objective-c - src/main/java - - - - - org.codehaus.plexus - plexus-compiler-j2objc - 2.10.0-SNAPSHOT - - - - ... - ``` - \ No newline at end of file diff --git a/plexus-compilers/plexus-compiler-j2objc/pom.xml b/plexus-compilers/plexus-compiler-j2objc/pom.xml deleted file mode 100644 index 6aa91bd7..00000000 --- a/plexus-compilers/plexus-compiler-j2objc/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - - - org.codehaus.plexus - plexus-compilers - 2.13.1-SNAPSHOT - - - plexus-compiler-j2objc - - Plexus J2ObjC Compiler - J2ObjC Compiler support for Plexus Compiler component. - - - - org.codehaus.plexus - plexus-utils - - - javax.inject - javax.inject - - - org.junit.jupiter - junit-jupiter-api - test - - - org.hamcrest - hamcrest - test - - - - - - no-tests-if-not-on-osx - - - !mac - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - - - - - - diff --git a/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/DefaultJ2ObjCCompilerParser.java b/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/DefaultJ2ObjCCompilerParser.java deleted file mode 100644 index b68d553b..00000000 --- a/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/DefaultJ2ObjCCompilerParser.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.codehaus.plexus.compiler.j2objc; - -import org.codehaus.plexus.compiler.CompilerMessage; -import org.codehaus.plexus.compiler.CompilerMessage.Kind; - -/** - * Handle the output of J2ObjC - * - * @author lmaitre - */ -public class DefaultJ2ObjCCompilerParser { - - private static String ERROR_PREFIX = "error: "; - - private static String CONVERT_PREFIX = "translating "; - - private static String TRANSLATION_PREFIX = "Translated "; - - /** - * Parse a line of log, reading the error and translating lines. - * - * @param line - * @return The compiler message for this line or null if there is no need of - * a message. - */ - public static CompilerMessage parseLine(String line) { - String file = null; - boolean error = false; - int startline = -1; - int startcolumn = -1; - int endline = -1; - int endcolumn = -1; - String message; - - if (line.startsWith(ERROR_PREFIX)) { - message = line.substring(ERROR_PREFIX.length()); - error = true; - } else if (line.startsWith(CONVERT_PREFIX)) { - message = line; - } else if (line.startsWith(TRANSLATION_PREFIX)) { - message = line; - } else { - System.err.println("Unknown output: " + line); - - return null; - } - - return new CompilerMessage( - file, error ? Kind.ERROR : Kind.NOTE, startline, startcolumn, endline, endcolumn, message); - } -} diff --git a/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java b/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java deleted file mode 100644 index b5c6bccb..00000000 --- a/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java +++ /dev/null @@ -1,323 +0,0 @@ -package org.codehaus.plexus.compiler.j2objc; - -/* - * Copyright 2005 The Apache Software Foundation. - * - * Licensed 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. - */ - -import javax.inject.Named; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.codehaus.plexus.compiler.AbstractCompiler; -import org.codehaus.plexus.compiler.CompilerConfiguration; -import org.codehaus.plexus.compiler.CompilerException; -import org.codehaus.plexus.compiler.CompilerMessage; -import org.codehaus.plexus.compiler.CompilerMessage.Kind; -import org.codehaus.plexus.compiler.CompilerOutputStyle; -import org.codehaus.plexus.compiler.CompilerResult; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.cli.CommandLineException; -import org.codehaus.plexus.util.cli.CommandLineUtils; -import org.codehaus.plexus.util.cli.Commandline; -import org.codehaus.plexus.util.cli.StreamConsumer; -import org.codehaus.plexus.util.cli.WriterStreamConsumer; - -/** - * A plexus compiler which use J2ObjC . It is derived from the CSharpCompiler to - * compile with J2ObjC. - * - * @author Ludovic - * Maître - * - */ -@Named("j2objc") -public class J2ObjCCompiler extends AbstractCompiler { - - private static final String X_BOOTCLASSPATH = "Xbootclasspath"; - - /** - * -J Pass Java , such as -Xmx1G, to the system runtime. - */ - private static final String J_FLAG = "J"; - - /** - * --batch-translate-max= The maximum number of source files that are - * translated. together. Batching speeds up translation, but requires more - * memory. - */ - private static final String BATCH_SIZE = "batch-translate-max"; - - /** - * Put the arguments of j2objc who takes one dash inside an array, in order - * the check the command line. - */ - private static final List ONE_DASH_ARGS = Arrays.asList(new String[] { - "-pluginpath", - "-pluginoptions", - "-t", - "-Xno-jsni-warnings", - "-sourcepath", - "-classpath", - "-d", - "-encoding", - "-g", - "-q", - "-v", - "-Werror", - "-h", - "-use-arc", - "-use-reference-counting", - "-x" - }); - - /** - * Put the command line arguments with 2 dashes inside an array, in order - * the check the command line and build it. - */ - private static final List TWO_DASH_ARGS = Arrays.asList(new String[] { - "--build-closure", - "--dead-code-report", - "--doc-comments", - "--no-extract-unsequenced", - "--generate-deprecated", - "--mapping", - "--no-class-methods", - "--no-final-methods-functions", - "--no-hide-private-members", - "--no-package-directories", - "--prefix", - "--prefixes", - "--preserve-full-paths", - "--strip-gwt-incompatible", - "--strip-reflection", - "--segmented-headers", - "--timing-info", - "--quiet", - "--verbose", - "--help" - }); - - public J2ObjCCompiler() { - super(CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE, ".java", null, null); - } - - // ---------------------------------------------------------------------- - // Compiler Implementation - // ---------------------------------------------------------------------- - - @Override - public String getCompilerId() { - return "j2objc"; - } - - public boolean canUpdateTarget(CompilerConfiguration configuration) throws CompilerException { - return false; - } - - public CompilerResult performCompile(CompilerConfiguration config) throws CompilerException { - File destinationDir = new File(config.getOutputLocation()); - if (!destinationDir.exists()) { - destinationDir.mkdirs(); - } - - config.setSourceFiles(null); - - String[] sourceFiles = J2ObjCCompiler.getSourceFiles(config); - - if (sourceFiles.length == 0) { - return new CompilerResult().success(true); - } - - logCompiling(sourceFiles, config); - - String[] args = buildCompilerArguments(config, sourceFiles); - - List messages; - - if (config.isFork()) { - messages = compileOutOfProcess( - config.getWorkingDirectory(), config.getBuildDirectory(), findExecutable(config), args); - } else { - throw new CompilerException("This compiler doesn't support in-process compilation."); - } - - return new CompilerResult().compilerMessages(messages); - } - - public String[] createCommandLine(CompilerConfiguration config) throws CompilerException { - return buildCompilerArguments(config, J2ObjCCompiler.getSourceFiles(config)); - } - - /** - * Find the executable given in the configuration or use j2objc from the - * PATH. - * - * @param config - * @return the List of args - */ - private String findExecutable(CompilerConfiguration config) { - String executable = config.getExecutable(); - - if (!StringUtils.isEmpty(executable)) { - return executable; - } - - return "j2objc"; - } - - /** - * Build the compiler arguments : - *
  • the output location is used for -d of j2objc) - *
  • the classpath entries are added to -classpath - *
  • the sourcefiles are listed at the end of the command line - *
  • the configuration can contain any of the arguments - * - * @param config - * @param sourceFiles - * @return The List to give to the command line tool - * @throws CompilerException - */ - private String[] buildCompilerArguments(CompilerConfiguration config, String[] sourceFiles) - throws CompilerException { - /* - * j2objc --help Usage: j2objc - */ - List args = new ArrayList<>(); - Map compilerArguments = config.getCustomCompilerArgumentsAsMap(); - - // Verbose - if (config.isVerbose()) { - args.add("-v"); - } - - // Destination/output directory - args.add("-d"); - args.add(config.getOutputLocation()); - - if (!config.getClasspathEntries().isEmpty()) { - List classpath = new ArrayList<>(); - for (String element : config.getClasspathEntries()) { - File f = new File(element); - classpath.add(f.getAbsolutePath()); - - classpath.add(element); - } - args.add("-classpath"); - args.add(StringUtils.join(classpath.toArray(), File.pathSeparator)); - } - - if (config.isVerbose()) { - System.out.println("Args: "); - } - - for (String k : compilerArguments.keySet()) { - if (config.isVerbose()) { - System.out.println(k + "=" + compilerArguments.get(k)); - } - String v = compilerArguments.get(k); - if (J_FLAG.equals(k)) { - args.add(J_FLAG + v); - } else if (X_BOOTCLASSPATH.equals(k)) { - args.add(X_BOOTCLASSPATH + ":" + v); - } else if (BATCH_SIZE.equals(k)) { - args.add("-" + BATCH_SIZE + "=" + v); - } else { - if (TWO_DASH_ARGS.contains(k)) { - args.add("-" + k); - } else if (ONE_DASH_ARGS.contains(k)) { - args.add(k); - } else { - throw new IllegalArgumentException("The argument " + k + " isnt't a flag recognized by J2ObjC."); - } - if (v != null) { - args.add(v); - } - } - } - - for (String sourceFile : sourceFiles) { - args.add(sourceFile); - } - - return args.toArray(new String[args.size()]); - } - - private List compileOutOfProcess( - File workingDirectory, File target, String executable, String[] args) throws CompilerException { - - Commandline cli = new Commandline(); - - cli.setWorkingDirectory(workingDirectory.getAbsolutePath()); - - cli.setExecutable(executable); - - cli.addArguments(args); - - Writer stringWriter = new StringWriter(); - - StreamConsumer out = new WriterStreamConsumer(stringWriter); - - StreamConsumer err = new WriterStreamConsumer(stringWriter); - - int returnCode; - - List messages; - - try { - returnCode = CommandLineUtils.executeCommandLine(cli, out, err); - - messages = parseCompilerOutput(new BufferedReader(new StringReader(stringWriter.toString()))); - } catch (CommandLineException | IOException e) { - throw new CompilerException("Error while executing the external compiler.", e); - } - - if (returnCode != 0 && messages.isEmpty()) { - // TODO: exception? - messages.add(new CompilerMessage( - "Failure executing the compiler, but could not parse the error:" + EOL + stringWriter.toString(), - Kind.ERROR)); - } - - return messages; - } - - public static List parseCompilerOutput(BufferedReader bufferedReader) throws IOException { - List messages = new ArrayList<>(); - - String line = bufferedReader.readLine(); - System.out.println("start output"); - while (line != null) { - System.out.println(line); - CompilerMessage compilerError = DefaultJ2ObjCCompilerParser.parseLine(line); - - if (compilerError != null) { - messages.add(compilerError); - } - - line = bufferedReader.readLine(); - } - System.out.println("end output"); - return messages; - } -} diff --git a/plexus-compilers/plexus-compiler-j2objc/src/site/site.xml b/plexus-compilers/plexus-compiler-j2objc/src/site/site.xml deleted file mode 100644 index 38cbad8a..00000000 --- a/plexus-compilers/plexus-compiler-j2objc/src/site/site.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java b/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java deleted file mode 100644 index 1107e272..00000000 --- a/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.codehaus.plexus.compiler.j2objc; - -/** - * The MIT License - *

    - * Copyright (c) 2005, The Codehaus - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -import java.io.File; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import org.codehaus.plexus.compiler.CompilerConfiguration; -import org.hamcrest.io.FileMatchers; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * j2objc must be in the PATH - * @author lmaitre - */ -public class J2ObjCCompilerTest { - - @Test - public void testJ2ObjCCompiler() throws Exception { - J2ObjCCompiler comp = new J2ObjCCompiler(); - Map customCompilerArguments = new HashMap<>(); - customCompilerArguments.put("-use-arc", null); - customCompilerArguments.put("-sourcepath", "src/test/resources"); - CompilerConfiguration cc = new CompilerConfiguration(); - cc.setOutputLocation("target/generated/objective-c"); - cc.setSourceLocations(Arrays.asList(new String[] {"src/test/resources"})); - cc.setWorkingDirectory(new File(".")); - cc.setFork(true); - cc.setVerbose(true); - cc.setCustomCompilerArgumentsAsMap(customCompilerArguments); - - comp.performCompile(cc); - File f = new File("target/generated/objective-c/de/test/App.h"); - assertThat("file not exists:" + f, f, FileMatchers.anExistingFile()); - f = new File("target/generated/objective-c/de/test/App.m"); - assertThat("file not exists:" + f, f, FileMatchers.anExistingFile()); - } -} diff --git a/plexus-compilers/plexus-compiler-j2objc/src/test/resources/de/test/App.java b/plexus-compilers/plexus-compiler-j2objc/src/test/resources/de/test/App.java deleted file mode 100644 index 4ee7ddac..00000000 --- a/plexus-compilers/plexus-compiler-j2objc/src/test/resources/de/test/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.test; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} diff --git a/plexus-compilers/pom.xml b/plexus-compilers/pom.xml index 13a8f086..820c650e 100644 --- a/plexus-compilers/pom.xml +++ b/plexus-compilers/pom.xml @@ -19,7 +19,6 @@ plexus-compiler-eclipse plexus-compiler-javac plexus-compiler-javac-errorprone - plexus-compiler-j2objc