mathieucarbou / license-maven-plugin

Manage license headers in your source files
https://mathieu.carbou.me/license-maven-plugin/
Apache License 2.0
242 stars 86 forks source link

Propose we stop reading blindly all java system properties with example including removal of system.getenv() #709

Closed hazendaz closed 5 months ago

hazendaz commented 9 months ago

This is to global in scope and takes on so many properties that have nothing to do with this project in any way. We know what properties we support. So lets only read in what we actually support.

Bad usage

    // then we override by java system properties (command-line -D...)
    for (String key : System.getProperties().stringPropertyNames()) {
      props.put(key, System.getProperty(key));
    }

Or better yet do it the maven way which get all users properties.

Better usage (will need some adjustments to testing to mock session)

    // then we override by maven session user properties (command-line -D...)
    Map sessionMap = session.getUserProperties();
    props.putAll((Map<String, String>) sessionMap);

In my testing, this picked up a much shorter list as follows when all said and done. This includes also dumping System.getenv.

##This comes from maven.config##
 - aether.checksums.algorithms=SHA-512,SHA-256,SHA-1,MD5
 - aether.connector.smartChecksums=false

## From the plugin ##
 - owner=hazendaz
 - project.artifactId=javabean-tester
 - project.description=Javabean Tester Simplifies POJO Testing and greatly simplifies Lombok Bean Testing!
 - project.groupId=com.github.hazendaz
 - project.inceptionYear=2012
 - project.name=javabean-tester
 - project.organization.name=hazendaz
 - project.organization.url=https://github.com/hazendaz/
 - project.url=https://github.com/hazendaz/javabean-tester
 - project.version=2.6.3-SNAPSHOT

## From -D options ##
 - someJunk=someJunk

## From the plugin (deprecated, should remove for version 5.0) ##
 - year=2012

## The file being processed ##
 - file.name=SampleExtensionBean.java

## From the git resolver ##
 - license.git.copyrightCreationYear=2014
 - license.git.copyrightLastYear=2022
 - license.git.copyrightExistenceYears=2014-2022
 - license.git.copyrightYears=2012-2022
 - license.git.CreationAuthorEmail=jeremylandis@hotmail.com
 - license.git.CreationAuthorName=Jeremy Landis
hazendaz commented 9 months ago

note: I did not use the other flag to show even more properties as it currently stands. I felt this was more typical in usage.

mathieucarbou commented 9 months ago

The problem is that license placeholders accept properties coming from -D and env, and we do not know about them.

mathieucarbou commented 5 months ago

I have closing because this is not something that can be implemented in a backward compatible way. All sys props are allowed.