Skip to content

Commit 309f07c

Browse files
committed
Add search ignore mask support
1 parent 02449c1 commit 309f07c

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

README.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,23 @@ allow a simple configuration way based on environment variables which override d
132132

133133
### Simplified configuration
134134

135-
|env or property name | description | default value
136-
|---------------------------|---------------------------------------------------------------|---------------------------
137-
|CEM_SEARCH_ROOTS | Examples search roots (comma separated) | ""
138-
|CEM_SEARCH_GLOB | Examples files globs | "**/*.*"
139-
|CEM_EXAMPLES_OVERVIEW_UUID | The fixed UUID for the overview GIST which list all examples | "cafacafe-cafecafe"
140-
|CEM_CONFIG_FILE | Your custom advanced configuration file (optional) | *undefined*
141-
|CEM_SUMMARY_TITLE | Generated summary title | Examples knowledge base
142-
|CEM_GITHUB_ENABLED | To enable or disable standard GITHUB support | true
143-
|CEM_GITHUB_ACTIVATION_KEY | Example publish keyword for github | "gist"
144-
|CEM_GITHUB_TOKEN | Github authentication token for gists API access | *more information below*
145-
|CEM_GITHUB_API | Github API http end point | "https://api.github.com"
146-
|CEM_GITLAB_ENABLED | To enable or disable standard GITLAB support | true
147-
|CEM_GITLAB_ACTIVATION_KEY | Example publish keyword for the gitlab | "snippet"
148-
|CEM_GITLAB_TOKEN | gitlab authentication token for snippets API access | *more information below*
149-
|CEM_GITLAB_API | Gitlab API http end point | "https://gitlab.com/api/v4"
150-
|CEM_GITLAB_VISIBILITY | Gitlab published examples chosen visibility | "public"
135+
| env or property name | description | default value
136+
|----------------------------|---------------------------------------------------------------|---------------------------
137+
| CEM_SEARCH_ROOTS | Examples search roots (comma separated) | ""
138+
| CEM_SEARCH_GLOB | Examples files globs | "**/*.*"
139+
| CEM_SEARCH_IGNORE_MASK | Ignore file regular expression | "(/[.]bsp)|(/[.]scala)"
140+
| CEM_EXAMPLES_OVERVIEW_UUID | The fixed UUID for the overview GIST which list all examples | "cafacafe-cafecafe"
141+
| CEM_CONFIG_FILE | Your custom advanced configuration file (optional) | *undefined*
142+
| CEM_SUMMARY_TITLE | Generated summary title | Examples knowledge base
143+
| CEM_GITHUB_ENABLED | To enable or disable standard GITHUB support | true
144+
| CEM_GITHUB_ACTIVATION_KEY | Example publish keyword for github | "gist"
145+
| CEM_GITHUB_TOKEN | Github authentication token for gists API access | *more information below*
146+
| CEM_GITHUB_API | Github API http end point | "https://api.github.com"
147+
| CEM_GITLAB_ENABLED | To enable or disable standard GITLAB support | true
148+
| CEM_GITLAB_ACTIVATION_KEY | Example publish keyword for the gitlab | "snippet"
149+
| CEM_GITLAB_TOKEN | gitlab authentication token for snippets API access | *more information below*
150+
| CEM_GITLAB_API | Gitlab API http end point | "https://gitlab.com/api/v4"
151+
| CEM_GITLAB_VISIBILITY | Gitlab published examples chosen visibility | "public"
151152

