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

Apply project settings to o.e.equinox.transforms.hook #335

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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.equinox.transforms.hook
Bundle-Version: 1.3.300.qualifier
Bundle-Version: 1.3.400.qualifier
Fragment-Host: org.eclipse.osgi;bundle-version="[3.10.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Localization: transformsHook
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.equinox.transforms.hook/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ <h3>License</h3>
</p>

</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@
import org.eclipse.osgi.internal.log.EquinoxLogServices;

/**
* This class is used by the transformer hook to parse urls provided by transform developers that specifies the particular transforms that should be utilized for a particular transformer.
* TODO: factor this out into a new type of service the transformer uses. Then there could be CSV transforms, programatic transforms, etc.
* This class is used by the transformer hook to parse urls provided by
* transform developers that specifies the particular transforms that should be
* utilized for a particular transformer. TODO: factor this out into a new type
* of service the transformer uses. Then there could be CSV transforms,
* programatic transforms, etc.
*/
public class CSVParser {

/**
* Parse the given url as a CSV file containing transform tuples. The tuples have the form:
* Parse the given url as a CSV file containing transform tuples. The tuples
* have the form:
*
* <pre>
* bundleRegex,pathRegex,transformerResource
* </pre>
* </pre>
*
* @param transformMapURL the map url
* @return an array of tuples derived from the contents of the file
* @throws IOException thrown if there are issues parsing the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import java.io.InputStream;

/**
* An input stream that is based off of another stream.
* This other stream is provided as needed by an {@link InputStreamProvider} so that the underlying stream is not eagerly loaded.
* An input stream that is based off of another stream. This other stream is
* provided as needed by an {@link InputStreamProvider} so that the underlying
* stream is not eagerly loaded.
*/
public class LazyInputStream extends InputStream {

Expand All @@ -29,7 +30,8 @@ public class LazyInputStream extends InputStream {

/**
* Construct a new lazy stream based off the given provider.
* @param provider the input stream provider. Must not be <code>null</code>.
*
* @param provider the input stream provider. Must not be <code>null</code>.
*/
public LazyInputStream(InputStreamProvider provider) {
if (provider == null)
Expand Down Expand Up @@ -135,12 +137,14 @@ public String toString() {
}

/**
* An interface to be implemented by clients that wish to utilize {@link LazyInputStream}s.
* The implementation of this interface should defer obtaining the desired input stream until absolutely necessary.
* An interface to be implemented by clients that wish to utilize
* {@link LazyInputStream}s. The implementation of this interface should defer
* obtaining the desired input stream until absolutely necessary.
*/
public static interface InputStreamProvider {
/**
* Return the input stream.
*
* @return the input stream
* @throws IOException thrown if there is an issue obtaining the stream
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
import java.net.URL;

/**
* A proxy stream transformer is a transformer instance that relies on reflection to obtain the "getInputStream" method from an underlying object.
* This class is useful due to the restrictions in the builder that prevent transformer providers from directly implementing {@link StreamTransformer} due to visibility and builder issues related to referring to classes within fragments.
* A proxy stream transformer is a transformer instance that relies on
* reflection to obtain the "getInputStream" method from an underlying object.
* This class is useful due to the restrictions in the builder that prevent
* transformer providers from directly implementing {@link StreamTransformer}
* due to visibility and builder issues related to referring to classes within
* fragments.
*/
public class ProxyStreamTransformer extends StreamTransformer {

Expand All @@ -31,13 +35,17 @@ public class ProxyStreamTransformer extends StreamTransformer {

/**
* Create a new proxy transformer based on the given object.
*
* @param object the object to proxy
* @throws SecurityException thrown if there is an issue utilizing the reflection methods
* @throws NoSuchMethodException thrown if the provided object does not have a "getInputStream" method that takes an {@link InputStream} and an {@link URL}
* @throws SecurityException thrown if there is an issue utilizing the
* reflection methods
* @throws NoSuchMethodException thrown if the provided object does not have a
* "getInputStream" method that takes an
* {@link InputStream} and an {@link URL}
*/
public ProxyStreamTransformer(Object object) throws SecurityException, NoSuchMethodException {
this.object = object;
method = object.getClass().getMethod("getInputStream", new Class[] {InputStream.class, URL.class}); //$NON-NLS-1$
method = object.getClass().getMethod("getInputStream", new Class[] { InputStream.class, URL.class }); //$NON-NLS-1$
Class<?> returnType = method.getReturnType();
if (!returnType.equals(InputStream.class))
throw new NoSuchMethodException();
Expand All @@ -47,7 +55,7 @@ public ProxyStreamTransformer(Object object) throws SecurityException, NoSuchMet
@Override
public InputStream getInputStream(InputStream inputStream, URL transformerUrl) throws IOException {
try {
return (InputStream) method.invoke(object, new Object[] {inputStream, transformerUrl});
return (InputStream) method.invoke(object, new Object[] { inputStream, transformerUrl });
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new IOException(e.getMessage());
} catch (InvocationTargetException e) {
Expand All @@ -59,7 +67,8 @@ public InputStream getInputStream(InputStream inputStream, URL transformerUrl) t

/**
* Get the object that is being proxied.
* @return the object. Never <code>null</code>.
*
* @return the object. Never <code>null</code>.
*/
public Object getTransformer() {
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
import java.net.URL;

/**
* This class represents the fundamental building block of the transformer system.
* Implementations of this class are capable of transforming an input stream based on a given transformer url.
* The meaning and content of this URL are unspecified - it is the transformers responsibility to interpret these as need be.
* This class represents the fundamental building block of the transformer
* system. Implementations of this class are capable of transforming an input
* stream based on a given transformer url. The meaning and content of this URL
* are unspecified - it is the transformers responsibility to interpret these as
* need be.
*/
public abstract class StreamTransformer {
/**
* Provided a transformed version of the provided input stream.
* @param inputStream the original stream
* @param transformerUrl an url that may be used by the transformer in determining the proper transform to invoke.
*
* @param inputStream the original stream
* @param transformerUrl an url that may be used by the transformer in
* determining the proper transform to invoke.
* @return the transformed stream
* @throws IOException thrown if there is an issue invoking the transform
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
import org.osgi.util.tracker.ServiceTracker;

/**
* Class that represents a dynamic list of TransformTuples that have been registered against a particular transform type.
* Class that represents a dynamic list of TransformTuples that have been
* registered against a particular transform type.
*/
public class TransformInstanceListData extends ServiceTracker<URL, URL> {
/**
* Used when there are no transform data types
*/
private static final String[] EMPTY_TYPES = new String[0];
/**
* Stale state of the transform list. Set to true whenever one of the ServiceTrackerCustomization methods are invoked.
* Stale state of the transform list. Set to true whenever one of the
* ServiceTrackerCustomization methods are invoked.
*/
private volatile boolean stale = true;

Expand All @@ -45,18 +47,23 @@ public class TransformInstanceListData extends ServiceTracker<URL, URL> {
private List<TransformTuple> rawTuples = new ArrayList<>();

/**
* Map from bundle ID -> boolean representing whether or not a given bundle currently has any transforms registered against it.
* Map from bundle ID -> boolean representing whether or not a given bundle
* currently has any transforms registered against it.
*/
private Map<String, Boolean> bundleIdToTransformPresence = new HashMap<>();
private final EquinoxLogServices logServices;

/**
* Create a new transform list bound to the given context. If new transforms are registered against the given context the contents of this list will change.
* @param context the bundle context
* Create a new transform list bound to the given context. If new transforms are
* registered against the given context the contents of this list will change.
*
* @param context the bundle context
* @param logServices
* @throws InvalidSyntaxException thrown if there's an issue listening for changes to the given transformer type
* @throws InvalidSyntaxException thrown if there's an issue listening for
* changes to the given transformer type
*/
public TransformInstanceListData(BundleContext context, EquinoxLogServices logServices) throws InvalidSyntaxException {
public TransformInstanceListData(BundleContext context, EquinoxLogServices logServices)
throws InvalidSyntaxException {
super(context, context.createFilter("(&(objectClass=" //$NON-NLS-1$
+ URL.class.getName() + ")(" + TransformTuple.TRANSFORMER_TYPE //$NON-NLS-1$
+ "=*))"), null); //$NON-NLS-1$
Expand All @@ -65,7 +72,9 @@ public TransformInstanceListData(BundleContext context, EquinoxLogServices logSe
}

/**
* Return the transforms types currently held by this list. If a change has been detected since the last request this list will be rebuilt.
* Return the transforms types currently held by this list. If a change has been
* detected since the last request this list will be rebuilt.
*
* @return the transforms types currently held by this list
*/
public synchronized String[] getTransformTypes() {
Expand All @@ -78,7 +87,9 @@ public synchronized String[] getTransformTypes() {
}

/**
* Return the transforms of a particular type currently held by this list. If a change has been detected since the last request this list will be rebuilt.
* Return the transforms of a particular type currently held by this list. If a
* change has been detected since the last request this list will be rebuilt.
*
* @return the transforms currently held by this list
*/
public synchronized TransformTuple[] getTransformsFor(String type) {
Expand All @@ -89,7 +100,10 @@ public synchronized TransformTuple[] getTransformsFor(String type) {
}

/**
* Return whether or not there are any transforms who's bundle pattern matches the ID of the provided bundle. Only transforms with a present transform handler are considered during the invocation of this method.
* Return whether or not there are any transforms who's bundle pattern matches
* the ID of the provided bundle. Only transforms with a present transform
* handler are considered during the invocation of this method.
*
* @param bundle the bundle to test
* @return the presence of associated transforms.
*/
Expand All @@ -115,7 +129,8 @@ public synchronized boolean hasTransformsFor(Bundle bundle) {
}

/**
* Consults the bundle context for services of the transformer type type and builds the internal cache.
* Consults the bundle context for services of the transformer type type and
* builds the internal cache.
*/
private void rebuildTransformMap() {
transformerToTuple.clear();
Expand Down Expand Up @@ -167,4 +182,4 @@ public void removedService(ServiceReference<URL> reference, URL service) {
super.removedService(reference, service);
stale = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
import java.util.regex.Pattern;

/**
* Class that represents an association between a bundle pattern, a path pattern, and the location of a transformer to apply to any resource that matches both the bundle and path pattern.
* Class that represents an association between a bundle pattern, a path
* pattern, and the location of a transformer to apply to any resource that
* matches both the bundle and path pattern.
*/
public class TransformTuple {

/**
* Constant used when registering transform tuples to identify the type of transformer they should be assigned to.
* Constant used when registering transform tuples to identify the type of
* transformer they should be assigned to.
*/
public static final String TRANSFORMER_TYPE = "equinox.transformerType"; //$NON-NLS-1$
public Pattern bundlePattern;
public Pattern pathPattern;
public URL transformerUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import org.eclipse.osgi.storage.bundlefile.BundleEntry;

/**
* This class is capable of providing a transformed version of an entry contained within a base bundle entity.
* This class is capable of providing a transformed version of an entry
* contained within a base bundle entity.
*/
public class TransformedBundleEntry extends BundleEntry {

Expand All @@ -32,9 +33,11 @@ public class TransformedBundleEntry extends BundleEntry {
private TransformedBundleFile bundleFile;

/**
* Create a wrapped bundle entry. Calls to obtain the content of this entry will be resolved via the provided input stream rather than the original.
* @param bundleFile the host bundle file
* @param original the original entry
* Create a wrapped bundle entry. Calls to obtain the content of this entry will
* be resolved via the provided input stream rather than the original.
*
* @param bundleFile the host bundle file
* @param original the original entry
* @param wrappedStream the override stream
*/
public TransformedBundleEntry(TransformedBundleFile bundleFile, BundleEntry original, InputStream wrappedStream) {
Expand Down Expand Up @@ -69,8 +72,9 @@ public String getName() {
}

/**
* Obtaining the size means inspecting the transformed stream.
* If this stream does not support marks the stream is drained and a copy is retained for later use.
* Obtaining the size means inspecting the transformed stream. If this stream
* does not support marks the stream is drained and a copy is retained for later
* use.
*/
public long getSize() {
ByteArrayOutputStream tempBuffer = new ByteArrayOutputStream(1024);
Expand All @@ -90,8 +94,11 @@ public long getSize() {
stream = new ByteArrayInputStream(tempBuffer.toByteArray());
}
} catch (IOException e) {
bundleFile.getGeneration().getBundleInfo().getStorage().getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Problem calculating size of stream for file. Stream may now be corrupted : " //$NON-NLS-1$
+ getName(), e);
bundleFile.getGeneration().getBundleInfo().getStorage().getLogServices().log(EquinoxContainer.NAME,
FrameworkLogEntry.ERROR,
"Problem calculating size of stream for file. Stream may now be corrupted : " //$NON-NLS-1$
+ getName(),
e);
}
return tempBuffer.size();

Expand Down
Loading
Loading