Skip to content

Commit

Permalink
Move CiModelInterpolator to JSR-330 component
Browse files Browse the repository at this point in the history
Instead of manually configured plexus component
we can use annotations.
  • Loading branch information
slawekjaranowski committed Mar 19, 2023
1 parent dc0747d commit 9feb170
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* under the License.
*/

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

import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
Expand All @@ -42,7 +46,6 @@
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.interpolation.MavenBuildTimestamp;
import org.apache.maven.model.interpolation.ModelInterpolator;
import org.apache.maven.model.path.PathTranslator;
import org.apache.maven.model.path.UrlNormalizer;
import org.codehaus.plexus.interpolation.AbstractValueSource;
Expand All @@ -60,10 +63,10 @@

/**
* Based on StringSearchModelInterpolator in maven-model-builder.
*
* IMPORTANT: this is a legacy Plexus component, with manually authored descriptor in src/main/resources!
*/
public class CiModelInterpolator implements CiInterpolator, ModelInterpolator {
@Named
@Singleton
public class CiModelInterpolator implements CiInterpolator {

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

Expand Down Expand Up @@ -99,15 +102,19 @@ public class CiModelInterpolator implements CiInterpolator, ModelInterpolator {
// There is a protected setter for this one?
private RecursionInterceptor recursionInterceptor;

private PathTranslator pathTranslator;
private final PathTranslator pathTranslator;

private UrlNormalizer urlNormalizer;
private final UrlNormalizer urlNormalizer;

public CiModelInterpolator() {
@Inject
public CiModelInterpolator(PathTranslator pathTranslator, UrlNormalizer urlNormalizer) {
this.pathTranslator = pathTranslator;
this.urlNormalizer = urlNormalizer;
this.interpolator = createInterpolator();
this.recursionInterceptor = new PrefixAwareRecursionInterceptor(PROJECT_PREFIXES);
}

@Override
public Model interpolateModel(
Model model, File projectDir, ModelBuildingRequest config, ModelProblemCollector problems) {
interpolateObject(model, model, projectDir, config, problems);
Expand Down Expand Up @@ -570,7 +577,7 @@ protected final Interpolator getInterpolator() {
return interpolator;
}

class BuildTimestampValueSource extends AbstractValueSource {
static class BuildTimestampValueSource extends AbstractValueSource {
private final MavenBuildTimestamp mavenBuildTimestamp;

BuildTimestampValueSource(Date startTime, Properties properties) {
Expand All @@ -586,7 +593,7 @@ public Object getValue(String expression) {
}
}

class ProblemDetectingValueSource implements ValueSource {
static class ProblemDetectingValueSource implements ValueSource {

private final ValueSource valueSource;

Expand Down Expand Up @@ -628,7 +635,7 @@ public void clearFeedback() {
}
}

class PathTranslatingPostProcessor implements InterpolationPostProcessor {
static class PathTranslatingPostProcessor implements InterpolationPostProcessor {

private final Collection<String> unprefixedPathKeys;
private final File projectDir;
Expand Down Expand Up @@ -659,7 +666,7 @@ public Object execute(String expression, Object value) {
}
}

class UrlNormalizingPostProcessor implements InterpolationPostProcessor {
static class UrlNormalizingPostProcessor implements InterpolationPostProcessor {

private UrlNormalizer normalizer;

Expand Down
22 changes: 0 additions & 22 deletions src/main/resources/META-INF/plexus/components.xml

This file was deleted.

0 comments on commit 9feb170

Please sign in to comment.