How can I exclude certain packages from the exports with bndwrap - ant

The existing jar that I am trying to wrap with the ant bndwrap task has the classes from another jar included within it. By this I mean the unrolled jar, not an embedded jar.
How can I omit these packages from the export packages declaration of the bundle?
Basically the jar has the packages
org.stuff
and
org.otherstuff
I want to only export the org.stuff package, but bndwrap will include both.

If you use Export-Package in the bnd file, you can define exclusion as well with a "!".
Example from http://www.aqute.biz/Bnd/Bnd:
Export-Package: !com.acme.impl, com.acme.*;version=1.2
Also, if you use wrapping, -exportcontents can be interesting for you: http://www.aqute.biz/Bnd/Wrapping:
"The binaries and sources are not in the final jar but bnd does not yet know what needs to be exported. This can be indicated with the -exportcontents instruction. It has the same syntax as Export-Package but does not copy from the classpath, it only applies the instruction to the content of the final JAR."

Related

Building a non-uberjar Docker image with leiningen

I have a clojure project that depends on a Java library, that does not work, when it gets included in an uberjar. (It needs different XML descriptors using the same filename in different JAR files.)
Everything I find on using Docker with leiningen depends on building and packaging a uberjar. That's also how I built all clojure Docker images so far.
Is there any leiningen plugin out there, that understands to package a Docker image using several jar files like io.fabric8/docker-maven-plugin does?
Whenever packaging (uberjar, war) the big file that is created contains .class files and a directory structure. Where are these XML files supposed to be (class)loaded from? You can experiment with packing manually. After all it (whether uberjar, war or jar) is just a zip file.
When you know exactly the layout you need SBT is flexible enough to insure you can package from the many input jar files. Unfortunately lein plugins will do things like always overwrite duplicates, and you can't control the packaging behaviour. I can't remember exactly the inflexibilities, but I couldn't control how the packaging process went, what decisions were made.
For doing it manually I use a Linux something called Archive Manager, which I found to be much better than what I used when on Windows. Doing it manually may be all you need. The downside of SBT of course being that you have to learn it, which includes a bit of Scala.
It needs different XML descriptors using the same filename in different JAR files.
Just thinking about this, is it that you need to append the contents of each file that is in a different jar into the one file that is in the uberjar? You can try it out. If it works and you need to package up often enough that manually creating and renaming a zip file every time becomes a pain, then I believe that SBT will be your best bet.
I have to package my container with the original jar file and then reference this jar in the classpath when starting the application
The classloader loads classes rather than jars. It is the container's job to unpackage all the things you give it, such as .class files, (uber)jars, wars. Any program that dynamically loads from the classpath is loading either classes or resources (things like .xml files). I suppose a .jar file could be a resource, in which case you would put the jar file in the uberjar. So it is still possible to package it up.

Add generated subproject configure file to main project in CMake

I am trying to compile my application using CMake, and I need to compile Lua with it for various reasons. My current setup is as follows:
project/
CMakeLists.txt
...
libs/
CMakeLists.txt
...
lua/
CMakeLists.txt
...
I am using LuaDist as it already provides a CMake build system for lua. The problem comes when I try to include lua.h from my project, as it requires luaconfig.h which is generated by the Lua subproject and output to its binary directory, not source directory.
In my main project I do something like this:
include_directories(libs/lua/src/ etc...)
How can I also include generated files from subprojects in my main project?
If you're including lua directly via an add_subdirectory call, you can also use include_directories(${lua_BINARY_DIR}) (assuming there's a project(lua) command in lua's CMakeLists.txt file). The name of the variable may be something else if the project command is different, or you may need multiple additional include_directories, depending on where the header files you need are ... but this should get you started.

Trying to publish directory tree and auxiliary properties file with apache ivy, with later complex retrieval

