1

I'm using the Apache Felix Maven Bundle Plugin to generate the OSGi metadata.

<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>

You can configure which packages are exported or you can use the default, which excludes packages such as *.impl.* and *.internal.*.

Is there a way to generate Javadoc only for the exported packages without having to duplicate this information?

Edit:

My current approach is that I set the excludePackageNames property (a Maven Javadoc Plugin property) manually and thus duplicate this information:

<excludePackageNames>*.internal.*:*.impl.*</excludePackageNames> <!-- used by Javadoc plugin --><!-- TODO: get this from OSGi meta data-->

http://sourceforge.net/p/drombler/drombler-oss-parent/ci/default/tree/pom.xml#l64

Puce
  • 37,247
  • 13
  • 80
  • 152
  • maybe you could run the javadoc with the content of the generated jar? – poussma Jul 23 '12 at 20:15
  • Could you explain this further? The Javadoc information is not included in the class files, AFAIK. – Puce Jul 23 '12 at 20:37
  • 1
    I was thinking of extracting the list of included files in the jar and passing this list to the javadoc binary. I am afraid this is the only way to generate the documentation that sticks to the jar content. I cannot see another way. – poussma Jul 23 '12 at 20:46
  • This is an interesting question. I'd imagine that one could create a maven plugin that read the generated Manifest.MF and fed that as configuration to the javadoc generator, as @ZNK-M suggested. – Chris Dolan Jul 25 '12 at 12:43
  • BTW, I thought of another solution yesterday. I was answering a question about ant on so.com. The guy was using the file mapper object. That allows you to transform a file name to another. For Instance convert *.class found in a jar to *.html. You can then pass the result of it to another task. You could generate the whole javadoc and copy only the files that matches the mapper. – poussma Jul 25 '12 at 12:54
  • @ChrisDolan yes, this seems the way to go, e.g. a Maven Plugin Goal which populates `excludePackageNames` used by the Javadoc Plugin. maven-bundle-plugin doesn't seem to provide this goal. Is there another plugin? It's strange this is not a common use case. – Puce Jul 25 '12 at 13:03
  • @Puce - I think Javadoc is just not as important as it used to be. A pattern I'm seeing instead is source distribution of the API jar. Source is a superset of Javadoc if your IDE is good enough. – Chris Dolan Jul 25 '12 at 13:11
  • @ChrisDolan can you provide your comment as an answer.In case nobody else comes with a ready solution, I will accept it. – Puce Jul 25 '12 at 13:16
  • @ZNK-M the jar also contains the private packages, so analyzing the classes in the jar doesn't help I think. – Puce Jul 25 '12 at 13:19

2 Answers2

0

The Apache Maven bundle plugin is based on bndlib, which has its own plugin model. If a maven plugin model has class visibility to other maven plugins then it is easy to get this information. In the instructions in the pom register a plugin:

<instructions>
  <_plugin>com.example.MyPlugin</_plugin>
</instruction>

In this bnd plugin, implement the AnalyzerPlugin interface

boolean analyzeJar(Analyzer analyzer) throws Exception {
   doJavadoc( analyzer.getExportedPackages().keySet() );
}

I am not that familiar with maven plugins, since bnd will do dynamic class loader (yuck), it must be able to see your code.

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
  • Thanks for your answer, but I'm not sure I'm getting everything. Please see my update for my current approach. I think I have to set the excludePackageNames property with information retrieved from bnd in order to integrate with the Maven Javadoc Plugin. I guess your approach would mean not to use the Maven Javadoc Plugin? – Puce Jul 24 '13 at 08:56
  • yes, you would have too generate your own javadoc. I guess you could also use the information to set a property that is then used by the javadoc plugin. This answer just provides you with the package names that are actually exported. – Peter Kriens Jul 24 '13 at 10:03
0

I guess the best thing would be, if the Maven Bundle Plugin would provide a goal to generate the needed information.

I filed a new issue: https://issues.apache.org/jira/browse/FELIX-4181

Puce
  • 37,247
  • 13
  • 80
  • 152