Coder Social home page Coder Social logo

Support different output formats about sortpom HOT 25 CLOSED

ekryd avatar ekryd commented on July 26, 2024
Support different output formats

from sortpom.

Comments (25)

php-coder avatar php-coder commented on July 26, 2024 1

Ok, I'll try it this weekend. Thanks!

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024 1

Released version 2.7.0 with the new functionality. Will update the wiki documentation soon.

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

This sounds like a good idea. Could you give me an example of how you would like the output to look like?

from sortpom.

php-coder avatar php-coder commented on July 26, 2024

I'm suggesting something like this (inspired by the CheckStyle/PMD reports):

<?xml version="1.0" encoding="UTF-8"?>
<sortpom version="2.5.0">
    <violation line="19">
        The xml element &lt;groupId&gt;com.github.heneke.thymeleaf&lt;/groupId&gt; should be placed before &lt;groupId&gt;javax.validation&lt;/groupId&gt;
    </violation>
</sortpom>

If it's possible the column and rule attributes could be added too.

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

There are (at least) two ways to do this.
Do you mean that you run the plugin as normal but specify that the output should be sent to a external file or do you want the run the plugin under the reporting section of the pom.xml?

See example of the two different ways at https://maven.apache.org/plugins/maven-pmd-plugin/usage.html

from sortpom.

php-coder avatar php-coder commented on July 26, 2024

Do you mean that you run the plugin as normal but specify that the output should be sent to a external file or do you want the run the plugin under the reporting section of the pom.xml?

The first option. I'd like to have output on the console as well as in the file (that later could be parsed).

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Great! I will make some changes and we will see if you like it. Disclaimer: this is done on my spare time, so I can't promise a specific delivery date.

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Normally if the plugin is configured in the pom-file or run with
mvn sortpom:verify -Dsort.verifyFail="Warn"

The output to the console would be
[INFO] --- sortpom-maven-plugin:2.4.0:verify (default-cli) @ sortpom-parent ---
[INFO] Verifying file /path/pom.xml
[WARNING] The xml element should be placed before
[WARNING] The file /path/pom.xml is not sorted

New way would be be a configuration like
mvn sortpom:verify -Dsort.verifyFail="Warn" -Dsort.outputType="console, file"
-Dsort.outputFile="sortpom-reports/sortpom-result.xml"

The output to the console would be the same and the the output to the file would be

Verifying file /path/pom.xml The xml element <version> should be placed before <packaging> The file /path/pom.xml is not sorted

Would this be enough or should the the output be more customised?

from sortpom.

php-coder avatar php-coder commented on July 26, 2024

Verifying file /path/pom.xml
The xml element should be placed before
The file /path/pom.xml is not sorted
Would this be enough or should the the output be more customised?

I believe that the first and the last lines aren't so useful because they don't contain actual violations. Could we omit them? Also, this output will be in XML/JSON form or am I missing something here?

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Wtf! My xml example just vanished! This is how it should have looked

The output to the console would be the same and the the output to the file would be

<?xml version="1.0" encoding="UTF-8"?>
<sortpom version="2.6.0">
    <information>Verifying file /path/pom.xml</information>
    <warning>The xml element &lt;version&gt; should be placed before &lt;packaging&gt;</warning>
    <warning>The file /path/pom.xml is not sorted</warning>
</sortpom>

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

If the following command was run:
mvn sortpom:verify -Dsort.verifyFail="Warn" -Dsort.outputType="console, file"
-Dsort.outputFile="sortpom-reports/sortpom-result.xml"

The console output would be
[INFO] --- sortpom-maven-plugin:2.4.0:verify (default-cli) @ sortpom-parent ---
[INFO] Verifying file /path/pom.xml
[WARNING] The xml element should be placed before
[WARNING] The file /path/pom.xml is not sorted

and the file output (./target/sortpom-reports/sortpom-result.xml) would be

<?xml version="1.0" encoding="UTF-8"?>
<sortpom version="2.6.0">
  <file name="c:\path\pom.xml">
    <violation goal="verify">The xml element &lt;version&gt; should be placed before &lt;packaging&gt;</violation>
  </file>
</sortpom>

I would like to keep the file indicator, but is the goal attribute really necessary?
Unfortunately I can only report one violation for the pom.xml.

What would the xml look like when everything is ok, just the sortpom and file tag?
I think that the console output should only be available to the verify goal, thoughts?
The violation entry will be written no matter what the verifyFail option says, right?

from sortpom.

php-coder avatar php-coder commented on July 26, 2024

I would like to keep the file indicator, but is the goal attribute really necessary?

Yes, I agree that goal attribute isn't necessary (at least to me :))

What would the xml look like when everything is ok, just the sortpom and file tag?

I expect that the report file isn't created at all.

The violation entry will be written no matter what the verifyFail option says, right?

Sounds reasonable.

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Good! Then I will start to look at the code and see how this can be realized. I will keep you posted when I have done some progress.

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Added a new branch with the new functionality.
The new parameter would be used like this:
mvn sortpom:verify -Dsort.violationFilename="target/sortpom_reports/violation.xml"

and the output would be like this:

<?xml version="1.0" encoding="UTF-8"?>
<sortpom>
  <file filename="/Users/bjorn/Workspace/SortPom/maven-plugin/target/it/violation-file/pom.xml">
    <violation>The xml element &lt;modelVersion&gt; should be placed before &lt;name&gt;</violation>
  </file>
</sortpom>

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

I will continue with some more tests.

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Finally I have gotten some time to code properly!
Question:
Should the violation file be overwritten automatically if it already exists? Or should the plugin stop directly? Or stop just when it is about to write to the file?
My thoughts is that the plugin should stop directly, so that an existing violation file cannot give a false impression that the build failed. Or should an old file be deleted if the verification was ok?

from sortpom.

php-coder avatar php-coder commented on July 26, 2024

I would expect that file will be overwritten. When there is no violations then report won't have them.

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Overwrite works for me. Just to clarify: If the verify passed and an old violation file exists, will it be deleted or will it be left alone?

from sortpom.

php-coder avatar php-coder commented on July 26, 2024

It should be overwritten by empty report:

<?xml version="1.0" encoding="UTF-8"?>
<sortpom>
  <file filename="/Users/bjorn/Workspace/SortPom/maven-plugin/target/it/violation-file/pom.xml">
  </file>
</sortpom>

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Lets see:

I can think of two scenarios where the violation file will be left by the build.

  1. Optimized Jenkins build where the target directory is cleaned seldom to improve build speed.
    In this case the violation file should be cleared or emptied.
  2. Deployment with some sort release plugin where the same phases run again and again.
    In this case the violation file should be kept to indicate that the pom-file caused a violation at some point in the build.

I think that I will solve the problem as I handle the backup file. Write the violation file only if an violation occurred. Overwrite old file if violation occurs, otherwise just leave the disk drive as it is. This will be the easiest to implement/test. Any problems with leftover violation files will have to be solved by the user of the plugin. Would that work for you?

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Hi
I have made an implementation that is on the master branch. Could you please try it out by downloading the code, build it with mvn clean install, and run it with mvn com.github.ekryd.sortpom:sortpom-maven-plugin:2.6.1-SNAPSHOT:verify -Dsort.violationFilename="target/sortpom_reports/violation.xml"?
Feel free to try out your use case and any corner cases.

from sortpom.

php-coder avatar php-coder commented on July 26, 2024

It worked for me, thanks!

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Added some documentation to the parameter wiki. Have you tried the official version yet?

from sortpom.

php-coder avatar php-coder commented on July 26, 2024

No, I've added it to my todo list :)

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

I know that feeling ;-)

from sortpom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.