Skip to content

Commit

Permalink
[MJAVADOC-338] When includeDependencySources=true the javadoc plugin …
Browse files Browse the repository at this point in the history
…should not download the internet every time it is run
  • Loading branch information
rfscholte committed Feb 24, 2019
1 parent 10ed96a commit fd0c42a
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 42 deletions.
35 changes: 35 additions & 0 deletions src/it/mrm/repository/mjavadoc338-direct.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.javadoc.its</groupId>
<artifactId>mjavadoc338-direct</artifactId>
<version>1.0</version>

<dependencies>
<dependency>
<groupId>org.apache.maven.plugins.javadoc.its</groupId>
<artifactId>mjavadoc338-transitive</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

</project>
27 changes: 27 additions & 0 deletions src/it/mrm/repository/mjavadoc338-transitive.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.javadoc.its</groupId>
<artifactId>mjavadoc338-transitive</artifactId>
<version>1.0</version>

</project>
9 changes: 9 additions & 0 deletions src/it/mrm/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ under the License.
-->

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>mrm-maven-plugin</id>
<name>Mock Repository Manager</name>
<url>@mrm.repository.url@</url>
<mirrorOf>*,!repo494,!repo514</mirrorOf>
</mirror>
</mirrors>

<profiles>
<profile>
<id>it-repo</id>
Expand Down
19 changes: 19 additions & 0 deletions src/it/projects/MJAVADOC-338_downloadSources/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.
invoker.debug = false
invoker.goals.1 = javadoc:javadoc
invoker.goals.2 = javadoc:javadoc
57 changes: 57 additions & 0 deletions src/it/projects/MJAVADOC-338_downloadSources/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>

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

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.javadoc.it</groupId>
<artifactId>mjavadoc338</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<includeDependencySources>true</includeDependencySources>
<doclint>none</doclint>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencies>
<dependency>
<groupId>org.apache.maven.plugins.javadoc.its</groupId>
<artifactId>mjavadoc338-direct</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package foo;

/*
* 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.
*/

public class Bar {}
36 changes: 36 additions & 0 deletions src/it/projects/MJAVADOC-338_downloadSources/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.
*/
// NOOO never from central

def buildLog = new File(basedir,'build.log')

if ( mavenVersion ==~ /3\.[0-3]\..*/ )
{
assert 1 == buildLog.readLines().count{it ==~ /\[INFO\] Downloading\: .+\/mjavadoc338-direct-1\.0-sources\.jar/}
assert 1 == buildLog.readLines().count{it ==~ /\[INFO\] Downloading\: .+\/mjavadoc338-direct-1\.0-javadoc-resources\.jar/}
}
else
{
assert 1 == buildLog.readLines().count{it ==~ /\[INFO\] Downloading from mrm-maven-plugin\: .+\/mjavadoc338-direct-1\.0-sources\.jar/}
assert 1 == buildLog.readLines().count{it ==~ /\[INFO\] Downloading from mrm-maven-plugin\: .+\/mjavadoc338-direct-1\.0-javadoc-resources\.jar/}
}


assert !buildLog.readLines().any{it ==~ /\[INFO\] Downloading from .+\/mjavadoc338-transitive-1\.0-sources\.jar/}
assert !buildLog.readLines().any{it ==~ /\[INFO\] Downloading from .+\/mjavadoc338-transitive-1\.0-javadoc-resources\.jar/}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<repositories>
<repository>
<id>local.private</id>
<id>repo494</id>
<url>@mrm.3rdparty.url@</url>
<releases>
<enabled>true</enabled>
Expand Down
2 changes: 1 addition & 1 deletion src/it/projects/MJAVADOC-514_3rdparty-doclettags/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<repositories>
<repository>
<id>local.private</id>
<id>repo514</id>
<url>@mrm.3rdparty.url@</url>
<releases>
<enabled>true</enabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2442,32 +2442,6 @@ protected final Map<String, Collection<Path>> getDependencySourcePaths()

final SourceResolverConfig config = getDependencySourceResolverConfig();

final List<TransformableFilter> andFilters = new ArrayList<>();

final List<String> dependencyIncludes = dependencySourceIncludes;
final List<String> dependencyExcludes = dependencySourceExcludes;

if ( !includeTransitiveDependencySources || isNotEmpty( dependencyIncludes ) || isNotEmpty(
dependencyExcludes ) )
{
if ( !includeTransitiveDependencySources )
{
andFilters.add( createDependencyArtifactFilter() );
}

if ( isNotEmpty( dependencyIncludes ) )
{
andFilters.add( new PatternInclusionsFilter( dependencyIncludes ) );
}

if ( isNotEmpty( dependencyExcludes ) )
{
andFilters.add( new PatternExclusionsFilter( dependencyExcludes ) );
}

config.withFilter( new AndFilter( andFilters ) );
}

