Skip to content
Snippets Groups Projects
Commit e241c259 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

Pulled out some common functionality to an abstract class.

parent 2616d479
No related branches found
No related tags found
No related merge requests found
/**
* 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;
}
......@@ -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();
......
......@@ -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");
}
}
}
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