Skip to content

Commit

Permalink
Use unix path separator for classpath attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
pmendelski committed Feb 20, 2021
1 parent cae2a04 commit be340a6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
## [0.1.12] - 2021-02-20
### Changed
- Use unix path separator for `Class-Path` attribute

## [0.1.11] - 2021-02-10
### Changed
Expand All @@ -20,7 +22,9 @@
### Changed
- Fix SCM attributes generated in multi-module projects [#1](https://github.com/coditory/gradle-manifest-plugin/issues/1).

[Unreleased]: https://github.com/coditory/gradle-manifest-plugin/compare/v0.1.10...HEAD
[0.1.10]: https://github.com/coditory/gradle-manifest-plugin/compare/v0.1.10...HEAD
[Unreleased]: https://github.com/coditory/gradle-manifest-plugin/compare/v0.1.12...HEAD
[0.1.12]: https://github.com/coditory/gradle-manifest-plugin/compare/v0.1.11...v0.1.12
[0.1.11]: https://github.com/coditory/gradle-manifest-plugin/compare/v0.1.10...v0.1.11
[0.1.10]: https://github.com/coditory/gradle-manifest-plugin/compare/v0.1.9...v0.1.10
[0.1.9]: https://github.com/coditory/gradle-manifest-plugin/compare/v0.1.8...v0.1.9
[0.1.8]: https://github.com/coditory/gradle-manifest-plugin/compare/v0.1.7...v0.1.8
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,10 @@ internal object ManifestAttributes {
if (extension.classpathPrefix == null) {
return mapOf()
}
return mapOf(
"Class-Path" to orEmpty {
project.configurations.getByName(RUNTIME_CLASSPATH_CONFIGURATION_NAME)
.map { Path.of(extension.classpathPrefix, it.name) }
.joinToString(" ")
}
)
val classPath = project.configurations.getByName(RUNTIME_CLASSPATH_CONFIGURATION_NAME)
.map { Path.of(extension.classpathPrefix, it.name).toString() }
.joinToString(" ") { it.replace('\\', '/').replace("//+".toRegex(), "/") }
return mapOf("Class-Path" to classPath)
}

private fun implementationTitle(project: Project): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.coditory.gradle.manifest.base.runGradle
import org.assertj.core.api.Assertions.assertThat
import org.gradle.testkit.runner.TaskOutcome
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

Expand Down Expand Up @@ -34,11 +35,13 @@ class GenerateClasspathSpec {
}
manifest {
classpathPrefix = "my-jars"
classpathPrefix = "my/jars"
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter:2.4.2'
implementation 'com.coditory.quark:quark-context:0.1.2'
runtime 'com.coditory.logback:logback-filters:0.1.0'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.7.0'
}
"""
Expand All @@ -53,17 +56,65 @@ class GenerateClasspathSpec {
.isEqualTo(TaskOutcome.SUCCESS)

// and
assertThat(project.readFile("build/resources/main/META-INF/MANIFEST.MF"))
val manifest = project.readFile("build/resources/main/META-INF/MANIFEST.MF")
assertThat(manifest.replace("\r\n ", ""))
.contains("my/jars/quark-context-0.1.2.jar")
.contains("my/jars/logback-filters-0.1.0.jar")
.contains("my/jars/spring-boot-starter-2.4.2.jar")

// and
assertThat(manifest)
.contains(
"Class-Path: my-jars/spring-boot-starter-2.4.2.jar my-jars/spring-boot-au\r\n" +
" toconfigure-2.4.2.jar my-jars/spring-boot-2.4.2.jar my-jars/spring-boot\r\n" +
" -starter-logging-2.4.2.jar my-jars/jakarta.annotation-api-1.3.5.jar my-\r\n" +
" jars/spring-context-5.3.3.jar my-jars/spring-aop-5.3.3.jar my-jars/spri\r\n" +
" ng-beans-5.3.3.jar my-jars/spring-expression-5.3.3.jar my-jars/spring-c\r\n" +
" ore-5.3.3.jar my-jars/snakeyaml-1.27.jar my-jars/logback-classic-1.2.3.\r\n" +
" jar my-jars/log4j-to-slf4j-2.13.3.jar my-jars/jul-to-slf4j-1.7.30.jar m\r\n" +
" y-jars/spring-jcl-5.3.3.jar my-jars/logback-core-1.2.3.jar my-jars/slf4\r\n" +
" j-api-1.7.30.jar my-jars/log4j-api-2.13.3.jar"
"Class-Path: my/jars/spring-boot-starter-2.4.2.jar my/jars/quark-context-\r\n" +
" 0.1.2.jar my/jars/logback-filters-0.1.0.jar my/jars/spring-boot-autocon\r\n" +
" figure-2.4.2.jar my/jars/spring-boot-2.4.2.jar my/jars/spring-boot-star\r\n" +
" ter-logging-2.4.2.jar my/jars/jakarta.annotation-api-1.3.5.jar my/jars/\r\n" +
" spring-context-5.3.3.jar my/jars/spring-aop-5.3.3.jar my/jars/spring-be\r\n" +
" ans-5.3.3.jar my/jars/spring-expression-5.3.3.jar my/jars/spring-core-5\r\n" +
" .3.3.jar my/jars/snakeyaml-1.27.jar my/jars/logback-classic-1.2.3.jar m\r\n" +
" y/jars/log4j-to-slf4j-2.13.3.jar my/jars/jul-to-slf4j-1.7.30.jar my/jar\r\n" +
" s/slf4j-api-1.7.30.jar my/jars/annotations-16.0.1.jar my/jars/spring-jc\r\n" +
" l-5.3.3.jar my/jars/logback-core-1.2.3.jar my/jars/log4j-api-2.13.3.jar"
)
}

@Test
fun `should create classpath with unix file separators from windows classpathPrefix`() {
// given
val project = projectWithPlugins()
.withGroup("com.coditory")
.withBuildGradle(
"""
plugins {
id 'java'
id 'com.coditory.manifest'
}
repositories {
jcenter()
}
manifest {
classpathPrefix = "my\\important\\jars\\"
}
dependencies {
compile 'com.coditory.quark:quark-context:0.1.2'
}
"""
)
.build()

// when
val result = project.runGradle(listOf("processResources"))

// then
assertThat(result.task(":manifest")?.outcome)
.isEqualTo(TaskOutcome.SUCCESS)

// and
val manifest = project.readFile("build/resources/main/META-INF/MANIFEST.MF")
assertThat(manifest.replace("\r\n ", ""))
.contains("my/important/jars/quark-context-0.1.2.jar")
}
}

0 comments on commit be340a6

Please sign in to comment.