Removed kapt options (failed)
This commit is contained in:
parent
8769bf1884
commit
d8156fe871
4 changed files with 5 additions and 383 deletions
|
@ -1,27 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2023 the original author or authors.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package rife.bld.extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The apt ({@code kapt}) required modes.
|
|
||||||
*
|
|
||||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
public enum AptMode {
|
|
||||||
STUBS, APT, STUBS_AND_APT
|
|
||||||
}
|
|
|
@ -46,7 +46,6 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
private File buildMainDirectory_;
|
private File buildMainDirectory_;
|
||||||
private File buildTestDirectory_;
|
private File buildTestDirectory_;
|
||||||
private CompileKotlinOptions compileOptions_;
|
private CompileKotlinOptions compileOptions_;
|
||||||
private KaptOptions kaptOptions_;
|
|
||||||
private BaseProject project_;
|
private BaseProject project_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,6 +214,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
executeCreateBuildDirectories();
|
executeCreateBuildDirectories();
|
||||||
executeBuildMainSources();
|
executeBuildMainSources();
|
||||||
executeBuildTestSources();
|
executeBuildTestSources();
|
||||||
|
|
||||||
if (!silent()) {
|
if (!silent()) {
|
||||||
System.out.println("Kotlin compilation finished successfully.");
|
System.out.println("Kotlin compilation finished successfully.");
|
||||||
}
|
}
|
||||||
|
@ -260,8 +260,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
|
|
||||||
// friend-path
|
// friend-path
|
||||||
if (friendPaths != null) {
|
if (friendPaths != null) {
|
||||||
args.add("-Xfriend-paths");
|
args.add("-Xfriend-paths=" + friendPaths.getAbsolutePath());
|
||||||
args.add(friendPaths.getAbsolutePath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// options
|
// options
|
||||||
|
@ -269,21 +268,6 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
args.addAll(compileOptions_.args());
|
args.addAll(compileOptions_.args());
|
||||||
}
|
}
|
||||||
|
|
||||||
// kapt plugin & options
|
|
||||||
if (kaptOptions_ != null) {
|
|
||||||
var kaptJar = getJarList(project_.libBldDirectory(), "^.*kotlin-annotation-processing.*\\.jar$");
|
|
||||||
if (kaptJar.size() == 1) {
|
|
||||||
args.add("-Xplugin=" + kaptJar.get(0));
|
|
||||||
kaptOptions_.args().forEach(a -> {
|
|
||||||
args.add("-P");
|
|
||||||
args.add(a);
|
|
||||||
});
|
|
||||||
} else if (LOGGER.isLoggable(Level.WARNING)) {
|
|
||||||
LOGGER.warning("Could not locate the Kotlin annotation processing JAR in:" +
|
|
||||||
project_.libBldDirectory().getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// sources
|
// sources
|
||||||
sources.forEach(f -> args.add(f.getAbsolutePath()));
|
sources.forEach(f -> args.add(f.getAbsolutePath()));
|
||||||
|
|
||||||
|
@ -305,7 +289,8 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
executeBuildSources(
|
executeBuildSources(
|
||||||
compileTestClasspath(),
|
compileTestClasspath(),
|
||||||
sources(testSourceFiles(), testSourceDirectories()),
|
sources(testSourceFiles(), testSourceDirectories()),
|
||||||
buildTestDirectory(), buildMainDirectory());
|
buildTestDirectory(),
|
||||||
|
buildMainDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -345,17 +330,6 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
.testSourceFiles(getKotlinFileList(new File(project.srcTestDirectory(), "kotlin")));
|
.testSourceFiles(getKotlinFileList(new File(project.srcTestDirectory(), "kotlin")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides the annotation processor ({@code kapt} options.
|
|
||||||
*
|
|
||||||
* @param options the {@code kapt} options
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public CompileKotlinOperation kaptOptions(KaptOptions options) {
|
|
||||||
kaptOptions_ = options;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides main source directories that should be compiled.
|
* Provides main source directories that should be compiled.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,325 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2023 the original author or authors.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package rife.bld.extension;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The (@{code kapt}) compiler plugin options,
|
|
||||||
*
|
|
||||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
public class KaptOptions {
|
|
||||||
private final static String PLUGIN_ID = "plugin:org.jetbrains.kotlin.kapt3:";
|
|
||||||
private final Logger LOGGER = Logger.getLogger(KaptOptions.class.getName());
|
|
||||||
private final List<String> apClasspath_ = new ArrayList<>();
|
|
||||||
private final Collection<Map<String, String>> apOptions_ = new ArrayList<>();
|
|
||||||
private final AptMode aptMode_;
|
|
||||||
private final Collection<String> classes_;
|
|
||||||
private final Collection<Map<String, String>> javacArguments_ = new ArrayList<>();
|
|
||||||
private final List<String> processors_ = new ArrayList<>();
|
|
||||||
private final Collection<String> sources_;
|
|
||||||
private final File stubs_;
|
|
||||||
private boolean correctErrorTypes_;
|
|
||||||
private File dumpFileReadHistory_;
|
|
||||||
private File incrementalData_;
|
|
||||||
private boolean verbose_;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* <p>
|
|
||||||
* The application processor mode can be one of the following:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@link AptMode#STUBS stubs} - only generate stubs needed for annotation processing</li>
|
|
||||||
* <li>{@link AptMode#APT apt} - only run annotation processing</li>
|
|
||||||
* <li>{@link AptMode#STUBS_AND_APT stubsAndApt} - generate stubs and run annotation processing.</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param sources an output path for the generated files
|
|
||||||
* @param classes an output path for the generated class files and resources
|
|
||||||
* @param stubs an output path for the stub files. In other words, some temporary directory
|
|
||||||
* @param mode the mode
|
|
||||||
*/
|
|
||||||
KaptOptions(Collection<String> sources, Collection<String> classes, File stubs, AptMode mode) {
|
|
||||||
sources_ = sources;
|
|
||||||
classes_ = classes;
|
|
||||||
stubs_ = stubs;
|
|
||||||
aptMode_ = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* <p>
|
|
||||||
* The application processor mode can be one of the following:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@link AptMode#STUBS stubs} - only generate stubs needed for annotation processing</li>
|
|
||||||
* <li>{@link AptMode#APT apt} - only run annotation processing</li>
|
|
||||||
* <li>{@link AptMode#STUBS_AND_APT stubsAndApt} - generate stubs and run annotation processing.</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param sources an output path for the generated files
|
|
||||||
* @param classes an output path for the generated class files and resources
|
|
||||||
* @param stubs an output path for the stub files. In other words, some temporary directory
|
|
||||||
* @param mode the mode
|
|
||||||
*/
|
|
||||||
KaptOptions(Collection<String> sources, Collection<String> classes, String stubs, AptMode mode) {
|
|
||||||
this(sources, classes, new File(stubs), mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A path to the annotation processor JAR. Pass as many classpath as the number of JARs that you have.
|
|
||||||
*
|
|
||||||
* @param apClasspath the list of classpath
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions apClasspath(Collection<String> apClasspath) {
|
|
||||||
apClasspath_.addAll(apClasspath);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A path to the annotation processor JAR. Pass as many classpath as the number of JARs that you have.
|
|
||||||
*
|
|
||||||
* @param apClasspath one or more classpath
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions apClasspath(String... apClasspath) {
|
|
||||||
apClasspath_.addAll(List.of(apClasspath));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of the annotation processor options.
|
|
||||||
*
|
|
||||||
* @param apOptions the list of options
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions apOptions(Map<String, String> apOptions) {
|
|
||||||
apOptions_.add(apOptions);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted arguments.
|
|
||||||
*
|
|
||||||
* @return the arguments
|
|
||||||
*/
|
|
||||||
public List<String> args() {
|
|
||||||
var args = new ArrayList<String>();
|
|
||||||
|
|
||||||
// sources
|
|
||||||
if (!sources_.isEmpty()) {
|
|
||||||
sources_.forEach(s -> args.add(PLUGIN_ID + "sources=" + s));
|
|
||||||
}
|
|
||||||
|
|
||||||
// classes
|
|
||||||
if (!classes_.isEmpty()) {
|
|
||||||
classes_.forEach(c -> args.add(PLUGIN_ID + "classes=" + c));
|
|
||||||
}
|
|
||||||
|
|
||||||
// stubs
|
|
||||||
args.add(PLUGIN_ID + "stubs=" + stubs_.getAbsolutePath());
|
|
||||||
|
|
||||||
// apMode
|
|
||||||
args.add(PLUGIN_ID + "aptMode=" + aptMode_.name().toLowerCase());
|
|
||||||
|
|
||||||
// apclasspath
|
|
||||||
if (!apClasspath_.isEmpty()) {
|
|
||||||
apClasspath_.forEach(c -> args.add(PLUGIN_ID + "apclasspath=" + c));
|
|
||||||
}
|
|
||||||
|
|
||||||
// apoptions
|
|
||||||
if (!apOptions_.isEmpty()) {
|
|
||||||
apOptions_.forEach(o -> {
|
|
||||||
try {
|
|
||||||
args.add(PLUGIN_ID + "apoptions=" + encodeList(o));
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
|
||||||
LOGGER.log(Level.WARNING, "Could not encode application processor option: " + o, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// correctErrorTypes
|
|
||||||
if (correctErrorTypes_) {
|
|
||||||
args.add(PLUGIN_ID + "correctErrorTypes=true");
|
|
||||||
}
|
|
||||||
|
|
||||||
// dumpFileReadHistory
|
|
||||||
if (dumpFileReadHistory_ != null) {
|
|
||||||
args.add(PLUGIN_ID + "dumpFileReadHistory=" + dumpFileReadHistory_.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
// incrementalData
|
|
||||||
if (incrementalData_ != null) {
|
|
||||||
args.add(PLUGIN_ID + "incrementalData=" + incrementalData_.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
// javacArguments
|
|
||||||
if (!javacArguments_.isEmpty()) {
|
|
||||||
javacArguments_.forEach(a -> {
|
|
||||||
try {
|
|
||||||
args.add(PLUGIN_ID + "javacArguments=" + encodeList(a));
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
|
||||||
LOGGER.log(Level.WARNING, "Could not encode javac argument: " + a, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// processors
|
|
||||||
if (!processors_.isEmpty()) {
|
|
||||||
args.add(PLUGIN_ID + "processors=" + String.join(",", processors_));
|
|
||||||
}
|
|
||||||
|
|
||||||
// verbose
|
|
||||||
if (verbose_) {
|
|
||||||
args.add(PLUGIN_ID + "verbose=true");
|
|
||||||
}
|
|
||||||
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To enable error type inferring in stubs.
|
|
||||||
* <p>
|
|
||||||
* Some annotation processors (such as {@code AutoFactory}) rely on precise types in declaration signatures. By
|
|
||||||
* default, {@code kapt} replaces every unknown type (including types for the generated classes) to
|
|
||||||
* {@code NonExistentClass}, but you use this option to change this behavior.
|
|
||||||
*
|
|
||||||
* @param correctErrorTypes {@code true} or {@code false}
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions correctErrorTypes(boolean correctErrorTypes) {
|
|
||||||
correctErrorTypes_ = correctErrorTypes;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An output path to dump for each file a list of classes used during annotation processing.
|
|
||||||
*
|
|
||||||
* @param dupFileReadHistory the output path
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions dupFileReadHistory(File dupFileReadHistory) {
|
|
||||||
dumpFileReadHistory_ = dupFileReadHistory;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An output path to dump for each file a list of classes used during annotation processing.
|
|
||||||
*
|
|
||||||
* @param dupFileReadHistory the output path
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions dupFileReadHistory(String dupFileReadHistory) {
|
|
||||||
dumpFileReadHistory_ = new File(dupFileReadHistory);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Base-64 encodes the options list
|
|
||||||
private String encodeList(Map<String, String> options) throws IOException {
|
|
||||||
var os = new ByteArrayOutputStream();
|
|
||||||
var oos = new ObjectOutputStream(os);
|
|
||||||
|
|
||||||
oos.writeInt(options.size());
|
|
||||||
for (var entry : options.entrySet()) {
|
|
||||||
oos.writeUTF(entry.getKey());
|
|
||||||
oos.writeUTF(entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
oos.flush();
|
|
||||||
return Base64.getEncoder().encodeToString(os.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An output path for the binary stubs.
|
|
||||||
*
|
|
||||||
* @param incrementalData the output path
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions incrementalData(File incrementalData) {
|
|
||||||
incrementalData_ = incrementalData;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An output path for the binary stubs.
|
|
||||||
*
|
|
||||||
* @param incrementalData the output path
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions incrementalData(String incrementalData) {
|
|
||||||
incrementalData_ = new File(incrementalData);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of the options passed to {@code javac}.
|
|
||||||
*
|
|
||||||
* @param javacArguments the {@code javac} arguments
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions javacArguments(Map<String, String> javacArguments) {
|
|
||||||
javacArguments_.add(javacArguments);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of annotation processor qualified class names. If specified, {@code kapt} does not try to find annotation
|
|
||||||
* processors in {@link #apClasspath}.
|
|
||||||
*
|
|
||||||
* @param processors the list of qualified class names
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions processors(Collection<String> processors) {
|
|
||||||
processors_.addAll(processors);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of annotation processor qualified class names. If specified, {@code kapt} does not try to find annotation
|
|
||||||
* processors in {@link #apClasspath}.
|
|
||||||
*
|
|
||||||
* @param processors one or moe qualified class names
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions processors(String... processors) {
|
|
||||||
processors_.addAll(List.of(processors));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables verbose output.
|
|
||||||
*
|
|
||||||
* @param verbose {@code true} or {@code false}
|
|
||||||
* @return this class instance
|
|
||||||
*/
|
|
||||||
public KaptOptions verbose(boolean verbose) {
|
|
||||||
verbose_ = verbose;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -219,7 +219,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
||||||
/**
|
/**
|
||||||
* Configures the operation from a {@link BaseProject}.
|
* Configures the operation from a {@link BaseProject}.
|
||||||
* <p>
|
* <p>
|
||||||
* Sets the {@link #sourceSet} and {@link #moduleName} from the project.
|
* Sets the {@link #sourceSet sourceSet} and {@link #moduleName moduleName} from the project.
|
||||||
*
|
*
|
||||||
* @param project the project to configure the operation from
|
* @param project the project to configure the operation from
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue