-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently a warning of the resolver might be printed multiple times to the log because we call the resolver for each registered environment. This adds a duplication filtering on the log message that each message is only printed once per project.
- Loading branch information
Showing
4 changed files
with
136 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
tycho-core/src/main/java/org/eclipse/tycho/osgi/configuration/FilteringMavenLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.osgi.configuration; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.LegacySupport; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
import org.codehaus.plexus.component.annotations.Requirement; | ||
import org.codehaus.plexus.logging.Logger; | ||
import org.eclipse.tycho.core.shared.MavenLogger; | ||
|
||
/** | ||
* A logger that filters duplicate messages from the output, each message is only printed once | ||
*/ | ||
@Component(role = MavenLogger.class, hint = FilteringMavenLogger.HINT) | ||
public class FilteringMavenLogger implements MavenLogger { | ||
|
||
static final String HINT = "filtering"; | ||
|
||
@Requirement | ||
private LegacySupport legacySupport; | ||
|
||
@Requirement | ||
private Logger logger; | ||
|
||
private Map<MavenProject, Set<LogKey>> messageLogMap = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void error(String message, Throwable cause) { | ||
if (logger.isErrorEnabled() && mustLog(message, cause, 1)) { | ||
logger.error(message, cause); | ||
} | ||
} | ||
|
||
private boolean mustLog(String message, Throwable cause, int type) { | ||
if (legacySupport == null) { | ||
return true; | ||
} | ||
MavenSession session = legacySupport.getSession(); | ||
if (session == null) { | ||
return true; | ||
} | ||
MavenProject project = session.getCurrentProject(); | ||
if (project == null) { | ||
return true; | ||
} | ||
LogKey logKey; | ||
if (cause == null) { | ||
logKey = new LogKey(message, "", type); | ||
} else { | ||
logKey = new LogKey(message, cause.toString(), type); | ||
} | ||
return messageLogMap.computeIfAbsent(project, p -> ConcurrentHashMap.newKeySet()).add(logKey); | ||
} | ||
|
||
@Override | ||
public void warn(String message, Throwable cause) { | ||
if (logger.isWarnEnabled() && mustLog(message, cause, 2)) { | ||
logger.warn(message, cause); | ||
} | ||
} | ||
|
||
@Override | ||
public void info(String message) { | ||
if (logger.isInfoEnabled() && mustLog(message, null, 3)) { | ||
logger.info(message); | ||
} | ||
} | ||
|
||
@Override | ||
public void debug(String message, Throwable cause) { | ||
if (logger.isDebugEnabled() && mustLog(message, cause, 4)) { | ||
logger.warn(message, cause); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isDebugEnabled() { | ||
return logger.isDebugEnabled(); | ||
} | ||
|
||
@Override | ||
public <T> T adapt(Class<T> adapt) { | ||
if (adapt == Logger.class) { | ||
return adapt.cast(logger); | ||
} | ||
return null; | ||
} | ||
|
||
private static final record LogKey(String msg, String t, int type) { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters