-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c842f3
commit 759f65f
Showing
10 changed files
with
205 additions
and
146 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
55 changes: 55 additions & 0 deletions
55
asciidoctor-maven-plugin/src/main/java/org/asciidoctor/maven/AsciidoctorJFactory.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,55 @@ | ||
package org.asciidoctor.maven; | ||
|
||
import java.io.File; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.asciidoctor.Asciidoctor; | ||
import org.asciidoctor.jruby.AsciidoctorJRuby; | ||
import org.asciidoctor.jruby.internal.JRubyRuntimeContext; | ||
import org.jruby.Ruby; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class AsciidoctorJFactory { | ||
|
||
Asciidoctor create(String gemPath, Log log) throws MojoExecutionException { | ||
Asciidoctor asciidoctor; | ||
if (gemPath == null) { | ||
asciidoctor = AsciidoctorJRuby.Factory.create(); | ||
} else { | ||
// Replace Windows path separator to avoid paths with mixed \ and /. | ||
// This happens for instance when setting: <gemPath>${project.build.directory}/gems-provided</gemPath> | ||
// because the project's path is converted to string. | ||
String normalizedGemPath = (File.separatorChar == '\\') ? gemPath.replaceAll("\\\\", "/") : gemPath; | ||
asciidoctor = AsciidoctorJRuby.Factory.create(normalizedGemPath); | ||
} | ||
|
||
Ruby rubyInstance = null; | ||
try { | ||
rubyInstance = (Ruby) JRubyRuntimeContext.class.getMethod("get") | ||
.invoke(null); | ||
} catch (NoSuchMethodException e) { | ||
if (rubyInstance == null) { | ||
try { | ||
rubyInstance = (Ruby) JRubyRuntimeContext.class.getMethod("get", Asciidoctor.class).invoke(null, asciidoctor); | ||
} catch (Exception e1) { | ||
throw new MojoExecutionException("Failed to invoke get(AsciiDoctor) for JRubyRuntimeContext", e1); | ||
} | ||
|
||
} | ||
} catch (Exception e) { | ||
throw new MojoExecutionException("Failed to invoke get for JRubyRuntimeContext", e); | ||
} | ||
|
||
String gemHome = rubyInstance.evalScriptlet("ENV['GEM_HOME']").toString(); | ||
String gemHomeExpected = (gemPath == null || "".equals(gemPath)) ? "" : gemPath.split(java.io.File.pathSeparator)[0]; | ||
|
||
if (!"".equals(gemHome) && !gemHomeExpected.equals(gemHome)) { | ||
log.warn("Using inherited external environment to resolve gems (" + gemHome + "), i.e. build is platform dependent!"); | ||
} | ||
|
||
return asciidoctor; | ||
} | ||
} |
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
Oops, something went wrong.