From 05c539c9b4057d46b35e649f906f325361b8a88e Mon Sep 17 00:00:00 2001
From: Weijun Wang <weijun@openjdk.org>
Date: Fri, 13 Mar 2020 17:45:55 +0800
Subject: [PATCH] 8240980: Backout JDK-8240261

Reviewed-by: dholmes
---
 make/gensrc/Gensrc-java.base.gmk              |  4 +-
 .../classes/build/tools/intpoly/FieldGen.java | 29 ++++-----
 .../classes/build/tools/intpoly/header.txt    | 28 ++++++++
 .../src/classes/build/tools/util/Header.java  | 64 -------------------
 4 files changed, 43 insertions(+), 82 deletions(-)
 create mode 100644 make/jdk/src/classes/build/tools/intpoly/header.txt
 delete mode 100644 make/jdk/src/classes/build/tools/util/Header.java

diff --git a/make/gensrc/Gensrc-java.base.gmk b/make/gensrc/Gensrc-java.base.gmk
index 7548a14b735..81d37181e38 100644
--- a/make/gensrc/Gensrc-java.base.gmk
+++ b/make/gensrc/Gensrc-java.base.gmk
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -101,7 +101,7 @@ GENSRC_JAVA_BASE += $(GENSRC_LSREQUIVMAPS)
 ################################################################################
 
 INTPOLY_GEN_DONE := $(GENSRC_DIR)/_intpoly-gensrc.marker
-INTPOLY_HEADER := $(TOPDIR)/make/templates/gpl-cp-header
+INTPOLY_HEADER := $(TOPDIR)/make/jdk/src/classes/build/tools/intpoly/header.txt
 $(INTPOLY_GEN_DONE): $(INTPLOY_HEADER) $(BUILD_TOOLS_JDK)
 	$(call MakeDir, $(GENSRC_DIR))
 	$(call LogInfo, Generating fixed-field math classes for java.base)
diff --git a/make/jdk/src/classes/build/tools/intpoly/FieldGen.java b/make/jdk/src/classes/build/tools/intpoly/FieldGen.java
index 97de1f6ddd5..dfde325b613 100644
--- a/make/jdk/src/classes/build/tools/intpoly/FieldGen.java
+++ b/make/jdk/src/classes/build/tools/intpoly/FieldGen.java
@@ -1,12 +1,10 @@
 /*
- * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
+ * published by the Free Software Foundation.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -23,13 +21,12 @@
  * questions.
  */
 
+
 /*
  * This file is used to generated optimized finite field implementations.
  */
 package build.tools.intpoly;
 
-import build.tools.util.Header;
-
 import java.io.*;
 import java.math.BigInteger;
 import java.nio.file.Files;
@@ -587,16 +584,8 @@ public class FieldGen {
 
     private String generate(FieldParams params) throws IOException {
         CodeBuffer result = new CodeBuffer();
-        for (String line : Header.javaHeader(headerPath)) {
-            result.appendLine(line);
-        }
-
-        result.appendLine();
-        result.appendLine("/*");
-        result.appendLine(" * This file is generated by FieldGen.java. "
-                + "Do not modify it directly.");
-        result.appendLine(" */");
-        result.appendLine();
+        String header = readHeader();
+        result.appendLine(header);
 
         if (packageName != null) {
             result.appendLine("package " + packageName + ";");
@@ -921,4 +910,12 @@ public class FieldGen {
             result.freeTemporary(temp);
         }
     }
+
+    private String readHeader() throws IOException {
+        BufferedReader reader
+                = Files.newBufferedReader(headerPath);
+        StringBuffer result = new StringBuffer();
+        reader.lines().forEach(s -> result.append(s + "\n"));
+        return result.toString();
+    }
 }
diff --git a/make/jdk/src/classes/build/tools/intpoly/header.txt b/make/jdk/src/classes/build/tools/intpoly/header.txt
new file mode 100644
index 00000000000..95599194ab5
--- /dev/null
+++ b/make/jdk/src/classes/build/tools/intpoly/header.txt
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * This file is generated by FieldGen.java. Do not modify it directly.
+ */
diff --git a/make/jdk/src/classes/build/tools/util/Header.java b/make/jdk/src/classes/build/tools/util/Header.java
deleted file mode 100644
index 9e78e2000bf..00000000000
--- a/make/jdk/src/classes/build/tools/util/Header.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package build.tools.util;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.List;
-
-public class Header {
-
-    // template: a file inside make/template/
-    // years: "2020," or "2000, 2020,"
-    public static List<String> javaHeader(Path template, String years)
-            throws IOException {
-        List<String> result = new ArrayList<>();
-        result.add("/*");
-        int emptyLines = 0;
-        for (String line :  Files.readAllLines(template)) {
-            if (line.isEmpty()) {
-                emptyLines++;
-            } else {
-                // Only add empty lines when they are not at the end
-                for (int i = 0; i < emptyLines; i++) {
-                    result.add(" *");
-                }
-                emptyLines = 0;
-                result.add(" * " + line.replace("%YEARS%", years));
-            }
-        }
-        result.add(" */");
-        return result;
-    }
-
-    public static List<String> javaHeader(Path template)
-            throws IOException {
-        return javaHeader(template, LocalDate.now().getYear() + ",");
-    }
-}