Skip to content

Commit

Permalink
[MJAVADOC-617] Normalize module path so that '..' in the path are res…
Browse files Browse the repository at this point in the history
…olved (#27)

* MJAVADOC-617 Normalize module path so that '..' in the path are resolved

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.

* MJAVADOC-617 Add regression test

* MJAVADOC-617 Simplify code as suggested by review

* MJAVADOC-617 Fix checkstyle problems

* MJAVADOC-617 Refactor duplicated code into abstract sub classes

- Refactor duplicated code into common new
AbstractAggregateMavenProjectStub and
AbstractAggregateChildMavenProjectStub classes
- Fix toLowerCase without Locale
- Simplify method getOverviewSummary and make it static

* MJAVADOC-617 improve test assertions
  • Loading branch information
weissreto committed Apr 8, 2020
1 parent e203bbf commit d39b275
Show file tree
Hide file tree
Showing 15 changed files with 497 additions and 168 deletions.
Expand Up @@ -2401,10 +2401,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() );
modulePaths.add( basePath.resolve( module ).normalize() );
}

Set<MavenProject> aggregatedModules = new LinkedHashSet<>();
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
Expand Down Expand Up @@ -232,18 +233,10 @@ 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();
String overview = readFile( overviewSummary ).toLowerCase( Locale.ENGLISH );
assertTrue( overview.contains( "<a href=\"resources/test/package-summary.html\">resources.test</a>" ) );
assertTrue( overview.contains( ">blabla</" ) );
assertTrue( overview.contains( "<a href=\"resources/test2/package-summary.html\">resources.test2</a>" ) );
Expand All @@ -257,4 +250,25 @@ 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.isDirectory() );
assertTrue( getOverviewSummary( apidocs ).isFile() );
}

private static File getOverviewSummary(File apidocs)
{
if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
{
return new File( apidocs, "overview-summary.html" );
}
return new File( apidocs, "index.html" );
}

}
@@ -0,0 +1,82 @@
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:reto.weiss@axonivy.com">Reto Weiss</a>
*/
public class AbstractAggregateChildMavenProjectStub
extends MavenProjectStub
{
private String baseDir;

public AbstractAggregateChildMavenProjectStub(String baseDir, String pomFileName, String targetDirectory)
{
this.baseDir = baseDir;
readModel( new File( getBasedir(), pomFileName ) );

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() + targetDirectory );
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() + baseDir );
}

/** {@inheritDoc} */
@Override
public MavenProject getExecutionProject()
{
return this;
}
}
@@ -0,0 +1,90 @@
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.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;

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:reto.weiss@axonivy.com">Reto Weiss</a>
*/
public class AbstractAggregateMavenProjectStub
extends MavenProjectStub
{
private final String baseDir;
private final String[] projects;
public AbstractAggregateMavenProjectStub(String baseDir, String pomFileName, String targetDirectory, String... projects)
{
this.baseDir = baseDir;
this.projects = projects;
readModel( new File( getBasedir(), pomFileName) );

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

setExecutionRoot( true );

Build build = new Build();
build.setFinalName( getModel().getArtifactId() );
build.setSourceDirectory( getBasedir() + "/src/main/java" );
build.setDirectory( super.getBasedir() + targetDirectory );
setBuild( build );

List<String> compileSourceRoots = new ArrayList<>();
setCompileSourceRoots( compileSourceRoots );
}

@Override
public File getBasedir()
{
return new File( super.getBasedir() + baseDir);
}

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

@Override
public List<String> getModules()
{
return Arrays.asList( projects );
}

@Override
public Set<Artifact> getDependencyArtifacts()
{
return Collections.emptySet();
}
}
@@ -0,0 +1,34 @@
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.
*/

/**
* @author <a href="mailto:reto.weiss@axonivy.com">Reto Weiss</a>
*/
public class AggregateNotInSubFolderProject1TestMavenProjectStub
extends AbstractAggregateChildMavenProjectStub
{
public AggregateNotInSubFolderProject1TestMavenProjectStub()
{
super( "/src/test/resources/unit/aggregate-modules-not-in-subfolders-test/project1",
"pom.xml",
"/target/test/unit/aggregate-modules-not-in-subfolders-test/project1/target" );
}
}
@@ -0,0 +1,34 @@
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.
*/

/**
* @author <a href="mailto:reto.weiss@axonivy.com">Reto Weiss</a>
*/
public class AggregateNotInSubFolderProject2TestMavenProjectStub
extends AbstractAggregateChildMavenProjectStub
{
public AggregateNotInSubFolderProject2TestMavenProjectStub()
{
super( "/src/test/resources/unit/aggregate-modules-not-in-subfolders-test/project2",
"pom.xml",
"/target/test/unit/aggregate-modules-not-in-subfolders-test/project2/target");
}
}
@@ -0,0 +1,36 @@
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.
*/

/**
* @author <a href="mailto:reto.weiss@axonivy.com">Reto Weiss</a>
*/
public class AggregateNotInSubFolderTestMavenProjectStub
extends AbstractAggregateMavenProjectStub
{
public AggregateNotInSubFolderTestMavenProjectStub()
{
super( "/src/test/resources/unit/aggregate-modules-not-in-subfolders-test/all",
"pom.xml",
"/target/test/unit/aggregate-modules-not-in-subfolders-test/target",
"../project1",
"../project2");
}
}

0 comments on commit d39b275

Please sign in to comment.