Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/scala_maven/ScalaMojoSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public abstract class ScalaMojoSupport extends AbstractMojo {

/** Scala 's version to use. (property 'maven.scala.version' replaced by 'scala.version') */
@Parameter(property = "scala.version")
private String scalaVersion;
protected String scalaVersion;

/**
* Organization/group ID of the Scala used in the project. Default value is 'org.scala-lang'. This
Expand Down Expand Up @@ -524,7 +524,7 @@ final JavaMainCaller getEmptyScalaCommand(final String mainClass) throws Excepti
* if you are invoking the REPL.
* @return a {@link JavaMainCaller} to use to invoke the given command.
*/
private JavaMainCaller getEmptyScalaCommand(final String mainClass, final boolean forkOverride)
JavaMainCaller getEmptyScalaCommand(final String mainClass, final boolean forkOverride)
throws Exception {

// If we are deviating from the plugin settings, let the user know
Expand Down
101 changes: 101 additions & 0 deletions src/test/java/scala_maven/ScalaMojoSupportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
package scala_maven;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.List;
import org.junit.Test;
import scala_maven_executions.JavaMainCaller;
import scala_maven_executions.JavaMainCallerSupport;

public class ScalaMojoSupportTest {

Expand Down Expand Up @@ -60,4 +66,99 @@ public void scala2_13_should_generate_non_prefixed_target() {
assertEquals("11", ScalaMojoSupport.targetOption("11", new VersionNumber("2.13.8")));
assertEquals("17", ScalaMojoSupport.targetOption("17", new VersionNumber("2.13.8")));
}

static class ScalaMojoSupportWithRelease extends ScalaMojoSupport {
public ScalaMojoSupportWithRelease() {
this.release = "42";
this.target = "8";
}

public List<String> getScalacOptions() throws Exception {
try {
return super.getScalacOptions();
} catch (final Exception e) {
e.printStackTrace();
throw e;
}
}

public void setScalaVersion(final String v) {
this.scalaVersion = v;
}

@Override
protected void doExecute() throws Exception {}

@Override
JavaMainCaller getEmptyScalaCommand(final String mainClass, final boolean forkOverride) {
return new JavaMainCallerArgs(this);
}
}

static class JavaMainCallerArgs extends JavaMainCallerSupport {
public JavaMainCallerArgs(final ScalaMojoSupport mojo) {
super(mojo, null, null, null, null);
}

public List<String> getArgs() {
return this.args;
}

@Override
public scala_maven_executions.SpawnMonitor spawn(boolean displayCmd) throws Exception {
return null;
}

@Override
public boolean run(boolean displayCmd, boolean throwFailure) throws Exception {
return false;
}

@Override
public void redirectToLog() {}
}

final ScalaMojoSupportWithRelease mojoWithRelease = new ScalaMojoSupportWithRelease();

@Test
public void scala2_11_should_skip_release_option() throws Exception {
mojoWithRelease.setScalaVersion("2.11.0");
List<String> opts = mojoWithRelease.getScalacOptions();
assertNotNull(opts);
assertFalse(opts.contains("-release"));
assertFalse(opts.contains("42"));
}

@Test
public void scala2_12_should_skip_release_option() throws Exception {
mojoWithRelease.setScalaVersion("2.12.0");
List<String> opts = mojoWithRelease.getScalacOptions();
assertNotNull(opts);
assertTrue(opts.contains("-release"));
assertTrue(opts.contains("42"));
}

@Test
public void scala2_13_should_keep_release_option() throws Exception {
mojoWithRelease.setScalaVersion("2.13.0");
List<String> opts = mojoWithRelease.getScalacOptions();
assertNotNull(opts);
assertTrue(opts.contains("-release"));
assertTrue(opts.contains("42"));
}

@Test
public void scala2_12_scala_command_contain_target_and_release() throws Exception {
mojoWithRelease.setScalaVersion("2.12.0");
final JavaMainCaller caller = mojoWithRelease.getScalaCommand(true, "String");
assertNotNull(caller);
assertTrue(caller instanceof JavaMainCallerArgs);

final JavaMainCallerArgs callerJvm = (JavaMainCallerArgs) caller;
assertNotNull(callerJvm.getArgs());
assertEquals(3, callerJvm.getArgs().size());
assertTrue(callerJvm.getArgs().contains("-release"));
assertTrue(callerJvm.getArgs().contains("42"));
assertTrue(callerJvm.getArgs().contains("-target:jvm-1.8"));
}
}