Skip to content
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
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Scala Steward: Reformat with scalafmt 3.7.0
9918d3ef687de71b9006c3989cd4306212f7ff63

# Scala Steward: Reformat with scalafmt 3.10.4
8b4cde6f77c4192809208de1b8c11e57e36c6f71
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.10.3"
version = "3.10.4"
runner.dialect = scala213
maxColumn = 100
docstrings.style = Asterisk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ object MojoImplementation {
}

val (modules, extraClasspath) = {
val hasJunit = allArtifacts.exists(a => a.getGroupId == "junit" && a.getArtifactId == "junit")
val hasJunit =
allArtifacts.exists(a => a.getGroupId == "junit" && a.getArtifactId == "junit")
val hasJunitInterface = allArtifacts.exists(a => a.getArtifactId == "junit-interface")
if (hasJunit && !hasJunitInterface && configuration == "test") {
val junitInterfaceVersion = "0.13.3"
Expand Down Expand Up @@ -347,7 +348,9 @@ object MojoImplementation {
log.debug(s"Configuration to be serialized:\n$config")
bloop.config.write(config, configTarget.toPath)

log.info(s"Starting to write configuration for project: ${project.getArtifactId()} with configuration: $configuration")
log.info(
s"Starting to write configuration for project: ${project.getArtifactId()} with configuration: $configuration"
)
log.debug(s"Source directories: ${sourceDirs0.map(_.getAbsolutePath).mkString(", ")}")
log.debug(s"Classpath: ${classpath0().asScala.mkString(", ")}")
log.debug(s"Resources: ${resources0.asScala.mkString(", ")}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,26 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
case (configFile, projectName, List(module1, module2)) =>
// module1 is "module1"
// module2 is "module1-test"

// module1's test configuration should be renamed to avoid conflict with module2
// Default would be "module1-test", but "module1-test" exists as a reactor artifact (module2)
// So it should be "module1-test-scope"
assertEquals("module1", module1.project.name)

// We need to check the test configuration name for module1.
// check() function loads the "compile" configuration (default expectation in this test suite assumption?)
// Actually check() loads the config based on the project file name.
// module1 comes from "conflicting_modules/module1/pom.xml" -> parent dir is "module1".
// The bloop file loaded is "module1.json".

// Let's check the test config of module1
val module1TestConfigPath = configFile.project.directory.resolve(".bloop").resolve("module1-test-scope.json")
assertTrue(s"Test config for module1 should be renamed to module1-test-scope.json", Files.exists(module1TestConfigPath))

val module1TestConfigPath =
configFile.project.directory.resolve(".bloop").resolve("module1-test-scope.json")
assertTrue(
s"Test config for module1 should be renamed to module1-test-scope.json",
Files.exists(module1TestConfigPath)
)

val module1TestConfig = readValidBloopConfig(module1TestConfigPath.toFile())
assertEquals("module1-test-scope", module1TestConfig.project.name)

Expand Down Expand Up @@ -310,48 +314,62 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
case List(m1, m2) => (m1, m2)
case _ => fail(s"Expected 2 submodules, but got ${submodulesList.size}")
}

// Standard naming should be preserved when no collision exists
assert(!configFile.project.name.contains("-compile"))
assert(!module1.project.name.contains("-compile"))
assert(!module2.project.name.contains("-compile"))
// Note: To test actual collision, we would need to construct a project structure
// where a submodule name conflicts with the test suffix of another module.
// For now, we verify that the default behavior is correct (no suffixes).

// Note: To test actual collision, we would need to construct a project structure
// where a submodule name conflicts with the test suffix of another module.
// For now, we verify that the default behavior is correct (no suffixes).
}
}

@Test
def junitSupport() = {
check("junit_project/pom.xml") { (configFile, projectName, subprojects) =>
assert(subprojects.isEmpty)

// Read the test configuration file
val testConfigFile = readValidBloopConfig(configFile.project.directory.resolve(".bloop").resolve(s"$projectName-test.json").toFile())

val testConfigFile = readValidBloopConfig(
configFile.project.directory.resolve(".bloop").resolve(s"$projectName-test.json").toFile()
)

// Check if junit-interface is present in the resolution modules of the test config
val resolutionModules = testConfigFile.project.resolution.get.modules
val hasJunitInterface = resolutionModules.exists(_.name.contains("junit-interface"))

assertTrue("junit-interface should be present in test config when junit is used", hasJunitInterface)


assertTrue(
"junit-interface should be present in test config when junit is used",
hasJunitInterface
)

// Also check classpath
val hasJunitInterfaceInClasspath = testConfigFile.project.classpath.exists(_.toString.contains("junit-interface"))
assertTrue("junit-interface should be present in test classpath when junit is used", hasJunitInterfaceInClasspath)
val hasJunitInterfaceInClasspath =
testConfigFile.project.classpath.exists(_.toString.contains("junit-interface"))
assertTrue(
"junit-interface should be present in test classpath when junit is used",
hasJunitInterfaceInClasspath
)
}
}

private def check(testProject: String, submodules: List[String] = Nil, extraContent: Map[String, String] = Map.empty)(
private def check(
testProject: String,
submodules: List[String] = Nil,
extraContent: Map[String, String] = Map.empty
)(
checking: (Config.File, String, List[Config.File]) => Unit
): Unit = {
println(s"Checking $testProject")
val tempDir = Files.createTempDirectory("mavenBloop")
val outFile = copyFromResource(tempDir, testProject)
extraContent.foreach { case (relativePath, content) =>
val p = tempDir.resolve(relativePath)
Files.createDirectories(p.getParent)
Files.write(p, content.getBytes("UTF-8"))
extraContent.foreach {
case (relativePath, content) =>
val p = tempDir.resolve(relativePath)
Files.createDirectories(p.getParent)
Files.write(p, content.getBytes("UTF-8"))
}
submodules.foreach(copyFromResource(tempDir, _))
val wrapperJar = copyFromResource(tempDir, s"maven-wrapper.jar")
Expand Down Expand Up @@ -443,8 +461,6 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
}
}



@Test
def withIncludes() = {
check(
Expand All @@ -456,17 +472,20 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
) { (configFile, projectName, subprojects) =>
assert(subprojects.isEmpty)
val resources = configFile.project.resources.getOrElse(Nil)

val included = resources.find(_.toString.endsWith("included.txt"))
val excluded = resources.find(_.toString.endsWith("excluded.txt"))

assert(included.isDefined, "included.txt should be in resources")
assert(excluded.isEmpty, "excluded.txt should NOT be in resources")

// Ensure the directory itself is not added when we have explicit includes
val resourceDir = configFile.project.directory.resolve("src/main/resources").toAbsolutePath
val hasResourceDir = resources.exists(_.toAbsolutePath == resourceDir)
assert(!hasResourceDir, s"Resource directory $resourceDir should NOT be in resources when includes are specified")
assert(
!hasResourceDir,
s"Resource directory $resourceDir should NOT be in resources when includes are specified"
)
}
}

Expand All @@ -488,7 +507,10 @@ class MavenConfigGenerationTest extends BaseConfigSuite {

val baseDirectory = configFile.project.directory.toAbsolutePath
val hasBaseDir = resources.exists(_.toAbsolutePath == baseDirectory)
assert(!hasBaseDir, s"Base directory $baseDirectory should NOT be in resources when includes are specified")
assert(
!hasBaseDir,
s"Base directory $baseDirectory should NOT be in resources when includes are specified"
)
}
}

Expand All @@ -506,7 +528,7 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
val resourceDir = configFile.project.directory.resolve("src/main/resources").toAbsolutePath
val hasResourceDir = resources.exists(_.toAbsolutePath == resourceDir)
assert(hasResourceDir, s"Resource directory $resourceDir SHOULD be in resources")

// Individual files should NOT be listed
val hasFile = resources.exists(_.toString.endsWith("hello.txt"))
assert(!hasFile, "Individual files inside resource dir should NOT be in resources list")
Expand Down