You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2017/06/18 19:27:19 UTC
[1/2] logging-log4j2 git commit: Move java9 to its own module. Mark
artifacts that don't go to nexus as non-dpeloyable
Repository: logging-log4j2
Updated Branches:
refs/heads/master 6c8f0d6bc -> 55b9fd209
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-samples/loggerProperties/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/loggerProperties/pom.xml b/log4j-samples/loggerProperties/pom.xml
index 207bb2e..62700ea 100644
--- a/log4j-samples/loggerProperties/pom.xml
+++ b/log4j-samples/loggerProperties/pom.xml
@@ -50,6 +50,14 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-samples/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/pom.xml b/log4j-samples/pom.xml
index 2c7cc63..e301bfb 100644
--- a/log4j-samples/pom.xml
+++ b/log4j-samples/pom.xml
@@ -111,6 +111,14 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-samples/scala-api/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/scala-api/pom.xml b/log4j-samples/scala-api/pom.xml
index d305bcb..7d3bbe8 100644
--- a/log4j-samples/scala-api/pom.xml
+++ b/log4j-samples/scala-api/pom.xml
@@ -75,6 +75,14 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4c58276..5235378 100644
--- a/pom.xml
+++ b/pom.xml
@@ -191,6 +191,7 @@
<javadoc.plugin.version>2.10.4</javadoc.plugin.version>
<!-- surefire.plugin.version 2.18 yields http://jira.codehaus.org/browse/SUREFIRE-1121, which is fixed in 2.18.1 -->
<!-- surefire.plugin.version 2.19 yields https://issues.apache.org/jira/browse/SUREFIRE-1193. -->
+ <!-- all versions after 2.13 yield https://issues.apache.org/jira/browse/SUREFIRE-720 -->
<surefire.plugin.version>2.20</surefire.plugin.version>
<failsafe.plugin.version>2.20</failsafe.plugin.version>
<checkstyle.plugin.version>2.17</checkstyle.plugin.version>
@@ -302,6 +303,12 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api-java9</artifactId>
+ <version>${project.version}</version>
+ <type>zip</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${project.version}</version>
</dependency>
@@ -937,64 +944,6 @@
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
- <executions>
- <execution>
- <id>clean-java9</id>
- <goals>
- <goal>clean</goal>
- </goals>
- <phase>process-resources</phase>
- <configuration>
- <excludeDefaultDirectories>true</excludeDefaultDirectories>
- <filesets>
- <fileset>
- <directory>${project.build.directory}/classes</directory>
- <includes>
- <include>**/*.class</include>
- </includes>
- <excludes>
- <exclude>module-info.class</exclude>
- </excludes>
- <followSymlinks>false</followSymlinks>
- </fileset>
- </filesets>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>${compiler.plugin.version}</version>
- <executions>
- <execution>
- <!-- disable annotation processing for first pass -->
- <id>default-compile</id>
- <configuration>
- <excludes>
- <exclude>module-info.java</exclude>
- </excludes>
- </configuration>
- </execution>
- <execution>
- <id>java9-compile</id>
- <goals>
- <goal>compile</goal>
- </goals>
- <phase>compile</phase>
- <configuration>
- <!-- compile everything to ensure module-info contains right entries -->
- <!-- required when JAVA_HOME is JDK 8 or below -->
- <jdkToolchain>
- <version>9</version>
- </jdkToolchain>
- <release>9</release>
- <proc>none</proc>
- <includes>
- <include>module-info.java</include>
- </includes>
- </configuration>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -1323,6 +1272,7 @@
</site>
</distributionManagement>
<modules>
+ <module>log4j-api-java9</module>
<module>log4j-api</module>
<module>log4j-core</module>
<module>log4j-core-its</module>
[2/2] logging-log4j2 git commit: Move java9 to its own module. Mark
artifacts that don't go to nexus as non-dpeloyable
Posted by rg...@apache.org.
Move java9 to its own module. Mark artifacts that don't go to nexus as non-dpeloyable
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/55b9fd20
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/55b9fd20
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/55b9fd20
Branch: refs/heads/master
Commit: 55b9fd20907994a5115e28674d03ddb215e149b4
Parents: 6c8f0d6
Author: Ralph Goers <rg...@nextiva.com>
Authored: Sun Jun 18 10:40:53 2017 -0700
Committer: Ralph Goers <rg...@nextiva.com>
Committed: Sun Jun 18 12:27:11 2017 -0700
----------------------------------------------------------------------
.../logging/log4j/util/ClassNamePredicate.class | Bin 0 -> 1153 bytes
.../logging/log4j/util/ClassPredicate.class | Bin 0 -> 1230 bytes
.../logging/log4j/util/StackLocator.class | Bin 0 -> 809 bytes
.../logging/log4j/util/StackLocatorUtil.class | Bin 0 -> 1941 bytes
.../log4j/util/StackWalkerStackLocator.class | Bin 0 -> 5503 bytes
.../logging/log4j/util/ClassNamePredicate.java | 45 ++++
.../logging/log4j/util/ClassPredicate.java | 46 ++++
.../apache/logging/log4j/util/StackLocator.java | 39 +++
.../logging/log4j/util/StackLocatorUtil.java | 70 +++++
.../log4j/util/StackWalkerStackLocator.java | 63 +++++
log4j-api-java9/pom.xml | 153 +++++++++++
log4j-api-java9/src/assembly/java9.xml | 36 +++
.../apache/logging/log4j/util/StackLocator.java | 78 ++++++
.../logging/log4j/util/StackLocatorTest.java | 101 +++++++
log4j-api/pom.xml | 104 +++----
.../logging/log4j/util/DefaultStackLocator.java | 268 -------------------
.../log4j/util/ReflectionStackLocator.java | 181 -------------
.../apache/logging/log4j/util/StackLocator.java | 263 +++++++++++++++++-
.../logging/log4j/util/StackLocatorUtil.java | 26 +-
.../logging/log4j/util/ClassNamePredicate.java | 45 ----
.../logging/log4j/util/ClassPredicate.java | 46 ----
.../log4j/util/StackWalkerStackLocator.java | 63 -----
.../log4j/util/StackLocatorUtilTest.java | 3 +-
log4j-core-its/pom.xml | 8 -
log4j-distribution/pom.xml | 14 +-
log4j-perf/pom.xml | 8 +
log4j-samples/configuration/pom.xml | 8 +
log4j-samples/flume-common/pom.xml | 8 +
log4j-samples/flume-embedded/pom.xml | 8 +
log4j-samples/flume-remote/pom.xml | 8 +
log4j-samples/loggerProperties/pom.xml | 8 +
log4j-samples/pom.xml | 8 +
log4j-samples/scala-api/pom.xml | 8 +
pom.xml | 66 +----
34 files changed, 1007 insertions(+), 775 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/ClassNamePredicate.class
----------------------------------------------------------------------
diff --git a/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/ClassNamePredicate.class b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/ClassNamePredicate.class
new file mode 100644
index 0000000..44d47fb
Binary files /dev/null and b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/ClassNamePredicate.class differ
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/ClassPredicate.class
----------------------------------------------------------------------
diff --git a/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/ClassPredicate.class b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/ClassPredicate.class
new file mode 100644
index 0000000..c59981d
Binary files /dev/null and b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/ClassPredicate.class differ
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackLocator.class
----------------------------------------------------------------------
diff --git a/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackLocator.class b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackLocator.class
new file mode 100644
index 0000000..a6d9761
Binary files /dev/null and b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackLocator.class differ
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackLocatorUtil.class
----------------------------------------------------------------------
diff --git a/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackLocatorUtil.class b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackLocatorUtil.class
new file mode 100644
index 0000000..3058059
Binary files /dev/null and b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackLocatorUtil.class differ
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackWalkerStackLocator.class
----------------------------------------------------------------------
diff --git a/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackWalkerStackLocator.class b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackWalkerStackLocator.class
new file mode 100644
index 0000000..5cf29d1
Binary files /dev/null and b/log4j-api-java9/META-INF/versions/9/org/apache/logging/log4j/util/StackWalkerStackLocator.class differ
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/ClassNamePredicate.java
----------------------------------------------------------------------
diff --git a/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/ClassNamePredicate.java b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/ClassNamePredicate.java
new file mode 100644
index 0000000..063e538
--- /dev/null
+++ b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/ClassNamePredicate.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.function.Predicate;
+
+/**
+ * <em>This class should be considered to be internal.</em> Used to locate the StackFrame that called the named class.
+ */
+public final class ClassNamePredicate implements Predicate<StackWalker.StackFrame> {
+
+ private final String fqcn;
+
+ public ClassNamePredicate(String fqcn) {
+ this.fqcn = fqcn;
+ }
+
+ private boolean next = false;
+
+ @Override
+ public boolean test(StackWalker.StackFrame f) {
+ if (fqcn.equals(f.getClassName())) {
+ next = true;
+ return false;
+ } else if (next) {
+ next = false;
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/ClassPredicate.java
----------------------------------------------------------------------
diff --git a/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/ClassPredicate.java b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/ClassPredicate.java
new file mode 100644
index 0000000..3f8d15a
--- /dev/null
+++ b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/ClassPredicate.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.function.Predicate;
+
+/**
+ * <em>This class should be considered to be internal.</em> Used to locate the StackFrame that called the named class.
+ */
+
+public final class ClassPredicate implements Predicate<StackWalker.StackFrame> {
+
+ private final Class<?> clazz;
+
+ public ClassPredicate(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ private boolean next = false;
+
+ @Override
+ public boolean test(StackWalker.StackFrame f) {
+ if (clazz.equals(f.getDeclaringClass())) {
+ next = true;
+ return false;
+ } else if (next) {
+ next = false;
+ return true;
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackLocator.java
----------------------------------------------------------------------
diff --git a/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackLocator.java b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackLocator.java
new file mode 100644
index 0000000..3ae15ef
--- /dev/null
+++ b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackLocator.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.Stack;
+
+/**
+ * Interface for methods used to locate information about the caller.
+ */
+public interface StackLocator {
+
+ Class<?> getCallerClass(final int depth);
+
+ StackTraceElement getStackTraceElement(final int depth);
+
+ Class<?> getCallerClass(final String fqcn);
+
+ Class<?> getCallerClass(final String fqcn, final String pkg);
+
+ Class<?> getCallerClass(final Class<?> anchor);
+
+ Stack<Class<?>> getCurrentStackTrace();
+
+ StackTraceElement calcLocation(final String fqcnOfLogger);
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackLocatorUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackLocatorUtil.java b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackLocatorUtil.java
new file mode 100644
index 0000000..326247b
--- /dev/null
+++ b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackLocatorUtil.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.Stack;
+
+/**
+ * <em>Consider this class private.</em> Provides various methods to determine the caller class. <h3>Background</h3>
+ */
+public final class StackLocatorUtil {
+ private static StackLocator stackLocator = null;
+
+ private static final String EMPTY = "";
+
+ static {
+ stackLocator = new StackWalkerStackLocator();
+ }
+
+ private StackLocatorUtil() {
+ }
+
+ // TODO: return Object.class instead of null (though it will have a null ClassLoader)
+ // (MS) I believe this would work without any modifications elsewhere, but I could be wrong
+
+ // migrated from ReflectiveCallerClassUtility
+ public static Class<?> getCallerClass(final int depth) {
+ return stackLocator.getCallerClass(depth + 1);
+ }
+
+ public static StackTraceElement getStackTraceElement(final int depth) {
+ return stackLocator.getStackTraceElement(depth + 1);
+ }
+ // migrated from ClassLoaderContextSelector
+ public static Class<?> getCallerClass(final String fqcn) {
+ return getCallerClass(fqcn, EMPTY);
+ }
+
+ // migrated from Log4jLoggerFactory
+ public static Class<?> getCallerClass(final String fqcn, final String pkg) {
+ return stackLocator.getCallerClass(fqcn, pkg);
+ }
+
+ // added for use in LoggerAdapter implementations mainly
+ public static Class<?> getCallerClass(final Class<?> anchor) {
+ return stackLocator.getCallerClass(anchor);
+ }
+
+ // migrated from ThrowableProxy
+ public static Stack<Class<?>> getCurrentStackTrace() {
+ return stackLocator.getCurrentStackTrace();
+ }
+
+ public static StackTraceElement calcLocation(final String fqcnOfLogger) {
+ return stackLocator.calcLocation(fqcnOfLogger);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackWalkerStackLocator.java
----------------------------------------------------------------------
diff --git a/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackWalkerStackLocator.java b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackWalkerStackLocator.java
new file mode 100644
index 0000000..dc10fef
--- /dev/null
+++ b/log4j-api-java9/log4j-api-java9/org/apache/logging/log4j/util/StackWalkerStackLocator.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.List;
+import java.util.Stack;
+import java.util.stream.Collectors;
+
+/**
+ * <em>Consider this class private.</em> Determines the caller's class.
+ */
+public class StackWalkerStackLocator implements StackLocator {
+
+ private final static StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
+
+ private final static StackWalker stackWalker = StackWalker.getInstance();
+
+ public Class<?> getCallerClass(final String fqcn) {
+ return getCallerClass(fqcn, "");
+ }
+
+ public Class<?> getCallerClass(final String fqcn, final String pkg) {
+ return walker.walk(s -> s.filter(new ClassNamePredicate(fqcn)).findFirst()).get().getDeclaringClass();
+ }
+
+ public Class<?> getCallerClass(final Class<?> anchor) {
+ return walker.walk(s -> s.filter(new ClassPredicate(anchor)).findFirst()).get().getDeclaringClass();
+ }
+
+ public Class<?> getCallerClass(final int depth) {
+ ;
+ return walker.walk(s -> s.skip(depth).findFirst()).get().getDeclaringClass();
+ }
+
+ public Stack<Class<?>> getCurrentStackTrace() {
+ Stack<Class<?>> stack = new Stack<Class<?>>();
+ List<Class<?>> classes = walker.walk(s -> s.map(f -> f.getDeclaringClass()).collect(Collectors.toList()));
+ stack.addAll(classes);
+ return stack;
+ }
+
+ public StackTraceElement calcLocation(final String fqcnOfLogger) {
+ return stackWalker.walk(s -> s.filter(new ClassNamePredicate(fqcnOfLogger)).findFirst()).get().toStackTraceElement();
+ }
+
+ public StackTraceElement getStackTraceElement(final int depth) {
+ return stackWalker.walk(s -> s.skip(depth).findFirst()).get().toStackTraceElement();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-api-java9/pom.xml b/log4j-api-java9/pom.xml
new file mode 100644
index 0000000..6d6c832
--- /dev/null
+++ b/log4j-api-java9/pom.xml
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache license, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the license for the specific language governing permissions and
+ ~ limitations under the license.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>2.8.3-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+ <artifactId>log4j-api-java9</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Log4j API Java 9 support</name>
+ <description>The Apache Log4j API (Java 9)</description>
+ <properties>
+ <log4jParentDir>${basedir}/..</log4jParentDir>
+ <docLabel>API Documentation</docLabel>
+ <projectDir>/api</projectDir>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <toolchains>
+ <jdk>
+ <version>9</version>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-compile</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-test-compile</id>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <source>9</source>
+ <target>9</target>
+ <release>9</release>
+ <proc>none</proc>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <!-- Do not upgrade until https://issues.apache.org/jira/browse/SUREFIRE-720 is fixed -->
+ <version>2.13</version>
+ <executions>
+ <execution>
+ <id>test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <systemPropertyVariables>
+ <java.awt.headless>true</java.awt.headless>
+ </systemPropertyVariables>
+ <forkCount>2C</forkCount>
+ <reuseForks>true</reuseForks>
+ <includes>
+ <include>**/Test*.java</include>
+ <include>**/*Test.java</include>
+ </includes>
+ <excludes>
+ <exclude>**/*FuncTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>zip</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <finalName>log4j-api-java9-${project.version}</finalName>
+ <appendAssemblyId>false</appendAssemblyId>
+ <descriptors>
+ <descriptor>src/assembly/java9.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/src/assembly/java9.xml
----------------------------------------------------------------------
diff --git a/log4j-api-java9/src/assembly/java9.xml b/log4j-api-java9/src/assembly/java9.xml
new file mode 100644
index 0000000..739c95d
--- /dev/null
+++ b/log4j-api-java9/src/assembly/java9.xml
@@ -0,0 +1,36 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<assembly>
+ <id>src</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <baseDirectory>/</baseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>${project.build.outputDirectory}</directory>
+ <outputDirectory>/classes/META-INF/versions/9</outputDirectory>
+ <includes>
+ <include>**/*.class</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</assembly>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/src/main/java/org/apache/logging/log4j/util/StackLocator.java
----------------------------------------------------------------------
diff --git a/log4j-api-java9/src/main/java/org/apache/logging/log4j/util/StackLocator.java b/log4j-api-java9/src/main/java/org/apache/logging/log4j/util/StackLocator.java
new file mode 100644
index 0000000..9450fda
--- /dev/null
+++ b/log4j-api-java9/src/main/java/org/apache/logging/log4j/util/StackLocator.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.List;
+import java.util.Stack;
+import java.util.stream.Collectors;
+
+/**
+ * <em>Consider this class private.</em> Determines the caller's class.
+ */
+public class StackLocator {
+
+ private final static StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
+
+ private final static StackWalker stackWalker = StackWalker.getInstance();
+
+ private final static StackLocator INSTANCE = new StackLocator();
+
+
+ public static StackLocator getInstance() {
+ return INSTANCE;
+ }
+
+ private StackLocator() {
+ }
+
+ public Class<?> getCallerClass(final String fqcn) {
+ return getCallerClass(fqcn, "");
+ }
+
+ public Class<?> getCallerClass(final String fqcn, final String pkg) {
+ return walker.walk(s -> s.dropWhile(f -> !f.getClassName().equals(fqcn)).
+ dropWhile(f -> f.getClassName().equals(fqcn)).dropWhile(f -> !f.getClassName().startsWith(pkg)).
+ findFirst()).map(StackWalker.StackFrame::getDeclaringClass).orElse(null);
+ }
+
+ public Class<?> getCallerClass(final Class<?> anchor) {
+ return walker.walk(s -> s.dropWhile(f -> !f.getDeclaringClass().equals(anchor)).
+ dropWhile(f -> f.getDeclaringClass().equals(anchor)).findFirst()).
+ map(StackWalker.StackFrame::getDeclaringClass).orElse(null);
+ }
+
+ public Class<?> getCallerClass(final int depth) {
+ ;
+ return walker.walk(s -> s.skip(depth).findFirst()).map(StackWalker.StackFrame::getDeclaringClass).orElse(null);
+ }
+
+ public Stack<Class<?>> getCurrentStackTrace() {
+ Stack<Class<?>> stack = new Stack<Class<?>>();
+ List<Class<?>> classes = walker.walk(s -> s.map(f -> f.getDeclaringClass()).collect(Collectors.toList()));
+ stack.addAll(classes);
+ return stack;
+ }
+
+ public StackTraceElement calcLocation(final String fqcnOfLogger) {
+ return stackWalker.walk(s -> s.dropWhile(f -> f.getClassName().equals(fqcnOfLogger)).
+ dropWhile(f -> f.getClassName().equals(fqcnOfLogger)).findFirst()).get().toStackTraceElement();
+ }
+
+ public StackTraceElement getStackTraceElement(final int depth) {
+ return stackWalker.walk(s -> s.skip(depth).findFirst()).get().toStackTraceElement();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api-java9/src/test/java/org/apache/logging/log4j/util/StackLocatorTest.java
----------------------------------------------------------------------
diff --git a/log4j-api-java9/src/test/java/org/apache/logging/log4j/util/StackLocatorTest.java b/log4j-api-java9/src/test/java/org/apache/logging/log4j/util/StackLocatorTest.java
new file mode 100644
index 0000000..bcf4d74
--- /dev/null
+++ b/log4j-api-java9/src/test/java/org/apache/logging/log4j/util/StackLocatorTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.Stack;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.ParentRunner;
+import static org.junit.Assert.*;
+
+@RunWith(BlockJUnit4ClassRunner.class)
+public class StackLocatorTest {
+
+ private static StackLocator stackLocator;
+
+ @BeforeClass
+ public static void setupClass() {
+
+ stackLocator = StackLocator.getInstance();
+ }
+
+ @Test
+ public void testGetCallerClass() throws Exception {
+ final Class<?> expected = StackLocatorTest.class;
+ final Class<?> actual = stackLocator.getCallerClass(1);
+ assertSame(expected, actual);
+ }
+
+ @Test
+ public void testGetCallerClassNameViaStackTrace() throws Exception {
+ final Class<?> expected = StackLocatorTest.class;
+ final Class<?> actual = Class.forName(new Throwable().getStackTrace()[0].getClassName());
+ assertSame(expected, actual);
+ }
+
+ @Test
+ public void testGetCurrentStackTrace() throws Exception {
+ final Stack<Class<?>> classes = stackLocator.getCurrentStackTrace();
+ final Stack<Class<?>> reversed = new Stack<>();
+ reversed.ensureCapacity(classes.size());
+ while (!classes.empty()) {
+ reversed.push(classes.pop());
+ }
+ while (reversed.peek() != StackLocator.class) {
+ reversed.pop();
+ }
+ reversed.pop(); // ReflectionUtil
+ assertSame(StackLocatorTest.class, reversed.pop());
+ }
+
+ @Test
+ public void testGetCallerClassViaName() throws Exception {
+ final Class<?> expected = BlockJUnit4ClassRunner.class;
+ final Class<?> actual = stackLocator.getCallerClass("org.junit.runners.ParentRunner");
+ // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and
+ // update this test accordingly
+ assertSame(expected, actual);
+ }
+
+ @Test
+ public void testGetCallerClassViaAnchorClass() throws Exception {
+ final Class<?> expected = BlockJUnit4ClassRunner.class;
+ final Class<?> actual = stackLocator.getCallerClass(ParentRunner.class);
+ // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and
+ // update this test accordingly
+ assertSame(expected, actual);
+ }
+
+ @Test
+ public void testLocateClass() {
+ ClassLocator locator = new ClassLocator();
+ Class<?> clazz = locator.locateClass();
+ assertNotNull("Could not locate class", clazz);
+ assertEquals("Incorrect class", this.getClass(), clazz);
+ }
+
+ class ClassLocator {
+
+ public Class<?> locateClass() {
+ return stackLocator.getCallerClass(ClassLocator.class);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-api/pom.xml b/log4j-api/pom.xml
index 0b161d6..26ccd4d 100644
--- a/log4j-api/pom.xml
+++ b/log4j-api/pom.xml
@@ -33,6 +33,12 @@
<projectDir>/api</projectDir>
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api-java9</artifactId>
+ <scope>provided</scope>
+ <type>zip</type>
+ </dependency>
<!-- Place Felix before Equinox because Felix is signed. / also place it before org.osgi.core so that its versions of the OSGi classes are used -->
<dependency>
<groupId>org.apache.felix</groupId>
@@ -80,64 +86,49 @@
<build>
<plugins>
<plugin>
- <artifactId>maven-clean-plugin</artifactId>
- <version>3.0.0</version>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>3.0.1</version>
<executions>
<execution>
- <id>clean-java9</id>
+ <id>unpack-classes</id>
+ <phase>prepare-package</phase>
<goals>
- <goal>clean</goal>
+ <goal>unpack</goal>
</goals>
- <phase>process-resources</phase>
<configuration>
- <excludeDefaultDirectories>true</excludeDefaultDirectories>
- <filesets>
- <fileset>
- <directory>${project.build.directory}/classes</directory>
- <includes>
- <include>**/*.class</include>
- </includes>
- <excludes>
- <exclude>module-info.class</exclude>
- <exclude>**/util/ClassNamePredicate.class</exclude>
- <exclude>**/util/ClassPredicate.class</exclude>
- <exclude>**/util/StackWalkerStackLocator.class</exclude>
- </excludes>
- <followSymlinks>false</followSymlinks>
- </fileset>
- </filesets>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api-java9</artifactId>
+ <version>${project.version}</version>
+ <type>zip</type>
+ <overWrite>false</overWrite>
+ </artifactItem>
+ </artifactItems>
+ <includes>**/*.class</includes>
+ <excludes>**/*.java</excludes>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Export-Package>org.apache.logging.log4j.*</Export-Package>
- <Import-Package>
- sun.reflect;resolution:=optional,
- org.apache.logging.log4j.core.osgi;resolution:=optional,
- org.apache.logging.log4j.core.util;resolution:=optional,
- *
- </Import-Package>
- <Bundle-Activator>org.apache.logging.log4j.util.Activator</Bundle-Activator>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.7</version>
<executions>
<execution>
- <phase>process-classes</phase>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
- <source>src/main/java9</source>
+ <source>${project.build.directory}/log4j-api-java9</source>
</sources>
</configuration>
</execution>
@@ -155,32 +146,6 @@
<target>1.7</target>
</configuration>
</execution>
- <execution>
- <id>process-plugins</id>
- <phase>none</phase>
- </execution>
- <execution>
- <id>java9-compile</id>
- <goals>
- <goal>compile</goal>
- </goals>
- <phase>process-classes</phase>
- <configuration>
- <!-- compile everything to ensure module-info contains right entries -->
- <!-- required when JAVA_HOME is JDK 8 or below -->
- <jdkToolchain>
- <version>9</version>
- </jdkToolchain>
- <release>9</release>
- <proc>none</proc>
- <includes>
- <include>module-info.java</include>
- <include>**/util/ClassNamePredicate.java</include>
- <include>**/util/ClassPredicate.java</include>
- <include>**/util/StackWalkerStackLocator.java</include>
- </includes>
- </configuration>
- </execution>
</executions>
</plugin>
<plugin>
@@ -207,6 +172,7 @@
<Implementation-Vendor-Id>org.apache</Implementation-Vendor-Id>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
+ <Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
@@ -249,6 +215,14 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
<reporting>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/src/main/java/org/apache/logging/log4j/util/DefaultStackLocator.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/DefaultStackLocator.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/DefaultStackLocator.java
deleted file mode 100644
index bd65672..0000000
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/DefaultStackLocator.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.util;
-
-import java.util.Stack;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * <em>Consider this class private.</em> Provides various methods to determine the caller class. <h3>Background</h3>
- * <p>
- * This method, available only in the Oracle/Sun/OpenJDK implementations of the Java Virtual Machine, is a much more
- * efficient mechanism for determining the {@link Class} of the caller of a particular method. When it is not available,
- * a {@link SecurityManager} is the second-best option. When this is also not possible, the {@code StackTraceElement[]}
- * returned by {@link Throwable#getStackTrace()} must be used, and its {@code String} class name converted to a
- * {@code Class} using the slow {@link Class#forName} (which can add an extra microsecond or more for each invocation
- * depending on the runtime ClassLoader hierarchy).
- * </p>
- * <p>
- * During Java 8 development, the {@code sun.reflect.Reflection.getCallerClass(int)} was removed from OpenJDK, and this
- * change was back-ported to Java 7 in version 1.7.0_25 which changed the behavior of the call and caused it to be off
- * by one stack frame. This turned out to be beneficial for the survival of this API as the change broke hundreds of
- * libraries and frameworks relying on the API which brought much more attention to the intended API removal.
- * </p>
- * <p>
- * After much community backlash, the JDK team agreed to restore {@code getCallerClass(int)} and keep its existing
- * behavior for the rest of Java 7. However, the method is deprecated in Java 8, and current Java 9 development has not
- * addressed this API. Therefore, the functionality of this class cannot be relied upon for all future versions of Java.
- * It does, however, work just fine in Sun JDK 1.6, OpenJDK 1.6, Oracle/OpenJDK 1.7, and Oracle/OpenJDK 1.8. Other Java
- * environments may fall back to using {@link Throwable#getStackTrace()} which is significantly slower due to
- * examination of every virtual frame of execution.
- * </p>
- */
-public class DefaultStackLocator implements StackLocator {
-
- protected static final Logger LOGGER = StatusLogger.getLogger();
- private static PrivateSecurityManager SECURITY_MANAGER;
-
- static {
- PrivateSecurityManager psm;
- try {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new RuntimePermission("createSecurityManager"));
- }
- psm = new PrivateSecurityManager();
- } catch (final SecurityException ignored) {
- LOGGER.debug("Not allowed to create SecurityManager. "
- + "Falling back to slowest ReflectionUtil implementation.");
- psm = null;
- }
- SECURITY_MANAGER = psm;
- }
-
- protected DefaultStackLocator() {
- }
-
- protected PrivateSecurityManager getSecurityManager() {
- return SECURITY_MANAGER;
- }
-
- // migrated from ReflectiveCallerClassUtility
- @PerformanceSensitive
- public Class<?> getCallerClass(final int depth) {
- if (depth < 0) {
- throw new IndexOutOfBoundsException(Integer.toString(depth));
- }
- // slower fallback method using stack trace
- final StackTraceElement element = getStackTraceElement(depth + 1);
- try {
- return LoaderUtil.loadClass(element.getClassName());
- } catch (final ClassNotFoundException e) {
- LOGGER.error("Could not find class in StackLocatorUtil.getCallerClass({}).", depth, e);
- }
- // TODO: return Object.class
- return null;
- }
-
- public StackTraceElement calcLocation(final String fqcnOfLogger) {
- if (fqcnOfLogger == null) {
- return null;
- }
- // LOG4J2-1029 new Throwable().getStackTrace is faster than Thread.currentThread().getStackTrace().
- final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
- StackTraceElement last = null;
- for (int i = stackTrace.length - 1; i > 0; i--) {
- final String className = stackTrace[i].getClassName();
- if (fqcnOfLogger.equals(className)) {
- return last;
- }
- last = stackTrace[i];
- }
- return null;
- }
-
- public StackTraceElement getStackTraceElement(final int depth) {
- // (MS) I tested the difference between using Throwable.getStackTrace() and Thread.getStackTrace(), and
- // the version using Throwable was surprisingly faster! at least on Java 1.8. See ReflectionBenchmark.
- final StackTraceElement[] elements = new Throwable().getStackTrace();
- int i = 0;
- for (final StackTraceElement element : elements) {
- if (isValid(element)) {
- if (i == depth) {
- return element;
- }
- ++i;
- }
- }
- LOGGER.error("Could not find an appropriate StackTraceElement at index {}", depth);
- throw new IndexOutOfBoundsException(Integer.toString(depth));
- }
-
- private boolean isValid(final StackTraceElement element) {
- // ignore native methods (oftentimes are repeated frames)
- if (element.isNativeMethod()) {
- return false;
- }
- final String cn = element.getClassName();
- // ignore OpenJDK internal classes involved with reflective invocation
- if (cn.startsWith("sun.reflect.")) {
- return false;
- }
- final String mn = element.getMethodName();
- // ignore use of reflection including:
- // Method.invoke
- // InvocationHandler.invoke
- // Constructor.newInstance
- if (cn.startsWith("java.lang.reflect.") && (mn.equals("invoke") || mn.equals("newInstance"))) {
- return false;
- }
- // ignore use of Java 1.9+ reflection classes
- if (cn.startsWith("jdk.internal.reflect.")) {
- return false;
- }
- // ignore Class.newInstance
- if (cn.equals("java.lang.Class") && mn.equals("newInstance")) {
- return false;
- }
- // ignore use of Java 1.7+ MethodHandle.invokeFoo() methods
- if (cn.equals("java.lang.invoke.MethodHandle") && mn.startsWith("invoke")) {
- return false;
- }
- // any others?
- return true;
- }
-
- // migrated from ClassLoaderContextSelector
- @PerformanceSensitive
- public Class<?> getCallerClass(final String fqcn) {
- return getCallerClass(fqcn, Strings.EMPTY);
- }
-
- // migrated from Log4jLoggerFactory
- @PerformanceSensitive
- public Class<?> getCallerClass(final String fqcn, final String pkg) {
- if (SECURITY_MANAGER != null) {
- return SECURITY_MANAGER.getCallerClass(fqcn, pkg);
- }
- try {
- return LoaderUtil.loadClass(getCallerClassName(fqcn, pkg, new Throwable().getStackTrace()));
- } catch (final ClassNotFoundException ignored) {
- // no problem really
- }
- // TODO: return Object.class
- return null;
- }
-
- // added for use in LoggerAdapter implementations mainly
- @PerformanceSensitive
- public Class<?> getCallerClass(final Class<?> anchor) {
- if (SECURITY_MANAGER != null) {
- return SECURITY_MANAGER.getCallerClass(anchor);
- }
- try {
- return LoaderUtil.loadClass(getCallerClassName(anchor.getName(), Strings.EMPTY,
- new Throwable().getStackTrace()));
- } catch (final ClassNotFoundException ignored) {
- // no problem really
- }
- return Object.class;
- }
-
- private static String getCallerClassName(final String fqcn, final String pkg, final StackTraceElement... elements) {
- boolean next = false;
- for (final StackTraceElement element : elements) {
- final String className = element.getClassName();
- if (className.equals(fqcn)) {
- next = true;
- continue;
- }
- if (next && className.startsWith(pkg)) {
- return className;
- }
- }
- return Object.class.getName();
- }
-
- // migrated from ThrowableProxy
- @PerformanceSensitive
- public Stack<Class<?>> getCurrentStackTrace() {
- // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int)
- if (SECURITY_MANAGER != null) {
- final Class<?>[] array = SECURITY_MANAGER.getClassContext();
- final Stack<Class<?>> classes = new Stack<>();
- classes.ensureCapacity(array.length);
- for (final Class<?> clazz : array) {
- classes.push(clazz);
- }
- return classes;
- }
- return new Stack<>();
- }
-
- /**
- *
- */
- static final class PrivateSecurityManager extends SecurityManager {
-
- @Override
- protected Class<?>[] getClassContext() {
- return super.getClassContext();
- }
-
- protected Class<?> getCallerClass(final String fqcn, final String pkg) {
- boolean next = false;
- for (final Class<?> clazz : getClassContext()) {
- if (fqcn.equals(clazz.getName())) {
- next = true;
- continue;
- }
- if (next && clazz.getName().startsWith(pkg)) {
- return clazz;
- }
- }
- // TODO: return Object.class
- return null;
- }
-
- protected Class<?> getCallerClass(final Class<?> anchor) {
- boolean next = false;
- for (final Class<?> clazz : getClassContext()) {
- if (anchor.equals(clazz)) {
- next = true;
- continue;
- }
- if (next) {
- return clazz;
- }
- }
- return Object.class;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionStackLocator.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionStackLocator.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionStackLocator.java
deleted file mode 100644
index 961bbfc..0000000
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionStackLocator.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.util;
-
-import java.lang.reflect.Method;
-import java.util.Stack;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * <em>Consider this class private.</em> Provides various methods to determine the caller class. <h3>Background</h3>
- * <p>
- * This method, available only in the Oracle/Sun/OpenJDK implementations of the Java Virtual Machine, is a much more
- * efficient mechanism for determining the {@link Class} of the caller of a particular method. When it is not available,
- * a {@link SecurityManager} is the second-best option. When this is also not possible, the {@code StackTraceElement[]}
- * returned by {@link Throwable#getStackTrace()} must be used, and its {@code String} class name converted to a
- * {@code Class} using the slow {@link Class#forName} (which can add an extra microsecond or more for each invocation
- * depending on the runtime ClassLoader hierarchy).
- * </p>
- * <p>
- * During Java 8 development, the {@code sun.reflect.Reflection.getCallerClass(int)} was removed from OpenJDK, and this
- * change was back-ported to Java 7 in version 1.7.0_25 which changed the behavior of the call and caused it to be off
- * by one stack frame. This turned out to be beneficial for the survival of this API as the change broke hundreds of
- * libraries and frameworks relying on the API which brought much more attention to the intended API removal.
- * </p>
- * <p>
- * After much community backlash, the JDK team agreed to restore {@code getCallerClass(int)} and keep its existing
- * behavior for the rest of Java 7. However, the method is deprecated in Java 8, and current Java 9 development has not
- * addressed this API. Therefore, the functionality of this class cannot be relied upon for all future versions of Java.
- * It does, however, work just fine in Sun JDK 1.6, OpenJDK 1.6, Oracle/OpenJDK 1.7, and Oracle/OpenJDK 1.8. Other Java
- * environments may fall back to using {@link Throwable#getStackTrace()} which is significantly slower due to
- * examination of every virtual frame of execution.
- * </p>
- */
-public final class ReflectionStackLocator extends DefaultStackLocator {
- // Checkstyle Suppress: the lower-case 'u' ticks off CheckStyle...
- // CHECKSTYLE:OFF
- static final int JDK_7u25_OFFSET;
- // CHECKSTYLE:OFF
-
- private static final boolean SUN_REFLECTION_SUPPORTED;
- private static final Method GET_CALLER_CLASS;
-
- private static final ReflectionStackLocator INSTANCE;
-
- static {
- Method getCallerClass;
- int java7u25CompensationOffset = 0;
- try {
- final Class<?> sunReflectionClass = LoaderUtil.loadClass("sun.reflect.Reflection");
- getCallerClass = sunReflectionClass.getDeclaredMethod("getCallerClass", int.class);
- Object o = getCallerClass.invoke(null, 0);
- final Object test1 = getCallerClass.invoke(null, 0);
- if (o == null || o != sunReflectionClass) {
- LOGGER.warn("Unexpected return value from Reflection.getCallerClass(): {}", test1);
- getCallerClass = null;
- java7u25CompensationOffset = -1;
- } else {
- o = getCallerClass.invoke(null, 1);
- if (o == sunReflectionClass) {
- LOGGER.warn("You are using Java 1.7.0_25 which has a broken implementation of "
- + "Reflection.getCallerClass.");
- LOGGER.warn("You should upgrade to at least Java 1.7.0_40 or later.");
- LOGGER.debug("Using stack depth compensation offset of 1 due to Java 7u25.");
- java7u25CompensationOffset = 1;
- }
- }
- } catch (final Exception | LinkageError e) {
- LOGGER.info("sun.reflect.Reflection.getCallerClass is not supported. "
- + "ReflectionUtil.getCallerClass will be much slower due to this.", e);
- getCallerClass = null;
- java7u25CompensationOffset = -1;
- }
-
- SUN_REFLECTION_SUPPORTED = getCallerClass != null;
- GET_CALLER_CLASS = getCallerClass;
- JDK_7u25_OFFSET = java7u25CompensationOffset;
-
- INSTANCE = new ReflectionStackLocator();
- }
-
- public static StackLocator getInstance() {
- return INSTANCE;
- }
-
- private ReflectionStackLocator() {
- }
-
- // TODO: return Object.class instead of null (though it will have a null ClassLoader)
- // (MS) I believe this would work without any modifications elsewhere, but I could be wrong
-
- // migrated from ReflectiveCallerClassUtility
- @PerformanceSensitive
- public Class<?> getCallerClass(final int depth) {
- if (depth < 0) {
- throw new IndexOutOfBoundsException(Integer.toString(depth));
- }
- // note that we need to add 1 to the depth value to compensate for this method, but not for the Method.invoke
- // since Reflection.getCallerClass ignores the call to Method.invoke()
- try {
- return (Class<?>) GET_CALLER_CLASS.invoke(null, depth + 1 + JDK_7u25_OFFSET);
- } catch (final Exception e) {
- // theoretically this could happen if the caller class were native code
- LOGGER.error("Error in ReflectionUtil.getCallerClass({}).", depth, e);
- // TODO: return Object.class
- return null;
- }
- }
-
- // migrated from Log4jLoggerFactory
- @PerformanceSensitive
- public Class<?> getCallerClass(final String fqcn, final String pkg) {
- boolean next = false;
- Class<?> clazz;
- for (int i = 2; null != (clazz = getCallerClass(i)); i++) {
- if (fqcn.equals(clazz.getName())) {
- next = true;
- continue;
- }
- if (next && clazz.getName().startsWith(pkg)) {
- return clazz;
- }
- }
- // TODO: return Object.class
- return null;
- }
-
- // added for use in LoggerAdapter implementations mainly
- @PerformanceSensitive
- public Class<?> getCallerClass(final Class<?> anchor) {
- boolean next = false;
- Class<?> clazz;
- for (int i = 2; null != (clazz = getCallerClass(i)); i++) {
- if (anchor.equals(clazz)) {
- next = true;
- continue;
- }
- if (next) {
- return clazz;
- }
- }
- return Object.class;
- }
-
- // migrated from ThrowableProxy
- @PerformanceSensitive
- public Stack<Class<?>> getCurrentStackTrace() {
- // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int)
- if (getSecurityManager() != null) {
- final Class<?>[] array = getSecurityManager().getClassContext();
- final Stack<Class<?>> classes = new Stack<>();
- classes.ensureCapacity(array.length);
- for (final Class<?> clazz : array) {
- classes.push(clazz);
- }
- return classes;
- }
- // slower version using getCallerClass where we cannot use a SecurityManager
- final Stack<Class<?>> classes = new Stack<>();
- Class<?> clazz;
- for (int i = 1; null != (clazz = getCallerClass(i)); i++) {
- classes.push(clazz);
- }
- return classes;
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java
index 3ae15ef..794001e 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java
@@ -16,24 +16,269 @@
*/
package org.apache.logging.log4j.util;
+import java.lang.reflect.Method;
import java.util.Stack;
/**
- * Interface for methods used to locate information about the caller.
+ * <em>Consider this class private.</em> Provides various methods to determine the caller class. <h3>Background</h3>
+ * <p>
+ * This method, available only in the Oracle/Sun/OpenJDK implementations of the Java Virtual Machine, is a much more
+ * efficient mechanism for determining the {@link Class} of the caller of a particular method. When it is not available,
+ * a {@link SecurityManager} is the second-best option. When this is also not possible, the {@code StackTraceElement[]}
+ * returned by {@link Throwable#getStackTrace()} must be used, and its {@code String} class name converted to a
+ * {@code Class} using the slow {@link Class#forName} (which can add an extra microsecond or more for each invocation
+ * depending on the runtime ClassLoader hierarchy).
+ * </p>
+ * <p>
+ * During Java 8 development, the {@code sun.reflect.Reflection.getCallerClass(int)} was removed from OpenJDK, and this
+ * change was back-ported to Java 7 in version 1.7.0_25 which changed the behavior of the call and caused it to be off
+ * by one stack frame. This turned out to be beneficial for the survival of this API as the change broke hundreds of
+ * libraries and frameworks relying on the API which brought much more attention to the intended API removal.
+ * </p>
+ * <p>
+ * After much community backlash, the JDK team agreed to restore {@code getCallerClass(int)} and keep its existing
+ * behavior for the rest of Java 7. However, the method is deprecated in Java 8, and current Java 9 development has not
+ * addressed this API. Therefore, the functionality of this class cannot be relied upon for all future versions of Java.
+ * It does, however, work just fine in Sun JDK 1.6, OpenJDK 1.6, Oracle/OpenJDK 1.7, and Oracle/OpenJDK 1.8. Other Java
+ * environments may fall back to using {@link Throwable#getStackTrace()} which is significantly slower due to
+ * examination of every virtual frame of execution.
+ * </p>
*/
-public interface StackLocator {
+public final class StackLocator {
- Class<?> getCallerClass(final int depth);
+ private static PrivateSecurityManager SECURITY_MANAGER;
- StackTraceElement getStackTraceElement(final int depth);
+ // Checkstyle Suppress: the lower-case 'u' ticks off CheckStyle...
+ // CHECKSTYLE:OFF
+ static final int JDK_7u25_OFFSET;
+ // CHECKSTYLE:OFF
- Class<?> getCallerClass(final String fqcn);
+ private static final boolean SUN_REFLECTION_SUPPORTED;
+ private static final Method GET_CALLER_CLASS;
- Class<?> getCallerClass(final String fqcn, final String pkg);
+ private static final StackLocator INSTANCE;
- Class<?> getCallerClass(final Class<?> anchor);
+ static {
+ Method getCallerClass;
+ int java7u25CompensationOffset = 0;
+ try {
+ final Class<?> sunReflectionClass = LoaderUtil.loadClass("sun.reflect.Reflection");
+ getCallerClass = sunReflectionClass.getDeclaredMethod("getCallerClass", int.class);
+ Object o = getCallerClass.invoke(null, 0);
+ final Object test1 = getCallerClass.invoke(null, 0);
+ if (o == null || o != sunReflectionClass) {
+ getCallerClass = null;
+ java7u25CompensationOffset = -1;
+ } else {
+ o = getCallerClass.invoke(null, 1);
+ if (o == sunReflectionClass) {
+ System.out.println("WARNING: Java 1.7.0_25 is in use which has a broken implementation of Reflection.getCallerClass(). " +
+ " Plesae consider upgrading to Java 1.7.0_40 or later.");
+ java7u25CompensationOffset = 1;
+ }
+ }
+ } catch (final Exception | LinkageError e) {
+ System.out.println("WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.");
+ getCallerClass = null;
+ java7u25CompensationOffset = -1;
+ }
- Stack<Class<?>> getCurrentStackTrace();
+ SUN_REFLECTION_SUPPORTED = getCallerClass != null;
+ GET_CALLER_CLASS = getCallerClass;
+ JDK_7u25_OFFSET = java7u25CompensationOffset;
- StackTraceElement calcLocation(final String fqcnOfLogger);
+ INSTANCE = new StackLocator();
+ }
+
+ public static StackLocator getInstance() {
+ return INSTANCE;
+ }
+
+ private StackLocator() {
+ }
+
+ // TODO: return Object.class instead of null (though it will have a null ClassLoader)
+ // (MS) I believe this would work without any modifications elsewhere, but I could be wrong
+
+ // migrated from ReflectiveCallerClassUtility
+ @PerformanceSensitive
+ public Class<?> getCallerClass(final int depth) {
+ if (depth < 0) {
+ throw new IndexOutOfBoundsException(Integer.toString(depth));
+ }
+ // note that we need to add 1 to the depth value to compensate for this method, but not for the Method.invoke
+ // since Reflection.getCallerClass ignores the call to Method.invoke()
+ try {
+ return (Class<?>) GET_CALLER_CLASS.invoke(null, depth + 1 + JDK_7u25_OFFSET);
+ } catch (final Exception e) {
+ // theoretically this could happen if the caller class were native code
+ // TODO: return Object.class
+ return null;
+ }
+ }
+
+ // migrated from Log4jLoggerFactory
+ @PerformanceSensitive
+ public Class<?> getCallerClass(final String fqcn, final String pkg) {
+ boolean next = false;
+ Class<?> clazz;
+ for (int i = 2; null != (clazz = getCallerClass(i)); i++) {
+ if (fqcn.equals(clazz.getName())) {
+ next = true;
+ continue;
+ }
+ if (next && clazz.getName().startsWith(pkg)) {
+ return clazz;
+ }
+ }
+ // TODO: return Object.class
+ return null;
+ }
+
+ // added for use in LoggerAdapter implementations mainly
+ @PerformanceSensitive
+ public Class<?> getCallerClass(final Class<?> anchor) {
+ boolean next = false;
+ Class<?> clazz;
+ for (int i = 2; null != (clazz = getCallerClass(i)); i++) {
+ if (anchor.equals(clazz)) {
+ next = true;
+ continue;
+ }
+ if (next) {
+ return clazz;
+ }
+ }
+ return Object.class;
+ }
+
+ // migrated from ThrowableProxy
+ @PerformanceSensitive
+ public Stack<Class<?>> getCurrentStackTrace() {
+ // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int)
+ if (getSecurityManager() != null) {
+ final Class<?>[] array = getSecurityManager().getClassContext();
+ final Stack<Class<?>> classes = new Stack<>();
+ classes.ensureCapacity(array.length);
+ for (final Class<?> clazz : array) {
+ classes.push(clazz);
+ }
+ return classes;
+ }
+ // slower version using getCallerClass where we cannot use a SecurityManager
+ final Stack<Class<?>> classes = new Stack<>();
+ Class<?> clazz;
+ for (int i = 1; null != (clazz = getCallerClass(i)); i++) {
+ classes.push(clazz);
+ }
+ return classes;
+ }
+
+ public StackTraceElement calcLocation(final String fqcnOfLogger) {
+ if (fqcnOfLogger == null) {
+ return null;
+ }
+ // LOG4J2-1029 new Throwable().getStackTrace is faster than Thread.currentThread().getStackTrace().
+ final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
+ StackTraceElement last = null;
+ for (int i = stackTrace.length - 1; i > 0; i--) {
+ final String className = stackTrace[i].getClassName();
+ if (fqcnOfLogger.equals(className)) {
+ return last;
+ }
+ last = stackTrace[i];
+ }
+ return null;
+ }
+
+ public StackTraceElement getStackTraceElement(final int depth) {
+ // (MS) I tested the difference between using Throwable.getStackTrace() and Thread.getStackTrace(), and
+ // the version using Throwable was surprisingly faster! at least on Java 1.8. See ReflectionBenchmark.
+ final StackTraceElement[] elements = new Throwable().getStackTrace();
+ int i = 0;
+ for (final StackTraceElement element : elements) {
+ if (isValid(element)) {
+ if (i == depth) {
+ return element;
+ }
+ ++i;
+ }
+ }
+ throw new IndexOutOfBoundsException(Integer.toString(depth));
+ }
+
+ private boolean isValid(final StackTraceElement element) {
+ // ignore native methods (oftentimes are repeated frames)
+ if (element.isNativeMethod()) {
+ return false;
+ }
+ final String cn = element.getClassName();
+ // ignore OpenJDK internal classes involved with reflective invocation
+ if (cn.startsWith("sun.reflect.")) {
+ return false;
+ }
+ final String mn = element.getMethodName();
+ // ignore use of reflection including:
+ // Method.invoke
+ // InvocationHandler.invoke
+ // Constructor.newInstance
+ if (cn.startsWith("java.lang.reflect.") && (mn.equals("invoke") || mn.equals("newInstance"))) {
+ return false;
+ }
+ // ignore use of Java 1.9+ reflection classes
+ if (cn.startsWith("jdk.internal.reflect.")) {
+ return false;
+ }
+ // ignore Class.newInstance
+ if (cn.equals("java.lang.Class") && mn.equals("newInstance")) {
+ return false;
+ }
+ // ignore use of Java 1.7+ MethodHandle.invokeFoo() methods
+ if (cn.equals("java.lang.invoke.MethodHandle") && mn.startsWith("invoke")) {
+ return false;
+ }
+ // any others?
+ return true;
+ }
+
+ protected PrivateSecurityManager getSecurityManager() {
+ return SECURITY_MANAGER;
+ }
+
+ private static final class PrivateSecurityManager extends SecurityManager {
+
+ @Override
+ protected Class<?>[] getClassContext() {
+ return super.getClassContext();
+ }
+
+ protected Class<?> getCallerClass(final String fqcn, final String pkg) {
+ boolean next = false;
+ for (final Class<?> clazz : getClassContext()) {
+ if (fqcn.equals(clazz.getName())) {
+ next = true;
+ continue;
+ }
+ if (next && clazz.getName().startsWith(pkg)) {
+ return clazz;
+ }
+ }
+ // TODO: return Object.class
+ return null;
+ }
+
+ protected Class<?> getCallerClass(final Class<?> anchor) {
+ boolean next = false;
+ for (final Class<?> clazz : getClassContext()) {
+ if (anchor.equals(clazz)) {
+ next = true;
+ continue;
+ }
+ if (next) {
+ return clazz;
+ }
+ }
+ return Object.class;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java
index 855103e..56812fe 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java
@@ -25,31 +25,7 @@ public final class StackLocatorUtil {
private static StackLocator stackLocator = null;
static {
- try {
- final Class<?> stackLocatorClass = LoaderUtil.loadClass("org.apache.logging.log4j.util.StackWalkerStackLocator");
- stackLocator = (StackLocator) stackLocatorClass.newInstance();
- } catch (NoClassDefFoundError e) {
- // Ignore this error.
- } catch (ClassNotFoundException e) {
- // Ignore this exception.
- } catch (InstantiationException e) {
- // Ignore this exception.
- } catch (IllegalAccessException e) {
- // Ignore this exception.
- } catch (UnsupportedClassVersionError e) {
- // Ignore this error.
- }
- if (stackLocator == null) {
- try {
- final Class<?> stackLocatorClass = LoaderUtil.loadClass("sun.reflect.Reflection");
- stackLocator = ReflectionStackLocator.getInstance();
- } catch (ClassNotFoundException cnfe) {
- // Ignore this exception.
- }
- }
- if (stackLocator == null) {
- stackLocator = new DefaultStackLocator();
- }
+ stackLocator = StackLocator.getInstance();
}
private StackLocatorUtil() {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/src/main/java9/org/apache/logging/log4j/util/ClassNamePredicate.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java9/org/apache/logging/log4j/util/ClassNamePredicate.java b/log4j-api/src/main/java9/org/apache/logging/log4j/util/ClassNamePredicate.java
deleted file mode 100644
index 063e538..0000000
--- a/log4j-api/src/main/java9/org/apache/logging/log4j/util/ClassNamePredicate.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.util;
-
-import java.util.function.Predicate;
-
-/**
- * <em>This class should be considered to be internal.</em> Used to locate the StackFrame that called the named class.
- */
-public final class ClassNamePredicate implements Predicate<StackWalker.StackFrame> {
-
- private final String fqcn;
-
- public ClassNamePredicate(String fqcn) {
- this.fqcn = fqcn;
- }
-
- private boolean next = false;
-
- @Override
- public boolean test(StackWalker.StackFrame f) {
- if (fqcn.equals(f.getClassName())) {
- next = true;
- return false;
- } else if (next) {
- next = false;
- return true;
- }
- return false;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/src/main/java9/org/apache/logging/log4j/util/ClassPredicate.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java9/org/apache/logging/log4j/util/ClassPredicate.java b/log4j-api/src/main/java9/org/apache/logging/log4j/util/ClassPredicate.java
deleted file mode 100644
index 3f8d15a..0000000
--- a/log4j-api/src/main/java9/org/apache/logging/log4j/util/ClassPredicate.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.util;
-
-import java.util.function.Predicate;
-
-/**
- * <em>This class should be considered to be internal.</em> Used to locate the StackFrame that called the named class.
- */
-
-public final class ClassPredicate implements Predicate<StackWalker.StackFrame> {
-
- private final Class<?> clazz;
-
- public ClassPredicate(Class<?> clazz) {
- this.clazz = clazz;
- }
-
- private boolean next = false;
-
- @Override
- public boolean test(StackWalker.StackFrame f) {
- if (clazz.equals(f.getDeclaringClass())) {
- next = true;
- return false;
- } else if (next) {
- next = false;
- return true;
- }
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/src/main/java9/org/apache/logging/log4j/util/StackWalkerStackLocator.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java9/org/apache/logging/log4j/util/StackWalkerStackLocator.java b/log4j-api/src/main/java9/org/apache/logging/log4j/util/StackWalkerStackLocator.java
deleted file mode 100644
index dc10fef..0000000
--- a/log4j-api/src/main/java9/org/apache/logging/log4j/util/StackWalkerStackLocator.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.util;
-
-import java.util.List;
-import java.util.Stack;
-import java.util.stream.Collectors;
-
-/**
- * <em>Consider this class private.</em> Determines the caller's class.
- */
-public class StackWalkerStackLocator implements StackLocator {
-
- private final static StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
-
- private final static StackWalker stackWalker = StackWalker.getInstance();
-
- public Class<?> getCallerClass(final String fqcn) {
- return getCallerClass(fqcn, "");
- }
-
- public Class<?> getCallerClass(final String fqcn, final String pkg) {
- return walker.walk(s -> s.filter(new ClassNamePredicate(fqcn)).findFirst()).get().getDeclaringClass();
- }
-
- public Class<?> getCallerClass(final Class<?> anchor) {
- return walker.walk(s -> s.filter(new ClassPredicate(anchor)).findFirst()).get().getDeclaringClass();
- }
-
- public Class<?> getCallerClass(final int depth) {
- ;
- return walker.walk(s -> s.skip(depth).findFirst()).get().getDeclaringClass();
- }
-
- public Stack<Class<?>> getCurrentStackTrace() {
- Stack<Class<?>> stack = new Stack<Class<?>>();
- List<Class<?>> classes = walker.walk(s -> s.map(f -> f.getDeclaringClass()).collect(Collectors.toList()));
- stack.addAll(classes);
- return stack;
- }
-
- public StackTraceElement calcLocation(final String fqcnOfLogger) {
- return stackWalker.walk(s -> s.filter(new ClassNamePredicate(fqcnOfLogger)).findFirst()).get().toStackTraceElement();
- }
-
- public StackTraceElement getStackTraceElement(final int depth) {
- return stackWalker.walk(s -> s.skip(depth).findFirst()).get().toStackTraceElement();
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-api/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
index dd8285e..c3d7705 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
@@ -18,7 +18,6 @@ package org.apache.logging.log4j.util;
import java.util.Stack;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
@@ -35,7 +34,7 @@ public class StackLocatorUtilTest {
@Test
public void testStackTraceEquivalence() throws Exception {
for (int i = 1; i < 15; i++) {
- final Class<?> expected = Reflection.getCallerClass(i + ReflectionStackLocator.JDK_7u25_OFFSET);
+ final Class<?> expected = Reflection.getCallerClass(i + StackLocator.JDK_7u25_OFFSET);
final Class<?> actual = StackLocatorUtil.getCallerClass(i);
final Class<?> fallbackActual = Class.forName(
StackLocatorUtil.getStackTraceElement(i).getClassName());
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-core-its/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-core-its/pom.xml b/log4j-core-its/pom.xml
index 0f0a3f3..f46596c 100644
--- a/log4j-core-its/pom.xml
+++ b/log4j-core-its/pom.xml
@@ -105,14 +105,6 @@
</dependency>
<!-- TEST DEPENDENCIES -->
-
- <!-- Pull in useful test classes from API -->
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
<!-- Log4j 1.2 tests -->
<dependency>
<groupId>log4j</groupId>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-distribution/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-distribution/pom.xml b/log4j-distribution/pom.xml
index e77e883..05b8019 100644
--- a/log4j-distribution/pom.xml
+++ b/log4j-distribution/pom.xml
@@ -300,11 +300,7 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
- <!-- As the main Apache pom only builds source zip archives but
- commons wants both zip and tar.gz and because this is configured
- in the assembly, we need to use a specific assembly. That also allows
- naming the final artifact as -src not -source-release.
- -->
+
<execution>
<id>log4j2-source-release-assembly</id>
<phase>package</phase>
@@ -358,6 +354,14 @@
<skipDeploy>true</skipDeploy>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-perf/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-perf/pom.xml b/log4j-perf/pom.xml
index 11ecc82..81959f4 100644
--- a/log4j-perf/pom.xml
+++ b/log4j-perf/pom.xml
@@ -216,6 +216,14 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-samples/configuration/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/configuration/pom.xml b/log4j-samples/configuration/pom.xml
index 048167f..5c13396 100644
--- a/log4j-samples/configuration/pom.xml
+++ b/log4j-samples/configuration/pom.xml
@@ -50,6 +50,14 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-samples/flume-common/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/flume-common/pom.xml b/log4j-samples/flume-common/pom.xml
index 0441031..f56c0ce 100644
--- a/log4j-samples/flume-common/pom.xml
+++ b/log4j-samples/flume-common/pom.xml
@@ -71,6 +71,14 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-samples/flume-embedded/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/flume-embedded/pom.xml b/log4j-samples/flume-embedded/pom.xml
index a2f28c2..08ff472 100644
--- a/log4j-samples/flume-embedded/pom.xml
+++ b/log4j-samples/flume-embedded/pom.xml
@@ -138,6 +138,14 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55b9fd20/log4j-samples/flume-remote/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/flume-remote/pom.xml b/log4j-samples/flume-remote/pom.xml
index e4b5731..05d605e 100644
--- a/log4j-samples/flume-remote/pom.xml
+++ b/log4j-samples/flume-remote/pom.xml
@@ -126,6 +126,14 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>