This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch MPDF-95 in repository https://gitbox.apache.org/repos/asf/maven-pdf-plugin.git
commit 743312666411c448ef8b5c3315194720ec75962c Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Fri Jun 4 10:25:24 2021 +0200 [MPDF-95] Require Maven 3.1.1 --- pom.xml | 69 ++++-- .../plugins/pdf/DocumentDescriptorReader.java | 6 +- .../maven/plugins/pdf/DocumentModelBuilder.java | 4 - .../java/org/apache/maven/plugins/pdf/PdfMojo.java | 231 ++------------------- .../plugins/pdf/DocumentDescriptorReaderTest.java | 4 +- .../plugins/pdf/stubs/DefaultMavenProjectStub.java | 10 +- .../pdf/stubs/FilteringMavenProjectStub.java | 12 +- .../plugins/pdf/stubs/ITextMavenProjectStub.java | 9 +- 8 files changed, 80 insertions(+), 265 deletions(-) diff --git a/pom.xml b/pom.xml index a34bff5..fdad34c 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ under the License. <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugins</artifactId> <version>34</version> - <relativePath>../../pom/maven/maven-plugins/pom.xml</relativePath> + <relativePath/> </parent> <artifactId>maven-pdf-plugin</artifactId> @@ -91,7 +91,7 @@ under the License. <properties> <doxiaVersion>1.10</doxiaVersion> <doxiaSitetoolsVersion>1.10</doxiaSitetoolsVersion> - <mavenVersion>2.2.1</mavenVersion> + <mavenVersion>3.1.1</mavenVersion> <javaVersion>7</javaVersion> <project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp> </properties> @@ -115,19 +115,20 @@ under the License. <dependency> <groupId>org.apache.maven.reporting</groupId> <artifactId>maven-reporting-exec</artifactId> - <version>1.4</version> + <version>1.5.1</version> </dependency> <!-- Maven --> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> + <artifactId>maven-core</artifactId> <version>${mavenVersion}</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> + <artifactId>maven-compat</artifactId> <version>${mavenVersion}</version> + <scope>test</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> @@ -140,11 +141,6 @@ under the License. <version>${mavenVersion}</version> </dependency> <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-artifact-manager</artifactId> - <version>${mavenVersion}</version> - </dependency> - <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> <scope>provided</scope> @@ -160,6 +156,12 @@ under the License. <groupId>org.apache.maven.doxia</groupId> <artifactId>doxia-sink-api</artifactId> <version>${doxiaVersion}</version> + <exclusions> + <exclusion> + <artifactId>plexus-container-default</artifactId> + <groupId>org.codehaus.plexus</groupId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.maven.doxia</groupId> @@ -187,6 +189,12 @@ under the License. <groupId>org.apache.maven.doxia</groupId> <artifactId>doxia-integration-tools</artifactId> <version>${doxiaSitetoolsVersion}</version> + <exclusions> + <exclusion> + <artifactId>plexus-container-default</artifactId> + <groupId>org.codehaus.plexus</groupId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.maven.doxia</groupId> @@ -247,10 +255,6 @@ under the License. <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-component-api</artifactId> </exclusion> - <exclusion> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-container-default</artifactId> - </exclusion> </exclusions> </dependency> @@ -271,13 +275,14 @@ under the License. <dependency> <groupId>org.apache.maven.plugin-testing</groupId> <artifactId>maven-plugin-testing-harness</artifactId> - <version>1.3</version> + <version>3.1.0</version> <scope>test</scope> - </dependency> - <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-container-default</artifactId> - <version>1.0-alpha-9-stable-1</version> + <exclusions> + <exclusion> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-container-default</artifactId> + </exclusion> + </exclusions> </dependency> </dependencies> @@ -293,6 +298,30 @@ under the License. </pluginManagement> <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>enforce</goal> + </goals> + <id>ensure-no-container-api</id> + <configuration> + <rules> + <bannedDependencies> + <excludes> + <exclude>org.codehaus.plexus:plexus-component-api</exclude> + <exclude>org.codehaus.plexus:plexus-container-default</exclude> + </excludes> + <message>The new containers are not supported. You probably added a dependency that is missing the exclusions.</message> + </bannedDependencies> + </rules> + <fail>true</fail> + </configuration> + </execution> + </executions> + </plugin> <!-- START SNIPPET: configuration --> <plugin> <groupId>org.apache.maven.plugins</groupId> diff --git a/src/main/java/org/apache/maven/plugins/pdf/DocumentDescriptorReader.java b/src/main/java/org/apache/maven/plugins/pdf/DocumentDescriptorReader.java index 7b72355..c893606 100644 --- a/src/main/java/org/apache/maven/plugins/pdf/DocumentDescriptorReader.java +++ b/src/main/java/org/apache/maven/plugins/pdf/DocumentDescriptorReader.java @@ -138,7 +138,7 @@ public class DocumentDescriptorReader } catch ( Exception e ) { - addFeedback( "Failed to extract \'" + expression + "\' from: " + project, e ); + addFeedback( "Failed to extract '" + expression + "' from: " + project, e ); } return null; @@ -164,9 +164,7 @@ public class DocumentDescriptorReader } catch ( InterpolationException e ) { - final IOException io = new IOException( "Error interpolating document descriptor" ); - io.initCause( e ); - throw io; + throw new IOException( "Error interpolating document descriptor", e ); } } } diff --git a/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java b/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java index 025a597..d37028f 100644 --- a/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java +++ b/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java @@ -94,10 +94,6 @@ public class DocumentModelBuilder return getDocumentModel( project, decorationModel, date ); } - // ---------------------------------------------------------------------- - // Private methods - // ---------------------------------------------------------------------- - /** * Extract a DocumentModel from a MavenProject. * diff --git a/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java b/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java index 142c777..86c47bf 100644 --- a/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java +++ b/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java @@ -21,7 +21,6 @@ package org.apache.maven.plugins.pdf; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; @@ -31,15 +30,10 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Properties; import org.apache.commons.io.input.XmlStreamReader; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.doxia.Doxia; import org.apache.maven.doxia.docrenderer.AbstractDocumentRenderer; import org.apache.maven.doxia.docrenderer.DocumentRenderer; @@ -56,9 +50,7 @@ import org.apache.maven.doxia.index.IndexingSink; import org.apache.maven.doxia.module.xdoc.XdocSink; import org.apache.maven.doxia.parser.ParseException; import org.apache.maven.doxia.parser.manager.ParserNotFoundException; -import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.impl.SinkAdapter; -import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; import org.apache.maven.doxia.site.decoration.DecorationModel; import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader; import org.apache.maven.doxia.siterenderer.Renderer; @@ -71,14 +63,11 @@ import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.Reporting; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; -import org.apache.maven.reporting.AbstractMavenReportRenderer; import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReportException; import org.apache.maven.reporting.exec.MavenReportExecution; @@ -115,10 +104,6 @@ public class PdfMojo */ private static final String EOL = System.getProperty( "line.separator" ); - // ---------------------------------------------------------------------- - // Mojo components - // ---------------------------------------------------------------------- - /** * FO Document Renderer. */ @@ -157,14 +142,6 @@ public class PdfMojo private SiteTool siteTool; /** - * The Plugin manager instance used to resolve Plugin descriptors. - * - * @since 1.1 - */ - @Component( role = PluginManager.class ) - private PluginManager pluginManager; - - /** * Doxia. * * @since 1.1 @@ -173,18 +150,6 @@ public class PdfMojo private Doxia doxia; /** - * Project builder. - * - * @since 1.1 - */ - @Component - private MavenProjectBuilder mavenProjectBuilder; - - // ---------------------------------------------------------------------- - // Mojo Parameters - // ---------------------------------------------------------------------- - - /** * The Maven Project Object. */ @Parameter( defaultValue = "${project}", readonly = true, required = true ) @@ -318,10 +283,6 @@ public class PdfMojo @Parameter( defaultValue = "${project.reporting}", readonly = true ) private Reporting reporting; - // ---------------------------------------------------------------------- - // Instance fields - // ---------------------------------------------------------------------- - /** * The current document Renderer. * @see #implementation @@ -362,10 +323,6 @@ public class PdfMojo */ private PlexusContainer container; - // ---------------------------------------------------------------------- - // Public methods - // ---------------------------------------------------------------------- - /** {@inheritDoc} */ public void execute() throws MojoExecutionException, MojoFailureException @@ -415,10 +372,6 @@ public class PdfMojo return includeReports; } - // ---------------------------------------------------------------------- - // Private methods - // ---------------------------------------------------------------------- - /** * Init and validate parameters */ @@ -1331,26 +1284,18 @@ public class PdfMojo } catch ( ParseException e ) { - StringBuilder sb = new StringBuilder( 1024 ); - - sb.append( EOL ); - sb.append( "Error when parsing the generated report xdoc file: " ); - sb.append( generatedReport.getAbsolutePath() ); - sb.append( EOL ); - sb.append( e.getMessage() ); - sb.append( EOL ); - - sb.append( "You could:" ).append( EOL ); - sb.append( " * exclude all reports using -DincludeReports=false" ).append( EOL ); - sb.append( " * remove the " ); - sb.append( fullGoal ); - sb.append( " from the <reporting/> part. To not affect the site generation, " ); - sb.append( "you could create a PDF profile." ); - - sb.append( EOL ).append( "Ignoring the \"" ).append( localReportName ) - .append( "\" report in the PDF." ).append( EOL ); - - getLog().error( sb.toString() ); + String sb = EOL + + "Error when parsing the generated report xdoc file: " + + generatedReport.getAbsolutePath() + EOL + + e.getMessage() + EOL + + "You could:" + EOL + + " * exclude all reports using -DincludeReports=false" + EOL + + " * remove the " + + fullGoal + + " from the <reporting/> part. To not affect the site generation, " + + "you could create a PDF profile." + EOL + + "Ignoring the \"" + localReportName + "\" report in the PDF." + EOL; + getLog().error( sb ); getLog().debug( e ); return false; @@ -1376,11 +1321,6 @@ public class PdfMojo protected List<MavenReportExecution> getReports() throws MojoExecutionException { - if ( !isMaven3OrMore() ) - { - getLog().error( "Report generation is not supported with Maven <= 2.x" ); - } - MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest(); mavenReportExecutorRequest.setLocalRepository( localRepository ); mavenReportExecutorRequest.setMavenSession( session ); @@ -1428,51 +1368,9 @@ public class PdfMojo mpir.setArtifactId( "maven-project-info-reports-plugin" ); reportingPlugins.add( mpir ); } - return reportingPlugins.toArray( new ReportPlugin[reportingPlugins.size()] ); - } - - /** - * Check the current Maven version to see if it's Maven 3.0 or newer. - */ - protected static boolean isMaven3OrMore() - { - try - { - ArtifactVersion mavenVersion = new DefaultArtifactVersion( getMavenVersion() ); - return VersionRange.createFromVersionSpec( "[3.0,)" ).containsVersion( mavenVersion ); - } - catch ( InvalidVersionSpecificationException e ) - { - return false; - } -// return new ComparableVersion( getMavenVersion() ).compareTo( new ComparableVersion( "3.0" ) ) >= 0; + return reportingPlugins.toArray( new ReportPlugin[0] ); } - protected static String getMavenVersion() - { - // This relies on the fact that MavenProject is the in core classloader - // and that the core classloader is for the maven-core artifact - // and that should have a pom.properties file - // if this ever changes, we will have to revisit this code. - final Properties properties = new Properties(); - - try ( InputStream in = MavenProject.class.getClassLoader().getResourceAsStream( - "META-INF/maven/org.apache.maven/maven-core/pom.properties" ) ) - { - properties.load( in ); - } - catch ( IOException ioe ) - { - return ""; - } - - return properties.getProperty( "version" ).trim(); - } - - // ---------------------------------------------------------------------- - // static methods - // ---------------------------------------------------------------------- - /** * Write the given content to the given file. * <br/> @@ -1520,10 +1418,6 @@ public class PdfMojo return excludesLocales; } - // ---------------------------------------------------------------------- - // Inner class - // ---------------------------------------------------------------------- - /** * A sink to render a Maven report as a generated xdoc file, with some known workarounds. * @@ -1556,103 +1450,4 @@ public class PdfMojo } } - /** - * Renderer Maven report similar to org.apache.maven.plugins.site.CategorySummaryDocumentRenderer - * - * @since 1.1 - */ - private static class ProjectInfoRenderer - extends AbstractMavenReportRenderer - { - private final List<MavenReport> generatedReports; - - private final I18N i18n; - - private final Locale locale; - - ProjectInfoRenderer( Sink sink, List<MavenReport> generatedReports, I18N i18n, Locale locale ) - { - super( sink ); - - this.generatedReports = generatedReports; - this.i18n = i18n; - this.locale = locale; - } - - /** {@inheritDoc} */ - public String getTitle() - { - return i18n.getString( "pdf-plugin", locale, "report.project-info.title" ); - } - - /** {@inheritDoc} */ - public void renderBody() - { - sink.section1(); - sink.sectionTitle1(); - sink.text( i18n.getString( "pdf-plugin", locale, "report.project-info.title" ) ); - sink.sectionTitle1_(); - - sink.paragraph(); - sink.text( i18n.getString( "pdf-plugin", locale, "report.project-info.description1" ) + " " ); - sink.link( "http://maven.apache.org" ); - sink.text( "Maven" ); - sink.link_(); - sink.text( " " + i18n.getString( "pdf-plugin", locale, "report.project-info.description2" ) ); - sink.paragraph_(); - - sink.section2(); - sink.sectionTitle2(); - sink.text( i18n.getString( "pdf-plugin", locale, "report.project-info.sectionTitle" ) ); - sink.sectionTitle2_(); - - sink.table(); - - sink.tableRows( new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT }, false ); - - String name = i18n.getString( "pdf-plugin", locale, "report.project-info.column.document" ); - String description = i18n.getString( "pdf-plugin", locale, "report.project-info.column.description" ); - - sink.tableRow(); - - sink.tableHeaderCell( SinkEventAttributeSet.CENTER ); - - sink.text( name ); - - sink.tableHeaderCell_(); - - sink.tableHeaderCell( SinkEventAttributeSet.CENTER ); - - sink.text( description ); - - sink.tableHeaderCell_(); - - sink.tableRow_(); - - if ( generatedReports != null ) - { - for ( final MavenReport report : generatedReports ) - { - sink.tableRow(); - sink.tableCell(); - sink.link( report.getOutputName() + ".html" ); - sink.text( report.getName( locale ) ); - sink.link_(); - sink.tableCell_(); - sink.tableCell(); - sink.text( report.getDescription( locale ) ); - sink.tableCell_(); - sink.tableRow_(); - } - } - - sink.tableRows_(); - - sink.table_(); - - sink.section2_(); - - sink.section1_(); - } - } } diff --git a/src/test/java/org/apache/maven/plugins/pdf/DocumentDescriptorReaderTest.java b/src/test/java/org/apache/maven/plugins/pdf/DocumentDescriptorReaderTest.java index d402633..ab07d3f 100644 --- a/src/test/java/org/apache/maven/plugins/pdf/DocumentDescriptorReaderTest.java +++ b/src/test/java/org/apache/maven/plugins/pdf/DocumentDescriptorReaderTest.java @@ -65,8 +65,8 @@ public class DocumentDescriptorReaderTest assertEquals( "Table of Contents", model.getToc().getName() ); assertEquals( 5, model.getToc().getItems().size() ); assertNotNull( model.getMeta() ); - assertTrue( model.getMeta().getTitle().indexOf( - "User guide in en of Test filtering version 1.0-SNAPSHOT" ) == 0 ); + assertEquals( 0, model.getMeta().getTitle().indexOf( + "User guide in en of Test filtering version 1.0-SNAPSHOT" ) ); assertEquals( "[email protected] [email protected]", model.getMeta().getAuthor() ); } diff --git a/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java index 240dfb3..1975fb9 100644 --- a/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java +++ b/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java @@ -25,12 +25,11 @@ import java.util.Collections; import java.util.List; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.MavenArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; /** @@ -67,11 +66,10 @@ public class DefaultMavenProjectStub } /** {@inheritDoc} */ - public List getRemoteArtifactRepositories() + public List<ArtifactRepository> getRemoteArtifactRepositories() { - ArtifactRepository repository = - new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2", - new DefaultRepositoryLayout() ); + ArtifactRepository repository = new MavenArtifactRepository( "central", "https://repo.maven.apache.org/maven2", + new DefaultRepositoryLayout(), null, null ); return Collections.singletonList( repository ); } diff --git a/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java index 93a587f..27467b5 100644 --- a/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java +++ b/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java @@ -26,12 +26,12 @@ import java.util.List; import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.MavenArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.model.Developer; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; /** @@ -73,7 +73,7 @@ public class FilteringMavenProjectStub } /** {@inheritDoc} */ - public List getDevelopers() + public List<Developer> getDevelopers() { return getModel().getDevelopers(); } @@ -85,11 +85,11 @@ public class FilteringMavenProjectStub } /** {@inheritDoc} */ - public List getRemoteArtifactRepositories() + public List<ArtifactRepository> getRemoteArtifactRepositories() { ArtifactRepository repository = - new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2", - new DefaultRepositoryLayout() ); + new MavenArtifactRepository( "central", "https://repo.maven.apache.org/maven2", + new DefaultRepositoryLayout(), null,null ); return Collections.singletonList( repository ); } diff --git a/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java index 0b2e5bf..b988477 100644 --- a/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java +++ b/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java @@ -25,12 +25,11 @@ import java.util.Collections; import java.util.List; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.MavenArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; /** @@ -61,11 +60,11 @@ public class ITextMavenProjectStub } /** {@inheritDoc} */ - public List getRemoteArtifactRepositories() + public List<ArtifactRepository> getRemoteArtifactRepositories() { ArtifactRepository repository = - new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2", - new DefaultRepositoryLayout() ); + new MavenArtifactRepository( "central", "https://repo.maven.apache.org/maven2", + new DefaultRepositoryLayout(), null, null ); return Collections.singletonList( repository ); }
