Parcourir la source

Flesh out project, add version resource

master
Chris Smith il y a 12 ans
Parent
révision
2d0be4cf8a

+ 25
- 4
build.xml Voir le fichier

@@ -11,8 +11,15 @@
11 11
     <mkdir dir="${build}"/>
12 12
   </target>
13 13
 
14
-  <target name="compile" depends="init" description="compile the source">
15
-    <javac srcdir="${src}" destdir="${build}" includeantruntime="false"/>
14
+  <target name="compile" depends="init,-get-version" description="compile the source">
15
+    <path id="compile-classpath">
16
+      <fileset dir="lib">
17
+        <include name="**/*.jar"/>
18
+      </fileset>
19
+    </path>
20
+
21
+    <javac srcdir="${src}" destdir="${build}" includeantruntime="false" classpathref="compile-classpath"/>
22
+    <echo file="${build}/name/smithc/chris/version">${version}</echo>
16 23
   </target>
17 24
 
18 25
   <target name="-init-version">
@@ -24,10 +31,13 @@
24 31
     <taskdef name="git-describe" classname="org.mdonoughe.JGitDescribeTask" classpathref="jgit-classpath"/>
25 32
   </target>
26 33
 
27
-  <target name="dist" depends="compile,-init-version" description="generate the distribution">
34
+  <target name="-get-version" depends="-init-version">
35
+    <git-describe dir=".git" property="version" />
36
+  </target>
37
+
38
+  <target name="dist" depends="compile,-get-version" description="generate the distribution">
28 39
     <mkdir dir="${dist}"/>
29 40
 
30
-    <git-describe dir=".git" property="version" />
31 41
     <jar jarfile="${dist}/RestIRC-${version}.jar" basedir="${build}"/>
32 42
   </target>
33 43
 
@@ -35,4 +45,15 @@
35 45
     <delete dir="${build}"/>
36 46
     <delete dir="${dist}"/>
37 47
   </target>
48
+
49
+  <target name="run" depends="compile">
50
+    <path id="run-classpath">
51
+      <pathelement path="${build}"/>
52
+      <fileset dir="lib">
53
+        <include name="**/*.jar"/>
54
+      </fileset>
55
+    </path>
56
+
57
+    <java classpathref="run-classpath" classname="name.smith.chris.restirc.RestIrc"/>
58
+  </target>
38 59
 </project>

+ 2
- 1
etc/ivy/ivysettings.xml Voir le fichier

@@ -7,7 +7,7 @@
7 7
 
8 8
         <ibiblio name="sonatype" root="https://oss.sonatype.org/content/repositories/snapshots/" m2compatible="true"/>
9 9
 
10
-        <ibiblio name="java" root="https://maven.java.net/content/repositories/snapshots/" m2compatible="true"/>
10
+        <ibiblio name="java" root="https://maven.java.net/content/repositories/releases/" m2compatible="true"/>
11 11
 
12 12
         <url name="jgit-describe">
13 13
             <ivy pattern="file:///${basedir}/etc/ivy/[module]/ivy.xml"/>
@@ -36,6 +36,7 @@
36 36
         <module organisation="org.eclipse.jgit" name="*" resolver="jgit"/>
37 37
         <module organisation="com.github.peichhorn" name="*" resolver="sonatype"/>
38 38
         <module organisation="com.sun.*" name="*" resolver="java"/>
39
+        <module organisation="javax.*" name="*" resolver="java"/>
39 40
         <module organisation="com.dmdirc" name="parser-common" resolver="dmdirc-parser-common"/>
40 41
         <module organisation="com.dmdirc" name="parser-irc" resolver="dmdirc-parser-irc"/>
41 42
         <module organisation="com.dmdirc" name="util" resolver="dmdirc-util"/>

+ 8
- 2
ivy.xml Voir le fichier

@@ -3,7 +3,7 @@
3 3
 
4 4
     <configurations>
5 5
         <conf name="build" description="Everything needed to support the build process"/>
