test/jdk/lib/testlibrary/java/util/jar/CreateMultiReleaseTestJars.java
changeset 48690 374c63fbe652
parent 47218 918745561887
child 52158 f351c1a6c37a
equal deleted inserted replaced
48689:e704f48d8277 48690:374c63fbe652
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    67             + "class PackagePrivate {\n"
    67             + "class PackagePrivate {\n"
    68             + "    int getVersion() {\n"
    68             + "    int getVersion() {\n"
    69             + "        return 9;\n"
    69             + "        return 9;\n"
    70             + "    }\n"
    70             + "    }\n"
    71             + "}\n";
    71             + "}\n";
    72     final private String java10 = java8.replace("8", "10");
    72     final int currentVersion = Runtime.version().major();
       
    73     final String currentVersionStr = Integer.toString(currentVersion);
       
    74     final private String javaCurrent = java8.replace("8", currentVersionStr);
    73     final String readme8 = "This is the root readme file";
    75     final String readme8 = "This is the root readme file";
    74     final String readme9 = "This is the version nine readme file";
    76     final String readme9 = "This is the version nine readme file";
    75     final String readme10 = "This is the version ten readme file";
    77     final String readmeCurrent = "This is the current version readme file";
    76     private Map<String,byte[]> rootClasses;
    78     private Map<String,byte[]> rootClasses;
    77     private Map<String,byte[]> version9Classes;
    79     private Map<String,byte[]> version9Classes;
    78     private Map<String,byte[]> version10Classes;
    80     private Map<String,byte[]> versionCurrentClasses;
    79 
    81 
    80     public void buildUnversionedJar() throws IOException {
    82     public void buildUnversionedJar() throws IOException {
    81         JarBuilder jb = new JarBuilder("unversioned.jar");
    83         JarBuilder jb = new JarBuilder("unversioned.jar");
    82         jb.addEntry("README", readme8.getBytes());
    84         jb.addEntry("README", readme8.getBytes());
    83         jb.addEntry("version/Main.java", main.getBytes());
    85         jb.addEntry("version/Main.java", main.getBytes());
   132         jb.addEntry("version/Version.class", rootClasses.get("version.Version"));
   134         jb.addEntry("version/Version.class", rootClasses.get("version.Version"));
   133         jb.addEntry("META-INF/versions/9/README", readme9.getBytes());
   135         jb.addEntry("META-INF/versions/9/README", readme9.getBytes());
   134         jb.addEntry("META-INF/versions/9/version/Version.java", java9.getBytes());
   136         jb.addEntry("META-INF/versions/9/version/Version.java", java9.getBytes());
   135         jb.addEntry("META-INF/versions/9/version/PackagePrivate.java", ppjava9.getBytes());
   137         jb.addEntry("META-INF/versions/9/version/PackagePrivate.java", ppjava9.getBytes());
   136         jb.addEntry("META-INF/versions/9/version/PackagePrivate.class", version9Classes.get("version.PackagePrivate"));
   138         jb.addEntry("META-INF/versions/9/version/PackagePrivate.class", version9Classes.get("version.PackagePrivate"));
   137         jb.addEntry("META-INF/versions/10/README", readme10.getBytes());
   139         jb.addEntry("META-INF/versions/" + currentVersionStr + "/README", readmeCurrent.getBytes());
   138         jb.addEntry("META-INF/versions/10/version/Version.java", java10.getBytes());
   140         jb.addEntry("META-INF/versions/" + currentVersionStr + "/version/Version.java", javaCurrent.getBytes());
   139         jb.addEntry("META-INF/versions/10/version/Version.class", version10Classes.get("version.Version"));
   141         jb.addEntry("META-INF/versions/" + currentVersionStr + "/version/Version.class", versionCurrentClasses.get("version.Version"));
   140     }
   142     }
   141 
   143 
   142     public void buildSignedMultiReleaseJar() throws Exception {
   144     public void buildSignedMultiReleaseJar() throws Exception {
   143         String testsrc = System.getProperty("test.src",".");
   145         String testsrc = System.getProperty("test.src",".");
   144         String testdir = findTestDir(testsrc);
   146         String testdir = findTestDir(testsrc);
   184         input.clear();
   186         input.clear();
   185         input.put("version.Version", java9);
   187         input.put("version.Version", java9);
   186         input.put("version.PackagePrivate", ppjava9);
   188         input.put("version.PackagePrivate", ppjava9);
   187         version9Classes = (new Compiler(input)).setRelease(9).compile();
   189         version9Classes = (new Compiler(input)).setRelease(9).compile();
   188         input.clear();
   190         input.clear();
   189         input.put("version.Version", java10);
   191         input.put("version.Version", javaCurrent);
   190         version10Classes = (new Compiler(input)).setRelease(9).compile();  // fixme in JDK 10
   192         versionCurrentClasses = (new Compiler(input)).compile();  // Use default release
   191     }
   193     }
   192 }
   194 }