
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.io.*;

// In JDK 7, javadoc terminates with exit code 0 even when there are errors.
// To find an error, we either have to parse the build.log generated by
// maven-invoker-plugin, or look at the generated HTML files.
// The latter is approach is more stable, as it does not depend on a given
// javadoc version or the error message formatting.
// Our module2 has a dependency on commons-io, and class Bar has a parameter
// of type org.apache.commons.io.ByteOrderMark. In the generated Javadoc,
// this parameter type should occur with its fully qualified name.
// If the package prefix is missing, we know that maven-javadoc-plugin
// failed to resolve the classpath dependencies.

boolean result = true;

try
{
    File javadoc = new File( basedir, "target/site/apidocs/com/example/bar/Bar.html" );
    if ( !javadoc.exists() )
    {
        System.err.println( javadoc + " is missing" );
        return false;
    }

    FileReader fr = new FileReader( javadoc );
    BufferedReader br = new BufferedReader( fr );
    String line;
    while ( ( line = br.readLine() ) != null )
    {
        if ( line.contains( "org.apache.commons.io" ) )
        {
            result = true;
            break;
        }
    }
    br.close();
    if ( !result )
    {
        System.err.println( "package name org.apache.commons.io not found" );
    }
    return result;
}
catch ( Exception e )
{
    e.printStackTrace();
    return false;
}

return result;
