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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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.

import static org.apache.maven.plugins.javadoc.JavadocUtil.isNotEmpty;
import static org.apache.maven.plugins.javadoc.JavadocUtil.toList;
import static org.apache.maven.plugins.javadoc.JavadocUtil.toRelative;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -61,19 +99,19 @@
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Settings;
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
import org.apache.maven.shared.artifact.filter.resolve.AndFilter;
import org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter;
import org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter;
import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
import org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate;
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.apache.maven.wagon.PathUtils;
Expand Down Expand Up @@ -101,44 +139,6 @@
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.xml.Xpp3Dom;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;

import static org.apache.maven.plugins.javadoc.JavadocUtil.toRelative;
import static org.apache.maven.plugins.javadoc.JavadocUtil.toList;
import static org.apache.maven.plugins.javadoc.JavadocUtil.isEmpty;
import static org.apache.maven.plugins.javadoc.JavadocUtil.isNotEmpty;

/**
* Base class with majority of Javadoc functionalities.
*
Expand Down Expand Up @@ -2390,10 +2390,11 @@ private Set<MavenProject> modulesForAggregatedProject( MavenProject aggregatedPr
return Collections.singleton( aggregatedProject );
}

Path basePath = aggregatedProject.getBasedir().toPath();
List<Path> modulePaths = new LinkedList<>();
for ( String module : aggregatedProject.getModules() )
{
modulePaths.add( new File( aggregatedProject.getBasedir(), module ).toPath().normalize() );
modulePaths.add( basePath.resolve(module).normalize() );
}

Set<MavenProject> aggregatedModules = new LinkedHashSet<>();
Expand Down
Expand Up @@ -232,15 +232,7 @@ public void testAggregateJavadocResources()
File apidocs = new File( getBasedir(), "target/test/unit/aggregate-resources-test/target/site/apidocs" );

// Test overview
File overviewSummary;
if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
{
overviewSummary = new File( apidocs, "overview-summary.html" );
}
else
{
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

Expand All @@ -257,4 +249,30 @@ public void testAggregateJavadocResources()
assertTrue( overview.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" ) );
assertTrue( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
}

public void testAggregateWithModulsNotInSubFolders() throws Exception
{
File testPom = new File( unit, "aggregate-modules-not-in-subfolders-test/all/pom.xml");
JavadocReport mojo = lookupMojo( testPom );
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() );

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

}

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

{
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...

}
return overviewSummary;
}

}
@@ -0,0 +1,79 @@
package org.apache.maven.plugins.javadoc.stubs;

/*
* 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.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Build;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
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?

*/
public class AggregateNotInSubFolderProject1TestMavenProjectStub
extends MavenProjectStub
{
public AggregateNotInSubFolderProject1TestMavenProjectStub()
{
readModel( new File( getBasedir(), "pom.xml" ) );

setGroupId( Objects.toString( getModel().getGroupId(), getModel().getParent().getGroupId() ) );
setArtifactId( getModel().getArtifactId() );
setVersion( Objects.toString( getModel().getVersion(), getModel().getParent().getVersion() ) );
setName( getModel().getName() );
setUrl( getModel().getUrl() );
setPackaging( getModel().getPackaging() );

setExecutionRoot( true );

Artifact artifact = new JavadocPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
setArtifact( artifact );

Build build = new Build();
build.setFinalName( getModel().getArtifactId() );
build.setSourceDirectory( getBasedir() + "/src/main/java" );
build.setDirectory( super.getBasedir() + "/target/test/unit/aggregate-modules-not-in-subfolders-test/project1/target" );
setBuild( build );

List<String> compileSourceRoots = new ArrayList<>();
compileSourceRoots.add( getBasedir().getAbsolutePath() + "/src/main/java" );
setCompileSourceRoots( compileSourceRoots );
}

/** {@inheritDoc} */
@Override
public File getBasedir()
{
return new File( super.getBasedir() + "/src/test/resources/unit/aggregate-modules-not-in-subfolders-test/project1" );
}

/** {@inheritDoc} */
@Override
public MavenProject getExecutionProject()
{
return this;
}
}
@@ -0,0 +1,79 @@
package org.apache.maven.plugins.javadoc.stubs;

/*
* 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.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Build;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
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 class AggregateNotInSubFolderProject2TestMavenProjectStub
extends MavenProjectStub
{
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?


setGroupId( Objects.toString( getModel().getGroupId(), getModel().getParent().getGroupId() ) );
setArtifactId( getModel().getArtifactId() );
setVersion( Objects.toString( getModel().getVersion(), getModel().getParent().getVersion() ) );
setName( getModel().getName() );
setUrl( getModel().getUrl() );
setPackaging( getModel().getPackaging() );

setExecutionRoot( true );

Artifact artifact = new JavadocPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
setArtifact( artifact );

Build build = new Build();
build.setFinalName( getModel().getArtifactId() );
build.setSourceDirectory( getBasedir() + "/src/main/java" );
build.setDirectory( super.getBasedir() + "/target/test/unit/aggregate-modules-not-in-subfolders-test/project2/target" );
setBuild( build );

List<String> compileSourceRoots = new ArrayList<>();
compileSourceRoots.add( getBasedir() + "/src/main/java" );
setCompileSourceRoots( compileSourceRoots );
}

/** {@inheritDoc} */
@Override
public File getBasedir()
{
return new File( super.getBasedir() + "/src/test/resources/unit/aggregate-modules-not-in-subfolders-test/project2" );
}

/** {@inheritDoc} */
@Override
public MavenProject getExecutionProject()
{
return this;
}
}