Skip to content

Commit 54c39e9

Browse files
authored
Merge pull request #31 from LeeTibbert/PR_Add_ScalaNative_0.4.0_2021-01-25
Upgrade Scala.js and Scala version patch levels then add Scala Native support
2 parents e2f74f7 + 4772a4d commit 54c39e9

File tree

7 files changed

+120
-12
lines changed

7 files changed

+120
-12
lines changed

.travis.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ language: scala
22

33
scala:
44
- 2.11.12
5-
- 2.12.10
6-
- 2.13.1
5+
- 2.12.13
6+
- 2.13.4
77
jdk:
88
- openjdk8
99
env:
1010
matrix:
11-
- SCALAJS_VERSION=
12-
- SCALAJS_VERSION=0.6.28
11+
- SCALAJVM_VERSION=true
12+
- SCALAJS_VERSION=0.6.33
1313
- SCALAJS_VERSION=1.0.0
14+
- SCALANATIVE_VERSION=true
1415

1516
script:
1617
- |
17-
if [ "$SCALAJS_VERSION" = "" ]; then
18-
PROJECT_NAME="portable-scala-reflectJVM"
19-
else
20-
PROJECT_NAME="portable-scala-reflectJS"
21-
fi
18+
[ -v SCALAJVM_VERSION ] && PROJECT_PLATFORM="JVM"
19+
[ -v SCALAJS_VERSION ] && PROJECT_PLATFORM="JS"
20+
[ -v SCALANATIVE_VERSION ] && PROJECT_PLATFORM="Native"
21+
PROJECT_NAME="portable-scala-reflect${PROJECT_PLATFORM}"
22+
2223
- sbt ++$TRAVIS_SCALA_VERSION! $PROJECT_NAME/test
2324
- sbt ++$TRAVIS_SCALA_VERSION! $PROJECT_NAME/doc
2425
- sbt ++$TRAVIS_SCALA_VERSION! $PROJECT_NAME/mimaReportBinaryIssues

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# portable-scala-reflect: platform-agnostic reflection for Scala
22

