Skip to content
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

NCL-5717: Remove nexus-staging-maven-plugin by default #783

Merged
merged 4 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( session.getUserProperties() ) );
}

/**
* 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,12 +50,14 @@ public class PluginRemovalManipulator
{
private final Logger logger = LoggerFactory.getLogger( getClass() );

private ManipulationSession session;
protected ManipulationSession session;

dwalluck marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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 )
Expand All @@ -65,16 +67,28 @@ public void init( final ManipulationSession session )
}

/**
* 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
Expand Up @@ -106,6 +106,6 @@ public Set<Project> applyChanges( final List<Project> projects )
@Override
public int getExecutionIndex()
{
return 53;
return 55;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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
rnc marked this conversation as resolved.
Show resolved Hide resolved
{
/** The name of the property containing a boolean controlling whether this is enabled, {@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 list version of the {@code <groupId>:<artifactId>} coordinates of nexus-staging-maven-plugin. */
private static final List<ProjectRef> PLUGIN_REMOVAL = Collections.singletonList( SimpleVersionlessArtifactRef.parse( NEXUS_STAGING_MAVEN_PLUGIN_SPEC ) );

/** Whether or not this manipulator is enabled. Defaults to {@code true}. */
private boolean enabled = true;

static
{
State.activeByDefault.add( NexusStagingMavenPluginRemovalState.class );
}

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

/**
* 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 )
{
enabled = Boolean.parseBoolean( userProps.getProperty( NEXUS_STAGING_MAVEN_PLUGIN_REMOVAL_PROPERTY,
Boolean.TRUE.toString() ) );
}

/**
* 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 enabled;
}

/**
* 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 PLUGIN_REMOVAL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
*/
package org.commonjava.maven.ext.core.state;

import lombok.NoArgsConstructor;
import org.commonjava.maven.atlas.ident.ref.ProjectRef;
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;

/**
* Captures configuration relating to plugin removal from the POMs.
*/
@NoArgsConstructor
public class PluginRemovalState
implements State
{
Expand All @@ -39,7 +42,7 @@ public class PluginRemovalState

private List<ProjectRef> pluginRemoval;

public PluginRemovalState( final Properties userProps )
public PluginRemovalState( Properties userProps )
{
initialise( userProps );
}
Expand All @@ -62,6 +65,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
Expand Up @@ -57,7 +57,7 @@
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<altDeploymentRepository>local-repo::default::file://${basedir}/target/deploy-local</altDeploymentRepository>
<altDeploymentRepository>local-repo::default::file://${basedir}/target/local-deploy</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def repopom = new File( repodir, "${pom.artifactId.text()}-${pom.version.text()}
System.out.println( "Checking for installed pom: ${repopom.getAbsolutePath()}")
assert repopom.exists()

def deploydir = new File("${project.build.directory}/deploy-local", "${pom.groupId.text().replace('.', '/')}/${pom.artifactId.text()}/${pom.version.text()}" )
def deploydir = new File("${project.build.directory}/local-deploy", "${pom.groupId.text().replace('.', '/')}/${pom.artifactId.text()}/${pom.version.text()}" )
def deploypom = new File( deploydir, "${pom.artifactId.text()}-${pom.version.text()}.pom" )
System.out.println( "Checking for deployed pom: ${deploypom.getAbsolutePath()}")
assert deploypom.exists()
2 changes: 1 addition & 1 deletion integration-test/src/it/deploy-install-skip/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<configuration>
<skip>true</skip>

<altDeploymentRepository>local-repo::default::file://${basedir}/target/deploy-local</altDeploymentRepository>
<altDeploymentRepository>local-repo::default::file://${basedir}/target/local-deploy</altDeploymentRepository>

</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/src/it/deploy-install-skip/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def repopom = new File( repodir, "${pom.artifactId.text()}-${pom.version.text()}
System.out.println( "Checking for installed pom: ${repopom.getAbsolutePath()}")
assert repopom.exists()

def deploydir = new File("${project.build.directory}/deploy-local", "${pom.groupId.text().replace('.', '/')}/${pom.artifactId.text()}/${pom.version.text()}" )
def deploydir = new File("${project.build.directory}/local-deploy", "${pom.groupId.text().replace('.', '/')}/${pom.artifactId.text()}/${pom.version.text()}" )
def deploypom = new File( deploydir, "${pom.artifactId.text()}-${pom.version.text()}.pom" )
System.out.println( "Checking for deployed pom: ${deploypom.getAbsolutePath()}")
assert deploypom.exists()
Loading