Skip to content

Commit ff00ea1

Browse files
authored
Merge pull request #10 from 2m/wip-classgraph-2m
Migrate to the classgraph lib
2 parents 3a3e5dd + a5163a9 commit ff00ea1

File tree

9 files changed

+90
-45
lines changed

9 files changed

+90
-45
lines changed

.scalafmt.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
maxColumn = 120
2+
docstrings = JavaDoc
3+
assumeStandardLibraryStripMargin = true
4+
rewrite.rules = [RedundantBraces, RedundantParens, SortImports, SortModifiers]
5+
unindentTopLevelOperators = true
6+
align.tokens = [
7+
{code = "%", owner = "Term.ApplyInfix"},
8+
{code = "%%", owner = "Term.ApplyInfix"},
9+
{code = ":=", owner = "Term.ApplyInfix"},
10+
"="
11+
]

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ scala: 2.12.4
55
jobs:
66
include:
77
- stage: test
8-
script: sbt test
8+
script: sbt scalafmtCheck scalafmtSbtCheck
9+
name: "Formatting check"
10+
- script: sbt test
11+
name: "Tests run"
912
- stage: publish
1013
script: sbt ^publish
1114

RELEASING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Releasing
2+
3+
1. Check [closed issues without a milestone](https://github.com/lightbend/sbt-paradox-apidoc/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20no%3Amilestone) and either assign them the upcoming release milestone or 'invalid'
4+
1. Create a [new release](https://github.com/lightbend/sbt-paradox-apidoc/releases/new) with:
5+
* the next tag version (e.g. `v0.2`)
6+
* title and release description including notable changes
7+
* link to the [milestone](https://github.com/lightbend/sbt-paradox-apidoc/milestones) showing an overview of closed issues for this release
8+
* overview of contributors generated by [`sbt-authors`](https://github.com/2m/authors) (eg. `sbt authors v0.1 v0.2`)
9+
1. Travis CI will start a [CI build](https://travis-ci.org/lightbend/sbt-paradox-apidoc/builds) for the new tag and publish artifacts to Bintray.
10+
1. Close the milestone for this release and start a new one.

build.sbt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
scalaVersion := "2.12.7"
22

3-
sbtPlugin := true
3+
sbtPlugin := true
44
crossSbtVersions := List("1.0.0")
5-
organization := "com.lightbend.paradox"
6-
name := "sbt-paradox-apidoc"
5+
organization := "com.lightbend.paradox"
6+
name := "sbt-paradox-apidoc"
77

88
addSbtPlugin(Library.sbtParadox)
99
libraryDependencies ++= Seq(
10-
Library.fastClassPathScanner,
11-
Library.jtidy % Test,
10+
Library.classgraph,
11+
Library.jtidy % Test,
1212
Library.scalatest % Test
1313
)
1414

1515
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0"))
1616
homepage := Some(url("https://github.com/lightbend/sbt-paradox-apidoc"))
17-
scmInfo := Some(ScmInfo(url("https://github.com/lightbend/sbt-paradox-apidoc"), "[email protected]:lightbend/sbt-paradox-apidoc.git"))
17+
scmInfo := Some(
18+
ScmInfo(url("https://github.com/lightbend/sbt-paradox-apidoc"), "[email protected]:lightbend/sbt-paradox-apidoc.git"))
1819
developers += Developer("contributors",
19-
"Contributors",
20-
"https://gitter.im/lightbend/paradox",
21-
url("https://github.com/lightbend/sbt-paradox-apidoc/graphs/contributors"))
20+
"Contributors",
21+
"https://gitter.im/lightbend/paradox",
22+
url("https://github.com/lightbend/sbt-paradox-apidoc/graphs/contributors"))
2223
organizationName := "Lightbend Inc."
23-
startYear := Some(2018)
24+
startYear := Some(2018)
2425

2526
bintrayOrganization := Some("sbt")
26-
bintrayRepository := "sbt-plugin-releases"
27+
bintrayRepository := "sbt-plugin-releases"
2728

2829
enablePlugins(AutomateHeaderPlugin)
30+
scalafmtOnCompile := true

project/Dependencies.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import sbt._
22

33
object Version {
4-
val fastClassPathScanner = "2.21"
5-
val jtidy = "r938"
6-
val sbtParadox = "0.4.3"
7-
val scalatest = "3.0.3"
4+
val classgraph = "4.4.2"
5+
val jtidy = "r938"
6+
val sbtParadox = "0.4.3"
7+
val scalatest = "3.0.5"
88
}
99

1010
object Library {
11-
val fastClassPathScanner = "io.github.lukehutch" % "fast-classpath-scanner" % Version.fastClassPathScanner
12-
val jtidy = "net.sf.jtidy" % "jtidy" % Version.jtidy
13-
val sbtParadox = "com.lightbend.paradox" % "sbt-paradox" % Version.sbtParadox
14-
val scalatest = "org.scalatest" %% "scalatest" % Version.scalatest
11+
val classgraph = "io.github.classgraph" % "classgraph" % Version.classgraph
12+
val jtidy = "net.sf.jtidy" % "jtidy" % Version.jtidy
13+
val sbtParadox = "com.lightbend.paradox" % "sbt-paradox" % Version.sbtParadox
14+
val scalatest = "org.scalatest" %% "scalatest" % Version.scalatest
1515
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.2.4
1+
sbt.version=1.2.6

project/plugins.sbt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.1.0")
2-
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
3-
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0")
1+
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.1.0")
2+
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
3+
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0")
4+
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")

src/main/scala/com/lightbend/paradox/apidoc/ApidocDirective.scala

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import org.pegdown.Printer
2121
import org.pegdown.ast.{DirectiveNode, TextNode, Visitor}
2222

2323
class ApidocDirective(allClasses: IndexedSeq[String]) extends InlineDirective("apidoc") {
24-
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
24+
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit =
2525
if (node.label.split('[')(0).contains('.')) {
2626
val fqcn = node.label
2727
if (allClasses.contains(fqcn)) {
@@ -31,11 +31,9 @@ class ApidocDirective(allClasses: IndexedSeq[String]) extends InlineDirective("a
3131
} else {
3232
throw new java.lang.IllegalStateException(s"fqcn not found by @apidoc[$fqcn]")
3333
}
34-
}
35-
else {
34+
} else {
3635
renderByClassName(node.label, node, visitor, printer)
3736
}
38-
}
3937

4038
private def baseClassName(label: String) = {
4139
val labelWithoutGenerics = label.split("\\[")(0)
@@ -52,16 +50,27 @@ class ApidocDirective(allClasses: IndexedSeq[String]) extends InlineDirective("a
5250

5351
def syntheticNode(group: String, label: String, fqcn: String, node: DirectiveNode): DirectiveNode = {
5452
val syntheticSource = new DirectiveNode.Source.Direct(fqcn)
55-
val attributes = new org.pegdown.ast.DirectiveAttributes.AttributeMap()
56-
new DirectiveNode(DirectiveNode.Format.Inline, group, null, null, attributes, null,
57-
new DirectiveNode(DirectiveNode.Format.Inline, group + "doc", label, syntheticSource, node.attributes, fqcn,
58-
new TextNode(label)
59-
))
53+
val attributes = new org.pegdown.ast.DirectiveAttributes.AttributeMap()
54+
new DirectiveNode(
55+
DirectiveNode.Format.Inline,
56+
group,
57+
null,
58+
null,
59+
attributes,
60+
null,
61+
new DirectiveNode(DirectiveNode.Format.Inline,
62+
group + "doc",
63+
label,
64+
syntheticSource,
65+
node.attributes,
66+
fqcn,
67+
new TextNode(label))
68+
)
6069
}
6170

6271
def renderByClassName(label: String, node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
63-
val query = node.label.replaceAll("\\\\_", "_")
64-
val className = baseClassName(query)
72+
val query = node.label.replaceAll("\\\\_", "_")
73+
val className = baseClassName(query)
6574
val classSuffix = if (query.endsWith("$")) "$" else ""
6675

6776
val matches = allClasses.filter(_.endsWith('.' + className))

src/main/scala/com/lightbend/paradox/apidoc/ApidocPlugin.scala

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.lightbend.paradox.apidoc
1818

19-
import _root_.io.github.lukehutch.fastclasspathscanner.FastClasspathScanner
19+
import io.github.classgraph.ClassGraph
2020
import com.lightbend.paradox.markdown.Writer
2121
import com.lightbend.paradox.sbt.ParadoxPlugin
2222
import com.lightbend.paradox.sbt.ParadoxPlugin.autoImport.paradoxDirectives
@@ -40,17 +40,26 @@ object ApidocPlugin extends AutoPlugin {
4040
def apidocParadoxGlobalSettings: Seq[Setting[_]] = Seq(
4141
apidocRootPackage := "scala",
4242
paradoxDirectives ++= Def.taskDyn {
43-
val classpath = (fullClasspath in Compile).value.files.map(_.toURI.toURL).toArray
43+
val classpath = (fullClasspath in Compile).value.files.map(_.toURI.toURL).toArray
4444
val classLoader = new java.net.URLClassLoader(classpath, this.getClass.getClassLoader)
45-
val scanner = new FastClasspathScanner(apidocRootPackage.value).addClassLoader(classLoader).scan()
46-
val allClasses = scanner.getNamesOfAllClasses.asScala.toVector
47-
Def.task { Seq(
48-
{ _: Writer.Context new ApidocDirective(allClasses) }
49-
)}
45+
val scanner = new ClassGraph()
46+
.whitelistPackages(apidocRootPackage.value)
47+
.addClassLoader(classLoader)
48+
.scan()
49+
val allClasses = scanner.getAllClasses.getNames.asScala.toVector
50+
Def.task {
51+
Seq(
52+
{ _: Writer.Context
53+
new ApidocDirective(allClasses)
54+
}
55+
)
56+
}
5057
}.value
5158
)
5259

53-
def apidocSettings(config: Configuration): Seq[Setting[_]] = apidocParadoxGlobalSettings ++ inConfig(config)(Seq(
54-
// scoped settings here
55-
))
60+
def apidocSettings(config: Configuration): Seq[Setting[_]] =
61+
apidocParadoxGlobalSettings ++ inConfig(config)(
62+
Seq(
63+
// scoped settings here
64+
))
5665
}

0 commit comments

Comments
 (0)