Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Nov 28, 2022
2 parents 16d3251 + cbb9e40 commit 74cdfa8
Show file tree
Hide file tree
Showing 479 changed files with 10,475 additions and 2,504 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/automate_issue_labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Check for Team label inclusion
run: |
if ${{ contains(join(github.event.issue.labels.*.name, ','), 'Team/') }} == true; then
echo "team_label_added=true" >> $GITHUB_ENV
else
echo "team_label_added=false" >> $GITHUB_ENV
fi
- name: Check for Type label inclusion
if: ${{ !(contains(join(github.event.issue.labels.*.name, ','), 'Type/')) }}
run: gh issue edit $ISSUE --add-label "needTriage"

- name: Check for Compilation related issue
if: ${{ contains(github.event.issue.body, '-> Compilation') && {{ env.team_label_added == false }} }}
if: ${{ contains(github.event.issue.body, '-> Compilation') && !contains(join(github.event.issue.labels.*.name, ','), 'Team/') }}
run: |
gh issue edit $ISSUE --add-label "needTriage"
gh issue edit $ISSUE --add-label "userCategory/Compilation"
Expand All @@ -46,7 +38,7 @@ jobs:
ISSUE: ${{ github.event.issue.number }}

- name: Check for Central related isssue
if: ${{ contains(github.event.issue.body, '-> Central') && {{ env.team_label_added == false }} }}
if: ${{ contains(github.event.issue.body, '-> Central') && !contains(join(github.event.issue.labels.*.name, ','), 'Team/') }}
run: |
gh issue edit $ISSUE --add-label "needTriage"
gh issue edit $ISSUE --add-label "userCategory/Central"
Expand Down Expand Up @@ -142,7 +134,7 @@ jobs:
ISSUE: ${{ github.event.issue.number }}

- name: Check for Editor related issue
if: ${{ contains(github.event.issue.body, '-> Editor') && {{ env.team_label_added == false }} }}
if: ${{ contains(github.event.issue.body, '-> Editor') && !contains(join(github.event.issue.labels.*.name, ','), 'Team/') }}
run: |
gh issue edit $ISSUE --add-label "needTriage"
gh issue edit $ISSUE --add-label "userCategory/Editor"
Expand Down Expand Up @@ -174,7 +166,7 @@ jobs:
ISSUE: ${{ github.event.issue.number }}

