-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Berry
committed
Sep 2, 2014
1 parent
1bed772
commit 6ad01ec
Showing
9 changed files
with
200 additions
and
1 deletion.
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
85 changes: 85 additions & 0 deletions
85
...rc/main/java/org/bladerunnerjs/plugin/plugins/commands/standard/J2eeifyCommandPlugin.java
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,85 @@ | ||
package org.bladerunnerjs.plugin.plugins.commands.standard; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOUtils; | ||
import org.bladerunnerjs.appserver.ApplicationServerUtils; | ||
import org.bladerunnerjs.logging.Logger; | ||
import org.bladerunnerjs.model.App; | ||
import org.bladerunnerjs.model.BRJS; | ||
import org.bladerunnerjs.model.exception.command.CommandArgumentsException; | ||
import org.bladerunnerjs.model.exception.command.CommandOperationException; | ||
import org.bladerunnerjs.model.exception.template.TemplateInstallationException; | ||
import org.bladerunnerjs.plugin.utility.command.ArgsParsingCommandPlugin; | ||
import org.bladerunnerjs.utility.RelativePathUtility; | ||
import org.bladerunnerjs.utility.TemplateUtility; | ||
|
||
import com.martiansoftware.jsap.JSAP; | ||
import com.martiansoftware.jsap.JSAPException; | ||
import com.martiansoftware.jsap.JSAPResult; | ||
import com.martiansoftware.jsap.UnflaggedOption; | ||
|
||
|
||
public class J2eeifyCommandPlugin extends ArgsParsingCommandPlugin | ||
{ | ||
public class Messages { | ||
public static final String APP_DOES_NOT_EXIST_EXCEPTION = "The app '%s' does not exist"; | ||
public static final String SUCCESSFULLY_J2EEIFIED_APP_MESSAGE = "Successfully 'j2eeified' the '%s' app, the neccessary jars and config have been copied into '%s'"; | ||
} | ||
|
||
private BRJS brjs; | ||
private Logger logger; | ||
|
||
@Override | ||
protected void configureArgsParser(JSAP argsParser) throws JSAPException { | ||
argsParser.registerParameter(new UnflaggedOption("app-name").setRequired(true).setHelp("the name of the application to 'j2eeify'")); | ||
} | ||
|
||
@Override | ||
public void setBRJS(BRJS brjs) | ||
{ | ||
this.brjs = brjs; | ||
this.logger = brjs.logger(this.getClass()); | ||
} | ||
|
||
@Override | ||
public String getCommandName() | ||
{ | ||
return "j2eeify"; | ||
} | ||
|
||
@Override | ||
public String getCommandDescription() | ||
{ | ||
return "Copies WEB-INF files into an application ready for adding servlets and other J2EE features"; | ||
} | ||
|
||
@Override | ||
protected int doCommand(JSAPResult parsedArgs) throws CommandArgumentsException, CommandOperationException { | ||
String appName = parsedArgs.getString("app-name"); | ||
App app = brjs.app(appName); | ||
|
||
if(!app.dirExists()) throw new CommandArgumentsException( String.format(Messages.APP_DOES_NOT_EXIST_EXCEPTION, appName), this ); | ||
|
||
Map<String, String> transformations = new HashMap<>(); | ||
transformations.put("app-name", app.getName()); | ||
try | ||
{ | ||
TemplateUtility.installTemplate(app, "j2eeify-app", transformations, true ); | ||
String webXmlContents = IOUtils.toString( ApplicationServerUtils.getDefaultWebXmlResourceLocation() ); | ||
FileUtils.write( app.file("WEB-INF/web.xml") , webXmlContents ); | ||
} | ||
catch (TemplateInstallationException | IOException ex) | ||
{ | ||
throw new CommandOperationException(ex); | ||
} | ||
|
||
String relativeWebInf = RelativePathUtility.get(app.root(), app.root().dir(), app.file("WEB-INF")); | ||
logger.println(Messages.SUCCESSFULLY_J2EEIFIED_APP_MESSAGE, appName, relativeWebInf); | ||
|
||
return 0; | ||
} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
brjs-core/src/test/java/org/bladerunnerjs/spec/command/J2eeifyCommandPluginTest.java
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,94 @@ | ||
package org.bladerunnerjs.spec.command; | ||
|
||
import org.bladerunnerjs.model.App; | ||
import org.bladerunnerjs.model.exception.command.ArgumentParsingException; | ||
import org.bladerunnerjs.model.exception.command.CommandArgumentsException; | ||
import org.bladerunnerjs.plugin.plugins.commands.standard.J2eeifyCommandPlugin; | ||
import org.bladerunnerjs.testing.specutility.engine.SpecTest; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
|
||
public class J2eeifyCommandPluginTest extends SpecTest { | ||
App app; | ||
App badApp; | ||
|
||
@Before | ||
public void initTestObjects() throws Exception | ||
{ | ||
given(brjs).hasCommandPlugins(new J2eeifyCommandPlugin()) | ||
.and(brjs).hasBeenCreated() | ||
.and(brjs).usesProductionTemplates(); | ||
app = brjs.app("app"); | ||
badApp = brjs.app("app#$@/"); | ||
brjs.appJars().create();; | ||
|
||
given(app).hasBeenCreated(); | ||
} | ||
|
||
@After | ||
public void stopAppServer() throws Exception { | ||
given(brjs.applicationServer(appServerPort)).stopped() | ||
.and(brjs.applicationServer(appServerPort)).requestTimesOutFor("/"); | ||
} | ||
|
||
@Test | ||
public void exceptionIsThrownIfThereAreTooFewArguments() throws Exception { | ||
when(brjs).runCommand("j2eeify"); | ||
then(exceptions).verifyException(ArgumentParsingException.class, unquoted("Parameter 'app-name' is required")) | ||
.whereTopLevelExceptionIs(CommandArgumentsException.class); | ||
} | ||
|
||
@Test | ||
public void exceptionIsThrownIfThereAreTooManyArguments() throws Exception { | ||
when(brjs).runCommand("j2eeify", "a", "b", "c"); | ||
then(exceptions).verifyException(ArgumentParsingException.class, unquoted("Unexpected argument: b")) | ||
.whereTopLevelExceptionIs(CommandArgumentsException.class); | ||
} | ||
|
||
@Test | ||
public void exceptionIsThrownIfTheAppDoesntExist() throws Exception { | ||
when(brjs).runCommand("j2eeify", "idontexist"); | ||
then(exceptions).verifyFormattedException(CommandArgumentsException.class, J2eeifyCommandPlugin.Messages.APP_DOES_NOT_EXIST_EXCEPTION, "idontexist"); | ||
} | ||
|
||
@Test | ||
public void templateFilesAreCopied() throws Exception { | ||
when(brjs).runCommand("j2eeify", "app"); | ||
then(app).hasDir("WEB-INF") | ||
.and(app).hasFile("WEB-INF/web.xml") | ||
.and(app).hasFile("WEB-INF/classes/log4j.properties") | ||
.and(app).hasFile("WEB-INF/lib/slf4j-log4j12-1.6.6.jar"); | ||
} | ||
|
||
@Test | ||
public void webInfIsPopulatedFromApplicationServerUtils() throws Exception { | ||
when(brjs).runCommand("j2eeify", "app"); | ||
then(app).fileContentsContains("WEB-INF/web.xml", "<servlet-class>org.bladerunnerjs.appserver.BRJSDevServlet</servlet-class>") | ||
.and(app).fileContentsDoesNotContain("WEB-INF/web.xml", "This web.xml should be empty"); | ||
} | ||
|
||
@Test | ||
public void messageIsPrintedOnSucces() throws Exception { | ||
when(brjs).runCommand("j2eeify", "app"); | ||
then(logging).containsFormattedConsoleMessage(J2eeifyCommandPlugin.Messages.SUCCESSFULLY_J2EEIFIED_APP_MESSAGE, "app", "apps/app/WEB-INF"); | ||
} | ||
|
||
@Test | ||
public void applicationServerStillStartsAfterWebInfIsCopiedIn() throws Exception { | ||
given(app.defaultAspect()).indexPageHasContent("APP INDEX PAGE"); | ||
when(brjs).runCommand("j2eeify", "app") | ||
.and(brjs.applicationServer(appServerPort)).started(); | ||
then(brjs.applicationServer(appServerPort)).requestForUrlContains("/app/en/", "APP INDEX PAGE"); | ||
} | ||
|
||
|
||
@Test | ||
public void commandIsAutomaticallyLoaded() throws Exception | ||
{ | ||
given(brjs).hasBeenAuthenticallyCreated(); | ||
when(brjs).runCommand("j2eeify", "app"); | ||
then(exceptions).verifyNoOutstandingExceptions(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...ld-resources/includes/sdk/templates/j2eeify-app-template/WEB-INF/classes/log4j.properties
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,4 @@ | ||
log4j.rootLogger=WARN, consoleAppender | ||
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender | ||
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.consoleAppender.layout.ConversionPattern=%d [%t] %-5p %c - %m%n |
8 changes: 8 additions & 0 deletions
8
brjs-sdk/build-resources/includes/sdk/templates/j2eeify-app-template/WEB-INF/jetty-env.xml
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,8 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> | ||
<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext"> | ||
<!-- required to stop Jetty warning that no transaction manager has been set --> | ||
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction"> | ||
<Arg></Arg> | ||
</New> | ||
</Configure> |
Binary file added
BIN
+478 KB
.../build-resources/includes/sdk/templates/j2eeify-app-template/WEB-INF/lib/log4j-1.2.17.jar
Binary file not shown.
Binary file added
BIN
+9.48 KB
...resources/includes/sdk/templates/j2eeify-app-template/WEB-INF/lib/slf4j-log4j12-1.6.6.jar
Binary file not shown.
1 change: 1 addition & 0 deletions
1
brjs-sdk/build-resources/includes/sdk/templates/j2eeify-app-template/WEB-INF/web.xml
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 @@ | ||
<!-- This web.xml should be empty, it's contents is populated using content from ApplicationServerUtils so it's the same as the web.xml used if an app doesn't contain a WEB-INF --> |