I'm still struggling with figuring out how to integrate Apache Ivy into my somewhat complex Ant build.
If it matters, I'm using ATG Dynamo, which contributes most of the mess I'm trying to deal with.
The result of a build of a module is a "build" directory, with several subdirectories. I need to publish the entire contents of the "build" directory, along with a properties file (env/default.properties) that is not produced by the build, but one property in that file is needed when later retrieving this artifact, as it indicates the absolute path (relative to another property setting) where the contents of the "build" directory need to be installed.
The entire build will have several similarly structured modules. I'm pretty sure the target that does the "ivy:publish" can be defined in a "base" build script that all the module build scripts import.
I imagine the "ivy.xml" for each module would have a "publications" element that specifies the two (?) pieces that are being published, being the "build" directory and the "env/default.properties" file. I've never seen an example that publishes a directory, is that possible? If not, then I would guess that I'd have to specify more processing and detail in the "ivy:publish" target, such that I would first zip up the "build" directory and the "env/default.properties" file both into a zip file and publish that as the single artifact. Is this more likely?
It is quite new in Ivy, and it is not released yet, but there is a concept of "packaging" which can handle directories.
See the official documentation: http://ant.apache.org/ivy/history/trunk/concept.html#packaging
With this feature, Ivy can handle by itself the unzipping of a folder. On the publish part, you are on your own, you'll have to make a zip yourself. On the retrieve part, Ivy will unzip the folder in the cache. So you will still have to do some process to copy it at the proper place.
It has not been tested, but probably you can go even further by implementing a custom unpacking algorithm, which will do the unpacking at the proper place. You'll have to implement a class which extends org.apache.ivy.core.pack.ArchivePacking, and declare it in your ivysettings.xml, like this:
<ivysetting>
<classpath file="${ivy.settings.dir}/custom-packing.jar"/>
<typedef name="customPacking" classname="com.acme.ivy.CustomPacking" />
<customPacking />
</ivysettings>
And then in your ivy.xml, declare your artifact as packaged by your custom packaging name:
<ivy-module version="1.0">
...
<publications>
<artifact name="mydistrib" type="distrib" ext=".zip" packaging="my-custom-packaging" />
</publications>
</ivy-module>

Sonar tests and binaries properties, what do they do?

In Sonar documentation there are two properties options, the sonar.tests and sonar.binaries.
# path to test source directories (optional)
sonar.tests=testDir1,testDir2
# path to project binaries (optional), for example directory of Java bytecode
sonar.binaries=binDir
Questions:
If sonar.tests and sonar.binaries are added to my Ant target, how do they show up in Sonar? What would be different in Sonar if I did/did not set these properties?
Should sonar.binaries contain both source binaries and test binaries, or only source?
Can .jar files be given to both properties instead of path to actual .class files and/or .java files?
Answers:
If you do not set those 2 properties, you won't have test results ("sonar.tests") nor violations detected by Findbugs or bytecode-based tools ("sonar.binaries").
"sonar.binaries" should contain only compiled sources, not tests
No. Only "sonar.libraries" can (and actually must) point to JAR files.

Cleanup Antscript

Are there any tools available that allow the cleanup of a ant script?
I especially need to remove unecessary jar files... The Ant script I have to clean has more than 500 entries and has grown uncrontrolled over time.
There's no automated way of cleaning up jar files. You can look at the various include statements in your Java code, but they merely mention classes to include and not the jar themselves. Even if you can determine that a particular class is served by jarA.jar, it could be that jarA.jar is dependent upon jarB.jar.
You can even start removing jar files one at a time to see what breaks your build. That can be somewhat automated, especially if you specify your classpath via fileset instead of each specific jar. However, what if you actually need a jar for runtime, and not for the build?
My suggestion is to use Ant with Ivy. Ivy gives you the same Maven jar dependency capabilities without converting your project to Maven.
Take a look at Ivy and see how it works with Ant. Then, if possible, ask your developers to determine exactly what jars they need and what versions of those jars they need. You will have to help them. You might have to go through the jars in your repository and attempt to figure out what versions of the jars are in your repository.
You don't have to worry about jars that other jars depend upon. Ivy will take care of that for you. What you simply need are the jars that your developers depend upon, and they should know because they're the ones who use the include statements in their programs to specify a particular dependency.
Once you've determined the primary jars (and revisions) you need, you can easily convert your build.xml files to take advantage of Ivy's jar dependency system. Once you've done that, you can remove all the jars from your source repository since Ant with Ivy will download the required ones from the Internet based Maven repository system.

Resources