Skip to content

Commit

Permalink
Exlude secondary source elements by matching rather than substraction (
Browse files Browse the repository at this point in the history
…asciidoctor#410)

This is a very subtle issue. When two Filtree instances are subtracted from each other
in order to eliminate a set of files, the base directory of the tree is lost. If this is
in a CopySpec the relative paths will thus also be lost. The solution is to use a matcher
of type PatternFilterable and then to exclude by FileTreeElement.

When using
  • Loading branch information
ysb33r committed Jan 19, 2020
1 parent 0c016d4 commit ddf77fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import org.gradle.api.InvalidUserDataException
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.CopySpec
import org.gradle.api.file.FileTree
import org.gradle.api.file.FileTreeElement
import org.gradle.api.provider.Provider
import org.gradle.api.specs.Spec
import org.gradle.api.tasks.Console
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
Expand All @@ -38,6 +40,7 @@ import org.gradle.api.tasks.OutputDirectories
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.api.tasks.util.PatternSet
import org.ysb33r.grolifant.api.FileUtils
import org.ysb33r.grolifant.api.StringUtils
Expand Down Expand Up @@ -672,9 +675,14 @@ abstract class AbstractAsciidoctorBaseTask extends DefaultTask {
* @return Source tree based upon configured pattern.
*/
protected FileTree getSecondarySourceFileTreeFrom(File dir) {
FileTree initialTree = project.fileTree(dir).
matching(this.secondarySourceDocumentPattern ?: defaultSecondarySourceDocumentPattern)
(initialTree - getSourceFileTreeFrom(dir)).asFileTree
FileTree doNotInclude = getSourceFileTreeFrom(dir)
project.fileTree(dir)
.matching(this.secondarySourceDocumentPattern ?: defaultSecondarySourceDocumentPattern)
.matching { PatternFilterable target ->
target.exclude({ FileTreeElement element ->
doNotInclude.contains(element.file)
} as Spec<FileTreeElement>)
}
}

/** The default PatternSet that will be used if {@code sources} was never called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AsciidoctorEpubTask extends AbstractAsciidoctorTask {
kindleGenExtension = project.extensions.getByType(KindleGenExtension)
sourceDir = 'src/docs/asciidocEpub'

// TODO: We are setting this curretnly to fix a problem in asciidoctor-epub GEM.
// TODO: We are setting this currently to fix a problem in asciidoctor-epub GEM.
useIntermediateWorkDir()
}

Expand Down

0 comments on commit ddf77fd

Please sign in to comment.