Maven: test js compiler test scope dependencies

This commit is contained in:
Sergey Mashkov
2017-01-24 15:11:13 +03:00
committed by Ilya Gorbunov
parent 5a28e8cc20
commit e500eba59f
2 changed files with 32 additions and 16 deletions
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.maven;
import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtil;
import kotlin.text.StringsKt; import kotlin.text.StringsKt;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
@@ -98,7 +98,12 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
arguments.kjsm = kjsm; arguments.kjsm = kjsm;
arguments.moduleKind = moduleKind; arguments.moduleKind = moduleKind;
List<String> libraries = getKotlinJavascriptLibraryFiles(); List<String> libraries = null;
try {
libraries = getKotlinJavascriptLibraryFiles();
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("Unresolved dependencies", e);
}
getLog().debug("libraryFiles: " + libraries); getLog().debug("libraryFiles: " + libraries);
arguments.libraryFiles = ArrayUtil.toStringArray(libraries); arguments.libraryFiles = ArrayUtil.toStringArray(libraries);
@@ -116,33 +121,38 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
} }
} }
protected List<String> getClassPathElements() throws DependencyResolutionRequiredException {
return project.getCompileClasspathElements();
}
/** /**
* Returns all Kotlin Javascript dependencies that this project has, including transitive ones. * Returns all Kotlin Javascript dependencies that this project has, including transitive ones.
* *
* @return array of paths to kotlin javascript libraries * @return array of paths to kotlin javascript libraries
*/ */
@NotNull @NotNull
private List<String> getKotlinJavascriptLibraryFiles() { private List<String> getKotlinJavascriptLibraryFiles() throws DependencyResolutionRequiredException {
List<String> libraries = new ArrayList<String>(); List<String> libraries = new ArrayList<String>();
for (Artifact artifact : project.getArtifacts()) { for (String path : getClassPathElements()) {
if (artifact.getScope().equals(Artifact.SCOPE_COMPILE)) { File file = new File(path);
File file = artifact.getFile();
if (LibraryUtils.isKotlinJavascriptLibrary(file)) { if (file.exists() && LibraryUtils.isKotlinJavascriptLibrary(file)) {
libraries.add(file.getAbsolutePath()); libraries.add(file.getAbsolutePath());
} }
else { else {
getLog().warn("artifact " + artifact + " is not a Kotlin Javascript Library"); getLog().debug("artifact " + file.getAbsolutePath() + " is not a Kotlin Javascript Library");
}
} }
} }
for (String file : getOutputDirectoriesCollector()) { for (String path : getOutputDirectoriesCollector()) {
if (new File(file).exists()) { File file = new File(path);
libraries.add(file);
if (file.exists() && LibraryUtils.isKotlinJavascriptLibrary(file)) {
libraries.add(file.getAbsolutePath());
} }
else { else {
getLog().warn("JS output directory missing: " + file); getLog().debug("JS output directory missing: " + file);
} }
} }
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.maven; package org.jetbrains.kotlin.maven;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
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.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -86,6 +87,11 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
arguments.metaInfo = metaInfo; arguments.metaInfo = metaInfo;
} }
@Override
protected List<String> getClassPathElements() throws DependencyResolutionRequiredException {
return project.getTestClasspathElements();
}
@Override @Override
protected List<String> getRelatedSourceRoots(MavenProject project) { protected List<String> getRelatedSourceRoots(MavenProject project) {
return project.getTestCompileSourceRoots(); return project.getTestCompileSourceRoots();