Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ task createProperties() {

task build {
dependsOn createProperties
dependsOn(":persist-core:build")
dependsOn(":persist-cli:build")
dependsOn(":persist-cli-tests:build")
dependsOn(":persist-tool:build")
Expand Down
6 changes: 4 additions & 2 deletions persist-cli-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies {
transitive = false
}

testImplementation project(":persist-core")
testImplementation project(":persist-cli")
testImplementation group: 'org.testng', name: 'testng', version: "${testngVersion}"
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
Expand Down Expand Up @@ -302,8 +303,9 @@ jacoco {

jacocoTestReport {
dependsOn test
def classFiles = new File("${rootDir}/persist-cli/build/classes/java/main/io/ballerina/persist")
additionalClassDirs(classFiles)
def coreClassFiles = new File("${rootDir}/persist-core/build/classes/java/main/io/ballerina/persist")
def cliClassFiles = new File("${rootDir}/persist-cli/build/classes/java/main/io/ballerina/persist")
additionalClassDirs(coreClassFiles, cliClassFiles)
reports {
xml.required = true
}
Expand Down
1 change: 1 addition & 0 deletions persist-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
checkstyle project(':checkstyle')
checkstyle "com.puppycrawl.tools:checkstyle:${checkstylePluginVersion}"

implementation project(':persist-core')
implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}"
implementation (group: 'org.ballerinalang', name: 'ballerina-cli', version: "${ballerinaLangVersion}") {
exclude group: 'org.ballerinalang', module: 'maven-resolver'
Expand Down
49 changes: 3 additions & 46 deletions persist-cli/src/main/java/io/ballerina/persist/cmd/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@
import io.ballerina.compiler.syntax.tree.Token;
import io.ballerina.persist.BalException;
import io.ballerina.persist.nodegenerator.syntax.constants.BalSyntaxConstants;
import io.ballerina.persist.utils.FileUtils;
import io.ballerina.tools.text.TextDocument;
import io.ballerina.tools.text.TextDocuments;
import org.ballerinalang.formatter.core.Formatter;
import org.ballerinalang.formatter.core.FormatterException;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

import static io.ballerina.persist.PersistToolsConstants.SCHEMA_FILE_NAME;
import static io.ballerina.persist.nodegenerator.syntax.constants.BalSyntaxConstants.BAL_EXTENSION;
Expand All @@ -58,49 +53,11 @@ public static void generateSchemaBalFile(Path persistPath) throws BalException {
}

public static void writeOutputString(String content, String outPath) throws BalException, IOException {
Path pathToFile = Paths.get(outPath);
Path parentDirectory = pathToFile.getParent();
if (Objects.nonNull(parentDirectory)) {
if (!Files.exists(parentDirectory)) {
try {
Files.createDirectories(parentDirectory);
} catch (IOException e) {
throw new BalException(
String.format("could not create the parent directories of output path %s. %s",
parentDirectory, e.getMessage()));
}
}
try (PrintWriter writer = new PrintWriter(outPath, StandardCharsets.UTF_8)) {
writer.println(content);
}
}
FileUtils.writeToTargetFile(content, outPath);
}

public static void writeToTargetFile(String content, String outPath) throws BalException, IOException {
Path pathToFile = Paths.get(outPath);
Path parentDirectory = pathToFile.getParent();
if (Objects.nonNull(parentDirectory)) {
if (!Files.exists(parentDirectory)) {
try {
Files.createDirectories(parentDirectory);
} catch (IOException e) {
throw new BalException(
String.format("could not create the parent directories of output path %s. %s",
parentDirectory, e.getMessage()));
}
}
File file = new File(pathToFile.toString());
if (!file.exists()) {
boolean fileCreated = file.createNewFile();
if (!fileCreated) {
throw new BalException(
String.format("Could not create the file in the output path %s.", outPath));
}
}
try (PrintWriter writer = new PrintWriter(outPath, StandardCharsets.UTF_8)) {
writer.println(content);
}
}
FileUtils.writeToTargetFile(content, outPath);
}

public static String generateSchemaSyntaxTree() throws FormatterException {
Expand Down
1 change: 1 addition & 0 deletions persist-cli/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

module io.ballerina.persist {
requires io.ballerina.persist.core;
requires io.ballerina.runtime;
requires io.ballerina.lang;
requires io.ballerina.cli;
Expand Down
166 changes: 166 additions & 0 deletions persist-core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
*
* Licensed 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.
*
*/

plugins {
id 'java-library'
id 'checkstyle'
id 'com.github.spotbugs'
}

description = 'Ballerina - Persist Core Java Library'

repositories {
mavenCentral()
}

configurations {
implementation
externalJars
}

dependencies {
checkstyle project(':checkstyle')
checkstyle "com.puppycrawl.tools:checkstyle:${checkstylePluginVersion}"

implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-tools-api', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-parser', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'toml-parser', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'formatter-core', version: "${ballerinaLangVersion}"
testImplementation group: 'org.testng', name: 'testng', version: "${testngVersion}"
}

test {
useTestNG() {
suites 'src/test/resources/testng.xml'
}
testLogging.showStandardStreams = true
testLogging {
events "PASSED", "FAILED", "SKIPPED"
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
finalizedBy jacocoTestReport
}

spotbugsMain {
enabled = true
ignoreFailures = true
def classLoader = plugins["com.github.spotbugs"].class.classLoader
def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence")
def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort")
effort = SpotBugsEffort.MAX
reportLevel = SpotBugsConfidence.LOW
reportsDir = layout.buildDirectory.dir("reports/spotbugs")
reports {
text.required = true
}
def excludeFile = file("${rootDir}/spotbugs-exclude.xml")
if (excludeFile.exists()) {
excludeFilter = excludeFile
}
}

spotbugsTest {
enabled = false
}

jacoco {
toolVersion = "${jacocoVersion}"
}

jacocoTestReport {
dependsOn test
reports {
xml.required = true
}
}

task validateSpotbugs() {
doLast {
if (spotbugsMain.reports.size() > 0 &&
spotbugsMain.reports[0].destination.exists() &&
spotbugsMain.reports[0].destination.text.readLines().size() > 0) {
spotbugsMain.reports[0].destination?.eachLine {
println 'Failure: ' + it
}
throw new GradleException("Spotbugs rule violations were found.");
}
}
}

checkstyle {
toolVersion "${checkstylePluginVersion}"
configFile rootProject.file("build-config/checkstyle/build/checkstyle.xml")
configProperties = ["suppressionFile" : file("${rootDir}/build-config/checkstyle/build/suppressions.xml")]
}

spotbugsMain.finalizedBy validateSpotbugs
checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles")
checkstyleTest.dependsOn(":checkstyle:downloadCheckstyleRuleFiles")

def excludePattern = '**/module-info.java'
tasks.withType(Checkstyle) {
exclude excludePattern
}

compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}

jar {
manifest {
attributes('Implementation-Title': project.name, 'Implementation-Version': project.version)
}
}

clean {
delete layout.buildDirectory
}

publishing {
publications {
mavenJava(MavenPublication) {
groupId "io.ballerina"
artifactId "persist-core"
from components.java
}
}

repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/ballerina-platform/persist-tools")
credentials {
username = System.getenv("publishUser")
password = System.getenv("publishPAT")
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading