Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/replace plexus abstract log enabled with slf4j #1917

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.RequestTrace;
Expand All @@ -52,7 +51,7 @@
*/
@Named
@Deprecated
public class DefaultArtifactDeployer extends AbstractLogEnabled implements ArtifactDeployer {
public class DefaultArtifactDeployer implements ArtifactDeployer {

@Inject
private RepositorySystem repoSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.RequestTrace;
Expand All @@ -49,7 +48,7 @@
@Named
@Singleton
@Deprecated
public class DefaultArtifactInstaller extends AbstractLogEnabled implements ArtifactInstaller {
public class DefaultArtifactInstaller implements ArtifactInstaller {

@Inject
private RepositorySystem repoSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@
import org.apache.maven.repository.legacy.WagonManager;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*/
@Named
@Singleton
@Deprecated
public class DefaultRepositoryMetadataManager extends AbstractLogEnabled implements RepositoryMetadataManager {
public class DefaultRepositoryMetadataManager implements RepositoryMetadataManager {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRepositoryMetadataManager.class);

@Inject
private WagonManager wagonManager;

Expand Down Expand Up @@ -91,33 +94,31 @@ public void resolve(RepositoryMetadata metadata, RepositoryRequest request)
if (!policy.isEnabled()) {
update = false;

if (getLogger().isDebugEnabled()) {
getLogger()
.debug("Skipping update check for " + metadata.getKey() + " (" + file
+ ") from disabled repository " + repository.getId() + " ("
+ repository.getUrl() + ")");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Skipping update check for " + metadata.getKey() + " (" + file
+ ") from disabled repository " + repository.getId() + " ("
+ repository.getUrl() + ")");
}
} else if (request.isForceUpdate()) {
update = true;
} else if (localCopyLastModified != null && !policy.checkOutOfDate(localCopyLastModified)) {
update = false;

if (getLogger().isDebugEnabled()) {
getLogger()
.debug("Skipping update check for " + metadata.getKey() + " (" + file
+ ") from repository " + repository.getId() + " (" + repository.getUrl()
+ ") in favor of local copy");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Skipping update check for " + metadata.getKey() + " (" + file
+ ") from repository " + repository.getId() + " (" + repository.getUrl()
+ ") in favor of local copy");
}
} else {
update = updateCheckManager.isUpdateRequired(metadata, repository, file);
}

if (update) {
getLogger().info(metadata.getKey() + ": checking for updates from " + repository.getId());
LOGGER.info(metadata.getKey() + ": checking for updates from " + repository.getId());
try {
wagonManager.getArtifactMetadata(metadata, repository, file, policy.getChecksumPolicy());
} catch (ResourceDoesNotExistException e) {
getLogger().debug(metadata + " could not be found on repository: " + repository.getId());
LOGGER.debug(metadata + " could not be found on repository: " + repository.getId());

// delete the local copy so the old details aren't used.
if (file.exists()) {
Expand All @@ -132,10 +133,9 @@ public void resolve(RepositoryMetadata metadata, RepositoryRequest request)
}
}
} catch (TransferFailedException e) {
getLogger()
.warn(metadata + " could not be retrieved from repository: " + repository.getId()
+ " due to an error: " + e.getMessage());
getLogger().debug("Exception", e);
LOGGER.warn(metadata + " could not be retrieved from repository: " + repository.getId()
+ " due to an error: " + e.getMessage());
LOGGER.debug("Exception", e);
} finally {
updateCheckManager.touch(metadata, repository, file);
}
Expand Down Expand Up @@ -243,10 +243,10 @@ private boolean loadMetadata(
try {
metadata = readMetadata(metadataFile);
} catch (RepositoryMetadataReadException e) {
if (getLogger().isDebugEnabled()) {
getLogger().warn(e.getMessage(), e);
if (LOGGER.isDebugEnabled()) {
LOGGER.warn(e.getMessage(), e);
} else {
getLogger().warn(e.getMessage());
LOGGER.warn(e.getMessage());
}
return setRepository;
}
Expand Down Expand Up @@ -294,28 +294,27 @@ private void fixTimestamp(File metadataFile, Metadata metadata, Metadata referen
String lastUpdated = versioning.getLastUpdated();
String now = versioningRef.getLastUpdated();
if (lastUpdated != null && now != null && now.compareTo(lastUpdated) < 0) {
getLogger()
.warn("The last updated timestamp in " + metadataFile + " refers to the future (now = "
+ now
+ ", lastUpdated = " + lastUpdated + "). Please verify that the clocks of all"
+ " deploying machines are reasonably synchronized.");
LOGGER.warn("The last updated timestamp in " + metadataFile + " refers to the future (now = "
+ now
+ ", lastUpdated = " + lastUpdated + "). Please verify that the clocks of all"
+ " deploying machines are reasonably synchronized.");
versioning.setLastUpdated(now);
changed = true;
}
}
}

if (changed) {
getLogger().debug("Repairing metadata in " + metadataFile);
LOGGER.debug("Repairing metadata in " + metadataFile);

try (OutputStream out = Files.newOutputStream(metadataFile.toPath())) {
new MetadataStaxWriter().write(out, metadata.getDelegate());
} catch (IOException | XMLStreamException e) {
String msg = "Could not write fixed metadata to " + metadataFile + ": " + e.getMessage();
if (getLogger().isDebugEnabled()) {
getLogger().warn(msg, e);
if (LOGGER.isDebugEnabled()) {
LOGGER.warn(msg, e);
} else {
getLogger().warn(msg);
LOGGER.warn(msg);
}
}
}
Expand Down Expand Up @@ -354,9 +353,8 @@ private File getArtifactMetadataFromDeploymentRepository(
wagonManager.getArtifactMetadataFromDeploymentRepository(
metadata, remoteRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
} catch (ResourceDoesNotExistException e) {
getLogger()
.info(metadata + " could not be found on repository: " + remoteRepository.getId()
+ ", so will be created");
LOGGER.info(metadata + " could not be found on repository: " + remoteRepository.getId()
+ ", so will be created");

// delete the local copy so the old details aren't used.
if (file.exists()) {
Expand All @@ -383,7 +381,7 @@ public void deploy(
throws RepositoryMetadataDeploymentException {
File file;
if (metadata instanceof RepositoryMetadata) {
getLogger().info("Retrieving previous metadata from " + deploymentRepository.getId());
LOGGER.info("Retrieving previous metadata from " + deploymentRepository.getId());
try {
file = getArtifactMetadataFromDeploymentRepository(metadata, localRepository, deploymentRepository);
} catch (TransferFailedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@
import org.codehaus.plexus.interpolation.PrefixedValueSourceWrapper;
import org.codehaus.plexus.interpolation.RecursionInterceptor;
import org.codehaus.plexus.interpolation.ValueSource;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Use a regular expression search to find and resolve expressions within the POM.
*
* TODO Consolidate this logic with the PluginParameterExpressionEvaluator, minus deprecations/bans.
*/
@Deprecated
public abstract class AbstractStringBasedModelInterpolator extends AbstractLogEnabled
implements ModelInterpolator, Initializable {
public abstract class AbstractStringBasedModelInterpolator implements ModelInterpolator, Initializable {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractStringBasedModelInterpolator.class);

private static final List<String> PROJECT_PREFIXES = Arrays.asList("pom.", "project.");

Expand Down Expand Up @@ -249,8 +249,6 @@ protected String interpolateInternal(
return src;
}

Logger logger = getLogger();

String result = src;
synchronized (this) {
for (ValueSource vs : valueSources) {
Expand All @@ -271,27 +269,27 @@ protected String interpolateInternal(
if (debug) {
List<Object> feedback = interpolator.getFeedback();
if (feedback != null && !feedback.isEmpty()) {
logger.debug("Maven encountered the following problems during initial POM interpolation:");
LOGGER.debug("Maven encountered the following problems during initial POM interpolation:");

Object last = null;
for (Object next : feedback) {
if (next instanceof Throwable) {
if (last == null) {
logger.debug("", ((Throwable) next));
LOGGER.debug("", ((Throwable) next));
} else {
logger.debug(String.valueOf(last), ((Throwable) next));
LOGGER.debug(String.valueOf(last), ((Throwable) next));
}
} else {
if (last != null) {
logger.debug(String.valueOf(last));
LOGGER.debug(String.valueOf(last));
}

last = next;
}
}

if (last != null) {
logger.debug(String.valueOf(last));
LOGGER.debug(String.valueOf(last));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.maven.project.path.PathTranslator;
import org.codehaus.plexus.interpolation.Interpolator;
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Use a regular expression search to find and resolve expressions within the POM.
Expand All @@ -32,6 +34,7 @@
*/
@Deprecated
public class RegexBasedModelInterpolator extends AbstractStringBasedModelInterpolator {
private static final Logger LOGGER = LoggerFactory.getLogger(RegexBasedModelInterpolator.class);

public RegexBasedModelInterpolator() throws IOException {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
import org.codehaus.plexus.interpolation.Interpolator;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.codehaus.plexus.interpolation.ValueSource;
import org.codehaus.plexus.logging.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* StringSearchModelInterpolator
Expand All @@ -49,6 +50,7 @@
@Named
@Singleton
public class StringSearchModelInterpolator extends AbstractStringBasedModelInterpolator {
private static final Logger LOGGER = LoggerFactory.getLogger(StringSearchModelInterpolator.class);

private static final Map<Class<?>, Field[]> FIELDS_BY_CLASS = new WeakHashMap<>();
private static final Map<Class<?>, Boolean> PRIMITIVE_BY_CLASS = new WeakHashMap<>();
Expand All @@ -74,7 +76,7 @@ protected void interpolateObject(
List<InterpolationPostProcessor> postProcessors = createPostProcessors(model, projectDir, config);

InterpolateObjectAction action =
new InterpolateObjectAction(obj, valueSources, postProcessors, debugEnabled, this, getLogger());
new InterpolateObjectAction(obj, valueSources, postProcessors, debugEnabled, this);

ModelInterpolationException error = AccessController.doPrivileged(action);

Expand All @@ -98,7 +100,6 @@ private static final class InterpolateObjectAction implements PrivilegedAction<M
private final boolean debugEnabled;
private final LinkedList<Object> interpolationTargets;
private final StringSearchModelInterpolator modelInterpolator;
private final Logger logger;
private final List<ValueSource> valueSources;
private final List<InterpolationPostProcessor> postProcessors;

Expand All @@ -107,8 +108,7 @@ private static final class InterpolateObjectAction implements PrivilegedAction<M
List<ValueSource> valueSources,
List<InterpolationPostProcessor> postProcessors,
boolean debugEnabled,
StringSearchModelInterpolator modelInterpolator,
Logger logger) {
StringSearchModelInterpolator modelInterpolator) {
this.valueSources = valueSources;
this.postProcessors = postProcessors;
this.debugEnabled = debugEnabled;
Expand All @@ -117,7 +117,6 @@ private static final class InterpolateObjectAction implements PrivilegedAction<M
interpolationTargets.add(target);

this.modelInterpolator = modelInterpolator;
this.logger = logger;
}

public ModelInterpolationException run() {
Expand Down Expand Up @@ -169,8 +168,8 @@ private void traverseObjectWithParents(Class<?> cls, Object target) throws Model
try {
c.clear();
} catch (UnsupportedOperationException e) {
if (debugEnabled && logger != null) {
logger.debug("Skipping interpolation of field: " + field + " in: "
if (debugEnabled && LOGGER != null) {
LOGGER.debug("Skipping interpolation of field: " + field + " in: "
+ cls.getName()
+ "; it is an unmodifiable collection.");
}
Expand Down Expand Up @@ -217,8 +216,8 @@ private void traverseObjectWithParents(Class<?> cls, Object target) throws Model
try {
entry.setValue(interpolated);
} catch (UnsupportedOperationException e) {
if (debugEnabled && logger != null) {
logger.debug("Skipping interpolation of field: " + field
if (debugEnabled && LOGGER != null) {
LOGGER.debug("Skipping interpolation of field: " + field
+ " (key: " + entry.getKey() + ") in: "
+ cls.getName()
+ "; it is an unmodifiable collection.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.repository.legacy.WagonManager;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Describes a version transformation during artifact resolution.
*
* TODO try and refactor to remove abstract methods - not particular happy about current design
*/
@Deprecated
public abstract class AbstractVersionTransformation extends AbstractLogEnabled implements ArtifactTransformation {
public abstract class AbstractVersionTransformation implements ArtifactTransformation {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractVersionTransformation.class);

@Inject
protected RepositoryMetadataManager repositoryMetadataManager;

Expand Down Expand Up @@ -96,18 +99,18 @@ protected String resolveVersion(Artifact artifact, RepositoryRequest request)

// TODO also do this logging for other metadata?
// TODO figure out way to avoid duplicated message
if (getLogger().isDebugEnabled()) {
if (LOGGER.isDebugEnabled()) {
if (!version.equals(artifact.getBaseVersion())) {
String message = artifact.getArtifactId() + ": resolved to version " + version;
if (artifact.getRepository() != null) {
message += " from repository " + artifact.getRepository().getId();
} else {
message += " from local repository";
}
getLogger().debug(message);
LOGGER.debug(message);
} else {
// Locally installed file is newer, don't use the resolved version
getLogger().debug(artifact.getArtifactId() + ": using locally installed snapshot");
LOGGER.debug(artifact.getArtifactId() + ": using locally installed snapshot");
}
}
return version;
Expand Down
Loading