From 73b2652ac7fe35412d3e8cdc5047f59bb93e18f3 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Tue, 9 May 2023 00:11:00 +0200 Subject: [PATCH] [MPIR-435] Custom bundle sometimes not loaded due to parent-first class loading This closes #48 --- .../custom/project-info-reports.properties | 6 +- .../custom/project-info-reports_de.properties | 18 ++++++ .../custom/project-info-reports_fr.properties | 18 ++++++ src/it/full-pom/verify.bsh | 30 ++++++++- .../AbstractProjectInfoReport.java | 2 +- .../projectinfo/MailingListsReportTest.java | 27 ++++++++ .../projectinfo/stubs/MailingListsStub2.java | 37 +++++++++++ .../custom-bundle/plugin-config.xml | 62 +++++++++++++++++++ .../custom/project-info-reports.properties | 18 ++++++ 9 files changed, 211 insertions(+), 7 deletions(-) create mode 100644 src/it/full-pom/src/site/custom/project-info-reports_de.properties create mode 100644 src/it/full-pom/src/site/custom/project-info-reports_fr.properties create mode 100644 src/test/java/org/apache/maven/report/projectinfo/stubs/MailingListsStub2.java create mode 100644 src/test/resources/plugin-configs/custom-bundle/plugin-config.xml create mode 100644 src/test/resources/plugin-configs/custom-bundle/src/site/custom/project-info-reports.properties diff --git a/src/it/full-pom/src/site/custom/project-info-reports.properties b/src/it/full-pom/src/site/custom/project-info-reports.properties index 644d0b94..66ca7318 100644 --- a/src/it/full-pom/src/site/custom/project-info-reports.properties +++ b/src/it/full-pom/src/site/custom/project-info-reports.properties @@ -5,9 +5,9 @@ # 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 @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -report.mailing-lists.intro = mail list intro text foo \ No newline at end of file +report.mailing-lists.intro = mail list intro text foo diff --git a/src/it/full-pom/src/site/custom/project-info-reports_de.properties b/src/it/full-pom/src/site/custom/project-info-reports_de.properties new file mode 100644 index 00000000..63bfed3d --- /dev/null +++ b/src/it/full-pom/src/site/custom/project-info-reports_de.properties @@ -0,0 +1,18 @@ +# 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. + +report.mailing-lists.intro = mail list intro text foo ("de") diff --git a/src/it/full-pom/src/site/custom/project-info-reports_fr.properties b/src/it/full-pom/src/site/custom/project-info-reports_fr.properties new file mode 100644 index 00000000..5cef9a6a --- /dev/null +++ b/src/it/full-pom/src/site/custom/project-info-reports_fr.properties @@ -0,0 +1,18 @@ +# 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. + +report.mailing-lists.intro = mail list intro text foo ("fr") diff --git a/src/it/full-pom/verify.bsh b/src/it/full-pom/verify.bsh index df74b5a7..73ca2b7b 100644 --- a/src/it/full-pom/verify.bsh +++ b/src/it/full-pom/verify.bsh @@ -91,6 +91,30 @@ try return false; } + mailinglists = new File( siteDir, "de/mailing-lists.html"); + content = FileUtils.fileRead( mailinglists, "UTF-8" ); + if ( !content.contains( "mail list intro text foo ("de")" ) ) + { + System.err.println( "de/mailing-lists.html doesn't contain mail list intro text foo (\"de\")" ); + return false; + } + + mailinglists = new File( siteDir, "fr/mailing-lists.html"); + content = FileUtils.fileRead( mailinglists, "UTF-8" ); + if ( !content.contains( "mail list intro text foo ("fr")" ) ) + { + System.err.println( "fr/mailing-lists.html doesn't contain mail list intro text foo (\"fr\")" ); + return false; + } + + mailinglists = new File( siteDir, "sv/mailing-lists.html"); + content = FileUtils.fileRead( mailinglists, "UTF-8" ); + if ( !content.contains( "mail list intro text foo" ) ) + { + System.err.println( "sv/mailing-lists.html doesn't contain mail list intro text foo" ); + return false; + } + File dependencies = new File( siteDir, "dependencies.html"); content = FileUtils.fileRead( dependencies, "UTF-8" ); if ( !content.contains( "doxia-core-1.2.jar" ) ) @@ -107,16 +131,16 @@ try System.err.println( "MPIR-216: dependency-management doesn't contain doxia-sink-api url https://maven.apache.org/doxia/doxia/doxia-sink-api/" ); return false; } - + File dependencyConvergence = new File( siteDir, "dependency-convergence.html"); content = FileUtils.fileRead( dependencyConvergence, "UTF-8" ); - + if ( !content.contains( "You do not have 100% convergence." ) ) { System.err.println( "dependency-convergence not rendered correctly" ); return false; } - + } catch ( Throwable t ) { diff --git a/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java b/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java index 2ad27bf2..9829e947 100644 --- a/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java +++ b/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java @@ -329,7 +329,7 @@ private static class CustomI18N implements I18N { URLClassLoader classLoader = null; try { classLoader = new URLClassLoader( - new URL[] {customBundleFile.getParentFile().toURI().toURL()}); + new URL[] {customBundleFile.getParentFile().toURI().toURL()}, null); } catch (MalformedURLException e) { // could not happen. } diff --git a/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java b/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java index 6404eaea..9bb86b7e 100644 --- a/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java +++ b/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java @@ -84,6 +84,33 @@ public void testReport() throws Exception { assertEquals("https://example.com/unsubscribe", unsubscribeLinks[0].getAttribute("href")); } + /** + * Test custom bundle + * + * @throws Exception if any + */ + public void testCustomBundle() throws Exception { + generateReport("mailing-lists", "custom-bundle/plugin-config.xml"); + assertTrue( + "Test html generated", getGeneratedReport("mailing-lists.html").exists()); + + URL reportURL = getGeneratedReport("mailing-lists.html").toURI().toURL(); + assertNotNull(reportURL); + + // HTTPUnit + WebRequest request = new GetMethodWebRequest(reportURL.toString()); + WebResponse response = WEB_CONVERSATION.getResponse(request); + + // Basic HTML tests + assertTrue(response.isHTML()); + assertTrue(response.getContentLength() > 0); + + // Test the texts + TextBlock[] textBlocks = response.getTextBlocks(); + assertEquals(getString("report.mailing-lists.title"), textBlocks[0].getText()); + assertEquals("mail list intro text foo", textBlocks[1].getText()); + } + /** * Test report in French (MPIR-59) * diff --git a/src/test/java/org/apache/maven/report/projectinfo/stubs/MailingListsStub2.java b/src/test/java/org/apache/maven/report/projectinfo/stubs/MailingListsStub2.java new file mode 100644 index 00000000..7b3380ce --- /dev/null +++ b/src/test/java/org/apache/maven/report/projectinfo/stubs/MailingListsStub2.java @@ -0,0 +1,37 @@ +/* + * 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. + */ +package org.apache.maven.report.projectinfo.stubs; + +import java.io.File; + +/** + * @author Vincent Siveton + * @version $Id$ + */ +public class MailingListsStub2 extends ProjectInfoProjectStub { + @Override + public File getBasedir() { + return new File(super.getBasedir() + "/custom-bundle/"); + } + + @Override + protected String getPOM() { + return "plugin-config.xml"; + } +} diff --git a/src/test/resources/plugin-configs/custom-bundle/plugin-config.xml b/src/test/resources/plugin-configs/custom-bundle/plugin-config.xml new file mode 100644 index 00000000..0b3b9ee4 --- /dev/null +++ b/src/test/resources/plugin-configs/custom-bundle/plugin-config.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + org.apache.maven.plugin.projectinfo.tests + mailing-lists + 1.0-SNAPSHOT + jar + mailing lists project info + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + + Test List + test@maven.apache.org + MAILTO:test-subscribe@maven.apache.org + + + Test List 2 + test2@maven.apache.org + MAILTO:test-subscribe2@maven.apache.org + https://example.com/unsubscribe + + + + + + maven-project-info-reports-plugin + + target/test-harness/mailing-lists + ${localRepository} + + ${basedir}/src/test/resources/plugin-configs/custom-bundle/src/site/custom/project-info-reports.properties + + + + + diff --git a/src/test/resources/plugin-configs/custom-bundle/src/site/custom/project-info-reports.properties b/src/test/resources/plugin-configs/custom-bundle/src/site/custom/project-info-reports.properties new file mode 100644 index 00000000..644d0b94 --- /dev/null +++ b/src/test/resources/plugin-configs/custom-bundle/src/site/custom/project-info-reports.properties @@ -0,0 +1,18 @@ +# 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. + +report.mailing-lists.intro = mail list intro text foo \ No newline at end of file