Work on CLI

This commit is contained in:
James Agnew 2015-09-11 16:13:40 -04:00
parent 1961042d11
commit 2c1ca358fe
10 changed files with 309 additions and 91 deletions

2
.gitignore vendored
View File

@ -19,7 +19,7 @@ tmp.txt
.vagrant
/vagrant/build
/vagrant/chef/tmp
jpaserver_derby_files
# Created by https://www.gitignore.io

View File

@ -1,8 +1,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Note: HAPI projects use the "hapi-fhir" POM as their base to provide easy management. You do not need to use this in your own projects, so the "parent" tag
and it's contents below may be removed if you are using this file as a basis for your own project. -->
<!-- Note: HAPI projects use the "hapi-fhir" POM as their base to provide easy management. You do not need to use this in your own projects, so the "parent" tag and it's contents below may be removed
if you are using this file as a basis for your own project. -->
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
@ -24,6 +24,12 @@
<artifactId>hapi-fhir-base</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-example</artifactId>
<version>1.2-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2</artifactId>
@ -49,6 +55,11 @@
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
@ -60,55 +71,58 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</dependency>
</dependencies>
<build>
<!-- Tells Maven to name the generated WAR file as hapi-fhir-jpaserver-example.war -->
<finalName>hapi-fhir-jpaserver-example</finalName>
<!-- The following is not required for the application to build, but allows you to test it by issuing "mvn jetty:run" from the command line. -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.1.v20140108</version>
<configuration>
<webApp>
<contextPath>/hapi-fhir-jpaserver-example</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- Tell Maven which Java source version you want to use -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-example</artifactId>
<version>1.2-SNAPSHOT</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>target/classes</outputDirectory>
<destFileName>hapi-fhir-jpaserver-example.war</destFileName>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>
<!-- The configuration here tells the WAR plugin to include the FHIR Tester overlay. You can omit it if you are not using that feature. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<overlay>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-testpage-overlay</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
<!-- This plugin is just a part of the HAPI internal build process, you do not need to incude it in your own projects -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
@ -116,7 +130,38 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>hapi-fhir-cli</finalName>
<artifactSet>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>ca.uhn.fhir.cli.App</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*</artifact>
<excludes>
<exclude>**/*.SF</exclude>
<exclude>**/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -0,0 +1,55 @@
package ca.uhn.fhir.cli;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
public class App {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(App.class);
private static List<BaseCommand> ourCommands;
static {
ourCommands = new ArrayList<BaseCommand>();
ourCommands.add(new RunServerCommand());
}
public static void main(String[] theArgs) {
if (theArgs.length == 0) {
logUsage();
return;
}
BaseCommand command = null;
for (BaseCommand nextCommand : ourCommands) {
if (nextCommand.getCommandName().equals(theArgs[0])) {
command = nextCommand;
break;
}
}
Options options = command.getOptions();
DefaultParser parser = new DefaultParser();
CommandLine parsedOptions;
try {
String[] args = Arrays.asList(theArgs).subList(1, theArgs.length).toArray(new String[theArgs.length - 1]);
parsedOptions = parser.parse(options, args, true);
command.run(parsedOptions);
} catch (ParseException e) {
ourLog.error("Invalid command options for command: " + command.getCommandName());
ourLog.error(e.getMessage());
ourLog.error("Aborting!");
return;
}
}
private static void logUsage() {
}
}

View File

