Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored goals, - "run" will now run the server synchronously - "start" will run asynchronously Updated README with better usage examples
- Loading branch information
1 parent
e24b2e2
commit 01aeb9b
Showing
5 changed files
with
135 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.garrettheel.moco; | ||
|
||
import com.github.dreamhead.moco.bootstrap.Main; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Runs a Moco server with a config file and port number. Note that the server will run | ||
* synchronously and can be stopped by killing the process. | ||
*/ | ||
@Mojo( name="run" ) | ||
public class MocoRunMojo extends AbstractMojo { | ||
|
||
/** | ||
* The file containing the JSON configuration. | ||
*/ | ||
@Parameter(required = true) | ||
private File configFile; | ||
|
||
/** | ||
* The port to start the server on. | ||
*/ | ||
@Parameter(required = true) | ||
private Integer port; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
checkParams(); | ||
|
||
Main.main(new String[]{ | ||
"-p", String.format("%d", port), // port | ||
configFile.getAbsolutePath() // config file | ||
}); | ||
|
||
getLog().info("Started Moco server on port " + port); | ||
|
||
try { | ||
Thread.currentThread().join(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void checkParams() throws MojoExecutionException { | ||
if (!configFile.exists()) { | ||
throw new MojoExecutionException("Moco config file does not exist."); | ||
} | ||
if (port == null || port < 1) { | ||
throw new MojoExecutionException("Invalid port number specified."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters