17
17
package org .springframework .boot .cli .command ;
18
18
19
19
import java .awt .Desktop ;
20
+ import java .io .File ;
21
+ import java .util .List ;
20
22
import java .util .logging .Level ;
21
23
22
24
import joptsimple .OptionSet ;
23
25
import joptsimple .OptionSpec ;
24
26
25
27
import org .springframework .boot .cli .Command ;
28
+ import org .springframework .boot .cli .compiler .GroovyCompilerConfigurationAdapter ;
26
29
import org .springframework .boot .cli .compiler .GroovyCompilerScope ;
30
+ import org .springframework .boot .cli .compiler .RepositoryConfigurationFactory ;
31
+ import org .springframework .boot .cli .compiler .grape .RepositoryConfiguration ;
27
32
import org .springframework .boot .cli .runner .SpringApplicationRunner ;
28
33
import org .springframework .boot .cli .runner .SpringApplicationRunnerConfiguration ;
29
34
@@ -53,41 +58,25 @@ public void stop() {
53
58
}
54
59
}
55
60
56
- private static class RunOptionHandler extends OptionHandler {
61
+ private static class RunOptionHandler extends CompilerOptionHandler {
57
62
58
63
private OptionSpec <Void > watchOption ;
59
64
60
65
private OptionSpec <Void > editOption ;
61
66
62
- private OptionSpec <Void > noGuessImportsOption ;
63
-
64
- private OptionSpec <Void > noGuessDependenciesOption ;
65
-
66
67
private OptionSpec <Void > verboseOption ;
67
68
68
69
private OptionSpec <Void > quietOption ;
69
70
70
- private OptionSpec <Void > localOption ;
71
-
72
- private OptionSpec <String > classpathOption ;
73
-
74
71
private SpringApplicationRunner runner ;
75
72
76
73
@ Override
77
- protected void options () {
74
+ protected void doOptions () {
78
75
this .watchOption = option ("watch" , "Watch the specified file for changes" );
79
- this .localOption = option ("local" ,
80
- "Accumulate the dependencies in a local folder (./repository)" );
81
76
this .editOption = option (asList ("edit" , "e" ),
82
77
"Open the file with the default system editor" );
83
- this .noGuessImportsOption = option ("no-guess-imports" ,
84
- "Do not attempt to guess imports" );
85
- this .noGuessDependenciesOption = option ("no-guess-dependencies" ,
86
- "Do not attempt to guess dependencies" );
87
78
this .verboseOption = option (asList ("verbose" , "v" ), "Verbose logging" );
88
79
this .quietOption = option (asList ("quiet" , "q" ), "Quiet logging" );
89
- this .classpathOption = option (asList ("classpath" , "cp" ),
90
- "Additional classpath entries" ).withRequiredArg ();
91
80
}
92
81
93
82
@ Override
@@ -98,11 +87,14 @@ protected void run(OptionSet options) throws Exception {
98
87
Desktop .getDesktop ().edit (fileOptions .getFiles ().get (0 ));
99
88
}
100
89
90
+ List <RepositoryConfiguration > repositoryConfiguration = RepositoryConfigurationFactory
91
+ .createDefaultRepositoryConfiguration ();
92
+ repositoryConfiguration .add (0 , new RepositoryConfiguration ("local" , new File (
93
+ "repository" ).toURI (), true ));
94
+
101
95
SpringApplicationRunnerConfiguration configuration = new SpringApplicationRunnerConfigurationAdapter (
102
- options );
103
- if (configuration .isLocal () && System .getProperty ("grape.root" ) == null ) {
104
- System .setProperty ("grape.root" , "." );
105
- }
96
+ options , this , repositoryConfiguration );
97
+
106
98
this .runner = new SpringApplicationRunner (configuration ,
107
99
fileOptions .getFilesArray (), fileOptions .getArgsArray ());
108
100
this .runner .compileAndRun ();
@@ -112,13 +104,14 @@ protected void run(OptionSet options) throws Exception {
112
104
* Simple adapter class to present the {@link OptionSet} as a
113
105
* {@link SpringApplicationRunnerConfiguration}.
114
106
*/
115
- private class SpringApplicationRunnerConfigurationAdapter implements
107
+ private class SpringApplicationRunnerConfigurationAdapter extends
108
+ GroovyCompilerConfigurationAdapter implements
116
109
SpringApplicationRunnerConfiguration {
117
110
118
- private OptionSet options ;
119
-
120
- public SpringApplicationRunnerConfigurationAdapter ( OptionSet options ) {
121
- this . options = options ;
111
+ public SpringApplicationRunnerConfigurationAdapter ( OptionSet options ,
112
+ CompilerOptionHandler optionHandler ,
113
+ List < RepositoryConfiguration > repositoryConfiguration ) {
114
+ super ( options , optionHandler , repositoryConfiguration ) ;
122
115
}
123
116
124
117
@ Override
@@ -128,44 +121,19 @@ public GroovyCompilerScope getScope() {
128
121
129
122
@ Override
130
123
public boolean isWatchForFileChanges () {
131
- return this .options .has (RunOptionHandler .this .watchOption );
132
- }
133
-
134
- @ Override
135
- public boolean isGuessImports () {
136
- return !this .options .has (RunOptionHandler .this .noGuessImportsOption );
137
- }
138
-
139
- @ Override
140
- public boolean isGuessDependencies () {
141
- return !this .options .has (RunOptionHandler .this .noGuessDependenciesOption );
142
- }
143
-
144
- @ Override
145
- public boolean isLocal () {
146
- return this .options .has (RunOptionHandler .this .localOption );
124
+ return getOptions ().has (RunOptionHandler .this .watchOption );
147
125
}
148
126
149
127
@ Override
150
128
public Level getLogLevel () {
151
- if (this . options .has (RunOptionHandler .this .verboseOption )) {
129
+ if (getOptions () .has (RunOptionHandler .this .verboseOption )) {
152
130
return Level .FINEST ;
153
131
}
154
- if (this . options .has (RunOptionHandler .this .quietOption )) {
132
+ if (getOptions () .has (RunOptionHandler .this .quietOption )) {
155
133
return Level .OFF ;
156
134
}
157
135
return Level .INFO ;
158
136
}
159
-
160
- @ Override
161
- public String [] getClasspath () {
162
- if (this .options .has (RunOptionHandler .this .classpathOption )) {
163
- return this .options .valueOf (RunOptionHandler .this .classpathOption )
164
- .split (":" );
165
- }
166
- return NO_CLASSPATH ;
167
- }
168
-
169
137
}
170
138
}
171
139
0 commit comments