@ -1,5 +1,9 @@
package ca.uhn.fhir.cli;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.IGenericClient;
@ -14,4 +18,18 @@ public class BaseCommand {
return fhirClient;
}
public Options getOptions() {
return null;
}
public String getCommandName() {
// TODO Auto-generated method stub
return null;
}
public void run(CommandLine theCommandLine) throws ParseException {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,102 @@
package ca.uhn.fhir.cli;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class RunServerCommand extends BaseCommand {
private static final int DEFAULT_PORT = 8080;
private static final String OPTION_P = "p";
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RunServerCommand.class);
private int myPort;
private Server myServer;
@Override
public String getCommandName() {
return "run-server";
}
@Override
public Options getOptions() {
Options options = new Options();
options.addOption(OPTION_P, "port", true, "The port to listen on (default is " + DEFAULT_PORT + ")");
return options;
}
private int parseOptionInteger(CommandLine theCommandLine, String opt, int defaultPort) throws ParseException {
try {
return Integer.parseInt(theCommandLine.getOptionValue(opt, Integer.toString(defaultPort)));
} catch (NumberFormatException e) {
throw new ParseException("Invalid value '" + theCommandLine.getOptionValue(opt) + " (must be numeric)");
}
}
@Override
public void run(CommandLine theCommandLine) throws ParseException {
myPort = parseOptionInteger(theCommandLine, OPTION_P, DEFAULT_PORT);
ourLog.info("Preparing HAPI FHIR JPA server");
File tempWarFile;
try {
tempWarFile = File.createTempFile("hapi-fhir", ".war");
tempWarFile.deleteOnExit();
InputStream inStream = RunServerCommand.class.getResourceAsStream("/hapi-fhir-jpaserver-example.war");
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(tempWarFile, false));
IOUtils.copy(inStream, outStream);
} catch (IOException e) {
ourLog.error("Failed to create temporary file", e);
return;
}
ourLog.info("Starting HAPI FHIR JPA server");
WebAppContext root = new WebAppContext();
root.setAllowDuplicateFragmentNames(true);
root.setWar(tempWarFile.getAbsolutePath());
root.setContextPath("/");
myServer = new Server(myPort);
myServer.setHandler(root);
try {
myServer.start();
} catch (Exception e) {
ourLog.error("Server failed to start", e);
return;
}
ourLog.info("Server started on port {}", myPort);
ourLog.info("Web Testing UI : http://localhost:{}/", myPort);
ourLog.info("Server Base URL: http://localhost:{}/baseDstu2/", myPort);
}
public void run(String[] theArgs) {
getOptions();
// myServer = new Server(myPort);
//
// WebAppContext webAppContext = new WebAppContext();
// webAppContext.setContextPath("/");
// webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml");
// webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-example");
// webAppContext.setParentLoaderPriority(true);
//
// myServer.setHandler(webAppContext);
// myServer.start();
}
}

View File

@ -258,8 +258,6 @@
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -10,7 +10,6 @@
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>ca.uhn.hapi.example</groupId>
<artifactId>hapi-fhir-jpaserver-example</artifactId>
<packaging>war</packaging>

View File

@ -12,7 +12,7 @@
<bean class="ca.uhn.fhir.to.TesterConfig">
<property name="servers">
<list>
<value>home , DSTU2 , Local Server , ${serverBase}/base</value>
<value>home , DSTU2 , Local Server , ${serverBase}/baseDstu2</value>
</list>
</property>
</bean>

View File

