Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit 5ab7b58

Browse files
committed
Each resource now reports its resolver
1 parent bd45abb commit 5ab7b58

19 files changed

+247
-310
lines changed

pom.xml

+29-12
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@
9797
<dependency>
9898
<groupId>com.ckkloverdos</groupId>
9999
<artifactId>typedkey</artifactId>
100-
<version>0.5.0</version>
100+
<version>0.7.0</version>
101101
</dependency>
102102
<dependency>
103103
<groupId>junit</groupId>
104104
<artifactId>junit</artifactId>
105-
<version>4.10</version>
105+
<version>4.11</version>
106106
<scope>test</scope>
107107
</dependency>
108108
</dependencies>
109109

110110
<build>
111-
<sourceDirectory>src/main/scala</sourceDirectory>
112-
<testSourceDirectory>src/test/scala</testSourceDirectory>
111+
<sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
112+
<testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>
113113
<resources>
114114
<resource>
115115
<directory>${basedir}/src/main/resources</directory>
@@ -145,23 +145,39 @@
145145
</plugin>
146146

147147
<plugin>
148-
<groupId>org.scala-tools</groupId>
149-
<artifactId>maven-scala-plugin</artifactId>
150-
<version>2.15.2</version>
148+
<groupId>net.alchim31.maven</groupId>
149+
<artifactId>scala-maven-plugin</artifactId>
150+
<version>3.1.0</version>
151151
<configuration>
152+
<recompileMode>incremental</recompileMode>
152153
<scalaVersion>${scala.version}</scalaVersion>
153154
<charset>${project.build.sourceEncoding}</charset>
155+
<javacArgs>
156+
<javacArg>-Xlint:unchecked</javacArg>
157+
<javacArg>-Xlint:deprecation</javacArg>
158+
</javacArgs>
154159
<args>
155160
<arg>-deprecation</arg>
156161
<arg>-unchecked</arg>
157162
<arg>-optimize</arg>
158163
</args>
159-
<charset>${project.build.sourceEncoding}</charset>
160164
</configuration>
161165
<executions>
162166
<execution>
167+
<id>scala-compile-first</id>
168+
<phase>process-resources</phase>
163169
<goals>
170+
<goal>add-source</goal>
164171
<goal>compile</goal>
172+
<goal>doc-jar</goal>
173+
</goals>
174+
</execution>
175+
176+
<execution>
177+
<id>scala-test-compile</id>
178+
<phase>process-test-resources</phase>
179+
<goals>
180+
<!--<goal>add-source</goal>-->
165181
<goal>testCompile</goal>
166182
</goals>
167183
</execution>
@@ -171,7 +187,7 @@
171187
<plugin>
172188
<groupId>org.apache.maven.plugins</groupId>
173189
<artifactId>maven-surefire-plugin</artifactId>
174-
<version>2.9</version>
190+
<version>2.12.4</version>
175191
<configuration>
176192
<useFile>false</useFile>
177193
<reportFormat>plain</reportFormat>
@@ -181,21 +197,22 @@
181197
<plugin>
182198
<groupId>org.apache.maven.plugins</groupId>
183199
<artifactId>maven-source-plugin</artifactId>
184-
<version>2.1.2</version>
200+
<version>2.2.1</version>
185201
<executions>
186202
<execution>
187203
<id>attach-sources</id>
188204
<goals>
189-
<goal>jar-no-fork</goal>
205+
<goal>jar</goal>
190206
</goals>
207+
<phase>package</phase>
191208
</execution>
192209
</executions>
193210
</plugin>
194211

195212
<plugin>
196213
<groupId>org.apache.maven.plugins</groupId>
197214
<artifactId>maven-release-plugin</artifactId>
198-
<version>2.2.2</version>
215+
<version>2.3.2</version>
199216
<configuration>
200217
<preparationGoals>clean verify</preparationGoals>
201218
</configuration>

project/build.properties

-25
This file was deleted.

project/build/Project.scala

-108
This file was deleted.

src/main/scala/com/ckkloverdos/props/AnyProps.scala

+12-10
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
package com.ckkloverdos.props
1818

1919
import com.ckkloverdos.convert.Converters
20-
import java.net.URL
20+
import com.ckkloverdos.maybe.{NoVal, Maybe}
21+
import com.ckkloverdos.resource.{StreamResourceContext, StreamResource, ThreadResourceContext}
2122
import java.io.InputStream
2223
import java.util.Properties
23-
import com.ckkloverdos.resource.{StreamResourceContext, WrappingStreamResource, StreamResource, DefaultResourceContext}
24-
import com.ckkloverdos.maybe.{NoVal, Maybe}
2524

