Path: blob/master/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/VersionHelper.java
41161 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.jdeps;2627import com.sun.tools.classfile.ClassFile;28import com.sun.tools.classfile.ConstantPoolException;2930import java.util.Map;31import java.util.concurrent.ConcurrentHashMap;32import java.util.jar.JarEntry;33import java.util.jar.JarFile;3435public class VersionHelper {36private static final String META_INF_VERSIONS = "META-INF/versions/";37private static final Map<String,String> nameToVersion = new ConcurrentHashMap<>();3839public static String get(String classname) {40if (nameToVersion.containsKey(classname)) {41return nameToVersion.get(classname) + "/" + classname;42}43return classname;44}4546public static void add(JarFile jarfile, JarEntry e, ClassFile cf)47throws ConstantPoolException48{49String realName = e.getRealName();50if (realName.startsWith(META_INF_VERSIONS)) {51int len = META_INF_VERSIONS.length();52int n = realName.indexOf('/', len);53if (n > 0) {54String version = realName.substring(len, n);55assert (Integer.parseInt(version) > 8);56String name = cf.getName().replace('/', '.');57if (nameToVersion.containsKey(name)) {58if (!version.equals(nameToVersion.get(name))) {59throw new MultiReleaseException(60"err.multirelease.version.associated",61name, nameToVersion.get(name), version62);63}64} else {65nameToVersion.put(name, version);66}67} else {68throw new MultiReleaseException("err.multirelease.jar.malformed",69jarfile.getName(), realName);70}71}72}73}747576