Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jSnapLoader: basic code and architecture #1

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions logo-by-sgvrepo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 15 additions & 8 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/7.6/userguide/multi_project_builds.html
*/
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}

rootProject.name = 'jSnapLoader'
include('snaploader')
include('snaploader-examples')
12 changes: 12 additions & 0 deletions snaploader-examples/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'application'
}

application {
mainClass = 'com.avrsandbox.snaploader.examples.TestBasicFeatures'
}

dependencies {
implementation project(path: ':snaploader')
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2023, AvrSandbox, jSnapLoader
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.avrsandbox.snaploader.examples;

import com.avrsandbox.snaploader.LibraryInfo;
import com.avrsandbox.snaploader.NativeBinaryLoader;

public final class TestBasicFeatures {

private static final String userdir = System.getProperty("user.dir");
private static final String fileSeparator = System.getProperty("file.separator");
private static final String jar = "jme3-alloc-desktop-1.0.0-pre-gamma-2.jar";
private static final String libraryBasename = "jmealloc";

private static final String libraryAbsolutePath = userdir + fileSeparator + "libs";
private static final String jarFile = libraryAbsolutePath + fileSeparator + jar;
private static final LibraryInfo libraryInfo = new LibraryInfo(jarFile, null, libraryBasename, libraryAbsolutePath);

public static void main(String[] args) {
new NativeBinaryLoader(libraryInfo).loadLibraryIfEnabled();
}
}
25 changes: 0 additions & 25 deletions snaploader/build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java library 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/7.6/userguide/building_java_projects.html
*/

plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
}

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

dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'

// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'

// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:31.1-jre'
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
44 changes: 34 additions & 10 deletions snaploader/src/main/java/com/avrsandbox/snaploader/LibraryInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,65 @@
*
* @author pavl_g
*/
public enum LibraryInfo {

/**
* Represents the default basename to the native binary.
*/
LIBRARY("");
public final class LibraryInfo {

private String jarPath;
private String directory;
private String baseName;
private String extractionDir;

/**
* Wraps information about the library.
* Instantiates a library info data structure pointing to a library in an external jar with jarPath.
*
* @param jarPath a path to an external jar to locate the library inside, "null" to use the project jar (classpath).
* @param baseName the library basename, for example: 'lib-basename.so'.
*/
LibraryInfo(final String baseName) {
public LibraryInfo(String jarPath, String directory, String baseName, String extractionDir) {
this.jarPath = jarPath;
this.directory = directory;
this.baseName = baseName;
this.extractionDir = extractionDir;
}

/**
* Retrieves the dynamic library basename.
* Default is [jmealloc].
*
* @return the library base-name in string
*/
public String getBaseName() {
return baseName;
}

public String getJarPath() {
return jarPath;
}

public String getDirectory() {
return directory;
}

public String getExtractionDir() {
return extractionDir;
}

public void setJarPath(String jarPath) {
this.jarPath = jarPath;
}

public void setDirectory(String directory) {
this.directory = directory;
}

/**
* Adjusts the library base name in a dynamic library name (lib-[basename]).
* Default is [jmealloc].
*
* @param baseName a new base-name to assign
*/
public void setBaseName(final String baseName) {
this.baseName = baseName;
}

public void setExtractionDir(String extractionDir) {
this.extractionDir = extractionDir;
}
}
Loading