Commit 34632a31 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Base work on emulated runtime shelf.

parent 747c6de3
Pipeline #44277 passed with stages
in 1 minute and 40 seconds
<component name="CopyrightManager">
<settings default="DefaultCopyright">
<settings>
<module2copyright>
<element module="Non-Project Files" copyright="DefaultCopyright" />
</module2copyright>
<LanguageOptions name="JAVA">
<option name="fileTypeOverride" value="3" />
<option name="block" value="false" />
......@@ -8,4 +11,4 @@
<option name="block" value="false" />
</LanguageOptions>
</settings>
</component>
</component>
\ No newline at end of file
......@@ -9,12 +9,24 @@
#include "squirreljme.h"
#define RUNTIME_CLASSNAME "cc/squirreljme/emulator/EmulatedRuntimeShelf"
#define RUNTIME_VMDESCRIPTION_DESC "(I)Ljava/lang/String"
JNIEXPORT void JNICALL Impl_mle_RuntimeShelf_garbageCollect(
JNIEnv* env, jclass classy)
{
// Does nothing
}
JNIEXPORT jstring JNICALL Impl_mle_RuntimeShelf_vmDescription(
JNIEnv* env, jclass classy, jint id)
{
return (jstring)forwardCallStaticObject(env, RUNTIME_CLASSNAME,
"vmDescription", RUNTIME_VMDESCRIPTION_DESC,
id);
}
JNIEXPORT jint JNICALL Impl_mle_RuntimeShelf_lineEnding(JNIEnv*, jclass)
{
#if defined(_WIN32)
......@@ -34,6 +46,7 @@ static const JNINativeMethod mleRuntimeMethods[] =
{
{"garbageCollect", "()V", (void*)Impl_mle_RuntimeShelf_garbageCollect},
{"lineEnding", "()I", (void*)Impl_mle_RuntimeShelf_lineEnding},
{"vmDescription", RUNTIME_VMDESCRIPTION_DESC, (void*)Impl_mle_RuntimeShelf_vmDescription},
{"vmType", "()I", (void*)Impl_mle_RuntimeShelf_vmType},
};
......
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.emulator;
import cc.squirreljme.jvm.mle.RuntimeShelf;
import cc.squirreljme.jvm.mle.constants.VMDescriptionType;
import cc.squirreljme.jvm.mle.exceptions.MLECallError;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Emulated shelf for {@link RuntimeShelf}.
*
* @since 2021/08/08
*/
public class EmulatedRuntimeShelf
{
/**
* Same as {@link RuntimeShelf#vmDescription(int)}.
*
* @param __type One of {@link VMDescriptionType}.
* @return The string for the given description or {@code null} if not
* set.
* @throws MLECallError If {@code __type} is not valid.
* @since 2020/06/17
*/
public static String vmDescription(int __type)
throws MLECallError
{
switch (__type)
{
case VMDescriptionType.UNSPECIFIED:
return null;
case VMDescriptionType.VM_VERSION:
return System.getProperty("java.vm.version");
case VMDescriptionType.VM_NAME:
return System.getProperty("java.vm.name");
case VMDescriptionType.VM_VENDOR:
return System.getProperty("java.vm.vendor");
case VMDescriptionType.VM_EMAIL:
return System.getProperty("java.vm.vendor.email");
case VMDescriptionType.VM_URL:
return System.getProperty("java.vm.vendor.url");
case VMDescriptionType.EXECUTABLE_PATH:
return null;
case VMDescriptionType.OS_NAME:
return System.getProperty("os.name");
case VMDescriptionType.OS_VERSION:
return System.getProperty("os.version");
case VMDescriptionType.OS_ARCH:
return System.getProperty("os.arch");
case VMDescriptionType.VM_SECURITY_POLICY:
return null;
case VMDescriptionType.COMPLEX_DRIVER_LIST:
return null;
default:
throw new MLECallError("Invalid " + __type);
}
}
}
......@@ -59,7 +59,7 @@ public final class ComplexDriverLoader
* @throws NullPointerException On null arguments.
* @since 2021/08/05
*/
public static <F extends ComplexDriverFactory> F factoryInstance(
public static <F extends ComplexDriverFactory> F factory(
Class<F> __class)
throws NullPointerException
{
......@@ -295,12 +295,16 @@ public final class ComplexDriverLoader
if (result != null)
return result;
// No actual drivers?
String rawList = RuntimeShelf.vmDescription(
VMDescriptionType.COMPLEX_DRIVER_LIST);
if (rawList == null || rawList.isEmpty())
return null;
// Working result
List<ComplexDriverPair> working = new ArrayList<>();
// Split the raw list accordingly to find services
String rawList = RuntimeShelf.vmDescription(
VMDescriptionType.COMPLEX_DRIVER_LIST);
for (int at = 0, n = rawList.length(); at < n;)
{
// Find the end of the string
......
......@@ -224,6 +224,11 @@ final class __ServiceLoaderFreshIterator__<S>
if (ln == null)
break;
//
int commentChar = ln.charAt('#');
if (commentChar >= 0)
ln = ln.substring(0, commentChar);
// Trim the line to remove useless spaces
ln = ln.trim();
......@@ -231,10 +236,6 @@ final class __ServiceLoaderFreshIterator__<S>
if (ln.isEmpty())
continue;
// Ignore comments
if (ln.charAt(0) == '#')
continue;
// Add otherwise
classes.add(ln);
}
......
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
/**
* Tests for SquirrelJME specific language details.
*
* @since 2021/08/08
*/
package squirreljme.lang;
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package squirreljme.util;
import cc.squirreljme.runtime.cldc.lang.ComplexDriverFactory;
/**
* Interface for fake drivers.
*
* @since 2021/08/08
*/
public interface FakeDriverInterface
extends ComplexDriverFactory
{
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package squirreljme.util;
/**
* First leveled factory.
*
* @since 2021/08/08
*/
public class FakeFirstDriverFactory
implements FakeDriverInterface
{
/**
* {@inheritDoc}
* @since 2021/08/08
*/
@Override
public <I> I instance(Class<I> __class)
{
return null;
}
/**
* {@inheritDoc}
* @since 2021/08/08
*/
@Override
public String name()
{
return "fake.first";
}
/**
* {@inheritDoc}
* @since 2021/08/08
*/
@Override
public int priority()
{
return MAX_PRIORITY;
}
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package squirreljme.util;
import cc.squirreljme.runtime.cldc.lang.ComplexDriverFactory;
/**
* Last leveled factory.
*
* @since 2021/08/08
*/
public class FakeLastDriverFactory
implements FakeDriverInterface
{
/**
* {@inheritDoc}
* @since 2021/08/08
*/
@Override
public <I> I instance(Class<I> __class)
{
return null;
}
/**
* {@inheritDoc}
* @since 2021/08/08
*/
@Override
public String name()
{
return "fake.last";
}
/**
* {@inheritDoc}
* @since 2021/08/08
*/
@Override
public int priority()
{
return ComplexDriverFactory.MIN_PRIORITY;
}
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package squirreljme.util;
import cc.squirreljme.runtime.cldc.lang.ComplexDriverFactory;
/**
* Interface for no actual driver.
*
* @since 2021/08/08
*/
public interface NoDriverInterface
extends ComplexDriverFactory
{
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package squirreljme.util;
import cc.squirreljme.runtime.cldc.lang.ComplexDriverLoader;
import net.multiphasicapps.tac.TestRunnable;
/**
* Tests that drivers can be loaded.
*
* @since 2021/08/08
*/
public class TestDriverLoad
extends TestRunnable
{
/**
* {@inheritDoc}
*
* @since 2021/08/08
*/
@Override
public void test()
{
NoDriverInterface none =
ComplexDriverLoader.<NoDriverInterface>factory(
NoDriverInterface.class);
this.secondary("none", none == null);
FakeDriverInterface found =
ComplexDriverLoader.<FakeDriverInterface>factory(
FakeDriverInterface.class);
this.secondary("first",
found.getClass() == FakeFirstDriverFactory.class);
}
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
/**
* Tests for general utilities.
*
* @since 2021/08/08
*/
package squirreljme.util;
squirreljme.util.FakeFirstDriverFactory
squirreljme.lang.FakeLastDriverFactory
util.serviceloader.impls.CuteSquirrels
util.serviceloader.impls.ComfortableDrey
# This is a comment!
util.serviceloader.impls.StashTheAcorns
util.serviceloader.impls.CuteSquirrels # and squirrels are very cute!
util.serviceloader.impls.ComfortableDrey
# Wasting extra space!
Manifest-Version: 1.0
result: NoResult
thrown: NoExceptionThrown
secondary-none: none
secondary-first: true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment