Path: blob/master/test/jdk/java/security/misc/Versions.java
41149 views
/*1* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8232357 8221801 824467426* @summary Make sure version info is consistent between code and license27* @run testng Versions28*/2930import org.testng.Assert;31import org.testng.annotations.DataProvider;32import org.testng.annotations.Test;3334import java.io.IOException;35import java.nio.file.Files;36import java.nio.file.Path;37import java.util.regex.Matcher;38import java.util.regex.Pattern;3940public class Versions {4142Path rootPath = Path.of(System.getProperty("test.root"), "../..");43Path legalPath = Path.of(System.getProperty("test.jdk"), "legal");4445@DataProvider(name = "data")46public Object[][] createData() {47return new Object[][]{48{"src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/XMLDSigRI.java",49Pattern.compile("// Apache Santuario XML Security for Java, version (?<n>\\S+)"),50"src/java.xml.crypto/share/legal/santuario.md",51Pattern.compile("## Apache Santuario v(?<n>\\S+)"),52"java.xml.crypto/santuario.md"},53{"make/data/publicsuffixlist/VERSION",54Pattern.compile("list/(?<n>[0-9a-f]+)/public_suffix_list.dat"),55"src/java.base/share/legal/public_suffix.md",56Pattern.compile("list/(?<n>[0-9a-f]+)/public_suffix_list.dat"),57"java.base/public_suffix.md"},58{"src/java.smartcardio/unix/native/libj2pcsc/MUSCLE/pcsclite.h",59Pattern.compile("#define PCSCLITE_VERSION_NUMBER +\"(?<n>[0-9\\.]+)\""),60"src/java.smartcardio/unix/legal/pcsclite.md",61Pattern.compile("## PC/SC Lite v(?<n>[0-9\\.]+)"),62"java.smartcardio/pcsclite.md"}63};64}6566@Test(dataProvider = "data")67public void Test(String src, Pattern sp, String legal, Pattern lp,68String legalInBuild) throws IOException {6970Path pSrc = rootPath.resolve(src);71Path pLegal = rootPath.resolve(legal);7273Assert.assertEquals(fetch(pSrc, sp), fetch(pLegal, lp));7475Path pLegalInBuild = legalPath.resolve(legalInBuild);76if (!Files.exists(pLegalInBuild)) {77System.out.println("Not an image build, or file platform dependent");78} else {79Assert.assertEquals(Files.mismatch(pLegal, pLegalInBuild), -1);80}81}8283// Find a match in path and return the extracted named group84static String fetch(Path path, Pattern pattern)85throws IOException {86return Files.lines(path)87.map(pattern::matcher)88.filter(Matcher::find)89.findFirst()90.map(m -> m.group("n"))91.get();92}93}949596