-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "replace" as a default available transformer
A while back in the incubation phase there was a dedicated bundle that provided a "replace" transformer. As this is the very basic transformation and do not require any special dependency it is now added back (in a slightly enhanced implementation) as being available by default.
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...uinox.transforms.hook/src/org/eclipse/equinox/internal/transforms/ReplaceTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************* | ||
* 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 replaces a matching resource with | ||
* another. | ||
*/ | ||
class ReplaceTransformer { | ||
|
||
static final String TYPE = "replace"; //$NON-NLS-1$ | ||
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, String.format("Can't replace resource with %s", 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, TYPE))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters