Skip to content

Add support for importing external projects (Mule, TIBCO) #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
balTools("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") {
transitive = false
}
implementation "org.ballerinalang:toml-parser:${ballerinaLangVersion}"
}

def balDistribution = file("$project.buildDir/extracted-distribution/jballerina-tools-${ballerinaLangVersion}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.projectservice.core;

import io.ballerina.projectservice.core.baltool.BalToolsUtil;

import java.lang.reflect.Method;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Map;

/**
* Utility class to invoke methods from migration tools and converting results.
*
* @since 1.2.0
*/
public class MigrateToolInvokingUtil {

private static final String KEY_ERROR = "error";
private static final String KET_TEXT_EDITS = "textEdits";
private static final String KEY_REPORT = "report";

private MigrateToolInvokingUtil() {
}

public static ToolExecutionResult invokeToolMethod(String commandName, String className, String methodName,
Map<String, Object> args) {
BalToolsUtil.updateOldBalToolsToml();
URLClassLoader classLoader = BalToolsUtil.getCustomToolClassLoader(commandName);
try {
Class<?> toolClass = classLoader.loadClass(className);
Method method = toolClass.getMethod(methodName, Map.class);
Object invoke = method.invoke(null, args);
classLoader.close();
if (invoke instanceof Map<?,?> mapResult) {
return transformToolExecutionResult(mapResult);
}
throw new RuntimeException("Unexpected return type from migration method: " + invoke.getClass());
} catch (Exception e) {
throw new RuntimeException("Error invoking migration method", e);
}
}

private static ToolExecutionResult transformToolExecutionResult(Map<?, ?> mapResult) {
ToolExecutionResult.Builder resultBuilder = new ToolExecutionResult.Builder();
for (Map.Entry<?, ?> entry : mapResult.entrySet()) {
if (entry.getKey() instanceof String key && entry.getValue() instanceof Object value) {
switch (key) {
case KEY_ERROR -> resultBuilder.error((String) value);
case KET_TEXT_EDITS -> {
if (value instanceof Map<?, ?> textEdits) {
Map<String, String> edits = new HashMap<>();
for (Map.Entry<?, ?> textEditEntry : textEdits.entrySet()) {
if (textEditEntry.getKey() instanceof String editKey &&
textEditEntry.getValue() instanceof String editValue) {
edits.put(editKey, editValue);
}
}
resultBuilder.textEdits(edits);
}
}
case KEY_REPORT -> resultBuilder.report((String) value);
}
}
}
return resultBuilder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.projectservice.core;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

import static io.ballerina.projectservice.core.MigrateToolInvokingUtil.invokeToolMethod;

/**
* Utility class to import TIBCO projects.
*
* @since 1.2.0
*/
public class TibcoImporter {

private static final String TIBCO_TOOL_COMMAND = "migrate-tibco";
private static final String TIBCO_TOOL_CLASS_NAME = "tibco.TibcoToBalConverter";
private static final String TIBCO_TOOL_METHOD_NAME = "migrateTIBCO";

private static final String PARAM_OGR_NAME = "orgName";
private static final String PARAM_PROJECT_NAME = "projectName";
private static final String PARAM_SOURCE_PATH = "sourcePath";
private static final String PARAM_STATE_CALLBACK = "stateCallback";
private static final String PARAM_LOG_CALLBACK = "logCallback";

public static ToolExecutionResult importTibco(String orgName, String packageName, String sourcePath,
Consumer<String> stateCallback, Consumer<String> logCallback) {
Map<String, Object> args = new HashMap<>();
args.put(PARAM_OGR_NAME, orgName);
args.put(PARAM_PROJECT_NAME, packageName);
args.put(PARAM_SOURCE_PATH, sourcePath);
args.put(PARAM_STATE_CALLBACK, stateCallback);
args.put(PARAM_LOG_CALLBACK, logCallback);
return invokeToolMethod(TIBCO_TOOL_COMMAND, TIBCO_TOOL_CLASS_NAME, TIBCO_TOOL_METHOD_NAME, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.projectservice.core;

import java.util.HashMap;
import java.util.Map;

/**
* Represents the result of a tool execution.
*
* @param error Error message if any occurred during execution.
* @param textEdits A map of text edits where keys are file paths and values are the edits to be applied.
* @param report HTML report generated by the tool execution.
*
* @since 1.2.0
*/
public record ToolExecutionResult(String error, Map<String, String> textEdits, String report) {

public static class Builder {
private String error;
private Map<String, String> textEdits = new HashMap<>();
private String report;

public Builder error(String error) {
this.error = error;
return this;
}

public void textEdits(Map<String, String> textEdits) {
this.textEdits = textEdits;
}

public void report(String report) {
this.report = report;
}

public ToolExecutionResult build() {
return new ToolExecutionResult(error, textEdits, report);
}
}
}
Loading
Loading