Skip to content

Let the DefaultBuildContext delegate to the legacy build-api #71

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 2, 2023
Merged
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
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ See the Apache License Version 2.0 for the specific language governing permissio
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<!-- The depednecies are only to support the legacy API therefore we exclude anything as we only need the API/classes -->
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<version>0.0.7</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.9.0.M2</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

<build>
Expand Down
96 changes: 65 additions & 31 deletions src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.codehaus.plexus.build;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

Expand All @@ -23,7 +24,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.Scanner;
import org.codehaus.plexus.util.io.CachingOutputStream;
import org.slf4j.Logger;
Expand All @@ -47,11 +48,28 @@
@Singleton
public class DefaultBuildContext implements BuildContext {

private final Map<String, Object> contextMap = new ConcurrentHashMap<>();
private final Logger logger = LoggerFactory.getLogger(DefaultBuildContext.class);
// the legacy API requires the AbstractLogEnabled we just have it here to get
// compile errors in case it is missing from the classpath!
@SuppressWarnings("unused")
private static final AbstractLogEnabled DUMMY = null;

private final Map<String, Object> contextMap = new ConcurrentHashMap<>();
private org.sonatype.plexus.build.incremental.BuildContext legacy;

/**
* @param legacy the legacy API we delegate to by default, this allow us to
* support "older" plugins and implementors of the API while still
* having a way to move forward!
*/
@Inject
public DefaultBuildContext(org.sonatype.plexus.build.incremental.BuildContext legacy) {
this.legacy = legacy;
}

/** {@inheritDoc} */
public boolean hasDelta(String relpath) {
return true;
return legacy.hasDelta(relpath);
}

/**
Expand All @@ -61,7 +79,7 @@ public boolean hasDelta(String relpath) {
* @return a boolean.
*/
public boolean hasDelta(File file) {
return true;
return legacy.hasDelta(file);
}

/**
Expand All @@ -71,34 +89,44 @@ public boolean hasDelta(File file) {
* @return a boolean.
*/
public boolean hasDelta(List<String> relpaths) {
return true;
return legacy.hasDelta(relpaths);
}

/** {@inheritDoc} */
public OutputStream newFileOutputStream(File file) throws IOException {
return new CachingOutputStream(file.toPath());
if (isDefaultImplementation()) {
return new CachingOutputStream(file.toPath());
}
return legacy.newFileOutputStream(file);
}

/**
* @return <code>true</code> if the legacy is the default implementation and we
* can safely override/change behavior here, or <code>false</code> if a
* custom implementation is used and full delegation is required.
*/
private boolean isDefaultImplementation() {
return legacy.getClass().equals(org.sonatype.plexus.build.incremental.DefaultBuildContext.class);
}

/** {@inheritDoc} */
public Scanner newScanner(File basedir) {
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(basedir);
return ds;
return legacy.newScanner(basedir);
}

/** {@inheritDoc} */
public void refresh(File file) {
// do nothing
legacy.refresh(file);
}

/** {@inheritDoc} */
public Scanner newDeleteScanner(File basedir) {
return new EmptyScanner(basedir);
return legacy.newDeleteScanner(basedir);
}

/** {@inheritDoc} */
public Scanner newScanner(File basedir, boolean ignoreDelta) {
return newScanner(basedir);
return legacy.newScanner(basedir, ignoreDelta);
}

/**
Expand All @@ -107,7 +135,7 @@ public Scanner newScanner(File basedir, boolean ignoreDelta) {
* @return a boolean.
*/
public boolean isIncremental() {
return false;
return legacy.isIncremental();
}

/** {@inheritDoc} */
Expand All @@ -120,10 +148,6 @@ public void setValue(String key, Object value) {
contextMap.put(key, value);
}

private String getMessage(File file, int line, int column, String message) {
return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message;
}

/** {@inheritDoc} */
public void addError(File file, int line, int column, String message, Throwable cause) {
addMessage(file, line, column, message, SEVERITY_ERROR, cause);
Expand All @@ -134,28 +158,38 @@ public void addWarning(File file, int line, int column, String message, Throwabl
addMessage(file, line, column, message, SEVERITY_WARNING, cause);
}

private String getMessage(File file, int line, int column, String message) {
return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message;
}

/** {@inheritDoc} */
public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {
switch (severity) {
case BuildContext.SEVERITY_ERROR:
logger.error(getMessage(file, line, column, message), cause);
return;
case BuildContext.SEVERITY_WARNING:
logger.warn(getMessage(file, line, column, message), cause);
return;
if (isDefaultImplementation()) {
switch (severity) {
case BuildContext.SEVERITY_ERROR:
logger.error(getMessage(file, line, column, message), cause);
return;
case BuildContext.SEVERITY_WARNING:
logger.warn(getMessage(file, line, column, message), cause);
return;
default:
logger.debug(getMessage(file, line, column, message), cause);
return;
}
}
throw new IllegalArgumentException("severity=" + severity);
legacy.addMessage(file, line, column, message, severity, cause);
}

/** {@inheritDoc} */
public void removeMessages(File file) {}
public void removeMessages(File file) {
if (isDefaultImplementation()) {
return;
}
legacy.removeMessages(file);
}

/** {@inheritDoc} */
public boolean isUptodate(File target, File source) {
return target != null
&& target.exists()
&& source != null
&& source.exists()
&& target.lastModified() > source.lastModified();
return legacy.isUptodate(target, source);
}
}
93 changes: 0 additions & 93 deletions src/main/java/org/codehaus/plexus/build/EmptyScanner.java

This file was deleted.

This file was deleted.

Loading