LOG4J2-2303: Add release distribution script
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-scala/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j-scala/commit/ddc513c5 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-scala/tree/ddc513c5 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-scala/diff/ddc513c5 Branch: refs/heads/sbt Commit: ddc513c58cd302353c00898bace1a5d4f953d2e4 Parents: be2e32b Author: Matt Sicker <boa...@gmail.com> Authored: Tue Apr 3 16:00:11 2018 -0500 Committer: Matt Sicker <boa...@gmail.com> Committed: Tue Apr 3 16:00:31 2018 -0500 ---------------------------------------------------------------------- build.sbt | 3 +- create-distributions.sh | 62 +++++++++++++++++++++++++ project/Distributions.scala | 96 +++++++++++++++++++++++++++++++++++++++ src/asciidoctor/changes.adoc | 1 + 4 files changed, 161 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j-scala/blob/ddc513c5/build.sbt ---------------------------------------------------------------------- diff --git a/build.sbt b/build.sbt index 9398b25..722267f 100644 --- a/build.sbt +++ b/build.sbt @@ -82,7 +82,7 @@ lazy val packagingSettings = Seq( ), unmanagedSources in Compile := { val Some((_, minor)) = CrossVersion.partialVersion(scalaVersion.value) - val extras = if (minor > 10) ((baseDirectory.value / "src" / "main" / "scala-2.11+") ** "*.scala").get else Nil + val extras = if (minor > 10) ((sourceDirectory.value / "main" / "scala-2.11+") ** "*.scala").get else Nil (unmanagedSources in Compile).value ++ extras } ) @@ -126,6 +126,7 @@ lazy val root = (project in file(".")) .enablePlugins(SiteScaladocPlugin) .enablePlugins(SbtOsgi) .settings(bundleSettings: _*) + .enablePlugins(Distributions) lazy val nopublish = Seq( publish := {}, http://git-wip-us.apache.org/repos/asf/logging-log4j-scala/blob/ddc513c5/create-distributions.sh ---------------------------------------------------------------------- diff --git a/create-distributions.sh b/create-distributions.sh new file mode 100755 index 0000000..9750ea6 --- /dev/null +++ b/create-distributions.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function sign_file() { + release_key=${GPG_KEYID:-748F15B2CF9BA8F024155E6ED7C92B70FA1C814D} + gpg --detach-sign --armor --user ${release_key} "$1" +} + +function create_sources_from_tag() { + out_format=$1 + release_version=$2 + git archive --prefix=apache-log4j-api-scala-${release_version}-src/ -o target/apache-log4j-api-scala-${release_version}-src.${out_format} ${release_version} + sign_file target/apache-log4j-api-scala-${release_version}-src.${out_format} +} + +function create_all_sources_from_tag() { + create_sources_from_tag zip $1 + create_sources_from_tag tar.gz $1 +} + +function create_sources() { + out_format=$1 + git archive --prefix=apache-log4j-api-scala-SNAPSHOT-src/ -o target/apache-log4j-api-scala-SNAPSHOT-src.${out_format} HEAD +} + +function create_all_sources() { + create_sources zip + create_sources tar.gz +} + +function create_all_binaries() { + ./sbt -batch "; + package; packageDistributions" +} + +function create_all() { + create_all_sources + create_all_binaries +} + +function main() { + case $1 in + SNAPSHOT) create_all;; + *) create_all_sources_from_tag $1; create_all_binaries;; + esac +} + +tag=${1:-SNAPSHOT} + +main ${tag} http://git-wip-us.apache.org/repos/asf/logging-log4j-scala/blob/ddc513c5/project/Distributions.scala ---------------------------------------------------------------------- diff --git a/project/Distributions.scala b/project/Distributions.scala new file mode 100644 index 0000000..25b4b5a --- /dev/null +++ b/project/Distributions.scala @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +import java.io.FileOutputStream +import java.util.zip.GZIPOutputStream + +import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream +import sbt.{Def, _} +import sbt.plugins.JvmPlugin + +object Distributions extends AutoPlugin { + override lazy val trigger = allRequirements + + override lazy val requires = JvmPlugin + + object autoImport { + // run this task after "+ package" to get all versions included + val packageDistributions = taskKey[Seq[File]]("Packages zip and tar.gz binary distributions") + val packageZip = packageDistributionTask("zip") + val packageTarGz = packageDistributionTask("tar.gz") + } + + import autoImport._ + + override def projectSettings: Seq[Def.Setting[_]] = Seq( + packageDistributions := Seq( + packageZip.value, + packageTarGz.value + ) + ) + + private val classified = "-([a-z]+)\\.jar".r + + def packageDistributionTask(ext: String): Def.Initialize[Task[File]] = Def.task { + val target = Keys.target.value + val binaries = target * "scala-*" ** "log4j-api-scala*.jar" pair { file => + file.name match { + case classified(_) => None + case _ => Some(file.name) + } + } + val base = Keys.baseDirectory.value + val inputs = binaries ++ Seq( + (base / "LICENSE.txt", "LICENSE"), + (base / "NOTICE.txt", "NOTICE") + ) + val version = Keys.version.value + val output = target / s"apache-log4j-api-scala-$version-bin.$ext" + ext match { + case "zip" => makeZip(inputs, output) + case "tar.gz" => makeTarGz(inputs, output) + case _ => sys.error(s"Unknown distribution extension: $ext") + } + output + } + + def tarGz(sources: Traversable[(File, String)], output: File): Unit = { + val out = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(output))) + for ((f, name) <- sources) { + out.putArchiveEntry(out.createArchiveEntry(f, name)) + IO.transfer(f, out) + out.closeArchiveEntry() + } + out.finish() + out.close() + } + + def makeTarGz(inputs: Traversable[(File, String)], output: File): Unit = { + val out = output.getAbsoluteFile + if (out.exists()) { + if (out.isFile) out.delete() else sys.error(s"Cannot write to file $out as it is not a file") + } + tarGz(inputs, out) + } + + def makeZip(inputs: Traversable[(File, String)], output: File): Unit = { + val out = output.getAbsoluteFile + if (out.exists()) { + if (out.isFile) out.delete() else sys.error(s"Cannot write to file $out as it is not a file") + } + IO.zip(inputs, out) + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-scala/blob/ddc513c5/src/asciidoctor/changes.adoc ---------------------------------------------------------------------- diff --git a/src/asciidoctor/changes.adoc b/src/asciidoctor/changes.adoc index fabd482..6682e8c 100644 --- a/src/asciidoctor/changes.adoc +++ b/src/asciidoctor/changes.adoc @@ -21,6 +21,7 @@ [vertical] New Features:: [horizontal] +LOG4J2-2303::: Add release distribution script. LOG4J2-2295::: Add OSGi metadata to release jars. LOG4J2-2294::: Add release audit information to build. LOG4J2-2298::: Add changelog to site.