- name: Check for other issues
if: ${{ contains(github.event.issue.body, '-> Other Area') && {{ env.team_label_added == false }} }}
if: ${{ contains(github.event.issue.body, '-> Other Area') && !contains(join(github.event.issue.labels.*.name, ','), 'Team/') }}
run: gh issue edit $ISSUE --add-label "needTriage"
env:
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public BLock() {
public synchronized boolean lock(Strand strand) {
if (isLockFree() || lockedBySameContext(strand)) {
this.current.offerLast(strand);
strand.acquiredLockCount++;
return true;
}

Expand All @@ -54,7 +55,8 @@ public synchronized boolean lock(Strand strand) {

public synchronized void unlock() {
//current cannot be empty as unlock cannot be called without lock being called first.
this.current.removeLast();
Strand removedStrand = this.current.removeLast();
removedStrand.acquiredLockCount--;
if (!waitingForLock.isEmpty()) {
Strand strand = this.waitingForLock.removeFirst();
strand.scheduler.unblockStrand(strand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ public BLock getLockFromMap(String lockName) {
});
}

public void panicIfInLock(String lockName, Strand strand) {
for (BLock lock : globalLockMap.values()) {
if (lock.isLockFree()) {
continue;
}
if (lock.lockedBySameContext(strand)) {
throw ErrorCreator.createError(BallerinaErrorReasons.ASYNC_CALL_INSIDE_LOCK);
}
public void panicIfInLock(Strand strand) {
if (strand.acquiredLockCount > 0) {
throw ErrorCreator.createError(BallerinaErrorReasons.ASYNC_CALL_INSIDE_LOCK);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class Strand {
public Set<ChannelDetails> channelDetails;
public Set<SchedulerItem> dependants;
public boolean cancel;
public int acquiredLockCount;

SchedulerItem schedulerItem;
List<WaitContext> waitingContexts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.ballerinalang.docgen.docs.BallerinaDocGenerator;
import picocli.CommandLine;

import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -123,7 +122,7 @@ public void execute() {
BalaProject balaProject = BalaProject.loadProject(defaultBuilder, balaPath);
try {
BallerinaDocGenerator.generateAPIDocs(balaProject, this.projectPath.toString(), false);
} catch (IOException e) {
} catch (Exception e) {
CommandUtil.printError(this.errStream, e.getMessage(), null, false);
CommandUtil.exitError(this.exitWhenFinish);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void execute(Project project) {
BallerinaDocGenerator.generateAPIDocs(project, outputPath.toString(), false);
this.out.println("Saved to: " + sourceRootPath.relativize(outputPath).toString());

} catch (IOException e) {
} catch (Exception e) {
throw createLauncherException("Unable to generate API Documentation.", e.getCause());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
import org.wso2.ballerinalang.util.Lists;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -180,6 +182,13 @@ public void execute(Project project) {
}

TestUtils.writeToTestSuiteJson(testSuiteMap, testsCachePath);
try {
Path nativeConfigPath = target.getNativeConfigPath();
createReflectConfig(nativeConfigPath, project.currentPackage(), testSuiteMap);
} catch (IOException e) {
throw createLauncherException("error while generating the necessary graalvm reflection config", e);
}


if (hasTests) {
int testResult = 1;
Expand Down Expand Up @@ -291,25 +300,33 @@ private int runTestSuiteWithNativeImage(Package currentPackage, JBallerinaBacken
}

List<String> cmdArgs = new ArrayList<>();
List<String> nativeArgs = new ArrayList<>();
cmdArgs.add(nativeImageCommand);

Path nativeConfigPath = target.getNativeConfigPath(); // <abs>target/cache/test_cache/native-config
Path nativeTargetPath = target.getNativePath(); // <abs>target/native

// Create Configs
createReflectConfig(nativeConfigPath, currentPackage);

// Run native-image command with generated configs
cmdArgs.addAll(Lists.of("-cp", classPath));
cmdArgs.add(TesterinaConstants.TESTERINA_LAUNCHER_CLASS_NAME);
cmdArgs.add("@" + (nativeConfigPath.resolve("native-image-args.txt")));
nativeArgs.addAll(Lists.of("-cp", classPath));


// set name and path
cmdArgs.add("-H:Name=" + packageName);
cmdArgs.add("-H:Path=" + nativeTargetPath);
nativeArgs.add("-H:Name=" + packageName);
nativeArgs.add("-H:Path=" + nativeTargetPath);

// native-image configs
cmdArgs.add("-H:ReflectionConfigurationFiles=" + nativeConfigPath.resolve("reflect-config.json"));
cmdArgs.add("--no-fallback");
nativeArgs.add("-H:ReflectionConfigurationFiles=" + nativeConfigPath.resolve("reflect-config.json"));
nativeArgs.add("--no-fallback");

try (FileWriter nativeArgumentWriter = new FileWriter(nativeConfigPath.resolve("native-image-args.txt")
.toString(), Charset.defaultCharset())) {
nativeArgumentWriter.write(String.join(" ", nativeArgs));
nativeArgumentWriter.flush();
} catch (IOException e) {
throw createLauncherException("error while generating the necessary graalvm argument file", e);
}

ProcessBuilder builder = new ProcessBuilder();
builder.command(cmdArgs.toArray(new String[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import com.google.gson.GsonBuilder;
import io.ballerina.projects.Module;
import io.ballerina.projects.Package;
import io.ballerina.projects.util.ProjectUtils;
import io.ballerina.runtime.internal.util.RuntimeUtils;
import org.ballerinalang.test.runtime.entity.TestSuite;

import java.io.FileWriter;
import java.io.IOException;
Expand All @@ -31,6 +33,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static io.ballerina.identifier.Utils.encodeNonFunctionIdentifier;
import static org.ballerinalang.test.runtime.util.TesterinaConstants.ANON_ORG;
Expand All @@ -46,7 +49,8 @@ public class NativeUtils {
private static final String MODULE_CONFIGURATION_MAPPER = "$configurationMapper";
private static final String MODULE_EXECUTE_GENERATED = "tests.test_execute-generated_";

public static void createReflectConfig(Path nativeConfigPath, Package currentPackage) throws IOException {
public static void createReflectConfig(Path nativeConfigPath, Package currentPackage,
Map<String, TestSuite> testSuiteMap) throws IOException {
String org = currentPackage.packageOrg().toString();
String version = currentPackage.packageVersion().toString();

Expand All @@ -57,84 +61,86 @@ public static void createReflectConfig(Path nativeConfigPath, Package currentPac

for (Module module : currentPackage.modules()) {
String name = module.moduleName().toString();
String moduleName = ProjectUtils.getJarFileName(module);

ReflectConfigClass testInitClass = new ReflectConfigClass(getQualifiedClassName(org, name, version,
ReflectConfigClass testInitRefConfClz = new ReflectConfigClass(getQualifiedClassName(org, name, version,
MODULE_INIT_CLASS_NAME));

testInitClass.addReflectConfigClassMethod(
testInitRefConfClz.addReflectConfigClassMethod(
new ReflectConfigClassMethod(
"$moduleInit",
new String[]{"io.ballerina.runtime.internal.scheduling.Strand"}
)
);

testInitClass.addReflectConfigClassMethod(
testInitRefConfClz.addReflectConfigClassMethod(
new ReflectConfigClassMethod(
"$moduleStart",
new String[]{"io.ballerina.runtime.internal.scheduling.Strand"}
)
);

testInitClass.addReflectConfigClassMethod(
testInitRefConfClz.addReflectConfigClassMethod(
new ReflectConfigClassMethod(
"$moduleStop",
new String[]{"io.ballerina.runtime.internal.scheduling.RuntimeRegistry"}
)
);

ReflectConfigClass testConfigurationMapper = new ReflectConfigClass(getQualifiedClassName(org, name,
version, MODULE_CONFIGURATION_MAPPER));
ReflectConfigClass testConfigurationMapperRefConfClz = new ReflectConfigClass(
getQualifiedClassName(org, name, version, MODULE_CONFIGURATION_MAPPER));

testConfigurationMapper.addReflectConfigClassMethod(
testConfigurationMapperRefConfClz.addReflectConfigClassMethod(
new ReflectConfigClassMethod(
"$configureInit",
new String[]{"java.lang.String[]", "java.nio.file.Path[]", "java.lang.String"}
)
);
ReflectConfigClass testTestExecuteGeneratedRefConfClz = new ReflectConfigClass("");
if (testSuiteMap.containsKey(moduleName)) {
testTestExecuteGeneratedRefConfClz = new ReflectConfigClass(testSuiteMap.get(moduleName)
.getTestUtilityFunctions().get("__execute__"));
testTestExecuteGeneratedRefConfClz.addReflectConfigClassMethod(
new ReflectConfigClassMethod(
"__execute__",
new String[]{
"io.ballerina.runtime.internal.scheduling.Strand",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString"
}
)
);
}

ReflectConfigClass testTestExecuteGenerated = new ReflectConfigClass(getQualifiedClassName(org, name,
version, MODULE_EXECUTE_GENERATED + tally));

testTestExecuteGenerated.addReflectConfigClassMethod(
new ReflectConfigClassMethod(
"__execute__",
new String[]{
"io.ballerina.runtime.internal.scheduling.Strand",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString"
}
)
);

ReflectConfigClass testNameZeroName =
ReflectConfigClass testNameZeroNameRefConfClz =
new ReflectConfigClass(getQualifiedClassName(org, name, version, name));
testNameZeroName.setQueryAllDeclaredMethods(true);
testNameZeroNameRefConfClz.setQueryAllDeclaredMethods(true);

// Add all class values to the array
classList.add(testInitClass);
classList.add(testConfigurationMapper);
classList.add(testTestExecuteGenerated);
classList.add(testInitRefConfClz);
classList.add(testConfigurationMapperRefConfClz);
classList.add(testTestExecuteGeneratedRefConfClz);

classList.add(testNameZeroName);
classList.add(testNameZeroNameRefConfClz);

// Increment tally to cover executable_<tally> class
tally += 1;
}

ReflectConfigClass runtimeEntityTestSuite = new ReflectConfigClass("org.ballerinalang.test.runtime.entity" +
".TestSuite");
runtimeEntityTestSuite.setAllDeclaredFields(true);
runtimeEntityTestSuite.setUnsafeAllocated(true);
ReflectConfigClass runtimeEntityTestSuiteRefConfClz = new ReflectConfigClass(
"org.ballerinalang.test.runtime.entity" + ".TestSuite");
runtimeEntityTestSuiteRefConfClz.setAllDeclaredFields(true);
runtimeEntityTestSuiteRefConfClz.setUnsafeAllocated(true);

classList.add(runtimeEntityTestSuite);
classList.add(runtimeEntityTestSuiteRefConfClz);

// Write the array to the config file
try (Writer writer = new FileWriter(nativeConfigPath.resolve("reflect-config.json").toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public void testNewCommand() throws IOException {

Assert.assertTrue(Files.exists(packageDir.resolve("main.bal")));
Assert.assertFalse(Files.exists(packageDir.resolve(ProjectConstants.PACKAGE_MD_FILE_NAME)));
Assert.assertTrue(Files.exists(packageDir.resolve(ProjectConstants.GITIGNORE_FILE_NAME)));
String gitignoreContent = Files.readString(
packageDir.resolve(ProjectConstants.GITIGNORE_FILE_NAME), StandardCharsets.UTF_8);
String expectedGitignoreContent = "target\n" +
"Config.toml\n";
Assert.assertEquals(gitignoreContent.trim(), expectedGitignoreContent.trim());
Assert.assertTrue(readOutput().contains("Created new package"));

Assert.assertTrue(Files.exists(packageDir.resolve(".devcontainer.json")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ public void visit(BLangTernaryExpr ternaryExpr) {
@Override
public void visit(BLangWaitExpr awaitExpr) {
lookupNodes(awaitExpr.exprList);
setEnclosingNode(awaitExpr, awaitExpr.pos);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import io.ballerina.compiler.syntax.tree.SimpleNameReferenceNode;
import io.ballerina.compiler.syntax.tree.SpecificFieldNode;
import io.ballerina.compiler.syntax.tree.SpreadFieldNode;
import io.ballerina.compiler.syntax.tree.StartActionNode;
import io.ballerina.compiler.syntax.tree.TableConstructorExpressionNode;
import io.ballerina.compiler.syntax.tree.TemplateExpressionNode;
import io.ballerina.compiler.syntax.tree.Token;
Expand All @@ -89,6 +90,7 @@
import io.ballerina.compiler.syntax.tree.TypeofExpressionNode;
import io.ballerina.compiler.syntax.tree.UnaryExpressionNode;
import io.ballerina.compiler.syntax.tree.VariableDeclarationNode;
import io.ballerina.compiler.syntax.tree.WaitActionNode;
import io.ballerina.compiler.syntax.tree.WildcardBindingPatternNode;
import io.ballerina.compiler.syntax.tree.XMLFilterExpressionNode;
import io.ballerina.compiler.syntax.tree.XMLNamespaceDeclarationNode;
Expand Down Expand Up @@ -246,6 +248,16 @@ public Optional<Location> transform(SimpleNameReferenceNode simpleNameReferenceN
return simpleNameReferenceNode.name().apply(this);
}

@Override
public Optional<Location> transform(StartActionNode startActionNode) {
return Optional.of(startActionNode.location());
}

@Override
public Optional<Location> transform(WaitActionNode waitActionNode) {
return Optional.of(waitActionNode.location());
}

@Override
public Optional<Location> transform(TypeDefinitionNode typeDefinitionNode) {
return typeDefinitionNode.typeName().apply(this);
Expand Down
Loading

0 comments on commit 74cdfa8

Please sign in to comment.