Skip to content
Snippets Groups Projects
Commit 01f76197 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥
Browse files

Added the ability to enable MongoDB features.

parent db4117d9
No related branches found
No related tags found
No related merge requests found
......@@ -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>
......
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment