27
27
import de .flapdoodle .embed .mongo .Command ;
28
28
import de .flapdoodle .embed .mongo .MongodExecutable ;
29
29
import de .flapdoodle .embed .mongo .MongodStarter ;
30
- import de .flapdoodle .embed .mongo .config .DownloadConfigBuilder ;
31
- import de .flapdoodle .embed .mongo .config .ExtractedArtifactStoreBuilder ;
32
- import de .flapdoodle .embed .mongo .config .IMongodConfig ;
33
- import de .flapdoodle .embed .mongo .config .MongodConfigBuilder ;
30
+ import de .flapdoodle .embed .mongo .config .Defaults ;
31
+ import de .flapdoodle .embed .mongo .config .ImmutableMongodConfig ;
32
+ import de .flapdoodle .embed .mongo .config .MongodConfig ;
34
33
import de .flapdoodle .embed .mongo .config .Net ;
35
- import de .flapdoodle .embed .mongo .config .RuntimeConfigBuilder ;
36
34
import de .flapdoodle .embed .mongo .config .Storage ;
37
35
import de .flapdoodle .embed .mongo .distribution .Feature ;
38
36
import de .flapdoodle .embed .mongo .distribution .IFeatureAwareVersion ;
39
37
import de .flapdoodle .embed .mongo .distribution .Version ;
40
38
import de .flapdoodle .embed .mongo .distribution .Versions ;
41
- import de .flapdoodle .embed .process .config .IRuntimeConfig ;
39
+ import de .flapdoodle .embed .process .config .RuntimeConfig ;
42
40
import de .flapdoodle .embed .process .config .io .ProcessOutput ;
43
- import de .flapdoodle .embed .process .config .store .IDownloadConfig ;
44
- import de .flapdoodle .embed .process .distribution .GenericVersion ;
41
+ import de .flapdoodle .embed .process .config .store .DownloadConfig ;
42
+ import de .flapdoodle .embed .process .config .store .ImmutableDownloadConfig ;
43
+ import de .flapdoodle .embed .process .distribution .Version .GenericVersion ;
45
44
import de .flapdoodle .embed .process .io .Processors ;
46
45
import de .flapdoodle .embed .process .io .Slf4jLevel ;
47
46
import de .flapdoodle .embed .process .io .progress .Slf4jProgressListener ;
48
47
import de .flapdoodle .embed .process .runtime .Network ;
49
- import de .flapdoodle .embed .process .store .ArtifactStoreBuilder ;
48
+ import de .flapdoodle .embed .process .store .ExtractedArtifactStore ;
50
49
import org .slf4j .Logger ;
51
50
import org .slf4j .LoggerFactory ;
52
51
81
80
* @author Yogesh Lonkar
82
81
* @author Mark Paluch
83
82
* @author Issam El-atif
83
+ * @author Paulius Dambrauskas
84
84
* @since 1.3.0
85
85
*/
86
86
@ Configuration (proxyBeanMethods = false )
@@ -97,14 +97,14 @@ public class EmbeddedMongoAutoConfiguration {
97
97
98
98
private final MongoProperties properties ;
99
99
100
- public EmbeddedMongoAutoConfiguration (MongoProperties properties , EmbeddedMongoProperties embeddedProperties ) {
100
+ public EmbeddedMongoAutoConfiguration (MongoProperties properties ) {
101
101
this .properties = properties ;
102
102
}
103
103
104
104
@ Bean (initMethod = "start" , destroyMethod = "stop" )
105
105
@ ConditionalOnMissingBean
106
- public MongodExecutable embeddedMongoServer (IMongodConfig mongodConfig , IRuntimeConfig runtimeConfig ,
107
- ApplicationContext context ) throws IOException {
106
+ public MongodExecutable embeddedMongoServer (MongodConfig mongodConfig , RuntimeConfig runtimeConfig ,
107
+ ApplicationContext context ) {
108
108
Integer configuredPort = this .properties .getPort ();
109
109
if (configuredPort == null || configuredPort == 0 ) {
110
110
setEmbeddedPort (context , mongodConfig .net ().getPort ());
@@ -113,7 +113,7 @@ public MongodExecutable embeddedMongoServer(IMongodConfig mongodConfig, IRuntime
113
113
return mongodStarter .prepare (mongodConfig );
114
114
}
115
115
116
- private MongodStarter getMongodStarter (IRuntimeConfig runtimeConfig ) {
116
+ private MongodStarter getMongodStarter (RuntimeConfig runtimeConfig ) {
117
117
if (runtimeConfig == null ) {
118
118
return MongodStarter .getDefaultInstance ();
119
119
}
@@ -122,8 +122,8 @@ private MongodStarter getMongodStarter(IRuntimeConfig runtimeConfig) {
122
122
123
123
@ Bean
124
124
@ ConditionalOnMissingBean
125
- public IMongodConfig embeddedMongoConfiguration (EmbeddedMongoProperties embeddedProperties ) throws IOException {
126
- MongodConfigBuilder builder = new MongodConfigBuilder ().version (determineVersion (embeddedProperties ));
125
+ public MongodConfig embeddedMongoConfiguration (EmbeddedMongoProperties embeddedProperties ) throws IOException {
126
+ ImmutableMongodConfig . Builder builder = MongodConfig . builder ().version (determineVersion (embeddedProperties ));
127
127
EmbeddedMongoProperties .Storage storage = embeddedProperties .getStorage ();
128
128
if (storage != null ) {
129
129
String databaseDir = storage .getDatabaseDir ();
@@ -149,12 +149,16 @@ private IFeatureAwareVersion determineVersion(EmbeddedMongoProperties embeddedPr
149
149
return version ;
150
150
}
151
151
}
152
- return Versions .withFeatures (new GenericVersion (embeddedProperties . getVersion () ));
152
+ return Versions .withFeatures (createEmbeddedMongoVersion (embeddedProperties ));
153
153
}
154
- return Versions .withFeatures (new GenericVersion (embeddedProperties . getVersion () ),
154
+ return Versions .withFeatures (createEmbeddedMongoVersion (embeddedProperties ),
155
155
embeddedProperties .getFeatures ().toArray (new Feature [0 ]));
156
156
}
157
157
158
+ private GenericVersion createEmbeddedMongoVersion (EmbeddedMongoProperties embeddedProperties ) {
159
+ return de .flapdoodle .embed .process .distribution .Version .of (embeddedProperties .getVersion ());
160
+ }
161
+
158
162
private InetAddress getHost () throws UnknownHostException {
159
163
if (this .properties .getHost () == null ) {
160
164
return InetAddress .getByAddress (Network .localhostIsIPv6 () ? IP6_LOOPBACK_ADDRESS : IP4_LOOPBACK_ADDRESS );
@@ -189,29 +193,28 @@ private Map<String, Object> getMongoPorts(MutablePropertySources sources) {
189
193
190
194
@ Configuration (proxyBeanMethods = false )
191
195
@ ConditionalOnClass (Logger .class )
192
- @ ConditionalOnMissingBean (IRuntimeConfig .class )
196
+ @ ConditionalOnMissingBean (RuntimeConfig .class )
193
197
static class RuntimeConfigConfiguration {
194
198
195
199
@ Bean
196
- IRuntimeConfig embeddedMongoRuntimeConfig (
200
+ RuntimeConfig embeddedMongoRuntimeConfig (
197
201
ObjectProvider <DownloadConfigBuilderCustomizer > downloadConfigBuilderCustomizers ) {
198
202
Logger logger = LoggerFactory .getLogger (getClass ().getPackage ().getName () + ".EmbeddedMongo" );
199
203
ProcessOutput processOutput = new ProcessOutput (Processors .logTo (logger , Slf4jLevel .INFO ),
200
204
Processors .logTo (logger , Slf4jLevel .ERROR ),
201
205
Processors .named ("[console>]" , Processors .logTo (logger , Slf4jLevel .DEBUG )));
202
- return new RuntimeConfigBuilder (). defaultsWithLogger (Command .MongoD , logger ).processOutput (processOutput )
206
+ return Defaults . runtimeConfigFor (Command .MongoD , logger ).processOutput (processOutput )
203
207
.artifactStore (getArtifactStore (logger , downloadConfigBuilderCustomizers .orderedStream ()))
204
- .daemonProcess (false ).build ();
208
+ .isDaemonProcess (false ).build ();
205
209
}
206
210
207
- private ArtifactStoreBuilder getArtifactStore (Logger logger ,
211
+ private ExtractedArtifactStore getArtifactStore (Logger logger ,
208
212
Stream <DownloadConfigBuilderCustomizer > downloadConfigBuilderCustomizers ) {
209
- DownloadConfigBuilder downloadConfigBuilder = new DownloadConfigBuilder ()
210
- .defaultsForCommand (Command .MongoD );
213
+ ImmutableDownloadConfig .Builder downloadConfigBuilder = Defaults .downloadConfigFor (Command .MongoD );
211
214
downloadConfigBuilder .progressListener (new Slf4jProgressListener (logger ));
212
215
downloadConfigBuilderCustomizers .forEach ((customizer ) -> customizer .customize (downloadConfigBuilder ));
213
- IDownloadConfig downloadConfig = downloadConfigBuilder .build ();
214
- return new ExtractedArtifactStoreBuilder (). defaults (Command .MongoD ).download (downloadConfig );
216
+ DownloadConfig downloadConfig = downloadConfigBuilder .build ();
217
+ return Defaults . extractedArtifactStoreFor (Command .MongoD ).withDownloadConfig (downloadConfig );
215
218
}
216
219
217
220
}
0 commit comments