try
{
return resourceResolver.resolveDependencySourcePaths( config );
Expand Down Expand Up @@ -2506,9 +2480,41 @@ private TransformableFilter createDependencyArtifactFilter()
*/
private SourceResolverConfig getDependencySourceResolverConfig()
{
return configureDependencySourceResolution(
new SourceResolverConfig( project, session.getProjectBuildingRequest(),
sourceDependencyCacheDir ).withReactorProjects( reactorProjects ) );
final List<TransformableFilter> andFilters = new ArrayList<>();

final List<String> dependencyIncludes = dependencySourceIncludes;
final List<String> dependencyExcludes = dependencySourceExcludes;

if ( !includeTransitiveDependencySources || isNotEmpty( dependencyIncludes ) || isNotEmpty(
dependencyExcludes ) )
{
if ( !includeTransitiveDependencySources )
{
andFilters.add( createDependencyArtifactFilter() );
}

if ( isNotEmpty( dependencyIncludes ) )
{
andFilters.add( new PatternInclusionsFilter( dependencyIncludes ) );
}

if ( isNotEmpty( dependencyExcludes ) )
{
andFilters.add( new PatternExclusionsFilter( dependencyExcludes ) );
}
}

return configureDependencySourceResolution( new SourceResolverConfig( project,
getProjectBuildingRequest( project ),
sourceDependencyCacheDir ).withReactorProjects( reactorProjects ) )
.withFilter( new AndFilter( andFilters ) );

}

private ProjectBuildingRequest getProjectBuildingRequest( MavenProject currentProject )
{
return new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() )
.setRemoteRepositories( currentProject.getRemoteArtifactRepositories() );
}

/**
Expand Down Expand Up @@ -2707,9 +2713,7 @@ private Collection<File> getPathElements()
sb.append( subProject.getArtifactId() ).append( ":" );
sb.append( subProject.getVersion() ).append( '\n' );

ProjectBuildingRequest buildingRequest = session.getProjectBuildingRequest();
buildingRequest =
buildingRequest.setRemoteRepositories( subProject.getRemoteArtifactRepositories() );
ProjectBuildingRequest buildingRequest = getProjectBuildingRequest( subProject );

List<Dependency> managedDependencies = null;
if ( subProject.getDependencyManagement() != null )
Expand Down Expand Up @@ -2783,7 +2787,7 @@ public Artifact resolveDependency( Dependency dependency )

try
{
return artifactResolver.resolveArtifact( session.getProjectBuildingRequest(), coordinate ).getArtifact();
return artifactResolver.resolveArtifact( getProjectBuildingRequest( project ), coordinate ).getArtifact();
}
catch ( ArtifactResolverException e )
{
Expand Down Expand Up @@ -3573,7 +3577,7 @@ private List<String> getArtifactsAbsolutePath( JavadocPathArtifact javadocArtifa
coordinate.setVersion( javadocArtifact.getVersion() );

Iterable<ArtifactResult> deps =
dependencyResolver.resolveDependencies( session.getProjectBuildingRequest(), coordinate,
dependencyResolver.resolveDependencies( getProjectBuildingRequest( project ), coordinate,
ScopeFilter.including( "compile", "provided" ) );
for ( ArtifactResult a : deps )
{
Expand Down Expand Up @@ -3607,11 +3611,7 @@ private Artifact createAndResolveArtifact( JavadocPathArtifact javadocArtifact )
coordinate.setArtifactId( javadocArtifact.getArtifactId() );
coordinate.setVersion( javadocArtifact.getVersion() );

DefaultProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
buildingRequest.setRemoteRepositories( project.getRemoteArtifactRepositories() );

return artifactResolver.resolveArtifact( buildingRequest, coordinate ).getArtifact();
return artifactResolver.resolveArtifact( getProjectBuildingRequest( project ), coordinate ).getArtifact();
}

/**
Expand Down Expand Up @@ -6142,7 +6142,7 @@ private List<String> getDependenciesLinks()
try
{
MavenProject artifactProject =
mavenProjectBuilder.build( artifact, session.getProjectBuildingRequest() ).getProject();
mavenProjectBuilder.build( artifact, getProjectBuildingRequest( project ) ).getProject();

if ( StringUtils.isNotEmpty( artifactProject.getUrl() ) )
{
Expand Down

0 comments on commit fd0c42a

Please sign in to comment.