@ -49,7 +49,7 @@
<servlet-mapping>
<servlet-name>fhirServlet</servlet-name>
<url-pattern>/base/*</url-pattern>
<url-pattern>/baseDstu2/*</url-pattern>
</servlet-mapping>
<servlet-mapping>

79
pom.xml
View File

@ -209,9 +209,8 @@
<apache_httpclient_version>4.4</apache_httpclient_version>
<apache_httpcore_version>4.4</apache_httpcore_version>
<derby_version>10.11.1.1</derby_version>
<!-- Note on Hibernate versions: Hibernate 4.3+ uses JPA 2.1, which is too new for a number of platforms including JBoss EAP 6.x and Glassfish 3.0. Upgrade this
version with caution! Also note that if you change this, you may get a failure in hibernate4-maven-plugin. See the note in hapi-fhir-jpaserver-base/pom.xml's configuration
for that plugin... <hibernate_version>4.3.7.Final</hibernate_version> -->
<!-- Note on Hibernate versions: Hibernate 4.3+ uses JPA 2.1, which is too new for a number of platforms including JBoss EAP 6.x and Glassfish 3.0. Upgrade this version with caution! Also note that if
you change this, you may get a failure in hibernate4-maven-plugin. See the note in hapi-fhir-jpaserver-base/pom.xml's configuration for that plugin... <hibernate_version>4.3.7.Final</hibernate_version> -->
<hibernate_version>4.2.17.Final</hibernate_version>
<hibernate_validator_version>5.1.0.Final</hibernate_validator_version>
<jetty_version>9.2.6.v20141205</jetty_version>
@ -263,15 +262,20 @@
<version>${phloc_commons_version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
@ -562,6 +566,11 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
@ -821,47 +830,43 @@
<configuration>
<target>
<copy todir="target/site/apidocs">
<fileset dir="hapi-fhir-base/target/site/apidocs" />
<fileset dir="hapi-fhir-base/target/site/apidocs"/>
</copy>
<copy todir="target/site/apidocs-dstu">
<fileset dir="hapi-fhir-structures-dstu/target/site/apidocs" />
<fileset dir="hapi-fhir-structures-dstu/target/site/apidocs"/>
</copy>
<copy todir="target/site/apidocs-hl7org-dstu2">
<fileset dir="hapi-fhir-structures-hl7org-dstu2/target/site/apidocs" />
<fileset dir="hapi-fhir-structures-hl7org-dstu2/target/site/apidocs"/>
</copy>
<copy todir="target/site/apidocs-dstu2">
<fileset dir="hapi-fhir-structures-dstu2/target/site/apidocs" />
<fileset dir="hapi-fhir-structures-dstu2/target/site/apidocs"/>
</copy>
<copy todir="target/site/apidocs-jpaserver">
<fileset dir="hapi-fhir-jpaserver-base/target/site/apidocs" />
<fileset dir="hapi-fhir-jpaserver-base/target/site/apidocs"/>
</copy>
<copy todir="target/site/xref-jpaserver">
<fileset dir="hapi-fhir-jpaserver-base/target/site/xref" />
<fileset dir="hapi-fhir-jpaserver-base/target/site/xref"/>
</copy>
<copy todir="target/site/xref-base">
<fileset dir="hapi-fhir-base/target/site/xref" />
<fileset dir="hapi-fhir-base/target/site/xref"/>
</copy>
<!--
<copy todir="target/site/cobertura">
<fileset dir="hapi-fhir-cobertura/target/site/cobertura" />
</copy>
-->
<!-- <copy todir="target/site/cobertura"> <fileset dir="hapi-fhir-cobertura/target/site/cobertura" /> </copy> -->
<copy todir="target/site">
<fileset dir="hapi-fhir-base/target/site" includes="checkstyle.*" />
<fileset dir="hapi-fhir-base/target/site" includes="checkstyle.*"/>
</copy>
<echo>Fixing Checkstyle Report</echo>
<replace dir="target/site" summary="true">
<include name="checkstyle.html" />
<include name="checkstyle.html"/>
<replacetoken>"../../</replacetoken>
<replacevalue>"./</replacevalue>
</replace>
<replace dir="target/site" summary="true">
<include name="*.html" />
<include name="*.html"/>
<replacetoken>http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css</replacetoken>
<replacevalue>./css/bootstrap-responsive.min.css</replacevalue>
</replace>
<replace dir="target/site" summary="true">
<include name="index.html" />
<include name="index.html"/>
<replacetoken><![CDATA[<h2 id="Welcome">Welcome</h2>]]></replacetoken>
<replacevalue><![CDATA[<div class="jumbotron subhead">
<div class="row" id="banner">
@ -890,33 +895,33 @@
<target>
<echo>Adding Fontawesome</echo>
<replace dir="target/site" summary="true">
<include name="*.html" />
<include name="*.html"/>
<replacetoken><![CDATA[<a href="download.html" title="Download">Download</a>]]></replacetoken>
<replacevalue><![CDATA[<a href="download.html" title="Download"><i class="fa fa-download"></i> Download</a>]]></replacevalue>
</replace>
<replace dir="target/site" summary="true">
<include name="*.html" />
<include name="*.html"/>
<replacetoken><![CDATA[<a href="https://github.com/jamesagnew/hapi-fhir/" title="GitHub Project" class="externalLink">GitHub Project</a>]]></replacetoken>
<replacevalue><![CDATA[<a href="https://github.com/jamesagnew/hapi-fhir/" title="GitHub Project" class="externalLink"><i class="fa fa-github"></i> GitHub Project</a>]]></replacevalue>
</replace>
<replace dir="target/site" summary="true">
<include name="*.html" />
<include name="*.html"/>
<replacetoken><![CDATA[data-toggle="dropdown">Test Servers <]]></replacetoken>
<replacevalue><![CDATA[data-toggle="dropdown"><i class="fa fa-fire"></i>&nbsp;Test Servers&nbsp;<]]></replacevalue>
</replace>
<replace dir="target/site" summary="true">
<include name="*.html" />
<include name="*.html"/>
<replacetoken><![CDATA[data-toggle="dropdown">Documentation <]]></replacetoken>
<replacevalue><![CDATA[data-toggle="dropdown"><i class="fa fa-book"></i>&nbsp;Documentation&nbsp;<]]></replacevalue>
</replace>
<replace dir="target/site" summary="true">
<include name="*.html" />
<include name="*.html"/>
<replacetoken><![CDATA[data-toggle="dropdown">Get Help <]]></replacetoken>
<replacevalue><![CDATA[data-toggle="dropdown"><i class="fa fa-support"></i>&nbsp;Get Help&nbsp;<]]></replacevalue>
</replace>
<echo>Changing Breadcrumbs</echo>
<replace dir="target/site" summary="true">
<include name="doc_*.html" />
<include name="doc_*.html"/>
<replacetoken><![CDATA[<li class="divider">/</li>]]></replacetoken>
<replacevalue><![CDATA[<li class="divider">/</li>
<li><a href="docindex.html" title="Documentation">Documentation</a></li>
@ -967,8 +972,8 @@
<echo>Adding Google analytics in target/site for &lt;body&gt;</echo>
<replace dir="target/site" summary="true">
<include name="**/*.html"></include>
<replacefilter token="#build#" value="${label}" />
<replacefilter token="#version#" value="${project.version}" />
<replacefilter token="#build#" value="${label}"/>
<replacefilter token="#version#" value="${project.version}"/>
<replacetoken><![CDATA[</body>]]></replacetoken>
<replacevalue><![CDATA[
<script>
@ -1106,9 +1111,8 @@
<reporting>
<plugins>
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <reportSets> <reportSet> <reports><report>checkstyle-aggregate</report></reports>
</reportSet> </reportSets> <configuration> <configLocation>config/sun_checks.xml</configLocation> <includes> hapi-fhir-base/src/main/java/**/*.java </includes> </configuration>
</plugin> -->
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <reportSets> <reportSet> <reports><report>checkstyle-aggregate</report></reports> </reportSet>
</reportSets> <configuration> <configLocation>config/sun_checks.xml</configLocation> <includes> hapi-fhir-base/src/main/java/**/*.java </includes> </configuration> </plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
@ -1183,9 +1187,8 @@
</modules>
<build>
<plugins>
<!-- <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>${maven_assembly_plugin_version}</version> <executions> <execution> <phase>package</phase>
<goals> <goal>single</goal> </goals> <configuration> <attach>false</attach> <descriptors> <descriptor>${project.basedir}/src/assembly/hapi-fhir-sample-projects.xml</descriptor>
</descriptors> </configuration> </execution> </executions> </plugin> -->
<!-- <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>${maven_assembly_plugin_version}</version> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals>
<configuration> <attach>false</attach> <descriptors> <descriptor>${project.basedir}/src/assembly/hapi-fhir-sample-projects.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> -->
</plugins>
</build>
@ -1224,9 +1227,7 @@
<module>hapi-fhir-structures-dstu2</module>
<module>hapi-fhir-structures-hl7org-dstu2</module>
<module>hapi-fhir-jpaserver-base</module>
<!--
<module>hapi-fhir-cobertura</module>
-->
<!-- <module>hapi-fhir-cobertura</module> -->
<module>examples</module>
</modules>
<reporting>