Skip to content

Commit ccec55c

Browse files
committed
Added initial scala based Hal Implicit Conversions
1 parent 5e601c9 commit ccec55c

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed

pom.xml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.theoryinpractise</groupId>
5+
<artifactId>halbuilder-scala</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>${project.artifactId}</name>
8+
<description>My wonderfull scala app</description>
9+
<inceptionYear>2010</inceptionYear>
10+
<licenses>
11+
<license>
12+
<name>My License</name>
13+
<url>http://....</url>
14+
<distribution>repo</distribution>
15+
</license>
16+
</licenses>
17+
18+
<properties>
19+
<maven.compiler.source>1.5</maven.compiler.source>
20+
<maven.compiler.target>1.5</maven.compiler.target>
21+
<encoding>UTF-8</encoding>
22+
<scala.version>2.10.0-M7</scala.version>
23+
</properties>
24+
25+
<!--
26+
<repositories>
27+
<repository>
28+
<id>scala-tools.org</id>
29+
<name>Scala-Tools Maven2 Repository</name>
30+
<url>http://scala-tools.org/repo-releases</url>
31+
</repository>
32+
</repositories>
33+
34+
<pluginRepositories>
35+
<pluginRepository>
36+
<id>scala-tools.org</id>
37+
<name>Scala-Tools Maven2 Repository</name>
38+
<url>http://scala-tools.org/repo-releases</url>
39+
</pluginRepository>
40+
</pluginRepositories>
41+
-->
42+
<dependencies>
43+
<dependency>
44+
<groupId>org.scala-lang</groupId>
45+
<artifactId>scala-library</artifactId>
46+
<version>${scala.version}</version>
47+
</dependency>
48+
49+
50+
<dependency>
51+
<groupId>com.theoryinpractise</groupId>
52+
<artifactId>halbuilder-core</artifactId>
53+
<version>2.0.1-SNAPSHOT</version>
54+
</dependency>
55+
56+
<!-- Test -->
57+
<dependency>
58+
<groupId>junit</groupId>
59+
<artifactId>junit</artifactId>
60+
<version>4.8.1</version>
61+
<scope>test</scope>
62+
</dependency>
63+
<!--<dependency>-->
64+
<!--<groupId>org.scala-tools.testing</groupId>-->
65+
<!--<artifactId>specs_${scala.version}</artifactId>-->
66+
<!--<version>1.6.5</version>-->
67+
<!--<scope>test</scope>-->
68+
<!--</dependency>-->
69+
<dependency>
70+
<groupId>org.scalatest</groupId>
71+
<artifactId>scalatest</artifactId>
72+
<version>1.2</version>
73+
<scope>test</scope>
74+
</dependency>
75+
</dependencies>
76+
77+
<build>
78+
<sourceDirectory>src/main/scala</sourceDirectory>
79+
<testSourceDirectory>src/test/scala</testSourceDirectory>
80+
<plugins>
81+
<plugin>
82+
<groupId>org.scala-tools</groupId>
83+
<artifactId>maven-scala-plugin</artifactId>
84+
<version>2.15.2</version>
85+
<executions>
86+
<execution>
87+
<goals>
88+
<goal>compile</goal>
89+
<goal>testCompile</goal>
90+
</goals>
91+
<configuration>
92+
<args>
93+
<arg>-make:transitive</arg>
94+
<arg>-dependencyfile</arg>
95+
<arg>${project.build.directory}/.scala_dependencies</arg>
96+
</args>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
<plugin>
102+
<groupId>org.apache.maven.plugins</groupId>
103+
<artifactId>maven-surefire-plugin</artifactId>
104+
<version>2.12.2</version>
105+
<configuration>
106+
<useFile>false</useFile>
107+
<disableXmlReport>true</disableXmlReport>
108+
<!-- If you have classpath issue like NoDefClassError,... -->
109+
<!-- useManifestOnlyJar>false</useManifestOnlyJar -->
110+
<includes>
111+
<include>**/*Test.*</include>
112+
<include>**/*Suite.*</include>
113+
</includes>
114+
</configuration>
115+
</plugin>
116+
</plugins>
117+
</build>
118+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.theoryinpractise.halbuilder.scala
2+
3+
import com.theoryinpractise.halbuilder.api.Representation
4+
5+
object HalImplicits {
6+
7+
class RichRepresentation(r : Representation) {
8+
def tryValue(name: String) : Option[Object] = Option(r.getValue(name))
9+
}
10+
11+
implicit def RichRepresentation(r: Representation) = new RichRepresentation(r)
12+
13+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.theoryinpractise.halbuilder.scala
2+
3+
import org.junit._
4+
import com.theoryinpractise.halbuilder.DefaultRepresentationFactory
5+
import com.theoryinpractise.halbuilder.api.RepresentationFactory
6+
import com.theoryinpractise.halbuilder.scala.HalImplicits._
7+
8+
@Test
9+
class HalScalaTest {
10+
11+
@Test
12+
def testHal() = {
13+
14+
val rf = new DefaultRepresentationFactory()
15+
val resource = rf.newRepresentation()
16+
val json = resource.withProperty("name", "mark").renderContent(RepresentationFactory.HAL_JSON)
17+
18+
println(json)
19+
20+
val name = resource.tryValue("name").getOrElse("[unknown]")
21+
println(s"Name is $name")
22+
23+
}
24+
25+
}

0 commit comments

Comments
 (0)