Skip to content

Commit

Permalink
Merge branch 'master' into mac-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Suganya committed Feb 15, 2021
2 parents fd4d9cd + b9ff225 commit 12ba92f
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 29 deletions.
3 changes: 2 additions & 1 deletion ballerinaByExample/templates/example-temp.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
layout: ballerina-example-page
title: {{.Name}}
description: Ballerina by Example is a hands-on introduction to Ballerina using annotated example programs. Check out the first example or browse the full list below.
description: {{.MetaDescription}}
keywords: {{.MetaKeywords}}
permalink: {{if .IsLatest}}/learn/by-example/{{.Id}}{{else}}/{{.Version}}/learn/by-example/{{.Id}}{{end}}
redirect_from:
- /{{.RedirectVersion}}/learn/by-example/{{.Id}}
Expand Down
33 changes: 31 additions & 2 deletions ballerinaByExample/tools/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var balFileExtn = ".bal"
var protoFilePathExtn = ".proto"
var yamlFileExtn = ".yaml"
var descriptionFileExtn = ".description"
var metatagsFileExtn = ".metatags"
var serverOutputPrefix = ".server"
var clientOutputPrefix = ".client"

Expand Down Expand Up @@ -167,6 +168,8 @@ type Example struct {
GoCode, GoCodeHash, UrlHash string
Segs [][]*Seg
Descs string
MetaDescription string
MetaKeywords string
NextExample *Example
PrevExample *Example
FullCode string
Expand Down Expand Up @@ -235,6 +238,22 @@ func parseHashFile(sourcePath string) (string, string) {
return lines[0], lines[1]
}

func parseMetatagsFile(sourcePath string) map[string]string {
lines := readLines(sourcePath)
tagMap := make(map[string]string)
for _, line := range lines {
line = strings.TrimSpace(line);
if len(line) == 0 {
continue;
}
i := strings.Index(line, ":")
key := strings.TrimSpace(line[:i])
value := strings.TrimSpace(line[i+1:])
tagMap[key] = value;
}
return tagMap
}

func generatePlaygroundLink(example Example) string {
fileName := strings.ReplaceAll(example.Id, "-", "_") + ".bal";
req := &PlaygroundRequest { Content: example.GoCode, Description: example.Name, FileName: fileName };
Expand Down Expand Up @@ -418,13 +437,20 @@ func parseExamples(categories []BBECategory) []*Example {
continue
}

metatagsFilePath := fileDirPath + exampleBaseFilePattern + metatagsFileExtn
if !isFileExist(metatagsFilePath) {
fmt.Fprintln(os.Stderr, "\t[WARN] Skipping bbe : "+exampleName+". "+metatagsFilePath+" is not found")
continue
}

balFiles := getAllBalFiles(fileDirPath);
if len(balFiles) == 0 {
fmt.Fprintln(os.Stderr, "\t[WARN] Skipping bbe : " + exampleName + ". No *.bal files are found")
continue
}

rearrangedPaths = appendFilePath(rearrangedPaths, descFilePath)
rearrangedPaths = appendFilePath(rearrangedPaths, metatagsFilePath)
for _, balFilePath := range balFiles {
var extension = filepath.Ext(balFilePath)
var currentSample = balFilePath[0:len(balFilePath)-len(extension)]
Expand Down Expand Up @@ -513,8 +539,11 @@ func prepareExample(sourcePaths []string, example Example, currentExamplesList [
}
}()
for _, sourcePath := range sourcePaths {

if strings.HasSuffix(sourcePath, ".hash") {
if strings.HasSuffix(sourcePath, metatagsFileExtn) {
metaTags := parseMetatagsFile(sourcePath)
example.MetaDescription = metaTags["description"];
example.MetaKeywords = metaTags["keywords"];
} else if strings.HasSuffix(sourcePath, ".hash") {
example.GoCodeHash, example.UrlHash = parseHashFile(sourcePath)
} else {
sourceSegs, filecontents, _ := parseAndRenderSegs(sourcePath)
Expand Down
5 changes: 3 additions & 2 deletions test-scripts/ballerina-test-automation/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ballerinaVersion=swan-lake-preview8
ballerinaVersion=swan-lake-alpha1
specVersion=v2020-12-17
toolVersion=0.8.10
versionDisplayText=Alpha 1
toolVersion=0.8.14
latestToolVersion=0.8.14
latestPatchVersion=1.2.13
latestPatchSpecVersion=2020R1
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test {
options.suites('src/test/resources/testng.xml')
systemProperty 'BALLERINA_VERSION', project.properties['ballerinaVersion']
systemProperty 'SPEC_VERSION', project.properties['specVersion']
systemProperty 'VERSION_DISPLAY_TEXT', project.properties['versionDisplayText']
systemProperty 'TOOL_VERSION', project.properties['toolVersion']
systemProperty 'LATEST_TOOL_VERSION', project.properties['latestToolVersion']
systemProperty 'LATEST_PATCH_VERSION', project.properties['latestPatchVersion']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testSmoke(Executor executor) {
executor.transferArtifacts();
executor.install();

TestUtils.testInstallation(executor, version, specVersion, toolVersion);
TestUtils.testInstallation(executor, version, specVersion, toolVersion, System.getProperty("VERSION_DISPLAY_TEXT"));

executor.uninstall();
executor.cleanArtifacts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testProject(Executor executor) {
executor.transferArtifacts();
executor.install();

TestUtils.testInstallation(executor, version, specVersion, toolVersion);
TestUtils.testInstallation(executor, version, specVersion, toolVersion, System.getProperty("VERSION_DISPLAY_TEXT"));
TestUtils.testProject(executor, previousVersion, previousSpecVersion, toolVersion);

executor.uninstall();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,27 @@
public class TestUtils {
private static final String OS = System.getProperty("os.name").toLowerCase(Locale.getDefault());
private static final String SWAN_LAKE_KEYWORD = "swan-lake";
private static final String VERSION_DISPLAY_TEXT = System.getProperty("VERSION_DISPLAY_TEXT");


public static String getVersionOutput(String jBallerinaVersion, String specVersion, String toolVersion) {
/**
* Get version output for version command.
* @param jBallerinaVersion Installed jBallerina version
* @param specVersion Installed language specification
* @param toolVersion Installed tool version
* @param versionDisplayText display text for installed jBallerina version
*
* @return version output
*/
public static String getVersionOutput(String jBallerinaVersion, String specVersion, String toolVersion,
String versionDisplayText) {
String toolText = TestUtils.isOldToolVersion(toolVersion) ? "Ballerina tool" : "Update Tool";
if (jBallerinaVersion.contains(TestUtils.SWAN_LAKE_KEYWORD)) {
String[] versionParts = jBallerinaVersion.split("-");
return "Ballerina Swan Lake Preview " + versionParts[versionParts.length - 1].replace("preview", "") + "\n"
+ "Language specification " + specVersion + "\n" + toolText + " " + toolVersion + "\n";
return "Ballerina Swan Lake " + versionDisplayText + "\n" + "Language specification " + specVersion +
"\n" + toolText + " " + toolVersion + "\n";
}

String ballerinaReference = isSupportedRelease(jBallerinaVersion) ? "jBallerina" : "Ballerina";
return ballerinaReference + " " + jBallerinaVersion + "\n" +
"Language specification " + specVersion + "\n" +
return ballerinaReference + " " + jBallerinaVersion + "\n" + "Language specification " + specVersion + "\n" +
toolText + " " + toolVersion + "\n";
}

Expand All @@ -63,7 +71,7 @@ public static void testDistCommands(Executor executor, String version, String sp
String previousVersion, String previousSpecVersion,
String previousVersionsLatestPatch, String latestToolVersion) {
//Test installation
TestUtils.testInstallation(executor, version, specVersion, toolVersion);
TestUtils.testInstallation(executor, version, specVersion, toolVersion, VERSION_DISPLAY_TEXT);

//Test `ballerina dist list`
String actualOutput = executor.executeCommand("dist list", false, toolVersion);
Expand All @@ -76,7 +84,7 @@ public static void testDistCommands(Executor executor, String version, String sp
executor.executeCommand("dist pull "
+ TestUtils.getSupportedVersion(toolVersion, previousVersion), true, toolVersion);

TestUtils.testInstallation(executor, previousVersion, previousSpecVersion, toolVersion);
TestUtils.testInstallation(executor, previousVersion, previousSpecVersion, toolVersion, previousVersion);

//Test Update notification message
if (isSupportedRelease(previousVersion)) {
Expand All @@ -92,7 +100,7 @@ public static void testDistCommands(Executor executor, String version, String sp
toolVersion);

//Verify the the installation
TestUtils.testInstallation(executor, version, specVersion, toolVersion);
TestUtils.testInstallation(executor, version, specVersion, toolVersion, VERSION_DISPLAY_TEXT);

//Test `ballerina dist update`
executor.executeCommand("dist use " + TestUtils.getSupportedVersion(toolVersion, previousVersion),
Expand All @@ -105,7 +113,8 @@ public static void testDistCommands(Executor executor, String version, String sp
executor.executeCommand("update", true, toolVersion);

executor.executeCommand("dist update", true, latestToolVersion);
TestUtils.testInstallation(executor, previousVersionsLatestPatch, previousSpecVersion, latestToolVersion);
TestUtils.testInstallation(executor, previousVersionsLatestPatch, previousSpecVersion, latestToolVersion,
previousVersionsLatestPatch);

//Try `ballerina dist remove`
executor.executeCommand("dist remove " + TestUtils.getSupportedVersion(toolVersion, previousVersion),
Expand All @@ -120,9 +129,10 @@ public static void testDistCommands(Executor executor, String version, String sp
* @param specVersion Installed language specification
* @param toolVersion Installed tool version
*/
public static void testInstallation(Executor executor, String version, String specVersion, String toolVersion) {
public static void testInstallation(Executor executor, String version, String specVersion, String toolVersion,
String versionDisplayText) {
Assert.assertEquals(executor.executeCommand("-v", false, toolVersion),
TestUtils.getVersionOutput(version, specVersion, toolVersion));
TestUtils.getVersionOutput(version, specVersion, toolVersion, versionDisplayText));
}

/**
Expand All @@ -139,7 +149,7 @@ public static void testDependencyFetch(Executor executor, String toolVersion) {
Assert.assertTrue(output.contains("Fetching the dependencies for 'slp1' from the remote server..."));
Assert.assertTrue(output.contains("jdk8u202-b08-jre"));
Assert.assertTrue(output.contains("'slp1' successfully set as the active distribution"));
TestUtils.testInstallation(executor, "swan-lake-preview1", "v2020-06-18", toolVersion);
TestUtils.testInstallation(executor, "swan-lake-preview1", "v2020-06-18", toolVersion, "Preview 1");
String cmdName = Utils.getCommandName(toolVersion);
Path userDir = Paths.get(System.getProperty("user.dir"));
executor.executeCommand("new project1 && cd project1 && " + cmdName + "add module1 && " +
Expand All @@ -154,7 +164,7 @@ public static void testDependencyFetch(Executor executor, String toolVersion) {
Assert.assertTrue(output.contains("Fetching the dependencies for 'slp7' from the remote server..."));
Assert.assertTrue(output.contains("Downloading jdk-11.0.8+10-jre"));
Assert.assertTrue(output.contains("'slp7' successfully set as the active distribution"));
TestUtils.testInstallation(executor, "swan-lake-preview7", "v2020-09-22", toolVersion);
TestUtils.testInstallation(executor, "swan-lake-preview7", "v2020-09-22", toolVersion, "Preview 7");

executor.executeCommand("new project2 && cd project2 &&" + cmdName + "add module1 && " +
cmdName + "build", false, toolVersion);
Expand Down Expand Up @@ -220,7 +230,7 @@ public static void testProject(Executor executor, String previousVersion, String
Assert.assertTrue(Files.exists(projectPath.resolve("target/bin/sampleProject1.jar")));

executor.executeCommand("dist pull " + previousVersion, true, toolVersion);
testInstallation(executor, previousVersion, previousSpecVersion, toolVersion);
testInstallation(executor, previousVersion, previousSpecVersion, toolVersion, previousVersion);
executor.executeCommand("new sampleProject2 && cd sampleProject2 && " + cmdName + "add module1 && " +
cmdName + "build module1", false, toolVersion);
projectPath = userDir.resolve("sampleProject2");
Expand All @@ -234,6 +244,9 @@ private static String getSupportedVersion(String toolVersion, String version) {
return "jballerina-" + version;
}
if (version.contains(TestUtils.SWAN_LAKE_KEYWORD)) {
if (version.contains("alpha") || version.contains("beta")) {
return "sl" + version.split("-")[2];
}
return "slp" + version.replace("swan-lake-preview", "");
}
return version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public void checkServerTrusted(java.security.cert.X509Certificate[] certs, Strin
}
};

public static final String DISTRIBUTION_LOCATION =
"http://dist-dev.ballerina.io/downloads/";
public static final String DISTRIBUTION_LOCATION ="http://dist-dev.ballerina.io/downloads/";

public static void downloadFile(String version, String installerName) {
try {
Expand Down Expand Up @@ -108,7 +107,6 @@ public static String executeCommand(String command) {
file.createNewFile();
file.setExecutable(true);
PrintWriter writer = new PrintWriter(file.getPath(), "UTF-8");
System.out.println(command);
writer.println(command);
writer.close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test {
options.suites('src/test/resources/testng.xml')
systemProperty 'BALLERINA_VERSION', project.properties['ballerinaVersion']
systemProperty 'SPEC_VERSION', project.properties['specVersion']
systemProperty 'VERSION_DISPLAY_TEXT', project.properties['versionDisplayText']
systemProperty 'TOOL_VERSION', project.properties['toolVersion']
systemProperty 'LATEST_TOOL_VERSION', project.properties['latestToolVersion']
systemProperty 'LATEST_PATCH_VERSION', project.properties['latestPatchVersion']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testFetchDependency(Executor executor) {
executor.transferArtifacts();
executor.install();

TestUtils.testInstallation(executor, version, specVersion, toolVersion);
TestUtils.testInstallation(executor, version, specVersion, toolVersion, "1.2.8");
TestUtils.testDependencyFetch(executor, toolVersion);

executor.uninstall();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class UpdateToolTest {
String specVersion = System.getProperty("SPEC_VERSION");
String toolVersion = System.getProperty("TOOL_VERSION");
String latestToolVersion = System.getProperty("LATEST_TOOL_VERSION");
String VERSION_DISPLAY_TEXT = System.getProperty("VERSION_DISPLAY_TEXT");

String previousVersion = "1.2.0";
String previousSpecVersion = "2020R1";
Expand All @@ -47,11 +48,11 @@ public void testUpdateTool(Executor executor) {
//Test dist list
TestUtils.verifyDistList(executor, toolVersion);
//Test installation
TestUtils.testInstallation(executor, version, specVersion, toolVersion);
TestUtils.testInstallation(executor, version, specVersion, toolVersion, VERSION_DISPLAY_TEXT);

//Test `ballerina update`
executor.executeCommand("update", true, toolVersion);
TestUtils.testInstallation(executor, version, specVersion, latestToolVersion);
TestUtils.testInstallation(executor, version, specVersion, latestToolVersion, VERSION_DISPLAY_TEXT);

//Execute all ballerina dist commands once updated
TestUtils.testDistCommands(executor, version, specVersion, latestToolVersion, previousVersion,
Expand Down

0 comments on commit 12ba92f

Please sign in to comment.