summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-11-24 23:11:36 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-11-24 23:12:08 +0100
commit75c716f5d7cdb0f4978c42a4dcae6c6ee4dcb42d (patch)
tree91bcf5b47bbef0a88acad5c6bbe32fdbd8a9b1d4
parentc05d711bb757b0e2705bb22b9710b6be6eb37d99 (diff)
downloadjgit-75c716f5d7cdb0f4978c42a4dcae6c6ee4dcb42d.tar.gz
jgit-75c716f5d7cdb0f4978c42a4dcae6c6ee4dcb42d.zip
Implement RecordingLogger based on org.slf4j.Logger
Jetty 10 uses slf4j for logging and deprecated its own Logger interface org.eclipse.jetty.util.log.Logger. Change-Id: I1b0c3a23e43190a50987175973725c3ad6e32f5f
-rw-r--r--org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java198
2 files changed, 97 insertions, 104 deletions
diff --git a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF
index 6be5cdd09e..4e4a549579 100644
--- a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF
@@ -29,7 +29,8 @@ Import-Package: javax.servlet;version="[2.5.0,5.0.0)",
org.eclipse.jgit.revwalk;version="[6.0.0,6.1.0)",
org.eclipse.jgit.transport;version="[6.0.0,6.1.0)",
org.eclipse.jgit.transport.resolver;version="[6.0.0,6.1.0)",
- org.junit;version="[4.13,5.0.0)"
+ org.junit;version="[4.13,5.0.0)",
+ org.slf4j.helpers;version="[1.7.0,2.0.0)"
Export-Package: org.eclipse.jgit.junit.http;version="6.0.0";
uses:="org.eclipse.jgit.transport,
org.eclipse.jgit.junit,
diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java
index d2ef733d74..9c3c980ad8 100644
--- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java
+++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, Google Inc. and others
+ * Copyright (C) 2010, 2021 Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -7,7 +7,6 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-
package org.eclipse.jgit.junit.http;
import java.text.MessageFormat;
@@ -15,12 +14,12 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.eclipse.jetty.util.log.Logger;
+import org.slf4j.helpers.MarkerIgnoringBase;
+
+public class RecordingLogger extends MarkerIgnoringBase {
+
+ private static final long serialVersionUID = 1L;
-/**
- * Log warnings into an array for later inspection.
- */
-public class RecordingLogger implements Logger {
private static List<Warning> warnings = new ArrayList<>();
/**
@@ -60,8 +59,6 @@ public class RecordingLogger implements Logger {
}
}
- private final String name;
-
/**
* Constructor for <code>RecordingLogger</code>.
*/
@@ -78,171 +75,166 @@ public class RecordingLogger implements Logger {
this.name = name;
}
- /** {@inheritDoc} */
@Override
- public Logger getLogger(@SuppressWarnings("hiding") String name) {
- return new RecordingLogger(name);
+ public boolean isTraceEnabled() {
+ // Ignore (not relevant to test failures)
+ return false;
}
- /** {@inheritDoc} */
@Override
- public String getName() {
- return name;
+ public void trace(String msg) {
+ // Ignore (not relevant to test failures)
}
- /**
- * Warning
- *
- * @param msg
- * @param arg0
- * @param arg1
- */
- public void warn(String msg, Object arg0, Object arg1) {
- synchronized (warnings) {
- warnings.add(new Warning(MessageFormat.format(msg, arg0, arg1)));
- }
+ @Override
+ public void trace(String format, Object arg) {
+ // Ignore (not relevant to test failures)
}
- /** {@inheritDoc} */
@Override
- public void warn(String msg, Throwable th) {
- synchronized (warnings) {
- warnings.add(new Warning(msg, th));
- }
+ public void trace(String format, Object arg1, Object arg2) {
+ // Ignore (not relevant to test failures)
}
- /**
- * Warning
- *
- * @param msg
- * warning message
- */
- public void warn(String msg) {
- synchronized (warnings) {
- warnings.add(new Warning(msg));
- }
+ @Override
+ public void trace(String format, Object... arguments) {
+ // Ignore (not relevant to test failures)
}
- /**
- * Debug log
- *
- * @param msg
- * @param arg0
- * @param arg1
- */
- public void debug(String msg, Object arg0, Object arg1) {
+ @Override
+ public void trace(String msg, Throwable t) {
// Ignore (not relevant to test failures)
}
- /** {@inheritDoc} */
@Override
- public void debug(String msg, Throwable th) {
- // Ignore (not relevant to test failures)
+ public boolean isDebugEnabled() {
+ return false;
}
- /**
- * Debug log
- *
- * @param msg
- * debug message
- */
+ @Override
public void debug(String msg) {
// Ignore (not relevant to test failures)
}
- /**
- * Info
- *
- * @param msg
- * @param arg0
- * @param arg1
- */
- public void info(String msg, Object arg0, Object arg1) {
+ @Override
+ public void debug(String format, Object arg) {
// Ignore (not relevant to test failures)
}
- /**
- * Info
- *
- * @param msg
- */
- public void info(String msg) {
+ @Override
+ public void debug(String format, Object arg1, Object arg2) {
// Ignore (not relevant to test failures)
}
- /** {@inheritDoc} */
@Override
- public boolean isDebugEnabled() {
+ public void debug(String format, Object... arguments) {
+ // Ignore (not relevant to test failures)
+ }
+
+ @Override
+ public void debug(String msg, Throwable t) {
+ // Ignore (not relevant to test failures)
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
return false;
}
- /** {@inheritDoc} */
@Override
- public void setDebugEnabled(boolean enabled) {
+ public void info(String msg) {
+ // Ignore (not relevant to test failures)
+ }
+
+ @Override
+ public void info(String format, Object arg) {
+ // Ignore (not relevant to test failures)
+ }
+
+ @Override
+ public void info(String format, Object arg1, Object arg2) {
+ // Ignore (not relevant to test failures)
+ }
+
+ @Override
+ public void info(String format, Object... arguments) {
+ // Ignore (not relevant to test failures)
+ }
+
+ @Override
+ public void info(String msg, Throwable t) {
// Ignore (not relevant to test failures)
}
- /** {@inheritDoc} */
@Override
- public void warn(String msg, Object... args) {
+ public boolean isWarnEnabled() {
+ return true;
+ }
+
+ @Override
+ public void warn(String msg) {
+ synchronized (warnings) {
+ warnings.add(new Warning(msg));
+ }
+ }
+
+ @Override
+ public void warn(String format, Object arg) {
+ warn(format, Collections.singleton(arg));
+ }
+
+ @Override
+ public void warn(String format, Object... arguments) {
synchronized (warnings) {
int i = 0;
- int index = msg.indexOf("{}");
+ int index = format.indexOf("{}");
while (index >= 0) {
- msg = msg.replaceFirst("\\{\\}", "{" + i++ + "}");
- index = msg.indexOf("{}");
+ format = format.replaceFirst("\\{\\}", "{" + i++ + "}");
+ index = format.indexOf("{}");
}
- warnings.add(new Warning(MessageFormat.format(msg, args)));
+ warnings.add(new Warning(MessageFormat.format(format, arguments)));
}
}
- /** {@inheritDoc} */
@Override
- public void warn(Throwable thrown) {
- synchronized (warnings) {
- warnings.add(new Warning(thrown));
- }
+ public void warn(String format, Object arg1, Object arg2) {
+ warn(format, new Object[] { arg1, arg2 });
}
- /** {@inheritDoc} */
@Override
- public void info(String msg, Object... args) {
- // Ignore (not relevant to test failures)
+ public void warn(String msg, Throwable t) {
+ synchronized (warnings) {
+ warnings.add(new Warning(msg, t));
+ }
}
- /** {@inheritDoc} */
@Override
- public void info(Throwable thrown) {
- // Ignore (not relevant to test failures)
+ public boolean isErrorEnabled() {
+ return false;
}
- /** {@inheritDoc} */
@Override
- public void info(String msg, Throwable thrown) {
+ public void error(String msg) {
// Ignore (not relevant to test failures)
}
- /** {@inheritDoc} */
@Override
- public void debug(String msg, Object... args) {
+ public void error(String format, Object arg) {
// Ignore (not relevant to test failures)
}
- /** {@inheritDoc} */
@Override
- public void debug(Throwable thrown) {
+ public void error(String format, Object arg1, Object arg2) {
// Ignore (not relevant to test failures)
}
- /** {@inheritDoc} */
@Override
- public void ignore(Throwable arg0) {
+ public void error(String format, Object... arguments) {
// Ignore (not relevant to test failures)
}
- /** {@inheritDoc} */
@Override
- public void debug(String msg, long value) {
+ public void error(String msg, Throwable t) {
// Ignore (not relevant to test failures)
}
}
an class="k">new RepositoryNotFoundException(name); Repository db = exports.get(StringUtils.nameWithDotGit(name)); if (db != null) { db.incrementOpen(); return db; } for (File base : exportBase) { File dir = FileKey.resolve(new File(base, name), FS.DETECTED); if (dir == null) continue; try { FileKey key = FileKey.exact(dir, FS.DETECTED); db = RepositoryCache.open(key, true); } catch (IOException e) { throw new RepositoryNotFoundException(name, e); } try { if (isExportOk(req, name, db)) { // We have to leak the open count to the caller, they // are responsible for closing the repository if we // complete successfully. return db; } throw new ServiceNotEnabledException(); } catch (RuntimeException | IOException e) { db.close(); throw new RepositoryNotFoundException(name, e); } catch (ServiceNotEnabledException e) { db.close(); throw e; } } if (exportBase.size() == 1) { File dir = new File(exportBase.iterator().next(), name); throw new RepositoryNotFoundException(name, new RepositoryNotFoundException(dir)); } throw new RepositoryNotFoundException(name); } /** * Whether <code>git-daemon-export-ok</code> is required to export a * repository * * @return false if <code>git-daemon-export-ok</code> is required to export * a repository; true if <code>git-daemon-export-ok</code> is * ignored. * @see #setExportAll(boolean) */ public boolean isExportAll() { return exportAll; } /** * Set whether or not to export all repositories. * <p> * If false (the default), repositories must have a * <code>git-daemon-export-ok</code> file to be accessed through this * daemon. * <p> * If true, all repositories are available through the daemon, whether or * not <code>git-daemon-export-ok</code> exists. * * @param export a boolean. */ public void setExportAll(boolean export) { exportAll = export; } /** * Add a single repository to the set that is exported by this daemon. * <p> * The existence (or lack-thereof) of <code>git-daemon-export-ok</code> is * ignored by this method. The repository is always published. * * @param name * name the repository will be published under. * @param db * the repository instance. */ public void exportRepository(String name, Repository db) { exports.put(StringUtils.nameWithDotGit(name), db); } /** * Recursively export all Git repositories within a directory. * * @param dir * the directory to export. This directory must not itself be a * git repository, but any directory below it which has a file * named <code>git-daemon-export-ok</code> will be published. */ public void exportDirectory(File dir) { exportBase.add(dir); } /** * Check if this repository can be served. * <p> * The default implementation of this method returns true only if either * {@link #isExportAll()} is true, or the {@code git-daemon-export-ok} file * is present in the repository's directory. * * @param req * the current HTTP request. * @param repositoryName * name of the repository, as present in the URL. * @param db * the opened repository instance. * @return true if the repository is accessible; false if not. * @throws java.io.IOException * the repository could not be accessed, the caller will claim * the repository does not exist. */ protected boolean isExportOk(C req, String repositoryName, Repository db) throws IOException { if (isExportAll()) return true; else if (db.getDirectory() != null) return new File(db.getDirectory(), "git-daemon-export-ok").exists(); //$NON-NLS-1$ else return false; } private static boolean isUnreasonableName(String name) { if (name.length() == 0) return true; // no empty paths if (name.indexOf('\\') >= 0) return true; // no windows/dos style paths if (new File(name).isAbsolute()) return true; // no absolute paths if (name.startsWith("../")) //$NON-NLS-1$ return true; // no "l../etc/passwd" if (name.contains("/../")) //$NON-NLS-1$ return true; // no "foo/../etc/passwd" if (name.contains("/./")) //$NON-NLS-1$ return true; // "foo/./foo" is insane to ask if (name.contains("//")) //$NON-NLS-1$ return true; // double slashes is sloppy, don't use it return false; // is a reasonable name } }