{"action":"created","issue":{"url":"https://api.github.com/repos/paul-hammant/qdox/issues/5","labels_url":"https://api.github.com/repos/paul-hammant/qdox/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/paul-hammant/qdox/issues/5/comments","events_url":"https://api.github.com/repos/paul-hammant/qdox/issues/5/events","html_url":"https://github.com/paul-hammant/qdox/issues/5","id":94960662,"number":5,"title":"Improve addSource(File source) to accept package-info.java files as well.","user":{"login":"lennartj","id":906157,"avatar_url":"https://avatars.githubusercontent.com/u/906157?v=3","gravatar_id":"","url":"https://api.github.com/users/lennartj","html_url":"https://github.com/lennartj","followers_url":"https://api.github.com/users/lennartj/followers","following_url":"https://api.github.com/users/lennartj/following{/other_user}","gists_url":"https://api.github.com/users/lennartj/gists{/gist_id}","starred_url":"https://api.github.com/users/lennartj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lennartj/subscriptions","organizations_url":"https://api.github.com/users/lennartj/orgs","repos_url":"https://api.github.com/users/lennartj/repos","events_url":"https://api.github.com/users/lennartj/events{/privacy}","received_events_url":"https://api.github.com/users/lennartj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-14T14:45:45Z","updated_at":"2015-07-14T21:28:11Z","closed_at":null,"body":"When using QDox to extract information from a ```package-info.java``` file, we currently have to use the ```addSource(URL)``` method, since the ```addSource(File)``` simply ignores package-info.java files. This is not documented, as far as I can see. The code snippet below is from SourceLibrary.java, and it has opinions about the package-info.java when added as a File - but parses it happily when added as an URL:\r\n\r\n```java\r\n    /**\r\n     * Add a {@link URL} containing java code to this library\r\n     * \r\n     * @param url a {@link URL} which should contain java code\r\n     * @return The constructed {@link JavaSource} object of this url\r\n     * @throws ParseException if this content couldn't be parsed to a JavaModel\r\n     */\r\n    public JavaSource addSource( URL url )\r\n        throws ParseException, IOException\r\n    {\r\n        return addSource( new InputStreamReader( url.openStream(), encoding), url );\r\n    }\r\n\r\n    /**\r\n     * Add a {@link File} containing java code to this library\r\n     * \r\n     * @param file a {@link File} which should contain java code\r\n     * @return The constructed {@link JavaSource} object of this file\r\n     * @throws ParseException\r\n     * @throws IOException\r\n     */\r\n    public JavaSource addSource( File file )\r\n        throws ParseException, IOException\r\n    {\r\n        JavaSource result = null;\r\n        if ( !\"package-info.java\".equals( file.getName() ) ) \r\n        {\r\n            result = parse( new FileInputStream( file ), file.toURI().toURL() );\r\n            // if an error is handled by the errorHandler the result will be null\r\n            if( result != null )\r\n            {\r\n                if( getJavaPackage( result.getPackageName() ) == null )\r\n                {\r\n                    File packageInfo = new File(file.getParentFile(), \"package-info.java\");\r\n                    if( packageInfo.exists() )\r\n                    {\r\n                        JavaPackage pckg = parse( new FileInputStream( packageInfo ), packageInfo.toURI().toURL() ).getPackage();\r\n                        context.add( pckg );\r\n                    }\r\n                }\r\n                registerJavaSource(result);\r\n            }\r\n        }\r\n    \treturn result;\r\n    }\r\n```\r\n\r\nThis leads to somewhat clunky code on the client side:\r\n\r\n```java\r\nif(sourceCodeFile.getName().trim().equalsIgnoreCase(\"package-info.java\")) {\r\n\r\n                // For some reason, QDox requires the package-info.java to\r\n                // be added as a URL instead of a File.\r\n                builder.addSource(sourceCodeFile.toURI().toURL());\r\n                ....\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/paul-hammant/qdox/issues/comments/121395131","html_url":"https://github.com/paul-hammant/qdox/issues/5#issuecomment-121395131","issue_url":"https://api.github.com/repos/paul-hammant/qdox/issues/5","id":121395131,"user":{"login":"lennartj","id":906157,"avatar_url":"https://avatars.githubusercontent.com/u/906157?v=3","gravatar_id":"","url":"https://api.github.com/users/lennartj","html_url":"https://github.com/lennartj","followers_url":"https://api.github.com/users/lennartj/followers","following_url":"https://api.github.com/users/lennartj/following{/other_user}","gists_url":"https://api.github.com/users/lennartj/gists{/gist_id}","starred_url":"https://api.github.com/users/lennartj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lennartj/subscriptions","organizations_url":"https://api.github.com/users/lennartj/orgs","repos_url":"https://api.github.com/users/lennartj/repos","events_url":"https://api.github.com/users/lennartj/events{/privacy}","received_events_url":"https://api.github.com/users/lennartj/received_events","type":"User","site_admin":false},"created_at":"2015-07-14T21:28:11Z","updated_at":"2015-07-14T21:28:11Z","body":"A reference to the actual code is in the \r\n\r\nhttps://github.com/mojohaus/jaxb2-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/jaxb2/schemageneration/AbstractXsdGeneratorMojo.java\r\n\r\nin the method\r\n\r\n````java\r\nprivate List<String> getSchemaGeneratorSourceFiles(final List<URL> sources)\r\n            throws IOException, MojoExecutionException { ... } \r\n````\r\n"}}