6
-        <conf name="compile" description="Everything needed to compile RestIRC separately"/>
6
+        <conf name="compile" description="Everything needed to compile RestIRC"/>
7 7
         <conf name="test" description="Everything needed to test RestIRC"/>
8 8
         <conf name="default" extends="build,compile,test"/>
9 9
     </configurations>
@@ -16,7 +16,12 @@
16 16
 
17 17
         <dependency org="com.github.peichhorn" name="lombok-pg" rev="0.10.8-SNAPSHOT" conf="compile->default" />
18 18
 
19
-        <dependency org="com.sun.jersey" name="jersey-server" rev="1.12-SNAPSHOT" conf="compile->default"/>
19
+        <dependency org="com.sun.jersey" name="jersey-core" rev="1.+" conf="compile->default"/>
20
+        <dependency org="com.sun.jersey" name="jersey-server" rev="1.+" conf="compile->default"/>
21
+        <dependency org="com.sun.jersey" name="jersey-grizzly2" rev="1.+" conf="compile->default"/>
22
+        <dependency org="com.sun.jersey" name="jersey-json" rev="1.+" conf="compile->default"/>
23
+        <dependency org="javax.ws.rs" name="javax.ws.rs-api" rev="2.+" conf="compile->default"/>
24
+
20 25
         <dependency org="com.dmdirc" name="parser-common" rev="latest.integration" conf="compile->default"/>
21 26
         <dependency org="com.dmdirc" name="parser-irc" rev="latest.integration" conf="compile->default"/>
22 27
         <dependency org="com.dmdirc" name="util" rev="latest.integration" conf="compile->default"/>
@@ -25,5 +30,6 @@
25 30
         <dependency org="org.mockito" name="mockito-all" rev="1.+" conf="test->default" />
26 31
 
27 32
         <exclude org="ant" module="ant"/>
33
+        <exclude org="com.sun.xml.bind" module="jaxb-impl"/>
28 34
     </dependencies>
29 35
 </ivy-module>

+ 5
- 1
nbproject/project.xml Voir le fichier

@@ -39,6 +39,9 @@
39 39
                     <target>clean</target>
40 40
                     <target>compile</target>
41 41
                 </action>
42
+                <action name="run">
43
+                    <target>run</target>
44
+                </action>
42 45
             </ide-actions>
43 46
             <export>
44 47
                 <type>folder</type>
@@ -63,6 +66,7 @@
63 66
                     <ide-action name="build"/>
64 67
                     <ide-action name="rebuild"/>
65 68
                     <ide-action name="clean"/>
69
+                    <ide-action name="run"/>
66 70
                 </context-menu>
67 71
             </view>
68 72
             <subprojects/>
@@ -70,7 +74,7 @@
70 74
         <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/3">
71 75
             <compilation-unit>
72 76
                 <package-root>src</package-root>
