Skip to content
Permalink
Browse files
8275745: Reproducible copyright headers
Backport-of: a0227965bb8d1d49718794d67f8a4cfeebc9bec2
  • Loading branch information
Andrew Leonard authored and gnu-andrew committed Mar 9, 2022
1 parent 673c585 commit 0d933c9b4f096c55058209ab7eaa8588bdc95ffb
Showing 8 changed files with 42 additions and 20 deletions.
@@ -356,6 +356,14 @@ AC_DEFUN_ONCE([BASIC_SETUP_COMPLEX_TOOLS],
fi
AC_SUBST(IS_GNU_TIME)
# Check if it's GNU date
check_date=`$DATE --version 2>&1 | $GREP GNU`
if test "x$check_date" != x; then
IS_GNU_DATE=yes
else
IS_GNU_DATE=no
fi
if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
UTIL_REQUIRE_PROGS(DSYMUTIL, dsymutil)
UTIL_REQUIRE_PROGS(MIG, mig)
@@ -216,6 +216,12 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_JDK_OPTIONS],
AC_MSG_ERROR([Copyright year must have a value])
elif test "x$with_copyright_year" != x; then
COPYRIGHT_YEAR="$with_copyright_year"
elif test "x$SOURCE_DATE_EPOCH" != x; then
if test "x$IS_GNU_DATE" = xyes; then
COPYRIGHT_YEAR=`date --date=@$SOURCE_DATE_EPOCH +%Y`
else
COPYRIGHT_YEAR=`date -j -f %s $SOURCE_DATE_EPOCH +%Y`
fi
else
COPYRIGHT_YEAR=`$DATE +'%Y'`
fi
@@ -114,6 +114,7 @@ public class CLDRConverter {
ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT);

private static Set<String> AVAILABLE_TZIDS;
static int copyrightYear;
private static String zoneNameTempFile;
private static String tzDataDir;
private static final Map<String, String> canonicalTZMap = new HashMap<>();
@@ -217,6 +218,10 @@ public static void main(String[] args) throws Exception {
verbose = true;
break;

case "-year":
copyrightYear = Integer.parseInt(args[++i]);
break;

case "-zntempfile":
zoneNameTempFile = args[++i];
break;
@@ -235,7 +240,7 @@ public static void main(String[] args) throws Exception {
}
}
} catch (RuntimeException e) {
severe("unknown or imcomplete arg(s): " + currentArg);
severe("unknown or incomplete arg(s): " + currentArg);
usage();
System.exit(1);
}
@@ -260,6 +265,10 @@ public static void main(String[] args) throws Exception {
setupBaseLocales("en-US");
}

if (copyrightYear == 0) {
copyrightYear = ZonedDateTime.now(ZoneId.of("America/Los_Angeles")).getYear();
}

bundleGenerator = new ResourceBundleGenerator();