2625
/**
2726
* Properties with conversion methods.
@@ -109,29 +108,32 @@ class AnyProps(val map: Map[String, Any])(implicit conv: Converters = Converters
109108
object AnyProps {
110109
lazy val DefaultFalseStrings = Set("false", "off", "0")
111110

112-
lazy val DummyWrappedURL = new URL("streamresource://wrapped")
113-
lazy val DummyWrappedPath = "wrapped"
114-
115111
lazy val empty = new Props(Map())
116112

117113
def apply(rc: StreamResource)(implicit conv: Converters): Maybe[AnyProps] = {
118-
rc.mapInputStream { in
114+
rc.mapStream { in
119115
val props = new java.util.Properties
120116
props.load(in)
121117
import collection.JavaConversions._
122118
props.toMap
123119
} map (new AnyProps(_))
124120
}
125121

126-
def apply(in: InputStream)(implicit conv: Converters): Maybe[AnyProps] =
127-
this(new WrappingStreamResource(in, DummyWrappedPath, DummyWrappedURL))
122+
def apply(in: InputStream)(implicit conv: Converters): Maybe[AnyProps] = {
123+
Maybe {
124+
val props = new java.util.Properties
125+
props.load(in)
126+
import collection.JavaConversions._
127+
new AnyProps(props.toMap)
128+
}
129+
}
128130

129131
def apply(props: Properties)(implicit conv: Converters): Maybe[AnyProps] = {
130132
import collection.JavaConversions._
131133
Maybe(new AnyProps(props.toMap))
132134
}
133135

134-
def apply(path: String, rc: StreamResourceContext = DefaultResourceContext)(implicit conv: Converters): Maybe[AnyProps] = {
136+
def apply(path: String, rc: StreamResourceContext = ThreadResourceContext)(implicit conv: Converters): Maybe[AnyProps] = {
135137
rc.getResource(path).flatMap(this(_))
136138
}
137139

src/main/scala/com/ckkloverdos/props/Props.scala

+16-14
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616

1717
package com.ckkloverdos.props
1818

19-
import com.ckkloverdos.resource.{StreamResource, WrappingStreamResource, StreamResourceContext, DefaultResourceContext}
20-
import java.io.InputStream
21-
import java.net.URL
22-
import java.util.Properties
2319
import com.ckkloverdos.convert.Converters
24-
import com.ckkloverdos.maybe.{NoVal, Maybe}
25-
import com.ckkloverdos.key.StringKey
2620
import com.ckkloverdos.env.Env
21+
import com.ckkloverdos.maybe.{NoVal, Maybe}
22+
import com.ckkloverdos.resource.{StreamResource, StreamResourceContext, ThreadResourceContext}
23+
import java.io.InputStream
24+
import java.util.Properties
25+
import com.ckkloverdos.key.TKeyOnly
2726

2827
/**
2928
* Properties with conversion methods.
@@ -208,7 +207,7 @@ class Props(val map: Map[String, String])(implicit conv: Converters = Converters
208207
}
209208

210209
def toEnv: Env = {
211-
map.foldLeft(Env())((env, kv) env + (StringKey(kv._1), kv._2))
210+
map.foldLeft(Env())((env, kv) env + (new TKeyOnly[String](kv._1), kv._2))
212211
}
213212

214213
def group(keyPrefix: String): Props = {
@@ -228,29 +227,32 @@ class Props(val map: Map[String, String])(implicit conv: Converters = Converters
228227
}
229228

230229
object Props {
231-
lazy val DummyWrappedURL = new URL("streamresource://wrapped")
232-
lazy val DummyWrappedPath = "wrapped"
233-
234230
lazy val empty = new Props(Map())
235231

236232
def apply(rc: StreamResource)(implicit conv: Converters): Maybe[Props] = {
237-
rc.mapInputStream { in
233+
rc.mapStream { in
238234
val props = new java.util.Properties
239235
props.load(in)
240236
import collection.JavaConversions._
241237
props.toMap
242238
} map (new Props(_))
243239
}
244240

245-
def apply(in: InputStream)(implicit conv: Converters): Maybe[Props] =
246-
this(new WrappingStreamResource(in, DummyWrappedPath, DummyWrappedURL))
241+
def apply(in: InputStream)(implicit conv: Converters): Maybe[Props] = {
242+
Maybe {
243+
val props = new java.util.Properties
244+
props.load(in)
245+
import collection.JavaConversions._
246+
new Props(props.toMap)
247+
}
248+
}
247249

248250
def apply(props: Properties)(implicit conv: Converters): Maybe[Props] = {
249251
import collection.JavaConversions._
250252
Maybe(new Props(props.toMap))
251253
}
252254

253-
def apply(path: String, rc: StreamResourceContext = DefaultResourceContext)(implicit conv: Converters): Maybe[Props] = {
255+
def apply(path: String, rc: StreamResourceContext = ThreadResourceContext)(implicit conv: Converters): Maybe[Props] = {
254256
rc.getResource(path).flatMap(this(_))
255257
}
256258

0 commit comments

Comments
 (0)