Skip to content
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

Upgraded Features #7

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= midscribe

Tool that is able to generate documentation from midpoint configuration objects in asciidoc format and HTML export.
Tool that is able to generate documentation from midpoint configuration objects in asciidoc format and HTML/PDF export.

== How To Build

Expand Down Expand Up @@ -54,6 +54,7 @@ Usage: java [-Dlogback.configurationFile=logback.xml] -jar midscribe.jar [option
Template file. File should be ZIP containing "template" directory with Velocity templates or path to directory with templates. Main template is "documentation.vm"
```


=== Examples

Following example generates only AsciiDoc file
Expand All @@ -66,6 +67,51 @@ This example generates AsciiDoc as well as HTML file
java -jar midscribe-executable.jar generate -s <FOLDER_WITH_MIDPOINT_XML_OBJECTS> -eo documentation.html -ef HTML
```

This example generates AsciiDoc as well as PDF file with custom property file
```
java -jar midscribe-executable.jar generate -s <FOLDER_WITH_MIDPOINT_XML_OBJECTS> -eo documentation.pdf -ef PDF -pf <CUSTOM_PROPERTY_FILE>
```

== Supported midpoint objects

The generator supports the following midpoint objects:

* Object templates
* Resources
* Libraries
* Orgs
* Roles
* Tasks
* Users
* Archetypes
* LookupTables
* Notifications
* SecurityPolicies
* ValuePolicies

== Properties File Configuration

The `midscribe.properties` or `custom.properties` file needs to include the following attributes for the title, project description etc. :

* `project.name`=MidPoint Project Documentation
* `project.author`=Company, s.r.o.
* `project.version`=0.1
* `project.date`={localdate}

* `project.description`=This is the optional preamble (an untitled section body).\
Useful for writing simple sectionless documents consisting only of a preamble.

* `project.expressionEnabled`=false (false is default, if you want to generate all expressions in the documentation you need to set it to true. Expressions are generated when there is custom script in mappings, notifications etc.)

== Custom styling
You can customize you own style that will be used for generating HTML/PDF file. For that you need to override the style.css file that is located :
```
midscribe/midscribe-core/src/main/resources/css/style.css
```

When there is no default css file, AsciiDoctor default style will be used.
PDF file uses the same styling as HTML because the PDF file is generated from HTML file.

== Example

Here is an example generated from object located in `midscribe-core/src/test/resources/objects` folder.
Expand Down
6 changes: 6 additions & 0 deletions midscribe-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<artifactId>velocity-engine-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.7</version> <!-- or the latest version -->
</dependency>

<dependency>
<groupId>com.evolveum.midpoint.infra</groupId>
<artifactId>schema</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.evolveum.midscribe.generator;

import org.asciidoctor.Asciidoctor;
import org.asciidoctor.AttributesBuilder;
import org.asciidoctor.Options;
import org.asciidoctor.SafeMode;

Expand All @@ -24,16 +25,34 @@ public void export(File adocFile, File output) throws IOException {
File dir = output.getAbsoluteFile().getParentFile();
File file = new File(output.getName());

Options options = Options.builder()
.safe(SafeMode.UNSAFE)
.toDir(dir)
.toFile(file)
.headerFooter(true)
.build();
// .templateDir(new File("./src/test/resources/css"));
String cssFilePath = "../../midscribe-core/src/main/resources/css/style.css";

Asciidoctor doctor = createAsciidoctor();
File cssFile = new File(cssFilePath);

doctor.convertFile(adocFile, options);
if (cssFile.exists() && cssFile.length() > 0) {
Options options = Options.builder()
.safe(SafeMode.UNSAFE)
.toDir(dir)
.toFile(file)
.headerFooter(true)
.attributes(AttributesBuilder.attributes().styleSheetName(cssFilePath))
.build();

Asciidoctor doctor = createAsciidoctor();

doctor.convertFile(adocFile, options);
} else {
// If the CSS file is empty or does not exist, convert without adding a custom stylesheet
Options options = Options.builder()
.safe(SafeMode.UNSAFE)
.toDir(dir)
.toFile(file)
.headerFooter(true)
.build();

Asciidoctor doctor = createAsciidoctor();

doctor.convertFile(adocFile, options);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package com.evolveum.midscribe.generator;

import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
import org.asciidoctor.SafeMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

import java.io.File;
import java.io.IOException;

/**
* Created by Viliam Repan (lazyman).
*/
public class PdfExporter extends ExporterBase {

private static final Logger LOG = LoggerFactory.getLogger(PdfExporter.class);
Expand All @@ -22,20 +15,38 @@ public String getDefaultExtension() {
}

@Override
public void export(File adocFile, File output) throws IOException {
File dir = output.getAbsoluteFile().getParentFile();
File file = new File(output.getName());
public void export(File adocFile, File outputPdf) throws IOException {
File tempHtmlFile = File.createTempFile("temp", ".html");

try {
HtmlExporter htmlExporter = new HtmlExporter();
htmlExporter.export(adocFile, tempHtmlFile);

String princeCommand = "prince " + tempHtmlFile.getAbsolutePath() + " -o " + outputPdf.getAbsolutePath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you switch to external command? Asciidoctor supports export to PDF, this creates dependency on another binary that might not be available. Native PDF export via asciidoctor is preferred, in case prince is needed then I'd expected user will use html export and then prince command separately

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem with the asciidoctor PDF export was formatting problem. Most of the generated documentation was unusable. The problem was that it did not recognize when the generated expression was ending therefore if the expression was longer and appeared on the next page it was overlapped with other sections. Use of the prince fixed that issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matejglombik I understand but can't accept 3rd party dependency this way. If I understand it correctly prince can be still used with midscribe --output-format html --output document.html; and then prince document.html document.pdf . We can rather try to fix pdf generator later to get rid of prince altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matejglombik I've created some simple test with resource object that contains long groovy script (in terms of line count and line length), midscribe rendered pdf where script just truncated and didn't continue to next page, lines breaks were created correctly. Could you provide (send) xml that creates incorrect output please?

Process process = Runtime.getRuntime().exec(princeCommand);
int exitCode = process.waitFor();
if (exitCode != 0) {
LOG.error("PrinceXML conversion failed with exit code " + exitCode);
}
} catch (IOException | InterruptedException e) {
LOG.error("Error converting AsciiDoc to PDF", e);
throw new IOException("Conversion failed", e);
} finally {
// Delete temporary HTML file
tempHtmlFile.delete();
}
}
}











Options options = Options.builder()
.safe(SafeMode.UNSAFE)
.inPlace(true)
.toDir(dir)
.toFile(file)
.backend("pdf")
.build();

Asciidoctor doctor = createAsciidoctor();

doctor.convertFile(adocFile, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,39 @@ public String getProperty(String key) {
return properties.getProperty(key);
}

public String translator(String placeholder) {
if (placeholder != null && placeholder.startsWith("$(") && placeholder.endsWith(")")) {
String key = placeholder.substring(2, placeholder.length() - 1);
String value = properties.getProperty(key);
if (value != null){
return value;
}
} else {
return placeholder;
}
return placeholder;
}

public List<UserType> loadUsers() throws Exception {
return loadObjects(UserType.class);
}

public List<ArchetypeType> loadArchetypes() throws Exception {
return loadObjects(ArchetypeType.class);
}

public List<ValuePolicyType> loadValuePolicies() throws Exception {
return loadObjects(ValuePolicyType.class);
}

public List<SecurityPolicyType> loadSecurityPolicies() throws Exception {
return loadObjects(SecurityPolicyType.class);
}

public List<SystemConfigurationType> loadSystemConfiguration() throws Exception {
return loadObjects(SystemConfigurationType.class);
}

public List<LookupTableType> loadLookupTables() throws Exception {
return loadObjects(LookupTableType.class);
}
Expand Down
Loading