Skip to content

Commit

Permalink
Merge branch 'master' into issues/42610
Browse files Browse the repository at this point in the history
# Conflicts:
#	misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordConverter.java
  • Loading branch information
Shadow-Devil committed Oct 23, 2024
2 parents 7d50f74 + 0fee0db commit 3cdcde9
Show file tree
Hide file tree
Showing 59 changed files with 307 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ public static boolean isJSONObject(Object json) {

MapValueImpl<BString, Object> map = new MapValueImpl<>(mapType);
Type mapConstraint = TypeUtils.getImpliedType(mapType.getConstrainedType());
if (mapConstraint == null || mapConstraint.getTag() == TypeTags.ANY_TAG ||
mapConstraint.getTag() == TypeTags.JSON_TAG) {
if (mapConstraint.getTag() == TypeTags.ANY_TAG || mapConstraint.getTag() == TypeTags.JSON_TAG) {
((MapValueImpl<BString, Object>) json).forEach(map::put);

return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ public static long remainder(long numerator, long denominator) {
try {
return numerator % denominator;
} catch (ArithmeticException e) {
if (denominator == 0) {
throw ErrorCreator.createError(ErrorReasons.DIVISION_BY_ZERO_ERROR, DIVIDE_BY_ZERO_ERROR);
} else {
throw ErrorCreator.createError(ErrorReasons.ARITHMETIC_OPERATION_ERROR,
StringUtils.fromString(e.getMessage()));
}
throw ErrorCreator.createError(ErrorReasons.DIVISION_BY_ZERO_ERROR, DIVIDE_BY_ZERO_ERROR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@

import io.ballerina.runtime.api.TypeTags;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.types.Field;
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.internal.types.BField;
import io.ballerina.runtime.internal.types.BStructureType;
import io.ballerina.runtime.internal.values.DecimalValue;
import io.ballerina.runtime.internal.values.IteratorValue;
import io.ballerina.runtime.internal.values.MapValue;
import io.ballerina.runtime.internal.values.MapValueImpl;
import io.ballerina.runtime.internal.values.TableValueImpl;
import io.ballerina.runtime.internal.values.TableValue;
import io.ballerina.runtime.internal.values.TupleValueImpl;
import org.apache.axiom.om.ds.AbstractPushOMDataSource;

import java.util.Collection;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

Expand All @@ -51,11 +54,11 @@ public class TableOmDataSource extends AbstractPushOMDataSource {
private static final String DEFAULT_ROOT_WRAPPER = "results";
private static final String DEFAULT_ROW_WRAPPER = "result";

private final TableValueImpl<?, ?> table;
private final TableValue<?, ?> table;
private final String rootWrapper;
private final String rowWrapper;

public TableOmDataSource(TableValueImpl<?, ?> table, String rootWrapper, String rowWrapper) {
public TableOmDataSource(TableValue<?, ?> table, String rootWrapper, String rowWrapper) {
this.table = table;
this.rootWrapper = rootWrapper != null ? rootWrapper : DEFAULT_ROOT_WRAPPER;
this.rowWrapper = rowWrapper != null ? rowWrapper : DEFAULT_ROW_WRAPPER;
Expand All @@ -67,32 +70,26 @@ public void serialize(XMLStreamWriter xmlStreamWriter) throws XMLStreamException
IteratorValue<?> itr = this.table.getIterator();

while (itr.hasNext()) {
table.getIterator().next();
xmlStreamWriter.writeStartElement("", this.rowWrapper, "");
TupleValueImpl tupleValue = (TupleValueImpl) itr.next();
MapValueImpl<?, ?> record = ((MapValueImpl<?, ?>) tupleValue.get(0));
MapValue<?, ?> record = ((MapValue<?, ?>) tupleValue.get(0));

BStructureType structType = (BStructureType) record.getType();
BField[] structFields = null;
if (structType != null) {
structFields = structType.getFields().values().toArray(new BField[0]);
}
for (int i = 0; i < structFields.length; i++) {
BField internalStructField = structFields[i];
int type = TypeUtils.getImpliedType(internalStructField.getFieldType()).getTag();
String fieldName = internalStructField.getFieldName();

writeElement(record, xmlStreamWriter, fieldName, type, i, structFields);
for (Field internalStructField : structType.getFields().values()) {
writeElement(record, xmlStreamWriter, internalStructField);
}
}
xmlStreamWriter.writeEndElement();
}
xmlStreamWriter.writeEndElement();
xmlStreamWriter.flush();
}

private void writeElement(MapValueImpl<?, ?> record,
XMLStreamWriter xmlStreamWriter, String name, int type, int index,
BField[] structFields) throws XMLStreamException {
private void writeElement(MapValue<?, ?> record, XMLStreamWriter xmlStreamWriter,
Field structField) throws XMLStreamException {
int type = TypeUtils.getImpliedType(structField.getFieldType()).getTag();
String name = structField.getFieldName();
boolean isArray = false;
xmlStreamWriter.writeStartElement("", name, "");
BString key = StringUtils.fromString(name);
Expand Down Expand Up @@ -122,13 +119,8 @@ private void writeElement(MapValueImpl<?, ?> record,
case TypeTags.OBJECT_TYPE_TAG:
case TypeTags.RECORD_TYPE_TAG:
isArray = true;
if (structFields == null) {
BArray structData = record.getArrayValue(key);
processArray(xmlStreamWriter, structData);
} else {
BMap<?, ?> structData = record.getMapValue(key);
processStruct(xmlStreamWriter, structData, structFields, index);
}
BMap<?, ?> structData = record.getMapValue(key);
processStruct(xmlStreamWriter, structData, structField);
break;
default:
value = String.valueOf(record.getStringValue(key));
Expand All @@ -146,42 +138,36 @@ private void writeElement(MapValueImpl<?, ?> record,
}

private void processArray(XMLStreamWriter xmlStreamWriter, BArray array) throws XMLStreamException {
if (array != null) {
for (int i = 0; i < array.size(); i++) {
xmlStreamWriter.writeStartElement("", ARRAY_ELEMENT_NAME, "");
xmlStreamWriter.writeCharacters(String.valueOf(array.get(i)));
xmlStreamWriter.writeEndElement();
}
if (array == null) {
return;
}
for (int i = 0; i < array.size(); i++) {
xmlStreamWriter.writeStartElement("", ARRAY_ELEMENT_NAME, "");
xmlStreamWriter.writeCharacters(String.valueOf(array.get(i)));
xmlStreamWriter.writeEndElement();
}
}

private void processStruct(XMLStreamWriter xmlStreamWriter, BMap<?, ?> structData,
BField[] structFields, int index) throws XMLStreamException {
boolean structError = true;
Type internalType = TypeUtils.getImpliedType(structFields[index].getFieldType());
if (internalType.getTag() == TypeTags.OBJECT_TYPE_TAG
|| internalType.getTag() == TypeTags.RECORD_TYPE_TAG) {
BField[] internalStructFields = ((BStructureType) internalType).getFields()
.values().toArray(new BField[0]);
if (internalStructFields != null) {
for (int i = 0; i < internalStructFields.length; i++) {
BString internalKeyName = StringUtils.fromString(internalStructFields[i].getFieldName());
Object val = structData.get(internalKeyName);
xmlStreamWriter.writeStartElement("", internalStructFields[i].getFieldName(), "");
if (val instanceof MapValueImpl<?, ?> mapValue) {
processStruct(xmlStreamWriter, mapValue, internalStructFields, i);
} else {
xmlStreamWriter.writeCharacters(val.toString());
}
xmlStreamWriter.writeEndElement();
}
structError = false;
}
}
if (structError) {
private void processStruct(XMLStreamWriter xmlStreamWriter, BMap<?, ?> structData, Field structField)
throws XMLStreamException {
Type internalType = TypeUtils.getImpliedType(structField.getFieldType());
if (internalType.getTag() != TypeTags.OBJECT_TYPE_TAG && internalType.getTag() != TypeTags.RECORD_TYPE_TAG) {
throw ErrorCreator.createError(StringUtils.fromString(
"error in constructing the xml element from struct type data"));
}

Collection<Field> internalStructFields = ((BStructureType) internalType).getFields().values();
for (Field internalStructField : internalStructFields) {
BString internalKeyName = StringUtils.fromString(internalStructField.getFieldName());
Object val = structData.get(internalKeyName);
xmlStreamWriter.writeStartElement("", internalStructField.getFieldName(), "");
if (val instanceof MapValueImpl<?, ?> mapValue) {
processStruct(xmlStreamWriter, mapValue, internalStructField);
} else {
xmlStreamWriter.writeCharacters(val.toString());
}
xmlStreamWriter.writeEndElement();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1744,9 +1744,7 @@ private static boolean checkObjectSubTypeForMethods(List<TypePair> unresolvedTyp
}

MethodType rhsFunc = rhsFunction.get();
if (rhsFunc == null ||
!isInSameVisibilityRegion(targetTypeModule, sourceTypeModule, lhsFunc.getFlags(),
rhsFunc.getFlags())) {
if (!isInSameVisibilityRegion(targetTypeModule, sourceTypeModule, lhsFunc.getFlags(), rhsFunc.getFlags())) {
return false;
}
if (SymbolFlags.isFlagOn(lhsFunc.getFlags(), SymbolFlags.REMOTE) != SymbolFlags
Expand Down Expand Up @@ -1803,7 +1801,7 @@ private static Optional<MethodType> getMatchingInvokableType(List<MethodType> rh
return matchingFunction;
}

if ((lhsFuncIsResource && !matchingFuncIsResource) || (matchingFuncIsResource && !lhsFuncIsResource)) {
if (!lhsFuncIsResource || !matchingFuncIsResource) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ private void getInfoFromYieldedState(StringBuilder strandInfo, String closingBra
strandInfo.append(RUNNABLE).append(closingBracketWithNewLines);
return;
}
if (!this.isYielded() || noPickedYieldStatus) {
// if frames have got empty, noPickedYieldStatus is true, then the state has changed to runnable
if (!this.isYielded()) {
strandInfo.append(RUNNABLE).append(closingBracketWithNewLines);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void verifyJavaCompatibility(String compiledVersion) {
}

// if both have only major versions, then stop checking further.
if (compiledVersionParts.length == 1 && compiledVersionParts.length == 1) {
if (compiledVersionParts.length == 1 && runtimeVersionParts.length == 1) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,8 @@ public void addChildren(BXml xmlItem) {
// If sequence contains children of same type
// the sequence type should be changed to that corresponding xml type
boolean isSameType = true;
Type tempExprType = null;

if (!children.isEmpty()) {
tempExprType = children.get(0).getType();
}
Type tempExprType = children.get(0).getType();

for (int i = 1; i < children.size(); i++) {
if (tempExprType != children.get(i).getType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private StatisticConfig() {
* @see Builder#percentiles(double...)
*/
public double[] getPercentiles() {
return percentiles != null ? Arrays.copyOf(percentiles, percentiles.length) : percentiles;
return percentiles != null ? Arrays.copyOf(percentiles, percentiles.length) : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,25 @@ public static TransactionResourceManager getInstance() {
*/
private void setLogProperties() {
final Path projectRoot = Path.of(RuntimeUtils.USER_DIR);
if (projectRoot != null) {
String logDir = getTransactionLogDirectory();
Path logDirPath = Path.of(logDir);
Path transactionLogDirectory;
if (!logDirPath.isAbsolute()) {
logDir = projectRoot.toAbsolutePath().toString() + File.separatorChar + logDir;
transactionLogDirectory = Path.of(logDir);
} else {
transactionLogDirectory = logDirPath;
}
if (!Files.exists(transactionLogDirectory)) {
try {
Files.createDirectory(transactionLogDirectory);
} catch (IOException e) {
STDERR.println("error: failed to create transaction log directory in " + logDir);
}
String logDir = getTransactionLogDirectory();
Path logDirPath = Path.of(logDir);
Path transactionLogDirectory;
if (!logDirPath.isAbsolute()) {
logDir = projectRoot.toAbsolutePath().toString() + File.separatorChar + logDir;
transactionLogDirectory = Path.of(logDir);
} else {
transactionLogDirectory = logDirPath;
}
if (!Files.exists(transactionLogDirectory)) {
try {
Files.createDirectory(transactionLogDirectory);
} catch (IOException e) {
STDERR.println("error: failed to create transaction log directory in " + logDir);
}
System.setProperty(ATOMIKOS_LOG_BASE_PROPERTY, logDir);
System.setProperty(ATOMIKOS_LOG_NAME_PROPERTY, "transaction_recovery");
System.setProperty(ATOMIKOS_REGISTERED_PROPERTY, "not-registered");
}
System.setProperty(ATOMIKOS_LOG_BASE_PROPERTY, logDir);
System.setProperty(ATOMIKOS_LOG_NAME_PROPERTY, "transaction_recovery");
System.setProperty(ATOMIKOS_REGISTERED_PROPERTY, "not-registered");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ public void execute() {
Proxy proxy = settings.getProxy();
mvnClient.setProxy(proxy.host(), proxy.port(), proxy.username(), proxy.password());

if (balaPath == null && isCustomRepository) {
if (balaPath == null) {
pushPackage(project, mvnClient);
} else if (isCustomRepository) {
} else {
if (!balaPath.toFile().exists()) {
throw new ProjectException("path provided for the bala file does not exist: " + balaPath + ".");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,40 +252,38 @@ public void execute(Project project) {
//Write the testsuite to the disk
TestUtils.writeToTestSuiteJson(testSuiteMap, testsCachePath);

if (hasTests) {
int testResult = 1;
try {
String warnings = GraalVMCompatibilityUtils.getAllWarnings(
project.currentPackage(), jBallerinaBackend.targetPlatform().code(), true);
if (!warnings.isEmpty()) {
out.println(warnings);
}
testResult = runTestSuiteWithNativeImage(project.currentPackage(), target, testSuiteMap);
if (testResult != 0) {
accumulatedTestResult = testResult;
}
if (report) {
for (Map.Entry<String, TestSuite> testSuiteEntry : testSuiteMap.entrySet()) {
String moduleName = testSuiteEntry.getKey();
ModuleStatus moduleStatus = TestUtils.loadModuleStatusFromFile(
testsCachePath.resolve(moduleName).resolve(TesterinaConstants.STATUS_FILE));
if (moduleStatus == null) {
continue;
}

if (!moduleName.equals(project.currentPackage().packageName().toString())) {
moduleName = ModuleName.from(project.currentPackage().packageName(),
moduleName).toString();
}
testReport.addModuleStatus(moduleName, moduleStatus);
int testResult;
try {
String warnings = GraalVMCompatibilityUtils.getAllWarnings(
project.currentPackage(), jBallerinaBackend.targetPlatform().code(), true);
if (!warnings.isEmpty()) {
out.println(warnings);
}
testResult = runTestSuiteWithNativeImage(project.currentPackage(), target, testSuiteMap);
if (testResult != 0) {
accumulatedTestResult = testResult;
}
if (report) {
for (Map.Entry<String, TestSuite> testSuiteEntry : testSuiteMap.entrySet()) {
String moduleName = testSuiteEntry.getKey();
ModuleStatus moduleStatus = TestUtils.loadModuleStatusFromFile(
testsCachePath.resolve(moduleName).resolve(TesterinaConstants.STATUS_FILE));
if (moduleStatus == null) {
continue;
}

if (!moduleName.equals(project.currentPackage().packageName().toString())) {
moduleName = ModuleName.from(project.currentPackage().packageName(),
moduleName).toString();
}
testReport.addModuleStatus(moduleName, moduleStatus);
}
} catch (IOException e) {
TestUtils.cleanTempCache(project, cachesRoot);
throw createLauncherException("error occurred while running tests: ", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} catch (IOException e) {
TestUtils.cleanTempCache(project, cachesRoot);
throw createLauncherException("error occurred while running tests: ", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
if (report && hasTests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ public DiagnosticResult diagnosticResult() {
}

public EmitResult emit(OutputType outputType, Path filePath) {
Path generatedArtifact = null;
Path generatedArtifact;

if (diagnosticResult.hasErrors()) {
return new EmitResult(false, new DefaultDiagnosticResult(new ArrayList<>()), generatedArtifact);
return new EmitResult(false, new DefaultDiagnosticResult(new ArrayList<>()), null);
}

List<Diagnostic> emitResultDiagnostics = new ArrayList<>();
Expand Down
Loading

0 comments on commit 3cdcde9

Please sign in to comment.