|
1 | 1 | package com.sourcemuse.gradle.plugin.flapdoodle.adapters |
2 | 2 |
|
3 | | -import static com.sourcemuse.gradle.plugin.LogDestination.CONSOLE |
4 | | -import static com.sourcemuse.gradle.plugin.LogDestination.FILE |
5 | | -import static com.sourcemuse.gradle.plugin.LogDestination.NONE |
6 | | - |
7 | 3 | import com.sourcemuse.gradle.plugin.GradleMongoPluginExtension |
8 | 4 | import com.sourcemuse.gradle.plugin.LogDestination |
9 | | -import de.flapdoodle.embed.mongo.packageresolver.Command |
10 | | -import de.flapdoodle.embed.mongo.config.MongodProcessOutputConfig |
11 | | -import de.flapdoodle.embed.process.config.process.ProcessOutput |
12 | 5 | import de.flapdoodle.embed.process.io.NamedOutputStreamProcessor |
13 | | -import de.flapdoodle.embed.process.io.NullProcessor |
14 | | -import de.flapdoodle.embed.process.io.Processors |
15 | | -import de.flapdoodle.embed.process.io.Slf4jLevel |
| 6 | +import de.flapdoodle.embed.process.io.ProcessOutput |
| 7 | +import de.flapdoodle.reverse.State |
| 8 | +import de.flapdoodle.reverse.StateID |
| 9 | +import de.flapdoodle.reverse.StateLookup |
| 10 | +import de.flapdoodle.reverse.Transition |
16 | 11 | import groovy.transform.TupleConstructor |
17 | 12 | import org.gradle.api.GradleScriptException |
18 | 13 | import org.gradle.api.Project |
19 | 14 |
|
20 | | -@TupleConstructor |
21 | | -class ProcessOutputFactory { |
22 | | - Project project |
23 | | - |
24 | | - ProcessOutput getProcessOutput(GradleMongoPluginExtension pluginExtension) { |
25 | | - def logDestination = pluginExtension.logging.toUpperCase() as LogDestination |
| 15 | +import static com.sourcemuse.gradle.plugin.LogDestination.CONSOLE |
| 16 | +import static com.sourcemuse.gradle.plugin.LogDestination.FILE |
| 17 | +import static com.sourcemuse.gradle.plugin.LogDestination.NONE |
26 | 18 |
|
27 | | - if (logDestination == CONSOLE) { |
28 | | - return MongodProcessOutputConfig.getDefaultInstance(Command.MongoD) |
29 | | - } |
| 19 | +@TupleConstructor |
| 20 | +class ProcessOutputFactory implements Transition<ProcessOutput> { |
| 21 | + Project project |
| 22 | + GradleMongoPluginExtension pluginExtension |
30 | 23 |
|
31 | | - if (logDestination == FILE) { |
32 | | - def logFile = new File(pluginExtension.logFilePath) |
33 | | - def logFilePath = logFile.isAbsolute() ? logFile.absolutePath : |
34 | | - createRelativeFilePathFromBuildDir(logFile) |
| 24 | + ProcessOutput getProcessOutput() { |
| 25 | + def logDestination = pluginExtension.logging.toUpperCase() as LogDestination |
35 | 26 |
|
36 | | - def fileOutputStreamProcessor = new FileOutputStreamProcessor(logFilePath) |
| 27 | + if (logDestination == CONSOLE) { |
| 28 | + return ProcessOutput.namedConsole("mongod") |
| 29 | + } |
37 | 30 |
|
38 | | - return ProcessOutput.builder() |
39 | | - .output(new NamedOutputStreamProcessor('[mongod output]', fileOutputStreamProcessor)) |
40 | | - .error(new NamedOutputStreamProcessor('[mongod error]', fileOutputStreamProcessor)) |
41 | | - .commands(new NamedOutputStreamProcessor('[mongod commands]', fileOutputStreamProcessor)) |
42 | | - .build() |
43 | | - } |
| 31 | + if (logDestination == FILE) { |
| 32 | + def logFile = new File(pluginExtension.logFilePath) |
| 33 | + def logFilePath = logFile.isAbsolute() ? logFile.absolutePath : |
| 34 | + createRelativeFilePathFromBuildDir(logFile) |
44 | 35 |
|
45 | | - if (logDestination == NONE) { |
46 | | - def nullProcessor = new NullProcessor() |
47 | | - return ProcessOutput.builder() |
48 | | - .output(nullProcessor) |
49 | | - .error(nullProcessor) |
50 | | - .commands(nullProcessor) |
51 | | - .build() |
52 | | - } |
| 36 | + def fileOutputStreamProcessor = new FileOutputStreamProcessor(logFilePath) |
53 | 37 |
|
54 | | - throw new GradleScriptException( |
55 | | - "Unrecognized 'logging' option: ${pluginExtension.logging}. " + |
56 | | - "Choose one of ${LogDestination.values().collect { it.toString().toLowerCase() }.join(', ')}.", |
57 | | - new IllegalArgumentException() |
58 | | - ) |
| 38 | + return ProcessOutput.builder() |
| 39 | + .output(new NamedOutputStreamProcessor('[mongod output]', fileOutputStreamProcessor)) |
| 40 | + .error(new NamedOutputStreamProcessor('[mongod error]', fileOutputStreamProcessor)) |
| 41 | + .commands(new NamedOutputStreamProcessor('[mongod commands]', fileOutputStreamProcessor)) |
| 42 | + .build() |
59 | 43 | } |
60 | 44 |
|
61 | | - private String createRelativeFilePathFromBuildDir(File logFile) { |
62 | | - project.buildDir.absolutePath + File.separatorChar + logFile.path |
| 45 | + if (logDestination == NONE) { |
| 46 | + return ProcessOutput.silent() |
63 | 47 | } |
| 48 | + |
| 49 | + throw new GradleScriptException( |
| 50 | + "Unrecognized 'logging' option: ${pluginExtension.logging}. " + |
| 51 | + "Choose one of ${LogDestination.values().collect { it.toString().toLowerCase() }.join(', ')}.", |
| 52 | + new IllegalArgumentException() |
| 53 | + ) |
| 54 | + } |
| 55 | + |
| 56 | + private String createRelativeFilePathFromBuildDir(File logFile) { |
| 57 | + project.buildDir.absolutePath + File.separatorChar + logFile.path |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + StateID<ProcessOutput> destination() { |
| 62 | + return StateID.of(ProcessOutput.class) |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + Set<StateID<?>> sources() { |
| 67 | + return Set.of() |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + State<ProcessOutput> result(StateLookup lookup) { |
| 72 | + return State.of(getProcessOutput()) |
| 73 | + } |
64 | 74 | } |
0 commit comments