-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds synchronization of resources for refresh mojo + hotfix to avoid …
…blocking main thread in http mojo (#478)
- Loading branch information
1 parent
ae49ced
commit 3b78659
Showing
13 changed files
with
1,167 additions
and
113 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
src/main/java/org/asciidoctor/maven/refresh/AbstractFileAlterationListenerAdaptor.java
This file contains 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 org.asciidoctor.maven.refresh; | ||
|
||
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.asciidoctor.maven.AsciidoctorRefreshMojo; | ||
|
||
import java.io.File; | ||
|
||
public abstract class AbstractFileAlterationListenerAdaptor extends FileAlterationListenerAdaptor { | ||
|
||
private final AsciidoctorRefreshMojo mojo; | ||
private final Runnable postAction; | ||
private final Log log; | ||
|
||
public AbstractFileAlterationListenerAdaptor(AsciidoctorRefreshMojo mojo, Runnable postAction, Log log) { | ||
this.mojo = mojo; | ||
this.postAction = postAction; | ||
this.log = log; | ||
} | ||
|
||
@Override | ||
public void onFileCreate(final File file) { | ||
processFile(file, "created"); | ||
postAction.run(); | ||
} | ||
|
||
@Override | ||
public void onFileChange(final File file) { | ||
processFile(file, "updated"); | ||
postAction.run(); | ||
} | ||
|
||
abstract void processFile(File file, String actionName); | ||
|
||
public AsciidoctorRefreshMojo getMojo() { | ||
return mojo; | ||
} | ||
|
||
public Log getLog() { | ||
return log; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...java/org/asciidoctor/maven/refresh/AsciidoctorConverterFileAlterationListenerAdaptor.java
This file contains 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,34 @@ | ||
package org.asciidoctor.maven.refresh; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.asciidoctor.maven.AsciidoctorRefreshMojo; | ||
import org.asciidoctor.maven.process.ResourcesProcessor; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
|
||
public class AsciidoctorConverterFileAlterationListenerAdaptor extends AbstractFileAlterationListenerAdaptor { | ||
|
||
private static final ResourcesProcessor EMPTY_RESOURCES_PROCESSOR = (sourcesDir, outputDir, encoding, configuration) -> { | ||
}; | ||
|
||
|
||
public AsciidoctorConverterFileAlterationListenerAdaptor(AsciidoctorRefreshMojo mojo, Runnable postAction, Log log) { | ||
super(mojo, postAction, log); | ||
} | ||
|
||
@Override | ||
synchronized void processFile(File file, String actionName) { | ||
getLog().info(String.format("Source file %s %s", file.getAbsolutePath(), actionName)); | ||
long timeInMillis = TimeCounter.timed(() -> { | ||
try { | ||
getMojo().processSources(Collections.singletonList(file), EMPTY_RESOURCES_PROCESSOR); | ||
} catch (MojoExecutionException e) { | ||
getLog().error(e); | ||
} | ||
}); | ||
getLog().info("Converted document in " + timeInMillis + "ms"); | ||
} | ||
|
||
} |
Oops, something went wrong.