Skip to content

[MNG-5957] Configuration within lifecycle phase#76

Closed
mkrizmanic wants to merge 1 commit intoapache:masterfrom
mkrizmanic:mng-5957
Closed

[MNG-5957] Configuration within lifecycle phase#76
mkrizmanic wants to merge 1 commit intoapache:masterfrom
mkrizmanic:mng-5957

Conversation

@mkrizmanic
Copy link
Contributor

The lifecycle phase can be configured as a comma-separated list of plugins specified with the following data:

<groupId>:<artifactId>:<version>:<goal>

that are not enough for my plugin.
My plugin has to reconfigure the default lifecycle using other plugins with dedicated configuration different from their defaults'.
So, I'd suppose to enhance the lifecycle phase parsing to support additional configuration as:

<groupId>:<artifactId>:<version>:<goal>[<configuration>]

Finally, the components.xml would support configurations like:

<component-set>
    <components>
        <component>
            <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
            ...
            <configuration>
                <lifecycles>
                    <lifecycle>
                        <id>default</id>
                        <phases>
                            <process-resources>
                                org.apache.maven.plugins:maven-resources-plugin:resources
                            </process-resources>
                            ...
                            <install>
                                <![CDATA[
                                org.apache.maven.plugins:maven-install-plugin:install,
                                org.apache.felix:maven-bundle-plugin:install[
                                        &lt;supportedProjectTypes&gt;
                                            &lt;supportedProjectType&gt;buzz&lt;/supportedProjectType&gt;
                                        &lt;/supportedProjectTypes&gt;]]]>
                            </install>

@mkrizmanic
Copy link
Contributor Author

Maybe the change seems to be a bit complicated but it really isn't. The current version splits goals using comma as the separator

String[] mojoGoals = StringUtils.split( goals, "," );

while the pull request uses the regular expression that matches the goals (similar as the current version) and optional additional configurations:

String goalRegex = "(?<goal>[^:\\[,\\s]+(?::[^:\\[,\\s]+)\{2,3\})";

// match [<configuration>]
String configurationRegex = "(?:\\[(?<configuration>(?:[^\\]]|(?:(?<=/)\\]))*)\\])?";

Pattern pattern = Pattern.compile( goalRegex + configurationRegex );
Matcher matcher = pattern.matcher( goals );

The goal may be compounded from 3 or 4 non-whitespace and non-comma character arrays delimited with colon - because the DefaultLifecyclePluginAnalyzer class requires them in parseGoalSpec method:

private GoalSpec parseGoalSpec( String goalSpec )
{
    GoalSpec gs = new GoalSpec();

    String[] p = StringUtils.split( goalSpec.trim(), ":" );

    if ( p.length == 3 )
    {
        // <groupId>:<artifactId>:<goal>
        gs.groupId = p[0];
        gs.artifactId = p[1];
        gs.goal = p[2];
    }
    else if ( p.length == 4 )
    {
        // <groupId>:<artifactId>:<version>:<goal>
        gs.groupId = p[0];
        gs.artifactId = p[1];
        gs.version = p[2];
        gs.goal = p[3];
    }
    else
    {
        // invalid
        gs = null;
    }

    return gs;
}

The configuration regex may contain any character except ‘]' that may be escaped ‘/]'.
The goals parsing is changed within the LifecyclePhase because it shouldn’t split goals only using the commas because the commas may be a part of an additional configuration.
WDYT?

@atanasenko
Copy link
Contributor

@mkrizmanic
Copy link
Contributor Author

Thanks. It works like a charm.

@mkrizmanic mkrizmanic closed this Jan 22, 2016
@mkrizmanic mkrizmanic deleted the mng-5957 branch January 22, 2016 20:48
@atanasenko
Copy link
Contributor

I didn't get to using it yet after implementing, cool that it works for someone :)

@mkrizmanic
Copy link
Contributor Author

@atanasenko do you have any other open issues regarding MNG-5805?

I had one that had been fixed: MNG-6127

@jira-importer
Copy link

Resolve #7733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants