Skip to content

Commit 5deab4f

Browse files
committed
Remove AsciidoctorUtils class
This class contained a method to convert options into asciidoctor cli. Used only for logging and tests it's considered not useful. Other changes: * Add AssertJ dependency to Java projects by default * Refactored AsciidoctorUtils.isOptionWithAttribute into JRubyAsciidoctor.containsAttributeWithValue Fixes asciidoctor#1169
1 parent 5083729 commit 5deab4f

File tree

5 files changed

+29
-202
lines changed

5 files changed

+29
-202
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,41 @@
11
package org.asciidoctor.cli;
22

33
import com.beust.jcommander.JCommander;
4-
import org.asciidoctor.Attributes;
5-
import org.asciidoctor.Options;
6-
import org.asciidoctor.OptionsBuilder;
74
import org.asciidoctor.SafeMode;
8-
import org.asciidoctor.jruby.internal.AsciidoctorUtils;
95
import org.junit.Test;
106

117
import java.io.File;
12-
import java.util.List;
8+
import java.nio.file.Path;
139

14-
import static org.hamcrest.CoreMatchers.is;
15-
import static org.hamcrest.MatcherAssert.assertThat;
16-
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
17-
import static org.hamcrest.collection.IsMapContaining.hasEntry;
18-
import static org.hamcrest.collection.IsMapContaining.hasKey;
10+
import static org.assertj.core.api.Assertions.assertThat;
1911

2012
public class WhenAsciidoctorAPICallIsCalled {
2113

2214
@Test
2315
public void api_parameters_should_be_transformed_to_cli_command() {
24-
25-
Attributes attributes = Attributes.builder()
26-
.attribute("myAtribute", "myValue")
27-
.sectionNumbers(true)
28-
.copyCss(false)
29-
.build();
30-
31-
OptionsBuilder optionsBuilder = Options.builder()
32-
.backend("docbook")
33-
.templateDirs(new File("a"), new File("b"))
34-
.safe(SafeMode.UNSAFE)
35-
.attributes(attributes);
36-
37-
List<String> command = AsciidoctorUtils.toAsciidoctorCommand(
38-
optionsBuilder.asMap(), "file.adoc");
39-
40-
String currentDirectory = new File("").getAbsolutePath() + File.separator;
41-
42-
String[] parameters = command.subList(1, command.size()).toArray(new String[0]);
16+
final String currentDirectory = new File("").getAbsolutePath() + File.separator;
17+
var parameters = new String[]{
18+
"-T", Path.of(currentDirectory, "a").toAbsolutePath().toString(),
19+
"-T", Path.of(currentDirectory, "b").toAbsolutePath().toString(),
20+
"-S", "UNSAFE",
21+
"-b", "docbook",
22+
"-a", "myAttribute=myValue",
23+
"-a", "sectnums",
24+
"-a", "copycss!",
25+
"file.adoc"
26+
};
4327

4428
final AsciidoctorCliOptions asciidoctorCliOptions = new AsciidoctorCliOptions();
4529
final JCommander jCommander = new JCommander(asciidoctorCliOptions);
4630
jCommander.parse(parameters);
4731

48-
assertThat(asciidoctorCliOptions.getTemplateDir(), containsInAnyOrder(currentDirectory + "a", currentDirectory + "b"));
49-
assertThat(asciidoctorCliOptions.getSafeMode(), is(SafeMode.UNSAFE));
50-
assertThat(asciidoctorCliOptions.getBackend(), is("docbook"));
51-
assertThat(asciidoctorCliOptions.getParameters(), containsInAnyOrder("file.adoc"));
52-
53-
assertThat(asciidoctorCliOptions.getAttributes(), hasEntry("myAtribute", "myValue"));
54-
assertThat(asciidoctorCliOptions.getAttributes(), hasKey("sectnums"));
55-
assertThat(asciidoctorCliOptions.getAttributes(), hasKey("copycss!"));
32+
assertThat(asciidoctorCliOptions.getTemplateDir()).containsExactlyInAnyOrder(currentDirectory + "a", currentDirectory + "b");
33+
assertThat(asciidoctorCliOptions.getSafeMode()).isEqualTo(SafeMode.UNSAFE);
34+
assertThat(asciidoctorCliOptions.getBackend()).isEqualTo("docbook");
35+
assertThat(asciidoctorCliOptions.getParameters()).containsExactly("file.adoc");
36+
assertThat(asciidoctorCliOptions.getAttributes())
37+
.containsEntry("myAttribute", "myValue")
38+
.containsEntry("sectnums", "")
39+
.containsEntry("copycss!", "");
5640
}
57-
5841
}

asciidoctorj-core/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ dependencies {
3333
testImplementation "com.google.guava:guava:$guavaVersion"
3434
testImplementation "org.jsoup:jsoup:$jsoupVersion"
3535
testImplementation "io.netty:netty-all:$nettyVersion"
36-
testImplementation "org.assertj:assertj-core:$assertjVersion"
3736
testImplementation project(':asciidoctorj-arquillian-extension')
3837
compileOnly "org.osgi:osgi.annotation:$osgiVersion"
3938
}

asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/AsciidoctorUtils.java

-158
This file was deleted.

asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ public <T> T convert(String content, Map<String, Object> options, Class<T> expec
286286

287287
this.rubyGemsPreloader.preloadRequiredLibraries(options);
288288

289-
logger.fine(String.join(" ", AsciidoctorUtils.toAsciidoctorCommand(options, "-")));
290-
291-
if (AsciidoctorUtils.isOptionWithAttribute(options, Attributes.SOURCE_HIGHLIGHTER, "pygments")) {
289+
if (containsAttributeWithValue(options, Attributes.SOURCE_HIGHLIGHTER, "pygments")) {
292290
logger.fine("In order to use Pygments with Asciidoctor, you need to install Pygments (and Python, if you don't have it yet). Read https://docs.asciidoctor.org/asciidoctor/latest/syntax-highlighting/pygments.");
293291
}
294292

@@ -324,6 +322,12 @@ public <T> T convert(String content, Map<String, Object> options, Class<T> expec
324322

325323
}
326324

325+
private boolean containsAttributeWithValue(Map<String, Object> options, String attributeName, String attributeValue) {
326+
return Optional.ofNullable((Map<String, String>) options.get(Options.ATTRIBUTES))
327+
.map(attributes -> attributes.get(attributeName))
328+
.map(value -> value.equals(attributeValue))
329+
.orElse(Boolean.FALSE);
330+
}
327331

328332
@Override
329333
public String convert(String content, Options options) {
@@ -372,8 +376,6 @@ public <T> T convertFile(File file, Map<String, Object> options, Class<T> expect
372376

373377
this.rubyGemsPreloader.preloadRequiredLibraries(options);
374378

375-
logger.fine(String.join(" ", AsciidoctorUtils.toAsciidoctorCommand(options, file.getAbsolutePath())));
376-
377379
String currentDirectory = rubyRuntime.getCurrentDirectory();
378380

379381
if (options.containsKey(Options.BASEDIR)) {

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ subprojects {
140140

141141
dependencies {
142142
testImplementation "junit:junit:$junitVersion"
143+
testImplementation "org.assertj:assertj-core:$assertjVersion"
143144
testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
144145
testImplementation("org.spockframework:spock-core:$spockVersion") {
145146
exclude group: 'org.hamcrest', module: 'hamcrest-core'

0 commit comments

Comments
 (0)