-
Notifications
You must be signed in to change notification settings - Fork 86
Add life-cycle methods to PostProcessor modifiers #245
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
Open
hmf
wants to merge
15
commits into
scalameta:main
Choose a base branch
from
hmf:post-life-cycle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b7f91b9
Adding LifeCycle counting to the PostModifier. The CliSuite test is f…
898a744
Adding LifeCycle counting to the PostModifier. Added tests to 2 test …
e093bdc
Corrected LifeCycle PostModifier tests. Provided default values for t…
342cf3e
Minor scalameta formatting.
302ba3b
Another minor scalameta formatting.
d55f20f
Another minor scalameta formatting.
40e1d54
Another minor scalameta formatting.
b8005c9
PostModifier onStart now gets a MainSettings wrapper instead of the i…
6a45cfa
PostModifier onStart now gets a MainSettings wrapper instead of the i…
8ba0ab0
PostModifier onExit now gets an Int as an exit code. Removed use on i…
07c886f
Added comments to PostModifier. Removed preProcess and postProcess fr…
9d05586
Added public Exit wrapper for PostModifier onExit.
57984e6
Public companion object Exit's apply method now package private. Lif…
55ed7e2
Reformatting LifeCycleCounter due to reset method change.
0bb50a1
Removed unnecessary test in CliSuite.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
mdoc-docs/src/main/resources/META-INF/services/mdoc.PostModifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| mdoc.docs.EvilplotModifier | ||
| mdoc.docs.LifeCycleModifier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
mdoc-docs/src/main/scala/mdoc/docs/LifeCycleModifier.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package mdoc.docs | ||
|
|
||
| import mdoc._ | ||
|
|
||
| /** | ||
| * Global counter used to test the [[mdoc.Main]] process counting. | ||
| */ | ||
| object LifeCycleCounter { | ||
| val numberOfStarts: ThreadLocal[Integer] = ThreadLocal.withInitial(() => 0) | ||
| val numberOfExists: ThreadLocal[Integer] = ThreadLocal.withInitial(() => 0) | ||
| } | ||
|
|
||
| class LifeCycleModifier extends PostModifier { | ||
| val name = "lifecycle" | ||
|
|
||
| // Starts and stops per instance | ||
| var numberOfStarts = 0 | ||
| var numberOfExists = 0 | ||
|
|
||
| def process(ctx: PostModifierContext): String = { | ||
| // Used for checking the counting | ||
| s"numberOfStarts = $numberOfStarts ; numberOfExists = $numberOfExists" | ||
| } | ||
|
|
||
| /** | ||
| * This is called once when the [[mdoc.Main]] process starts | ||
| * @param settings CLI or API settings used by mdoc | ||
| */ | ||
| override def onStart(settings: MainSettings): Unit = { | ||
| numberOfStarts += 1 | ||
| LifeCycleCounter.numberOfStarts.set(LifeCycleCounter.numberOfStarts.get() + 1) | ||
| } | ||
|
|
||
| /** | ||
| * This is called once when the [[mdoc.Main]] process finsihes | ||
| * @param exit is the exit code returned by mdoc's processing | ||
| */ | ||
| override def onExit(exit: Exit): Unit = { | ||
| numberOfExists += 1 | ||
| LifeCycleCounter.numberOfExists.set(LifeCycleCounter.numberOfExists.get() + 1) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package mdoc | ||
|
|
||
| import mdoc.internal.cli.{Exit => CliExit} | ||
|
|
||
| final class Exit private[mdoc] (val exit: CliExit) { | ||
| def merge(other: Exit): Exit = Exit(exit.merge(other.exit)) | ||
| def isSuccess: Boolean = exit == CliExit.success | ||
| def isError: Boolean = exit == CliExit.error | ||
| } | ||
|
|
||
| object Exit { | ||
| def apply(exit: CliExit): Exit = { | ||
| new Exit(exit) | ||
| } | ||
| def apply(): Exit = { | ||
| Exit(CliExit.success) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
tests/unit/src/test/resources/META-INF/services/mdoc.PostModifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| tests.markdown.EvilplotPostModifier | ||
| tests.markdown.BulletPostModifier | ||
| tests.markdown.LifeCycleModifier | ||
|
|
8 changes: 6 additions & 2 deletions
8
tests/unit/src/test/scala-2.11/tests/markdown/EvilplotPostModifier.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| package tests.markdown | ||
|
|
||
| import mdoc.PostModifier | ||
| import mdoc.PostModifierContext | ||
| import mdoc.{MainSettings, PostModifier, PostModifierContext, Exit} | ||
|
|
||
| class EvilplotPostModifier extends PostModifier { | ||
| val name = "evilplot" | ||
|
|
||
| def process(ctx: PostModifierContext): String = "" | ||
|
|
||
| override def onStart(settings: MainSettings): Unit = () | ||
|
|
||
| override def onExit(exit: Exit): Unit = () | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
tests/unit/src/test/scala-2.13/tests/markdown/EvilplotPostModifier.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| package tests.markdown | ||
|
|
||
| import mdoc.PostModifier | ||
| import mdoc.PostModifierContext | ||
| import mdoc.{MainSettings, PostModifier, PostModifierContext, Exit} | ||
|
|
||
| class EvilplotPostModifier extends PostModifier { | ||
| val name = "evilplot" | ||
| def process(ctx: PostModifierContext): String = "" | ||
|
|
||
| override def onStart(settings: MainSettings): Unit = () | ||
|
|
||
| override def onExit(exit: Exit): Unit = () | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this method, or make it package private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to make this package private because it is used here in
MainOps.