Repository navigation
fix: decouple ModelProcessor from XML-specific types (#13707) #13722
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,15 @@ | |
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.maven.api.annotations.Nonnull; | ||
| import org.apache.maven.api.annotations.Nullable; | ||
| import org.apache.maven.api.model.Model; | ||
| import org.apache.maven.api.services.Source; | ||
| import org.apache.maven.api.services.xml.XmlReaderException; | ||
| import org.apache.maven.api.services.xml.XmlReaderRequest; | ||
| import org.apache.maven.api.spi.ModelParserException; | ||
|
|
||
| /** | ||
| * Locates and reads POM files from the filesystem. | ||
|
|
@@ -34,6 +37,15 @@ | |
| */ | ||
| public interface ModelProcessor { | ||
|
|
||
| /** | ||
| * Option key for passing an {@link XmlReaderRequest.Transformer} through the options map. | ||
| * When present, the processor should use this transformer for XML parsing instead | ||
| * of any default transformer it would otherwise apply. | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| String TRANSFORMER = "transformer"; | ||
|
|
||
| /** | ||
| * Returns the file containing the pom to be parsed or null if a pom can not be found | ||
| * at the given file or in the given directory. | ||
|
|
@@ -42,13 +54,26 @@ public interface ModelProcessor { | |
| Path locateExistingPom(@Nonnull Path project); | ||
|
|
||
| /** | ||
| * Reads the model from the specified byte stream. The stream will be automatically closed before the method | ||
| * returns. | ||
| * Reads the model from the specified source. | ||
| * | ||
| * @param source The source to deserialize the model from, must not be {@code null}. | ||
| * @param options Possible reading options, may be {@code null}. | ||
| * @return The deserialized model, never {@code null}. | ||
| * @throws ModelParserException If the model could not be deserialized. | ||
| * @since 4.0.0 | ||
| */ | ||
| @Nonnull | ||
| Model read(@Nonnull Source source, @Nullable Map<String, ?> options) throws ModelParserException; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The deprecated bridge method and |
||
|
|
||
| /** | ||
| * Reads the model from the specified reader request. | ||
| * | ||
| * @param request The reader request to deserialize the model, must not be {@code null}. | ||
| * @return The deserialized model, never {@code null}. | ||
| * @throws IOException If the model could not be deserialized. | ||
| * @throws XmlReaderException If the input format could not be parsed. | ||
| * @deprecated Use {@link #read(Source, Map)} instead. | ||
| */ | ||
| @Deprecated(since = "4.0.0") | ||
| Model read(XmlReaderRequest request) throws IOException, XmlReaderException; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,6 @@ | |
| */ | ||
| package org.apache.maven.impl; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.net.URL; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
@@ -29,9 +27,12 @@ | |
| import org.apache.maven.api.di.Named; | ||
| import org.apache.maven.api.di.Singleton; | ||
| import org.apache.maven.api.model.Model; | ||
| import org.apache.maven.api.services.ModelSource; | ||
| import org.apache.maven.api.services.SuperPomProvider; | ||
| import org.apache.maven.api.services.model.ModelProcessor; | ||
| import org.apache.maven.api.services.xml.XmlReaderRequest; | ||
| import org.apache.maven.api.spi.ModelParser; | ||
| import org.apache.maven.api.spi.ModelParserException; | ||
| import org.apache.maven.impl.model.DefaultModelProcessor; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This creates tight coupling between two implementation classes that should remain independent. If The fix is to move // In Sources.java (maven-api-core)
@Nonnull
public static ModelSource urlSource(@Nonnull URL url, @Nullable String modelId) {
return new UrlModelSource(url, modelId);
}
|
||
|
|
||
| @Named | ||
| @Singleton | ||
|
|
@@ -61,16 +62,12 @@ private Model readModel(String version, String v) { | |
| throw new IllegalStateException("The super POM " + resource + " was not found" | ||
| + ", please verify the integrity of your Maven installation"); | ||
| } | ||
| try (InputStream is = url.openStream()) { | ||
| String modelId = | ||
| "org.apache.maven:maven-api-impl:" + getImplementationVersion(getClass()) + ":super-pom-" + version; | ||
| return modelProcessor.read(XmlReaderRequest.builder() | ||
| .modelId(modelId) | ||
| .location(url.toExternalForm()) | ||
| .inputStream(is) | ||
| .strict(false) | ||
| .build()); | ||
| } catch (IOException e) { | ||
| String modelId = | ||
| "org.apache.maven:maven-api-impl:" + getImplementationVersion(getClass()) + ":super-pom-" + version; | ||
| ModelSource source = DefaultModelProcessor.urlModelSource(url, modelId); | ||
| try { | ||
| return modelProcessor.read(source, Map.of(ModelParser.STRICT, false)); | ||
| } catch (ModelParserException e) { | ||
| throw new IllegalStateException( | ||
| "The super POM " + resource + " is damaged" | ||
| + ", please verify the integrity of your Maven installation", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.