Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added scala library support #2

Merged
merged 3 commits into from
Sep 5, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions bin/generate-scala-lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
if [ $# -ne 4 ]
then
echo "Error in $0 - Invalid Argument Count"
echo "Syntax: $0 location_of_service api_key package_name library_root"
exit
fi

echo "" > classpath.txt
for file in `ls lib`;
do echo -n 'lib/' >> classpath.txt;
echo -n $file >> classpath.txt;
echo -n ':' >> classpath.txt;
done
for file in `ls build`;
do echo -n 'build/' >> classpath.txt;
echo -n $file >> classpath.txt;
echo -n ':' >> classpath.txt;
done

export CLASSPATH=$(cat classpath.txt):conf/scala/templates
export JAVA_OPTS="${JAVA_OPTS} -Dproperty=Xmx2g"
scala $WORDNIK_OPTS $JAVA_CONFIG_OPTIONS $JAVA_OPTS -cp $CLASSPATH com.wordnik.swagger.codegen.config.scala.ScalaLibCodeGen "$@"
128 changes: 128 additions & 0 deletions conf/scala/sample/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0"?>
<project name="swagger-sample-scala-lib" xmlns:ivy="antlib:org.apache.ivy.ant" default="build.all" basedir=".">
<property environment="env" />
<property name="version.identifier" value="1.0" />
<property name="artifact.ext" value="jar" />
<property name="organization" value="wordnik" />
<property name="module" value="${ant.project.name}" />

<!-- default dirs for the build -->
<mkdir dir="lib"/>
<mkdir dir="lib/ext"/>

<condition property="scala.home" value="${env.SCALA_HOME}">
<isset property="env.SCALA_HOME" />
</condition>

<path id="scala.classpath">
<fileset dir="${scala.home}/lib">
<include name="scala**.jar" />
</fileset>
</path>

<ivy:settings file="ivysettings.xml" />

<taskdef resource="scala/tools/ant/antlib.xml">
<classpath>
<fileset dir="lib">
<include name="scala**.jar" />
</fileset>
<fileset dir="${scala.home}/lib">
<include name="scala**.jar" />
</fileset>
</classpath>
</taskdef>

<!-- this is the output module -->
<property name="module" value="${ant.project.name}" />

<target name="build.all" depends="clean, resolve, fastcompile" description="builds the module (default target)" />

<target name="clean" description="cleans the project folder">
<mkdir dir="build" />
<echo message="deleting build files" />
<delete quiet="true">
<fileset dir="build">
<include name="*.jar" />
<include name="*.xml" />
</fileset>
</delete>

<delete dir="build/main" quiet="true" />

<delete dir="dist" quiet="true" />

<!-- libraries handled by ivy -->
<echo message="deleting libs handled by ivy" />
<delete>
<fileset dir="lib">
<include name="*.jar" />
<include name="*.zip" />
</fileset>
</delete>
</target>

<!-- copies ONLY the swagger-sample jar to dist-->
<target name="fastdist" depends="fastcompile">
<copy todir="dist/lib">
<fileset dir="build">
<include name="*.jar" />
</fileset>
</copy>
</target>

<!-- copies all dependencies into the lib folder -->
<target name="resolve" description="retreive dependencies with ivy">
<ivy:retrieve pattern="${basedir}/lib/[artifact]-[revision].[ext]" conf="build" />
</target>

<target name="fastcompile" description="builds the module without artifact resolution or cleaning">
<delete quiet="true" file="build/${organization}-${artifact}-*.${artifact.ext}" />
<mkdir dir="build" />
<mkdir dir="build/main" />
<mkdir dir="build/main/java" />

<javac srcdir="src/main/java" debug="true" destdir="build/main/java">
<classpath>
<fileset dir="lib">
<include name="*.jar" />
</fileset>
<fileset dir="lib/ext">
<include name="*.jar" />
</fileset>
<pathelement location="build/main/java" />
</classpath>
</javac>


<scalac srcdir="src/main/java:src/main/scala" destdir="build/main/java">
<classpath>
<pathelement location="build/main/java" />
<fileset dir="lib">
<include name="*.jar" />
</fileset>
<fileset dir="lib/ext">
<include name="*.jar" />
</fileset>
<fileset dir="${scala.home}/lib"/>
</classpath>
<include name="**/*.scala" />
<include name="**/*.java" />
</scalac>

<jar jarfile="build/${module}-${version.identifier}.${artifact.ext}">
<fileset dir="build/main/java" />
</jar>
</target>

<!-- cleans up the dist -->
<target name="dist.clean" description="cleans the distribution folder">
<delete quiet="true" dir="dist" />
<delete quiet="true" file="dist.zip" />
</target>

<target name="dependency.tree" description="builds a graphml dependency diagram for viewing with yEd">
<ivy:report conf="build" graph="true" todir="." outputpattern="[artifact]-[revision].[ext]" />
</target>

</project>
31 changes: 31 additions & 0 deletions conf/scala/sample/ivy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<ivy-module version="2.0">
<info organisation="wordnik" module="sample-java-lib"/>
<configurations>
<conf name="build" description="build wordnik-java"/>
<conf name="test" visibility="public"/>
<conf name="source" visibility="public"/>
<conf name="pom" visibility="public"/>
</configurations>

<dependencies>
<!-- jersey dependencies -->
<dependency org="junit" name="junit" rev="4.4" conf="build->default"/>
<dependency org="com.sun.jersey" name="jersey-json" rev="1.4" conf="build->default"/>
<dependency org="com.sun.jersey" name="jersey-client" rev="1.4" conf="build->default"/>
<dependency org="com.sun.jersey" name="jersey-server" rev="1.4" conf="build->default"/>
<dependency org="com.sun.jersey" name="jersey-core" rev="1.4" conf="build->default"/>
<dependency org="asm" name="asm-parent" rev="3.1" conf="build->default"/>
<dependency org="commons-beanutils" name="commons-beanutils" rev="1.8.0" conf="build->default"/>
<dependency org="org.antlr" name="stringtemplate" rev="3.2" conf="build->default"/>
<!-- jackson jars -->
<dependency org="org.codehaus.jackson" name="jackson-jaxrs" rev="1.7.1" conf="build->default"/>
<dependency org="org.codehaus.jackson" name="jackson-xc" rev="1.7.1" conf="build->default"/>
<dependency org="org.codehaus.jackson" name="jackson-mapper-asl" rev="1.7.1" conf="build->default"/>


<dependency org="net.sourceforge.cobertura" name="cobertura" rev="1.9.2" conf="test->default">
<exclude org="asm" name="asm-tree"/>
<exclude org="asm" name="asm"/>
</dependency>
</dependencies>
</ivy-module>
23 changes: 23 additions & 0 deletions conf/scala/sample/ivysettings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<ivysettings>
<settings defaultResolver="chained" />
<property name="ivy.checksums" value=""/>
<property name="ivy.local.default.root" value="${ivy.default.ivy.user.dir}/local"
override="false" />
<property name="ivy.local.default.ivy.pattern"
value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
override="false" />
<property name="ivy.local.default.artifact.pattern"
value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
override="false" />
<resolvers>
<chain name="chained" returnFirst="true">
<filesystem name="local">
<ivy pattern="${ivy.local.default.root}/${ivy.local.default.ivy.pattern}" />
<artifact pattern="${ivy.local.default.root}/${ivy.local.default.artifact.pattern}" />
</filesystem>
<ibiblio name="ibiblio" m2compatible="true" />
<ibiblio name="javanet" root="http://download.java.net/maven/2/" m2compatible="true" />
</chain>
</resolvers>
</ivysettings>
27 changes: 27 additions & 0 deletions conf/scala/sample/java_code_gen_conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"apiUrl":"http://localhost:8002/api/",

"apiKey":"special-key",

"defaultServiceBaseClass":"Object",

"defaultModelBaseClass":"Object",

"serviceBaseClasses":{},

"defaultModelImports":[],

"defaultServiceImports":[],

"modelPackageName":"com.wordnik.swagger.sample.sdk.java.model",

"apiPackageName":"com.wordnik.swagger.sample.sdk.java.api",

"ignoreMethods":[],

"ignoreModels":[],

"outputDirectory":"../swagger-sample-app/sdk-libs/src/main/java/com/wordnik/swagger/sample/sdk/java",

"libraryHome":"../swagger-sample-app/sdk-libs"
}
42 changes: 42 additions & 0 deletions conf/scala/sample/lib-test-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"userList":[
{
"username":"testuser1",
"password":"password1",
"email":"test1@dummy.com"
},
{
"username":"testuser2",
"password":"password2",
"email":"test2@dummy.com"
}
],
"petList":[
{
"id":101,
"name":"pet1",
"photoUrls":["url1","url2"],
"tags":[
{
"id":1,
"name":"tag1"
},
{
"id":2,
"name":"tag2"
}
],
"status":"available",
"category":{"id":1,"name":"cat1"}
}
],
"orderList":[
{
"id":101,
"petId":1,
"quantity":1,
"status":"placed",
"shipDate":13456789
}
]
}
Loading