summaryrefslogtreecommitdiffstats
path: root/jvmaccess
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /jvmaccess
parentInitial commit. (diff)
downloadlibreoffice-cb75148ebd0135178ff46f89a30139c44f8d2040.tar.xz
libreoffice-cb75148ebd0135178ff46f89a30139c44f8d2040.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--jvmaccess/IwyuFilter_jvmaccess.yaml6
-rw-r--r--jvmaccess/Library_jvmaccess.mk33
-rw-r--r--jvmaccess/Makefile7
-rw-r--r--jvmaccess/Module_jvmaccess.mk23
-rw-r--r--jvmaccess/README.md4
-rw-r--r--jvmaccess/source/classpath.cxx108
-rw-r--r--jvmaccess/source/unovirtualmachine.cxx79
-rw-r--r--jvmaccess/source/virtualmachine.cxx119
-rw-r--r--jvmaccess/workbench/exceptiontest1.cxx40
-rw-r--r--jvmaccess/workbench/exceptiontest2.cxx40
-rw-r--r--jvmaccess/workbench/java/TestComponent.java89
-rw-r--r--jvmaccess/workbench/java/makefile.mk34
-rw-r--r--jvmaccess/workbench/java/manifest1
-rw-r--r--jvmaccess/workbench/javainfo/javainfotest.cxx363
-rw-r--r--jvmaccess/workbench/javainfo/makefile.mk34
-rw-r--r--jvmaccess/workbench/makefile.mk42
16 files changed, 1022 insertions, 0 deletions
diff --git a/jvmaccess/IwyuFilter_jvmaccess.yaml b/jvmaccess/IwyuFilter_jvmaccess.yaml
new file mode 100644
index 000000000..7d437137b
--- /dev/null
+++ b/jvmaccess/IwyuFilter_jvmaccess.yaml
@@ -0,0 +1,6 @@
+---
+assumeFilename: jvmaccess/source/classpath.cxx
+excludelist:
+ jvmaccess/source/classpath.cxx:
+ # Needed to inherit linker visibility from function declaration
+ - jvmaccess/classpath.hxx
diff --git a/jvmaccess/Library_jvmaccess.mk b/jvmaccess/Library_jvmaccess.mk
new file mode 100644
index 000000000..b4ef50a7d
--- /dev/null
+++ b/jvmaccess/Library_jvmaccess.mk
@@ -0,0 +1,33 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+
+$(eval $(call gb_Library_Library,jvmaccess))
+
+$(eval $(call gb_Library_add_defs,jvmaccess,\
+ -DJVMACCESS_DLLIMPLEMENTATION \
+))
+
+$(eval $(call gb_Library_use_api,jvmaccess,\
+ udkapi \
+))
+
+$(eval $(call gb_Library_use_libraries,jvmaccess,\
+ cppu \
+ cppuhelper \
+ sal \
+ salhelper \
+))
+
+$(eval $(call gb_Library_add_exception_objects,jvmaccess,\
+ jvmaccess/source/classpath \
+ jvmaccess/source/unovirtualmachine \
+ jvmaccess/source/virtualmachine \
+))
+
+# vim:set noet sw=4 ts=4:
diff --git a/jvmaccess/Makefile b/jvmaccess/Makefile
new file mode 100644
index 000000000..ccb1c85a0
--- /dev/null
+++ b/jvmaccess/Makefile
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+
+module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
+
+include $(module_directory)/../solenv/gbuild/partial_build.mk
+
+# vim: set noet sw=4 ts=4:
diff --git a/jvmaccess/Module_jvmaccess.mk b/jvmaccess/Module_jvmaccess.mk
new file mode 100644
index 000000000..f0a1705a8
--- /dev/null
+++ b/jvmaccess/Module_jvmaccess.mk
@@ -0,0 +1,23 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+
+$(eval $(call gb_Module_Module,jvmaccess))
+
+ifeq ($(ENABLE_JAVA),TRUE)
+
+$(eval $(call gb_Module_add_targets,jvmaccess,\
+))
+
+$(eval $(call gb_Module_add_targets,jvmaccess,\
+ Library_jvmaccess \
+))
+
+endif
+
+# vim:set noet sw=4 ts=4:
diff --git a/jvmaccess/README.md b/jvmaccess/README.md
new file mode 100644
index 000000000..f035e8f96
--- /dev/null
+++ b/jvmaccess/README.md
@@ -0,0 +1,4 @@
+# JVM Access Wrappers
+
+Wrappers so you can use all the Java Runtime Environments with their slightly
+incompatible APIs with more ease.
diff --git a/jvmaccess/source/classpath.cxx b/jvmaccess/source/classpath.cxx
new file mode 100644
index 000000000..95915196b
--- /dev/null
+++ b/jvmaccess/source/classpath.cxx
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <jvmaccess/classpath.hxx>
+
+#include <cassert>
+#include <vector>
+
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/XInterface.hpp>
+#include <com/sun/star/uri/UriReferenceFactory.hpp>
+#include <com/sun/star/uri/XVndSunStarExpandUrlReference.hpp>
+#include <com/sun/star/util/theMacroExpander.hpp>
+#include <cppuhelper/exc_hlp.hxx>
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+#include <o3tl/string_view.hxx>
+
+#include <jni.h>
+
+namespace com::sun::star::uno { class XComponentContext; }
+
+jobjectArray jvmaccess::ClassPath::translateToUrls(
+ css::uno::Reference< css::uno::XComponentContext > const & context,
+ JNIEnv * environment, std::u16string_view classPath)
+{
+ assert(context.is());
+ assert(environment != nullptr);
+ jclass classUrl(environment->FindClass("java/net/URL"));
+ if (classUrl == nullptr) {
+ return nullptr;
+ }
+ jmethodID ctorUrl(
+ environment->GetMethodID(classUrl, "<init>", "(Ljava/lang/String;)V"));
+ if (ctorUrl == nullptr) {
+ return nullptr;
+ }
+ ::std::vector< jobject > urls;
+ for (::sal_Int32 i = 0; i != -1;) {
+ OUString url(o3tl::getToken(classPath, 0, ' ', i));
+ if (!url.isEmpty()) {
+ css::uno::Reference< css::uri::XVndSunStarExpandUrlReference >
+ expUrl(
+ css::uri::UriReferenceFactory::create(context)->parse(url),
+ css::uno::UNO_QUERY);
+ if (expUrl.is()) {
+ css::uno::Reference< css::util::XMacroExpander > expander =
+ css::util::theMacroExpander::get(context);
+ try {
+ url = expUrl->expand( expander );
+ } catch (const css::lang::IllegalArgumentException & e) {
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ nullptr, anyEx );
+ }
+ }
+ jvalue arg;
+ arg.l = environment->NewString(
+ reinterpret_cast< jchar const * >(url.getStr()),
+ static_cast< jsize >(url.getLength()));
+ if (arg.l == nullptr) {
+ return nullptr;
+ }
+ jobject o(environment->NewObjectA(classUrl, ctorUrl, &arg));
+ if (o == nullptr) {
+ return nullptr;
+ }
+ urls.push_back(o);
+ }
+ }
+ jobjectArray result = environment->NewObjectArray(
+ static_cast< jsize >(urls.size()), classUrl, nullptr);
+ // static_cast is ok, as each element of urls occupied at least one
+ // character of the OUString classPath
+ if (result == nullptr) {
+ return nullptr;
+ }
+ jsize idx = 0;
+ for (auto const& url : urls)
+ {
+ environment->SetObjectArrayElement(result, idx++, url);
+ }
+ return result;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmaccess/source/unovirtualmachine.cxx b/jvmaccess/source/unovirtualmachine.cxx
new file mode 100644
index 000000000..08bfbcdcf
--- /dev/null
+++ b/jvmaccess/source/unovirtualmachine.cxx
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <jvmaccess/unovirtualmachine.hxx>
+
+#include <jvmaccess/virtualmachine.hxx>
+#include <sal/log.hxx>
+#include <utility>
+
+#include <jni.h>
+
+namespace jvmaccess {
+
+UnoVirtualMachine::CreationException::CreationException() {}
+
+UnoVirtualMachine::CreationException::CreationException(
+ CreationException const &)
+{}
+
+UnoVirtualMachine::CreationException &
+UnoVirtualMachine::CreationException::operator =(CreationException const &) {
+ return *this;
+}
+
+UnoVirtualMachine::UnoVirtualMachine(
+ rtl::Reference< jvmaccess::VirtualMachine > virtualMachine,
+ void * classLoader):
+ m_virtualMachine(std::move(virtualMachine)),
+ m_classLoader(nullptr)
+{
+ try {
+ m_classLoader =
+ jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
+ getEnvironment()->NewGlobalRef(static_cast< jobject >(classLoader));
+ } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {}
+ if (m_classLoader == nullptr) {
+ throw CreationException();
+ }
+}
+
+const rtl::Reference< jvmaccess::VirtualMachine >&
+UnoVirtualMachine::getVirtualMachine() const {
+ return m_virtualMachine;
+}
+
+UnoVirtualMachine::~UnoVirtualMachine() {
+ try {
+ jvmaccess::VirtualMachine::AttachGuard(m_virtualMachine).
+ getEnvironment()->DeleteGlobalRef(
+ static_cast< jobject >(m_classLoader));
+ } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {
+ SAL_INFO(
+ "jvmaccess",
+ "ignored"
+ " jvmaccess::VirtualMachine::AttachGuard::CreationException");
+ }
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmaccess/source/virtualmachine.cxx b/jvmaccess/source/virtualmachine.cxx
new file mode 100644
index 000000000..eb4b8069c
--- /dev/null
+++ b/jvmaccess/source/virtualmachine.cxx
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <cassert>
+
+#include <jvmaccess/virtualmachine.hxx>
+#include <sal/log.hxx>
+#include <utility>
+
+using jvmaccess::VirtualMachine;
+
+VirtualMachine::AttachGuard::CreationException::CreationException()
+{}
+
+VirtualMachine::AttachGuard::CreationException::CreationException(
+ CreationException const &)
+{}
+
+VirtualMachine::AttachGuard::CreationException &
+VirtualMachine::AttachGuard::CreationException::operator =(
+ CreationException const &)
+{
+ return *this;
+}
+
+VirtualMachine::AttachGuard::AttachGuard(
+ rtl::Reference< VirtualMachine > xMachine):
+ m_xMachine(std::move(xMachine))
+{
+ assert(m_xMachine.is());
+ m_pEnvironment = m_xMachine->attachThread(&m_bDetach);
+ if (m_pEnvironment == nullptr)
+ throw CreationException();
+}
+
+VirtualMachine::AttachGuard::~AttachGuard()
+{
+ if (m_bDetach)
+ m_xMachine->detachThread();
+}
+
+VirtualMachine::VirtualMachine(JavaVM * pVm, int nVersion, bool bDestroy,
+ JNIEnv const * pMainThreadEnv):
+ m_pVm(pVm), m_nVersion(nVersion), m_bDestroy(bDestroy)
+{
+ (void) pMainThreadEnv; // avoid warnings
+ assert(pVm != nullptr);
+ assert(nVersion >= JNI_VERSION_1_2);
+ assert(pMainThreadEnv);
+}
+
+VirtualMachine::~VirtualMachine()
+{
+ if (m_bDestroy)
+ {
+ // Do not destroy the VM. Under Java 1.3, the AWT event loop thread is
+ // not a daemon thread and is never terminated, so that calling
+ // DestroyJavaVM (waiting for all non-daemon threads to terminate) hangs
+ // forever.
+/*
+ jint n = m_pVm->DestroyJavaVM();
+ SAL_WARN_IF(n != JNI_OK, "jvmaccess", "JNI: DestroyJavaVM failed");
+*/
+ }
+}
+
+JNIEnv * VirtualMachine::attachThread(bool * pAttached) const
+{
+ assert(pAttached != nullptr && "bad parameter");
+ JNIEnv * pEnv;
+ jint n = m_pVm->GetEnv(reinterpret_cast< void ** >(&pEnv), m_nVersion);
+ SAL_WARN_IF(
+ n != JNI_OK && n != JNI_EDETACHED, "jvmaccess", "JNI: GetEnv failed");
+ if (pEnv == nullptr)
+ {
+ if (m_pVm->AttachCurrentThread
+ (
+#ifndef ANDROID
+ reinterpret_cast< void ** >(&pEnv),
+#else
+ // The Android <jni.h> has AttachCurrentThread() taking a
+ // JNIEnv** and not void **
+ &pEnv,
+#endif
+ nullptr)
+ != JNI_OK)
+ return nullptr;
+ *pAttached = true;
+ }
+ else
+ *pAttached = false;
+ return pEnv;
+}
+
+void VirtualMachine::detachThread() const
+{
+ jint n = m_pVm->DetachCurrentThread();
+ SAL_WARN_IF(n != JNI_OK, "jvmaccess", "JNI: DetachCurrentThread failed");
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmaccess/workbench/exceptiontest1.cxx b/jvmaccess/workbench/exceptiontest1.cxx
new file mode 100644
index 000000000..adc2db719
--- /dev/null
+++ b/jvmaccess/workbench/exceptiontest1.cxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "jvmaccess/virtualmachine.hxx"
+
+#include <iostream>
+
+// Modify source/virtualmachine.cxx before running this test, by letting the
+// AttachGuard ctor directly throw a CreationExcepiton (without even setting the
+// m_xMachine member).
+
+int main()
+{
+ try
+ {
+ jvmaccess::VirtualMachine::AttachGuard aGuard(0);
+ }
+ catch (jvmaccess::VirtualMachine::AttachGuard::CreationException&)
+ {
+ std::cout << "Exception caught" << std::endl;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmaccess/workbench/exceptiontest2.cxx b/jvmaccess/workbench/exceptiontest2.cxx
new file mode 100644
index 000000000..dd45877c5
--- /dev/null
+++ b/jvmaccess/workbench/exceptiontest2.cxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "jvmaccess/virtualmachine.hxx"
+
+#include <iostream>
+
+// Modify source/virtualmachine.cxx before running this test, by letting the
+// AttachGuard ctor directly throw a CreationExcepiton (without even setting the
+// m_xMachine member).
+
+int main()
+{
+ try
+ {
+ jvmaccess::VirtualMachine::AttachGuard aGuard(0);
+ }
+ catch (...)
+ {
+ std::cout << "Exception caught" << std::endl;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmaccess/workbench/java/TestComponent.java b/jvmaccess/workbench/java/TestComponent.java
new file mode 100644
index 000000000..8e692a73b
--- /dev/null
+++ b/jvmaccess/workbench/java/TestComponent.java
@@ -0,0 +1,89 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.jvmaccess.workbench;
+
+import com.sun.star.comp.loader.FactoryHelper;
+import com.sun.star.lang.XMain;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.uno.Type;
+
+/* Deploy this component with pkgchk, and call it with the Basic program
+
+ Sub Main
+ dim args$()
+ o = createunoservice("com.sun.star.comp.jvmaccess.workbench.TestComponent")
+ o.run args$()
+ End Sub
+
+ The name of the context class loader should appear on the console.
+ */
+
+public final class TestComponent implements XTypeProvider, XServiceInfo, XMain {
+ public Type[] getTypes() {
+ return new Type[] { new Type(XTypeProvider.class),
+ new Type(XServiceInfo.class),
+ new Type(XMain.class) };
+ }
+
+ public byte[] getImplementationId() {
+ return new byte[0];
+ }
+
+ public String getImplementationName() {
+ return getClass().getName();
+ }
+
+ public boolean supportsService(String serviceName) {
+ return serviceName.equals(serviceName);
+ }
+
+ public String[] getSupportedServiceNames() {
+ return new String[] { serviceName };
+ }
+
+ public int run(String[] arguments) {
+ System.out.println("context class loader: "
+ + Thread.currentThread().getContextClassLoader());
+ return 0;
+ }
+
+ public static XSingleServiceFactory __getServiceFactory(
+ String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)
+ {
+ if (implName.equals(TestComponent.class.getName())) {
+ return FactoryHelper.getServiceFactory(TestComponent.class,
+ serviceName, multiFactory,
+ regKey);
+ } else {
+ return null;
+ }
+ }
+
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return FactoryHelper.writeRegistryServiceInfo(
+ TestComponent.class.getName(), serviceName, regKey);
+ }
+
+ private static final String serviceName
+ = "com.sun.star.comp.jvmaccess.workbench.TestComponent";
+}
diff --git a/jvmaccess/workbench/java/makefile.mk b/jvmaccess/workbench/java/makefile.mk
new file mode 100644
index 000000000..405eae95d
--- /dev/null
+++ b/jvmaccess/workbench/java/makefile.mk
@@ -0,0 +1,34 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+PRJ = ..$/..
+PRJNAME = jvmaccess
+TARGET = workbench_java
+
+PACKAGE = com$/sun$/star$/comp$/jvmaccess$/workbench
+
+.INCLUDE: settings.mk
+
+JARFILES = ridl.jar jurt.jar
+JAVACLASSFILES = $(CLASSDIR)$/$(PACKAGE)$/TestComponent.class
+JARCLASSDIRS = $(PACKAGE)
+JARTARGET = jvmaccesstestcomponent.jar
+JARCOMPRESS = TRUE
+CUSTOMMANIFESTFILE = manifest
+
+.INCLUDE: target.mk
diff --git a/jvmaccess/workbench/java/manifest b/jvmaccess/workbench/java/manifest
new file mode 100644
index 000000000..73b21eca3
--- /dev/null
+++ b/jvmaccess/workbench/java/manifest
@@ -0,0 +1 @@
+RegistrationClassName: com.sun.star.comp.jvmaccess.workbench.TestComponent
diff --git a/jvmaccess/workbench/javainfo/javainfotest.cxx b/jvmaccess/workbench/javainfo/javainfotest.cxx
new file mode 100644
index 000000000..b07db0105
--- /dev/null
+++ b/jvmaccess/workbench/javainfo/javainfotest.cxx
@@ -0,0 +1,363 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "jvmaccess/javainfo.hxx"
+
+#include "osl/file.hxx"
+#include "osl/thread.h"
+#include "rtl/ustring.hxx"
+
+#include <stdio.h>
+#include <vector>
+
+using namespace osl;
+
+using jvmaccess::JavaInfo;
+
+
+#define JAVA_VERSION "1.4.1_01"
+
+bool test_constructor1();
+bool test_constructor2();
+bool test_createAllInfo();
+bool test_compareVersions();
+bool test_createAllInfo();
+bool test_createBestInfo();
+bool test_isEqual();
+bool test_getJarFilePath();
+
+void printInfo(const JavaInfo& info);
+
+int main( int argc, char * argv[], char * envp[])
+{
+ const int arSize= 20;
+ bool arRet[arSize];
+ int i =0;
+ arRet[i++]= test_createAllInfo();
+ arRet[i++]= test_constructor1();
+ arRet[i++]= test_constructor2();
+
+ arRet[i++]= test_compareVersions();
+ arRet[i++]= test_createBestInfo();
+ arRet[i++]= test_isEqual();
+ arRet[i++]= test_getJarFilePath();
+ bool error= true;
+ for(int j= 0; j < i; j++)
+ error &= arRet[j];
+
+ if( error == false)
+ printf("Errors occurred\n");
+ return 0;
+}
+
+bool test_constructor1()
+{
+ printf("\ntest JavaInfo::JavaInfo(const OUString& usJavaHome\n" \
+ "!Check output for correctness\n\n");
+ try{
+ JavaInfo info("file:///d:/java/j2sdk1.4.1_01");
+// JavaInfo info("file:///local/jl/java/j2sdk1.4.0");
+// JavaInfo info("file:///usr/local2/jl/java/j2sdk1.4.0");
+
+ printInfo(info);
+ }catch( JavaInfo::InitException& )
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool test_constructor2()
+{
+ printf("\ntest JavaInfo::JavaInfo(const OUString& usVersion, int requirements)\n" \
+ "!Check output for correctness\n\n");
+ bool arRet[20];
+ int i= 0;
+
+ JavaInfo a("file:///d:/java/j2sdk1.4.1_01");
+// -----------------------------------------------------
+// JavaInfo a("file:///usr/local2/jl/java/j2sdk1.4.0");
+
+// JavaInfo a("file:///local/jl/java/j2sdk1.4.0");
+ try{
+ JavaInfo info= JavaInfo(OUString(), 0);
+ arRet[i++]= true;
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+ try{
+ // make sure it supports accessibility
+ JavaInfo info= JavaInfo(OUString(), JavaInfo::Accessibility);
+ arRet[i++]= info.supportsAccessibility();
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+
+ try{
+ JavaInfo info(OUString(JAVA_VERSION), JavaInfo::EqualVersion);
+ arRet[i++]= info.compareVersions(a) == 0;
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+ try{
+ JavaInfo info(OUString(JAVA_VERSION), 0);
+ arRet[i++]= info.compareVersions(a) == 0;
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+
+ try{
+ JavaInfo info(OUString(JAVA_VERSION), JavaInfo::EqualVersion | JavaInfo::GreaterVersion);
+ arRet[i++]= info.compareVersions(a) >= 0;
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+ try{
+ JavaInfo info(OUString(JAVA_VERSION), JavaInfo::EqualVersion | JavaInfo::SmallerVersion);
+ arRet[i++]= info.compareVersions(a) <= 0;
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+ try{
+ JavaInfo info(OUString(JAVA_VERSION), JavaInfo::SmallerVersion);
+ arRet[i++]= info.compareVersions(a) < 0;
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+ try{
+ JavaInfo info(OUString(JAVA_VERSION), JavaInfo::GreaterVersion);
+ arRet[i++]= info.compareVersions(a) > 0;
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+
+ try{
+ JavaInfo info(OUString(JAVA_VERSION), JavaInfo::EqualVersion | JavaInfo::SmallerVersion
+ | JavaInfo::Accessibility);
+ arRet[i++]= info.compareVersions(a) <= 0 && info.supportsAccessibility();
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+ try{
+ JavaInfo info(OUString(JAVA_VERSION), JavaInfo::GreaterVersion | JavaInfo::Accessibility);
+ arRet[i++]= info.compareVersions(a) > 0 && info.supportsAccessibility();
+ }
+ catch( ...) {
+ arRet[i++]= false;
+ }
+
+
+ bool err= true;
+ for(int j= 0; j < i; j++)
+ err &= arRet[j];
+ if( err)
+ printf("ok\n");
+ else
+ printf("failed\n");
+ return err;
+
+}
+
+bool test_createAllInfo()
+{
+ printf("\ntest JavaInfo::createAllInfo\n" \
+ "! Compare output with values in registry, PATH, JAVA_HOME, LD_LIBRARY_PATH !\n\n");
+ std::vector<JavaInfo> vec;
+ JavaInfo::createAllInfo(&vec);
+ for(std::vector<JavaInfo>::size_type i= 0; i < vec.size(); i++)
+ printInfo(vec[i]);
+ return true;
+}
+
+bool test_compareVersions()
+{
+ bool ret= false;
+ printf("\ntest JavaInfo::compareVersions \n" \
+ "! Check output for correctness\n\n");
+
+
+ JavaInfo a("file:///C:/Program%20Files/JavaSoft/JRE/1.3.1");
+ JavaInfo b("file:///C:/Program%20Files/JavaSoft/JRE/1.3.1_04");
+ JavaInfo c("file:///C:/Program%20Files/Java/j2re1.4.0_03");
+ JavaInfo d("file:///C:/Program%20Files/Java/j2re1.4.2_04");
+// JavaInfo e("file:///d:/java/j2sdk1.4.0_01");
+// JavaInfo f("file:///d:/java/j2sdk1.4.0_02");
+// JavaInfo g("file:///d:/java/j2sdk1.4.1");
+// JavaInfo h("file:///d:/java/j2sdk1.4.1_01");
+
+// JavaInfo a("file:///usr/local2/jl/java/j2re1_3_1_02");
+// JavaInfo b("file:///usr/local2/jl/java/j2sdk1.4.0");
+// JavaInfo c("file:///usr/local2/jl/java/j2sdk1.4.1");
+// JavaInfo d("file:///usr/local2/jl/java/j2re1.4.1_01");
+
+// JavaInfo a("file:///local/jl/java/jre1.3.1");
+// JavaInfo b("file:///local/jl/java/jdk1.3.1_04");
+// JavaInfo c("file:///local/jl/java/j2sdk1.4.0");
+// JavaInfo d("file:///local/jl/java/j2sdk1.4.1");
+// JavaInfo e("file:///local/jl/java/j2re1.4.1_01");
+// fprintf(stderr,"###ok1");
+
+ if( (a.compareVersions(a) == 0
+ && a.compareVersions(b) < 0
+ && a.compareVersions(c) < 0
+// && a.compareVersions(d) < 0
+// && a.compareVersions(e) < 0
+// && a.compareVersions(h) < 0
+ )
+ &&
+ (a.compareVersions(a)== 0))
+
+ ret= true;
+
+ if(ret &&
+ (b.compareVersions(a) > 0
+ && b.compareVersions(b) == 0
+ && b.compareVersions(c) < 0
+ && b.compareVersions(d) < 0
+// && b.compareVersions(e) < 0
+// && b.compareVersions(h) < 0))
+ ))
+ ret= true;
+
+ if(ret &&
+ ( d.compareVersions(a) > 0
+ && d.compareVersions(b) > 0
+ && d.compareVersions(c) > 0
+ && d.compareVersions(d) == 0
+// && d.compareVersions(e) < 0
+// && d.compareVersions(f) < 0
+// && d.compareVersions(g) < 0
+// && d.compareVersions(h) < 0))
+ ))
+ ret= true;
+
+// if(ret
+// && e.compareVersions(a) > 0
+// && e.compareVersions(b) > 0
+// && e.compareVersions(c) > 0
+// && e.compareVersions(d) > 0
+// && e.compareVersions(e) == 0
+// )
+
+
+// if(ret &&
+// (f.compareVersions(a) > 0
+// && f.compareVersions(c) > 0
+// && f.compareVersions(d) > 0
+// && f.compareVersions(g) < 0
+// && f.compareVersions(h) < 0))
+// ret= true;
+
+ if( ! ret)
+ printf("failed\n");
+ else
+ printf("ok\n");
+
+ return ret;
+}
+
+bool test_createBestInfo()
+{
+ printf("\ntest JavaInfo::createBestInfo\n" \
+ "! Check output for correctness\n\n");
+ JavaInfo info= JavaInfo::createBestInfo(false);
+ printInfo(info);
+ return true;
+}
+
+bool test_isEqual()
+{
+ printf("\ntest JavaInfo::isEqual\n");
+ JavaInfo a(JAVA_VERSION); // accessible
+ JavaInfo b(JAVA_VERSION);
+
+ JavaInfo c("file:///c:/local/r/j2sdk1.4.0");// not Accessible
+ JavaInfo d("file:///d:/java/copy_j2sdk1.4.0");
+
+// JavaInfo a("file:///usr/local2/jl/java/j2re1_3_1_02");
+// JavaInfo b("file:///usr/local2/jl/java/j2re1_3_1_02");
+
+// JavaInfo c("file:///usr/local2/jl/java/j2sdk1.4.1");
+// JavaInfo d("file:///usr/local2/jl/java/copyj2sdk1.4.1");
+
+// JavaInfo a("file:///local/jl/java/jre1.3.1");
+// JavaInfo b("file:///local/jl/java/jre1.3.1");
+// JavaInfo c("file:///local/jl/java/j2sdk1.4.1");
+// JavaInfo d("file:///local/jl/java/copyj2sdk1.4.1");
+
+ bool arRet[20];
+ int i= 0;
+ arRet[i++]= a.isEqual(b);
+ arRet[i++]= ! a.isEqual(c); //must fail
+ arRet[i++]= a.isEqual(d);
+
+ bool err= true;
+ for(int j= 0; j < i; j++)
+ err &= arRet[j];
+ if( arRet == false)
+ printf("failed\n");
+ else
+ printf("ok\n");
+ return err;
+}
+
+bool test_getJarFilePath()
+{
+ printf("\ntest JavaInfo::getJarFilePath\n");
+ JavaInfo info(OUString("1.3.1"), JavaInfo::GreaterVersion | JavaInfo::EqualVersion );
+ OUString s= info.getJarFilePath("javaplugin.jar");
+
+ printf("check if this URL is correct:\n");
+ OString oPath= OUStringToOString(s, osl_getThreadTextEncoding());
+ printf("%s\n", oPath.getStr());
+ return true;
+}
+
+void printInfo(const JavaInfo& info)
+{
+ OUString usVersion= info.getVersion();
+ OString sVersion= OUStringToOString( usVersion, osl_getThreadTextEncoding());
+ OUString usHome= info.getInstallationLocation();
+ OString sHome= OUStringToOString( usHome, osl_getThreadTextEncoding());
+ OUString usType= info.getType();
+ OString sType= OUStringToOString(usType, osl_getThreadTextEncoding());
+ OUString usLib= info.getRuntimeLibLocation();
+ OString sLib= OUStringToOString(usLib, osl_getThreadTextEncoding());
+ OUString usLibLocation= info.getLibLocations();
+ OString sLibLocation= OUStringToOString(usLibLocation, osl_getThreadTextEncoding());
+ sal_Bool baccess= info.supportsAccessibility();
+
+ printf("%s %s\n",sType.getStr(), sVersion.getStr());
+ printf("\t%s \n",sHome.getStr());
+ printf("\t%s \n",sLib.getStr());
+ printf("\tLibDir: %s \n", sLibLocation.getStr());
+ printf("\t%s\n", baccess ? "accessible" : "not accessible");
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jvmaccess/workbench/javainfo/makefile.mk b/jvmaccess/workbench/javainfo/makefile.mk
new file mode 100644
index 000000000..ebe6f0de5
--- /dev/null
+++ b/jvmaccess/workbench/javainfo/makefile.mk
@@ -0,0 +1,34 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+PRJ = ..$/..
+PRJNAME = jvmaccess
+TARGET = workbench_javainfo
+
+ENABLE_EXCEPTIONS = TRUE
+
+LIBTARGET = NO
+TARGETTYPE = CUI
+
+.INCLUDE: settings.mk
+
+APP1TARGET = $(TARGET)
+APP1OBJS = $(OBJ)$/javainfotest.obj
+APP1STDLIBS = $(CPPULIB) $(JVMACCESSLIB) $(SALLIB)
+
+.INCLUDE : target.mk
diff --git a/jvmaccess/workbench/makefile.mk b/jvmaccess/workbench/makefile.mk
new file mode 100644
index 000000000..46c6abeb3
--- /dev/null
+++ b/jvmaccess/workbench/makefile.mk
@@ -0,0 +1,42 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you 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 http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+PRJ = ..
+PRJNAME = jvmaccess
+TARGET = workbench
+
+ENABLE_EXCEPTIONS = TRUE
+
+LIBTARGET = NO
+TARGETTYPE = CUI
+
+.INCLUDE: settings.mk
+
+APP1TARGET = exceptiontest1
+APP1OBJS = $(OBJ)$/exceptiontest1.obj
+APP1STDLIBS = \
+ $(JVMACCESSLIB) \
+ $(SALLIB)
+
+APP2TARGET = exceptiontest2
+APP2OBJS = $(OBJ)$/exceptiontest2.obj
+APP2STDLIBS = \
+ $(JVMACCESSLIB) \
+ $(SALLIB)
+
+.INCLUDE: target.mk