Includes a copy of in

https://publicsuffix.org/list/effective_tld_names.dat
in httpclient5/src/test/resources/org/publicsuffix/list/effective_tld_names.dat

Cleanly separate the concerns of which file to copy and whether to
filter it or not by using two <resource> elements:

- We want the .properties file copied and filtered. The git master
version causes only the properties file to be copied, the .dat file is
not copied.
- We want to the .dat file copied but not filtered.
This commit is contained in:
Gary Gregory 2024-08-23 10:01:11 -04:00 committed by Gary Gregory
parent 5b546de35c
commit 648690fdfd
7 changed files with 15874 additions and 9 deletions

View File

@ -4,3 +4,8 @@ Copyright 1999-2023 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
This product includes a copy of in https://publicsuffix.org/list/effective_tld_names.dat
in httpclient5/src/test/resources/org/publicsuffix/list/effective_tld_names.dat
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.

View File

@ -108,6 +108,12 @@
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.dat</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
@ -123,8 +129,7 @@
</goals>
<configuration>
<url>https://publicsuffix.org/list/effective_tld_names.dat</url>
<outputDirectory>${project.build.outputDirectory}/mozilla</outputDirectory>
<outputFileName>public-suffix-list.txt</outputFileName>
<outputDirectory>${project.basedir}/src/main/resources/org/publicsuffix/list</outputDirectory>
</configuration>
</execution>
</executions>

View File

@ -51,6 +51,8 @@ import org.slf4j.LoggerFactory;
@Contract(threading = ThreadingBehavior.SAFE)
public final class PublicSuffixMatcherLoader {
private static final String PUBLIC_SUFFIX_LIST = "org/publicsuffix/list/effective_tld_names.dat";
private static final Logger LOG = LoggerFactory.getLogger(PublicSuffixMatcherLoader.class);
private static final ReentrantLock lock = new ReentrantLock();
@ -81,9 +83,8 @@ public final class PublicSuffixMatcherLoader {
if (DEFAULT_INSTANCE == null) {
lock.lock();
try {
if (DEFAULT_INSTANCE == null){
final URL url = PublicSuffixMatcherLoader.class.getResource(
"/mozilla/public-suffix-list.txt");
if (DEFAULT_INSTANCE == null) {
final URL url = PublicSuffixMatcherLoader.class.getResource(PUBLIC_SUFFIX_LIST);
if (url != null) {
try {
DEFAULT_INSTANCE = load(url);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
// 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.
// ====================================================================
//
// This software consists of voluntary contributions made by many
// individuals on behalf of the Apache Software Foundation. For more
// information on the Apache Software Foundation, please see
// <http://www.apache.org/>.
The file effective_tld_names.dat in this folder is a copy of
https://publicsuffix.org/list/effective_tld_names.dat

View File

@ -40,11 +40,17 @@ import org.junit.jupiter.api.Test;
class TestPublicSuffixMatcher {
private static final String SOURCE_FILE = "suffixlistmatcher.txt";
private static final String PUBLIC_SUFFIX_LIST_FILE = "mozilla/public-suffix-list.txt";
private static final String PUBLIC_SUFFIX_LIST_FILE = "org/publicsuffix/list/effective_tld_names.dat";
private PublicSuffixMatcher matcher;
private PublicSuffixMatcher pslMatcher;
/**
* Create a matcher using the public suffix list file provided by publicsuffix.org (Mozilla).
*
* This test uses a copy of https://publicsuffix.org/list/effective_tld_names.dat in
* src/main/resources/org/publicsuffix/list/effective_tld_names.dat
*/
@BeforeEach
void setUp() throws Exception {
final ClassLoader classLoader = getClass().getClassLoader();
@ -54,10 +60,8 @@ class TestPublicSuffixMatcher {
final List<PublicSuffixList> lists = PublicSuffixListParser.INSTANCE.parseByType(new InputStreamReader(in, StandardCharsets.UTF_8));
matcher = new PublicSuffixMatcher(lists);
}
// Create a matcher using the public suffix list file provided by Mozilla
// Note: the test requires `mvn generate-resources` to have been called to fetch the Mozilla file into
// target/classes so that it is on the classpath
final URL publicSuffixListUrl = classLoader.getResource(PUBLIC_SUFFIX_LIST_FILE);
Assertions.assertNotNull(publicSuffixListUrl, PUBLIC_SUFFIX_LIST_FILE);
pslMatcher = PublicSuffixMatcherLoader.load(publicSuffixListUrl);
}

View File

@ -0,0 +1,43 @@
/*
* ====================================================================
* 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.http.psl;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
/**
* Tests {@link PublicSuffixMatcherLoader}.
*/
public class TestPublicSuffixMatcherLoader {
@Test
public void testGetDefault() {
assertNotNull(PublicSuffixMatcherLoader.getDefault());
}
}