diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/AbstractMongoMojo.java b/src/main/java/com/syncleus/maven/plugins/mongodb/AbstractMongoMojo.java new file mode 100644 index 0000000000000000000000000000000000000000..7d152f719246672e683bdf37b9dba9b6ee805f5e --- /dev/null +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/AbstractMongoMojo.java @@ -0,0 +1,44 @@ +/** + * Copyright: (c) Syncleus, Inc. + * + * You may redistribute and modify this source code under the terms and + * conditions of the Open Source Community License - Type C version 1.0 + * or any later version as published by Syncleus, Inc. at www.syncleus.com. + * There should be a copy of the license included with this file. If a copy + * of the license is not included you are granted no right to distribute or + * otherwise use this file except through a legal and valid license. You + * should also contact Syncleus, Inc. at the information below if you cannot + * find a license: + * + * Syncleus, Inc. + * 2604 South 12th Street + * Philadelphia, PA 19148 + */ +package com.syncleus.maven.plugins.mongodb; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; + +public abstract class AbstractMongoMojo extends AbstractMojo { + /** + * If true the plugin does nothing at all, allows you to skip from the command line. + * + * @since 1.0.0 + */ + @Parameter(property = "mongodb.skip", defaultValue = "false") + private boolean skip; + + @Override + public final void execute() throws MojoExecutionException, MojoFailureException { + if (skip) { + getLog().debug("skip=true, not starting mongodb"); + return; + } + + this.start(); + } + + public abstract void start() throws MojoExecutionException, MojoFailureException; +} 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 e4e2ce6e5ed3d9ce72f6e0b1e995201067175e4a..88ccd73cd37de4d14ceca63fdd863c0733a80345 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java @@ -23,7 +23,6 @@ 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; @@ -66,7 +65,7 @@ import static java.util.Collections.singletonList; * href="http://github.com/flapdoodle-oss/embedmongo.flapdoodle.de">http://github.com/flapdoodle-oss/embedmongo.flapdoodle.de</a> */ @Mojo(name = "start", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST) -public class StartMongoMojo extends AbstractMojo { +public class StartMongoMojo extends AbstractMongoMojo { private static final String PACKAGE_NAME = StartMongoMojo.class.getPackage().getName(); public static final String MONGOD_CONTEXT_PROPERTY_NAME = PACKAGE_NAME + ".mongod"; @@ -242,14 +241,6 @@ public class StartMongoMojo extends AbstractMojo { @Parameter(property = "project", readonly = true) private MavenProject project; - /** - * If true the plugin does nothing at all, allows you to skip from the command line. - * - * @since 1.0.0 - */ - @Parameter(property = "mongodb.skip", defaultValue = "false") - private boolean skip; - /** * A list of the MongoDB features enabled. * @@ -260,12 +251,7 @@ public class StartMongoMojo extends AbstractMojo { @Override @SuppressWarnings("unchecked") - public void execute() throws MojoExecutionException, MojoFailureException { - - if (skip) { - getLog().debug("skip=true, not starting mongodb"); - return; - } + public void start() throws MojoExecutionException, MojoFailureException { if (this.proxyHost != null && this.proxyHost.length() > 0) { this.addProxySelector(); diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/StopMongoMojo.java b/src/main/java/com/syncleus/maven/plugins/mongodb/StopMongoMojo.java index c4f8889e5e8f37741e8fa144b668a8b7568bd5db..b4287acb7b55b6bb1d7d40d0492955fa581f8ce3 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/StopMongoMojo.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/StopMongoMojo.java @@ -30,22 +30,9 @@ import org.apache.maven.plugins.annotations.Parameter; * */ @Mojo(name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST) -public class StopMongoMojo extends AbstractMojo { - - /** - * If true the plugin does nothing at all, allows you to skip from the command line. - * - * @since 1.0.0 - */ - @Parameter(property = "mongodb.skip", defaultValue = "false") - private boolean skip; - +public class StopMongoMojo extends AbstractMongoMojo { @Override - public void execute() throws MojoExecutionException, MojoFailureException { - if (skip) { - return; - } - + public void start() throws MojoExecutionException, MojoFailureException { final MongodProcess mongod = (MongodProcess) getPluginContext().get(StartMongoMojo .MONGOD_CONTEXT_PROPERTY_NAME); @@ -55,5 +42,4 @@ public class StopMongoMojo extends AbstractMojo { throw new MojoFailureException("No mongod process found, it appears embedmongo:start was not called"); } } - }