Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MJAVADOC-617] Normalize module path so that '..' in the path are resolved #27

Merged
merged 6 commits into from Apr 8, 2020

Conversation

weissreto
Copy link
Contributor

@weissreto weissreto commented Jul 19, 2019

On line 2403 a path is removed from a map. The given path may not be normalized but the pathes in the map are. This leads to the fact that the project for the given path is not found. And therefore no javadoc for the project is generated.
By normalizing the module path on line 2396 the code works event if the module path has '..' in it.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MJAVADOC-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MJAVADOC-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [x ] Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

On line 2403 a path is removed from a map. The given path may not be normalized but the pathes in the map are. This leads to the fact that the project for the given path is not found. And therefore no javadoc for the project is generated.
By normalizing the module path on line 2396 the code works event if the module path has '..' in it.
@chrisinmtown
Copy link

chrisinmtown commented Jan 21, 2020

I see that this project is active. The javadoc plugin version 3.1.1 has this bug, @weissreto has proposed a fix. Is the team considering a merge and release of a new version? Thanks in advance for any info.

@eolivelli
Copy link
Contributor

@chrisinmtown yes the project is hopefully still alive :)
We are very few, only volunteers, that work on Maven, that is composed of tens of repositories.
If you are interested in merging this fix you can ping politely for it and you can also bring to to the attention using dev@maven.apache.org mailing list.

I will check this issue as soon as I have cycles

@chrisinmtown
Copy link

chrisinmtown commented Jan 22, 2020

Thanks @eolivelli for the quick reply.
@weissreto I guess there is no test case now that reveals this failure, may I suggest that you please add a case to test the behavior, the case should fail on the 3.1.0 and 3.1.1 code, and pass on the code you propose.

@@ -2393,7 +2393,7 @@ protected void executeReport( Locale unusedLocale )
List<Path> modulePaths = new LinkedList<>();
for ( String module : aggregatedProject.getModules() )
{
modulePaths.add( new File( aggregatedProject.getBasedir(), module ).toPath() );
modulePaths.add( new File( aggregatedProject.getBasedir(), module ).toPath().normalize() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably use Paths.get here and avoid the File class completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have simpified code to use only class Path and not File.
Added also a regression test for the issue

@@ -1,5 +1,43 @@
package org.apache.maven.plugins.javadoc;

import static org.apache.maven.plugins.javadoc.JavadocUtil.isEmpty;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a not a well known class so static imports should probably be avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Elliotte
Sorry I messed up this commit, because my IDE reorganized the whole import section of this file. I reverted that in my last commit. I could squash the commits to get a clearer history if that is recommended. However I have not introduced this static import in this commit here I only moved it around.
Do I still have to refactor this static import? This will introduce some additional changes to this PR that are not relevant to the issue I try to fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that the imports were reorganized. If this is existing code, no need to fix it here. I don't know if maven follows any conventions for import ordering, but absent that it's best not to reorder imports to avoid churn.

{
overviewSummary = new File( apidocs, "index.html" );
}
File overviewSummary = getOverviewSummary(apidocs);

assertTrue( overviewSummary.exists() );
String overview = readFile( overviewSummary ).toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toLowerCase needs a locale

mojo.execute();

File apidocs = new File( getBasedir(), "target/test/unit/aggregate-modules-not-in-subfolders-test/target/site/apidocs" );
assertTrue(apidocs.exists());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertTrue( apidocs.exists() );


File apidocs = new File( getBasedir(), "target/test/unit/aggregate-modules-not-in-subfolders-test/target/site/apidocs" );
assertTrue(apidocs.exists());
assertTrue( getOverviewSummary(apidocs).exists() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( apidocs )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems checkstyle does not run on test classes ...
Will fix

File overviewSummary;
if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
{
overviewSummary = new File( apidocs, "overview-summary.html" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return new File...
is shorter and avoids an uninitialized variable.

}
else
{
overviewSummary = new File( apidocs, "index.html" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return new File...

assertTrue( getOverviewSummary(apidocs).exists() );
}

private File getOverviewSummary(File apidocs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static

import org.apache.maven.project.MavenProject;

/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this you?

import org.apache.maven.project.MavenProject;

/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you?

{
public AggregateNotInSubFolderProject2TestMavenProjectStub()
{
readModel( new File( getBasedir(), "pom.xml" ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of duplicate code here that could probably be refactored into a common location.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that there is alot of duplicated code. I copied them from older test classes that made the same thing. Will refactor all this code.

However, why do I need this stub classes at all? I tried to avoid them but then the test seems not to work correctly?

- Refactor duplicated code into common new
AbstractAggregateMavenProjectStub and
AbstractAggregateChildMavenProjectStub classes
- Fix toLowerCase without Locale
- Simplify method getOverviewSummary and make it static
@elharo elharo changed the title MJAVADOC-617 Normalize module path so that '..' in the path are resolved [MJAVADOC-617] Normalize module path so that '..' in the path are resolved Apr 1, 2020
Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some nits

mojo.execute();

File apidocs = new File( getBasedir(), "target/test/unit/aggregate-modules-not-in-subfolders-test/target/site/apidocs" );
assertTrue( apidocs.exists() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apidocs.isDirectory() would be slightly stronger test


File apidocs = new File( getBasedir(), "target/test/unit/aggregate-modules-not-in-subfolders-test/target/site/apidocs" );
assertTrue( apidocs.exists() );
assertTrue( getOverviewSummary( apidocs ).exists() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists --> isFile?

@weissreto
Copy link
Contributor Author

Hi Elliotte

Thanks a lot for reviewing and approving my PR.
What is next? Do I have to do something else so that my PR is merged?

Thanks for any advise.

Regards
Reto

@elharo elharo merged commit d39b275 into apache:master Apr 8, 2020
@weissreto
Copy link
Contributor Author

Thanks a lot for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants