-
Notifications
You must be signed in to change notification settings - Fork 38
[MPH-219] Replace AbstractEffectiveMojo as static util class #353
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
Open
Giovds
wants to merge
9
commits into
apache:master
Choose a base branch
from
infosupport:MPH-219-make-util-class-of-abstract-effective-mojo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3b29d38
[MPH-219] Make AbstractEffectiveMojo a static util class
Giovds ece82a8
[MPH-219] Remove identical method
Giovds 48e02e7
[MPH-219] Make SortedProperties class interal
Giovds a0f0d68
[MPH-219] Add missing tests
Giovds ba221a8
[MPH-219] Test names should match format
Giovds c3e66f3
[MPH-219] Automatic spotless apply after rebase with master
Giovds 8a2e360
[MPH-219] Make line seperator system independant
Giovds 042a98f
[MPH-219] Revert changing public API, deprecate instead
Giovds f5e23f4
Revert "[MPH-219] Revert changing public API, deprecate instead"
Giovds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.plugins.help; | ||
|
|
||
| import java.io.StringWriter; | ||
| import java.nio.charset.Charset; | ||
| import java.util.Properties; | ||
|
|
||
| import org.codehaus.plexus.util.StringUtils; | ||
| import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; | ||
| import org.codehaus.plexus.util.xml.XMLWriter; | ||
| import org.codehaus.plexus.util.xml.XmlWriterUtil; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static java.lang.String.format; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class EffectiveMojoUtilsTest { | ||
|
|
||
| private final StringWriter w = new StringWriter(); | ||
| private final String encoding = Charset.defaultCharset().displayName(); | ||
| private final XMLWriter writer = new PrettyPrintXMLWriter( | ||
| w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null); | ||
|
|
||
| @Test | ||
| void writeHeaderShouldWriteHeaderComments() { | ||
| EffectiveMojoUtils.writeHeader(writer); | ||
|
|
||
| assertEquals( | ||
| format("<?xml version=\"1.0\" encoding=\"%s\"?>%n", encoding) | ||
| + format("<!-- ====================================================================== -->%n") | ||
| + format("<!-- -->%n") | ||
| + format("<!-- Generated by Maven Help Plugin -->%n") | ||
| + format("<!-- See: https://maven.apache.org/plugins/maven-help-plugin/ -->%n") | ||
| + format("<!-- -->%n") | ||
| + format("<!-- ====================================================================== -->%n"), | ||
| w.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| void writeCommentShouldWriteGivenComment() { | ||
| EffectiveMojoUtils.writeComment(writer, "This is a comment"); | ||
|
|
||
| assertEquals( | ||
| format("<?xml version=\"1.0\" encoding=\"%s\"?>%n", encoding) | ||
| + format("<!-- ====================================================================== -->%n") | ||
| + format("<!-- -->%n") | ||
| + format("<!-- This is a comment -->%n") | ||
| + format("<!-- -->%n") | ||
| + format("<!-- ====================================================================== -->%n"), | ||
| w.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| void sortPropertiesShouldSortProperties() { | ||
| final Properties props = new Properties(); | ||
| props.setProperty("z", "last"); | ||
| props.setProperty("a", "first"); | ||
| props.setProperty("g", "middle"); | ||
|
|
||
| final Properties sortedProps = EffectiveMojoUtils.sortProperties(props); | ||
|
|
||
| final Object[] sortedValues = sortedProps.values().toArray(); | ||
| assertEquals("first", sortedValues[0]); | ||
| assertEquals("middle", sortedValues[1]); | ||
| assertEquals("last", sortedValues[2]); | ||
|
|
||
| final Object[] sortedKeys = sortedProps.keySet().toArray(); | ||
| assertEquals("a", sortedKeys[0]); | ||
| assertEquals("g", sortedKeys[1]); | ||
| assertEquals("z", sortedKeys[2]); | ||
| } | ||
|
|
||
| @Test | ||
| void prettyFormatShouldFormatXmlString() { | ||
| final String xml = "<root><child><subchild>value</subchild></child></root>"; | ||
|
|
||
| final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, false); | ||
|
|
||
| assertEquals( | ||
| format("<?xml version=\"1.0\" encoding=\"%s\"?>%n", encoding) | ||
| + format("<root>%n") | ||
| + format(" <child>%n") | ||
| + format(" <subchild>value</subchild>%n") | ||
| + format(" </child>%n") | ||
| + format("</root>%n"), | ||
| prettyXml); | ||
| } | ||
|
|
||
| @Test | ||
| void prettyFormatShouldOmitDeclarationWhenSpecified() { | ||
| final String xml = "<root><child><subchild>value</subchild></child></root>"; | ||
|
|
||
| final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, true); | ||
|
|
||
| assertEquals( | ||
| format("<root>%n") | ||
| + format(" <child>%n") | ||
| + format(" <subchild>value</subchild>%n") | ||
| + format(" </child>%n") | ||
| + format("</root>%n"), | ||
| prettyXml); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't remove existing public API. You need to deprecate this instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an agreement on all ASF repo's? I thought this was mainly for maven-core API's.
I don't know, but do ASF-plugins support extensions of plugin public API's, do people do this? A quick search on GitHub on this class only seems to result in forks.
Alternatively I can e.g. deprecate it and change the implementation to point to the new class.
When will it be removed, and does this require a new ticket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 042a98f could be reverted if it's decided to change it. Otherwise, the commit should revert the breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion is similar. This plugin is not library, and its API are goals and their parameters. I would not consider such change to require deprecation.
This class being
publicdoes not make it public API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly - plugin is not library