152153
Configuration examples :
153154
```shell

src/main/resources/reference.conf

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ code-examples-manager-config {
2626
// search expression, select example files to look for publish instructions
2727
search-glob = "**/*.*"
2828
search-glob = ${?CEM_SEARCH_GLOB}
29+
// ignore sub-directories which match this regexp pattern
30+
search-ignore-mask = "(/[.]bsp)|(/[.]scala)"
31+
search-ignore-mask = ${?CEM_SEARCH_IGNORE_MASK}
2932
}
3033
// =================================================================================
3134
// each adapter is taken into account if and only if enabled is true && token is defined

src/main/scala/fr/janalyse/cem/Configuration.scala

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import zio.config.ConfigSource.*
2525

2626
final case class ExamplesConfig(
2727
searchRootDirectories: String,
28-
searchGlob: String
28+
searchGlob: String,
29+
searchIgnoreMask: Option[String]
2930
)
3031

3132
final case class RenameRuleConfig(
@@ -61,7 +62,7 @@ final case class MetaConfig(
6162
buildVersion: Option[String],
6263
buildDateTime: Option[String],
6364
buildUUID: Option[String],
64-
contactEmail: Option[String],
65+
contactEmail: Option[String]
6566
) {
6667
def name: String = projectName.getOrElse("code-examples-manager")
6768

@@ -97,7 +98,8 @@ object Configuration {
9798

9899
val examplesConfig = (
99100
string("search-root-directories") |@|
100-
string("search-glob")
101+
string("search-glob") |@|
102+
string("search-ignore-mask").optional
101103
).to[ExamplesConfig]
102104

103105
val renameRuleConfig = (

src/main/scala/fr/janalyse/cem/Synchronize.scala

+12-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ object Synchronize {
3636
type SearchGlob = String
3737
type ExampleFilename = String
3838
type FileContent = String
39+
type IgnoreMask = String
3940

4041
val charset = Charset.Standard.utf8
4142

@@ -46,10 +47,13 @@ object Synchronize {
4647
} yield content
4748
}
4849

49-
def findFiles(fromRootFilename: SearchRoot, globPattern: SearchGlob): RIO[Blocking, List[ExampleFilename]] = {
50+
def findFiles(fromRootFilename: SearchRoot, globPattern: SearchGlob, ignoreMask:Option[IgnoreMask]=None): RIO[Blocking, List[ExampleFilename]] = {
5051
val pathMatcher = FileSystem.default.getPathMatcher(s"glob:$globPattern")
52+
val ignoreMaskRegex = ignoreMask.map(_.r)
5153
def pathFilter(path: Path, fileAttrs: BasicFileAttributes): Boolean = {
52-
pathMatcher.matches(path.toFile.toPath) && !fileAttrs.isDirectory
54+
pathMatcher.matches(path.toFile.toPath) &&
55+
!fileAttrs.isDirectory &&
56+
(ignoreMask.isEmpty || ignoreMaskRegex.get.findFirstIn(path.toString).isEmpty)
5357
}
5458
val from = Path(fromRootFilename)
5559
val foundFilesStream = Files.find(from)(pathFilter)
@@ -62,11 +66,12 @@ object Synchronize {
6266
def examplesFromGivenRoot(
6367
searchRoot: SearchRoot,
6468
globPattern: SearchGlob,
65-
filesFetcher: (SearchRoot, SearchGlob) => RIO[Blocking, List[ExampleFilename]],
69+
ignoreMask: Option[IgnoreMask],
70+
filesFetcher: (SearchRoot, SearchGlob, Option[IgnoreMask]) => RIO[Blocking, List[ExampleFilename]],
6671
contentFetcher: ExampleFilename => RIO[Blocking, FileContent]
6772
): RIO[Blocking, List[CodeExample]] = {
6873
for {
69-
foundFilenames <- filesFetcher(searchRoot, globPattern)
74+
foundFilenames <- filesFetcher(searchRoot, globPattern, ignoreMask)
7075
examplesTasks = foundFilenames.map(file => CodeExample.makeExample(file, searchRoot, contentFetcher(file))).toList
7176
examples <- RIO.mergeAll(examplesTasks)(List.empty[CodeExample])((accu, next) => next :: accu)
7277
} yield examples.filter(_.uuid.isDefined)
@@ -81,8 +86,8 @@ object Synchronize {
8186
} yield pathsAsStrings
8287
}
8388

84-
def examplesCollectFor(searchRoots: List[SearchRoot], usingGlobPattern: SearchGlob): RIO[Blocking, Vector[CodeExample]] = {
85-
val examplesFromRoots = searchRoots.map(fromRoot => examplesFromGivenRoot(fromRoot, usingGlobPattern, findFiles, readFileContent))
89+
def examplesCollectFor(searchRoots: List[SearchRoot], usingGlobPattern: SearchGlob, usingIgnoreMask:Option[IgnoreMask]): RIO[Blocking, Vector[CodeExample]] = {
90+
val examplesFromRoots = searchRoots.map(fromRoot => examplesFromGivenRoot(fromRoot, usingGlobPattern, usingIgnoreMask, findFiles, readFileContent))
8691
RIO.mergeAll(examplesFromRoots)(Vector.empty[CodeExample])((accu, newRoot) => accu.appendedAll(newRoot))
8792
}
8893

@@ -98,7 +103,7 @@ object Synchronize {
98103
config <- getConfig[ApplicationConfig]
99104
examplesConfig = config.codeExamplesManagerConfig.examples
100105
searchRoots <- examplesValidSearchRoots(examplesConfig.searchRootDirectories)
101-
localExamples <- examplesCollectFor(searchRoots, examplesConfig.searchGlob)
106+
localExamples <- examplesCollectFor(searchRoots, examplesConfig.searchGlob, examplesConfig.searchIgnoreMask)
102107
_ <- examplesCheckCoherency(localExamples)
103108
} yield localExamples
104109

0 commit comments

Comments
 (0)