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 5 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
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() );
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.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

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?

}

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");
}
}