Example usage for java.util.regex PatternSyntaxException PatternSyntaxException

List of usage examples for java.util.regex PatternSyntaxException PatternSyntaxException

Introduction

In this page you can find the example usage for java.util.regex PatternSyntaxException PatternSyntaxException.

Prototype

public PatternSyntaxException(String desc, String regex, int index) 

Source Link

Document

Constructs a new instance of this class.

Usage

From source file:org.apache.maven.plugin.javadoc.JavadocUtil.java

/**
 * Parse the output for 'javadoc -J-version' and return the javadoc version recognized.
 * <br/>//w  w  w .j  a v  a 2  s.  c om
 * Here are some output for 'javadoc -J-version' depending the JDK used:
 * <table>
 * <tr>
 *   <th>JDK</th>
 *   <th>Output for 'javadoc -J-version'</th>
 * </tr>
 * <tr>
 *   <td>Sun 1.4</td>
 *   <td>java full version "1.4.2_12-b03"</td>
 * </tr>
 * <tr>
 *   <td>Sun 1.5</td>
 *   <td>java full version "1.5.0_07-164"</td>
 * </tr>
 * <tr>
 *   <td>IBM 1.4</td>
 *   <td>javadoc full version "J2RE 1.4.2 IBM Windows 32 build cn1420-20040626"</td>
 * </tr>
 * <tr>
 *   <td>IBM 1.5 (French JVM)</td>
 *   <td>javadoc version complte de "J2RE 1.5.0 IBM Windows 32 build pwi32pdev-20070426a"</td>
 * </tr>
 * <tr>
 *   <td>FreeBSD 1.5</td>
 *   <td>java full version "diablo-1.5.0-b01"</td>
 * </tr>
 * <tr>
 *   <td>BEA jrockit 1.5</td>
 *   <td>java full version "1.5.0_11-b03"</td>
 * </tr>
 * </table>
 *
 * @param output for 'javadoc -J-version'
 * @return the version of the javadoc for the output.
 * @throws PatternSyntaxException if the output doesn't match with the output pattern
 * <tt>(?s).*?([0-9]+\\.[0-9]+)(\\.([0-9]+))?.*</tt>.
 * @throws IllegalArgumentException if the output is null
 */
protected static float parseJavadocVersion(String output) throws IllegalArgumentException {
    if (StringUtils.isEmpty(output)) {
        throw new IllegalArgumentException("The output could not be null.");
    }

    Pattern pattern = Pattern.compile("(?s).*?([0-9]+\\.[0-9]+)(\\.([0-9]+))?.*");

    Matcher matcher = pattern.matcher(output);
    if (!matcher.matches()) {
        throw new PatternSyntaxException("Unrecognized version of Javadoc: '" + output + "'", pattern.pattern(),
                pattern.toString().length() - 1);
    }

    String version = matcher.group(3);
    if (version == null) {
        version = matcher.group(1);
    } else {
        version = matcher.group(1) + version;
    }

    return Float.parseFloat(version);
}