1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org_scala_tools_maven;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Set;
23
24 import org_scala_tools_maven_executions.JavaMainCaller;
25 import org_scala_tools_maven_executions.JavaMainCallerInProcess;
26 import org_scala_tools_maven_executions.MainHelper;
27
28
29
30
31
32
33
34
35
36
37 public class ScalaConsoleMojo extends ScalaMojoSupport {
38
39
40
41
42
43
44
45 protected String mainConsole;
46
47
48
49
50
51
52
53 protected boolean useTestClasspath;
54
55
56
57
58
59
60
61 protected boolean useRuntimeClasspath;
62
63
64
65
66
67
68
69 protected File javaRebelPath;
70
71 @Override
72 @SuppressWarnings("unchecked")
73 protected void doExecute() throws Exception {
74
75 String sv = findScalaVersion().toString();
76 Set<String> classpath = new HashSet<String>();
77 addToClasspath("org.scala-lang", "scala-compiler", sv, classpath);
78 addToClasspath("org.scala-lang", "scala-library", sv, classpath);
79 addToClasspath("jline", "jline", "0.9.94", classpath);
80 classpath.addAll(project.getCompileClasspathElements());
81 if (useTestClasspath) {
82 classpath.addAll(project.getTestClasspathElements());
83 }
84 if (useRuntimeClasspath) {
85 classpath.addAll(project.getRuntimeClasspathElements());
86 }
87 String classpathStr = MainHelper.toMultiPath(classpath.toArray(new String[classpath.size()]));
88 JavaMainCaller jcmd = null;
89 List<String> list = new ArrayList<String>(args != null ? args.length + 3 : 3);
90 if(args != null) {
91 for(String arg : args) {
92 list.add(arg);
93 }
94 }
95 list.add("-cp");
96 list.add(classpathStr);
97
98 if(fork) {
99 getLog().warn("maven-scala-plugin cannot fork scala console!! Running in process");
100 }
101
102 jcmd = new JavaMainCallerInProcess(this, mainConsole, classpathStr, jvmArgs, list.toArray(new String[list.size()]));
103
104 addCompilerPluginOptions(jcmd);
105 if (javaRebelPath != null) {
106 if (!javaRebelPath.exists()) {
107 getLog().warn("javaRevelPath '"+javaRebelPath.getCanonicalPath()+"' not found");
108 } else {
109 jcmd.addJvmArgs("-noverify", "-javaagent:" + javaRebelPath.getCanonicalPath());
110 }
111 }
112 jcmd.run(displayCmd);
113 }
114 }