Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix publishing and resolution of Scaladoc bridges #88

Merged
merged 4 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/project/.bloop/

target/
/SEED
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV PATH $PATH:$JAVA_HOME/jre/bin:$JAVA_HOME/bin:/seed/bloop

COPY build.sh build.sbt BLOOP SEED COURSIER /seed/
COPY project/ /seed/project/
COPY src/ /seed/src/
COPY project/ /seed/project/
COPY src/ /seed/src/
COPY scaladoc/ /seed/scaladoc/

WORKDIR /seed

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,9 @@ The output could use colours and bold/italic/underlined text. Also, components s
```

## Development
To run all test cases, the Scaladoc bridges must be published locally after each commit:
sbt takes the Git commit (`git describe --tags`) as the Seed version. This version can be overridden by creating a `SEED` file in the root folder.

To run all test cases, the Scaladoc bridges must be published locally for the current Seed version:

```shell
$ sbt
Expand Down
12 changes: 7 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def parseVersion(file: Path): Option[String] =
.find(_.nonEmpty)
.map(_.trim)

val seedOrganisation = "tindzk"
val seedOrganisation = "tindzk"
val seedMavenRepository = s"https://dl.bintray.com/$seedOrganisation/maven/"

// Should be `val` instead of `def`, otherwise it is necessary to run
// scaladoc*/publishLocal after every commit
Expand All @@ -35,10 +36,11 @@ Compile / sourceGenerators += Def.task {
s"""package seed
|
|object BuildInfo {
| val Organisation = "$seedOrganisation"
| val Version = "$seedVersion"
| val Bloop = "$bloopVersion"
| val Coursier = "$bloopCoursierVersion"
| val Organisation = "$seedOrganisation"
| val Version = "$seedVersion"
| val Bloop = "$bloopVersion"
| val Coursier = "$bloopCoursierVersion"
| val MavenRepository = "$seedMavenRepository"
|}""".stripMargin
)

Expand Down
170 changes: 85 additions & 85 deletions src/main/scala/seed/cli/Doc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,21 @@ object Doc {
log.info(
s"Output path: ${Ansi.italic(moduleDest.toString)}"
)
Try {
documentModule(
build.build,
build.resolvers,
runtimeResolution,
compilerResolution,
seedConfig,
command.packageConfig,
module,
platform,
runtimeLibs,
moduleDest.toFile,
paths,
log
)
}.toEither match {
case Left(e) =>
log.error("Internal error occurred")
e.printStackTrace()
false
case Right(v) => v
}

documentModule(
build.build,
build.resolvers,
runtimeResolution,
compilerResolution,
seedConfig,
command.packageConfig,
module,
platform,
runtimeLibs,
moduleDest.toFile,
paths,
log
)
}
}

Expand Down Expand Up @@ -174,77 +167,84 @@ object Doc {
val moduleLibs =
Coursier.localArtefacts(r, resolvedLibraryDeps).map(_.libraryJar)

val classLoader = new java.net.URLClassLoader(
scaladocLibs.map(_.toUri.toURL).toArray,
null
)
try {
val classLoader = new java.net.URLClassLoader(
scaladocLibs.map(_.toUri.toURL).toArray,
null
)

val scaladocClass =
classLoader.loadClass("seed.publish.util.Scaladoc")
val scaladoc = scaladocClass.newInstance()
val scaladocMethods = scaladocClass.getDeclaredMethods.toList
val scaladocExecuteMethod =
scaladocMethods.find(_.getName == "execute").get
val scaladocSettingsMethod =
scaladocMethods.find(_.getName == "settings").get

val sourceFiles = BuildConfig
.sourcePaths(build, List(module -> platform))
.flatMap(BuildConfig.allSourceFiles)
.map(_.toFile)

log.info(
s"Documenting ${Ansi.bold(sourceFiles.length.toString)} files..."
)
val scaladocClass =
classLoader.loadClass("seed.publish.util.Scaladoc")
val scaladoc = scaladocClass.newInstance()
val scaladocMethods = scaladocClass.getDeclaredMethods.toList
val scaladocExecuteMethod =
scaladocMethods.find(_.getName == "execute").get
val scaladocSettingsMethod =
scaladocMethods.find(_.getName == "settings").get

val platformModule =
BuildConfig.platformModule(build(module).module, platform).get
val scalacParams = platformModule.scalaOptions ++ ScalaCompiler
.compilerPlugIns(
build,
platformModule,
compilerResolution,
platform,
platformModule.scalaVersion.get
val sourceFiles = BuildConfig
.sourcePaths(build, List(module -> platform))
.flatMap(BuildConfig.allSourceFiles)
.map(_.toFile)

log.info(
s"Documenting ${Ansi.bold(sourceFiles.length.toString)} files..."
)

val classpath = moduleClasspaths.map(new File(_)) ++
moduleLibs.map(_.toFile)

val settings = scaladocSettingsMethod.invoke(
scaladoc,
Array[File](),
classpath.toArray,
Array[File](),
Array[File](),
dest,
scalacParams.mkString(" ")
)
val platformModule =
BuildConfig.platformModule(build(module).module, platform).get
val scalacParams = platformModule.scalaOptions ++ ScalaCompiler
.compilerPlugIns(
build,
platformModule,
compilerResolution,
platform,
platformModule.scalaVersion.get
)

val result = scaladocExecuteMethod
.invoke(
val classpath = moduleClasspaths.map(new File(_)) ++
moduleLibs.map(_.toFile)

val settings = scaladocSettingsMethod.invoke(
scaladoc,
settings,
sourceFiles.toArray,
(message => log.error(Ansi.bold("[scaladoc] ") + message)): Consumer[
String
],
(message => log.warn(Ansi.bold("[scaladoc] ") + message)): Consumer[
String
]
Array[File](),
classpath.toArray,
Array[File](),
Array[File](),
dest,
scalacParams.mkString(" ")
)
.asInstanceOf[java.lang.Boolean]

if (result)
log.info(
s"Module ${Ansi.italic(seed.cli.util.Module.format(module, platform))} documented"
)
else
log.error(
s"Module ${Ansi.italic(seed.cli.util.Module.format(module, platform))} could not be documented"
)
val result = scaladocExecuteMethod
.invoke(
scaladoc,
settings,
sourceFiles.toArray,
(message => log.error(Ansi.bold("[scaladoc] ") + message)): Consumer[
String
],
(message => log.warn(Ansi.bold("[scaladoc] ") + message)): Consumer[
String
]
)
.asInstanceOf[java.lang.Boolean]

result
if (result)
log.info(
s"Module ${Ansi.italic(seed.cli.util.Module.format(module, platform))} documented"
)
else
log.error(
s"Module ${Ansi.italic(seed.cli.util.Module.format(module, platform))} could not be documented"
)

result
} catch {
case t: Throwable =>
log.error("Internal error occurred")
t.printStackTrace()
false
}
}

def resolveScaladocBridge(
Expand Down Expand Up @@ -276,7 +276,7 @@ object Doc {
val r =
ArtefactResolution.resolution(
seedConfig,
resolvers,
resolvers.copy(maven = resolvers.maven :+ BuildInfo.MavenRepository),
packageConfig,
scaladocDeps,
(scalaOrg, scalaVer),
Expand Down