// Parse data independent of locales
@@ -292,6 +301,7 @@ private static void usage() {
+ "\t-basemodule generates bundles that go into java.base module%n"
+ "\t-baselocales loc(,loc)* locales that go into the base module%n"
+ "\t-o dir output directory (default: ./build/gensrc)%n"
+ "\t-year year copyright year in output%n"
+ "\t-zntempfile template file for java.time.format.ZoneName.java%n"
+ "\t-tzdatadir tzdata directory for java.time.format.ZoneName.java%n"
+ "\t-utf8 use UTF-8 rather than \\uxxxx (for debug)%n");
@@ -26,6 +26,7 @@
package build.tools.cldrconverter;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
@@ -131,25 +132,18 @@ class CopyrightHeaders {
" * questions.\n" +
" */\n";

static String getOracleCopyright() {
int year = getYear();
static String getOracleCopyright(int year) {
return String.format(year > 2012 ? ORACLE_AFTER2012 : ORACLE2012, year);
}

static String getUnicodeCopyright() {
return UNICODE;
}

static String getOpenJDKCopyright() {
int year = getYear();
static String getOpenJDKCopyright(int year) {
return String.format(year > 2012 ? OPENJDK_AFTER2012 : OPENJDK2012, year);
}

private static int getYear() {
return new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"),
Locale.US).get(Calendar.YEAR);
}

// no instantiation
private CopyrightHeaders() {
}
@@ -198,7 +198,7 @@ public void generateBundle(String packageName, String baseName, String localeID,

try (PrintWriter out = new PrintWriter(file, encoding)) {
// Output copyright headers
out.println(CopyrightHeaders.getOpenJDKCopyright());
out.println(CopyrightHeaders.getOpenJDKCopyright(CLDRConverter.copyrightYear));
out.println(CopyrightHeaders.getUnicodeCopyright());

if (useJava) {
@@ -266,7 +266,7 @@ public void generateMetaInfo(Map<String, SortedSet<String>> metaInfo) throws IOE
CLDRConverter.info("Generating file " + file);

try (PrintWriter out = new PrintWriter(file, "us-ascii")) {
out.printf(CopyrightHeaders.getOpenJDKCopyright());
out.printf(CopyrightHeaders.getOpenJDKCopyright(CLDRConverter.copyrightYear));

out.printf((CLDRConverter.isBaseModule ? "package sun.util.cldr;\n\n" :
"package sun.util.resources.cldr.provider;\n\n")
@@ -30,13 +30,15 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.stream.Collectors;

@@ -52,17 +54,19 @@
public class EquivMapsGenerator {

public static void main(String[] args) throws Exception {
if (args.length != 2) {
if (args.length != 3) {
System.err.println("Usage: java EquivMapsGenerator"
+ " language-subtag-registry.txt LocaleEquivalentMaps.java");
+ " language-subtag-registry.txt LocaleEquivalentMaps.java copyrightYear");
System.exit(1);
}
copyrightYear = Integer.parseInt(args[2]);
readLSRfile(args[0]);
generateEquivalentMap();
generateSourceCode(args[1]);
}

private static String LSRrevisionDate;
private static int copyrightYear;
private static Map<String, StringBuilder> initialLanguageMap =
new TreeMap<>();
private static Map<String, StringBuilder> initialRegionVariantMap =
@@ -246,9 +250,7 @@ private static String generateValuesString(String[] values) {
+ "}";

private static String getOpenJDKCopyright() {
int year = ZonedDateTime.now(ZoneId
.of("America/Los_Angeles")).getYear();
return String.format(Locale.US, COPYRIGHT, year);
return String.format(Locale.US, COPYRIGHT, copyrightYear);
}

/**
@@ -62,6 +62,7 @@ $(CLDR_GEN_DONE): $(wildcard $(CLDR_DATA_DIR)/dtd/*.dtd) \
-baselocales "en-US" \
-o $(GENSRC_DIR) \
-basemodule \
-year $(COPYRIGHT_YEAR) \
-zntempfile $(ZONENAME_TEMPLATE) \
-tzdatadir $(TZ_DATA_DIR))
$(TOUCH) $@
@@ -99,7 +100,7 @@ GENSRC_LSREQUIVMAPS := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/sun/util/locale/Loc

$(GENSRC_LSREQUIVMAPS): $(TOPDIR)/make/data/lsrdata/language-subtag-registry.txt $(BUILD_TOOLS_JDK)
$(call MakeDir, $(@D))
$(TOOL_GENERATELSREQUIVMAPS) $< $@
$(TOOL_GENERATELSREQUIVMAPS) $< $@ $(COPYRIGHT_YEAR)

TARGETS += $(GENSRC_LSREQUIVMAPS)

@@ -46,6 +46,7 @@ $(CLDR_GEN_DONE): $(wildcard $(CLDR_DATA_DIR)/dtd/*.dtd) \
$(call ExecuteWithLog, $@, \
$(TOOL_CLDRCONVERTER) -base $(CLDR_DATA_DIR) \
-baselocales "en-US" \
-year $(COPYRIGHT_YEAR) \
-o $(GENSRC_DIR))
$(TOUCH) $@

1 comment on commit 0d933c9

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 0d933c9 Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.