Skip to content

Commit

Permalink
Support new SNL style (#170)
Browse files Browse the repository at this point in the history
* clean up the code

* clean up the code

* clean up the code

* clean up the code

* update for new format

* update for new format

* update for new format

* update for new format

* update for new format

* Update testing-GuideConverter.yml

* Update testing-GuideConverter.yml

* Update testing-GuideConverter.yml

* update for new format

* update for new format

* Update TestMain.java

* update for new format

* update for new format

* update for new format

* update for new format

* update for new format

* update for new format

* update for new format

* update for new format

* update comments

* update codeSnippet

* Update version-history-start-date.properties

* add bash and openFile features

* escape the greater than char

* fix the command and update testing-file.md

* fix the command and update testing-file.md

* comment out code to replace greater and less than characters

* Update version-history-start-date.properties

* update test file

* handle missing gitlab parameter

* display arguments

* display arguments

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* handle special case for mp-metrics

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* update version history

* support html

* update version history

* remove comment in xml file
  • Loading branch information
gkwan-ibm authored Mar 31, 2022
1 parent bc6d785 commit b0a288b
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 373 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/testing-GuideConverter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:

# Any prerequisite steps
- uses: actions/checkout@master
- uses: actions/checkout@main

- name: Checkout guide-getting-started
uses: actions/checkout@v2
Expand All @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: OpenLiberty/guides-common
path: Guides-common
path: guides-common

- uses: actions/setup-java@v1
with:
Expand All @@ -39,3 +39,11 @@ jobs:

- name: Testing with Maven
run: mvn -Dtest=TestMain test

- name: Post tests
if: always()
run: |
echo ===testing-clone-method.md===
cat testing-clone-method.md
echo ===clone.md===
cat clone.md
111 changes: 54 additions & 57 deletions src/main/java/CloudHostedGuideConverter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 IBM Corporation and others.
* Copyright (c) 2020, 2022 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -22,115 +22,112 @@ public static void main(String[] args) throws Exception {

String guideName = args[0];
String branch = args[1];
getMD(guideName, branch);
String gitLab = args.length > 2 ? args[2] : "cloud-hosted-" + guideName;
System.out.println("Converting " + guideName + " on branch " + branch + " to lab " + gitLab);
convertToMD(guideName, branch, gitLab);
System.out.println("Guide converted");
System.out.println("Find markdown in " + guideName + ".md");

}

// Reads the adoc from github, and writes it to an arraylist
public static void getMD(String guideName, String branch) throws IOException {
Scanner s = null;
FileInputStream ip = null;
FileInputStream ips = null;
public static void convertToMD(String guideName, String branch, String gitLab) throws IOException {
Scanner scanner = null;
FileInputStream lrpfis = null;
FileInputStream rpfis = null;

try {
//read adoc file from the open liberty guide
File guide = new File(guideName + "/README.adoc");
// URL url = new URL("https://raw.githubusercontent.com/openliberty/" + guideName + "/" + branch + "/README.adoc");
s = new Scanner(guide);
// ArrayList for whole text file
ArrayList<String> listOfLines = new ArrayList<>();
scanner = new Scanner(guide);
// ArrayList to hold the whole converted markdown format content
ArrayList<String> mdContent = new ArrayList<>();

int m = Functions.addSNLMetadata(mdContent, guideName, gitLab);

String GuideTitle = null;
String GuideDescription = null;
String guideTitle = null;
String guideDescription = null;

Properties prop = new Properties();
Properties props = new Properties();
Properties loopReplacementsProps = new Properties();
Properties replacementsProps = new Properties();

ip = new FileInputStream("loopReplacements.properties");
ips = new FileInputStream("replacements.properties");
lrpfis = new FileInputStream("loopReplacements.properties");
rpfis = new FileInputStream("replacements.properties");

prop.load(ip);
props.load(ips);
loopReplacementsProps.load(lrpfis);
replacementsProps.load(rpfis);

// write each line into the file
while (scanner.hasNextLine()) {
String inputLine = scanner.nextLine() + "\n";

// write each line into the file
while (s.hasNextLine()) {
String inputLine = s.nextLine() + "\n";

// process the guide title and description
if (inputLine.startsWith("= ")) {
GuideTitle = inputLine;
if (!s.nextLine().isEmpty() || !s.nextLine().isBlank()) {
s.nextLine();
s.nextLine();
GuideDescription = s.nextLine();
GuideDescription = GuideDescription.substring(GuideDescription.lastIndexOf(":") + 1, GuideDescription.length());
}
continue;
guideTitle = inputLine;
if (!scanner.nextLine().isEmpty() || !scanner.nextLine().isBlank()) {
scanner.nextLine();
scanner.nextLine();
guideDescription = scanner.nextLine();
guideDescription = guideDescription.substring(guideDescription.lastIndexOf(":") + 1, guideDescription.length());
}

if (inputLine.equals(GuideDescription)) {
inputLine = "";
continue;
}

// skip the Windows and Mac specific content
if (inputLine.startsWith("[.tab_content.windows_section.mac_section]")) {

while (!s.nextLine().startsWith("[.tab_content.linux_section]")) {
while (!scanner.nextLine().startsWith("[.tab_content.linux_section]")) {
continue;
}
}


// skip the Windows specific content
if (inputLine.startsWith("[.tab_content.windows_section]")) {
while (!s.nextLine().startsWith("[.tab_content.mac_section")) {
while (!scanner.nextLine().startsWith("[.tab_content.mac_section")) {
continue;
}
}


// skip the static guide content that marked by ifndef::cloud-hosted
if (inputLine.startsWith("ifndef::cloud-hosted[]")) {
while (!s.nextLine().startsWith("endif::[]")) {
while (!scanner.nextLine().startsWith("endif::[]")) {
continue;
}
}

listOfLines.add(inputLine);
mdContent.add(inputLine);
}


Functions.addPriorStep1(listOfLines, 0, guideName, GuideTitle, GuideDescription);
// Runs the src.main.java.Functions.class
Functions.ConditionsMethod(listOfLines, guideName, branch, prop, props);
// Functions.Next(listOfLines);
Functions.end(listOfLines, guideName, GuideTitle);
Functions.addPriorStep1(mdContent, m, guideName, guideTitle, guideDescription);
Functions.ConditionsMethod(mdContent, guideName, branch, loopReplacementsProps, replacementsProps);
Functions.end(mdContent, guideName, guideTitle);

//String builder to format the arraylist
// Convert the listOfLines to StringBuilder
StringBuilder builder = new StringBuilder();
for (String value : listOfLines) {
for (String value : mdContent) {
if (value.contains("{: codeblock}"))
continue;
builder.append(value);
}

String text = builder.toString();

writeToFile(text, guideName);
// Write the converted content to the file
writeToFile(builder.toString(), guideName);

} catch (IOException ex) {
System.out.println(ex);
} finally {
if (s != null) {
s.close();
ip.close();
ips.close();
if (scanner != null) {
scanner.close();
lrpfis.close();
rpfis.close();
}
}
}

// append to md file
public static void writeToFile(String str, String guideName)
throws IOException {
public static void writeToFile(String str, String guideName) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(guideName + ".md"));
writer.append("\n" + str);
writer.append(str + "\n");
writer.close();
}
}
Loading

0 comments on commit b0a288b

Please sign in to comment.