PlatformUtils.java revision 3170:dc017a37aac5
117680Spst/* 217680Spst * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 317680Spst * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 417680Spst * 517680Spst * This code is free software; you can redistribute it and/or modify it 617680Spst * under the terms of the GNU General Public License version 2 only, as 717680Spst * published by the Free Software Foundation. Oracle designates this 817680Spst * particular file as subject to the "Classpath" exception as provided 917680Spst * by Oracle in the LICENSE file that accompanied this code. 1017680Spst * 1117680Spst * This code is distributed in the hope that it will be useful, but WITHOUT 1217680Spst * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1317680Spst * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1417680Spst * version 2 for more details (a copy is included in the LICENSE file that 1517680Spst * accompanied this code). 1617680Spst * 1717680Spst * You should have received a copy of the GNU General Public License version 1817680Spst * 2 along with this work; if not, write to the Free Software Foundation, 1917680Spst * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2026183Sfenner * 2117680Spst * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2217680Spst * or visit www.oracle.com if you need additional information or have any 2317680Spst * questions. 2417680Spst */ 2526183Sfenner 2626183Sfennerpackage com.sun.tools.javac.platform; 2717680Spst 2817680Spstimport com.sun.tools.javac.main.Arguments; 2917680Spstimport com.sun.tools.javac.platform.PlatformProvider.PlatformNotSupported; 3017680Spstimport java.util.Optional; 3117680Spstimport java.util.ServiceLoader; 3217680Spstimport java.util.stream.StreamSupport; 3317680Spst 3417680Spst/** Internal utilities to work with PlatformDescriptions. 3517680Spst * 3617680Spst * <p><b>This is NOT part of any supported API. 3717680Spst * If you write code that depends on this, you do so at your own risk. 3817680Spst * This code and its internal interfaces are subject to change or 3917680Spst * deletion without notice.</b> 4021262Swollman */ 4117680Spstpublic class PlatformUtils { 4217680Spst 4317680Spst public static PlatformDescription lookupPlatformDescription(String platformString) { 4417680Spst int separator = platformString.indexOf(":"); 4517680Spst String platformProviderName = 4617680Spst separator != (-1) ? platformString.substring(0, separator) : platformString; 4717688Spst String platformOptions = 4817680Spst separator != (-1) ? platformString.substring(separator + 1) : ""; 4917688Spst Iterable<PlatformProvider> providers = 5017688Spst ServiceLoader.load(PlatformProvider.class, Arguments.class.getClassLoader()); 5117688Spst 5217688Spst return StreamSupport.stream(providers.spliterator(), false) 5317680Spst .filter(provider -> StreamSupport.stream(provider.getSupportedPlatformNames() 5432149Spst .spliterator(), 5532149Spst false) 5632149Spst .anyMatch(platformProviderName::equals)) 5732149Spst .findFirst() 5832149Spst .flatMap(provider -> { 5932149Spst try { 6032149Spst return Optional.of(provider.getPlatform(platformProviderName, platformOptions)); 6132149Spst } catch (PlatformNotSupported pns) { 6232149Spst return Optional.empty(); 6332149Spst } 6432149Spst }) 6532149Spst .orElse(null); 6632149Spst } 6732149Spst 6832149Spst} 6932149Spst