Skip to content

Commit

Permalink
Merge pull request #3 from attiasas/add_desktop_publish
Browse files Browse the repository at this point in the history
Add publish/distribute to desktop platform
  • Loading branch information
attiasas committed Aug 25, 2023
2 parents ad0f99f + 64dba14 commit 0f673ce
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "11"
java-version: "16"

- name: Clone core library
run: git clone https://github.com/attiasas/open-interactive-simulation-core.git core-repo
Expand Down
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@
## Table of Contents
- [📚 Overview](#-overview)
- [📦 Installation](#-installation)
- [🏗️ Usage](#-usage)
- [🐞 Reporting Issues](#-reporting-issues)
- [🤝 Contributions](#-contributions)

---
## 📚 Overview

This project is built on the [LibGdx](https://libgdx.com/) framework and provides the capability to run OIS projects on various platforms. It achieves this by utilizing the [OIS core](https://github.com/attiasas/open-interactive-simulation-core) library, which defines an API for seamless execution of different OIS projects along this project.

To streamline deployment, we've developed the [OIS deployer](https://github.com/attiasas/open-interactive-simulation-deployer) Gradle plugin. This plugin leverages the platform's features to facilitate the deployment of OIS projects on specific platforms based on your requirements by using this project.

## 📦 Installation

The project is not available in Maven central, required to be used locally

<details>
### 🚥 Requirements
* Java version `15` or a more recent release.
* Gradle version `7` or a newer version.

---
<summary>Install locally OIS core library</summary>
## 📦 Installation

The project is not available in Maven central, required to be used locally
Install locally OIS core library:

1. Clone the [core library](https://github.com/attiasas/open-interactive-simulation-core)
```bash
Expand All @@ -39,16 +43,31 @@ The project is not available in Maven central, required to be used locally
```

---
</details>
## 🏗️ Usage

Each sub module coresponse to a different project that is used to run/deploy to a specific platform.
Use the task configured by the project.

Configure the following environment variables:
### Running
When running the gradle commands configure the following environment variables:

| Environment Variable | Description |
|----------------------|---------------------------------------------------------|
| Environment Variable | Description |
|-----------------------------|---------------------------------------------------------|
| OIS_ENV_PROJECT_CONFIG_PATH | path to the `simulation.ois` project configuration file |
| OIS_ENV_PROJECT_JAR_PATH | path to the OIS project Jar location |
| OIS_ENV_PROJECT_ASSETS_DIR | (Optional) path to your project resource directory |
| OIS_ENV_PROJECT_JAR_PATH | path to the OIS project Jar location |
| OIS_ENV_PROJECT_ASSETS_DIR | (Optional) path to your project resource directory |

### Distributing
When running the gradle commands configure the following environment variables:

| Environment Variable | Description |
|--------------------------|------------------------------------------|
| OIS_ENV_PROJECT_NAME | the base name of the generated artifacts |
| OIS_ENV_PROJECT_JAR_PATH | path to the OIS project Jar location |

The resources needs to be placed at the `assets` directory at the root project
Create a directory named `.ois` and place the `simulation.ois` file inside.
Icons may be placed inside an `icons` directory.

## 🐞 Reporting Issues

Expand All @@ -61,4 +80,4 @@ by [reporting any issues](https://github.com/attiasas/open-interactive-simulatio
## 🤝 Contributions

We welcome pull requests from the community. To help us improve this project, please read
our [Contribution](./CONTRIBUTING.md#-guidelines) guide.
our [Contribution](./CONTRIBUTING.md) guide.
Empty file added assets/aOISProjectResource
Empty file.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {

allprojects {
group 'org.attias.open.interactive.simulation'
version '1.0-SNAPSHOT'
version '1.0.0'

ext {
gdxVersion = '1.12.0'
Expand All @@ -39,6 +39,8 @@ project(":desktop-runner") {
apply plugin: "java-library"

dependencies {
api files(System.getenv('OIS_ENV_PROJECT_JAR_PATH') ?: '..\\assets\\.ois\\dynamic.jar')

api "org.attias.open.interactive.simulation:open-interactive-simulation-core:$coreVersion"
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
Expand Down
59 changes: 41 additions & 18 deletions desktop-runner/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
plugins { id 'org.beryx.runtime' version '1.8.4' }

mainClassName = "org.attias.open.interactive.simulation.desktop.DesktopLauncher"
def osName = System.getProperty('os.name').toLowerCase(Locale.ROOT)

ext {
mainClassName = "org.attias.open.interactive.simulation.desktop.DesktopLauncher"
assetsDir = null
assetsDir = new File("../assets")
}

gradle.projectsEvaluated {
Expand All @@ -9,35 +13,25 @@ gradle.projectsEvaluated {
def assetsDirFile = new File(assetDirPath)
if (assetsDirFile.exists() && assetsDirFile.isDirectory()) {
assetsDir = assetsDirFile
sourceSets.main.resources.srcDirs = [assetsDirFile]
println "Assets directory set to: ${assetsDirFile.absolutePath}"
} else {
println "Warning: The specified asset directory does not exist or is not a directory."
}
} else {
println "Warning: Environment variable IOS_ENV_PROJECT_ASSETS_DIR not set."
}
println "Assets directory set to: ${assetsDir.absolutePath}"
sourceSets.main.resources.srcDirs = [assetsDir]
}

task run(dependsOn: classes, type: JavaExec) {
task runSimulation(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
if (project.assetsDir != null) {
println "workingDir set to Assets directory: ${project.assetsDir.absolutePath}"
workingDir = project.assetsDir
}
workingDir = project.assetsDir
ignoreExitValue = true
}

task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
if (project.assetsDir != null) {
println "workingDir set to Assets directory: ${project.assetsDir.absolutePath}"
workingDir = project.assetsDir
}
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
Expand All @@ -46,11 +40,40 @@ task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
duplicatesStrategy = 'include'
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
archiveFileName = System.getenv('OIS_ENV_PROJECT_NAME') + '.jar'
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
destinationDirectory = file("$buildDir/lib")
}

jpackageImage.dependsOn dist
dist.dependsOn classes

runtime {
options = ['--strip-debug',
'--compress', '2',
'--no-header-files',
'--no-man-pages',
'--strip-native-commands',
'--vm', 'server']
modules = ['java.base' ,
'java.desktop',
'jdk.unsupported']
distDir = file(buildDir)

jpackage {
//jpackageHome = '/usr/lib/jvm/open-jdk'
mainJar = dist.archiveFileName.get()
if (osName.contains('windows')) {
imageOptions = ["--icon", file("../assets/.ois/icons/icon128.ico")]
} else if (osName.contains('linux')) {
imageOptions = ["--icon", file("../assets/.ois/icons/icon128.png")]
} else if (osName.contains('mac')) {
imageOptions = ["--icon", file("../assets/.ois/icons/icon128.icns")]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.attias.open.interactive.simulation.desktop;

import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import org.attias.open.interactive.simulation.core.backend.engine.AppConfiguration;
import org.attias.open.interactive.simulation.core.backend.engine.InteractiveSimulationEngine;
import org.attias.open.interactive.simulation.core.backend.utils.ProjectUtils;

import java.io.IOException;

Expand All @@ -14,11 +16,35 @@ public static void main (String[] arg) throws IOException {
}

public static AppConfiguration getConfigurations(LwjglApplicationConfiguration config) throws IOException {
AppConfiguration appConfiguration = AppConfiguration.getFromEnvironment();
AppConfiguration appConfiguration = AppConfiguration.getRunnerConfigurations();

appConfiguration.setType(AppConfiguration.AppType.Desktop);
config.title = appConfiguration.getProjectConfiguration().name;
config.title = appConfiguration.getProjectConfiguration().title;

addIcons(config);

return appConfiguration;
}

public static void addIcons(LwjglApplicationConfiguration config) {
if (System.getenv("OIS_ENV_PROJECT_ASSETS_DIR") != null) {
// Running not in publish mode
return;
}
String extension = ".png";
String osName = System.getenv("os.name");
if (osName != null && osName.contains("darwin")) {
extension = ".icns";
}
int[] sizes = new int[]{128, 32};
System.out.println("Loading icons");
for (int size : sizes) {
try {
System.out.println("loading icon" + extension + ": " + size);
config.addIcon(ProjectUtils.OIS_DIRECTORY_NAME + "/icons/icon" + size + extension, Files.FileType.Internal);
} catch (Exception e) {
System.out.println("found exception");
}
}
}
}

0 comments on commit 0f673ce

Please sign in to comment.