diff --git a/bundles/org.eclipse.equinox.transforms.hook/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.transforms.hook/META-INF/MANIFEST.MF index 0439ba08288..2069b071de1 100644 --- a/bundles/org.eclipse.equinox.transforms.hook/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.transforms.hook/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.equinox.transforms.hook -Bundle-Version: 1.4.100.qualifier +Bundle-Version: 1.4.200.qualifier Fragment-Host: org.eclipse.osgi;bundle-version="[3.10.0,4.0.0)" Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Localization: transformsHook diff --git a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/ReplaceTransformer.java b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/ReplaceTransformer.java new file mode 100644 index 00000000000..cff8017f593 --- /dev/null +++ b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/ReplaceTransformer.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2024 Christoph Läubrich 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: + * Christoph Läubrich - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.internal.transforms; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Map; +import org.eclipse.osgi.framework.log.FrameworkLogEntry; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; + +/** + * Basic default transformer that simply replace a matching resource with + * another + */ +class ReplaceTransformer { + + private TransformerHook hook; + + ReplaceTransformer(TransformerHook hook) { + this.hook = hook; + } + + public InputStream getInputStream(InputStream inputStream, final URL transformerUrl) { + try { + return transformerUrl.openStream(); + } catch (IOException e) { + hook.log(FrameworkLogEntry.WARNING, "can't replace resource with " + transformerUrl, e); //$NON-NLS-1$ + return null; + } + } + + public static void register(BundleContext context, TransformerHook transformerHook) { + context.registerService(Object.class, new ReplaceTransformer(transformerHook), + FrameworkUtil.asDictionary(Map.of(TransformTuple.TRANSFORMER_TYPE, "replace"))); //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerHook.java b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerHook.java index 1eecc150be6..1f0bcea632f 100644 --- a/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerHook.java +++ b/bundles/org.eclipse.equinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/TransformerHook.java @@ -46,6 +46,7 @@ public void addHooks(HookRegistry hookRegistry) { public void start(BundleContext context) throws BundleException { try { + ReplaceTransformer.register(context, this); this.transformers = new TransformerList(context, logServices); } catch (InvalidSyntaxException e) { throw new BundleException("Problem registering service tracker: transformers", e); //$NON-NLS-1$