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

Bundlized version of ST4 and ANTLR #88

Open
sakno opened this issue Jul 6, 2014 · 16 comments
Open

Bundlized version of ST4 and ANTLR #88

sakno opened this issue Jul 6, 2014 · 16 comments
Assignees

Comments

@sakno
Copy link

sakno commented Jul 6, 2014

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

@sharwell
Copy link
Member

sharwell commented Jul 6, 2014

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.

@sakno
Copy link
Author

sakno commented Jul 6, 2014

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.

@cniles
Copy link

cniles commented Mar 19, 2015

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.

@parrt
Copy link
Member

parrt commented Mar 19, 2015

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

@cniles
Copy link

cniles commented Mar 19, 2015

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.

@parrt
Copy link
Member

parrt commented Mar 19, 2015

latest antlr jars are osgi compatible
T
On Mar 19, 2015, at 11:43 AM, Craig Niles notifications@github.com 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.

@cniles
Copy link

cniles commented Mar 19, 2015

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)?

@cbdiesse
Copy link

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.

@sakno
Copy link
Author

sakno commented Apr 26, 2016

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.

@sharwell sharwell self-assigned this Jul 17, 2016
@sharwell
Copy link
Member

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.

@felixdo
Copy link

felixdo commented Mar 27, 2017

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?

@parrt
Copy link
Member

parrt commented Mar 27, 2017

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

@felixdo
Copy link

felixdo commented Mar 27, 2017

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.

@parrt
Copy link
Member

parrt commented Mar 27, 2017

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

@felixdo
Copy link

felixdo commented Mar 27, 2017

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

@felixdo
Copy link

felixdo commented Mar 28, 2017

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... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants