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:
parent
5b546de35c
commit
648690fdfd
|
@ -4,3 +4,8 @@ Copyright 1999-2023 The Apache Software Foundation
|
||||||
This product includes software developed at
|
This product includes software developed at
|
||||||
The Apache Software Foundation (http://www.apache.org/).
|
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/.
|
||||||
|
|
|
@ -108,6 +108,12 @@
|
||||||
<include>**/*.properties</include>
|
<include>**/*.properties</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*.dat</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -123,8 +129,7 @@
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<url>https://publicsuffix.org/list/effective_tld_names.dat</url>
|
<url>https://publicsuffix.org/list/effective_tld_names.dat</url>
|
||||||
<outputDirectory>${project.build.outputDirectory}/mozilla</outputDirectory>
|
<outputDirectory>${project.basedir}/src/main/resources/org/publicsuffix/list</outputDirectory>
|
||||||
<outputFileName>public-suffix-list.txt</outputFileName>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|
|
@ -51,6 +51,8 @@ import org.slf4j.LoggerFactory;
|
||||||
@Contract(threading = ThreadingBehavior.SAFE)
|
@Contract(threading = ThreadingBehavior.SAFE)
|
||||||
public final class PublicSuffixMatcherLoader {
|
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 Logger LOG = LoggerFactory.getLogger(PublicSuffixMatcherLoader.class);
|
||||||
|
|
||||||
private static final ReentrantLock lock = new ReentrantLock();
|
private static final ReentrantLock lock = new ReentrantLock();
|
||||||
|
@ -81,9 +83,8 @@ public final class PublicSuffixMatcherLoader {
|
||||||
if (DEFAULT_INSTANCE == null) {
|
if (DEFAULT_INSTANCE == null) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
if (DEFAULT_INSTANCE == null){
|
if (DEFAULT_INSTANCE == null) {
|
||||||
final URL url = PublicSuffixMatcherLoader.class.getResource(
|
final URL url = PublicSuffixMatcherLoader.class.getResource(PUBLIC_SUFFIX_LIST);
|
||||||
"/mozilla/public-suffix-list.txt");
|
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
try {
|
try {
|
||||||
DEFAULT_INSTANCE = load(url);
|
DEFAULT_INSTANCE = load(url);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
|
@ -40,11 +40,17 @@ import org.junit.jupiter.api.Test;
|
||||||
class TestPublicSuffixMatcher {
|
class TestPublicSuffixMatcher {
|
||||||
|
|
||||||
private static final String SOURCE_FILE = "suffixlistmatcher.txt";
|
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 matcher;
|
||||||
private PublicSuffixMatcher pslMatcher;
|
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
|
@BeforeEach
|
||||||
void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
final ClassLoader classLoader = getClass().getClassLoader();
|
final ClassLoader classLoader = getClass().getClassLoader();
|
||||||
|
@ -54,10 +60,8 @@ class TestPublicSuffixMatcher {
|
||||||
final List<PublicSuffixList> lists = PublicSuffixListParser.INSTANCE.parseByType(new InputStreamReader(in, StandardCharsets.UTF_8));
|
final List<PublicSuffixList> lists = PublicSuffixListParser.INSTANCE.parseByType(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||||
matcher = new PublicSuffixMatcher(lists);
|
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);
|
final URL publicSuffixListUrl = classLoader.getResource(PUBLIC_SUFFIX_LIST_FILE);
|
||||||
|
Assertions.assertNotNull(publicSuffixListUrl, PUBLIC_SUFFIX_LIST_FILE);
|
||||||
pslMatcher = PublicSuffixMatcherLoader.load(publicSuffixListUrl);
|
pslMatcher = PublicSuffixMatcherLoader.load(publicSuffixListUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue