From 01f761978f9641cbbf68c920d860227eb414318d Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Thu, 11 Jun 2015 23:58:22 -0400 Subject: [PATCH] Added the ability to enable MongoDB features. --- README.md | 6 ++++ .../maven/plugins/mongodb/StartMongoMojo.java | 32 ++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ce9e2b0..1e4feca 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,12 @@ Usage <skip>false</skip> <!-- optional, skips this plugin entirely, use on the command line like -Dembedmongo.skip --> + + <features> + <feature>sync_delay</feature> + <feature>text_search</feature> + </features> + <!-- optional, a list of MongoDB features to enable, default is none --> </configuration> </execution> <execution> 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 120f80c..8010a4e 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.distribution.Feature; import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion; import de.flapdoodle.embed.mongo.distribution.Version; import de.flapdoodle.embed.mongo.distribution.Versions; @@ -50,6 +51,7 @@ import org.apache.maven.project.MavenProject; import java.io.File; import java.io.IOException; import java.net.*; +import java.util.HashSet; import java.util.List; import java.util.concurrent.TimeUnit; @@ -231,6 +233,14 @@ public class StartMongoMojo extends AbstractMojo { @Parameter(property = "project", readonly = true) private MavenProject project; + /** + * A list of the MongoDB features enabled. + * + * @since 1.0.0 + */ + @Parameter + private String[] features; + /** * If true the plugin does nothing at all, allows you to skip from the command line. * @@ -391,8 +401,18 @@ public class StartMongoMojo extends AbstractMojo { } private IFeatureAwareVersion getVersion() { - if(this.version == null || this.version.equals("")) - return Version.Main.PRODUCTION; + + final HashSet<Feature> featuresSet = new HashSet<Feature>(); + if(this.features != null && this.features.length > 0) { + for(final String featureString : this.features) + featuresSet.add(Feature.valueOf(featureString.toUpperCase())); + } + + if(this.version == null || this.version.equals("")) { + if(featuresSet.isEmpty()) + return Version.Main.PRODUCTION; + this.version = Version.Main.PRODUCTION.asInDownloadPath(); + } String versionEnumName = this.version.toUpperCase().replaceAll("\\.", "_"); @@ -400,18 +420,20 @@ public class StartMongoMojo extends AbstractMojo { versionEnumName = "V" + versionEnumName; } + IVersion determinedVersion; try { - return Version.valueOf(versionEnumName); + determinedVersion = Version.valueOf(versionEnumName); } catch (final IllegalArgumentException e) { getLog().warn("Unrecognised MongoDB version '" + this.version + "', this might be a new version that we don't yet know about. Attemping download anyway..."); - return Versions.withFeatures(new IVersion() { + determinedVersion = new IVersion() { @Override public String asInDownloadPath() { return version; } - }); + }; } + return Versions.withFeatures(determinedVersion, (featuresSet.isEmpty() ? null : (Feature[]) featuresSet.toArray())); } private String getDataDirectory() { -- GitLab