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