Skip to content

Commit

Permalink
NCL-5717: Remove nexus-staging-maven-plugin by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck committed Oct 5, 2020
1 parent 8eb4a9b commit 01ace96
Show file tree
Hide file tree
Showing 21 changed files with 823 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2012 Red Hat, Inc.
*
* Licensed 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.commonjava.maven.ext.core.impl;

import org.commonjava.maven.ext.common.model.Project;
import org.commonjava.maven.ext.core.ManipulationSession;
import org.commonjava.maven.ext.core.state.NexusStagingMavenPluginRemovalState;
import org.commonjava.maven.ext.core.state.PluginState;

import javax.inject.Named;
import javax.inject.Singleton;

import java.util.List;
import java.util.Set;

/**
* {@link Manipulator} implementation that can remove nexus-staging-maven-plugin from a project's pom file.
* Configuration is stored in a {@link PluginState} instance, which is in turn stored in the
* {@link ManipulationSession}.
*/
@Named("nexus-staging-maven-plugin-removal-manipulator")
@Singleton
public class NexusStagingMavenPluginRemovalManipulator
extends PluginRemovalManipulator {
/**
* Initialize the {@link PluginState} state holder in the {@link ManipulationSession}. This state holder detects
* version-change configuration from the Maven user properties (-D properties from the CLI) and makes it available
* for later.
*
* @param session the session
*/
@Override
public void init( ManipulationSession session )
{
this.session = session;
session.setState( new NexusStagingMavenPluginRemovalState() );
}

/**
* Apply the alignment changes to the list of {@link Project}s given.
*
* @param projects the projects to apply changes to
*/
@Override
public Set<Project> applyChanges( final List<Project> projects )
{
return applyChanges( projects, session.getState( NexusStagingMavenPluginRemovalState.class ) );
}

/**
* Determines the order in which manipulators are run, with the lowest number running first.
* Uses a 100-point scale.
*
* @return one greater than current index for {@code PluginRemovalManipulator}
*/
@Override
public int getExecutionIndex()
{
return 53;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.commonjava.maven.ext.core.ManipulationSession;
import org.commonjava.maven.ext.core.state.PluginRemovalState;
import org.commonjava.maven.ext.core.state.PluginState;
import org.commonjava.maven.ext.core.state.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,7 +40,8 @@

/**
* {@link Manipulator} implementation that can remove specified plugins from a project's pom file.
* Configuration is stored in a {@link PluginState} instance, which is in turn stored in the {@link ManipulationSession}.
* Configuration is stored in a {@link PluginState} instance, which is in turn stored in the
* {@link ManipulationSession}.
*/
@Named("plugin-removal-manipulator")
@Singleton
Expand All @@ -50,31 +50,45 @@ public class PluginRemovalManipulator
{
private final Logger logger = LoggerFactory.getLogger( getClass() );

private ManipulationSession session;
protected ManipulationSession session;

/**
* Initialize the {@link PluginState} state holder in the {@link ManipulationSession}. This state holder detects
* version-change configuration from the Maven user properties (-D properties from the CLI) and makes it available for
* later.
* version-change configuration from the Maven user properties (-D properties from the CLI) and makes it available
* for later.
*
* @param session the session
*/
@Override
public void init( final ManipulationSession session )
{
this.session = session;
session.setState( new PluginRemovalState( session.getUserProperties() ) );
session.setState( new PluginRemovalState() );
}

/**
* Apply the alignment changes to the list of {@link Project}'s given.
*
* @param projects the projects to apply the changes to
* @return the set of projects with changes
*/
@Override
public Set<Project> applyChanges( final List<Project> projects )
{
final State state = session.getState( PluginRemovalState.class );
return applyChanges( projects, session.getState( PluginRemovalState.class ) );
}

/**
* Apply the alignment changes to the list of {@link Project}'s given.
*
* @param projects the projects to apply changes to
* @param state the state
* @return the set of projects with changes
*/
protected Set<Project> applyChanges( final List<Project> projects, final PluginRemovalState state )
{
if ( !session.isEnabled() || !state.isEnabled() )
{
logger.debug( getClass().getSimpleName() + ": Nothing to do!" );
logger.debug( "{}: Nothing to do!", getClass().getSimpleName() );
return Collections.emptySet();
}

Expand All @@ -84,7 +98,7 @@ public Set<Project> applyChanges( final List<Project> projects )
{
final Model model = project.getModel();

if ( apply( project, model ) )
if ( apply( project, model, state ) )
{
changed.add( project );
}
Expand All @@ -93,16 +107,13 @@ public Set<Project> applyChanges( final List<Project> projects )
return changed;
}

private boolean apply( final Project project, final Model model )
protected boolean apply( final Project project, final Model model, final PluginRemovalState state )
{
final PluginRemovalState state = session.getState( PluginRemovalState.class );

if (logger.isDebugEnabled())
if ( logger.isDebugEnabled() )
{
logger.debug( "Applying plugin changes to: {}", ga( project ) );
}


boolean result = false;
List<ProjectRef> pluginsToRemove = state.getPluginRemoval();
if ( model.getBuild() != null )
Expand Down Expand Up @@ -140,6 +151,12 @@ private boolean scanPlugins( List<ProjectRef> pluginsToRemove, List<Plugin> plug
return result;
}

/**
* Determines the order in which manipulators are run, with the lowest number running first.
* Uses a 100-point scale.
*
* @return the execution index for {@code PluginRemovalManipulator} which is 52
*/
@Override
public int getExecutionIndex()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2012 Red Hat, Inc.
*
* Licensed 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.commonjava.maven.ext.core.state;

import org.commonjava.maven.atlas.ident.ref.ProjectRef;
import org.commonjava.maven.atlas.ident.ref.SimpleVersionlessArtifactRef;
import org.commonjava.maven.ext.annotation.ConfigValue;

import java.util.Collections;
import java.util.List;
import java.util.Properties;

/**
* Captures configuration relating to nexus-staging-maven-plugin removal from the POMs.
*/
public final class NexusStagingMavenPluginRemovalState
extends PluginRemovalState
{
/**
* The name of the property which contains a boolean controlling whether or not to remove.
*
* {@code -DnexusStagingMavenPluginRemoval=<true|false>}
*/
@ConfigValue( docIndex = "plugin-manip.html#nexus-staging-maven-plugin-removal" )
private static final String NEXUS_STAGING_MAVEN_PLUGIN_REMOVAL_PROPERTY = "nexusStagingMavenPluginRemoval";

/**
* The {@code <groupId>:<artifactId>} coordinates of nexus-staging-maven-plugin.
*/
private static final String NEXUS_STAGING_MAVEN_PLUGIN_SPEC = "org.sonatype.plugins:nexus-staging-maven-plugin";

/** The user properties. */
private Properties userProperties;

/**
* Initializes this state with the given {@code userProps}.
*
* The value {@link #isEnabled} will be set based on the value of the {@code nexusStagingMavenPluginRemoval}
* boolean property.
*
* @param userProps the user properties
*/
@Override
public void initialise( final Properties userProps )
{
this.userProperties = userProps;
}

/**
* Always enabled unless {@code nexusStagingMavenPluginRemoval} is set to {@code false} in the user properties
* or the CLI {@code -D} options.
*
* @see State#isEnabled()
*/
@Override
public boolean isEnabled()
{
return Boolean.parseBoolean( userProperties.getProperty( NEXUS_STAGING_MAVEN_PLUGIN_REMOVAL_PROPERTY,
Boolean.TRUE.toString() ) );
}

/**
* Always returns a singleton {@link List} containing a {@link ProjectRef} with the coordinates
* {@code org.sonatype.plugins:nexus-staging-maven-plugin}.
*
* @return a singleton {@link List} containing a {@link ProjectRef} with the coordinates
* {@code org.sonatype.plugins:nexus-staging-maven-plugin}
*/
@Override
public List<ProjectRef> getPluginRemoval()
{
return Collections.singletonList( SimpleVersionlessArtifactRef.parse( NEXUS_STAGING_MAVEN_PLUGIN_SPEC ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.commonjava.maven.ext.annotation.ConfigValue;
import org.commonjava.maven.ext.core.util.IdUtils;

import java.util.Collections;
import java.util.List;
import java.util.Properties;

Expand All @@ -39,11 +40,6 @@ public class PluginRemovalState

private List<ProjectRef> pluginRemoval;

public PluginRemovalState( final Properties userProps )
{
initialise( userProps );
}

public void initialise( Properties userProps )
{
pluginRemoval = IdUtils.parseGAs( userProps.getProperty( PLUGIN_REMOVAL_PROPERTY ) );
Expand All @@ -62,6 +58,6 @@ public boolean isEnabled()

public List<ProjectRef> getPluginRemoval()
{
return pluginRemoval;
return Collections.unmodifiableList( pluginRemoval );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import java.util.Properties;

/**
* Basic list of methods that state collections related to different {@link Manipulator}'s should implement. This is also a marker interface to
* Basic list of methods that state collections related to different {@link Manipulator}'s should implement. This is also a marker interface to
* help ensure the validity of content stored in the session.
*
*
* A State implementation can contain a mixture of configuration (parsed/configured from command-line properties or other sources) and storage output
* from the Manipulators.
*
*
* @author jdcasey
*/
public interface State
Expand All @@ -42,5 +42,5 @@ public interface State
*/
boolean isEnabled();

void initialise ( Properties userProperties) throws ManipulationException;
void initialise( Properties userProperties ) throws ManipulationException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (C) 2012 Red Hat, Inc.
#
# Licensed 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.
#

invoker.goals=install
Loading

0 comments on commit 01ace96

Please sign in to comment.