-
Notifications
You must be signed in to change notification settings - Fork 42
Cross compile to sbt2 #188
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1e6ec9d
Cross compile to sbt2
romainreuillon d376ed2
Generate github action yaml
romainreuillon dbdda61
Update scalafmt dialect
romainreuillon 0d4569f
Fix sbt version
romainreuillon 5c9765a
Use scala 2 compatible syntax
romainreuillon 24079d0
Use scala 2 compatible syntax
romainreuillon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * Copyright 2011-2013 Typesafe Inc. | ||
| * | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| package com.github.sbt.osgi | ||
|
|
||
| import sbt._ | ||
| import sbt.Keys._ | ||
| import sbt.plugins.JvmPlugin | ||
|
|
||
| object SbtOsgi extends AutoPlugin { | ||
|
|
||
| override lazy val trigger: PluginTrigger = noTrigger | ||
|
|
||
| override lazy val requires: Plugins = JvmPlugin | ||
|
|
||
| override lazy val projectSettings: Seq[Def.Setting[_]] = defaultOsgiSettings | ||
|
|
||
| override lazy val globalSettings: Seq[Def.Setting[_]] = defaultGlobalSettings | ||
|
|
||
| object autoImport { | ||
| type OsgiManifestHeaders = com.github.sbt.osgi.OsgiManifestHeaders | ||
|
|
||
| val OsgiKeys = com.github.sbt.osgi.OsgiKeys | ||
|
|
||
| lazy val osgiSettings: Seq[Setting[_]] = Seq( | ||
| Compile / packageBin / packagedArtifact := Def.uncached: | ||
| val conv = fileConverter.value | ||
| Scoped | ||
| .mkTuple2( | ||
| (Compile / packageBin / artifact).value, | ||
| conv.toVirtualFile(OsgiKeys.bundle.value.toPath) | ||
| ), | ||
| Compile / packageBin / artifact ~= (_.withType("bundle")) | ||
| ) | ||
| } | ||
|
|
||
| lazy val defaultOsgiSettings: Seq[Setting[_]] = { | ||
| import OsgiKeys._ | ||
| Seq( | ||
| bundle := Def.uncached: | ||
| val conv = fileConverter.value | ||
| Osgi.bundleTask( | ||
| manifestHeaders.value, | ||
| additionalHeaders.value, | ||
| (Compile / dependencyClasspathAsJars).value.map(_.data).map(r => conv.toPath(r).toFile) ++ (Compile / products).value, | ||
| conv.toPath((Compile / packageBin / artifactPath).value).toFile, | ||
| (Compile / resourceDirectories).value, | ||
| embeddedJars.value, | ||
| explodedJars.value, | ||
| failOnUndecidedPackage.value, | ||
| (Compile / sourceDirectories).value, | ||
| (Compile / packageBin / packageOptions).value, | ||
| packageWithJVMJar.value, | ||
| cacheStrategy.value, | ||
| streams.value | ||
| ), | ||
| manifestHeaders := Def.uncached: | ||
| OsgiManifestHeaders( | ||
| bundleActivator.value, | ||
| description.value, | ||
| apiURL.value.map(_.toURL), | ||
| licenses.value.map(l => (l.spdxId, l.uri.toURL)), | ||
| name.value, | ||
| bundleRequiredExecutionEnvironment.value, | ||
| organizationName.value, | ||
| bundleSymbolicName.value, | ||
| bundleVersion.value, | ||
| dynamicImportPackage.value, | ||
| exportPackage.value, | ||
| importPackage.value, | ||
| fragmentHost.value, | ||
| privatePackage.value, | ||
| requireBundle.value, | ||
| requireCapability.value | ||
| ), | ||
| Compile / sbt.Keys.packageBin := Def.uncached: | ||
| val conv = fileConverter.value | ||
| conv.toVirtualFile(bundle.value.toPath) | ||
| , | ||
| bundleSymbolicName := Osgi.defaultBundleSymbolicName(organization.value, normalizedName.value), | ||
| privatePackage := bundleSymbolicName(name => List(name + ".*")).value, | ||
| bundleVersion := version.value | ||
| ) | ||
| } | ||
|
|
||
| lazy val defaultGlobalSettings: Seq[Setting[_]] = { | ||
| import OsgiKeys._ | ||
| Seq( | ||
| bundle := file(""), | ||
| bundleActivator := None, | ||
| bundleSymbolicName := "", | ||
| bundleVersion := "", | ||
| bundleRequiredExecutionEnvironment := Nil, | ||
| dynamicImportPackage := Nil, | ||
| exportPackage := Nil, | ||
| importPackage := List("*"), | ||
| fragmentHost := None, | ||
| privatePackage := Nil, | ||
| requireBundle := Nil, | ||
| failOnUndecidedPackage := false, | ||
| requireCapability := Osgi.requireCapabilityTask, | ||
| additionalHeaders := Map.empty, | ||
| embeddedJars := Nil, | ||
| explodedJars := Nil, | ||
| packageWithJVMJar := false, | ||
| cacheStrategy := None | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.github.sbt.osgi | ||
|
|
||
| /* | ||
| * Copyright (C) 2025 Romain Reuillon | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| type ManifestAttributes = sbt.PackageOption.ManifestAttributes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Copyright 2011 Typesafe Inc. | ||
| * | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| package com.github.sbt.osgi | ||
|
|
||
| import aQute.bnd.osgi.Constants.* | ||
| import org.specs2.mutable.Specification | ||
|
|
||
| import java.io.File | ||
| import scala.collection.JavaConverters.* | ||
|
|
||
| class OsgiSpec extends Specification { | ||
|
|
||
| import Osgi.* | ||
|
|
||
| "Calling seqToStrOpt" should { | ||
| "return None for an empty Seq" in { | ||
| seqToStrOpt(Nil)(id) must be(None) | ||
| } | ||
| "return Some wrapping a properly constructed String for a non-empty Seq" in { | ||
| seqToStrOpt(Seq("foo", "bar", "baz"))(id) must beSome("foo,bar,baz") | ||
| seqToStrOpt(Seq(1, 2, 3))(_.toString) must beSome("1,2,3") | ||
| } | ||
| } | ||
|
|
||
| "Calling headersToProperties" should { | ||
| "return the proper properties" in { | ||
| val headers = OsgiManifestHeaders( | ||
| Some("bundleActivator"), | ||
| "bundleDescription", | ||
| Some(sbt.url("http://example.example").toURL), | ||
| Seq(("License", sbt.url("http://license.license").toURL)), | ||
| "bundleName", | ||
| Seq("req1", "req2"), | ||
| "bundleVendor", | ||
| "bundleSymbolicName", | ||
| "bundleVersion", | ||
| Seq("dynamicImportPackage"), | ||
| Seq("exportPackage1", "exportPackage2", "exportPackage3"), | ||
| Seq("importPackage"), | ||
| None, | ||
| Seq("privatePackage"), | ||
| Nil, | ||
| "requireCapability" | ||
| ) | ||
| val properties = headersToProperties(headers, Map.empty) | ||
| properties.asScala must havePairs( | ||
| BUNDLE_ACTIVATOR -> "bundleActivator", | ||
| BUNDLE_SYMBOLICNAME -> "bundleSymbolicName", | ||
| BUNDLE_DESCRIPTION -> "bundleDescription", | ||
| BUNDLE_DOCURL -> sbt.url("http://example.example").toString, | ||
| BUNDLE_LICENSE -> "http://license.license;description=License", | ||
| BUNDLE_NAME -> "bundleName", | ||
| BUNDLE_REQUIREDEXECUTIONENVIRONMENT -> "req1,req2", | ||
| BUNDLE_VENDOR -> "bundleVendor", | ||
| BUNDLE_VERSION -> "bundleVersion", | ||
| DYNAMICIMPORT_PACKAGE -> "dynamicImportPackage", | ||
| EXPORT_PACKAGE -> "exportPackage1,exportPackage2,exportPackage3", | ||
| IMPORT_PACKAGE -> "importPackage", | ||
| PRIVATE_PACKAGE -> "privatePackage", | ||
| REQUIRE_CAPABILITY -> "requireCapability" | ||
| ) | ||
| properties.asScala must not(haveKey(FRAGMENT_HOST)) | ||
| properties.asScala must not(haveKey(REQUIRE_BUNDLE)) | ||
| } | ||
| } | ||
|
|
||
| "Calling defaultBundleSymbolicName" should { | ||
| "concatenate organization and name properly" in { | ||
| defaultBundleSymbolicName("a.b.c", "d.c") must beEqualTo("a.b.c.d.c") | ||
| defaultBundleSymbolicName("a.b.c", "d-c") must beEqualTo("a.b.c.d.c") | ||
| defaultBundleSymbolicName("a.b.c", "c.d") must beEqualTo("a.b.c.d") | ||
| defaultBundleSymbolicName("a.b.c", "c-d") must beEqualTo("a.b.c.d") | ||
| defaultBundleSymbolicName("", "a") must beEqualTo("a") | ||
| defaultBundleSymbolicName("a", "") must beEqualTo("a") | ||
| defaultBundleSymbolicName("", "") must beEqualTo("") | ||
| } | ||
| } | ||
|
|
||
| "Calling includeResourceProperty" should { | ||
| "add resources and embedded jars and exploded jars to INCLUDERESOURCE" in { | ||
| val resourceDir = new File("/resource") | ||
| val jar = new File("/aJar.jar") | ||
| val anotherJar = new File("/anotherJar.jar") | ||
| val actual = includeResourceProperty(Seq(resourceDir), Seq(jar), Seq(anotherJar)) | ||
| actual must beSome(resourceDir.getAbsolutePath + "," + jar.getAbsolutePath + ",@" + anotherJar.getAbsolutePath) | ||
| } | ||
| } | ||
|
|
||
| "Calling bundleClasspathProperty" should { | ||
| "add bundle classes and embedded jars to classpath" in { | ||
| val embeddedJars = Seq(new File("/aJar.jar"), new File("/bJar.jar")) | ||
| val actual = bundleClasspathProperty(embeddedJars) | ||
| actual must beSome(".,aJar.jar,bJar.jar") | ||
| } | ||
| "remain default if no embedded jars are specified" in { | ||
| val embeddedJars = Seq() | ||
| val actual = bundleClasspathProperty(embeddedJars) | ||
| actual must beNone | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this plugin wants to run tests on JDK 21, then the minimum version should be 1.9.9.