Pankraz76 commented on code in PR #2326: URL: https://github.com/apache/maven/pull/2326#discussion_r2086815063
########## impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java: ########## @@ -38,65 +37,54 @@ import org.apache.maven.plugin.descriptor.io.PluginDescriptorStaxReader; import org.apache.maven.plugin.descriptor.io.PluginDescriptorStaxWriter; -import static org.apache.maven.impl.ImplUtils.nonNull; import static org.apache.maven.impl.StaxLocation.getLocation; import static org.apache.maven.impl.StaxLocation.getMessage; @Named @Singleton public class DefaultPluginXmlFactory implements PluginXmlFactory { + + static final PluginDescriptorStaxWriter WRITER = new PluginDescriptorStaxWriter(); + static final PluginDescriptorStaxReader READER = new PluginDescriptorStaxReader(); + @Override public PluginDescriptor read(@Nonnull XmlReaderRequest request) throws XmlReaderException { - nonNull(request, "request"); - Path path = request.getPath(); - URL url = request.getURL(); - Reader reader = request.getReader(); - InputStream inputStream = request.getInputStream(); - if (path == null && url == null && reader == null && inputStream == null) { - throw new IllegalArgumentException("path, url, reader or inputStream must be non null"); - } + READER.setAddDefaultEntities(request.isAddDefaultEntities()); + var read = request.assertReadable(); try { - PluginDescriptorStaxReader xml = new PluginDescriptorStaxReader(); - xml.setAddDefaultEntities(request.isAddDefaultEntities()); - if (inputStream != null) { - return xml.read(inputStream, request.isStrict()); - } else if (reader != null) { - return xml.read(reader, request.isStrict()); - } else if (path != null) { - try (InputStream is = Files.newInputStream(path)) { - return xml.read(is, request.isStrict()); - } - } else { - try (InputStream is = url.openStream()) { - return xml.read(is, request.isStrict()); + if (read.getInputStream() != null) { + return READER.read(read.getInputStream(), read.isStrict()); + } else if (read.getReader() != null) { + return READER.read(read.getReader(), read.isStrict()); + } else if (read.getPath() != null) { + try (InputStream is = Files.newInputStream(read.getPath())) { + return READER.read(is, read.isStrict()); } } - } catch (Exception e) { + try (InputStream is = read.getURL().openStream()) { + return READER.read(is, read.isStrict()); + } + } catch (IOException | XMLStreamException e) { throw new XmlReaderException("Unable to read plugin: " + getMessage(e), getLocation(e), e); } } @Override public void write(XmlWriterRequest<PluginDescriptor> request) throws XmlWriterException { - nonNull(request, "request"); - PluginDescriptor content = nonNull(request.getContent(), "content"); - Path path = request.getPath(); - OutputStream outputStream = request.getOutputStream(); - Writer writer = request.getWriter(); - if (writer == null && outputStream == null && path == null) { - throw new IllegalArgumentException("writer, outputStream or path must be non null"); - } Review Comment: why must factory have such details. All we need is some valid request. No need to take hostage on this concern handling is here. Lets trade `feature envy` for `delegation` and `segregation`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org