diff --git a/.github/workflows/main-branch.yml b/.github/workflows/main-branch.yml deleted file mode 100644 index 92a2532..0000000 --- a/.github/workflows/main-branch.yml +++ /dev/null @@ -1,240 +0,0 @@ -name: Main Branch Workflow - -on: - push: - branches: [ "main" ] - paths-ignore: - - 'README.md' - - 'CODE_OF_CONDUCT.md' - - 'CONTRIBUTING.md' - - 'LICENSE' - - '.github/**' - - 'examples/**' - workflow_dispatch: - -jobs: - build-jars: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - - name: Build with Gradle Wrapper - run: ./gradlew build --no-daemon - - - name: Extract project name from Gradle - id: extract-name - run: | - PROJECT_NAME=$(./gradlew -q printProjectName --no-daemon) - echo "PROJECT_NAME=${PROJECT_NAME}" >> $GITHUB_ENV - - - name: Extract version from Gradle - id: extract-version - run: | - VERSION=$(./gradlew -q printProjectVersion --no-daemon) - echo "VERSION=${VERSION}" >> $GITHUB_ENV - - - name: Upload jars - uses: actions/upload-artifact@v4 - with: - name: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}-jars - path: build/libs/*.jar - - - name: Upload JaCoCo test report - uses: actions/upload-artifact@v4 - with: - name: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}-test-report - path: build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml - - upload-codecov: - runs-on: ubuntu-latest - needs: - - build-jars - - steps: - - uses: actions/checkout@v4 - - name: Extract project name from Gradle - id: extract-name - run: | - PROJECT_NAME=$(./gradlew -q printProjectName --no-daemon) - echo "PROJECT_NAME=${PROJECT_NAME}" >> $GITHUB_ENV - - - name: Extract version from Gradle - id: extract-version - run: | - VERSION=$(./gradlew -q printProjectVersion --no-daemon) - echo "VERSION=${VERSION}" >> $GITHUB_ENV - - - name: Download JaCoCo test report - uses: actions/download-artifact@v4 - with: - name: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}-test-report - path: artifacts/ - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./build/reports/jacoco/test/jacocoTestReport.xml - fail_ci_if_error: true - - documentate: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - - name: Documentate with Gradle Wrapper - run: ./gradlew documentate --no-daemon - - - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v4 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./build/dokka/htmlMultiModule - publish_branch: gh-pages - - create-release: - runs-on: ubuntu-latest - needs: - - build-jars - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Extract project name from Gradle - id: extract_name - run: | - PROJECT_NAME=$(./gradlew -q printProjectName) - echo "PROJECT_NAME=${PROJECT_NAME}" >> $GITHUB_ENV - - - name: Extract version from Gradle - id: get-version - run: | - VERSION=$(./gradlew -q printProjectVersion) - echo "VERSION=${VERSION}" >> $GITHUB_ENV - - - name: Download jars - uses: actions/download-artifact@v4 - with: - name: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}-jars - path: artifacts/ - - - name: Release - uses: softprops/action-gh-release@v2 - if: "!contains(env.VERSION, '-')" - with: - tag_name: ${{ env.VERSION }} - body_path: ./CHANGELOG.md - files: | - artifacts/* - - publish: - runs-on: ubuntu-latest - needs: - - create-release - - permissions: - contents: read - packages: write - - steps: - - name: Checkout source - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - - - name: Configure Gradle - uses: gradle/gradle-build-action@v3 - - - name: Publish to GitHub Packages - run: ./gradlew publish --no-daemon - env: - PGP_PRIVATE_KEY: ${{ secrets.PGP_PRIVATE_KEY }} - PGP_PRIVATE_KEY_PASSWORD: ${{ secrets.PGP_PRIVATE_KEY_PASSWORD }} - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - GITHUB_REPO: ${{ github.repository }} - GITHUB_USERNAME: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - dependency-submission: - runs-on: ubuntu-latest - permissions: - contents: write - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. - # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md - - name: Generate and submit dependency graph - uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 - - generate-git-badges: - name: Generate Git Badges - runs-on: ubuntu-latest - permissions: - contents: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Output git info - id: git_info - run: | - function format_size { echo $(numfmt --to iec --suffix B $1); } - function format_number { LC_ALL=en_US.UTF-8 printf "%'d\n" $1; } - echo "file_count=$(format_number $(git ls-files | wc -l))" >> $GITHUB_OUTPUT - echo "lines_of_code=$(find . -type f -name "*.kt" -exec wc -l {} + | awk '{s+=$1} END {print s}')" >> $GITHUB_OUTPUT - git gc - echo "size=$(format_size $(($(git count-objects -v | grep 'size-pack: ' | sed 's/size-pack: //g' | tr -d '\n') * 1024)))" >> $GITHUB_OUTPUT - shell: bash - - - name: Generate-Badge - uses: likespro/generate-badge@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - filename: | - ( - "git-size" - "git-file-count" - "git-lines-of-code" - ) - label: ("size" "files" "lines-of-code") - message: | - ( - "${{ steps.git_info.outputs.size }}" - "${{ steps.git_info.outputs.file_count }}" - "${{ steps.git_info.outputs.lines_of_code }}" - ) - namedLogo: ("git" "git" "git") - color: ("f1502f" "f1502f" "f1502f") \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 5becba3..0000000 --- a/.gitignore +++ /dev/null @@ -1,43 +0,0 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ -.kotlin/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 7d9a8e5..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Environment-dependent path to Maven home directory -/mavenHomeManager.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Zeppelin ignored files -/ZeppelinRemoteNotebooks/ diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 27e1369..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 1e16934..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index fe0b0da..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 3ed86cc..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,15 +0,0 @@ -### Improvements -`core` module: -- Made JSON library (`org.json`) an `api` dependency -- Disabled types auto-boxing when working with Java primitives -- Remove `ExecutedFunctionThrowException` and replace with direct exception propagation in `LPFCP`. - -`ktor` module: -- Updated Ktor to version `3.1.3` -- `Ktor.LPFCPServer` now holds the entire embedded server instead of `NettyApplicationEngine` -- Added `exceptionDetailsConfiguration` parameter to `lpfcpServer` and `lpfcp` route. -It allows specifying the details to be included in response when the exception is thrown. -This will help to hide internal server implementations from users if needed. -### Other -- Updated dependencies' versions - diff --git a/LICENSE b/LICENSE deleted file mode 100644 index fa0086a..0000000 --- a/LICENSE +++ /dev/null @@ -1,373 +0,0 @@ -Mozilla Public License Version 2.0 -================================== - -1. Definitions --------------- - -1.1. "Contributor" - means each individual or legal entity that creates, contributes to - the creation of, or owns Covered Software. - -1.2. "Contributor Version" - means the combination of the Contributions of others (if any) used - by a Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - means Source Code Form to which the initial Contributor has attached - the notice in Exhibit A, the Executable Form of such Source Code - Form, and Modifications of such Source Code Form, in each case - including portions thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - (a) that the initial Contributor has attached the notice described - in Exhibit B to the Covered Software; or - - (b) that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the - terms of a Secondary License. - -1.6. "Executable Form" - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - means a work that combines Covered Software with other material, in - a separate file or files, that is not Covered Software. - -1.8. "License" - means this document. - -1.9. "Licensable" - means having the right to grant, to the maximum extent possible, - whether at the time of the initial grant or subsequently, any and - all of the rights conveyed by this License. - -1.10. "Modifications" - means any of the following: - - (a) any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered - Software; or - - (b) any new file in Source Code Form that contains any Covered - Software. - -1.11. "Patent Claims" of a Contributor - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the - License, by the making, using, selling, offering for sale, having - made, import, or transfer of either its Contributions or its - Contributor Version. - -1.12. "Secondary License" - means either the GNU General Public License, Version 2.0, the GNU - Lesser General Public License, Version 2.1, the GNU Affero General - Public License, Version 3.0, or any later versions of those - licenses. - -1.13. "Source Code Form" - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that - controls, is controlled by, or is under common control with You. For - purposes of this definition, "control" means (a) the power, direct - or indirect, to cause the direction or management of such entity, - whether by contract or otherwise, or (b) ownership of more than - fifty percent (50%) of the outstanding shares or beneficial - ownership of such entity. - -2. License Grants and Conditions --------------------------------- - -2.1. Grants - -Each Contributor hereby grants You a world-wide, royalty-free, -non-exclusive license: - -(a) under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - -(b) under Patent Claims of such Contributor to make, use, sell, offer - for sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - -The licenses granted in Section 2.1 with respect to any Contribution -become effective for each Contribution on the date the Contributor first -distributes such Contribution. - -2.3. Limitations on Grant Scope - -The licenses granted in this Section 2 are the only rights granted under -this License. No additional rights or licenses will be implied from the -distribution or licensing of Covered Software under this License. -Notwithstanding Section 2.1(b) above, no patent license is granted by a -Contributor: - -(a) for any code that a Contributor has removed from Covered Software; - or - -(b) for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - -(c) under Patent Claims infringed by Covered Software in the absence of - its Contributions. - -This License does not grant any rights in the trademarks, service marks, -or logos of any Contributor (except as may be necessary to comply with -the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - -No Contributor makes additional grants as a result of Your choice to -distribute the Covered Software under a subsequent version of this -License (see Section 10.2) or under the terms of a Secondary License (if -permitted under the terms of Section 3.3). - -2.5. Representation - -Each Contributor represents that the Contributor believes its -Contributions are its original creation(s) or it has sufficient rights -to grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - -This License is not intended to limit any rights You have under -applicable copyright doctrines of fair use, fair dealing, or other -equivalents. - -2.7. Conditions - -Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted -in Section 2.1. - -3. Responsibilities -------------------- - -3.1. Distribution of Source Form - -All distribution of Covered Software in Source Code Form, including any -Modifications that You create or to which You contribute, must be under -the terms of this License. You must inform recipients that the Source -Code Form of the Covered Software is governed by the terms of this -License, and how they can obtain a copy of this License. You may not -attempt to alter or restrict the recipients' rights in the Source Code -Form. - -3.2. Distribution of Executable Form - -If You distribute Covered Software in Executable Form then: - -(a) such Covered Software must also be made available in Source Code - Form, as described in Section 3.1, and You must inform recipients of - the Executable Form how they can obtain a copy of such Source Code - Form by reasonable means in a timely manner, at a charge no more - than the cost of distribution to the recipient; and - -(b) You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter - the recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - -You may create and distribute a Larger Work under terms of Your choice, -provided that You also comply with the requirements of this License for -the Covered Software. If the Larger Work is a combination of Covered -Software with a work governed by one or more Secondary Licenses, and the -Covered Software is not Incompatible With Secondary Licenses, this -License permits You to additionally distribute such Covered Software -under the terms of such Secondary License(s), so that the recipient of -the Larger Work may, at their option, further distribute the Covered -Software under the terms of either this License or such Secondary -License(s). - -3.4. Notices - -You may not remove or alter the substance of any license notices -(including copyright notices, patent notices, disclaimers of warranty, -or limitations of liability) contained within the Source Code Form of -the Covered Software, except that You may alter any license notices to -the extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - -You may choose to offer, and to charge a fee for, warranty, support, -indemnity or liability obligations to one or more recipients of Covered -Software. However, You may do so only on Your own behalf, and not on -behalf of any Contributor. You must make it absolutely clear that any -such warranty, support, indemnity, or liability obligation is offered by -You alone, and You hereby agree to indemnify every Contributor for any -liability incurred by such Contributor as a result of warranty, support, -indemnity or liability terms You offer. You may include additional -disclaimers of warranty and limitations of liability specific to any -jurisdiction. - -4. Inability to Comply Due to Statute or Regulation ---------------------------------------------------- - -If it is impossible for You to comply with any of the terms of this -License with respect to some or all of the Covered Software due to -statute, judicial order, or regulation then You must: (a) comply with -the terms of this License to the maximum extent possible; and (b) -describe the limitations and the code they affect. Such description must -be placed in a text file included with all distributions of the Covered -Software under this License. Except to the extent prohibited by statute -or regulation, such description must be sufficiently detailed for a -recipient of ordinary skill to be able to understand it. - -5. Termination --------------- - -5.1. The rights granted under this License will terminate automatically -if You fail to comply with any of its terms. However, if You become -compliant, then the rights granted under this License from a particular -Contributor are reinstated (a) provisionally, unless and until such -Contributor explicitly and finally terminates Your grants, and (b) on an -ongoing basis, if such Contributor fails to notify You of the -non-compliance by some reasonable means prior to 60 days after You have -come back into compliance. Moreover, Your grants from a particular -Contributor are reinstated on an ongoing basis if such Contributor -notifies You of the non-compliance by some reasonable means, this is the -first time You have received notice of non-compliance with this License -from such Contributor, and You become compliant prior to 30 days after -Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent -infringement claim (excluding declaratory judgment actions, -counter-claims, and cross-claims) alleging that a Contributor Version -directly or indirectly infringes any patent, then the rights granted to -You by any and all Contributors for the Covered Software under Section -2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all -end user license agreements (excluding distributors and resellers) which -have been validly granted by You or Your distributors under this License -prior to termination shall survive termination. - -************************************************************************ -* * -* 6. Disclaimer of Warranty * -* ------------------------- * -* * -* Covered Software is provided under this License on an "as is" * -* basis, without warranty of any kind, either expressed, implied, or * -* statutory, including, without limitation, warranties that the * -* Covered Software is free of defects, merchantable, fit for a * -* particular purpose or non-infringing. The entire risk as to the * -* quality and performance of the Covered Software is with You. * -* Should any Covered Software prove defective in any respect, You * -* (not any Contributor) assume the cost of any necessary servicing, * -* repair, or correction. This disclaimer of warranty constitutes an * -* essential part of this License. No use of any Covered Software is * -* authorized under this License except under this disclaimer. * -* * -************************************************************************ - -************************************************************************ -* * -* 7. Limitation of Liability * -* -------------------------- * -* * -* Under no circumstances and under no legal theory, whether tort * -* (including negligence), contract, or otherwise, shall any * -* Contributor, or anyone who distributes Covered Software as * -* permitted above, be liable to You for any direct, indirect, * -* special, incidental, or consequential damages of any character * -* including, without limitation, damages for lost profits, loss of * -* goodwill, work stoppage, computer failure or malfunction, or any * -* and all other commercial damages or losses, even if such party * -* shall have been informed of the possibility of such damages. This * -* limitation of liability shall not apply to liability for death or * -* personal injury resulting from such party's negligence to the * -* extent applicable law prohibits such limitation. Some * -* jurisdictions do not allow the exclusion or limitation of * -* incidental or consequential damages, so this exclusion and * -* limitation may not apply to You. * -* * -************************************************************************ - -8. Litigation -------------- - -Any litigation relating to this License may be brought only in the -courts of a jurisdiction where the defendant maintains its principal -place of business and such litigation shall be governed by laws of that -jurisdiction, without reference to its conflict-of-law provisions. -Nothing in this Section shall prevent a party's ability to bring -cross-claims or counter-claims. - -9. Miscellaneous ----------------- - -This License represents the complete agreement concerning the subject -matter hereof. If any provision of this License is held to be -unenforceable, such provision shall be reformed only to the extent -necessary to make it enforceable. Any law or regulation which provides -that the language of a contract shall be construed against the drafter -shall not be used to construe this License against a Contributor. - -10. Versions of the License ---------------------------- - -10.1. New Versions - -Mozilla Foundation is the license steward. Except as provided in Section -10.3, no one other than the license steward has the right to modify or -publish new versions of this License. Each version will be given a -distinguishing version number. - -10.2. Effect of New Versions - -You may distribute the Covered Software under the terms of the version -of the License under which You originally received the Covered Software, -or under the terms of any subsequent version published by the license -steward. - -10.3. Modified Versions - -If you create software not governed by this License, and you want to -create a new license for such software, you may create and use a -modified version of this License if you rename the license and remove -any references to the name of the license steward (except to note that -such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary -Licenses - -If You choose to distribute Source Code Form that is Incompatible With -Secondary Licenses under the terms of this version of the License, the -notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice -------------------------------------------- - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular -file, then You may include the notice in a location (such as a LICENSE -file in a relevant directory) where a recipient would be likely to look -for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice ---------------------------------------------------------- - - This Source Code Form is "Incompatible With Secondary Licenses", as - defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/README.md b/README.md index 99ecc0e..c972303 100644 Binary files a/README.md and b/README.md differ diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index 42ec898..0000000 --- a/build.gradle.kts +++ /dev/null @@ -1,216 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * From https://github.com/likespro/lpfcp-java - */ - -val GROUP = "io.github.likespro" // Until normal group ID - eth.likespro.commons -val VERSION = "1.1.0" -val NAME = "LPFCP Java" -val DESCRIPTION = "LPFCP protocol implementation in Java/Kotlin" -val URL = "https://github.com/likespro/lpfcp-java" -val LICENSES: MavenPomLicenseSpec.(project: Project) -> Unit = { project -> - license { - name.set("Mozilla Public License 2.0") - url.set("https://www.mozilla.org/en-US/MPL/2.0/") - } -} -val DEVELOPERS: MavenPomDeveloperSpec.() -> Unit = { - developer { - id.set("likespro") - email.set("likespro.eth@gmail.com") - } -} -val SCM: MavenPomScm.() -> Unit = { - connection.set("scm:git:git://github.com/likespro/lpfcp-java.git") - developerConnection.set("scm:git:ssh://github.com:likespro/lpfcp-java.git") - url.set("https://github.com/likespro/lpfcp-java") -} -val PUBLISHED_ARTIFACTS_PREFIX = "lpfcp-" // Until normal group ID - eth.likespro.commons - - - -/* =================== * - * AUTOMATIZED SECTION * - * =================== */ - - - -plugins { - id("java-library") - kotlin("jvm") version "2.1.21" - id("jacoco") - id("org.jetbrains.dokka") version "1.9.0" - id("maven-publish") - id("signing") - id("com.gradleup.nmcp.aggregation").version("0.1.4") - id("com.gradleup.nmcp").version("0.1.4") -} - -allprojects { - group = GROUP - version = VERSION - - repositories { - mavenCentral() - // mavenLocal() // For easier testing - } -} - -subprojects { - apply(plugin = "java-library") - apply(plugin = "kotlin") - apply(plugin = "jacoco") - apply(plugin = "org.jetbrains.dokka") - apply(plugin = "maven-publish") - apply(plugin = "signing") - apply(plugin = "com.gradleup.nmcp") - - dependencies { - testImplementation(platform("org.junit:junit-bom:5.10.0")) - testImplementation("org.junit.jupiter:junit-jupiter") - } - - java { - withJavadocJar() - withSourcesJar() - } - - jacoco { - toolVersion = "0.8.10" - } - tasks.test { - useJUnitPlatform() - finalizedBy(tasks.jacocoTestReport) - } - - tasks.create("documentate") { - group = "documentation" - dependsOn(tasks.dokkaHtml) - } - - publishing { - publications { - create("mavenJava") { - from(components["java"]) - - artifactId = PUBLISHED_ARTIFACTS_PREFIX + project.name - - pom { - name.set(NAME) - description.set(DESCRIPTION) - url.set(URL) - licenses { LICENSES(project) } - developers { DEVELOPERS() } - scm { SCM() } - } - } - } - - repositories { - if(System.getenv("GITHUB_REPO") != null) { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/" + System.getenv("GITHUB_REPO")) - - credentials { - username = System.getenv("GITHUB_USERNAME") - password = System.getenv("GITHUB_TOKEN") - } - } - } - } - } - - if(System.getenv("PGP_PRIVATE_KEY") != null) signing { - sign(publishing.publications) - useInMemoryPgpKeys(System.getenv("PGP_PRIVATE_KEY").replace("\\n", "\n")?.trimIndent(), System.getenv("PGP_PRIVATE_KEY_PASSWORD") ?: "") - } -} - -tasks.register("collectAllJars") { - into(layout.buildDirectory.dir("libs")) - subprojects.forEach { proj -> - dependsOn(proj.tasks.named("jar")) - from(proj.tasks.named("jar").flatMap { it.archiveFile }) - } -} -tasks.jar { - enabled = false - dependsOn("collectAllJars") -} - -tasks.register("jacocoRootReport") { - dependsOn(subprojects.map { it.tasks.named("test") }) - - executionData.setFrom( - subprojects.map { - file("${it.buildDir}/jacoco/test.exec") - } - ) - - // Classes (excluding generated and not-needed classes) - classDirectories.setFrom( - subprojects.map { - files( - fileTree("${it.buildDir}/classes/kotlin/main") { - exclude("**/R.class", "**/R$*.class", "**/BuildConfig.*", "**/Manifest*.*") - }, - fileTree("${it.buildDir}/classes/java/main") { - exclude("**/R.class", "**/R$*.class", "**/BuildConfig.*", "**/Manifest*.*") - } - ) - } - ) - - // Sources of Kotlin & Java - sourceDirectories.setFrom( - subprojects.flatMap { - listOf( - file("${it.projectDir}/src/main/kotlin"), - file("${it.projectDir}/src/main/java") - ) - } - ) - - reports { - xml.required.set(true) - html.required.set(true) - csv.required.set(false) - } -} -tasks.build { - finalizedBy(tasks.named("jacocoRootReport")) -} - -tasks.create("documentate") { - group = "documentation" - dependsOn(tasks.dokkaHtmlMultiModule) -} - -nmcpAggregation { - centralPortal { - username = System.getenv("SONATYPE_USERNAME") - password = System.getenv("SONATYPE_PASSWORD") - publishingType = "USER_MANAGED" - } -} -dependencies { - subprojects.forEach { nmcpAggregation(it) } -} -tasks.named("publish") { - if(!(version as String).contains("-")) finalizedBy("publishAggregationToCentralPortal") -} - -tasks.register("printProjectName") { - doLast { - println(rootProject.name) - } -} -tasks.register("printProjectVersion") { - doLast { - println(version) - } -} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts deleted file mode 100644 index b6e7b07..0000000 --- a/core/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -dependencies { - api("io.github.likespro:commons-core-mit:3.1.0") - implementation("io.github.likespro:commons-reflection:3.1.0") - implementation("io.github.likespro:commons-network:3.1.0") - - implementation("com.google.code.gson:gson:2.13.1") // TODO remove this after commons:3.1.1 - - implementation(kotlin("reflect")) -} \ No newline at end of file diff --git a/core/src/main/java/eth/likespro/lpfcp/FunctionCallHandler.kt b/core/src/main/java/eth/likespro/lpfcp/FunctionCallHandler.kt deleted file mode 100644 index ea1efed..0000000 --- a/core/src/main/java/eth/likespro/lpfcp/FunctionCallHandler.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * From https://github.com/likespro/lpfcp-java - */ - -package eth.likespro.lpfcp - -import eth.likespro.commons.reflection.ObjectEncoding.encodeObject -import org.json.JSONObject -import java.lang.reflect.InvocationHandler -import java.lang.reflect.Method -import java.lang.reflect.Type -import kotlin.reflect.jvm.javaType -import kotlin.reflect.jvm.kotlinFunction - -/** - * A handler for function calls that processes the request and returns the result. Used in Java/Kotlin proxies. - * - * @param processor A lambda function that takes a [JSONObject] request and a [Type] and returns the result of the function call. - */ -class FunctionCallHandler(val processor: (JSONObject, Type) -> Any?) : InvocationHandler { - override fun invoke(proxy: Any, method: Method, args: Array?): Any? { - return processor(JSONObject().apply { - put("functionName", method.name) - put("functionArgs", JSONObject().apply { - args?.forEachIndexed { index, arg -> - put("${index + 1}", arg.encodeObject()) - } - }) - }, method.kotlinFunction!!.returnType.javaType) - } -} \ No newline at end of file diff --git a/core/src/main/java/eth/likespro/lpfcp/LPFCP.kt b/core/src/main/java/eth/likespro/lpfcp/LPFCP.kt deleted file mode 100644 index 2295781..0000000 --- a/core/src/main/java/eth/likespro/lpfcp/LPFCP.kt +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * From https://github.com/likespro/lpfcp-java - */ - -package eth.likespro.lpfcp - -import eth.likespro.commons.models.EncodableResult -import eth.likespro.commons.network.HTTPUtils.post -import eth.likespro.commons.reflection.ObjectEncoding.decodeObject -import eth.likespro.commons.reflection.ReflectionUtils.getParametrizedType -import org.json.JSONException -import org.json.JSONObject -import java.lang.reflect.InvocationTargetException -import java.lang.reflect.Proxy -import java.lang.reflect.Type -import java.net.URI -import kotlin.collections.component1 -import kotlin.collections.component2 -import kotlin.collections.set -import kotlin.reflect.KParameter -import kotlin.reflect.full.findAnnotation -import kotlin.reflect.full.functions -import kotlin.reflect.full.instanceParameter -import kotlin.reflect.javaType - -/** - * The `LPFCP` object provides all core methods to make Server-side and Client-side working with LPFCP - */ -object LPFCP { - /** - * Annotation to mark functions as exposed for processing requests. - * Only functions annotated with `@ExposedFunction` can be invoked by `processRequest`. - */ - @Target(AnnotationTarget.FUNCTION) - annotation class ExposedFunction - - /** - * Exception thrown when the `functionName` key is missing or invalid in the request. - * @param msg The error message describing the issue. - */ - class IncorrectFunctionNameException(msg: String) : RuntimeException(msg) - - /** - * Exception thrown when the `functionArgs` key is missing or invalid in the request. - * @param msg The error message describing the issue. - */ - class IncorrectFunctionArgsException(msg: String) : RuntimeException(msg) - - /** - * Exception thrown when no function with the specified name and parameters is found. - * @param msg The error message describing the issue. - */ - class NoMatchingFunctionFoundException(msg: String) : RuntimeException(msg) - - - - /* - * -------------------------------------------------------------- - * PROCESSOR SIDE - * -------------------------------------------------------------- - */ - - - - /** - * Processes a request to invoke a function on the given processor object safely. - * - * @param request A `JSONObject` containing the function name and arguments. - * - `functionName`: The name of the function to invoke (String). - * - `functionArgs`: The arguments for the function (JSONObject). - * @param processor The object containing the functions to be invoked. - * @return An `EncodableResult` containing the result of the function call or an error. - */ - fun processRequest(request: JSONObject, processor: Any): EncodableResult { - return try { - EncodableResult.success(processRequestUnsafely(request, processor)) - } catch (e: Exception) { - EncodableResult.failure(e) - } - } - - /** - * Processes a request to invoke a function on the given processor object. - * - * @param request A `JSONObject` containing the function name and arguments. - * - `functionName`: The name of the function to invoke (String). - * - `functionArgs`: The arguments for the function (JSONObject). - * @param processor The object containing the functions to be invoked. - * @return A function's return value. - * - * @throws IncorrectFunctionNameException If the `functionName` key is missing or invalid. - * @throws IncorrectFunctionArgsException If the `functionArgs` key is missing or invalid. - * @throws NoMatchingFunctionFoundException If no matching function is found. - */ - @OptIn(ExperimentalStdlibApi::class) - fun processRequestUnsafely(request: JSONObject, processor: Any): Any? { - val kClass = processor::class - - // Extract the function name from the request - val functionName = try { request.getString("functionName") } catch (_: JSONException) { throw IncorrectFunctionNameException("`functionName` key not found or is not String.") } - - // Extract the function arguments from the request - val functionArgs = try { request.getJSONObject("functionArgs") } catch (_: JSONException) { throw IncorrectFunctionArgsException("`functionArgs` key not found or is not JSON Object.") } - - // Filter functions in the processor class that match the name and are annotated with @ExposedFunction - val functions = kClass.functions.filter { it.name == functionName && it.findAnnotation() != null } - functions.forEach { function -> - val args = mutableMapOf() - - // Map the provided arguments to the function's parameters - functionArgs.toMap().forEach { (argName, argValue) -> - function.parameters.find { it.name == argName || it.index.toString() == argName }?.let { param -> - try { - args[param] = (argValue as String).decodeObject(param.type.javaType) - } catch (_: Exception) { } - } - } - - // Skip the function if not all passed arguments are used - if(args.size != functionArgs.length()) { - return@forEach - } - - // Add the instance parameter if required - function.instanceParameter!!.let { args[it] = processor } - - try { - // Invoke the function with the mapped arguments - val result = function.callBy(args) - return result - } catch (e: InvocationTargetException) { - // Handle exceptions thrown by the invoked function - throw e.cause!! - } catch (_: IllegalArgumentException) { - // Handle argument mismatch errors - // Skip this function and continue searching for another one - } - } - - // Throw an exception if no matching function is found - throw NoMatchingFunctionFoundException("Function with specified params not found. Ensure the function has @ExposedFunction annotation.") - } - - - - /* - * -------------------------------------------------------------- - * INVOKER SIDE - * -------------------------------------------------------------- - */ - - - - /** - * Creates a proxy instance of the specified interface that forwards method calls to the provided processor LPFCP URI. - * - * @param Interface template parameter - Interface of the processor - * @param processorLPFCPURI A string representing the processor LPFCP endpoint URI. - * @return A proxy instance of the specified interface. - */ - inline fun getProcessor(processorLPFCPURI: String) = getProcessor (URI(processorLPFCPURI)) - - /** - * Creates a proxy instance of the specified interface that forwards method calls to the provided processor LPFCP URI. - * - * @param Interface template parameter - Interface of the processor - * @param processorLPFCP A URI representing the processor LPFCP endpoint. - * @return A proxy instance of the specified interface. - */ - inline fun getProcessor(processorLPFCP: URI) = getProcessor { request, type -> - (processorLPFCP.post(request.toString()).decodeObject(EncodableResult::class.java.getParametrizedType(type)) as EncodableResult<*>).getOrThrow() - } - - /** - * Creates a proxy instance of the specified interface that forwards method calls to the provided processor function. - * - * @param Interface template parameter - Interface of the processor - * @param processorLPFCP A function that takes: - * - `JSONObject` - function call request in LPFCP format; - * - `Type` - type of value that the called function must return. - * - * [processorLPFCP] returns an `Any?` - value from the invoked function. - * @return A proxy instance of the specified interface. - */ - inline fun getProcessor(noinline processorLPFCP: (JSONObject, Type) -> Any?): Interface { - return Proxy.newProxyInstance( - Interface::class.java.classLoader, - arrayOf(Interface::class.java), - FunctionCallHandler(processorLPFCP) - ) as Interface - } -} \ No newline at end of file diff --git a/core/src/main/java/eth/likespro/lpfcp/LPFCPJava.java b/core/src/main/java/eth/likespro/lpfcp/LPFCPJava.java deleted file mode 100644 index 6ea33b0..0000000 --- a/core/src/main/java/eth/likespro/lpfcp/LPFCPJava.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * From https://github.com/likespro/lpfcp-java - */ - -package eth.likespro.lpfcp; - -import eth.likespro.commons.models.EncodableResult; -import eth.likespro.commons.network.HTTPUtils; -import eth.likespro.commons.reflection.ObjectEncoding; -import eth.likespro.commons.reflection.ReflectionUtils; - -import kotlin.jvm.functions.Function2; -import org.json.JSONObject; - -import java.lang.reflect.Proxy; -import java.lang.reflect.Type; -import java.net.URI; - -/** - * Class LPFCPJava contains some methods from LPFCP object rewritten specifically for Java. - */ -public class LPFCPJava { - /** - * Creates a proxy instance of the specified interface that forwards method calls to the provided processor LPFCP URI. - * - * @param Interface of the processor - * @param interfaceClass Interface class of the processor - * @param processorLPFCPURI A string representing the processor LPFCP endpoint URI. - * @return A proxy instance of the specified interface. - */ - public static Interface getProcessor(Class interfaceClass, String processorLPFCPURI) { - return getProcessor(interfaceClass, URI.create(processorLPFCPURI)); - } - - /** - * Creates a proxy instance of the specified interface that forwards method calls to the provided processor LPFCP URI. - * - * @param Interface of the processor - * @param interfaceClass Interface class of the processor - * @param processorLPFCP A URI representing the processor LPFCP endpoint. - * - * @return A proxy instance of the specified interface. - */ - public static Interface getProcessor(Class interfaceClass, URI processorLPFCP) { - return getProcessor(interfaceClass, (request, returnType) -> { - //noinspection unchecked - return ((EncodableResult) ObjectEncoding.INSTANCE.decodeObject( - HTTPUtils.INSTANCE.post(processorLPFCP, request.toString()), - ReflectionUtils.INSTANCE.getParametrizedType(EncodableResult.class, returnType) - )).getOrThrow(); - }); - } - - /** - * Creates a proxy instance of the specified interface that forwards method calls to the provided processor function. - * - * @param Interface of the processor - * @param interfaceClass Interface class of the processor - * @param processorLPFCP A function that takes: - * - `JSONObject` - function call request in LPFCP format; - * - `Type` - type of value that the called function must return. - * - * [processorLPFCP] returns an `Any?` - value from the invoked function. - * - * @return A proxy instance of the specified interface. - */ - public static Interface getProcessor(Class interfaceClass, Function2 processorLPFCP) { - // noinspection unchecked - return (Interface) Proxy.newProxyInstance( - interfaceClass.getClassLoader(), - new Class[]{interfaceClass}, - new FunctionCallHandler(processorLPFCP) - ); - } -} diff --git a/core/src/test/java/eth/likespro/lpfcp/LPFCPJavaTest.java b/core/src/test/java/eth/likespro/lpfcp/LPFCPJavaTest.java deleted file mode 100644 index f25109c..0000000 --- a/core/src/test/java/eth/likespro/lpfcp/LPFCPJavaTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package eth.likespro.lpfcp; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class LPFCPJavaTest { - interface Calculator { - String hello(); - int add(int a, int b); - String add(String a, String b); - int multiply(int a, int b); - int divide(int a, int b); - Integer divideSafely(int a, int b); - } - - public static class CalculatorImpl implements Calculator { - @Override @LPFCP.ExposedFunction - public String hello() { - return "Hello, World!"; - } - - @Override @LPFCP.ExposedFunction - public int add(int a, int b) { - return a + b; - } - - @Override @LPFCP.ExposedFunction - public String add(String a, String b) { - return a + b; - } - - @Override - public int multiply(int a, int b) { - return a * b; - } - - @Override @LPFCP.ExposedFunction - public int divide(int a, int b) { - return a / b; - } - - @Override @LPFCP.ExposedFunction - public Integer divideSafely(int a, int b) { - if (b == 0) return null; - return a / b; - } - } - - public static CalculatorImpl calculator = new CalculatorImpl(); - - @Test void getProcessor_withLambda_proceedsRequest_withValidFunctionWithNoArgsAndNoArgs_returnsSuccess() { - Calculator processor = LPFCPJava.getProcessor(Calculator.class, (request, returnType) -> LPFCP.INSTANCE.processRequest(request, calculator).getOrThrow()); - String result = processor.hello(); - assertEquals("Hello, World!", result); - } -} \ No newline at end of file diff --git a/core/src/test/java/eth/likespro/lpfcp/LPFCPTests.kt b/core/src/test/java/eth/likespro/lpfcp/LPFCPTests.kt deleted file mode 100644 index 144ef1a..0000000 --- a/core/src/test/java/eth/likespro/lpfcp/LPFCPTests.kt +++ /dev/null @@ -1,288 +0,0 @@ -package eth.likespro.lpfcp - -import eth.likespro.commons.models.EncodableResult -import eth.likespro.commons.models.WrappedException -import org.json.JSONObject -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import java.lang.ArithmeticException - -class LPFCPTests { - /* - * -------------------------------------------------------------- - * PROCESSOR SIDE - * -------------------------------------------------------------- - */ - - - - @Test - fun processRequest_withValidFunctionWithNoArgsAndNoArgs_returnsSuccess() { - val processor = object { - @LPFCP.ExposedFunction - fun hello(): String = "Hello, World!" - } - val request = JSONObject("""{"functionName": "hello", "functionArgs": {}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(EncodableResult.success("Hello, World!"), result as EncodableResult<*>) - } - - @Test - fun processRequest_withValidFunctionAndArgs_returnsSuccess() { - val processor = object { - @LPFCP.ExposedFunction - fun add(a: Int, b: Int): Int = a + b - } - val request = JSONObject("""{"functionName": "add", "functionArgs": {"a": "3", "b": "5"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(EncodableResult.success(8), result as EncodableResult<*>) - } - - @Test - fun processRequest_withValidFunctionReturningNullAndArgs_returnsSuccess() { - val processor = object { - @LPFCP.ExposedFunction - fun divideSafely(a: Int, b: Int): Int? = if (b == 0) null else a / b - } - val request = JSONObject("""{"functionName": "divideSafely", "functionArgs": {"a": "3", "b": "0"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(EncodableResult.success(null), result as EncodableResult<*>) - } - - @Test - fun processRequest_withValidFunctionWithDefaultArgsAndArgs_returnsSuccess() { - val processor = object { - @LPFCP.ExposedFunction - fun add(a: Int = 1, b: Int = 2): Int = a + b - } - val request = JSONObject("""{"functionName": "add", "functionArgs": {"b": "10"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(EncodableResult.success(11), result as EncodableResult<*>) - } - - @Test - fun processRequest_withValidOverloadedFunctionAndArgs_returnsSuccess() { - val processor = object { - @LPFCP.ExposedFunction - fun add(a: Int, b: Int): Int = a + b - - @LPFCP.ExposedFunction - fun add(a: String, b: String): String = a + b - } - val request = JSONObject("""{"functionName": "add", "functionArgs": {"a": "\"3\"", "b": "\"5\""}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(EncodableResult.success("35"), result as EncodableResult<*>) - } - - @Test - fun processRequest_withValidOverloadedFunctionWithMoreArgsAndArgs_returnsSuccess() { - val processor = object { - @LPFCP.ExposedFunction - fun add(a: Int, b: Int): Int = a + b - - @LPFCP.ExposedFunction - fun add(a: Int, b: Int, c: Int): Int = a + b + c - } - val request = JSONObject("""{"functionName": "add", "functionArgs": {"a": "3", "b": "5", "c": "7"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(EncodableResult.success(15), result as EncodableResult<*>) - } - - class StaticProcessor { - companion object { - @LPFCP.ExposedFunction - @JvmStatic - fun add(a: Int, b: Int): Int = a + b - } - } - @Test - fun processRequest_withValidStaticFunctionAndArgs_returnsSuccess() { - val request = JSONObject("""{"functionName": "add", "functionArgs": {"a": "3", "b": "5"}}""") - val result = LPFCP.processRequest(request, StaticProcessor) - assertEquals(EncodableResult.success(8), result as EncodableResult<*>) - } - - @Test - fun processRequest_withMissingFunctionName_throwsIncorrectFunctionNameException() { - val processor = object {} - val request = JSONObject("""{"functionArgs": {"a": "3", "b": "5"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(LPFCP.IncorrectFunctionNameException::class.java, result.failure?.exceptionClass) - } - - @Test - fun processRequest_withInvalidFunctionName_throwsNoMatchingFunctionFound() { - val processor = object { - @LPFCP.ExposedFunction - fun multiply(a: Int, b: Int): Int = a * b - } - val request = JSONObject("""{"functionName": 123, "functionArgs": {"a": "3", "b": "5"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(LPFCP.IncorrectFunctionNameException::class.java, result.failure?.exceptionClass) - } - - @Test - fun processRequest_withNotExistingFunctionName_throwsNoMatchingFunctionFound() { - val processor = object { - @LPFCP.ExposedFunction - fun multiply(a: Int, b: Int): Int = a * b - } - val request = JSONObject("""{"functionName": "divide", "functionArgs": {"a": "3", "b": "5"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(LPFCP.NoMatchingFunctionFoundException::class.java, result.failure?.exceptionClass) - } - - @Test - fun processRequest_withNotAnnotatedFunction_throwsNoMatchingFunctionFound() { - val processor = object { - fun multiply(a: Int, b: Int): Int = a * b - } - val request = JSONObject("""{"functionName": "multiply", "functionArgs": {"a": "3", "b": "5"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(LPFCP.NoMatchingFunctionFoundException::class.java, result.failure?.exceptionClass) - } - - @Test - fun processRequest_withMissingFunctionArgs_throwsIncorrectFunctionArgsException() { - val processor = object { - @LPFCP.ExposedFunction - fun subtract(a: Int, b: Int): Int = a - b - } - val request = JSONObject("""{"functionName": "subtract"}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(LPFCP.IncorrectFunctionArgsException::class.java, result.failure?.exceptionClass) - } - - @Test - fun processRequest_withExtraArgs_skipsFunctionAndThrowsNoMatchingFunctionFound() { - val processor = object { - @LPFCP.ExposedFunction - fun divide(a: Int, b: Int): Int = a / b - } - val request = JSONObject("""{"functionName": "divide", "functionArgs": {"a": "10", "b": "2", "c": "1"}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(LPFCP.NoMatchingFunctionFoundException::class.java, result.failure?.exceptionClass) - } - - @Test - fun processRequest_withFunctionThrowingException_returnsIllegalStateException() { - val processor = object { - @LPFCP.ExposedFunction - fun throwError(): Nothing = throw kotlin.IllegalStateException("Error occurred") - } - val request = JSONObject("""{"functionName": "throwError", "functionArgs": {}}""") - val result = LPFCP.processRequest(request, processor) - assertEquals(IllegalStateException::class.java, result.failure?.exceptionClass) - } - - - - /* - * -------------------------------------------------------------- - * INVOKER SIDE - * -------------------------------------------------------------- - */ - - - - interface Calculator { - fun hello(): String - fun hello(name: String?): String - fun add(a: Int, b: Int): Int - fun add(a: String = "1", b: String = "2"): String - fun multiply(a: Int, b: Int): Int - fun divide(a: Int, b: Int): Int - fun divideSafely(a: Int, b: Int): Int? - } - - companion object { - val calculator = object : Calculator { - @LPFCP.ExposedFunction - override fun hello(): String = "Hello, World!" - - @LPFCP.ExposedFunction - override fun hello(name: String?): String = "Hello, $name!" - - @LPFCP.ExposedFunction - override fun add(a: Int, b: Int): Int = a + b - - @LPFCP.ExposedFunction - override fun add(a: String, b: String): String = a + b - - override fun multiply(a: Int, b: Int) = a * b - - @LPFCP.ExposedFunction - override fun divide(a: Int, b: Int) = a / b - - @LPFCP.ExposedFunction - override fun divideSafely(a: Int, b: Int): Int? = if (b == 0) null else a / b - } - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionWithNoArgs_returnsSuccess() { - val processor = LPFCP.getProcessor { request, _ -> - LPFCP.processRequest(request, calculator).getOrThrow() - } - val result = processor.hello() - assertEquals("Hello, World!", result) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionWithNullArgs_returnsSuccess() { - val processor = LPFCP.getProcessor { request, _ -> - LPFCP.processRequest(request, calculator).getOrThrow() - } - val result = processor.hello(null) - assertEquals("Hello, null!", result) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionAndArgs_returnsSuccess() { - val processor = LPFCP.getProcessor { request, _ -> - LPFCP.processRequest(request, calculator).getOrThrow() - } - val result = processor.add(3, 5) - assertEquals(8, result) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionReturningNullAndArgs_returnsSuccess() { - val processor = LPFCP.getProcessor { request, _ -> - LPFCP.processRequest(request, calculator).getOrThrow() - } - val result = processor.divideSafely(3, 0) - assertEquals(null, result) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidOverloadedFunctionAndArgs_returnsSuccess() { - val processor = LPFCP.getProcessor { request, _ -> - LPFCP.processRequest(request, calculator).getOrThrow() - } - val result = processor.add("3", "5") - assertEquals("35", result) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionWithDefaultArgsAndArgs_returnsSuccess() { - val processor = LPFCP.getProcessor { request, _ -> - LPFCP.processRequest(request, calculator).getOrThrow() - } - val result = processor.add(b = "5") - assertEquals("15", result) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionWithDefaultArgsAndArgsInReverseOrder_returnsSuccess() { - val processor = LPFCP.getProcessor { request, _ -> - LPFCP.processRequest(request, calculator).getOrThrow() - } - val result = processor.add(b = "5", a = "4") - assertEquals("45", result) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withFunctionThrowingException_returnsArithmeticException() { - val processor = LPFCP.getProcessor { request, _ -> - LPFCP.processRequest(request, calculator).getOrThrow() - } - assertEquals( - ArithmeticException::class.java, - assertThrows { processor.divide(5, 0) }.wrappedException.exceptionClass - ) - } -} \ No newline at end of file diff --git a/examples/calculator-java/.gitignore b/examples/calculator-java/.gitignore deleted file mode 100644 index b1dff0d..0000000 --- a/examples/calculator-java/.gitignore +++ /dev/null @@ -1,45 +0,0 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Kotlin ### -.kotlin - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/examples/calculator-java/.idea/.gitignore b/examples/calculator-java/.idea/.gitignore deleted file mode 100644 index 7d9a8e5..0000000 --- a/examples/calculator-java/.idea/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Environment-dependent path to Maven home directory -/mavenHomeManager.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Zeppelin ignored files -/ZeppelinRemoteNotebooks/ diff --git a/examples/calculator-java/.idea/gradle.xml b/examples/calculator-java/.idea/gradle.xml deleted file mode 100644 index 7e65002..0000000 --- a/examples/calculator-java/.idea/gradle.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/examples/calculator-java/.idea/kotlinc.xml b/examples/calculator-java/.idea/kotlinc.xml deleted file mode 100644 index 1e16934..0000000 --- a/examples/calculator-java/.idea/kotlinc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/calculator-java/.idea/misc.xml b/examples/calculator-java/.idea/misc.xml deleted file mode 100644 index fe0b0da..0000000 --- a/examples/calculator-java/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/examples/calculator-java/.idea/vcs.xml b/examples/calculator-java/.idea/vcs.xml deleted file mode 100644 index b2bdec2..0000000 --- a/examples/calculator-java/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/examples/calculator-java/README.md b/examples/calculator-java/README.md deleted file mode 100644 index c2d4541..0000000 --- a/examples/calculator-java/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Calculator - -A calculator application server & client side implementation with LPFCP Java using **Java**. - -To build all jars execute `./gradlew build`. Jars will be in `build/libs` folder \ No newline at end of file diff --git a/examples/calculator-java/build.gradle.kts b/examples/calculator-java/build.gradle.kts deleted file mode 100644 index 31c9b3e..0000000 --- a/examples/calculator-java/build.gradle.kts +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id("java") -} - -allprojects { - group = "io.github.likespro" - version = "1.1.0" - - repositories { - mavenCentral() - mavenLocal() - } -} - -subprojects { - apply(plugin = "java") -} - -tasks.register("collectAllJars") { - into(layout.buildDirectory.dir("libs")) - subprojects.forEach { proj -> - dependsOn(proj.tasks.named("jar")) - from(proj.tasks.named("jar").flatMap { it.archiveFile }) - } -} -tasks.jar { - enabled = false - dependsOn("collectAllJars") -} \ No newline at end of file diff --git a/examples/calculator-java/client/build.gradle.kts b/examples/calculator-java/client/build.gradle.kts deleted file mode 100644 index 6c4cab6..0000000 --- a/examples/calculator-java/client/build.gradle.kts +++ /dev/null @@ -1,4 +0,0 @@ -dependencies { - implementation("io.github.likespro:lpfcp-core:1.1.0") - implementation(project(":shared")) -} \ No newline at end of file diff --git a/examples/calculator-java/client/src/main/java/eth/likespro/lpfcp/calculator/ClientMain.java b/examples/calculator-java/client/src/main/java/eth/likespro/lpfcp/calculator/ClientMain.java deleted file mode 100644 index 0d55595..0000000 --- a/examples/calculator-java/client/src/main/java/eth/likespro/lpfcp/calculator/ClientMain.java +++ /dev/null @@ -1,17 +0,0 @@ -package eth.likespro.lpfcp.calculator; - -import eth.likespro.lpfcp.LPFCPJava; - -public class ClientMain { - public static void main(String[] args) { - // Creating a calculator object from Calculator interface with LPFCP - Calculator calculator = LPFCPJava.getProcessor( - Calculator.class, - "http://localhost:8080/lpfcp" // If the calculator server is hosted on the same machine - ); - - // Call Calculator functions as the calculator was just a regular implementation - System.out.println(calculator.add(1, 2)); // -> 3 - System.out.println((calculator.subtract(5, 3))); // -> 2 - } -} diff --git a/examples/calculator-java/gradle.properties b/examples/calculator-java/gradle.properties deleted file mode 100644 index b06a80a..0000000 --- a/examples/calculator-java/gradle.properties +++ /dev/null @@ -1,7 +0,0 @@ -# Enable the build cache to save time by reusing outputs produced by other successful builds. -# https://docs.gradle.org/current/userguide/build_cache.html -org.gradle.caching=true -# Enable the configuration cache to reuse the build configuration and enable parallel task execution. -# (Note that some plugins may not yet be compatible with the configuration cache.) -# https://docs.gradle.org/current/userguide/configuration_cache.html -org.gradle.configuration-cache=true diff --git a/examples/calculator-java/gradle/libs.versions.toml b/examples/calculator-java/gradle/libs.versions.toml deleted file mode 100644 index dc91593..0000000 --- a/examples/calculator-java/gradle/libs.versions.toml +++ /dev/null @@ -1,22 +0,0 @@ -# Version catalog is a central place for you to declare and version dependencies -# https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog -# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format - -[versions] -kotlin = "2.1.20" -kotlinxDatetime = "0.6.1" -kotlinxSerializationJSON = "1.7.3" -kotlinxCoroutines = "1.9.0" - -[libraries] -kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -kotlinxDatetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" } -kotlinxSerialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJSON" } -kotlinxCoroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutines" } - -# Libraries can be bundled together for easier import -[bundles] -kotlinxEcosystem = ["kotlinxDatetime", "kotlinxSerialization", "kotlinxCoroutines"] - -[plugins] -kotlinPluginSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } \ No newline at end of file diff --git a/examples/calculator-java/gradle/wrapper/gradle-wrapper.jar b/examples/calculator-java/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 9bbc975..0000000 Binary files a/examples/calculator-java/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/examples/calculator-java/gradle/wrapper/gradle-wrapper.properties b/examples/calculator-java/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 37f853b..0000000 --- a/examples/calculator-java/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,7 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/examples/calculator-java/gradlew b/examples/calculator-java/gradlew deleted file mode 100644 index faf9300..0000000 --- a/examples/calculator-java/gradlew +++ /dev/null @@ -1,251 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# 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 -# -# https://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. -# -# SPDX-License-Identifier: Apache-2.0 -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" -fi - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/examples/calculator-java/gradlew.bat b/examples/calculator-java/gradlew.bat deleted file mode 100644 index 9d21a21..0000000 --- a/examples/calculator-java/gradlew.bat +++ /dev/null @@ -1,94 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/examples/calculator-java/server/build.gradle.kts b/examples/calculator-java/server/build.gradle.kts deleted file mode 100644 index fec97bd..0000000 --- a/examples/calculator-java/server/build.gradle.kts +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - implementation("io.github.likespro:lpfcp-core:1.1.0") - implementation("io.github.likespro:lpfcp-ktor:1.1.0") - implementation(project(":shared")) -} \ No newline at end of file diff --git a/examples/calculator-java/server/src/main/java/eth/likespro/lpfcp/calculator/CalculatorImpl.java b/examples/calculator-java/server/src/main/java/eth/likespro/lpfcp/calculator/CalculatorImpl.java deleted file mode 100644 index 2d86706..0000000 --- a/examples/calculator-java/server/src/main/java/eth/likespro/lpfcp/calculator/CalculatorImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -package eth.likespro.lpfcp.calculator; - -import eth.likespro.lpfcp.LPFCP; - -public class CalculatorImpl implements Calculator { - @Override @LPFCP.ExposedFunction - public int add(int a, int b) { - return a + b; - } - - @Override @LPFCP.ExposedFunction - public int subtract(int a, int b) { - return a - b; - } -} diff --git a/examples/calculator-java/server/src/main/java/eth/likespro/lpfcp/calculator/ServerMain.java b/examples/calculator-java/server/src/main/java/eth/likespro/lpfcp/calculator/ServerMain.java deleted file mode 100644 index 3818c54..0000000 --- a/examples/calculator-java/server/src/main/java/eth/likespro/lpfcp/calculator/ServerMain.java +++ /dev/null @@ -1,15 +0,0 @@ -package eth.likespro.lpfcp.calculator; - -import eth.likespro.lpfcp.LPFCPJava; -import eth.likespro.lpfcp.ktor.Ktor; - -public class ServerMain { - public static void main(String[] args) { - // Creating a calculator object like always - Calculator calculator = new CalculatorImpl(); - - // Starting LPFCP Server, which exposes all annotated calculator functions - Ktor.INSTANCE.lpfcpServer(calculator, 8080) - .start(true); - } -} diff --git a/examples/calculator-java/settings.gradle.kts b/examples/calculator-java/settings.gradle.kts deleted file mode 100644 index 2b58ec5..0000000 --- a/examples/calculator-java/settings.gradle.kts +++ /dev/null @@ -1,4 +0,0 @@ -rootProject.name = "calculator" -include("shared") -include("server") -include("client") \ No newline at end of file diff --git a/examples/calculator-java/shared/build.gradle.kts b/examples/calculator-java/shared/build.gradle.kts deleted file mode 100644 index e69de29..0000000 diff --git a/examples/calculator-java/shared/src/main/java/eth/likespro/lpfcp/calculator/Calculator.java b/examples/calculator-java/shared/src/main/java/eth/likespro/lpfcp/calculator/Calculator.java deleted file mode 100644 index 87f2827..0000000 --- a/examples/calculator-java/shared/src/main/java/eth/likespro/lpfcp/calculator/Calculator.java +++ /dev/null @@ -1,6 +0,0 @@ -package eth.likespro.lpfcp.calculator; - -public interface Calculator { - int add(int a, int b); - int subtract(int a, int b); -} diff --git a/examples/calculator-kotlin/.gitignore b/examples/calculator-kotlin/.gitignore deleted file mode 100644 index b1dff0d..0000000 --- a/examples/calculator-kotlin/.gitignore +++ /dev/null @@ -1,45 +0,0 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Kotlin ### -.kotlin - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/examples/calculator-kotlin/.idea/.gitignore b/examples/calculator-kotlin/.idea/.gitignore deleted file mode 100644 index 7d9a8e5..0000000 --- a/examples/calculator-kotlin/.idea/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Environment-dependent path to Maven home directory -/mavenHomeManager.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Zeppelin ignored files -/ZeppelinRemoteNotebooks/ diff --git a/examples/calculator-kotlin/.idea/.name b/examples/calculator-kotlin/.idea/.name deleted file mode 100644 index afa6020..0000000 --- a/examples/calculator-kotlin/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -calculator \ No newline at end of file diff --git a/examples/calculator-kotlin/.idea/gradle.xml b/examples/calculator-kotlin/.idea/gradle.xml deleted file mode 100644 index 7e65002..0000000 --- a/examples/calculator-kotlin/.idea/gradle.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/examples/calculator-kotlin/.idea/kotlinc.xml b/examples/calculator-kotlin/.idea/kotlinc.xml deleted file mode 100644 index 1e16934..0000000 --- a/examples/calculator-kotlin/.idea/kotlinc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/calculator-kotlin/.idea/misc.xml b/examples/calculator-kotlin/.idea/misc.xml deleted file mode 100644 index fe0b0da..0000000 --- a/examples/calculator-kotlin/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/examples/calculator-kotlin/.idea/vcs.xml b/examples/calculator-kotlin/.idea/vcs.xml deleted file mode 100644 index b2bdec2..0000000 --- a/examples/calculator-kotlin/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/examples/calculator-kotlin/README.md b/examples/calculator-kotlin/README.md deleted file mode 100644 index 8e32f8c..0000000 --- a/examples/calculator-kotlin/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Calculator - -A calculator application server & client side implementation with LPFCP Java using **Kotlin**. - -To build all jars execute `./gradlew build`. Jars will be in `build/libs` folder \ No newline at end of file diff --git a/examples/calculator-kotlin/build.gradle.kts b/examples/calculator-kotlin/build.gradle.kts deleted file mode 100644 index 2b2826d..0000000 --- a/examples/calculator-kotlin/build.gradle.kts +++ /dev/null @@ -1,31 +0,0 @@ -plugins { - id("java") - kotlin("jvm") version "2.1.21" -} - -allprojects { - group = "io.github.likespro" - version = "1.1.0" - - repositories { - mavenCentral() - mavenLocal() - } -} - -subprojects { - apply(plugin = "java") - apply(plugin = "kotlin") -} - -tasks.register("collectAllJars") { - into(layout.buildDirectory.dir("libs")) - subprojects.forEach { proj -> - dependsOn(proj.tasks.named("jar")) - from(proj.tasks.named("jar").flatMap { it.archiveFile }) - } -} -tasks.jar { - enabled = false - dependsOn("collectAllJars") -} \ No newline at end of file diff --git a/examples/calculator-kotlin/client/build.gradle.kts b/examples/calculator-kotlin/client/build.gradle.kts deleted file mode 100644 index 6c4cab6..0000000 --- a/examples/calculator-kotlin/client/build.gradle.kts +++ /dev/null @@ -1,4 +0,0 @@ -dependencies { - implementation("io.github.likespro:lpfcp-core:1.1.0") - implementation(project(":shared")) -} \ No newline at end of file diff --git a/examples/calculator-kotlin/client/src/main/java/eth/likespro/lpfcp/calculator/ClientMain.kt b/examples/calculator-kotlin/client/src/main/java/eth/likespro/lpfcp/calculator/ClientMain.kt deleted file mode 100644 index e5d7ac3..0000000 --- a/examples/calculator-kotlin/client/src/main/java/eth/likespro/lpfcp/calculator/ClientMain.kt +++ /dev/null @@ -1,14 +0,0 @@ -package eth.likespro.lpfcp.calculator - -import eth.likespro.lpfcp.LPFCP - -fun main() { - // Creating a calculator object from Calculator interface with LPFCP - val calculator: Calculator = LPFCP.getProcessor( - "http://localhost:8080/lpfcp" // If the calculator server is hosted on the same machine - ) - - // Call Calculator functions as the calculator was just a regular implementation - println(calculator.add(1, 2)) // -> 3 - println(calculator.subtract(5, 3)) // -> 2 -} \ No newline at end of file diff --git a/examples/calculator-kotlin/gradle.properties b/examples/calculator-kotlin/gradle.properties deleted file mode 100644 index b06a80a..0000000 --- a/examples/calculator-kotlin/gradle.properties +++ /dev/null @@ -1,7 +0,0 @@ -# Enable the build cache to save time by reusing outputs produced by other successful builds. -# https://docs.gradle.org/current/userguide/build_cache.html -org.gradle.caching=true -# Enable the configuration cache to reuse the build configuration and enable parallel task execution. -# (Note that some plugins may not yet be compatible with the configuration cache.) -# https://docs.gradle.org/current/userguide/configuration_cache.html -org.gradle.configuration-cache=true diff --git a/examples/calculator-kotlin/gradle/libs.versions.toml b/examples/calculator-kotlin/gradle/libs.versions.toml deleted file mode 100644 index dc91593..0000000 --- a/examples/calculator-kotlin/gradle/libs.versions.toml +++ /dev/null @@ -1,22 +0,0 @@ -# Version catalog is a central place for you to declare and version dependencies -# https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog -# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format - -[versions] -kotlin = "2.1.20" -kotlinxDatetime = "0.6.1" -kotlinxSerializationJSON = "1.7.3" -kotlinxCoroutines = "1.9.0" - -[libraries] -kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -kotlinxDatetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" } -kotlinxSerialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJSON" } -kotlinxCoroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutines" } - -# Libraries can be bundled together for easier import -[bundles] -kotlinxEcosystem = ["kotlinxDatetime", "kotlinxSerialization", "kotlinxCoroutines"] - -[plugins] -kotlinPluginSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } \ No newline at end of file diff --git a/examples/calculator-kotlin/gradle/wrapper/gradle-wrapper.jar b/examples/calculator-kotlin/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 9bbc975..0000000 Binary files a/examples/calculator-kotlin/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/examples/calculator-kotlin/gradle/wrapper/gradle-wrapper.properties b/examples/calculator-kotlin/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 37f853b..0000000 --- a/examples/calculator-kotlin/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,7 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/examples/calculator-kotlin/gradlew b/examples/calculator-kotlin/gradlew deleted file mode 100644 index faf9300..0000000 --- a/examples/calculator-kotlin/gradlew +++ /dev/null @@ -1,251 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# 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 -# -# https://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. -# -# SPDX-License-Identifier: Apache-2.0 -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" -fi - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/examples/calculator-kotlin/gradlew.bat b/examples/calculator-kotlin/gradlew.bat deleted file mode 100644 index 9d21a21..0000000 --- a/examples/calculator-kotlin/gradlew.bat +++ /dev/null @@ -1,94 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/examples/calculator-kotlin/server/build.gradle.kts b/examples/calculator-kotlin/server/build.gradle.kts deleted file mode 100644 index fec97bd..0000000 --- a/examples/calculator-kotlin/server/build.gradle.kts +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - implementation("io.github.likespro:lpfcp-core:1.1.0") - implementation("io.github.likespro:lpfcp-ktor:1.1.0") - implementation(project(":shared")) -} \ No newline at end of file diff --git a/examples/calculator-kotlin/server/src/main/java/eth/likespro/lpfcp/calculator/CalculatorImpl.kt b/examples/calculator-kotlin/server/src/main/java/eth/likespro/lpfcp/calculator/CalculatorImpl.kt deleted file mode 100644 index d79bde2..0000000 --- a/examples/calculator-kotlin/server/src/main/java/eth/likespro/lpfcp/calculator/CalculatorImpl.kt +++ /dev/null @@ -1,11 +0,0 @@ -package eth.likespro.lpfcp.calculator - -import eth.likespro.lpfcp.LPFCP - -class CalculatorImpl: Calculator { - @LPFCP.ExposedFunction - override fun add(a: Int, b: Int): Int = a + b - - @LPFCP.ExposedFunction - override fun subtract(a: Int, b: Int): Int = a - b -} \ No newline at end of file diff --git a/examples/calculator-kotlin/server/src/main/java/eth/likespro/lpfcp/calculator/ServerMain.kt b/examples/calculator-kotlin/server/src/main/java/eth/likespro/lpfcp/calculator/ServerMain.kt deleted file mode 100644 index 36c3b3f..0000000 --- a/examples/calculator-kotlin/server/src/main/java/eth/likespro/lpfcp/calculator/ServerMain.kt +++ /dev/null @@ -1,12 +0,0 @@ -package eth.likespro.lpfcp.calculator - -import eth.likespro.lpfcp.ktor.Ktor.lpfcpServer - -fun main() { - // Creating a calculator object like always - val calculator = CalculatorImpl() - - // Starting LPFCP Server, which exposes all annotated calculator functions - lpfcpServer(processor = calculator, port = 8080) - .start(wait = true) -} \ No newline at end of file diff --git a/examples/calculator-kotlin/settings.gradle.kts b/examples/calculator-kotlin/settings.gradle.kts deleted file mode 100644 index 2b58ec5..0000000 --- a/examples/calculator-kotlin/settings.gradle.kts +++ /dev/null @@ -1,4 +0,0 @@ -rootProject.name = "calculator" -include("shared") -include("server") -include("client") \ No newline at end of file diff --git a/examples/calculator-kotlin/shared/build.gradle.kts b/examples/calculator-kotlin/shared/build.gradle.kts deleted file mode 100644 index e69de29..0000000 diff --git a/examples/calculator-kotlin/shared/src/main/java/eth/likespro/lpfcp/calculator/Calculator.kt b/examples/calculator-kotlin/shared/src/main/java/eth/likespro/lpfcp/calculator/Calculator.kt deleted file mode 100644 index 5b609d2..0000000 --- a/examples/calculator-kotlin/shared/src/main/java/eth/likespro/lpfcp/calculator/Calculator.kt +++ /dev/null @@ -1,6 +0,0 @@ -package eth.likespro.lpfcp.calculator - -interface Calculator { - fun add(a: Int, b: Int): Int - fun subtract(a: Int, b: Int): Int -} \ No newline at end of file diff --git a/git-file-count.md b/git-file-count.md new file mode 100644 index 0000000..8124253 --- /dev/null +++ b/git-file-count.md @@ -0,0 +1 @@ +{"schemaVersion":1,"label":"files","message":"71","color":"f1502f","namedLogo":"git"} diff --git a/git-lines-of-code.md b/git-lines-of-code.md new file mode 100644 index 0000000..3358f4f --- /dev/null +++ b/git-lines-of-code.md @@ -0,0 +1 @@ +{"schemaVersion":1,"label":"lines-of-code","message":"1482","color":"f1502f","namedLogo":"git"} diff --git a/git-size.md b/git-size.md new file mode 100644 index 0000000..0e444b7 --- /dev/null +++ b/git-size.md @@ -0,0 +1 @@ +{"schemaVersion":1,"label":"size","message":"131KB","color":"f1502f","namedLogo":"git"} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 249e583..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index a2882de..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon May 19 12:07:21 EEST 2025 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 1b6c787..0000000 --- a/gradlew +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# 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 -# -# https://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. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 107acd3..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/ktor/build.gradle.kts b/ktor/build.gradle.kts deleted file mode 100644 index 4d29f39..0000000 --- a/ktor/build.gradle.kts +++ /dev/null @@ -1,8 +0,0 @@ -dependencies { - implementation("io.ktor:ktor-server-netty:3.1.3") - implementation("io.ktor:ktor-server-core:3.1.3") - - implementation("io.github.likespro:commons-reflection:3.1.0") - - implementation(project(":core")) -} \ No newline at end of file diff --git a/ktor/src/main/java/eth/likespro/lpfcp/ktor/Ktor.kt b/ktor/src/main/java/eth/likespro/lpfcp/ktor/Ktor.kt deleted file mode 100644 index 42822d7..0000000 --- a/ktor/src/main/java/eth/likespro/lpfcp/ktor/Ktor.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * From https://github.com/likespro/lpfcp-java - */ - -package eth.likespro.lpfcp.ktor - -import eth.likespro.commons.models.WrappedException -import eth.likespro.commons.reflection.ObjectEncoding.encodeObject -import eth.likespro.lpfcp.LPFCP.ExposedFunction -import eth.likespro.lpfcp.LPFCP.processRequest -import io.ktor.server.engine.* -import io.ktor.server.netty.* -import io.ktor.server.request.* -import io.ktor.server.response.* -import io.ktor.server.routing.* -import org.json.JSONObject - -object Ktor { - /** - * A class-wrapper that manages the lifecycle of a Netty-based server engine. - * - * @property engine The Netty application engine instance used to handle server operations. - */ - class LPFCPServer(val embeddedServer: EmbeddedServer) { - /** - * Starts the Netty application engine. - * - * @param wait Specifies whether to block the current thread until the engine stops. Defaults to true. - * @return The instance of the started NettyApplicationEngine. - */ - fun start(wait: Boolean): LPFCPServer = this.apply { embeddedServer.start(wait) } - - /** - * Stops the Netty application engine with the specified grace period and timeout. - * - * @param gracePeriodMillis The time in milliseconds to wait for ongoing requests to complete before forcefully stopping. Defaults to 500 milliseconds. - * @param timeoutMillis The maximum time in milliseconds to wait for the engine to stop. Defaults to 1500 milliseconds. - */ - fun stop(gracePeriodMillis: Long = 500, timeoutMillis: Long = 1500) = embeddedServer.engine.stop(gracePeriodMillis, timeoutMillis) - } - - /** - * Creates an embedded Ktor server to handle LPFCP requests. - * Has only one route - `/lpfcp` - endpoint for LPFCP protocol. - * - * @param processor The object containing the functions to be invoked with [ExposedFunction] annotation. - * @param port The port on which the server will listen to (default is `8080`). - * @param exceptionDetailsConfiguration The configuration for the exception details to be included in the response - * (default is [WrappedException.DetailsConfiguration.INCLUDE_ALL]). - */ - fun lpfcpServer(processor: Any, port: Int = 8080, exceptionDetailsConfiguration: WrappedException.DetailsConfiguration = WrappedException.DetailsConfiguration.INCLUDE_ALL) = LPFCPServer(embeddedServer(Netty, port) { - routing { - lpfcp(processor, exceptionDetailsConfiguration = exceptionDetailsConfiguration) - } - }) - - /** - * Ktor route to handle LPFCP requests. - * - * @param processor The object containing the functions to be invoked with [ExposedFunction] annotation. - * @param path The path for the LPFCP endpoint (default is "/lpfcp"). - * @param exceptionDetailsConfiguration The configuration for the exception details to be included in the response - * (default is [WrappedException.DetailsConfiguration.INCLUDE_ALL]). - */ - fun Route.lpfcp(processor: Any, path: String = "/lpfcp", exceptionDetailsConfiguration: WrappedException.DetailsConfiguration = WrappedException.DetailsConfiguration.INCLUDE_ALL) { - post(path) { - val request = JSONObject(call.receiveText()) - call.respond(processRequest(request, processor) - .applyExceptionDetailsConfiguration(exceptionDetailsConfiguration) - .encodeObject()) - } - } -} \ No newline at end of file diff --git a/ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTests.kt b/ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTests.kt deleted file mode 100644 index 86f5e86..0000000 --- a/ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTests.kt +++ /dev/null @@ -1,111 +0,0 @@ -package eth.likespro.lpfcp.ktor - -import eth.likespro.commons.models.WrappedException -import eth.likespro.lpfcp.LPFCP -import eth.likespro.lpfcp.ktor.Ktor.lpfcpServer -import org.junit.jupiter.api.AfterAll -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import java.lang.ArithmeticException -import java.net.URI - -class KtorTests { - interface Calculator { - fun hello(): String - fun add(a: Int, b: Int): Int - fun add(a: String = "1", b: String = "2"): String - fun multiply(a: Int, b: Int): Int - fun divide(a: Int, b: Int): Int - fun divideSafely(a: Int, b: Int): Int? - } - - companion object { - val calculator = object : Calculator { - @LPFCP.ExposedFunction - override fun hello(): String = "Hello, World!" - - @LPFCP.ExposedFunction - override fun add(a: Int, b: Int): Int = a + b - - @LPFCP.ExposedFunction - override fun add(a: String, b: String): String = a + b - - override fun multiply(a: Int, b: Int) = a * b - - @LPFCP.ExposedFunction - override fun divide(a: Int, b: Int) = a / b - - @LPFCP.ExposedFunction - override fun divideSafely(a: Int, b: Int): Int? = if (b == 0) null else a / b - } - - val port = 8090 - var server: Ktor.LPFCPServer? = null - - @JvmStatic - @BeforeAll fun setupKtorServer() { - server = lpfcpServer(calculator, port).start(wait = false) - } - - @JvmStatic - @AfterAll fun teardownKtorServer() { - server?.stop(0, 0) - } - } - - - - /* - * -------------------------------------------------------------- - * KTOR SERVER SIDE - * -------------------------------------------------------------- - */ - - - - @Test fun ktorServer_withValidFunctionWithNoArgsAndNoArgs_returnsSuccess() { - val processor = LPFCP.getProcessor(URI("http://localhost:$port/lpfcp")) - val response = processor.hello() - assertEquals("Hello, World!", response) - } - - @Test fun ktorServer_withValidFunctionAndArgs_returnsSuccess() { - val processor = LPFCP.getProcessor("http://localhost:$port/lpfcp") - val response = processor.add(3, 5) - assertEquals(8, response) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionReturningNullAndArgs_returnsSuccess() { - val processor = LPFCP.getProcessor("http://localhost:$port/lpfcp") - val response = processor.divideSafely(3, 0) - assertEquals(null, response) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidOverloadedFunctionAndArgs_returnsSuccess() { - val processor = LPFCP.getProcessor("http://localhost:$port/lpfcp") - val response = processor.add("3", "5") - assertEquals("35", response) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionWithDefaultArgsAndArgs_returnsSuccess() { - val processor = LPFCP.getProcessor("http://localhost:$port/lpfcp") - val response = processor.add(b = "5") - assertEquals("15", response) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withValidFunctionWithDefaultArgsAndArgsInReverseOrder_returnsSuccess() { - val processor = LPFCP.getProcessor("http://localhost:$port/lpfcp") - val response = processor.add(b = "5", a = "4") - assertEquals("45", response) - } - - @Test fun getProcessor_withLambda_proceedsRequest_withFunctionThrowingException_returnsArithmeticException() { - val processor = LPFCP.getProcessor("http://localhost:$port/lpfcp") - assertEquals( - ArithmeticException::class.java, - assertThrows { processor.divide(5, 0) }.wrappedException.exceptionClass - ) - } -} \ No newline at end of file diff --git a/ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTestsJava.java b/ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTestsJava.java deleted file mode 100644 index 524d915..0000000 --- a/ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTestsJava.java +++ /dev/null @@ -1,91 +0,0 @@ -package eth.likespro.lpfcp.ktor; - -import eth.likespro.commons.models.WrappedException; -import eth.likespro.lpfcp.LPFCP; -import eth.likespro.lpfcp.LPFCPJava; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.net.URI; -import java.net.URISyntaxException; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class KtorTestsJava { - interface Calculator { - String hello(); - int add(int a, int b); - String add(String a, String b); - int multiply(int a, int b); - int divide(int a, int b); - Integer divideSafely(int a, int b); - } - - public static class CalculatorImpl implements Calculator { - @Override @LPFCP.ExposedFunction - public String hello() { - return "Hello, World!"; - } - - @Override @LPFCP.ExposedFunction - public int add(int a, int b) { - return a + b; - } - - @Override @LPFCP.ExposedFunction - public String add(String a, String b) { - return a + b; - } - - @Override - public int multiply(int a, int b) { - return a * b; - } - - @Override @LPFCP.ExposedFunction - public int divide(int a, int b) { - return a / b; - } - - @Override @LPFCP.ExposedFunction - public Integer divideSafely(int a, int b) { - if (b == 0) return null; - return a / b; - } - } - - public static CalculatorImpl calculator = new CalculatorImpl(); - public static Integer port = 8090; - public static Ktor.LPFCPServer server; - - @BeforeAll static void setupKtorServer() { - server = Ktor.INSTANCE.lpfcpServer(calculator, port, WrappedException.DetailsConfiguration.Companion.getINCLUDE_ALL()).start(false); - } - - @AfterAll static void teardownKtorServer() { - server.stop(0, 0); - } - - - - /* - * -------------------------------------------------------------- - * KTOR SERVER SIDE - * -------------------------------------------------------------- - */ - - - - @Test public void ktorServer_withValidFunctionWithNoArgsAndNoArgs_returnsSuccess() throws URISyntaxException { - Calculator processor = LPFCPJava.getProcessor(Calculator.class, new URI("http://localhost:" + port + "/lpfcp")); - String response = processor.hello(); - assertEquals("Hello, World!", response); - } - - @Test public void ktorServer_withValidFunctionAndArgs_returnsSuccess() { - Calculator processor = LPFCPJava.getProcessor(Calculator.class, "http://localhost:" + port + "/lpfcp"); - Integer response = processor.add(3, 5); - assertEquals(8, response); - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts deleted file mode 100644 index 884a43b..0000000 --- a/settings.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -rootProject.name = "lpfcp" -include("core") -include("ktor") \ No newline at end of file