Maven: tests support for multiplatform projects
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
@@ -41,6 +43,17 @@
|
||||
<goal>js</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<multiPlatform>true</multiPlatform>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>compile-test</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-js</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<multiPlatform>true</multiPlatform>
|
||||
</configuration>
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package org.jetbrains
|
||||
|
||||
import org.junit.*
|
||||
import kotlin.test.*
|
||||
|
||||
class JSSpecificTest {
|
||||
@Test
|
||||
fun test1() {
|
||||
assertEquals(1, 1)
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package org.jetbrains
|
||||
|
||||
impl fun assertEquals(a: String, b: String) {
|
||||
kotlin.test.assertEquals(a, b)
|
||||
}
|
||||
@@ -24,10 +24,18 @@
|
||||
<artifactId>test-multimodule-shared</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
@@ -44,6 +52,16 @@
|
||||
<multiPlatform>true</multiPlatform>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>compile-test</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<multiPlatform>true</multiPlatform>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.jetbrains
|
||||
|
||||
import org.junit.*
|
||||
|
||||
class JVMSpecificTest {
|
||||
@Test
|
||||
fun test1() {
|
||||
Assert.assertEquals(1, 1)
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package org.jetbrains
|
||||
|
||||
import org.junit.*
|
||||
|
||||
impl fun assertEquals(a: String, b: String) {
|
||||
Assert.assertEquals(a, b)
|
||||
}
|
||||
@@ -23,11 +23,14 @@
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>metadata</id>
|
||||
@@ -35,6 +38,12 @@
|
||||
<goal>metadata</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-metadata</id>
|
||||
<goals>
|
||||
<goal>test-metadata</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.jetbrains
|
||||
|
||||
import org.junit.*
|
||||
|
||||
open class SharedTest {
|
||||
@Test
|
||||
fun test0() {
|
||||
assertEquals("Hello, World!", getGreeting())
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package org.jetbrains
|
||||
|
||||
header fun assertEquals(a: String, b: String)
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package org.junit
|
||||
|
||||
@Suppress("HEADER_WITHOUT_IMPLEMENTATION")
|
||||
header annotation class Test
|
||||
+7
@@ -24,6 +24,7 @@ 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.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
||||
@@ -154,12 +155,18 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
||||
return new K2JSCompilerArguments();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getRelatedSourceRoots(MavenProject project) {
|
||||
return project.getCompileSourceRoots();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected K2JSCompiler createCompiler() {
|
||||
return new K2JSCompiler();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Set<String> getOutputDirectoriesCollector() {
|
||||
lock.lock();
|
||||
try {
|
||||
|
||||
+6
@@ -21,6 +21,7 @@ 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.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||
@@ -65,6 +66,11 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
||||
@Parameter(property = "kotlin.compiler.scriptTemplates", required = false, readonly = false)
|
||||
protected List<String> scriptTemplates;
|
||||
|
||||
@Override
|
||||
protected List<String> getRelatedSourceRoots(MavenProject project) {
|
||||
return project.getCompileSourceRoots();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected K2JVMCompiler createCompiler() {
|
||||
|
||||
+17
-6
@@ -34,6 +34,7 @@ import org.apache.maven.repository.RepositorySystem;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler;
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
|
||||
@@ -86,7 +87,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
return project.getCompileSourceRoots();
|
||||
}
|
||||
|
||||
public List<File> getSourceDirs() {
|
||||
private List<File> getSourceDirs() {
|
||||
List<String> sources = getSourceFilePaths();
|
||||
List<File> result = new ArrayList<File>(sources.size());
|
||||
|
||||
@@ -96,6 +97,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
|
||||
Map<String, MavenProject> projectReferences = project.getProjectReferences();
|
||||
if (projectReferences != null) {
|
||||
iterateDependencies:
|
||||
for (Dependency dependency : project.getDependencies()) {
|
||||
MavenProject sibling = projectReferences.get(dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion());
|
||||
if (sibling != null) {
|
||||
@@ -103,11 +105,9 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
if (plugin != null) {
|
||||
for (PluginExecution pluginExecution : plugin.getExecutions()) {
|
||||
if (pluginExecution.getGoals() != null && pluginExecution.getGoals().contains("metadata")) {
|
||||
List<String> sourceRoots = sibling.getCompileSourceRoots();
|
||||
if (sourceRoots != null) {
|
||||
for (String sourceRoot : sourceRoots) {
|
||||
addSourceRoots(result, sourceRoot);
|
||||
}
|
||||
for (String sourceRoot : orEmpty(getRelatedSourceRoots(sibling))) {
|
||||
addSourceRoots(result, sourceRoot);
|
||||
continue iterateDependencies;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,6 +119,8 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract List<String> getRelatedSourceRoots(MavenProject project);
|
||||
|
||||
private void addSourceRoots(List<File> result, String source) {
|
||||
File f = new File(source);
|
||||
if (f.isAbsolute()) {
|
||||
@@ -449,4 +451,13 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
super("Plugin option has an illegal format: " + option);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <T> List<T> orEmpty(@Nullable List<T> in) {
|
||||
if (in == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -22,6 +22,7 @@ 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.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||
|
||||
@@ -89,4 +90,9 @@ public class KotlinTestCompileMojo extends K2JVMCompileMojo {
|
||||
output = testOutput;
|
||||
super.configureSpecificCompilerArguments(arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getRelatedSourceRoots(MavenProject project) {
|
||||
return project.getTestCompileSourceRoots();
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -22,6 +22,7 @@ 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.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
|
||||
@@ -85,6 +86,11 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
|
||||
arguments.metaInfo = metaInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getRelatedSourceRoots(MavenProject project) {
|
||||
return project.getTestCompileSourceRoots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (skip) {
|
||||
|
||||
+11
@@ -5,12 +5,14 @@ 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.kotlin.cli.common.CLICompiler;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.util.text.StringUtil.join;
|
||||
@@ -21,6 +23,14 @@ public class MetadataMojo extends KotlinCompileMojoBase<K2MetadataCompilerArgume
|
||||
@Parameter(defaultValue = "${project.compileClasspathElements}", required = true, readonly = true)
|
||||
public List<String> classpath;
|
||||
|
||||
@Parameter(defaultValue = "${project.testClasspathElements}", required = true, readonly = true)
|
||||
public List<String> testClasspath;
|
||||
|
||||
@Override
|
||||
protected List<String> getRelatedSourceRoots(MavenProject project) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected CLICompiler<K2MetadataCompilerArguments> createCompiler() {
|
||||
@@ -42,6 +52,7 @@ public class MetadataMojo extends KotlinCompileMojoBase<K2MetadataCompilerArgume
|
||||
}
|
||||
|
||||
List<String> classpathList = filterClassPath(project.getBasedir(), classpath);
|
||||
classpathList.remove(project.getBuild().getOutputDirectory());
|
||||
|
||||
if (!classpathList.isEmpty()) {
|
||||
String classPathString = join(classpathList, File.pathSeparator);
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package org.jetbrains.kotlin.maven;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
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.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@Mojo(name = "test-metadata", defaultPhase = LifecyclePhase.PROCESS_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.TEST)
|
||||
public class TestMetadataMojo extends MetadataMojo {
|
||||
@Parameter(property = "maven.test.skip", defaultValue = "false")
|
||||
private boolean skip;
|
||||
|
||||
@Override
|
||||
protected List<String> getSourceFilePaths() {
|
||||
return project.getTestCompileSourceRoots();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments) throws MojoExecutionException {
|
||||
String productionOutput = output;
|
||||
|
||||
module = testModule;
|
||||
classpath = testClasspath;
|
||||
// arguments.friendPaths = new String[] { productionOutput };
|
||||
output = testOutput;
|
||||
super.configureSpecificCompilerArguments(arguments);
|
||||
|
||||
if (arguments.classpath == null) {
|
||||
arguments.classpath = productionOutput;
|
||||
} else {
|
||||
arguments.classpath = arguments.classpath + File.pathSeparator + productionOutput;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (skip) {
|
||||
getLog().info("Test compilation is skipped");
|
||||
} else {
|
||||
super.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user