5
5
use App \Exceptions \ExerciseConfigException ;
6
6
use App \Helpers \ExerciseConfig \Compilation \CompilationParams ;
7
7
use App \Helpers \ExerciseConfig \Pipeline \Box \Params \ConfigParams ;
8
+ use App \Helpers \ExerciseConfig \Pipeline \Box \Params \Priorities ;
9
+ use App \Helpers \ExerciseConfig \Pipeline \Box \Params \TaskCommands ;
10
+ use App \Helpers \ExerciseConfig \Pipeline \Box \Params \TaskType ;
8
11
use App \Helpers \ExerciseConfig \Pipeline \Ports \Port ;
9
12
use App \Helpers \ExerciseConfig \Pipeline \Ports \PortMeta ;
10
13
use App \Helpers \ExerciseConfig \VariableTypes ;
14
+ use App \Helpers \JobConfig \Tasks \Task ;
11
15
use Nette \Utils \Strings ;
12
16
13
17
@@ -19,6 +23,7 @@ class JavacCompilationBox extends CompilationBox
19
23
/** Type key */
20
24
public static $ JAVAC_TYPE = "javac " ;
21
25
public static $ JAVAC_BINARY = "/usr/bin/javac " ;
26
+ public static $ COMPILATION_SUBDIR = 'compiled-classes ' ;
22
27
public static $ CLASS_FILES_WILDCARD = "*.class " ;
23
28
public static $ JAVA_FILES_EXT_REGEX = "[.java] " ;
24
29
public static $ CLASS_FILES_PORT_KEY = "class-files " ;
@@ -101,27 +106,39 @@ public function getDefaultName(): string {
101
106
* @throws ExerciseConfigException
102
107
*/
103
108
public function compile (CompilationParams $ params ): array {
104
- $ task = $ this ->compileBaseTask ($ params );
105
- $ task ->setCommandBinary (self ::$ JAVAC_BINARY );
109
+ // Create a separate directory where all *.class files will end up.
110
+ $ mkdirTask = new Task ();
111
+ $ mkdirTask ->setPriority (Priorities::$ INITIATION );
112
+ $ mkdirTask ->setType (TaskType::$ INITIATION );
113
+ $ mkdirTask ->setCommandBinary (TaskCommands::$ MKDIR );
114
+ $ mkdirTask ->setCommandArguments ([
115
+ ConfigParams::$ SOURCE_DIR . $ this ->getDirectory () . ConfigParams::$ PATH_DELIM . self ::$ COMPILATION_SUBDIR
116
+ ]);
117
+
118
+ // Prepare compile task
119
+ $ compileTask = $ this ->compileBaseTask ($ params );
120
+ $ compileTask ->setCommandBinary (self ::$ JAVAC_BINARY );
106
121
107
122
$ args = [];
108
123
if ($ this ->hasInputPortValue (self ::$ ARGS_PORT_KEY )) {
109
124
$ args = $ this ->getInputPortValue (self ::$ ARGS_PORT_KEY )->getValue ();
110
125
}
111
126
127
+ // First order of business -- make sure all *.class files will be yielded to prepared dir (but in eval box)
128
+ $ args [] = '-d ' ;
129
+ $ args [] = ConfigParams::$ EVAL_DIR . self ::$ COMPILATION_SUBDIR ;
130
+
112
131
// if there were some provided jar files, lets add them to the command line args
113
132
$ classpath = JavaUtils::constructClasspath ($ this ->getInputPortValue (self ::$ JAR_FILES_PORT_KEY ));
114
133
$ args = array_merge ($ args , $ classpath );
115
134
116
135
// set wildcards for class files, which are derived from compiled classes
117
- $ wildClassFiles = [];
118
- foreach ($ this ->getInputPortValue (self ::$ SOURCE_FILES_PORT_KEY )->getValueAsArray () as $ srcFile ) {
119
- $ className = Strings::replace ($ srcFile , self ::$ JAVA_FILES_EXT_REGEX , "" );
120
- $ wildClassFiles [] = $ className . self ::$ CLASS_FILES_WILDCARD ;
121
- }
136
+ $ wildClassFiles = [
137
+ self ::$ COMPILATION_SUBDIR . ConfigParams::$ PATH_DELIM . self ::$ CLASS_FILES_WILDCARD
138
+ ];
122
139
$ this ->getOutputPortValue (self ::$ CLASS_FILES_PORT_KEY )->setValue ($ wildClassFiles );
123
140
124
- $ task ->setCommandArguments (
141
+ $ compileTask ->setCommandArguments (
125
142
array_merge (
126
143
$ args ,
127
144
$ this ->getInputPortValue (self ::$ SOURCE_FILES_PORT_KEY )
@@ -131,7 +148,7 @@ public function compile(CompilationParams $params): array {
131
148
)
132
149
);
133
150
134
- return [$ task ];
151
+ return [$ mkdirTask , $ compileTask ];
135
152
}
136
153
137
154
}
0 commit comments