Coder Social home page Coder Social logo

sphinx-javalink's Introduction

sphinx-javalink

A Sphinx extension for linking to javadoc-generated API documentation.

Installation

sphinx-javalink is availabe from PyPI:

pip install sphinx-javalink

Usage

Use the javaref role to link to Java types, members, and packages:

Alpacas are best stored in a :javaref:`java.util.HashMap`, while clients
may find that goats perform best in a :javaref:`java.util.TreeMap`. In
either case, use :javaref:`biz.cloudgoats.api.Wizard#convert(Object)` to
produce legally binding contracts.

For more details, see the :javaref:`biz.cloudgoats.api` package.

Reference targets use standard Javadoc @see and @link syntax. Reference titles are generated based on the configuration options described below. To use an explicit title, place the Java reference in angle brackets following the title:

:javaref:`I like objects! <java.lang.Object>`

By default, references must be fully qualified. For convenience, use the javaimport directive to import commonly used types:

.. javaimport::
   java.util.*
   biz.cloudgoats.api.Wizard

Alpacas are best stored in a :javaref:`HashMap`, while clients may find
that goats perform best in a :javaref:`TreeMap`. In either case, use
:javaref:`Wizard#convert(Object)` to produce chocolate covered pebbles or
peanuts, depending on environmental factors.

For more details, see the :javaref:`biz.cloudgoats.api` package.

Each import appears on its own line and may be either a type or a package name followed by a *. As in Java, this imports all types in the package. All types in the java.lang package are imported by default.

The javaimport directive must appear before the first javaref that uses one of the imported types. A document can have multiple javaimport directives; the imports are cumulative.

Examples

A simple example conf.py is included in the repository. For real-world examples, see these projects:

Configuration

javalink_classpath

Default: []

A list of jar files and directories in which to search for classes. Elements can take one of three forms:

  1. /path/to/library.jar - an absolute or relative path to a jar file
  2. /path/to/classes/dir - an absolute or relative path a directory containing class files
  3. /path/to/jar/dir/* - an absolute or relative path a directory containing jar files. Only jar files that are direct children of the directory are loaded.

All relative paths are relative to the source directory.

To link to classes in the standard library, rt.jar (shipped with the JRE) must be on the class path. Use javalink.find_rt_jar() to find the location of this jar on the local system. This function respects the JAVA_HOME environment variable and may optionally take the path to an alternative directory as an argument.

javalink_docroots

Default: []

A list of Javadocs that can be the target of links. A valid package-list file must exist in the directory specified by the root path or URL.

List elements may be either:

  1. A string
  2. A dictionary with the following keys:
    • root (string, required)
    • base (string, optional)
    • version (integer, optional)

Providing a string is equivalent to providing a dictionary with only the root key.

root is a path or URL used to fine the package-list file. base is the base component of generated links; if it is not specified, the value of root is used. version is the version of the javadoc tool used to generate the documentation; if it is not specified, the value of javalink_default_version is used.

Specifying a base that differs from root is useful when the package-list is available at a local path that is not available from the built and published documentation. This also allows offline builds, by downloading all remote package-list files ahead of time.

javalink_default_version

Default: 7

The version of the javadoc tool assumed if a version is not provided for a docroot. The version determines the format of generated links, which was changed in Java 8.

javalink_add_method_parameters

Default: True

A boolean that determines if parameter lists and parentheses are appended to generated method references. References with explicit titles are not modified.

javalink_add_package_names

Default: True

A boolean that determines if fully-qualified package names are prepended to generated references. References with explicit titles are not modified.

javalink_qualify_nested_types

Default: True

A boolean that determines if containing type names are prepended to generated references to nested types. Only applies if javalink_add_package_names is False. References with explicit titles are not modified.

Limitations and Known Issues

  • When linking to methods, only the types of arguments may be specified. Specifying argument names will produce incorrect results.
  • All references are created as literal nodes.

Requirements

  • Python 2.7 (no support for Python 3)
  • Sphinx
  • javatools

Contributing

Pull requests, bug reports, and feature requests are welcome.

License

MIT, see the LICENSE file.

Changelog

0.11.1 (2016-01-13)

  • Open resources lazily
  • Fix incorrect environment cache invalidation
  • Fix potential ordering issues with Sphinx events (thanks to @rlepinski)

0.11.0 (2015-12-13)

  • Significantly improve performance (10x speedup in testing)
    • Cache missing classes (thanks to @rlepinski)
    • Open all resources at startup instead of reopening for every class search
  • Fix reporting of invalid references for class paths with class files

0.10.2 (2015-12-02)

  • Support linking to overloaded methods (thanks to @thasso)

0.10.1 (2015-09-02)

  • Fix syntax error in env-merge-info hook (thanks to @dadouf)

0.10.0 (2015-08-30)

  • Support the env-merge-info hook
  • Fix #5 - support Java 8 link formats; required a breaking change to the javalink_docroots syntax (thanks to @dadouf)

0.9.2 (2015-03-08)

  • Fix #3 - resolve paths relative to the source directory

0.9.1 (2015-03-03)

  • Fix #2 - correctly generate links to varargs methods
  • Fix #1 - find_rt_jar() now works correctly on OS X

0.9.0 (2015-01-25)

  • Initial release

sphinx-javalink's People

Contributors

bluekeyes avatar rlepinski avatar thasso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sphinx-javalink's Issues

find_rt_jar() is broken on OS X with default environment

Because Apple dropped support for Java after Java 6 and left things to Oracle for Java 7 and Java 8, the way Java works on OS X is... non-standard. The program linked to /usr/bin/java is a wrapper that finds the latest Oracle binaries or uses the value given in JAVA_HOME and as a result, the assumption that find_rt_jar makes about the location of rt.jar relative to java is incorrect. If you set JAVA_HOME to point to the Oracle install (using /usr/libexec/java_home), then everything works as expected.

If running on OS X and no other options are set, we should probably execute /usr/libexec/java_home to find JAVA_HOME instead of guessing it based on the location of java.

Link generation for varargs methods is broken

To link to a varargs method, you have to use array syntax, but anchor tags for these methods use the ... syntax.

Check with javadoc to see what it allows for links and then fix this to do the same thing. I suspect we need to support both options for references, but only use varargs syntax in generated URLs.

Generates URLs with "(" while Javadoc has anchors with "-"

Hey,

I've been using sphinx-javalink plugin for my project (http://dev.flitch.io). Good job, it's very neat and rather easy to setup ;)

I run into a problem that has to see with a difference of behaviour between what Javadoc expects, and what your tool generates. Example here: http://dev.flitch.io/sdkandroid.html#bind-to-flitchio

In that paragraph, the hyperlink over onCreate() is:
http://dev.flitch.io/javadoc/com/supenta/flitchio/sdk/FlitchioController.html#onCreate()

Yet when we follow the link, it doesn't go to the right anchor. Indeed, when we look for the anchor, it is actually:
http://dev.flitch.io/javadoc/com/supenta/flitchio/sdk/FlitchioController.html#onCreate--

The difference is with the last 2 characters, the brackets, that Javadoc has encoded as dashes. I couldn't see any configuration to influence this behaviour, in either Javadoc or sphinx-javalink. I use very standard settings in both.

What can I do?
Thank you very much.

Paths are not relative to conf.py

Paths in javalink_classpath and javalink_docroots claim to be relative to the source directory. Instead, they are relative to the working directory of sphinx-build. Fix the docs or the code, but probably the code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.