Skip to content

Commit

Permalink
Merge branch 'master' into mas-cleanup-bir-41384
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadeeshan96 committed Nov 8, 2023
2 parents 199d333 + 90eacfe commit 8df7083
Show file tree
Hide file tree
Showing 67 changed files with 910 additions and 453 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ You can use the following resources to learn Ballerina.
>**Tip:** If you are unsure whether you have found a bug, search the existing issues in the GitHub repo and raise it in the [Ballerina Discord](https://discord.com/invite/wAJYFbMrG2) or [Stack Overflow](https://stackoverflow.com/questions/tagged/ballerina).
- Language, Tooling, Website: <a href="https://github.com/ballerina-platform/ballerina-lang/issues">ballerina-lang</a> repo
- Ballerina library: <a href="https://github.com/ballerina-platform/ballerina-standard-library/issues">ballerina-lang</a> repo
- Ballerina library: <a href="https://github.com/ballerina-platform/ballerina-standard-library/issues">ballerina-library</a> repo
- Security flaw: send an email to security@ballerina.io. For details, see the <a href="https://ballerina.io/security-policy/">security policy</a>.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private String getXmlNsUriPrefix(Map<String, String> nsPrefixMap, String uri) {
}

private void writeAttributes(HashSet<String> curNSSet, Map<String, String> attributeMap) throws XMLStreamException {
String defaultNS = xmlStreamWriter.getNamespaceContext().getNamespaceURI(XMLNS);
String defaultNS = xmlStreamWriter.getNamespaceContext().getNamespaceURI("");
for (Map.Entry<String, String> attributeEntry : attributeMap.entrySet()) {
String key = attributeEntry.getKey();
int closingCurlyPos = key.lastIndexOf('}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public class TableValueImpl<K, V> implements TableValue<K, V> {
private long maxIntKey = 0;

//These are required to achieve the iterator behavior
private LinkedHashMap<Long, K> indexToKeyMap;
private LinkedHashMap<Long, Long> indexToKeyMap;
private LinkedHashMap<Long, Long> keyToIndexMap;
private LinkedHashMap<K, V> keyValues;
private LinkedHashMap<Long, KeyValuePair<K, V>> keyValues;
private long noOfAddedEntries = 0;

private boolean nextKeySupported;
Expand Down Expand Up @@ -478,9 +478,11 @@ private class TableIterator<K, V> implements IteratorValue {

@Override
public Object next() {
K key = (K) indexToKeyMap.get(cursor);
if (key != null) {
V value = (V) keyValues.get(key);
Long hash = indexToKeyMap.get(cursor);
if (hash != null) {
KeyValuePair<K, V> keyValuePair = (KeyValuePair<K, V>) keyValues.get(hash);
K key = keyValuePair.getKey();
V value = keyValuePair.getValue();

List<Type> types = new ArrayList<>();
types.add(TypeChecker.getType(key));
Expand Down Expand Up @@ -534,7 +536,7 @@ public V putData(V data) {
entries.put(hash, entryList);
updateIndexKeyMappings((K) data, hash);
values.put(hash, newData);
keyValues.put((K) data, data);
keyValues.put(hash, KeyValuePair.of((K) data, data));
return data;
}

Expand Down Expand Up @@ -588,7 +590,7 @@ public void addData(V data) {
extEntries.add(entry);
List<V> extValues = values.get(hash);
extValues.add(data);
keyValues.put(key, data);
keyValues.put(hash, KeyValuePair.of(key, data));
updateIndexKeyMappings(key, hash);
return;
}
Expand Down Expand Up @@ -630,14 +632,13 @@ public V putData(K key, V data) {
}

private V putData(K key, V value, List<V> data, Map.Entry<K, V> entry, Long hash) {

List<Map.Entry<K, V>> entryList = new ArrayList<>();
entryList.add(entry);
entries.put(hash, entryList);
keys.put(hash, key);
updateIndexKeyMappings(key, hash);
values.put(hash, data);
keyValues.put(key, value);
keyValues.put(hash, KeyValuePair.of(key, value));
return data.get(0);
}

Expand All @@ -655,8 +656,8 @@ public V putData(V data) {
}

public V remove(K key) {
keyValues.remove(key);
Long hash = TableUtils.hash(key, null);
keyValues.remove(hash);
List<Map.Entry<K, V>> entryList = entries.get(hash);
if (entryList != null && entryList.size() > 1) {
for (Map.Entry<K, V> entry: entryList) {
Expand Down Expand Up @@ -747,11 +748,33 @@ public K wrapKey(MapValue data) {
}
}

private static final class KeyValuePair<K, V> {
private K key;
private V value;

public KeyValuePair(K key, V value) {
this.key = key;
this.value = value;
}

public static <K, V> KeyValuePair<K, V> of(K key, V value) {
return new KeyValuePair<>(key, value);
}

public K getKey() {
return key;
}

public V getValue() {
return value;
}
}

// This method updates the indexes and the order required by the iterators
private void updateIndexKeyMappings(K key, Long hash) {
if (!keyToIndexMap.containsKey(hash)) {
keyToIndexMap.put(hash, noOfAddedEntries);
indexToKeyMap.put(noOfAddedEntries, key);
indexToKeyMap.put(noOfAddedEntries, hash);
noOfAddedEntries++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ private BError createXMLCycleError() {
}

private void mergeAdjoiningTextNodesIntoList(List leftList, List<BXml> appendingList) {
XmlPi lastChild = (XmlPi) leftList.get(leftList.size() - 1);
String firstChildContent = ((XmlPi) appendingList.get(0)).getData();
String mergedTextContent = lastChild.getData() + firstChildContent;
XmlText lastChild = (XmlText) leftList.get(leftList.size() - 1);
String firstChildContent = appendingList.get(0).getTextValue();
String mergedTextContent = lastChild.getTextValue() + firstChildContent;
XmlText text = new XmlText(mergedTextContent);
leftList.set(leftList.size() - 1, text);
for (int i = 1; i < appendingList.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ private static void pullPackageFromRemote(String orgName, String packageName, St
CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
initializeProxy(settings.getProxy()), settings.getProxy().username(),
settings.getProxy().password(),
getAccessTokenOfCLI(settings));
getAccessTokenOfCLI(settings), settings.getCentral().getConnectTimeout(),
settings.getCentral().getReadTimeout(), settings.getCentral().getWriteTimeout(),
settings.getCentral().getCallTimeout());
try {
client.pullPackage(orgName, packageName, version, destination, supportedPlatform,
RepoUtils.getBallerinaVersion(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ private void deprecateInCentral(String packageInfo) {
CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
initializeProxy(settings.getProxy()), settings.getProxy().username(),
settings.getProxy().password(),
getAccessTokenOfCLI(settings));
getAccessTokenOfCLI(settings), settings.getCentral().getConnectTimeout(),
settings.getCentral().getReadTimeout(), settings.getCentral().getWriteTimeout(),
settings.getCentral().getCallTimeout());
client.deprecatePackage(packageValue, deprecationMsg,
JvmTarget.JAVA_17.code(),
RepoUtils.getBallerinaVersion(), this.undoFlag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ public void execute() {
try {
CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
initializeProxy(settings.getProxy()), settings.getProxy().username(),
settings.getProxy().password(), getAccessTokenOfCLI(settings));
settings.getProxy().password(), getAccessTokenOfCLI(settings),
settings.getCentral().getConnectTimeout(),
settings.getCentral().getReadTimeout(), settings.getCentral().getWriteTimeout(),
settings.getCentral().getCallTimeout());
client.pullPackage(orgName, packageName, version, packagePathInBalaCache, supportedPlatform,
RepoUtils.getBallerinaVersion(), false);
if (version.equals(Names.EMPTY.getValue())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ public void execute() {
}
CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
initializeProxy(settings.getProxy()), settings.getProxy().username(),
settings.getProxy().password(), getAccessTokenOfCLI(settings));
settings.getProxy().password(), getAccessTokenOfCLI(settings),
settings.getCentral().getConnectTimeout(),
settings.getCentral().getReadTimeout(), settings.getCentral().getWriteTimeout(),
settings.getCentral().getCallTimeout());
if (balaPath == null) {
pushPackage(project, client);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ private void searchInCentral(String query) {
initializeProxy(settings.getProxy()),
settings.getProxy().username(),
settings.getProxy().password(),
getAccessTokenOfCLI(settings));
getAccessTokenOfCLI(settings),
settings.getCentral().getConnectTimeout(),
settings.getCentral().getReadTimeout(),
settings.getCentral().getWriteTimeout(),
settings.getCentral().getCallTimeout());
boolean foundSearch = false;
String supportedPlatform = Arrays.stream(JvmTarget.values())
.map(target -> target.code())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,10 @@ private void pullToolFromCentral(String supportedPlatform, Path balaCacheDirPath
System.setProperty(CentralClientConstants.ENABLE_OUTPUT_STREAM, "true");
CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
initializeProxy(settings.getProxy()), settings.getProxy().username(),
settings.getProxy().password(), getAccessTokenOfCLI(settings));
settings.getProxy().password(), getAccessTokenOfCLI(settings),
settings.getCentral().getConnectTimeout(),
settings.getCentral().getReadTimeout(), settings.getCentral().getWriteTimeout(),
settings.getCentral().getCallTimeout());
String[] toolInfo = client.pullTool(toolId, version, balaCacheDirPath, supportedPlatform,
RepoUtils.getBallerinaVersion(), false);
boolean isPulled = Boolean.parseBoolean(toolInfo[0]);
Expand Down Expand Up @@ -574,7 +577,10 @@ private void searchToolsInCentral(String keyword) {
}
CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
initializeProxy(settings.getProxy()), settings.getProxy().username(),
settings.getProxy().password(), getAccessTokenOfCLI(settings));
settings.getProxy().password(), getAccessTokenOfCLI(settings),
settings.getCentral().getConnectTimeout(),
settings.getCentral().getReadTimeout(), settings.getCentral().getWriteTimeout(),
settings.getCentral().getCallTimeout());
boolean foundTools = false;
String supportedPlatform = Arrays.stream(JvmTarget.values())
.map(JvmTarget::code)
Expand Down Expand Up @@ -726,7 +732,10 @@ private String getLatestVersionForUpdateCommand(String supportedPlatforms, BalTo
System.setProperty(CentralClientConstants.ENABLE_OUTPUT_STREAM, "true");
CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
initializeProxy(settings.getProxy()), settings.getProxy().username(),
settings.getProxy().password(), getAccessTokenOfCLI(settings));
settings.getProxy().password(), getAccessTokenOfCLI(settings),
settings.getCentral().getConnectTimeout(),
settings.getCentral().getReadTimeout(), settings.getCentral().getWriteTimeout(),
settings.getCentral().getCallTimeout());
List<String> versions = client.getPackageVersions(tool.org(), tool.name(), supportedPlatforms,
RepoUtils.getBallerinaVersion());
return getLatestVersion(versions, tool.version());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.ballerinalang.util.RepoUtils;
import picocli.CommandLine;

import java.io.File;
Expand Down Expand Up @@ -277,8 +278,9 @@ public void testBalTestWithStickyFlag() throws IOException {
String buildLog = readOutput(true);
Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("bal-test-project.txt"));
Assert.assertTrue(projectPath.resolve(DEPENDENCIES_TOML).toFile().exists());
Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(), readFileAsString(
projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDeps.toml")).trim());
Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(),
readFileAsString(projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDeps.toml"))
.trim().replace("INSERT_VERSION_HERE", RepoUtils.getBallerinaShortVersion()));

// remove build file
Files.deleteIfExists(projectPath.resolve(TARGET_DIR_NAME).resolve(BUILD_FILE));
Expand All @@ -294,8 +296,9 @@ public void testBalTestWithStickyFlag() throws IOException {
String secondBuildLog = readOutput(true);
Assert.assertEquals(secondBuildLog.replaceAll("\r", ""), getOutput("bal-test-project.txt"));
Assert.assertTrue(projectPath.resolve(DEPENDENCIES_TOML).toFile().exists());
Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(), readFileAsString(
projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDeps.toml")).trim());
Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(),
readFileAsString(projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDeps.toml"))
.trim().replace("INSERT_VERSION_HERE", RepoUtils.getBallerinaShortVersion()));
}

@Test(description = "Test a ballerina project with the flag dump-graph")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.8.0-SNAPSHOT"
distribution-version = "INSERT_VERSION_HERE"

[[package]]
org = "ballerina"
Expand Down
Loading

0 comments on commit 8df7083

Please sign in to comment.