| /*=============================================================================# |
| # Copyright (c) 2018, 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.jcommons.runtime; |
| |
| import java.io.PrintStream; |
| |
| import org.eclipse.statet.jcommons.lang.NonNullByDefault; |
| import org.eclipse.statet.jcommons.lang.Nullable; |
| import org.eclipse.statet.jcommons.status.Status; |
| |
| |
| @NonNullByDefault |
| public class CommonsRuntime { |
| |
| |
| private static @Nullable AppEnvironment environment; |
| |
| |
| public static void init(final AppEnvironment environment) { |
| if (CommonsRuntime.environment != null) { |
| throw new IllegalStateException( |
| String.format("Already initialized by '%1$s'.", |
| CommonsRuntime.environment.getBundleId()) ); |
| } |
| CommonsRuntime.environment= environment; |
| } |
| |
| public static AppEnvironment getEnvironment() { |
| return CommonsRuntime.environment; |
| } |
| |
| |
| public static void log(final Status status) { |
| final AppEnvironment environment= CommonsRuntime.environment; |
| if (environment != null) { |
| environment.log(status); |
| } |
| else { |
| final PrintStream out; |
| switch (status.getSeverity()) { |
| case Status.OK: |
| case Status.INFO: |
| out= System.out; |
| break; |
| default: |
| out= System.err; |
| break; |
| } |
| out.print(status.toString()); |
| } |
| } |
| |
| |
| private CommonsRuntime() {} |
| |
| } |