From 848edc14cb85cde2385cebfe714815b6ca5bdbd3 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 11 Jul 2017 16:02:25 +0300 Subject: [PATCH] Maven plugin: fix warnings, update copyrights --- .../kotlin/maven/ExecuteKotlinScriptMojo.java | 35 ++++------ .../kotlin/maven/IdeaCoreLoggerFactory.java | 16 +++++ .../kotlin/maven/K2JSCompilerMojo.java | 10 +-- .../kotlin/maven/K2JVMCompileMojo.java | 27 ++++---- .../KotlinCompilationFailureException.java | 25 ++++--- .../kotlin/maven/KotlinCompileMojoBase.java | 66 +++++++------------ .../maven/KotlinMavenPluginExtension.java | 16 +++++ .../kotlin/maven/KotlinTestCompileMojo.java | 11 +--- .../maven/KotlinTestJSCompilerMojo.java | 9 ++- .../maven/MavenPluginLogMessageCollector.java | 50 +++++++------- .../jetbrains/kotlin/maven/MetadataMojo.java | 16 +++++ .../jetbrains/kotlin/maven/PluginOption.java | 18 ++++- .../maven/ScriptExecutionException.java | 3 +- .../kotlin/maven/TestMetadataMojo.java | 16 +++++ .../java/org/jetbrains/kotlin/maven/Util.java | 15 ++--- .../maven/incremental/MavenICReporter.java | 18 ++++- .../kapt/AnnotationProcessingManager.java | 37 +++++++---- .../maven/kapt/KaptJVMCompilerMojo.java | 24 +++++-- .../kotlin/maven/kapt/KaptOption.java | 16 +++++ .../maven/kapt/KaptTestJvmCompilerMojo.java | 18 ++++- 20 files changed, 286 insertions(+), 160 deletions(-) diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ExecuteKotlinScriptMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ExecuteKotlinScriptMojo.java index 39dee5626ff..bfd3737f7e5 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ExecuteKotlinScriptMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ExecuteKotlinScriptMojo.java @@ -23,7 +23,6 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Dependency; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -58,6 +57,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.stream.Collectors; /** * Allows to execute kotlin script files during the build process. @@ -106,13 +106,13 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo { @Parameter(defaultValue = "${localRepository}", required = true, readonly = true) private ArtifactRepository localRepository; - @Parameter(property = "kotlin.compiler.scriptTemplates", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.scriptTemplates") protected List scriptTemplates; - @Parameter(property = "kotlin.compiler.scriptArguments", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.scriptArguments") protected List scriptArguments; - @Parameter(property = "kotlin.compiler.scriptClasspath", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.scriptClasspath") protected List scriptClasspath; @Component @@ -167,7 +167,7 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo { configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector); - List deps = new ArrayList(); + List deps = new ArrayList<>(); deps.addAll(PathUtil.getJdkClassesRootsFromCurrentJre()); deps.addAll(getDependenciesForScript()); @@ -184,7 +184,10 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo { configuration.add(JVMConfigurationKeys.CONTENT_ROOTS, new KotlinSourceRoot(scriptFile.getAbsolutePath())); configuration.put(CommonConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME); - K2JVMCompiler.Companion.configureScriptDefinitions(scriptTemplates.toArray(new String[scriptTemplates.size()]), configuration, messageCollector, new HashMap()); + K2JVMCompiler.Companion.configureScriptDefinitions( + scriptTemplates.toArray(new String[scriptTemplates.size()]), + configuration, messageCollector, new HashMap<>() + ); KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES); @@ -214,7 +217,7 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo { } private List getDependenciesForScript() throws MojoExecutionException { - List deps = new ArrayList(); + List deps = new ArrayList<>(); deps.addAll(getKotlinRuntimeDependencies()); deps.add(getThisPluginAsDependency()); @@ -234,25 +237,13 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo { return getArtifactFile(artifact); } - private File getDependencyFile(Dependency dep) { - ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(dep.getType()); - Artifact artifact = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), null, dep.getType(), null, artifactHandler); - return getArtifactFile(artifact); - } - private File getArtifactFile(Artifact artifact) { localRepository.find(artifact); return artifact.getFile(); } private List getThisPluginDependencies() { - List files = new ArrayList(); - - for (ComponentDependency dep: plugin.getDependencies()) { - files.add(getDependencyFile(dep)); - } - - return files; + return plugin.getDependencies().stream().map(this::getDependencyFile).collect(Collectors.toList()); } private File getThisPluginAsDependency() { @@ -269,7 +260,7 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo { Artifact stdlibDep = null; Artifact runtimeDep = null; - ArrayList files = new ArrayList(2); + ArrayList files = new ArrayList<>(2); for (Artifact dep: project.getArtifacts()) { if (dep.getArtifactId().equals("kotlin-stdlib")) { @@ -297,4 +288,4 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo { // at com.intellij.openapi.application.PathManager.getHomePath(PathManager.java:96) new K2JVMCompiler(); } -} \ No newline at end of file +} diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/IdeaCoreLoggerFactory.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/IdeaCoreLoggerFactory.java index 032b2943ebe..fc5cfa08e61 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/IdeaCoreLoggerFactory.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/IdeaCoreLoggerFactory.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven; import com.intellij.openapi.diagnostic.Logger; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java index 1bd7aee1e42..af8dc5268d7 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -102,7 +102,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase libraries = null; + List libraries; try { libraries = getKotlinJavascriptLibraryFiles(); } catch (DependencyResolutionRequiredException e) { @@ -118,7 +118,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase> collector = getOutputDirectoriesCollector(); String key = project.getArtifactId(); - List paths = collector.computeIfAbsent(key, k -> Collections.synchronizedList(new ArrayList())); + List paths = collector.computeIfAbsent(key, k -> Collections.synchronizedList(new ArrayList<>())); paths.add(new File(outputFile).getParent()); } @@ -145,7 +145,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase getKotlinJavascriptLibraryFiles() throws DependencyResolutionRequiredException { - List libraries = new ArrayList(); + List libraries = new ArrayList<>(); for (String path : getClassPathElements()) { File file = new File(path); @@ -197,7 +197,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase> collector = (ConcurrentMap>) getPluginContext().get(OUTPUT_DIRECTORIES_COLLECTOR_PROPERTY_NAME); if (collector == null) { - collector = new ConcurrentSkipListMap>(); + collector = new ConcurrentSkipListMap<>(); getPluginContext().put(OUTPUT_DIRECTORIES_COLLECTOR_PROPERTY_NAME, collector); } diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java index 27e96616658..894a1888367 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ package org.jetbrains.kotlin.maven; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.*; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,7 +37,8 @@ import org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager; import java.io.File; import java.io.IOException; import java.net.URL; -import java.util.*; +import java.util.ArrayList; +import java.util.List; import static com.intellij.openapi.util.text.StringUtil.join; import static org.jetbrains.kotlin.maven.Util.filterClassPath; @@ -64,22 +68,22 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase scriptTemplates; - @Parameter(property = "kotlin.compiler.incremental", defaultValue = "false", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.incremental", defaultValue = "false") private boolean myIncremental; - @Parameter(property = "kotlin.compiler.incremental.cache.root", defaultValue = "${project.build.directory}/kotlin-ic", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.incremental.cache.root", defaultValue = "${project.build.directory}/kotlin-ic") public String incrementalCachesRoot; - @Parameter(property = "kotlin.compiler.javaParameters", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.javaParameters") protected boolean javaParameters; @NotNull @@ -119,7 +123,7 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase(paths); + paths = new ArrayList<>(paths); paths.add(sourcesDir.getAbsolutePath()); } @@ -184,13 +188,14 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase compiler, MessageCollector messageCollector, diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompilationFailureException.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompilationFailureException.java index f74ba8ec0d2..61e9d6c3b15 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompilationFailureException.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompilationFailureException.java @@ -1,22 +1,29 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven; import org.apache.maven.plugin.compiler.CompilationFailureException; import org.codehaus.plexus.compiler.CompilerMessage; import org.jetbrains.annotations.NotNull; -import java.util.Collections; import java.util.List; public class KotlinCompilationFailureException extends CompilationFailureException { - private List compilerMessages; - public KotlinCompilationFailureException(@NotNull List compilerMessages) { super(compilerMessages); - this.compilerMessages = Collections.unmodifiableList(compilerMessages); - } - - public List getCompilerMessages() { - return compilerMessages; } } - diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java index e5e5207ceb7..50c7e7d60d8 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,16 @@ import com.google.common.base.Joiner; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.ArrayUtil; -import com.intellij.util.Processor; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; -import org.apache.maven.plugin.*; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -80,18 +82,15 @@ public abstract class KotlinCompileMojoBase e @Parameter private boolean multiPlatform = false; - private List getAppliedCompilerPlugins() { - return (compilerPlugins == null) ? Collections.emptyList() : compilerPlugins; - } - protected List getSourceFilePaths() { if (sourceDirs != null && !sourceDirs.isEmpty()) return sourceDirs; return project.getCompileSourceRoots(); } + @NotNull private List getSourceDirs() { List sources = getSourceFilePaths(); - List result = new ArrayList(sources.size()); + List result = new ArrayList<>(sources.size()); for (String source : sources) { addSourceRoots(result, source); @@ -168,17 +167,17 @@ public abstract class KotlinCompileMojoBase e public String testModule; - @Parameter(property = "kotlin.compiler.languageVersion", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.languageVersion") protected String languageVersion; - @Parameter(property = "kotlin.compiler.apiVersion", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.apiVersion") protected String apiVersion; /** * possible values are: enable, error, warn */ - @Parameter(property = "kotlin.compiler.experimental.coroutines", required = false, readonly = false) + @Parameter(property = "kotlin.compiler.experimental.coroutines") @Nullable protected String experimentalCoroutines; @@ -237,17 +236,9 @@ public abstract class KotlinCompileMojoBase e } private boolean hasKotlinFilesInSources() throws MojoExecutionException { - List sources = getSourceDirs(); - if (sources == null || sources.isEmpty()) return false; - - for (File root : sources) { + for (File root : getSourceDirs()) { if (root.exists()) { - boolean sourcesExists = !FileUtil.processFilesRecursively(root, new Processor() { - @Override - public boolean process(File file) { - return !file.getName().endsWith(".kt"); - } - }); + boolean sourcesExists = !FileUtil.processFilesRecursively(root, file -> !file.getName().endsWith(".kt")); if (sourcesExists) return true; } } @@ -293,9 +284,9 @@ public abstract class KotlinCompileMojoBase e protected abstract void configureSpecificCompilerArguments(@NotNull A arguments, @NotNull List sourceRoots) throws MojoExecutionException; private List getCompilerPluginClassPaths() { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); - List files = new ArrayList(); + List files = new ArrayList<>(); for (Dependency dependency : mojoExecution.getPlugin().getDependencies()) { Artifact artifact = system.createDependencyArtifact(dependency); @@ -319,14 +310,15 @@ public abstract class KotlinCompileMojoBase e @NotNull private Map loadCompilerPlugins() throws PluginNotFoundException { - Map loadedPlugins = new HashMap(); - for (String pluginName : getAppliedCompilerPlugins()) { + if (compilerPlugins == null) return Collections.emptyMap(); + + Map loadedPlugins = new HashMap<>(); + for (String pluginName : compilerPlugins) { getLog().debug("Looking for plugin " + pluginName); try { KotlinMavenPluginExtension extension = container.lookup(KotlinMavenPluginExtension.class, pluginName); loadedPlugins.put(pluginName, extension); getLog().debug("Got plugin instance" + pluginName + " of type " + extension.getClass().getName()); - } catch (ComponentLookupException e) { getLog().debug("Unable to get plugin instance" + pluginName); throw new PluginNotFoundException(pluginName, e); @@ -337,7 +329,7 @@ public abstract class KotlinCompileMojoBase e @NotNull private List renderCompilerPluginOptions(@NotNull List options) { - List renderedOptions = new ArrayList(options.size()); + List renderedOptions = new ArrayList<>(options.size()); for (PluginOption option : options) { renderedOptions.add(option.toString()); } @@ -350,7 +342,7 @@ public abstract class KotlinCompileMojoBase e throw new IllegalStateException("No mojoExecution injected"); } - List pluginOptions = new ArrayList(); + List pluginOptions = new ArrayList<>(); Map plugins = loadCompilerPlugins(); @@ -374,15 +366,9 @@ public abstract class KotlinCompileMojoBase e pluginOptions.addAll(parseUserProvidedPluginOptions(this.pluginOptions, plugins)); } - Map> optionsByPluginName = new LinkedHashMap>(); + Map> optionsByPluginName = new LinkedHashMap<>(); for (PluginOption option : pluginOptions) { - List optionsForPlugin = optionsByPluginName.get(option.pluginName); - if (optionsForPlugin == null) { - optionsForPlugin = new ArrayList(); - optionsByPluginName.put(option.pluginName, optionsForPlugin); - } - - optionsForPlugin.add(option); + optionsByPluginName.computeIfAbsent(option.pluginName, key -> new ArrayList<>()).add(option); } for (Map.Entry> entry : optionsByPluginName.entrySet()) { @@ -410,7 +396,7 @@ public abstract class KotlinCompileMojoBase e @NotNull List rawOptions, @NotNull Map plugins ) throws PluginOptionIllegalFormatException, PluginNotFoundException { - List pluginOptions = new ArrayList(rawOptions.size()); + List pluginOptions = new ArrayList<>(rawOptions.size()); for (String rawOption : rawOptions) { Matcher matcher = OPTION_PATTERN.matcher(rawOption); @@ -434,7 +420,7 @@ public abstract class KotlinCompileMojoBase e @NotNull private List getSourceRoots() throws MojoExecutionException { - List sourceRoots = new ArrayList(); + List sourceRoots = new ArrayList<>(); for (File sourceDir : getSourceDirs()) { if (sourceDir.exists()) { sourceRoots.add(sourceDir); @@ -489,9 +475,7 @@ public abstract class KotlinCompileMojoBase e List pluginArguments; try { pluginArguments = renderCompilerPluginOptions(getCompilerPluginOptions()); - } catch (PluginNotFoundException e) { - throw new MojoExecutionException(e.getMessage(), e); - } catch (PluginOptionIllegalFormatException e) { + } catch (PluginNotFoundException | PluginOptionIllegalFormatException e) { throw new MojoExecutionException(e.getMessage(), e); } diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinMavenPluginExtension.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinMavenPluginExtension.java index 1535ea5e777..33f8ebb4e97 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinMavenPluginExtension.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinMavenPluginExtension.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven; import org.apache.maven.plugin.MojoExecution; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java index c91b0ced0fc..5311f271a2f 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestCompileMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,20 +26,15 @@ import org.apache.maven.project.MavenProject; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager; -import org.jetbrains.kotlin.maven.kapt.KaptTestJvmCompilerMojo; import java.io.File; import java.util.List; +// Note! +// Please change {@link KaptTestJvmCompilerMojo} because it was mostly copied from this file. /** * Compiles Kotlin test sources - * - * @noinspection UnusedDeclaration */ - -/** Note! - * Please change {@link KaptTestJvmCompilerMojo} as well as it was majorly copied from this file. */ - @Mojo(name = "test-compile", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST, diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestJSCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestJSCompilerMojo.java index aaf4e2c3d64..07f5e7234c3 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestJSCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinTestJSCompilerMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,12 +29,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments; import java.io.File; -import java.util.List; import java.util.Collections; +import java.util.List; + /** * Converts Kotlin to JavaScript code - * - * @noinspection UnusedDeclaration */ @Mojo(name = "test-js", defaultPhase = LifecyclePhase.TEST_COMPILE, @@ -74,7 +73,7 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo { private String outputFile; /** - * Flag enables or disables metafile generation + * Flag enables or disables .meta.js file generation */ @Parameter(defaultValue = "true") private boolean metaInfo; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MavenPluginLogMessageCollector.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MavenPluginLogMessageCollector.java index 7d4fa11c435..2fa130ef475 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MavenPluginLogMessageCollector.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MavenPluginLogMessageCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ package org.jetbrains.kotlin.maven; import com.intellij.openapi.util.Pair; -import kotlin.collections.CollectionsKt; -import kotlin.jvm.functions.Function1; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.compiler.CompilerMessage; import org.jetbrains.annotations.NotNull; @@ -30,12 +28,13 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; public class MavenPluginLogMessageCollector implements MessageCollector { private final Log log; - private final ArrayList> collectedErrors = new ArrayList>(); + private final ArrayList> collectedErrors = new ArrayList<>(); public MavenPluginLogMessageCollector(Log log) { this.log = checkNotNull(log, "log shouldn't be null"); @@ -65,7 +64,7 @@ public class MavenPluginLogMessageCollector implements MessageCollector { switch (severity) { case EXCEPTION: case ERROR: { - collectedErrors.add(new Pair(location, message)); + collectedErrors.add(new Pair<>(location, message)); log.error(text); break; } @@ -90,31 +89,26 @@ public class MavenPluginLogMessageCollector implements MessageCollector { } public void throwKotlinCompilerException() throws KotlinCompilationFailureException { - throw new KotlinCompilationFailureException( - CollectionsKt.map(getCollectedErrors(), new Function1, CompilerMessage>() { - @Override - public CompilerMessage invoke(Pair pair) { - CompilerMessageLocation location = pair.getFirst(); - String message = pair.getSecond(); - if (location == null) { - return new CompilerMessage(null, CompilerMessage.Kind.ERROR, 0, 0, 0, 0, message); - } + throw new KotlinCompilationFailureException(getCollectedErrors().stream().map(pair -> { + CompilerMessageLocation location = pair.getFirst(); + String message = pair.getSecond(); + if (location == null) { + return new CompilerMessage(null, CompilerMessage.Kind.ERROR, 0, 0, 0, 0, message); + } - String lineContent = location.getLineContent(); - int lineContentLength = lineContent == null ? 0 : lineContent.length(); + String lineContent = location.getLineContent(); + int lineContentLength = lineContent == null ? 0 : lineContent.length(); - return new CompilerMessage( - location.getPath(), - CompilerMessage.Kind.ERROR, - fixLocation(location.getLine()), - fixLocation(location.getColumn()), - fixLocation(location.getLine()), - Math.min(fixLocation(location.getColumn()), lineContentLength), - message - ); - } - }) - ); + return new CompilerMessage( + location.getPath(), + CompilerMessage.Kind.ERROR, + fixLocation(location.getLine()), + fixLocation(location.getColumn()), + fixLocation(location.getLine()), + Math.min(fixLocation(location.getColumn()), lineContentLength), + message + ); + }).collect(Collectors.toList())); } private static int fixLocation(int n) { diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MetadataMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MetadataMojo.java index a7ef4879857..a4343ead37c 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MetadataMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/MetadataMojo.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven; import org.apache.maven.plugin.MojoExecutionException; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/PluginOption.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/PluginOption.java index 867cdee05f8..87e61ae6533 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/PluginOption.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/PluginOption.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven; public class PluginOption { @@ -21,4 +37,4 @@ public class PluginOption { public String toString() { return "plugin:" + pluginId + ":" + key + "=" + value; } -} \ No newline at end of file +} diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ScriptExecutionException.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ScriptExecutionException.java index e4f2fd4f6b2..3d3fc2714ad 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ScriptExecutionException.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ScriptExecutionException.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,6 @@ * limitations under the License. */ - package org.jetbrains.kotlin.maven; import org.apache.maven.plugin.MojoExecutionException; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/TestMetadataMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/TestMetadataMojo.java index 495cabdd5e6..278bc571e1a 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/TestMetadataMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/TestMetadataMojo.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven; import org.apache.maven.plugin.MojoExecutionException; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/Util.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/Util.java index 6d2b2543bfb..7a7f89d3fab 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/Util.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/Util.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,14 @@ package org.jetbrains.kotlin.maven; -import kotlin.collections.CollectionsKt; -import kotlin.jvm.functions.Function1; - import java.io.File; import java.util.List; +import java.util.stream.Collectors; public class Util { static List filterClassPath(final File basedir, List classpath) { - return CollectionsKt.filter(classpath, new Function1() { - @Override - public Boolean invoke(String s) { - return new File(s).exists() || new File(basedir, s).exists(); - } - }); + return classpath.stream().filter(s -> + new File(s).exists() || new File(basedir, s).exists() + ).collect(Collectors.toList()); } } diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/incremental/MavenICReporter.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/incremental/MavenICReporter.java index 994203f8c16..48c8ff6870a 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/incremental/MavenICReporter.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/incremental/MavenICReporter.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven.incremental; import kotlin.jvm.functions.Function0; @@ -77,7 +93,7 @@ public class MavenICReporter implements ICReporter { } @NotNull - private final Set compiledKotlinFiles = new HashSet(); + private final Set compiledKotlinFiles = new HashSet<>(); protected boolean isLogEnabled() { return false; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/AnnotationProcessingManager.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/AnnotationProcessingManager.java index d2ea8728d41..483e71fd8f0 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/AnnotationProcessingManager.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/AnnotationProcessingManager.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven.kapt; import org.apache.maven.artifact.Artifact; @@ -68,15 +84,14 @@ public class AnnotationProcessingManager { @NotNull static File getGeneratedClassesDirectory(@NotNull MavenProject project, @NotNull String sourceSetName) { - if (sourceSetName.equals(COMPILE_SOURCE_SET_NAME)) { - return new File(project.getModel().getBuild().getOutputDirectory()); - } - else if (sourceSetName.equals(TEST_SOURCE_SET_NAME)) { - return new File(project.getModel().getBuild().getTestOutputDirectory()); - } - else { - throw new IllegalArgumentException("'" + COMPILE_SOURCE_SET_NAME + "' or '" + - TEST_SOURCE_SET_NAME + "' expected"); + switch (sourceSetName) { + case COMPILE_SOURCE_SET_NAME: + return new File(project.getModel().getBuild().getOutputDirectory()); + case TEST_SOURCE_SET_NAME: + return new File(project.getModel().getBuild().getTestOutputDirectory()); + default: + throw new IllegalArgumentException("'" + COMPILE_SOURCE_SET_NAME + "' or '" + + TEST_SOURCE_SET_NAME + "' expected"); } } @@ -91,7 +106,7 @@ public class AnnotationProcessingManager { aptDependencies = Collections.emptyList(); } - Set requiredArtifacts = new LinkedHashSet(); + Set requiredArtifacts = new LinkedHashSet<>(); requiredArtifacts.add(getArtifact(artifactHandlerManager, KAPT_DEPENDENCY)); @@ -114,7 +129,7 @@ public class AnnotationProcessingManager { throw new IllegalStateException("Annotation processing artifacts were not resolved."); } - List apClasspath = new ArrayList(resolutionResult.getArtifacts().size()); + List apClasspath = new ArrayList<>(resolutionResult.getArtifacts().size()); String kaptCompilerPluginArtifact = null; for (Artifact artifact : resolutionResult.getArtifacts()) { diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java index 5ecba584c31..6a63c21a56d 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven.kapt; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; @@ -15,12 +31,10 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.getGeneratedClassesDirectory; -import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.getGeneratedSourcesDirectory; -import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.getStubsDirectory; +import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.*; /** @noinspection UnusedDeclaration */ -@Mojo(name = "kapt", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = false) +@Mojo(name = "kapt", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE) public class KaptJVMCompilerMojo extends K2JVMCompileMojo { @Parameter private String[] annotationProcessors; @@ -62,7 +76,7 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo { @NotNull K2JVMCompilerArguments arguments, @NotNull AnnotationProcessingManager.ResolvedArtifacts resolvedArtifacts ) { - List options = new ArrayList(); + List options = new ArrayList<>(); options.add(new KaptOption("aptOnly", true)); options.add(new KaptOption("useLightAnalysis", useLightAnalysis)); diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptOption.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptOption.java index 8941e578998..5b15ed34c0e 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptOption.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptOption.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven.kapt; import org.jetbrains.annotations.NotNull; diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptTestJvmCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptTestJvmCompilerMojo.java index e76e20fa96c..155c709adeb 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptTestJvmCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptTestJvmCompilerMojo.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * 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. + */ + package org.jetbrains.kotlin.maven.kapt; import org.apache.maven.plugin.MojoExecutionException; @@ -18,7 +34,7 @@ import java.util.List; * * @noinspection UnusedDeclaration */ -@Mojo(name = "test-kapt", defaultPhase = LifecyclePhase.PROCESS_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = false) +@Mojo(name = "test-kapt", defaultPhase = LifecyclePhase.PROCESS_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.TEST) public class KaptTestJvmCompilerMojo extends KaptJVMCompilerMojo { /** * Flag to allow test compilation to be skipped.