Skip to content

Find dependencies on test and mock frameworks in Fat JAR #40

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

Merged
merged 2 commits into from
May 27, 2022
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
4 changes: 4 additions & 0 deletions utbot-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ classes {
jar {
manifest {
attributes 'Main-Class': 'org.utbot.cli.ApplicationKt'
attributes 'Bundle-SymbolicName': 'org.utbot.cli'
attributes 'Bundle-Version': "${project.version}"
attributes 'Implementation-Title': 'UtBot Java CLI'
attributes 'JAR-Type': 'Fat JAR'
}

version project.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ fun checkFrameworkDependencies(dependencyPaths: String?) {
//TODO: JIRA:1659
// check (somehow) that [UtExecutionInstrumentation] is in dependency path: in one of jars or folders

val dependencyNames = dependencyPaths
.splitToSequence(File.pathSeparatorChar)
val dependencyPathsSequence = dependencyPaths.splitToSequence(File.pathSeparatorChar)

val dependencyNames = dependencyPathsSequence
.mapNotNull { findDependencyName(it) }
.map { it.toLowerCase() }
.toSet()

val testFrameworkPatterns = TestFramework.allItems.map { it.patterns() }
val testFrameworkFound = dependencyNames.matchesAnyOf(testFrameworkPatterns)
val testFrameworkFound = dependencyNames.matchesAnyOf(testFrameworkPatterns) ||
dependencyPathsSequence.any { checkDependencyIsFatJar(it) }

if (!testFrameworkFound) {
error("""
Test frameworks are not found in dependency path $dependencyPaths, dependency names are:
Expand All @@ -41,7 +44,9 @@ fun checkFrameworkDependencies(dependencyPaths: String?) {
}

val mockFrameworkPatterns = MockFramework.allItems.map { it.patterns() }
val mockFrameworkFound = dependencyNames.matchesAnyOf(mockFrameworkPatterns)
val mockFrameworkFound = dependencyNames.matchesAnyOf(mockFrameworkPatterns) ||
dependencyPathsSequence.any { checkDependencyIsFatJar(it) }

if (!mockFrameworkFound) {
error("""
Mock frameworks are not found in dependency path $dependencyPaths, dependency names are:
Expand Down Expand Up @@ -75,4 +80,18 @@ private fun findDependencyName(jarPath: String): String? {
}

return null
}
}

// We consider Fat JARs contain test frameworks and mock frameworks in the dependencies.
private fun checkDependencyIsFatJar(jarPath: String): Boolean {
try {
val attributes = JarFile(jarPath).manifest.mainAttributes
val jarType = attributes.getValue("JAR-Type")

return jarType == "Fat JAR"
} catch (e: Exception) {
logger.warn { "Unexpected error during parsing $jarPath manifest file $e" }
}

return false
}
4 changes: 4 additions & 0 deletions utbot-junit-contest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ jar { dependsOn classes

manifest {
attributes 'Main-Class': 'org.utbot.contest.ContestKt'
attributes 'Bundle-SymbolicName': 'org.utbot.contest'
attributes 'Bundle-Version': "${project.version}"
attributes 'Implementation-Title': 'UtBot JUnit contest'
attributes 'JAR-Type': 'Fat JAR'
}

version '1.0'
Expand Down