1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package libcore; 18 19 import java.nio.file.Path; 20 import java.nio.file.Paths; 21 import java.util.ArrayList; 22 import java.util.Arrays; 23 import java.util.Collections; 24 import java.util.HashSet; 25 import java.util.LinkedHashSet; 26 import java.util.List; 27 import java.util.Set; 28 import libcore.Repository.OjluniRepository; 29 30 import static libcore.Repository.openJdk9; 31 import static libcore.Repository.openJdk11; 32 import static libcore.Repository.openJdkLegacy; 33 34 public class StandardRepositories { 35 36 private final List<Repository> allUpstreams; 37 // upstreams older than what is currently the default 38 private final List<Repository> historicUpstreams; 39 private final Repository openJdk8u222; 40 private final Repository openJdk8u121; 41 private final Repository openJdk9b113; 42 private final Repository openJdk9p181; 43 private final Repository openJdk7u40; 44 private final OjluniRepository ojluni; 45 StandardRepositories(Path buildTop, Path upstreamRoot)46 private StandardRepositories(Path buildTop, Path upstreamRoot) { 47 // allUpstreams is ordered from latest to earliest 48 Set<Repository> allUpstreams = new LinkedHashSet<>(); 49 allUpstreams.add(openJdk9(upstreamRoot, "9+181")); 50 this.openJdk9b113 = addAndReturn(allUpstreams, openJdk9(upstreamRoot, "9b113+")); 51 this.openJdk8u121 = addAndReturn(allUpstreams, openJdkLegacy(upstreamRoot, "8u121-b13")); 52 this.openJdk8u222 = addAndReturn(allUpstreams, openJdkLegacy(upstreamRoot, "8u222-b01")); 53 this.openJdk9p181 = addAndReturn(allUpstreams, openJdk9(upstreamRoot, "9+181")); 54 Repository openJdk8u60 = addAndReturn(allUpstreams, openJdkLegacy(upstreamRoot, "8u60")); 55 Repository openJdk11p28 = addAndReturn(allUpstreams, openJdk11(upstreamRoot, "11+28")); 56 this.openJdk7u40 = addAndReturn(allUpstreams, openJdkLegacy(upstreamRoot, "7u40")); 57 this.allUpstreams = Collections.unmodifiableList(new ArrayList<>(allUpstreams)); 58 this.historicUpstreams = Collections.unmodifiableList(new ArrayList<>( 59 Arrays.asList(openJdk8u121, openJdk8u60, openJdk11p28, openJdk9p181, openJdk9b113, 60 openJdk7u40) 61 )); 62 this.ojluni = new OjluniRepository(buildTop); 63 } 64 addAndReturn(Set<Repository> repositories, Repository repository)65 private static Repository addAndReturn(Set<Repository> repositories, Repository repository) { 66 repositories.add(repository); 67 return repository; 68 } 69 historicUpstreams()70 public List<Repository> historicUpstreams() { 71 return historicUpstreams; 72 } 73 ojluni()74 public OjluniRepository ojluni() { 75 return ojluni; 76 } 77 78 /** 79 * Returns all upstream repository snapshots, in order from latest to earliest. 80 */ upstreams()81 public List<Repository> upstreams() { 82 return allUpstreams; 83 } 84 fromEnv()85 public static StandardRepositories fromEnv() { 86 Path androidBuildTop = Util.pathFromEnvOrThrow("ANDROID_BUILD_TOP"); 87 Path upstreamRoot = Util.pathFromEnvOrThrow("OPENJDK_HOME"); 88 return new StandardRepositories(androidBuildTop, upstreamRoot); 89 } 90 91 private static final Set<String> juFilesFromJsr166 = Collections.unmodifiableSet( 92 new HashSet<>(Arrays.asList( 93 "AbstractQueue", 94 "ArrayDeque", 95 "ArrayPrefixHelpers", 96 "Deque", 97 "Map", 98 "NavigableMap", 99 "NavigableSet", 100 "PriorityQueue", 101 "Queue", 102 "SplittableRandom" 103 ))); 104 isJsr166(Path relPath)105 public boolean isJsr166(Path relPath) { 106 boolean result = relPath.startsWith("java/util/concurrent/"); 107 String ju = "java/util/"; 108 String suffix = ".java"; 109 if (!result && relPath.startsWith(ju)) { 110 String name = relPath.toString().substring(ju.length()); 111 if (name.endsWith(suffix)) { 112 name = name.substring(0, name.length() - suffix.length()); 113 result = juFilesFromJsr166.contains(name); 114 } 115 } 116 return result; 117 } 118 119 private static final Set<String> REL_PATHS_AT_OPENJDK9_181 = Collections.unmodifiableSet( 120 new HashSet<>(Arrays.asList( 121 "java/util/concurrent/Flow.java", 122 "java/util/AbstractList.java", 123 "java/util/ImmutableCollections.java", 124 "java/util/KeyValueHolder.java", 125 "java/util/List.java", 126 "java/util/Map.java", 127 "java/util/Objects.java", 128 "java/util/Set.java", 129 "jdk/internal/HotSpotIntrinsicCandidate.java", 130 "jdk/internal/vm/annotation/Stable.java", 131 "jdk/internal/util/Preconditions.java" 132 ))); 133 134 private static final Set<String> REL_PATHS_AT_OPENJDK8_222 = Collections.unmodifiableSet( 135 new HashSet<>(Arrays.asList( 136 "java/time/chrono/JapaneseEra.java", 137 "java/util/JapaneseImperialCalendar.java", 138 "sun/util/calendar/Era.java", 139 // Tests: 140 "java/time/tck/java/time/chrono/TCKJapaneseChronology.java", 141 "java/time/tck/java/time/chrono/TCKJapaneseEra.java", 142 "java/time/test/java/time/chrono/TestJapaneseChronology.java", 143 "java/time/test/java/time/chrono/TestUmmAlQuraChronology.java", 144 "java/time/test/java/time/format/TestNonIsoFormatter.java" 145 ))); 146 referenceUpstream(Path relPath)147 public Repository referenceUpstream(Path relPath) { 148 boolean isJsr166 = isJsr166(relPath); 149 if (REL_PATHS_AT_OPENJDK9_181.contains(relPath.toString())) { 150 return openJdk9p181; 151 } else if (REL_PATHS_AT_OPENJDK8_222.contains(relPath.toString())) { 152 return openJdk8u222; 153 } else if (isJsr166) { 154 return openJdk9b113; 155 } else if (relPath.startsWith("java/sql/") || relPath.startsWith("javax/sql/")) { 156 return openJdk7u40; 157 } else { 158 return openJdk8u121; 159 } 160 } 161 162 } 163