1 |
Hello, all, |
2 |
|
3 |
I recently created some new ebuilds for the hamcrest matcher libraries. |
4 |
In my ebuilds, I had added some functionality to so that the Javadoc=20 |
5 |
that is created will link to locally-installed documentation. On |
6 |
#gentoo-java, Betelgeuse recommended I that I generalise the |
7 |
functionality so that it can be applied more generally. I believe this |
8 |
also the topic of bug 145750. |
9 |
|
10 |
I have come up with an initial implementation for this and would like to |
11 |
get some feedback from other people. My implementation is broken up |
12 |
into two parts: |
13 |
|
14 |
1. An additional script to be added to javatoolkit: This was necessary |
15 |
as the existing xml-rewrite* scripts seem to concentrate on manipulating |
16 |
attributes, but this task required manipulating elements. This script |
17 |
is available as a patch to javatoolkit-0.3.0 available at: |
18 |
https://bugs.gentoo.org/attachment.cgi?id=3D207944 |
19 |
|
20 |
2. Modifications to the java-ant-2.eclass: I added a new function |
21 |
java-ant_link-javadoc() that does the work of looking up local |
22 |
documentation and calling the helper script. I also added a hook to the |
23 |
function from java-ant-2_src-configure(). This patch is available at: |
24 |
https://bugs.gentoo.org/attachment.cgi?id=3D207945 |
25 |
|
26 |
|
27 |
How it Works |
28 |
------------ |
29 |
|
30 |
When java-ant_link-javadoc() is called, it first checks to see if |
31 |
java-sdk-docs is installed, and if so gets the path to the API |
32 |
documentation. |
33 |
|
34 |
Next, it looks at the environment variable JAVA_ANT_DOCPATH, which by |
35 |
default is copied from EANT_GENTOO_CLASSPATH. It uses java-config to |
36 |
see if the JAVADOC_PATH is set for the package. If so, it adds it to |
37 |
the list of paths to documentation. |
38 |
|
39 |
Finally, it uses the javadoc-helper script with the found paths. This |
40 |
script searches for <javadoc> elements, strips them of any existing link |
41 |
information, and injects the link information passed from the command |
42 |
line. |
43 |
|
44 |
|
45 |
Limitations |
46 |
----------- |
47 |
|
48 |
1. The method above is opportunistic. If the user does not have any |
49 |
local API documentation, none is used. It is possible to modify the |
50 |
script to ensure that an ebuild's dependencies have the doc USE flag |
51 |
enabled, but that seems a bit heavy-handed to me. |
52 |
|
53 |
2. This method clobbers any existing link information in the build.xml. |
54 |
I did things this way because it was simplest. I do not know how |
55 |
Javadoc deals with overlapping packagelist information. It may be |
56 |
desirable to add a flag that disables this functionality for a given |
57 |
ebuild. |
58 |
|
59 |
3. This method does not link to external documentation. At least, if |
60 |
its not listed in a package.env. Allowing ebuild writers to define a |
61 |
JAVADOC_URL to be added to package.env could allow it. If the |
62 |
packagelist could be found locally, the javadoc-helper tool can even |
63 |
perform the linking offline. |
64 |
|
65 |
4. The SDK link uses the most recent version of java-sdk-docs. Perhaps |
66 |
it would help if script used the same version of the documentation as |
67 |
the JDK it is using. |
68 |
|
69 |
|
70 |
Other Notes |
71 |
----------- |
72 |
|
73 |
1. Since this is the first time I get into the details of how portage |
74 |
works and modifying eclasses, I appreciate any comments on how my |
75 |
implementation can be improved. For example, is there a better place to |
76 |
hook into java-ant_link-javadoc() script? |
77 |
|
78 |
2. The code is not thoroughly tested. I have not tried it with any |
79 |
alternative package managers. I appreciate any feedback on how to |
80 |
ensure that it is robust. Also, I am not a Python coder, so there may |
81 |
be errors lurking of which I am unaware. |
82 |
|
83 |
3. In my Python code I tried to use the principles in Robert Martin's |
84 |
book 'Clean Code'. Namely, the proliferation of many small, cohesive |
85 |
methods. I do not know what others think of it, but it was worth |
86 |
trying. |
87 |
|
88 |
|
89 |
I look forward to any feedback. I have attached the patches to bug |
90 |
145750 for review. Please let me know if there is anything I can do to |
91 |
improve this functionality. |
92 |
|
93 |
Sincerely, |
94 |
|
95 |
Daniel Solano Gómez |