-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lazy wrappers around diagram generators to make server init more …
…robust
- Loading branch information
Showing
18 changed files
with
135 additions
and
45 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
15 changes: 15 additions & 0 deletions
15
ditaa/src/main/java/org/asciidoctor/diagram/ditaa/DitaaDiagramGenerator.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,15 @@ | ||
package org.asciidoctor.diagram.ditaa; | ||
|
||
import org.asciidoctor.diagram.DiagramGeneratorFunction; | ||
import org.asciidoctor.diagram.LazyDiagramGenerator; | ||
|
||
public class DitaaDiagramGenerator extends LazyDiagramGenerator { | ||
public DitaaDiagramGenerator() { | ||
super("ditaa"); | ||
} | ||
|
||
@Override | ||
protected DiagramGeneratorFunction createGenerator() throws Exception { | ||
return new Ditaa(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
ditaa/src/main/resources/META-INF/services/org.asciidoctor.diagram.DiagramGenerator
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 |
---|---|---|
@@ -1 +1 @@ | ||
org.asciidoctor.diagram.ditaa.Ditaa | ||
org.asciidoctor.diagram.ditaa.DitaaDiagramGenerator |
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
15 changes: 15 additions & 0 deletions
15
plantuml/src/main/java/org/asciidoctor/diagram/plantuml/PlantUMLDiagramGenerator.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,15 @@ | ||
package org.asciidoctor.diagram.plantuml; | ||
|
||
import org.asciidoctor.diagram.DiagramGeneratorFunction; | ||
import org.asciidoctor.diagram.LazyDiagramGenerator; | ||
|
||
public class PlantUMLDiagramGenerator extends LazyDiagramGenerator { | ||
public PlantUMLDiagramGenerator() { | ||
super("plantuml"); | ||
} | ||
|
||
@Override | ||
protected DiagramGeneratorFunction createGenerator() throws Exception { | ||
return new PlantUML(); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
.../src/main/java/org/asciidoctor/diagram/plantuml/PlantUMLPreprocessorDiagramGenerator.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,15 @@ | ||
package org.asciidoctor.diagram.plantuml; | ||
|
||
import org.asciidoctor.diagram.DiagramGeneratorFunction; | ||
import org.asciidoctor.diagram.LazyDiagramGenerator; | ||
|
||
public class PlantUMLPreprocessorDiagramGenerator extends LazyDiagramGenerator { | ||
public PlantUMLPreprocessorDiagramGenerator() { | ||
super("plantumlpreprocessor"); | ||
} | ||
|
||
@Override | ||
protected DiagramGeneratorFunction createGenerator() throws Exception { | ||
return new PlantUMLPreprocessorDiagramGenerator(); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
plantuml/src/main/resources/META-INF/services/org.asciidoctor.diagram.DiagramGenerator
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
org.asciidoctor.diagram.plantuml.PlantUML | ||
org.asciidoctor.diagram.plantuml.PlantUMLPreprocessor | ||
org.asciidoctor.diagram.plantuml.PlantUMLDiagramGenerator | ||
org.asciidoctor.diagram.plantuml.PlantUMLPreprocessorDiagramGenerator |
6 changes: 1 addition & 5 deletions
6
server/src/main/java/org/asciidoctor/diagram/DiagramGenerator.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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
package org.asciidoctor.diagram; | ||
|
||
import java.io.IOException; | ||
|
||
public interface DiagramGenerator { | ||
public interface DiagramGenerator extends DiagramGeneratorFunction { | ||
String getName(); | ||
|
||
ResponseData generate(Request request) throws IOException; | ||
} |
7 changes: 7 additions & 0 deletions
7
server/src/main/java/org/asciidoctor/diagram/DiagramGeneratorFunction.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,7 @@ | ||
package org.asciidoctor.diagram; | ||
|
||
import java.io.IOException; | ||
|
||
public interface DiagramGeneratorFunction { | ||
ResponseData generate(Request request) throws IOException; | ||
} |
41 changes: 41 additions & 0 deletions
41
server/src/main/java/org/asciidoctor/diagram/LazyDiagramGenerator.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,41 @@ | ||
package org.asciidoctor.diagram; | ||
|
||
import java.io.IOException; | ||
|
||
public abstract class LazyDiagramGenerator implements DiagramGenerator { | ||
private final String name; | ||
private DiagramGeneratorFunction diagramGeneratorFunction; | ||
private IOException loadError; | ||
|
||
public LazyDiagramGenerator(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
protected abstract DiagramGeneratorFunction createGenerator() throws Exception; | ||
|
||
public ResponseData generate(Request request) throws IOException { | ||
if (loadError != null) { | ||
throw loadError; | ||
} | ||
|
||
if (diagramGeneratorFunction == null) { | ||
try { | ||
diagramGeneratorFunction = createGenerator(); | ||
} catch (Throwable e) { | ||
String message = getName() + " could not be initialised due to " + e.getClass().getSimpleName(); | ||
if (e.getMessage() != null) { | ||
message += ": " + e.getMessage(); | ||
} | ||
loadError = new IOException(message); | ||
loadError.setStackTrace(e.getStackTrace()); | ||
throw loadError; | ||
} | ||
} | ||
|
||
return diagramGeneratorFunction.generate(request); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...turizr/src/main/java/org/asciidoctor/diagram/structurizr/StructurizrDiagramGenerator.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,15 @@ | ||
package org.asciidoctor.diagram.structurizr; | ||
|
||
import org.asciidoctor.diagram.DiagramGeneratorFunction; | ||
import org.asciidoctor.diagram.LazyDiagramGenerator; | ||
|
||
public class StructurizrDiagramGenerator extends LazyDiagramGenerator { | ||
public StructurizrDiagramGenerator() { | ||
super("structurizr"); | ||
} | ||
|
||
@Override | ||
protected DiagramGeneratorFunction createGenerator() throws Exception { | ||
return new Structurizr(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
structurizr/src/main/resources/META-INF/services/org.asciidoctor.diagram.DiagramGenerator
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 |
---|---|---|
@@ -1 +1 @@ | ||
org.asciidoctor.diagram.structurizr.Structurizr | ||
org.asciidoctor.diagram.structurizr.StructurizrDiagramGenerator |
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
15 changes: 15 additions & 0 deletions
15
syntrax/src/main/java/org/asciidoctor/diagram/syntrax/SyntraxDiagramGenerator.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,15 @@ | ||
package org.asciidoctor.diagram.syntrax; | ||
|
||
import org.asciidoctor.diagram.DiagramGeneratorFunction; | ||
import org.asciidoctor.diagram.LazyDiagramGenerator; | ||
|
||
public class SyntraxDiagramGenerator extends LazyDiagramGenerator { | ||
public SyntraxDiagramGenerator() { | ||
super("syntrax"); | ||
} | ||
|
||
@Override | ||
protected DiagramGeneratorFunction createGenerator() throws Exception { | ||
return new Syntrax(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
syntrax/src/main/resources/META-INF/services/org.asciidoctor.diagram.DiagramGenerator
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 |
---|---|---|
@@ -1 +1 @@ | ||
org.asciidoctor.diagram.syntrax.Syntrax | ||
org.asciidoctor.diagram.syntrax.SyntraxDiagramGenerator |
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