Skip to content

Commit

Permalink
Java example for 0.15.2 (#1028)
Browse files Browse the repository at this point in the history
* new java project, but old source code

* update self tests for the example app

* fix test workflow, fix Makefile
  • Loading branch information
radetsky authored Oct 4, 2023
1 parent 4193cbc commit 3692085
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 169 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test-java.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ jobs:
java-example:
name: Example project – JavaThemis
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Install system dependencies
run: |
sudo sh -c 'echo "DEBIAN_FRONTEND=noninteractive" >> /etc/environment'
sudo apt update
sudo apt install --yes gcc make libssl-dev default-jdk
sudo apt install --yes gcc make libssl-dev default-jdk dpkg-dev
- name: Check out code
uses: actions/checkout@v2
- name: Install Themis Core with JNI
Expand All @@ -128,10 +128,10 @@ jobs:
- name: Build JavaThemis example
run: |
cd docs/examples/java
./gradlew --no-daemon build
JAVA_TOOL_OPTIONS=-Djava.library.path=/usr/local/lib ./gradlew --no-daemon build
# Thus runs a bit of an abomination: Themis Core and JNI libs are built
# from source while JavaThemis binaries are installed from Maven Central.
- name: Run JavaThemis example
run: |
cd docs/examples/java
java -Djava.library.path=/usr/local/lib -jar app/build/libs/app.jar
JAVA_TOOL_OPTIONS=-Djava.library.path=/usr/local/lib ./gradlew --no-daemon run
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ LDFLAGS += -L/usr/local/lib
# Build shared libraries
CFLAGS += -fPIC

#----- Mode packaging ----------------------------------------------------------
# Default value is not packaging mode. Goals: dev, rpm, deb_php will set it to 1
MODE_PACKAGING = 0


########################################################################
#
# Pretty-printing utilities
Expand Down
7 changes: 7 additions & 0 deletions docs/examples/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Java example

## Run
```
JAVA_TOOL_OPTIONS=-Djava.library.path=/opt/homebrew/lib ./gradlew run
```

41 changes: 25 additions & 16 deletions docs/examples/java/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
apply plugin: 'java'
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/8.0.2/userguide/building_java_projects.html
*/

plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
implementation 'com.cossacklabs.com:java-themis:0.14.0'
}
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'

sourceSets {
main {
java.srcDirs = ["src"]
}
// This dependency is used by the application.
implementation 'com.google.guava:guava:31.1-jre'
implementation("com.cossacklabs.com:java-themis:0.15.2")
}

// Pack *everything* into JAR, including dependencies and their dependencies.
// By default this will pack only local classes, compiled here.
jar {
manifest {
attributes "Main-Class": "main"
}
application {
// Define the main class for the application.
mainClass = 'java_themis_example.App'
}

from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package java_themis_example;

import com.cossacklabs.themis.*;

import java.io.IOException;
Expand All @@ -8,7 +13,7 @@
import java.util.Base64;


public class main {
public class App {

static Charset charset = StandardCharsets.UTF_8;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package java_themis_example;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class AppTest {
@Test void appDoesNotThrow() {
App classUnderTest = new App();
assertDoesNotThrow(() -> App.encryptDataForStoring(), "encryptDataForStoring() should run without exceptions");
assertDoesNotThrow(() -> App.encryptDataForMessaging(), "encryptDataForMessaging() should run without exceptions");
}
}


17 changes: 0 additions & 17 deletions docs/examples/java/build.gradle

This file was deleted.

Binary file modified docs/examples/java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/examples/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 20 16:40:39 EET 2021
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 3692085

Please sign in to comment.