Skip to content
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

Include the fat JAR of the LS extension #450

Merged
merged 2 commits into from
Nov 1, 2024
Merged
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 @@ -217,7 +217,7 @@ private Optional<Category> getConnection(Symbol symbol) {
}

private static List<Item> fetchConnections(ModuleID moduleId, String parentSymbol) {
DatabaseManager dbManager = new DatabaseManager();
DatabaseManager dbManager = DatabaseManager.getInstance();
Optional<FunctionResult> connectorResult =
dbManager.getFunction(moduleId.orgName(), moduleId.packageName(), NewConnection.INIT_SYMBOL,
DatabaseManager.FunctionKind.CONNECTOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public JsonArray getConnectors(Map<String, String> queryMap) {
if (CommonUtils.hasNoKeyword(queryMap, "offset")) {
modifiedQueryMap.put("offset", "0");
}
DatabaseManager dbManager = new DatabaseManager();
DatabaseManager dbManager = DatabaseManager.getInstance();

List<FunctionResult> connectorResults = CommonUtils.hasNoKeyword(queryMap, "q") ?
dbManager.getAllFunctions(DatabaseManager.FunctionKind.CONNECTOR) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void buildProjectNodes(Map<String, String> queryMap, LineRange position)

private void buildUtilityNodes(Map<String, String> queryMap) {
Category.Builder utilityBuilder = rootBuilder.stepIn(Category.Name.UTILITIES);
DatabaseManager dbManager = new DatabaseManager();
DatabaseManager dbManager = DatabaseManager.getInstance();

List<FunctionResult> functionResults = CommonUtils.hasNoKeyword(queryMap, "q") ?
dbManager.getAllFunctions(DatabaseManager.FunctionKind.FUNCTION) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import io.ballerina.flowmodelgenerator.core.db.model.FunctionResult;
import io.ballerina.flowmodelgenerator.core.db.model.ParameterResult;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
Expand All @@ -45,12 +48,41 @@ public class DatabaseManager {
private static final Logger LOGGER = Logger.getLogger(DatabaseManager.class.getName());
private final String dbPath;

private static class Holder {

private static final DatabaseManager INSTANCE = new DatabaseManager();
}

public static DatabaseManager getInstance() {
return Holder.INSTANCE;
}

public DatabaseManager() {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
throw new RuntimeException("Failed to load SQLite JDBC driver", e);
}

Path tempDir;
try {
tempDir = Files.createTempDirectory("central-index");
} catch (IOException e) {
throw new RuntimeException("Failed to create a temporary directory", e);
}

URL dbUrl = getClass().getClassLoader().getResource(INDEX_FILE_NAME);
if (dbUrl == null) {
throw new RuntimeException("Database resource not found: " + INDEX_FILE_NAME);
}
dbPath = "jdbc:sqlite:" + dbUrl.getPath();
Path tempFile = tempDir.resolve(INDEX_FILE_NAME);
try {
Files.copy(dbUrl.openStream(), tempFile);
} catch (IOException e) {
throw new RuntimeException("Failed to copy the database file to the temporary directory", e);
}

dbPath = "jdbc:sqlite:" + tempFile.toString();
}

public enum FunctionKind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static FlowNode fetchNodeTemplate(NodeBuilder nodeBuilder, Codedata code
return null;
}

DatabaseManager dbManager = new DatabaseManager();
DatabaseManager dbManager = DatabaseManager.getInstance();
Optional<FunctionResult> functionResult = codedata.id() != null ? dbManager.getFunction(codedata.id()) :
dbManager.getAction(codedata.org(), codedata.module(), codedata.symbol());
if (functionResult.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void setConcreteTemplateData(TemplateContext context) {
return;
}

DatabaseManager dbManager = new DatabaseManager();
DatabaseManager dbManager = DatabaseManager.getInstance();
Optional<FunctionResult> functionResult =
dbManager.getFunction(codedata.org(), codedata.module(), codedata.symbol(),
DatabaseManager.FunctionKind.FUNCTION);
Expand Down Expand Up @@ -184,7 +184,7 @@ public Map<Path, List<TextEdit>> toSource(SourceBuilder sourceBuilder) {
}

private static FlowNode fetchNodeTemplate(NodeBuilder nodeBuilder, Codedata codedata) {
DatabaseManager dbManager = new DatabaseManager();
DatabaseManager dbManager = DatabaseManager.getInstance();
Optional<FunctionResult> functionResult =
dbManager.getFunction(codedata.org(), codedata.module(), codedata.symbol(),
DatabaseManager.FunctionKind.FUNCTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Map<Path, List<TextEdit>> toSource(SourceBuilder sourceBuilder) {
}

private static FlowNode fetchNodeTemplate(NodeBuilder nodeBuilder, Codedata codedata) {
DatabaseManager dbManager = new DatabaseManager();
DatabaseManager dbManager = DatabaseManager.getInstance();
Optional<FunctionResult> functionResult = codedata.id() != null ? dbManager.getFunction(codedata.id()) :
dbManager.getFunction(codedata.org(), codedata.module(), codedata.symbol(),
DatabaseManager.FunctionKind.CONNECTOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
requires io.ballerina.openapi.core;
requires io.swagger.v3.oas.models;
requires jakarta.persistence;
requires org.xerial.sqlitejdbc;

exports io.ballerina.flowmodelgenerator.core;
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ def pullBallerinaModule(String packageName) {
}
}

// TODO: This should be removed once https://github.com/ballerina-platform/ballerina-distribution/issues/5811 is completed
shadowJar {
archiveBaseName.set(project.name)
archiveClassifier.set('')
archiveVersion.set(project.version.toString())
configurations = [project.configurations.runtimeClasspath]
dependencies {
include(dependency("org.xerial:sqlite-jdbc:${sqliteJdbcVersion}"))
exclude('META-INF/*.SF')
exclude('META-INF/*.DSA')
exclude('META-INF/*.RSA')
}
}

test.dependsOn pullBallerinaModule('ballerinax/redis')
test.dependsOn pullBallerinaModule('ballerinax/trigger.salesforce')

Expand All @@ -130,7 +144,6 @@ test {
}

ext.moduleName = 'io.ballerina.flowmodelgenerator.extension'

jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn configurations.dist
Expand All @@ -147,3 +160,7 @@ compileJava {
classpath = files()
}
}

artifacts {
archives shadowJar
}
Loading