Skip to content

Commit 69016b1

Browse files
RE "Freestyle & sbt-org-policies plugin Integration" (#626)
* Brings back the code related to the Freestyle & sbt-org-policies plugin Integration * Adds pipelineStages for the default scope
1 parent 53f5ac4 commit 69016b1

File tree

7 files changed

+227
-112
lines changed

7 files changed

+227
-112
lines changed

src/main/scala/org/scalaexercises/exercises/Exercises.scala

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
/*
2-
* scala-exercises-runtime
3-
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
2+
* scala-exercises
3+
*
4+
* Copyright 2015-2017 47 Degrees, LLC. <http://www.47deg.com>
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
418
*/
519

620
package org.scalaexercises.runtime
@@ -20,33 +34,38 @@ object Exercises {
2034
val LIBRARIES_PACKAGE = "org.scalaexercises.content"
2135

2236
private[this] def classMap(cl: ClassLoader) = {
23-
val files = cl.asInstanceOf[URLClassLoader].getURLs map (_.getFile)
37+
val files = cl.asInstanceOf[URLClassLoader].getURLs map (_.getFile)
2438
val classFinder = ClassFinder(files map (new File(_)) filter (f f.exists()))
25-
val classes = classFinder.getClasses.toIterator
39+
val classes = classFinder.getClasses.toIterator
2640
ClassFinder.classInfoMap(classes)
2741
}
2842

2943
private[this] def subclassesOf[A: ClassTag](cl: ClassLoader): List[String] = {
30-
def loop(currentClassLoader: ClassLoader, acc: List[String]): List[String] = Option(currentClassLoader) match {
31-
case None acc
32-
case Some(cll: URLClassLoader)
33-
val cn = ClassFinder.concreteSubclasses(implicitly[ClassTag[A]].runtimeClass.getName, classMap(cll))
34-
.filter(_.name.startsWith(LIBRARIES_PACKAGE))
35-
.map(_.name)
36-
.toList
37-
loop(currentClassLoader.getParent, acc ++ cn)
38-
case Some(o) loop(o.getParent, acc)
39-
}
44+
def loop(currentClassLoader: ClassLoader, acc: List[String]): List[String] =
45+
Option(currentClassLoader) match {
46+
case None acc
47+
case Some(cll: URLClassLoader)
48+
val cn = ClassFinder
49+
.concreteSubclasses(implicitly[ClassTag[A]].runtimeClass.getName, classMap(cll))
50+
.filter(_.name.startsWith(LIBRARIES_PACKAGE))
51+
.map(_.name)
52+
.toList
53+
loop(currentClassLoader.getParent, acc ++ cn)
54+
case Some(o) loop(o.getParent, acc)
55+
}
4056
loop(cl, Nil)
4157
}
4258

43-
def discoverLibraries(cl: ClassLoader = classOf[Exercise].getClassLoader): (List[String], List[Library]) = {
59+
def discoverLibraries(
60+
cl: ClassLoader = classOf[Exercise].getClassLoader): (List[String], List[Library]) = {
4461
val classNames: List[String] = subclassesOf[Library](cl)
4562

4663
val errorsAndLibraries = classNames.map { name
4764
for {
4865
loadedClass guard(Class.forName(name, true, cl), s"$name not found")
49-
loadedObject guard(loadedClass.getField("MODULE$").get(null), s"$name must be defined as an object")
66+
loadedObject guard(
67+
loadedClass.getField("MODULE$").get(null),
68+
s"$name must be defined as an object")
5069
loadedLibrary guard(loadedObject.asInstanceOf[Library], s"$name must extend Library")
5170
} yield loadedLibrary
5271
}
@@ -58,16 +77,16 @@ object Exercises {
5877
Either.catchNonFatal(f).leftMap(_ message)
5978

6079
def buildEvaluatorRequest(
61-
pkg: String,
62-
qualifiedMethod: String,
63-
rawArgs: List[String],
64-
imports: List[String] = Nil,
65-
resolvers: List[String],
66-
libraryDependencies: List[String]
80+
pkg: String,
81+
qualifiedMethod: String,
82+
rawArgs: List[String],
83+
imports: List[String] = Nil,
84+
resolvers: List[String],
85+
libraryDependencies: List[String]
6786
): (List[String], List[Dependency], String) = {
6887

6988
val extractEvaluatorResolvers: List[String] = {
70-
resolvers.filter(!_.isEmpty) map { resolver
89+
resolvers.filter(r => !r.isEmpty && r.contains("http")) map { resolver
7190
resolver.substring(resolver.indexOf("http"))
7291
}
7392
}
@@ -79,7 +98,7 @@ object Exercises {
7998
}
8099
}
81100

82-
val pre = (s"import $pkg._" :: imports).mkString("; ")
101+
val pre = (s"import $pkg._" :: imports).mkString("; ")
83102
val code = s"""$qualifiedMethod(${rawArgs.mkString(", ")})"""
84103

85104
val allCode = s"{$pre; $code}"
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
/*
2-
* scala-exercises-exercise-compiler
3-
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
2+
* scala-exercises
3+
*
4+
* Copyright 2015-2017 47 Degrees, LLC. <http://www.47deg.com>
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
418
*/
519

620
package org.scalaexercises.runtime
721

822
import java.text.SimpleDateFormat
9-
import java.util.{ Date, TimeZone }
23+
import java.util.{Date, TimeZone}
1024

1125
object Timestamp {
1226
val ISO8601 = "yyyy-MM-dd'T'HH:mm:ssz"
@@ -17,9 +31,8 @@ object Timestamp {
1731
setTimeZone(UTC)
1832
}
1933

20-
def fromDate(d: Date): String = {
34+
def fromDate(d: Date): String =
2135
FORMAT.format(d)
22-
}
2336

2437
def toDate(timestamp: String): Date = FORMAT.parse(timestamp)
2538
}

src/main/scala/org/scalaexercises/exercises/model.scala

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
/*
2-
* scala-exercises-runtime
3-
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
2+
* scala-exercises
3+
*
4+
* Copyright 2015-2017 47 Degrees, LLC. <http://www.47deg.com>
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
418
*/
519

620
package org.scalaexercises.runtime
@@ -9,7 +23,7 @@ package model
923
// This is the exercise runtime metamodel
1024

1125
/** An exercise library.
12-
*/
26+
*/
1327
trait Library {
1428
def owner: String
1529
def repository: String
@@ -24,14 +38,14 @@ trait Library {
2438
}
2539

2640
/** Library Build Metadata Information
27-
*/
41+
*/
2842
trait BuildInfo {
2943
def resolvers: List[String]
3044
def libraryDependencies: List[String]
3145
}
3246

3347
/** A section in a library.
34-
*/
48+
*/
3549
trait Section {
3650
def name: String
3751
def description: Option[String]
@@ -42,7 +56,7 @@ trait Section {
4256
}
4357

4458
/** A contribution to a section.
45-
*/
59+
*/
4660
trait Contribution {
4761
def sha: String
4862
def message: String
@@ -54,7 +68,7 @@ trait Contribution {
5468
}
5569

5670
/** Exercises within a section.
57-
*/
71+
*/
5872
trait Exercise {
5973
def name: String
6074
def description: Option[String]
@@ -67,48 +81,47 @@ trait Exercise {
6781

6882
// default case class implementations
6983
case class DefaultLibrary(
70-
owner: String,
71-
repository: String,
72-
name: String,
73-
description: String,
74-
color: Option[String],
75-
logoPath: String,
76-
logoData: Option[String],
77-
sections: List[Section] = Nil,
78-
timestamp: String,
79-
buildMetaInfo: BuildInfo
84+
owner: String,
85+
repository: String,
86+
name: String,
87+
description: String,
88+
color: Option[String],
89+
logoPath: String,
90+
logoData: Option[String],
91+
sections: List[Section] = Nil,
92+
timestamp: String,
93+
buildMetaInfo: BuildInfo
8094
) extends Library
8195

8296
case class DefaultContribution(
83-
sha: String,
84-
message: String,
85-
timestamp: String,
86-
url: String,
87-
author: String,
88-
authorUrl: String,
89-
avatarUrl: String
97+
sha: String,
98+
message: String,
99+
timestamp: String,
100+
url: String,
101+
author: String,
102+
authorUrl: String,
103+
avatarUrl: String
90104
) extends Contribution
91105

92106
case class DefaultSection(
93-
name: String,
94-
description: Option[String],
95-
exercises: List[Exercise] = Nil,
96-
imports: List[String] = Nil,
97-
path: Option[String] = None,
98-
contributions: List[DefaultContribution] = Nil
107+
name: String,
108+
description: Option[String],
109+
exercises: List[Exercise] = Nil,
110+
imports: List[String] = Nil,
111+
path: Option[String] = None,
112+
contributions: List[DefaultContribution] = Nil
99113
) extends Section
100114

101115
case class DefaultExercise(
102-
name: String,
103-
description: Option[String] = None,
104-
code: String,
105-
qualifiedMethod: String,
106-
imports: List[String],
107-
explanation: Option[String] = None,
108-
packageName: String
116+
name: String,
117+
description: Option[String] = None,
118+
code: String,
119+
qualifiedMethod: String,
120+
imports: List[String],
121+
explanation: Option[String] = None,
122+
packageName: String
109123
) extends Exercise
110124
/*
111125
* scala-exercises-runtime
112126
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
113127
*/
114-

0 commit comments

Comments
 (0)