stringtemplate4 icon indicating copy to clipboard operation
stringtemplate4 copied to clipboard

Bundlized version of ST4 and ANTLR

Open sakno opened this issue 11 years ago • 16 comments

Could you please add maven-bundle-plugin into StringTemplate/ANTLR pom.xml and OSGify these libraries?

sakno avatar Jul 06 '14 04:07 sakno

We aren't familiar with, and do not use this type of library. If you could explain what's involved in detail, or provide a pull request, it would be much easier to evaluate this.

sharwell avatar Jul 06 '14 04:07 sharwell

I want to use StringTemplate and ANTLR libraries in my application based on OSGI. I have two ways to to do that:

  1. Embed dependency in my OSGI bundle (not reusable and can cause ClassLoader problems)
  2. Install StringTemplate and ANTLR libraries as OSGI bundles

OSGI bundle is just a JAR file with special Manifest Headers. Without these headers OSGI environment (such as Apache Felix) couldn't install and load these libraries. The easiest way to do that is to add maven-bundle-plugin to your POM.xml.

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>org.antlr.stringTemplate</Bundle-SymbolicName>
                        <Export-Package>org.stringtemplate.*</Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

As you can see, it is quite simple. maven-bundle-plugin will add all necessary headers to JAR Manifest. And you library can be used in OSGI and non-OSGI environments both.

sakno avatar Jul 06 '14 06:07 sakno

Has there been any recent consideration of this? The change should have no impact unless an OSGi application kernel is being utilized. If you want I'll make the changes and send in a pull request.

cniles avatar Mar 19 '15 15:03 cniles

How about including the main antlr tool, which includes st 4?

parrt avatar Mar 19 '15 16:03 parrt

Are you suggesting adding OSGi metadata for the monolithic antlr artifact vice adding it to the ST4 artifact, or saying that this has been done already and I should be installing the main antlr tool?

If the former then yes; that would be a good idea and I would be happy to contribute.

cniles avatar Mar 19 '15 18:03 cniles

latest antlr jars are osgi compatible T On Mar 19, 2015, at 11:43 AM, Craig Niles [email protected] wrote:

Are you suggesting adding OSGi metadata for the monolithic antlr artifact vice adding it to the ST4 artifact, or saying that this has been done already and I should be installing the main antlr tool?

If the former then yes; that would be a good idea and I would be happy to contribute.

� Reply to this email directly or view it on GitHub.

parrt avatar Mar 19 '15 18:03 parrt

Looking through the public antlr 4.5 artifacts:

The one maven artifact that has OSGi headers is org.antlr/antlr4-runtime/4.5 (antlr4-runtime-4.5jar), but it doesn't contain the ST4 classes. The ST4 classes are in the artifact org.antlr/antlr4/4.5 but the osgi headers are not present in the jar's manifest.

Are these changes that are still not released (4.5.1)?

cniles avatar Mar 19 '15 19:03 cniles

Looking for antlr 4.5.x complete jar with StringTemplate-4 api exported and usable in eclipse plug-in development environment. The antlr.org site claim that the provided jar files are osgi ready, but it's not the case for antlr-4.5.3-complete.jar. the provided manifest.mf don't provide any package export. On the other hand, the runtime version : antlr-runtime-4.5.3 is osgi ready, but don't provide StringTemplate-4 packages. Meanwhile, no osgi version of StringTemplate-4 is provided.

In result, we have very hard time using ST4 and ANTLR4 in eclipse plug-in development env. Can anyone help provide something more effective to a low profil developper like me ? This will really help me cross the river. Thanks.

cbdiesse avatar Apr 26 '16 10:04 cbdiesse

You can solve this problem in this way:

  1. Create antlr-bundlized maven module in your poject
  2. Define packaging bundle to your module
  3. Specify artifact ID of ANTLR inside of <Embed-Dependency> tag in the configuration section of maven-bundle-plugin module. And don't forget to specify scope:=compile inside of this tag.
  4. Declare dependency on ANTLR with compile scope (any other OSGi-friendly dependencies should be declared with provided scope)
  5. Declare <Embed-Transitive> tag with value true in the configuration section
  6. Specify <Export-Package> tag in the configuration section of maven-bundle-plugin and set org.antlr.* as its value

Now you can use your antlr-bundlized module as OSGi-friendly version of ANTLR.

sakno avatar Apr 26 '16 12:04 sakno

We've now moved all the way in this direction for the ANTLR 4 runtime. However, that library proved easier than ST4, especially now that we've eliminated its last external dependency. I'll look at implementing this for ST4 as well, but there's an interesting dependency chain here:

ST4 → ANTLR 3 → ST3 → ANTLR 2

The real reason this is so interesting is twofold:

  1. ST4 doesn't use any features of ANTLR 3 which depend on ST3. However, ANTLR 3 as an independent bundle would need to declare the ST3 dependency.
  2. The shaded ST4 bundle wouldn't have any external dependencies, but maven-bundle-plugin runs before maven-shade-plugin so the manifest for the complete jar still lists imports for the ANTLR 3 runtime, even though they aren't actually required. I found this answer on Stack Overflow which suggests solutions to this exist, but I haven't followed this investigation to the end yet.

sharwell avatar Jul 17 '16 14:07 sharwell

I would like to play with this, but when I run mvn clean verify, the resulting jar does not contain the 'st4hidden' package that is in the jar I can download from the st website. What am I missing?

felixdo avatar Mar 27 '17 16:03 felixdo

@felixdo Does the resulting jar not operate as you would expect?

parrt avatar Mar 27 '17 16:03 parrt

No. I would like to produce a standalone OSGI bundle with no external dependencies for st4, which afaiu is the goal of this issue, and which does not exist atm. I would therefore need to include the antlr runtime just as it is included in ST-4.0.8.jar that I get from the st4 website. mvn clean verify does however not create that mysterious st4hidden package which contains the required antlr runtime.

felixdo avatar Mar 27 '17 16:03 felixdo

oh, well i guess we need to use the mvn shade thing to build a combined lib.

parrt avatar Mar 27 '17 17:03 parrt

yes that's what I meant. I thought the pom here already included that part.

felixdo avatar Mar 27 '17 18:03 felixdo

Maybe not even needed to include antlr, since that is already available in eclipse orbit https://dev.eclipse.org/ipzilla/show_bug.cgi?id=4865, so if we produce a bundle with a dependency on that, it should work. or not, if i still don't understand the dependency chain here... :)

felixdo avatar Mar 28 '17 07:03 felixdo