Skip to content

Commit fad297a

Browse files
committed
clean code
1 parent 0280f37 commit fad297a

File tree

9 files changed

+246
-103
lines changed

9 files changed

+246
-103
lines changed

build.sbt

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Your sbt build file. Guides on how to write one can be found at
22
// http://www.scala-sbt.org/0.13/docs/index.html
33

4-
scalaSource in Compile := baseDirectory.value / "src"
5-
64
scalaVersion := "2.10.4"
75

86
sparkVersion := "1.4.0"

pom.xml

+136-20
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,152 @@
77
<name>Spark-Redis</name>
88
<description>A Spark library for Redis</description>
99
<url>http://github.com/RedisLabs/spark-redis</url>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14+
<java.version>1.7</java.version>
15+
<scala.version>2.10.4</scala.version>
16+
<jedis.version>2.7.2</jedis.version>
17+
<spark.version>1.4.1</spark.version>
18+
</properties>
19+
1020
<build>
11-
<sourceDirectory>src</sourceDirectory>
12-
<resources>
13-
<resource>
14-
<directory>src</directory>
15-
<excludes>
16-
<exclude>**/*.java</exclude>
17-
</excludes>
18-
</resource>
19-
</resources>
2021
<plugins>
2122
<plugin>
22-
<groupId>org.scala-tools</groupId>
23-
<artifactId>maven-scala-plugin</artifactId>
23+
<groupId>net.alchim31.maven</groupId>
24+
<artifactId>scala-maven-plugin</artifactId>
25+
<version>3.2.2</version>
26+
<configuration>
27+
<scalaVersion>${scala.version}</scalaVersion>
28+
<javacArgs>
29+
<javacArg>-source</javacArg>
30+
<javacArg>${java.version}</javacArg>
31+
<javacArg>-target</javacArg>
32+
<javacArg>${java.version}</javacArg>
33+
</javacArgs>
34+
</configuration>
2435
<executions>
2536
<execution>
37+
<id>scala-compile</id>
38+
<phase>process-resources</phase>
2639
<goals>
2740
<goal>compile</goal>
41+
</goals>
42+
</execution>
43+
<execution>
44+
<id>scala-test-compile</id>
45+
<phase>process-test-resources</phase>
46+
<goals>
2847
<goal>testCompile</goal>
2948
</goals>
3049
</execution>
3150
</executions>
3251
</plugin>
3352
<plugin>
34-
<artifactId>maven-compiler-plugin</artifactId>
35-
<version>3.3</version>
53+
<groupId>org.scalastyle</groupId>
54+
<artifactId>scalastyle-maven-plugin</artifactId>
55+
<version>0.7.0</version>
56+
<configuration>
57+
<verbose>false</verbose>
58+
<failOnWarning>false</failOnWarning>
59+
<failOnViolation>true</failOnViolation>
60+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
61+
<sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
62+
<testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>
63+
<configLocation>${basedir}/scalastyle-config.xml</configLocation>
64+
<outputFile>${project.basedir}/scalastyle-output.xml</outputFile>
65+
<outputEncoding>UTF-8</outputEncoding>
66+
</configuration>
67+
<executions>
68+
<execution>
69+
<phase>compile</phase>
70+
<goals>
71+
<goal>check</goal>
72+
</goals>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-jar-plugin</artifactId>
79+
<version>2.6</version>
80+
<configuration>
81+
<skipIfEmpty>true</skipIfEmpty>
82+
</configuration>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-assembly-plugin</artifactId>
87+
<version>2.5.4</version>
3688
<configuration>
37-
<source>1.7</source>
38-
<target>1.7</target>
89+
<descriptorRefs>
90+
<descriptorRef>jar-with-dependencies</descriptorRef>
91+
</descriptorRefs>
3992
</configuration>
93+
<executions>
94+
<execution>
95+
<phase>package</phase>
96+
<goals>
97+
<goal>single</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
<plugin>
103+
<groupId>org.codehaus.mojo</groupId>
104+
<artifactId>build-helper-maven-plugin</artifactId>
105+
<version>1.10</version>
106+
<executions>
107+
<execution>
108+
<id>add-scala-sources</id>
109+
<phase>generate-sources</phase>
110+
<goals>
111+
<goal>add-source</goal>
112+
</goals>
113+
<configuration>
114+
<sources>
115+
<source>src/main/scala</source>
116+
</sources>
117+
</configuration>
118+
</execution>
119+
<execution>
120+
<id>add-scala-test-sources</id>
121+
<phase>generate-test-sources</phase>
122+
<goals>
123+
<goal>add-test-source</goal>
124+
</goals>
125+
<configuration>
126+
<sources>
127+
<source>src/test/scala</source>
128+
</sources>
129+
</configuration>
130+
</execution>
131+
</executions>
132+
</plugin>
133+
<plugin>
134+
<groupId>org.apache.maven.plugins</groupId>
135+
<artifactId>maven-site-plugin</artifactId>
136+
<version>3.4</version>
137+
<inherited>false</inherited>
138+
<dependencies>
139+
<dependency>
140+
<groupId>org.apache.maven.doxia</groupId>
141+
<artifactId>doxia-module-markdown</artifactId>
142+
<version>1.6</version>
143+
</dependency>
144+
<dependency>
145+
<groupId>lt.velykis.maven.skins</groupId>
146+
<artifactId>reflow-velocity-tools</artifactId>
147+
<version>1.1.1</version>
148+
</dependency>
149+
<!-- Reflow skin requires Velocity >= 1.7 -->
150+
<dependency>
151+
<groupId>org.apache.velocity</groupId>
152+
<artifactId>velocity</artifactId>
153+
<version>1.7</version>
154+
</dependency>
155+
</dependencies>
40156
</plugin>
41157
</plugins>
42158
</build>
@@ -49,29 +165,29 @@
49165
<dependency>
50166
<groupId>redis.clients</groupId>
51167
<artifactId>jedis</artifactId>
52-
<version>2.7.2</version>
168+
<version>${jedis.version}</version>
53169
<type>jar</type>
54170
<scope>compile</scope>
55171
</dependency>
56172
<dependency>
57173
<groupId>org.scala-lang</groupId>
58174
<artifactId>scala-library</artifactId>
59-
<version>2.10.4</version>
175+
<version>${scala.version}</version>
60176
</dependency>
61177
<dependency>
62178
<groupId>org.apache.spark</groupId>
63179
<artifactId>spark-core_2.10</artifactId>
64-
<version>1.4.0</version>
180+
<version>${spark.version}</version>
65181
</dependency>
66182
<dependency>
67183
<groupId>org.apache.spark</groupId>
68184
<artifactId>spark-streaming_2.10</artifactId>
69-
<version>1.4.0</version>
185+
<version>${spark.version}</version>
70186
</dependency>
71187
<dependency>
72188
<groupId>org.apache.spark</groupId>
73189
<artifactId>spark-sql_2.10</artifactId>
74-
<version>1.4.0</version>
190+
<version>${spark.version}</version>
75191
</dependency>
76192

77193
</dependencies>

src/com/redislabs/provider/redis/package.scala

-3
This file was deleted.

src/com/redislabs/provider/RedisConfig.scala renamed to src/main/scala/com/redislabs/provider/RedisConfig.scala

+8-9
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ class RedisConfig(val ip: String, val port: Int) extends Serializable {
1212
*
1313
* @param sPos start position of a slots range
1414
* @param ePos end position of a slots range
15-
* @return list of nodes(addr, port, index, range, startSlot, endSlot), where Inter([startSlot, endSlot], [sPos, ePos]) is not Nil(master only now)
15+
* @return list of nodes(addr, port, index, range, startSlot, endSlot), where
16+
* Inter([startSlot, endSlot], [sPos, ePos]) is not Nil(master only now)
1617
*/
17-
def getNodesBySlots(sPos: Int, ePos: Int) = {
18-
def inter(sPos1: Int, ePos1: Int, sPos2: Int, ePos2: Int):Boolean = {
19-
if (sPos1 <= sPos2)
20-
return ePos1 >= sPos2
21-
else
22-
return ePos2 >= sPos1
23-
}
18+
def getNodesBySlots(sPos: Int, ePos: Int): Array[(String, Int, Int, Int, Int, Int)] = {
19+
def inter(sPos1: Int, ePos1: Int, sPos2: Int, ePos2: Int) =
20+
if (sPos1 <= sPos2) ePos1 >= sPos2 else ePos2 >= sPos1
21+
2422
val node = nodes.get(scala.util.Random.nextInt().abs % nodes.size())
25-
getSlots((node._1, node._2)).filter(node => inter(sPos, ePos, node._5, node._6)).filter(_._3 == 0) //master only now
23+
getSlots((node._1, node._2)).filter(node => inter(sPos, ePos, node._5, node._6)).
24+
filter(_._3 == 0) //master only now
2625
}
2726
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.redislabs.provider
2+
3+
package object redis extends RedisFunctions

src/com/redislabs/provider/redis/partitioner/RedisPartition.scala renamed to src/main/scala/com/redislabs/provider/redis/partitioner/RedisPartition.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ import com.redislabs.provider._
55

66
case class RedisPartition(index: Int,
77
redisConfig: RedisConfig,
8-
slots: (Int, Int)) extends Partition
8+
slots: (Int, Int)) extends Partition

0 commit comments

Comments
 (0)