-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from metanorma/update_scripts
Update scripts
- Loading branch information
Showing
8 changed files
with
292 additions
and
13 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
103 changes: 103 additions & 0 deletions
103
src/main/java/org/metanorma/MetanormaCollectionManifest.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,103 @@ | ||
package org.metanorma; | ||
|
||
import org.yaml.snakeyaml.DumperOptions; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.*; | ||
import java.nio.file.Paths; | ||
import java.util.*; | ||
|
||
// To generate the collection manifest | ||
// see https://github.com/metanorma/annotated-express/issues/134 | ||
public class MetanormaCollectionManifest { | ||
|
||
List<Map.Entry<String,String>> inputOutputFiles; | ||
|
||
Map<String, Object> yamlObj = new LinkedHashMap<>(); | ||
|
||
public MetanormaCollectionManifest(List<Map.Entry<String,String>> inputOutputFiles) { | ||
this.inputOutputFiles = inputOutputFiles; | ||
try { | ||
Yaml yaml = new Yaml(); | ||
InputStream inputStream = Util.getStreamFromResources(stepmod2mn.class.getClassLoader(), "collection_template.yml"); | ||
yamlObj = yaml.load(inputStream); | ||
//System.out.println(yamlObj); | ||
} catch (Exception e) { | ||
e.printStackTrace(System.err); | ||
} | ||
} | ||
|
||
public void generate() throws IOException { | ||
// get repository root folder from 1st file | ||
String repositoryRootFolder = Util.getRepositoryRootFolder(inputOutputFiles.get(0).getValue()); | ||
if (!repositoryRootFolder.isEmpty()) { | ||
int counter = 0; | ||
for (Map.Entry<String, String> entry : inputOutputFiles) { | ||
String resultAdoc = entry.getValue(); | ||
String documentFolder = new File(resultAdoc).getParent(); | ||
File fileResultCollectionYml = Paths.get(documentFolder, "collection.yml").toFile(); | ||
InputStream is = new FileInputStream(fileResultCollectionYml); | ||
Yaml yaml = new Yaml(); | ||
Map<String, Object> yamlDocumentObj = yaml.load(is); | ||
//System.out.println(yamlDocumentObj); | ||
|
||
// manifest: | ||
// - level: document | ||
update_docref(yamlDocumentObj,0, documentFolder); | ||
|
||
// manifest: | ||
// - level: attachments | ||
update_docref(yamlDocumentObj,1, documentFolder); | ||
|
||
counter++; | ||
} | ||
|
||
DumperOptions options = new DumperOptions(); | ||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); | ||
Yaml yaml = new Yaml(options); | ||
PrintWriter writer = new PrintWriter(Paths.get(repositoryRootFolder, "collection.yml").toFile()); | ||
yaml.dump(yamlObj, writer); | ||
} | ||
} | ||
|
||
private void update_docref(Map<String, Object> yamlDocumentObj, int num, String documentFolder) { | ||
ArrayList docref = | ||
((ArrayList<Object>) | ||
((LinkedHashMap <String, Object>) | ||
((ArrayList<Object>) | ||
((LinkedHashMap <String, Object>) | ||
yamlDocumentObj.get("manifest")) | ||
.get("manifest")) | ||
.get(num)) | ||
.get("docref")); | ||
for (int i = 0; i < docref.size(); i++) { | ||
Map <String, Object> items = (LinkedHashMap <String, Object>)docref.get(i); | ||
String fileref = (String)items.get("fileref"); | ||
|
||
String fullPath = Paths.get(documentFolder, fileref).toFile().getAbsolutePath().replace("\\","/"); | ||
items.put("fileref",fullPath); | ||
|
||
// add updated structure into yaml object | ||
ArrayList template_docref = | ||
((ArrayList<Object>) | ||
((LinkedHashMap <String, Object>) | ||
((ArrayList<Object>) | ||
((LinkedHashMap <String, Object>) | ||
yamlObj.get("manifest")) | ||
.get("manifest")) | ||
.get(num)) | ||
.get("docref")); | ||
if (template_docref == null) { | ||
template_docref = new ArrayList<>(); | ||
} | ||
template_docref.add(items); | ||
((LinkedHashMap <String, Object>) | ||
((ArrayList<Object>) | ||
((LinkedHashMap <String, Object>) | ||
yamlObj.get("manifest")) | ||
.get("manifest")) | ||
.get(num)) | ||
.put("docref",template_docref); | ||
} | ||
} | ||
} |
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,37 @@ | ||
package org.metanorma; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
// To generate the cover page | ||
// see https://github.com/metanorma/annotated-express/issues/134 | ||
public class MetanormaCover { | ||
|
||
|
||
List<Map.Entry<String,String>> inputOutputFiles; | ||
|
||
public MetanormaCover(List<Map.Entry<String,String>> inputOutputFiles) { | ||
this.inputOutputFiles = inputOutputFiles; | ||
} | ||
|
||
public void generate() throws IOException { | ||
// get repository root folder from 1st file | ||
String repositoryRootFolder = Util.getRepositoryRootFolder(inputOutputFiles.get(0).getValue()); | ||
|
||
StringBuilder sbCover = new StringBuilder(); | ||
|
||
sbCover.append("<html><head/><body>\n" + | ||
" <h1>{{ doctitle }}</h1>\n" + | ||
" <h2>{{ docnumber }}</h2>\n" + | ||
" <nav>{{ nav_object['children'][0]['docrefs'] }}</nav>\n" + | ||
" </body></html>"); | ||
|
||
BufferedWriter writer = new BufferedWriter(new FileWriter(Paths.get(repositoryRootFolder, "cover.html").toFile())); | ||
writer.write(sbCover.toString()); | ||
writer.close(); | ||
} | ||
} |
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,62 @@ | ||
package org.metanorma; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
// Generate collection.sh | ||
// The script to process each part, and generate the overall collection | ||
// see https://github.com/metanorma/annotated-express/issues/134 | ||
public class ScriptCollection { | ||
|
||
List<Map.Entry<String,String>> inputOutputFiles; | ||
|
||
public ScriptCollection(List<Map.Entry<String,String>> inputOutputFiles) { | ||
this.inputOutputFiles = inputOutputFiles; | ||
} | ||
|
||
public void generate() throws IOException { | ||
// get repository root folder from 1st file | ||
String repositoryRootFolder = Util.getRepositoryRootFolder(inputOutputFiles.get(0).getValue()); | ||
if(!repositoryRootFolder.isEmpty()) { | ||
String documentFolder = new File(inputOutputFiles.get(0).getValue()).getParent(); | ||
String documentRelativeFolder = Util.getRelativePath(repositoryRootFolder, documentFolder); | ||
String documentsFolder = new File(documentFolder).getParent(); | ||
String documentsRelativeFolder = Util.getRelativePath(documentsFolder, repositoryRootFolder); | ||
|
||
StringBuilder sbScript = new StringBuilder(); | ||
sbScript.append("INPUT_REPOS=\""); | ||
List<String> repos = new ArrayList<>(); | ||
for (Map.Entry<String,String> entry: inputOutputFiles) { | ||
File f = new File(entry.getKey()); | ||
repos.add(f.getParentFile().getName()); | ||
} | ||
sbScript.append(repos.toString() | ||
.replace("[", "") | ||
.replace("]", "") | ||
.replace(" ", "") | ||
.replace(","," ")).append("\"\n\n"); | ||
|
||
sbScript.append("for name in $INPUT_REPOS").append("\n") | ||
.append("do").append("\n") | ||
.append(" echo $name").append("\n") | ||
// cd data/resource_docs/$name | ||
.append(" cd ").append(documentsRelativeFolder).append("/$name").append("\n") | ||
.append(" sh ./html_attachments.sh").append("\n") | ||
.append(" bundle exec metanorma -x xml document.adoc").append("\n") | ||
// cd ../../.." | ||
.append(" cd ").append(documentRelativeFolder).append("\n") | ||
.append("done").append("\n") | ||
.append("bundle exec metanorma collection collection.yml -x xml,html,presentation -w iso10303-output -c cover.html").append("\n"); | ||
|
||
BufferedWriter writer = new BufferedWriter(new FileWriter(Paths.get(repositoryRootFolder, "collection.sh").toFile())); | ||
writer.write(sbScript.toString()); | ||
writer.close(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
directives: | ||
- documents-inline | ||
bibdata: | ||
title: | ||
- language: en | ||
content: Industrial automation systems and integration -- Product data representation | ||
and exchange -- Integrated generic resource | ||
docid: | ||
type: iso | ||
id: '10303' | ||
edition: '7' | ||
copyright: | ||
owner: | ||
name: International Standards Organization | ||
abbreviation: ISO | ||
from: '2021' | ||
manifest: | ||
level: collection | ||
title: ISO collection | ||
manifest: | ||
- level: document | ||
title: Document | ||
docref: | ||
- level: attachments | ||
title: Attachments | ||
docref: | ||
|
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