Skip to content

Commit 8244f9d

Browse files
committed
fix: jar resources packaged incorrectly
Converts the JAR `resources { ... }` block into a mapping of resource paths to their paths relative to the root project. Fixes: #1725 Signed-off-by: Sam Gammon <[email protected]>
1 parent 8d0da4d commit 8244f9d

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

packages/builder/src/main/kotlin/elide/tooling/jvm/JarBuildConfigurator.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import elide.exec.ActionScope
3434
import elide.exec.Task
3535
import elide.exec.Task.Companion.fn
3636
import elide.exec.taskDependencies
37+
import elide.runtime.Logging
3738
import elide.tooling.Arguments
3839
import elide.tooling.Classpath
3940
import elide.tooling.Environment
@@ -56,6 +57,8 @@ public interface JarConfigurator {}
5657
* ## Jar Build Configurator
5758
*/
5859
internal class JarBuildConfigurator : BuildConfigurator {
60+
private val logging by lazy { Logging.of(JarBuildConfigurator::class) }
61+
5962
override fun dependsOn(): List<KClass<out BuildConfigurator>> = listOf(
6063
JvmBuildConfigurator::class,
6164
)
@@ -82,11 +85,20 @@ internal class JarBuildConfigurator : BuildConfigurator {
8285
val root = state.config.projectRoot
8386
val resources = jar.resources
8487
return resources.map { resource ->
85-
val path = root.resolve(resource.path)
88+
val pathKey = if (resource.key.startsWith("/")) resource.key else {
89+
logging.debug { "Resource key for JAR '${resource.key}' is not absolute; implying '/'" }
90+
"/${resource.key}"
91+
}
92+
val path = root.resolve(resource.value.path)
8693
if (!Files.exists(path)) {
87-
error("Resource '$resource' (specified for JAR '${jar.name}') does not exist in project root")
94+
error(buildString {
95+
append("Resource '${resource.value.path}'")
96+
append("(specified for JAR '")
97+
append(jar.name ?: "default")
98+
append("' does not exist in project root")
99+
})
88100
}
89-
path to resource.position
101+
path to pathKey
90102
}
91103
}
92104

@@ -95,8 +107,8 @@ internal class JarBuildConfigurator : BuildConfigurator {
95107
val built = state.config.taskGraph.build()
96108
return built.nodes().filter {
97109
// @TODO better than strings?
98-
it.toString().lowercase().let {
99-
it.contains("kotlin") || it.contains("java")
110+
it.toString().lowercase().let { token ->
111+
token.contains("kotlin") || token.contains("java")
100112
}
101113
}
102114
}

packages/tooling/api/tooling.api

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,24 +4106,24 @@ public final class elide/tooling/project/manifest/ElidePackageManifest$GradleCat
41064106
public final class elide/tooling/project/manifest/ElidePackageManifest$Jar : elide/tooling/project/manifest/ElidePackageManifest$Artifact {
41074107
public static final field Companion Lelide/tooling/project/manifest/ElidePackageManifest$Jar$Companion;
41084108
public fun <init> ()V
4109-
public fun <init> (Ljava/lang/String;Ljava/util/List;Ljava/util/List;Ljava/util/Map;Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;Ljava/util/List;Ljava/util/List;)V
4110-
public synthetic fun <init> (Ljava/lang/String;Ljava/util/List;Ljava/util/List;Ljava/util/Map;Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;Ljava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
4109+
public fun <init> (Ljava/lang/String;Ljava/util/List;Ljava/util/Map;Ljava/util/Map;Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;Ljava/util/List;Ljava/util/List;)V
4110+
public synthetic fun <init> (Ljava/lang/String;Ljava/util/List;Ljava/util/Map;Ljava/util/Map;Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;Ljava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
41114111
public final fun component1 ()Ljava/lang/String;
41124112
public final fun component2 ()Ljava/util/List;
4113-
public final fun component3 ()Ljava/util/List;
4113+
public final fun component3 ()Ljava/util/Map;
41144114
public final fun component4 ()Ljava/util/Map;
41154115
public final fun component5 ()Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;
41164116
public final fun component6 ()Ljava/util/List;
41174117
public final fun component7 ()Ljava/util/List;
4118-
public final fun copy (Ljava/lang/String;Ljava/util/List;Ljava/util/List;Ljava/util/Map;Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;Ljava/util/List;Ljava/util/List;)Lelide/tooling/project/manifest/ElidePackageManifest$Jar;
4119-
public static synthetic fun copy$default (Lelide/tooling/project/manifest/ElidePackageManifest$Jar;Ljava/lang/String;Ljava/util/List;Ljava/util/List;Ljava/util/Map;Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;Ljava/util/List;Ljava/util/List;ILjava/lang/Object;)Lelide/tooling/project/manifest/ElidePackageManifest$Jar;
4118+
public final fun copy (Ljava/lang/String;Ljava/util/List;Ljava/util/Map;Ljava/util/Map;Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;Ljava/util/List;Ljava/util/List;)Lelide/tooling/project/manifest/ElidePackageManifest$Jar;
4119+
public static synthetic fun copy$default (Lelide/tooling/project/manifest/ElidePackageManifest$Jar;Ljava/lang/String;Ljava/util/List;Ljava/util/Map;Ljava/util/Map;Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;Ljava/util/List;Ljava/util/List;ILjava/lang/Object;)Lelide/tooling/project/manifest/ElidePackageManifest$Jar;
41204120
public fun equals (Ljava/lang/Object;)Z
41214121
public fun getDependsOn ()Ljava/util/List;
41224122
public fun getFrom ()Ljava/util/List;
41234123
public final fun getManifest ()Ljava/util/Map;
41244124
public final fun getName ()Ljava/lang/String;
41254125
public final fun getOptions ()Lelide/tooling/project/manifest/ElidePackageManifest$JarOptions;
4126-
public final fun getResources ()Ljava/util/List;
4126+
public final fun getResources ()Ljava/util/Map;
41274127
public final fun getSources ()Ljava/util/List;
41284128
public fun hashCode ()I
41294129
public fun toString ()Ljava/lang/String;
@@ -4177,14 +4177,12 @@ public final class elide/tooling/project/manifest/ElidePackageManifest$JarOption
41774177

41784178
public final class elide/tooling/project/manifest/ElidePackageManifest$JarResource {
41794179
public static final field Companion Lelide/tooling/project/manifest/ElidePackageManifest$JarResource$Companion;
4180-
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
4180+
public fun <init> (Ljava/lang/String;)V
41814181
public final fun component1 ()Ljava/lang/String;
4182-
public final fun component2 ()Ljava/lang/String;
4183-
public final fun copy (Ljava/lang/String;Ljava/lang/String;)Lelide/tooling/project/manifest/ElidePackageManifest$JarResource;
4184-
public static synthetic fun copy$default (Lelide/tooling/project/manifest/ElidePackageManifest$JarResource;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lelide/tooling/project/manifest/ElidePackageManifest$JarResource;
4182+
public final fun copy (Ljava/lang/String;)Lelide/tooling/project/manifest/ElidePackageManifest$JarResource;
4183+
public static synthetic fun copy$default (Lelide/tooling/project/manifest/ElidePackageManifest$JarResource;Ljava/lang/String;ILjava/lang/Object;)Lelide/tooling/project/manifest/ElidePackageManifest$JarResource;
41854184
public fun equals (Ljava/lang/Object;)Z
41864185
public final fun getPath ()Ljava/lang/String;
4187-
public final fun getPosition ()Ljava/lang/String;
41884186
public fun hashCode ()I
41894187
public fun toString ()Ljava/lang/String;
41904188
}

packages/tooling/src/main/kotlin/elide/tooling/project/codecs/ElidePackageManifestCodec.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ public class ElidePackageManifestCodec : PackageManifestCodec<ElidePackageManife
218218
version = it,
219219
)
220220
})
221+
).addConversion(
222+
// convert string jar resource target path
223+
Conversion.of(PClassInfo.String, JarResource::class.java, StrConverter {
224+
JarResource(path = it)
225+
})
221226
).addConversion(
222227
// convert flag defaults as booleans
223228
Conversion.of(PClassInfo.Boolean, ProjectFlagValue::class.java,

packages/tooling/src/main/kotlin/elide/tooling/project/manifest/ElidePackageManifest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public data class ElidePackageManifest(
8383

8484
@Serializable public data class JarResource(
8585
val path: String,
86-
val position: String,
8786
)
8887

8988
@Serializable public data class ProjectSourceSpec(
@@ -139,7 +138,7 @@ public data class ElidePackageManifest(
139138
@Serializable public data class Jar(
140139
val name: String? = null,
141140
val sources: List<String> = emptyList(),
142-
val resources: List<JarResource> = emptyList(),
141+
val resources: Map<String, JarResource> = emptyMap(),
143142
val manifest: Map<String, String> = emptyMap(),
144143
val options: JarOptions = JarOptions(),
145144
override val from: List<String> = emptyList(),

packages/tooling/src/main/pkl/Jvm.pkl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ open class Jar extends artifacts.Artifact {
8585
}
8686

8787
/// Which resources to add to the JAR.
88-
resources: Listing<common.FilePath | JarResource> = new {}
88+
resources: Mapping<common.FilePath, common.FilePath | JarResource> = new {}
8989

9090
/// Keys and values to include in the JAR's manifest.
9191
manifest: Mapping<JarManifestKey, JarManifestValue> = new {}

0 commit comments

Comments
 (0)