Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/.metadata/
/.recommenders/
.classpath
.project
/.settings/

# OS
.DS_Store
Expand Down
23 changes: 0 additions & 23 deletions .project

This file was deleted.

4 changes: 0 additions & 4 deletions .settings/org.eclipse.core.resources.prefs

This file was deleted.

15 changes: 0 additions & 15 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

34 changes: 27 additions & 7 deletions src/main/java/org/eclipse/osgitech/plurl/impl/PlurlImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1071,14 +1071,34 @@ protected void remove(URLStreamHandlerFactory f) {
PlurlStreamHandler newProxyPlurlStreamHandler(URLStreamHandler handler) {
Class<?> checkClass = handler.getClass();
while (checkClass != null) {
for (Class<?> i : checkClass.getInterfaces()) {
if (PLURL_STREAM_HANDLER_CLASS_NAME.equals(i.getName())) {
for (Method m : i.getMethods()) {
if (m.getName().equals("parseURL")) { //$NON-NLS-1$
Class<?> plurlStreamHandlerClass = i;
Class<?> plurlSetterClass = m.getParameterTypes()[0];
return new PlurlStreamHandlerProxy(handler, plurlStreamHandlerClass, plurlSetterClass);
for (Class<?> handlerInterfaces : checkClass.getInterfaces()) {
// To determine if we can proxy the handler we look for an interface that defines a method
// public void parseURL(PlurlSetter plurlSetter, URL u, String spec, int start, int limit);
// But we cannot search for it the conventional way because the PlurlSetter may be a different
// copy from ours.
for (Method m : handlerInterfaces.getMethods()) {
if (m.getName().equals("parseURL")) { //$NON-NLS-1$
Class<?>[] params = m.getParameterTypes();
if (params.length == 5) {
// check the first param to see if it is a PlurlSetter candidate
Class<?> plurlSetterCandidate = params[0];
if (plurlSetterCandidate.isInterface()) {
try {
// try finding the appropriate setURL method
plurlSetterCandidate.getMethod("setURL", URL.class, String.class, String.class, Integer.TYPE, String.class, String.class,
String.class, String.class, String.class);
} catch (Exception e) {
// move on to the next interface
continue;
}
}
} else {
// Wrong number of arguments for parseURL; move on to next interface
continue;
}
Class<?> plurlStreamHandlerClass = handlerInterfaces;
Class<?> plurlSetterClass = m.getParameterTypes()[0];
return new PlurlStreamHandlerProxy(handler, plurlStreamHandlerClass, plurlSetterClass);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public void testAddRemoveProxyFactory() throws IOException {
doTestMultiplePlurlsAddRemoveFactory(TestFactoryType.PLURL_PROXY_FACTORY);
}

@Test
public void testAddRemovePlurlCopyFactory() throws IOException {
doTestMultiplePlurlsAddRemoveFactory(TestFactoryType.PLURL_COPY_FACTORY);
}

private static void doTestMultiplePlurlsAddRemoveFactory(TestFactoryType type) throws IOException {
doAddRemoveFactory(type, //
listOfPlurlTestHandlers.get(listOfPlurlTestHandlers.size() - 1), //
Expand All @@ -120,6 +125,11 @@ public void testURLContextProxyFactory() throws IOException {
doTestMultiplePlurlsTestURLContext(TestFactoryType.PLURL_PROXY_FACTORY);
}

@Test
public void testURLContextPlurlCopyFactory() throws IOException {
doTestMultiplePlurlsTestURLContext(TestFactoryType.PLURL_COPY_FACTORY);
}

private static void doTestMultiplePlurlsTestURLContext(TestFactoryType type) throws IOException {
doTestURLContext(type, //
listOfPlurlTestHandlers.get(listOfPlurlTestHandlers.size() - 1), //
Expand All @@ -146,6 +156,11 @@ public void testContentProxyFactory() throws IOException {
doTestMultiplePlurlsContent(TestFactoryType.PLURL_PROXY_FACTORY);
}

@Test
public void testContentPlurlCopyFactory() throws IOException {
doTestMultiplePlurlsContent(TestFactoryType.PLURL_COPY_FACTORY);
}

private static void doTestMultiplePlurlsContent(TestFactoryType type) throws IOException {
doTestContentContext(type, //
listOfPlurlTestHandlers.get(listOfPlurlTestHandlers.size() - 1), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public void testAddRemoveProxyFactory() throws IOException {
doAddRemoveFactory(TestFactoryType.PLURL_PROXY_FACTORY);
}

@Test
public void testAddRemovePlurlCopyFactory() throws IOException {
doAddRemoveFactory(TestFactoryType.PLURL_COPY_FACTORY);
}

private void doAddRemoveFactory(TestFactoryType type) throws IOException {
assumeThat(canReflect(type), is(String.valueOf(true)));

Expand Down Expand Up @@ -180,6 +185,11 @@ public void testGCProxyFactory() throws IOException {
doTestGCURLFactory(TestFactoryType.PLURL_PROXY_FACTORY);
}

@Test
public void testGCPlurlCopyFactory() throws IOException {
doTestGCURLFactory(TestFactoryType.PLURL_COPY_FACTORY);
}

private void doTestGCURLFactory(TestFactoryType type) throws IOException {
assumeThat(canReflect(type), is(String.valueOf(true)));

Expand Down Expand Up @@ -226,6 +236,11 @@ public void testContentProxyFactory() throws IOException {
doTestContentContext(TestFactoryType.PLURL_PROXY_FACTORY, plurlTestHandlers, null);
}

@Test
public void testContentPlurlCopyFactory() throws IOException {
doTestContentContext(TestFactoryType.PLURL_COPY_FACTORY, plurlTestHandlers, null);
}

static void doTestContentContext(TestFactoryType type, PlurlTestHandlers handlersToUse,
PlurlTestHandlers handlersToUninstall) throws IOException {
assumeThat(canReflect(type), is(String.valueOf(true)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public void testAddRemoveProxyFactory() throws IOException {
doAddRemoveFactory(TestFactoryType.PLURL_PROXY_FACTORY, plurlTestHandlers, null);
}

@Test
public void testAddRemovePlurlCopyFactory() throws IOException {
doAddRemoveFactory(TestFactoryType.PLURL_COPY_FACTORY, plurlTestHandlers, null);
}

static void doAddRemoveFactory(TestFactoryType type, PlurlTestHandlers handlersToUse,
PlurlTestHandlers handlersToUninstall) throws IOException {
assumeThat(canReflect(type), is(String.valueOf(true)));
Expand Down Expand Up @@ -151,6 +156,11 @@ public void testURLContextProxyFactory() throws IOException {
doTestURLContext(TestFactoryType.PLURL_PROXY_FACTORY, plurlTestHandlers, null);
}

@Test
public void testURLContextPlurlCopyFactory() throws IOException {
doTestURLContext(TestFactoryType.PLURL_COPY_FACTORY, plurlTestHandlers, null);
}

static void doTestURLContext(TestFactoryType type, PlurlTestHandlers handlersToUse,
PlurlTestHandlers handlersToUninstall) throws IOException {
assumeThat(canReflect(type), is(String.valueOf(true)));
Expand Down Expand Up @@ -246,6 +256,11 @@ public void testGCProxyFactory() throws IOException {
doTestGCURLFactory(TestFactoryType.PLURL_PROXY_FACTORY);
}

@Test
public void testGCPlurlCopyFactory() throws IOException {
doTestGCURLFactory(TestFactoryType.PLURL_COPY_FACTORY);
}

private void doTestGCURLFactory(TestFactoryType type) throws IOException {
assumeThat(canReflect(type), is(String.valueOf(true)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ public boolean shouldHandle(Class<?> clazz) {
}
}

public static class TestPlurlCopyContentHandlerFactory extends TestContentHandlerFactory
implements org.eclipse.osgitech.plurl.test.copy.PlurlContentHandlerFactory {

public TestPlurlCopyContentHandlerFactory(List<String> mimetypes, Class<?>... shouldHandleClasses) {
super(mimetypes, shouldHandleClasses);
}

@Override
protected ContentHandler createContentHandlerImpl(String mimetype) {
return new TestContentHandler(mimetype);
}

@Override
public boolean shouldHandle(Class<?> clazz) {
return shouldHandleImpl(clazz);
}
}

public static class TestContentHandler extends ContentHandler {
private final String mimetype;

Expand Down Expand Up @@ -184,6 +202,21 @@ public boolean shouldHandle(Class<?> clazz) {
}
}

public static class TestPlurlCopyStreamHandlerFactory extends TestURLStreamHandlerFactory implements org.eclipse.osgitech.plurl.test.copy.PlurlStreamHandlerFactory {
public TestPlurlCopyStreamHandlerFactory(List<String> protocols, Class<?>... shouldHandleClasses) {
super(protocols, shouldHandleClasses);
}
@Override
protected URLStreamHandler createURLStreamHandlerImpl(String protocol) {
return new TestPlurlCopyStreamHandler(false);
}

@Override
public boolean shouldHandle(Class<?> clazz) {
return shouldHandleImpl(clazz);
}
}

static class CatchAllPlurlFactory extends TestURLStreamHandlerFactory implements PlurlStreamHandlerFactory {
CatchAllPlurlFactory(String... protos) {
super(Arrays.asList(protos));
Expand Down Expand Up @@ -281,8 +314,58 @@ public String toString() {
}
}

static class TestPlurlCopyStreamHandler extends org.eclipse.osgitech.plurl.test.copy.PlurlStreamHandlerBase {
private final boolean unsupported;

public TestPlurlCopyStreamHandler() {
this(false);
}

public TestPlurlCopyStreamHandler(boolean unsupported) {
this.unsupported = unsupported;
}

@Override
public URLConnection openConnection(URL u) throws IOException {
if (unsupported) {
throw new UnsupportedOperationException();
}
return new URLConnection(u) {
@Override
public String getContentType() {
// for testing purposes just use the test protocol name
return u.getProtocol();
}

@Override
public void connect() throws IOException {
// do nothing
}

@Override
public InputStream getInputStream() throws IOException {
// just testing
return new ByteArrayInputStream(u.getProtocol().getBytes());
}
};
}

@Override
public void parseURL(PlurlSetter setter, URL u, String spec, int start, int limit) {
if (unsupported) {
throw new UnsupportedOperationException();
}
super.parseURL(setter, u, spec, start, limit);
}

@Override
public String toString() {
return getClass().getSimpleName() + '@' + System.identityHashCode(this);
}
}

enum TestFactoryType {
PLURL_FACTORY, PLURL_PROXY_FACTORY, NOT_PLURL_FACTORY, LEGACY_FACTORY
PLURL_FACTORY, PLURL_PROXY_FACTORY, PLURL_COPY_FACTORY, NOT_PLURL_FACTORY, LEGACY_FACTORY
}
static final boolean CAN_REFLECT_SET_URL_HANDLER;
static final String CAN_REFLECT_ON_URL_STREAM_HANDLER;
Expand Down Expand Up @@ -375,6 +458,8 @@ static TestURLStreamHandlerFactory createTestURLStreamHandlerFactory(TestFactory
return new TestNotPlurlStreamHandlerFactory(protocols, shouldHandleClasses);
case PLURL_PROXY_FACTORY:
return createProxyURLHandlerFactory(protocols, shouldHandleClasses);
case PLURL_COPY_FACTORY:
return new TestPlurlCopyStreamHandlerFactory(protocols, shouldHandleClasses);
default:
throw new UnsupportedOperationException("Unknown type: " + type);
}
Expand Down Expand Up @@ -407,6 +492,8 @@ static TestContentHandlerFactory createTestContentHandlerFactory(TestFactoryType
return new TestNotPlurlContentHandlerFactory(mimetypes, shouldHandleClasses);
case PLURL_PROXY_FACTORY:
return createProxyContentFactory(mimetypes, shouldHandleClasses);
case PLURL_COPY_FACTORY:
return new TestPlurlCopyContentHandlerFactory(mimetypes, shouldHandleClasses);
default:
throw new UnsupportedOperationException("Unknown type: " + type);
}
Expand Down Expand Up @@ -680,7 +767,7 @@ static Field getField(Class<?> clazz, Class<?> type, boolean instance) {
}

static String canReflect(TestFactoryType type) {
if (type == TestFactoryType.PLURL_FACTORY || type == TestFactoryType.PLURL_PROXY_FACTORY) {
if (type == TestFactoryType.PLURL_FACTORY || type == TestFactoryType.PLURL_PROXY_FACTORY || type == TestFactoryType.PLURL_COPY_FACTORY) {
return String.valueOf(true);
}
return PlurlTestHandlers.CAN_REFLECT_ON_URL_STREAM_HANDLER;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgitech.plurl.test.copy;

import java.net.ContentHandlerFactory;

/**
* A {@link ContentHandlerFactory} that also implements {@link PlurlFactory}
*/
public interface PlurlContentHandlerFactory extends ContentHandlerFactory, PlurlFactory {
// a marker interface for a ContentHandlerFactory that implements PlurlFactory
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgitech.plurl.test.copy;


public interface PlurlFactory {

boolean shouldHandle(Class<?> clazz);
}
Loading
Loading