use of de.flapdoodle.embed.process.runtime.ICommandLinePostProcessor in project embedmongo-maven-plugin by joelittlejohn.
the class StartMojo method executeStart.
@Override
@SuppressWarnings("unchecked")
public void executeStart() throws MojoExecutionException, MojoFailureException {
MongodExecutable executable;
try {
final List<String> mongodArgs = this.createMongodArgsList();
final ICommandLinePostProcessor commandLinePostProcessor = new ICommandLinePostProcessor() {
@Override
public List<String> process(final Distribution distribution, final List<String> args) {
args.addAll(mongodArgs);
return args;
}
};
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.MongoD).processOutput(getOutputConfig()).artifactStore(getArtifactStore()).commandLinePostProcessor(commandLinePostProcessor).build();
int port = getPort();
if (isRandomPort()) {
port = NetworkUtils.allocateRandomPort();
}
savePortToProjectProperties(port);
IMongodConfig config = new MongodConfigBuilder().version(getVersion()).net(new Net(bindIp, port, NetworkUtils.localhostIsIPv6())).replication(new Storage(getDataDirectory(), null, 0)).cmdOptions(new MongoCmdOptionsBuilder().enableAuth(authEnabled).useNoJournal(!journal).useStorageEngine(storageEngine).build()).build();
executable = MongodStarter.getInstance(runtimeConfig).prepare(config);
} catch (DistributionException e) {
throw new MojoExecutionException("Failed to download MongoDB distribution: " + e.withDistribution(), e);
} catch (IOException e) {
throw new MojoExecutionException("Unable to Config MongoDB: ", e);
}
try {
MongodProcess mongod = executable.start();
if (isWait()) {
while (true) {
try {
TimeUnit.MINUTES.sleep(5);
} catch (InterruptedException e) {
break;
}
}
}
getPluginContext().put(MONGOD_CONTEXT_PROPERTY_NAME, mongod);
} catch (IOException e) {
throw new MojoExecutionException("Unable to start the mongod", e);
}
}
Aggregations