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
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,17 @@ object MojoImplementation {
val dir = Paths.get(a.getDirectory())
if (Files.exists(dir)) {
if (a.getIncludes().isEmpty() && a.getExcludes().isEmpty()) {
Some(dir)
List(dir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test that verifies the fix?

} else {
val scanner = new DirectoryScanner()
scanner.setBasedir(a.getDirectory())
scanner.setIncludes(a.getIncludes().toArray(new Array[String](0)))
scanner.setExcludes(a.getExcludes().toArray(new Array[String](0)))
scanner.scan()
scanner.getIncludedFiles().map(f => dir.resolve(f))
scanner.getIncludedFiles().toList.map(f => dir.resolve(f))
}
} else None
case _ => None
} else Nil
case _ => Nil
})
val project = Config.Project(name, baseDirectory, Some(root.toPath), sourceDirs, None, None, fullDependencies, classpath, out, classesDir, resources, `scala`, java, sbt, test, platform, resolution, Some(tags), None)
Config.File(Config.File.LatestVersion, project)
Expand Down
19 changes: 19 additions & 0 deletions src/test/resources/default_resources/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>bloop.test</groupId>
<artifactId>default_resources</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>default-resources-test</name>

<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test that uses includes as well? Unless I am misremembering and there is such test already?

</resource>
</resources>
</build>
</project>
22 changes: 22 additions & 0 deletions src/test/resources/with_includes/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>bloop.test</groupId>
<artifactId>with_includes</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>with-includes-test</name>

<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>included.txt</include>
</includes>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,31 @@ class MavenConfigGenerationTest extends BaseConfigSuite {



@Test
def withIncludes() = {
check(
"with_includes/pom.xml",
extraContent = Map(
"with_includes/src/main/resources/included.txt" -> "This file should be included.",
"with_includes/src/main/resources/excluded.txt" -> "This file should be excluded."
)
) { (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")
}
}

@Test
def issue85() = {
check(
Expand All @@ -401,4 +426,25 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
}
}

@Test
def defaultResources() = {
check(
"default_resources/pom.xml",
extraContent = Map(
"default_resources/src/main/resources/hello.txt" -> "hello"
)
) { (configFile, projectName, subprojects) =>
assert(subprojects.isEmpty)
val resources = configFile.project.resources.getOrElse(Nil)
// When no includes/excludes are specified, the whole directory should be included
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")
}
}

}