Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8275745: Reproducible copyright headers
Reviewed-by: ihse, erikj
  • Loading branch information
magicus committed Nov 19, 2021
1 parent b1a1bf4 commit a022796
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 20 deletions.
8 changes: 8 additions & 0 deletions make/autoconf/basic_tools.m4
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions make/autoconf/jdk-options.m4
Expand Up @@ -199,6 +199,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
Expand Down
Expand Up @@ -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<>();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
}
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
Expand Up @@ -29,13 +29,15 @@
import java.io.IOException;
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;

Expand All @@ -51,17 +53,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 =
Expand Down Expand Up @@ -244,9 +248,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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion make/modules/java.base/Gensrc.gmk
Expand Up @@ -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) $@
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions make/modules/jdk.localedata/Gensrc.gmk
Expand Up @@ -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) $@

Expand Down

3 comments on commit a022796

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@andrew-m-leonard
Copy link

Choose a reason for hiding this comment

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

@openjdk
Copy link

@openjdk openjdk bot commented on a022796 Mar 8, 2022

Choose a reason for hiding this comment

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

@andrew-m-leonard the backport was successfully created on the branch andrew-m-leonard-backport-a0227965 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit a0227965 from the openjdk/jdk repository.

The commit being backported was authored by Magnus Ihse Bursie on 19 Nov 2021 and was reviewed by Magnus Ihse Bursie and Erik Joelsson.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev andrew-m-leonard-backport-a0227965:andrew-m-leonard-backport-a0227965
$ git checkout andrew-m-leonard-backport-a0227965
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev andrew-m-leonard-backport-a0227965

Please sign in to comment.