Minor, fix style issues in kotlin-maven-plugin
This commit is contained in:
+1
-2
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.kotlin.maven;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
@@ -65,7 +64,7 @@ public class JSSourceJarMojo extends AbstractMojo {
|
||||
}
|
||||
}
|
||||
if (definitionSourceDir != null) {
|
||||
if (!librarySourceDir.exists()) {
|
||||
if (!definitionSourceDir.exists()) {
|
||||
getLog().warn("Definition directory does not exist: " + definitionSourceDir);
|
||||
} else {
|
||||
try {
|
||||
|
||||
+7
-6
@@ -18,18 +18,19 @@ package org.jetbrains.kotlin.maven;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.io.InputSupplier;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
|
||||
import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments;
|
||||
import org.jetbrains.jet.cli.js.K2JSCompiler;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.k2js.config.MetaInfServices;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -81,7 +82,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
super.execute();
|
||||
if (appendLibraryJS != null && appendLibraryJS.booleanValue()) {
|
||||
if (appendLibraryJS != null && appendLibraryJS) {
|
||||
try {
|
||||
Charset charset = Charset.defaultCharset();
|
||||
File file = new File(outputFile);
|
||||
@@ -97,7 +98,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
||||
throw new MojoExecutionException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (copyLibraryJS != null && copyLibraryJS.booleanValue()) {
|
||||
if (copyLibraryJS != null && copyLibraryJS) {
|
||||
getLog().info("Copying kotlin JS library to " + outputKotlinJSDir);
|
||||
|
||||
copyJsLibraryFile(KOTLIN_JS_MAPS);
|
||||
@@ -107,7 +108,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
||||
}
|
||||
}
|
||||
|
||||
protected void appendFile(String jsLib, StringBuilder builder) throws MojoExecutionException {
|
||||
private static void appendFile(String jsLib, StringBuilder builder) throws MojoExecutionException {
|
||||
// lets copy the kotlin library into the output directory
|
||||
try {
|
||||
final InputStream inputStream = MetaInfServices.loadClasspathResource(jsLib);
|
||||
|
||||
+18
-20
@@ -47,8 +47,6 @@ import java.util.zip.ZipFile;
|
||||
import static com.intellij.openapi.util.text.StringUtil.join;
|
||||
|
||||
public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
|
||||
|
||||
// TODO it would be nice to avoid using 2 injected fields for sources
|
||||
// but I've not figured out how to have a defaulted parameter value
|
||||
// which is also customisable inside an <execution> in a maven pom.xml
|
||||
@@ -182,10 +180,10 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
}
|
||||
}
|
||||
|
||||
final CommonCompilerArguments arguments = createCompilerArguments();
|
||||
CommonCompilerArguments arguments = createCompilerArguments();
|
||||
configureCompilerArguments(arguments);
|
||||
|
||||
final CLICompiler compiler = createCompiler();
|
||||
CLICompiler compiler = createCompiler();
|
||||
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
|
||||
|
||||
final Log log = getLog();
|
||||
@@ -209,14 +207,14 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
}
|
||||
};
|
||||
|
||||
final ExitCode exitCode = executeCompiler(compiler, arguments, messageCollector);
|
||||
ExitCode exitCode = executeCompiler(compiler, arguments, messageCollector);
|
||||
|
||||
switch (exitCode) {
|
||||
case COMPILATION_ERROR:
|
||||
throw new MojoExecutionException("Compilation error. See log for more details");
|
||||
|
||||
case INTERNAL_ERROR:
|
||||
throw new MojoExecutionException("Internal compiler error. See log for more details");
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,7 +278,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
// don't include runtime, it should be in maven dependencies
|
||||
arguments.noStdlib = true;
|
||||
|
||||
final ArrayList<String> classpathList = new ArrayList<String>();
|
||||
ArrayList<String> classpathList = new ArrayList<String>();
|
||||
|
||||
if (module != null) {
|
||||
log.info("Compiling Kotlin module " + module);
|
||||
@@ -361,20 +359,20 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
return join(list, File.pathSeparator);
|
||||
}
|
||||
|
||||
protected File getJdkAnnotations() {
|
||||
final ClassLoader classLoader = getClass().getClassLoader();
|
||||
@NotNull
|
||||
private static File getJdkAnnotations() {
|
||||
ClassLoader classLoader = KotlinCompileMojoBase.class.getClassLoader();
|
||||
if (!(classLoader instanceof URLClassLoader)) {
|
||||
throw new RuntimeException("Kotlin plugin`s classloader is not URLClassLoader");
|
||||
throw new RuntimeException("Kotlin plugin`s class loader is not URLClassLoader");
|
||||
}
|
||||
|
||||
final URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
|
||||
for (URL url : urlClassLoader.getURLs()) {
|
||||
final String path = url.getPath();
|
||||
for (URL url : ((URLClassLoader) classLoader).getURLs()) {
|
||||
String path = url.getPath();
|
||||
if (StringUtil.isEmpty(path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final File file = new File(path);
|
||||
File file = new File(path);
|
||||
if (file.getName().startsWith("kotlin-jdk-annotations")) {
|
||||
return file;
|
||||
}
|
||||
@@ -383,12 +381,12 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
throw new RuntimeException("Could not get jdk annotations from Kotlin plugin`s classpath");
|
||||
}
|
||||
|
||||
protected List<String> scanAnnotations(Log log) {
|
||||
final List<String> annotations = new ArrayList<String>();
|
||||
private List<String> scanAnnotations(Log log) {
|
||||
List<String> annotations = new ArrayList<String>();
|
||||
|
||||
final Set<Artifact> artifacts = project.getArtifacts();
|
||||
Set<Artifact> artifacts = project.getArtifacts();
|
||||
for (Artifact artifact : artifacts) {
|
||||
final File file = artifact.getFile();
|
||||
File file = artifact.getFile();
|
||||
if (containsAnnotations(file, log)) {
|
||||
log.info("Discovered kotlin annotations in: " + file);
|
||||
try {
|
||||
@@ -403,14 +401,14 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
protected boolean containsAnnotations(File file, Log log) {
|
||||
private static boolean containsAnnotations(File file, Log log) {
|
||||
log.debug("Scanning for kotlin annotations in " + file);
|
||||
|
||||
ZipFile zipFile = null;
|
||||
try {
|
||||
zipFile = new ZipFile(file);
|
||||
|
||||
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
String name = entries.nextElement().getName();
|
||||
if (name.endsWith("/annotations.xml")) {
|
||||
|
||||
+1
-1
@@ -40,7 +40,6 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
|
||||
*/
|
||||
private boolean skip;
|
||||
|
||||
|
||||
// TODO it would be nice to avoid using 2 injected fields for sources
|
||||
// but I've not figured out how to have a defaulted parameter value
|
||||
// which is also customisable inside an <execution> in a maven pom.xml
|
||||
@@ -76,6 +75,7 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
|
||||
*/
|
||||
private List<String> defaultSourceDir;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (skip) {
|
||||
getLog().info("Test compilation is skipped");
|
||||
|
||||
Reference in New Issue
Block a user