| /*=============================================================================# |
| # Copyright (c) 2009, 2020 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.rj.server.eruntime; |
| |
| import static org.eclipse.statet.rj.server.util.ServerUtils.RJ_SERVER_ID; |
| |
| import java.io.IOException; |
| import java.net.URL; |
| |
| import org.osgi.framework.Bundle; |
| |
| import org.eclipse.core.runtime.FileLocator; |
| import org.eclipse.core.runtime.Platform; |
| |
| import org.eclipse.statet.jcommons.lang.NonNullByDefault; |
| |
| import org.eclipse.statet.rj.RjInvalidConfigurationException; |
| import org.eclipse.statet.rj.server.util.RJContext; |
| |
| |
| /** |
| * Server utilities when using the Eclipse Platform. |
| */ |
| @NonNullByDefault |
| public class ERJContext extends RJContext { |
| |
| |
| public ERJContext() { |
| super(); |
| } |
| |
| |
| @Override |
| public String getServerPolicyFilePath() throws RjInvalidConfigurationException { |
| try { |
| final Bundle bundle= Platform.getBundle(RJ_SERVER_ID); |
| if (bundle == null) { |
| throw new RjInvalidConfigurationException(String.format("RJ bundle '%1$s' is missing.", RJ_SERVER_ID)); |
| } |
| final URL intern= bundle.getEntry('/' + LOCALHOST_POLICY_FILENAME); |
| final URL java= FileLocator.resolve(intern); |
| final String path= java.toExternalForm(); |
| return path; |
| } |
| catch (final IOException e) { |
| throw new RjInvalidConfigurationException("Failed find server policy file.", e); |
| } |
| } |
| |
| } |