diff --git a/README.md b/README.md index 1e4feca68e911a0dc83a83fedae56e434867c0c8..aa146ebc8b6651ac21f13b617a97b361fec38c8d 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,9 @@ Usage <executableNaming>user</executableNaming> <!-- optional (user|uuid), sets the executable naming style, default is uuid --> + + <syncDelay>0</syncDelay> + <!-- optional, Sets the sync delay, 0 prevents all writing to disk, default lets MongoDB automatically determine value --> <skip>false</skip> <!-- optional, skips this plugin entirely, use on the command line like -Dembedmongo.skip --> diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java b/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java index 8010a4eb77d8acaa1397d606ba0ca62781226b8d..e4e2ce6e5ed3d9ce72f6e0b1e995201067175e4a 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java @@ -23,6 +23,7 @@ import de.flapdoodle.embed.mongo.MongodExecutable; import de.flapdoodle.embed.mongo.MongodProcess; import de.flapdoodle.embed.mongo.MongodStarter; import de.flapdoodle.embed.mongo.config.*; +import de.flapdoodle.embed.mongo.config.processlistener.ProcessListenerBuilder; import de.flapdoodle.embed.mongo.distribution.Feature; import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion; import de.flapdoodle.embed.mongo.distribution.Version; @@ -226,20 +227,20 @@ public class StartMongoMojo extends AbstractMojo { private String artifactDirectory; /** - * The maven project. + * Specifies the sync delay for MongoDB, 0 never syncs to disk, no value indicates default. * * @since 1.0.0 */ - @Parameter(property = "project", readonly = true) - private MavenProject project; + @Parameter(property = "mongodb.syncDelay") + private Integer syncDelay; /** - * A list of the MongoDB features enabled. + * The maven project. * * @since 1.0.0 */ - @Parameter - private String[] features; + @Parameter(property = "project", readonly = true) + private MavenProject project; /** * If true the plugin does nothing at all, allows you to skip from the command line. @@ -249,6 +250,14 @@ public class StartMongoMojo extends AbstractMojo { @Parameter(property = "mongodb.skip", defaultValue = "false") private boolean skip; + /** + * A list of the MongoDB features enabled. + * + * @since 1.0.0 + */ + @Parameter + private String[] features; + @Override @SuppressWarnings("unchecked") public void execute() throws MojoExecutionException, MojoFailureException { @@ -291,11 +300,25 @@ public class StartMongoMojo extends AbstractMojo { } savePortToProjectProperties(); - final IMongodConfig config = new MongodConfigBuilder() + MongodConfigBuilder configBuilder = new MongodConfigBuilder() .version(getVersion()) .net(new Net(bindIp, port, Network.localhostIsIPv6())) - .replication(new Storage(getDataDirectory(), replSet, oplogSize)) - .build(); + .replication(new Storage(getDataDirectory(), replSet, oplogSize)); + + if(this.syncDelay == null) { + configBuilder = configBuilder + .cmdOptions(new MongoCmdOptionsBuilder() + .defaultSyncDelay() + .build()); + } + else if(this.syncDelay > 0) { + configBuilder = configBuilder + .cmdOptions(new MongoCmdOptionsBuilder() + .syncDelay(this.syncDelay) + .build()); + } + final IMongodConfig config = configBuilder.build(); + executable = MongodStarter.getInstance(runtimeConfig).prepare(config); } catch (final UnknownHostException e) { @@ -433,7 +456,10 @@ public class StartMongoMojo extends AbstractMojo { }; } - return Versions.withFeatures(determinedVersion, (featuresSet.isEmpty() ? null : (Feature[]) featuresSet.toArray())); + if(featuresSet.isEmpty()) + return Versions.withFeatures(determinedVersion); + else + return Versions.withFeatures(determinedVersion, (Feature[]) featuresSet.toArray()); } private String getDataDirectory() {