33
[![Build Status](https://travis-ci.org/portable-scala/portable-scala-reflect.svg?branch=master)](https://travis-ci.org/portable-scala/portable-scala-reflect)
4-
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org/)
4+
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-0.6.33.svg)](https://www.scala-js.org/)
55
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-1.0.0.svg)](https://www.scala-js.org)
66
[![Scaladoc](https://javadoc-badge.appspot.com/org.portable-scala/portable-scala-reflect_2.12.svg?label=scaladoc)](https://javadoc.io/doc/org.portable-scala/portable-scala-reflect_2.12/latest/org/portablescala/reflect/index.html)
77

@@ -25,6 +25,7 @@ libraryDependencies += "org.portable-scala" %%% "portable-scala-reflect" % "1.0.
2525
* Scala 2.11.x, 2.12.x and 2.13.x
2626
* Scala/JVM
2727
* Scala.js 0.6.x and 1.x
28+
* Scala Native 0.4.x
2829

2930
## Usage
3031

build.sbt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sbtcrossproject.{crossProject, CrossType}
44
val previousVersion = "1.0.0"
55

66
inThisBuild(Def.settings(
7-
crossScalaVersions := Seq("2.12.10", "2.11.12", "2.13.1"),
7+
crossScalaVersions := Seq("2.12.13", "2.11.12", "2.13.4"),
88
scalaVersion := crossScalaVersions.value.head,
99
version := "1.1.0-SNAPSHOT",
1010
organization := "org.portable-scala",
@@ -26,7 +26,7 @@ inThisBuild(Def.settings(
2626
Some("scm:git:git@github.com:portable-scala/portable-scala-reflect.git"))),
2727
))
2828

29-
lazy val `portable-scala-reflect` = crossProject(JSPlatform, JVMPlatform)
29+
lazy val `portable-scala-reflect` = crossProject(JSPlatform, JVMPlatform, NativePlatform)
3030
.in(file("."))
3131
.settings(
3232
scalacOptions in (Compile, doc) -= "-Xfatal-warnings",
@@ -73,3 +73,10 @@ lazy val `portable-scala-reflect` = crossProject(JSPlatform, JVMPlatform)
7373
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test",
7474
)
7575
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
76+
.nativeSettings(
77+
libraryDependencies +=
78+
"org.scala-native" %%% "junit-runtime" % "0.4.0" % "test",
79+
addCompilerPlugin(
80+
"org.scala-native" % "junit-plugin" % "0.4.0" cross CrossVersion.full),
81+
mimaPreviousArtifacts := Set.empty, // SN just added, no previous artifact
82+
)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.portablescala.reflect
2+
3+
import scala.scalanative.reflect.{Reflect => ScalaNativeReflect}
4+
5+
object Reflect {
6+
/** Reflectively looks up a loadable module class.
7+
*
8+
* A module class is the technical term referring to the class of a Scala
9+
* `object`. The object or one of its super types (classes or traits) must
10+
* be annotated with
11+
* [[org.portablescala.reflect.annotation.EnableReflectiveInstantiation @EnableReflectiveInstantiation]].
12+
* Moreover, the object must be "static", i.e., declared at the top-level of
13+
* a package or inside a static object.
14+
*
15+
* If the module class cannot be found, either because it does not exist,
16+
* was not `@EnableReflectiveInstantiation` or was not static, this method
17+
* returns `None`.
18+
*
19+
* @param fqcn
20+
* Fully-qualified name of the module class, including its trailing `$`
21+
*/
22+
def lookupLoadableModuleClass(fqcn: String): Option[LoadableModuleClass] =
23+
ScalaNativeReflect.lookupLoadableModuleClass(fqcn)
24+
25+
/** Reflectively looks up a loadable module class.
26+
*
27+
* In Scala Native, this method ignores the parameter `loader`. Calling this
28+
* method is equivalent to
29+
* {{{
30+
* Reflect.lookupLoadableModuleClass(fqcn)
31+
* }}}
32+
*
33+
* @param fqcn
34+
* Fully-qualified name of the module class, including its trailing `$`
35+
*
36+
* @param loader
37+
* Ignored
38+
*/
39+
def lookupLoadableModuleClass(fqcn: String,
40+
loader: ClassLoader): Option[LoadableModuleClass] = {
41+
lookupLoadableModuleClass(fqcn)
42+
}
43+
44+
/** Reflectively looks up an instantiable class.
45+
*
46+
* The class or one of its super types (classes or traits) must be annotated
47+
* with
48+
* [[org.portablescala.reflect.annotation.EnableReflectiveInstantiation @EnableReflectiveInstantiation]].
49+
* Moreover, the class must not be abstract, nor be a local class (i.e., a
50+
* class defined inside a `def`). Inner classes (defined inside another
51+
* class) are supported.
52+
*
53+
* If the class cannot be found, either because it does not exist,
54+
* was not `@EnableReflectiveInstantiation` or was abstract or local, this
55+
* method returns `None`.
56+
*
57+
* @param fqcn
58+
* Fully-qualified name of the class
59+
*/
60+
def lookupInstantiatableClass(fqcn: String): Option[InstantiatableClass] =
61+
ScalaNativeReflect.lookupInstantiatableClass(fqcn)
62+
63+
/** Reflectively looks up an instantiable class.
64+
*
65+
* In Scala Native, this method ignores the parameter `loader`. Calling this
66+
* method is equivalent to
67+
* {{{
68+
* Reflect.lookupInstantiatableClass(fqcn)
69+
* }}}
70+
*
71+
* @param fqcn
72+
* Fully-qualified name of the class
73+
*
74+
* @param loader
75+
* Ignored
76+
*/
77+
def lookupInstantiatableClass(fqcn: String,
78+
loader: ClassLoader): Option[InstantiatableClass] = {
79+
lookupInstantiatableClass(fqcn)
80+
}
81+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.portablescala.reflect
2+
3+
package object annotation {
4+
type EnableReflectiveInstantiation =
5+
scala.scalanative.reflect.annotation.EnableReflectiveInstantiation
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.portablescala
2+
3+
package object reflect {
4+
type InstantiatableClass = scala.scalanative.reflect.InstantiatableClass
5+
6+
type InvokableConstructor = scala.scalanative.reflect.InvokableConstructor
7+
8+
type LoadableModuleClass = scala.scalanative.reflect.LoadableModuleClass
9+
}

project/plugins.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ val scalaJSVersion =
44
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
55
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")
66

7+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")
8+
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
9+
710
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0")

0 commit comments

Comments
 (0)