73
-                <classpath mode="compile">lib/asm-3.1.jar:lib/hamcrest-core-1.1.jar:lib/ivy-2.2.0.jar:lib/jersey-server-1.12-SNAPSHOT.jar:lib/jgit-describe-0.1.jar:lib/jsch-0.1.44-1.jar:lib/junit-4.10.jar:lib/logback-classic-1.0.0.jar:lib/logback-core-1.0.0.jar:lib/lombok-pg-0.10.8-SNAPSHOT.jar:lib/mockito-all-1.9.0.jar:lib/org.eclipse.jgit-1.2.0.201112221803-r.jar:lib/parser-common-working@dmdirc-parser-common.jar:lib/parser-irc-working@dmdirc-parser-irc.jar:lib/slf4j-api-1.6.4.jar:lib/util-working@dmdirc-util.jar</classpath>
77
+                <classpath mode="compile">lib/asm-3.1.jar:lib/gmbal-api-only-3.0.0-b023.jar:lib/grizzly-framework-2.1.2.jar:lib/grizzly-http-2.1.2.jar:lib/grizzly-http-server-2.1.2.jar:lib/grizzly-rcm-2.1.2.jar:lib/hamcrest-core-1.1.jar:lib/ivy-2.2.0.jar:lib/jackson-core-asl-1.9.2.jar:lib/jackson-jaxrs-1.9.2.jar:lib/jackson-mapper-asl-1.9.2.jar:lib/jackson-xc-1.9.2.jar:lib/javax.ws.rs-api-2.0-m01.jar:lib/jersey-grizzly2-1.11.jar:lib/jersey-json-1.11.jar:lib/jersey-server-1.11.jar:lib/jettison-1.1.jar:lib/jgit-describe-0.1.jar:lib/jsch-0.1.44-1.jar:lib/junit-4.10.jar:lib/logback-classic-1.0.0.jar:lib/logback-core-1.0.0.jar:lib/lombok-pg-0.10.8-SNAPSHOT.jar:lib/management-api-3.0.0-b012.jar:lib/mockito-all-1.9.0.jar:lib/org.eclipse.jgit-1.2.0.201112221803-r.jar:lib/parser-common-working@dmdirc-parser-common.jar:lib/parser-irc-working@dmdirc-parser-irc.jar:lib/slf4j-api-1.6.4.jar:lib/stax-api-1.0.1.jar:lib/util-working@dmdirc-util.jar</classpath>
74 78
                 <built-to>build</built-to>
75 79
                 <source-level>1.7</source-level>
76 80
             </compilation-unit>

+ 26
- 0
src/name/smith/chris/restirc/RestIrc.java Voir le fichier

@@ -0,0 +1,26 @@
1
+package name.smith.chris.restirc;
2
+
3
+import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
4
+import com.sun.jersey.api.core.PackagesResourceConfig;
5
+import com.sun.jersey.api.core.ResourceConfig;
6
+
7
+import java.net.URI;
8
+
9
+import javax.ws.rs.core.UriBuilder;
10
+
11
+/**
12
+ * Main program entry point. Handles initialisation logic.
13
+ */
14
+public class RestIrc {
15
+
16
+    private static URI getBaseURI() {
17
+        return UriBuilder.fromUri("http://localhost/").port(9998).build();
18
+    }
19
+
20
+    public static void main(final String[] args) throws Exception {
21
+        ResourceConfig rc = new PackagesResourceConfig("name.smith.chris.restirc.resources");
22
+        GrizzlyServerFactory.createHttpServer(getBaseURI(), rc);
23
+        System.in.read();
24
+    }
25
+
26
+}

+ 37
- 0
src/name/smith/chris/restirc/resources/VersionResource.java Voir le fichier

@@ -0,0 +1,37 @@
1
+package name.smith.chris.restirc.resources;
2
+
3
+import com.dmdirc.util.io.TextFile;
4
+
5
+import java.io.IOException;
6
+
7
+import javax.ws.rs.GET;
8
+import javax.ws.rs.Path;
9
+import javax.ws.rs.Produces;
10
+import javax.ws.rs.WebApplicationException;
11
+import javax.ws.rs.core.Response;
12
+
13
+/**
14
+ * Version resource. Simply returns the current version of the application.
15
+ */
16
+@Path("/version")
17
+public class VersionResource {
18
+
19
+    /**
20
+     * Gets the textual representation of the version.
21
+     *
22
+     * @return The textual representation of the version.
23
+     */
24
+    @GET
25
+    @Produces("text/plain")
26
+    public String getVersion() {
27
+        try {
28
+            final TextFile textFile = new TextFile(getClass()
29
+                    .getResourceAsStream("/name/smithc/chris/version"));
30
+            return textFile.getLines().get(0);
31
+        } catch (IOException ex) {
32
+            throw new WebApplicationException(ex,
33
+                    Response.Status.INTERNAL_SERVER_ERROR);
34
+        }
35
+    }
36
+
37
+}

Chargement…
Annuler
Enregistrer