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

Make Yoko editable under Eclipse #232

Merged
merged 2 commits into from
Jul 31, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 20 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright 2024 IBM Corporation and others.
*
* Licensed 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an \"AS IS\" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

import groovy.time.TimeDuration
import groovy.time.TimeCategory

Expand Down Expand Up @@ -88,7 +106,9 @@ subprojects { sp ->
// ensure tests run under $buildDir somewhere
test {
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
jvmArgs '--add-opens=java.base/java.io=ALL-UNNAMED'
jvmArgs '--add-opens=java.base/java.util=ALL-UNNAMED'
jvmArgs '--add-opens=java.rmi/java.rmi=ALL-UNNAMED'
useJUnitPlatform()
workingDir = "$buildDir/testWorkingDir"
doFirst {workingDir.mkdirs()}
Expand Down
23 changes: 23 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright 2024 IBM Corporation and others.
*
* Licensed 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an \"AS IS\" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

rootProject.name = 'yoko'
include ':yoko-osgi'
include ':yoko-spec-corba'
Expand All @@ -7,6 +25,11 @@ include ':yoko-rmi-impl'
include ':yoko-core'
include ':yoko-core:versioned-classes'
include ':test-osgi'
include ':yoko-verify'
include ':yoko-verify:artifact'
include ':yoko-verify:artifact:v0'
include ':yoko-verify:artifact:v1'
include ':yoko-verify:artifact:v2'
include ':jdk-supplement'
include ':testify'
include ':testify-iiop'
20 changes: 19 additions & 1 deletion test-osgi/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright 2024 IBM Corporation and others.
*
* Licensed 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an \"AS IS\" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

repositories {
mavenCentral()
}
Expand All @@ -10,7 +28,7 @@ dependencies {
runtimeOnly 'org.apache.felix:org.apache.felix.framework:7.0.3'
// runtime 'org.eclipse.platform:org.eclipse.osgi:3.13.0'
implementation project(":yoko-spec-corba")
implementation project(':yoko-core')
runtimeOnly project(':yoko-core')
}

import aQute.bnd.gradle.TestOSGi
Expand Down
22 changes: 11 additions & 11 deletions test-osgi/src/main/java/test/OrbInitTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 IBM Corporation and others.
* Copyright 2024 IBM Corporation and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,25 +17,22 @@
*/
package test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

import java.util.Properties;

import org.junit.BeforeClass;
import org.junit.Test;
import org.omg.CORBA.NO_IMPLEMENT;
import org.omg.CORBA.ORB;

import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.*;
import static test.OrbInitTest.createOrb;

public class OrbInitTest {
@BeforeClass
public static void logWhereTheOrbClassComesFromAtRuntime() {
System.out.println("ORB API class = " + ORB.class);
System.out.println("ORB API class loader = " + ORB.class.getClassLoader());
System.out.println("ORB impl class = " + org.apache.yoko.orb.CORBA.ORB.class);
System.out.println("ORB impl class loader = " + org.apache.yoko.orb.CORBA.ORB.class.getClassLoader());
}

/** Create a non-singleton orb without specifying any properties */
Expand All @@ -45,7 +42,10 @@ public static ORB createOrb(String...params){

/** Create a non-singleton orb */
public static ORB createOrb(Properties props, String...params){
return ORB.init(params, props);
final ORB orb = ORB.init(params, props);
System.out.println("ORB impl class = " + orb.getClass());
System.out.println("ORB impl class loader = " + orb.getClass().getClassLoader());
return orb;
}

public static Properties props(String...props) {
Expand Down
22 changes: 21 additions & 1 deletion testify-iiop/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
/*
* Copyright 2024 IBM Corporation and others.
*
* Licensed 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an \"AS IS\" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

dependencies {
implementation 'junit:junit:4.12'
implementation "org.hamcrest:hamcrest:2.1"
implementation "org.junit.jupiter:junit-jupiter:5.9.0"
implementation project(':yoko-spec-corba')
implementation project(':yoko-rmi-spec')
implementation project(":yoko-core")
implementation project(':yoko-util')
implementation project(':yoko-rmi-impl')
implementation project(':yoko-core')
implementation project(":testify")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 IBM Corporation and others.
* Copyright 2024 IBM Corporation and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
*/
package testify.iiop.annotation;

import org.apache.yoko.orb.spi.naming.NameServiceInitializer;
import org.junit.jupiter.api.extension.ExtendWith;
import org.omg.PortableInterceptor.ORBInitializer;

Expand All @@ -38,23 +37,31 @@
public @interface ConfigureOrb {
enum NameService {
NONE,
READ_ONLY(NameServiceInitializer.class, NameServiceInitializer.NS_REMOTE_ACCESS_ARG, "readOnly"),
READ_WRITE(NameServiceInitializer.class, NameServiceInitializer.NS_REMOTE_ACCESS_ARG, "readWrite");
READ_ONLY("org.apache.yoko.orb.spi.naming.NameServiceInitializer", "-YokoNameServiceRemoteAccess", "readOnly"),
READ_WRITE("org.apache.yoko.orb.spi.naming.NameServiceInitializer", "-YokoNameServiceRemoteAccess", "readWrite");
final String[] args;
private final Class<? extends ORBInitializer> initializerClass;
private final String initializerClassName;

NameService() {
this.args = new String[0];
this.initializerClass = null;
this.initializerClassName = null;
}

NameService(Class<? extends ORBInitializer> initializerClass, String...args) {
NameService(String initializerClassName, String...args) {
this.args = args;
this.initializerClass = initializerClass;
this.initializerClassName = initializerClassName;
}

Optional<Class<? extends ORBInitializer>> getInitializerClass() {
return Optional.ofNullable(initializerClass);
return Optional.ofNullable(initializerClassName).map(c -> {
try {
return Class.forName(c);
} catch (ClassNotFoundException e) {
Error e2 = new NoClassDefFoundError();
e2.initCause(e);
throw e2;
}
}).map(ORBInitializer.class.getClass()::cast);
}
}

Expand Down
106 changes: 88 additions & 18 deletions testify-iiop/src/main/java/testify/iiop/annotation/ServerInstance.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 IBM Corporation and others.
* Copyright 2024 IBM Corporation and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,34 +17,42 @@
*/
package testify.iiop.annotation;

import org.apache.yoko.orb.OBPortableServer.POAManager_impl;
import org.apache.yoko.orb.OCI.IIOP.AcceptorInfo;
import static org.apache.yoko.io.AlignmentBoundary.FOUR_BYTE_BOUNDARY;
import static org.apache.yoko.io.AlignmentBoundary.TWO_BYTE_BOUNDARY;
import static org.apache.yoko.io.Buffer.createReadBuffer;
import static testify.bus.TestLogLevel.WARN;
import static testify.hex.HexParser.HEX_STRING;

import java.util.Map;
import java.util.Properties;
import java.util.stream.IntStream;

import org.apache.yoko.io.ReadBuffer;
import org.omg.CORBA.BAD_INV_ORDER;
import org.omg.CORBA.COMM_FAILURE;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CORBA.Policy;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.PortableServer.IdAssignmentPolicyValue;
import org.omg.PortableServer.IdUniquenessPolicyValue;
import org.omg.PortableServer.ImplicitActivationPolicyValue;
import org.omg.PortableServer.LifespanPolicyValue;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.AdapterAlreadyExists;
import org.omg.PortableServer.POAPackage.InvalidPolicy;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.RequestProcessingPolicyValue;
import org.omg.PortableServer.ServantRetentionPolicyValue;
import org.omg.PortableServer.ThreadPolicyValue;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.AdapterAlreadyExists;
import org.omg.PortableServer.POAPackage.InvalidPolicy;
import org.omg.PortableServer.POAPackage.WrongPolicy;
import org.opentest4j.AssertionFailedError;

import testify.bus.Bus;
import testify.iiop.annotation.ConfigureServer.ServerName;
import testify.util.Maps;
import testify.util.Throw;

import java.util.Map;
import java.util.Properties;

import static testify.bus.TestLogLevel.WARN;

class ServerInstance {
final Bus bus;
final ORB orb;
Expand All @@ -53,18 +61,80 @@ class ServerInstance {
final int port;
final String host;


/**
* To avoid using the internals of the POA Manager implementation
* just create an IOR and fish out the host and port from that.
*/
private final static class AddressIntrospector {
final String host;
final int port;

public AddressIntrospector(ORB orb, POA poa) {
final byte[] iiopProfile = getIiopProfile(getIor(orb, poa));
ReadBuffer rb = createReadBuffer(iiopProfile);
rb.skipBytes(2); // skip iiop_Version
// read the host name
rb.align(FOUR_BYTE_BOUNDARY);
int len = rb.readInt(); // host string length
StringBuilder sb = new StringBuilder(len);
// read all but last byte, since strings are null-terminated in the IOR
IntStream.range(0, len - 1).forEach(i -> sb.append(rb.readByteAsChar()));
this.host = sb.toString();
rb.skipBytes(1); // consume the null terminator
// read the port number
rb.align(TWO_BYTE_BOUNDARY);
this.port = rb.readShort() & 0xffff;
}

static String getIor(ORB orb, POA poa) {
try {
org.omg.CORBA.Object o = poa.create_reference("IDL:Special.ID.Object:1.0");
return orb.object_to_string(o);
} catch (WrongPolicy e) {
throw new AssertionFailedError("internal test framework error", e);
}
}

static byte[] getIiopProfile(String ior) {
System.out.println("fake ior to discover server endpoint:" + ior);
String hex = ior.substring("IOR:".length()); // strip leading "IOR:"
byte[] binary = HEX_STRING.parse(hex);
ReadBuffer rb = createReadBuffer(binary); // parse IOR
try {
//skip the BOM
rb.skipBytes(1);
//skip past the type_id
rb.align(FOUR_BYTE_BOUNDARY);
int len = rb.readInt();
rb.skipBytes(len);
rb.align(FOUR_BYTE_BOUNDARY);
// read how many profiles there are (typically 1)
rb.readInt();
// leaf through the profiles looking for the one with an ID of zero (i.e. the TAG_INTERNET_IOP profile)
for (;;) {
int profileId = rb.readInt();
int dataLen = rb.readInt();
if (0 == profileId) return rb.readBytes(new byte[dataLen]);
rb.skipBytes(dataLen);
rb.align(FOUR_BYTE_BOUNDARY);
}
} finally {
System.out.println(rb.dumpAllDataWithPosition());
}
}
}

ServerInstance(Bus bus, ServerName name, String[] args, Properties props) {
this.bus = bus;
this.orb = ORB.init(args, props);
try {
final POA rootPoa = getRootPoa(bus, orb, 7);
POAManager_impl pm = (POAManager_impl) rootPoa.the_POAManager();
final POAManager pm = rootPoa.the_POAManager();
pm.activate();
final AcceptorInfo info = (AcceptorInfo) pm.get_acceptors()[0].get_info();
// We might have been started up without a specific port.
// In any case, dig out the host and port number and save them away.
this.port = info.port() & 0xFFFF;
this.host = info.hosts()[0];
AddressIntrospector info = new AddressIntrospector(orb, rootPoa);
this.host = info.host;
this.port = info.port;
bus.log(() -> String.format("Server listening on host %s and port %d%n", host, port));
// create the POA policies for the server
Policy[] policies = {
Expand Down
Loading
Loading