|
| 1 | +/* |
| 2 | + * Copyright 2019-2021 the original author or authors. |
| 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 | + * https://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 org.springframework.nativex.substitutions.logback; |
| 18 | + |
| 19 | +import java.net.URL; |
| 20 | + |
| 21 | +import ch.qos.logback.classic.LoggerContext; |
| 22 | +import ch.qos.logback.core.LogbackException; |
| 23 | +import ch.qos.logback.core.joran.spi.JoranException; |
| 24 | +import com.oracle.svm.core.annotate.Alias; |
| 25 | +import com.oracle.svm.core.annotate.Substitute; |
| 26 | +import com.oracle.svm.core.annotate.TargetClass; |
| 27 | + |
| 28 | +import org.springframework.nativex.substitutions.LogbackIsAround; |
| 29 | +import org.springframework.nativex.substitutions.OnlyIfPresent; |
| 30 | + |
| 31 | +@TargetClass(className = "ch.qos.logback.classic.util.ContextInitializer", onlyWith = { OnlyIfPresent.class, LogbackIsAround.class }) |
| 32 | +final class Target_ContextInitializer { |
| 33 | + |
| 34 | + @Alias |
| 35 | + LoggerContext loggerContext; |
| 36 | + |
| 37 | + @Substitute |
| 38 | + public void configureByResource(URL url) throws JoranException { |
| 39 | + if (url == null) { |
| 40 | + throw new IllegalArgumentException("URL argument cannot be null"); |
| 41 | + } |
| 42 | + final String urlString = url.toString(); |
| 43 | + if (urlString.endsWith("groovy")) { |
| 44 | + throw new LogbackException("Logback Groovy configuration is not supported on native"); |
| 45 | + } else if (urlString.endsWith("xml")) { |
| 46 | + throw new LogbackException("Logback XML configuration is not supported yet, see https://github.com/spring-projects-experimental/spring-native/issues/625"); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments