Skip to content

Commit

Permalink
PRODTASKS-697 Remove deprecated injectRemotePlugins. Minor javadoc bu…
Browse files Browse the repository at this point in the history
…ild improvements
  • Loading branch information
rnc committed Sep 20, 2019
1 parent 273d9af commit d0ece46
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -55,9 +54,11 @@ public class JSONUtils
*
* @param jsonReport The JSON POJO to convert to a string.
* @return A string with the converted JSON.
* @throws IOException if an error occurs.
*/
// Public API.
public static String jsonToString( Object jsonReport )
throws JsonProcessingException
throws IOException
{
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString( jsonReport );
}
Expand All @@ -67,6 +68,7 @@ public static String jsonToString( Object jsonReport )
*
* @param jsonFile the file to read
* @return PME ; the root of the JSON hierarchy.
* @throws IOException if an error occurs
*/
@SuppressWarnings("WeakerAccess") // Public API.
public static PME fileToJSON( File jsonFile ) throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private void validateSession() throws ManipulationException
/**
* This will re-initialise any state linked to this session. This is useful if the user properties have been
* updated.
* @throws ManipulationException if an error occurs.
*/
protected void reinitialiseSessionStates() throws ManipulationException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public class PluginManipulator

private enum PluginType
{
// Attempting to configure using remote plugins is not supported - just remote plugin management (like dependencyManagement).
RemotePM,
RemoteP,
LocalPM,
LocalP;

Expand All @@ -80,8 +80,6 @@ public String toString()
{
case RemotePM:
return "RemotePluginManagement";
case RemoteP:
return "Plugins";
case LocalPM:
return "LocalPluginManagement";
case LocalP:
Expand Down Expand Up @@ -136,22 +134,15 @@ public Set<Project> applyChanges( final List<Project> projects )
}

final Set<Project> changed = new HashSet<>();
final Set<Plugin> mgmtOverrides = loadRemoteBOM( PluginType.RemotePM );
final Set<Plugin> pluginOverrides = loadRemoteBOM( PluginType.RemoteP );
final Set<Plugin> mgmtOverrides = loadRemoteBOM();

for ( final Project project : projects )
{
final Model model = project.getModel();

if (!mgmtOverrides.isEmpty())
{
apply( project, model, PluginType.RemotePM, mgmtOverrides );

changed.add( project );
}
if (!pluginOverrides.isEmpty())
{
apply( project, model, PluginType.RemoteP, pluginOverrides );
apply( project, model, mgmtOverrides );

changed.add( project );
}
Expand Down Expand Up @@ -208,7 +199,7 @@ public Set<Project> applyChanges( final List<Project> projects )
}


private Set<Plugin> loadRemoteBOM( PluginType type )
private Set<Plugin> loadRemoteBOM()
throws ManipulationException
{
final RESTState rState = session.getState( RESTState.class );
Expand All @@ -231,71 +222,50 @@ private Set<Plugin> loadRemoteBOM( PluginType type )
while ( iter.hasNext() )
{
final ProjectVersionRef ref = iter.next();
if ( type == PluginType.RemotePM )
{
bomOverrides.addAll( effectiveModelBuilder.getRemotePluginManagementVersionOverrides( ref,
exclusions ) );
}
else
{
bomOverrides.addAll( effectiveModelBuilder.getRemotePluginVersionOverrides( ref, exclusions ) );
}
bomOverrides.addAll( effectiveModelBuilder.getRemotePluginManagementVersionOverrides( ref, exclusions ) );
}
}


// TODO: Remote Plugin (as opposed to Remote PluginManagement) alignment is deprecated. Therefore we don't support combining it with REST.
if ( type == PluginType.RemoteP )
if ( pState.getPrecedence() == PluginPrecedence.BOM )
{
if ( pState.getPrecedence() != PluginPrecedence.BOM )
{
logger.warn( "Remote plugin alignment is only supported with precedence type of BOM" );
}
mergedOverrides = bomOverrides;
}
else
{
if ( pState.getPrecedence() == PluginPrecedence.BOM )
if ( mergedOverrides.isEmpty() )
{
mergedOverrides = bomOverrides;
if ( mergedOverrides.isEmpty() )
{
String msg = rState.isEnabled() ? "pluginSource for restURL" : "pluginManagement";
String msg = rState.isEnabled() ? "pluginSource for restURL" : "pluginManagement";

logger.warn( "No dependencies found for pluginSource {}. Has {} been configured? ", pState.getPrecedence(), msg );
}
}
if ( pState.getPrecedence() == PluginPrecedence.REST )
{
mergedOverrides = restOverrides;
if ( mergedOverrides.isEmpty() )
{
logger.warn( "No dependencies found for pluginSource {}. Has restURL been configured? ", pState.getPrecedence() );
}
}
else if ( pState.getPrecedence() == PluginPrecedence.RESTBOM )
{
mergedOverrides = restOverrides;
mergedOverrides.addAll( bomOverrides );
logger.warn( "No dependencies found for pluginSource {}. Has {} been configured? ", pState.getPrecedence(), msg );
}
else if ( pState.getPrecedence() == PluginPrecedence.BOMREST )
}
if ( pState.getPrecedence() == PluginPrecedence.REST )
{
mergedOverrides = restOverrides;
if ( mergedOverrides.isEmpty() )
{
mergedOverrides = bomOverrides;
mergedOverrides.addAll( restOverrides );
logger.warn( "No dependencies found for pluginSource {}. Has restURL been configured? ", pState.getPrecedence() );
}
}
else if ( pState.getPrecedence() == PluginPrecedence.RESTBOM )
{
mergedOverrides = restOverrides;
mergedOverrides.addAll( bomOverrides );
}
else if ( pState.getPrecedence() == PluginPrecedence.BOMREST )
{
mergedOverrides = bomOverrides;
mergedOverrides.addAll( restOverrides );
}

logger.debug ("Final remote override list for type {} with precedence {} is {}", type.toString(), pState.getPrecedence(), mergedOverrides);
logger.debug( "Final remote override list for type {} with precedence {} is {}", PluginType.RemotePM.toString(), pState.getPrecedence(), mergedOverrides );

return mergedOverrides;
}

private void apply( final Project project, final Model model, PluginType type, final Set<Plugin> override )
private void apply( final Project project, final Model model, final Set<Plugin> override )
throws ManipulationException
{
if (logger.isDebugEnabled())
{
logger.debug("Applying plugin changes for {} to: {} ", type, ga(project));
logger.debug( "Applying plugin changes for {} to: {} ", PluginType.RemotePM, ga( project));
}

if ( project.isInheritanceRoot() )
Expand All @@ -320,23 +290,23 @@ private void apply( final Project project, final Model model, PluginType type, f
}

// Override plugin management versions
applyOverrides( project, type, PluginType.LocalPM, project.getResolvedManagedPlugins( session ), override );
applyOverrides( project, PluginType.LocalPM, project.getResolvedManagedPlugins( session ), override );
}

applyOverrides( project, type, PluginType.LocalP, project.getResolvedPlugins( session ), override );
applyOverrides( project, PluginType.LocalP, project.getResolvedPlugins( session ), override );

final Map<Profile, Map<ProjectVersionRef, Plugin>> pd = project.getResolvedProfilePlugins( session );
final Map<Profile, Map<ProjectVersionRef, Plugin>> pmd = project.getResolvedProfileManagedPlugins( session );

logger.debug ("Processing profiles with plugin management");
for ( Profile p : pmd.keySet() )
{
applyOverrides( project, type, PluginType.LocalPM, pmd.get( p ), override );
applyOverrides( project, PluginType.LocalPM, pmd.get( p ), override );
}
logger.debug ("Processing profiles with plugins");
for ( Profile p : pd.keySet() )
{
applyOverrides( project, type, PluginType.LocalP, pd.get( p ), override );
applyOverrides( project, PluginType.LocalP, pd.get( p ), override );
}
}

Expand All @@ -352,13 +322,12 @@ private void apply( final Project project, final Model model, PluginType type, f
* configurations will also be applied to the local plugins.
*
* @param project the current project
* @param remotePluginType The type of the remote plugin (mgmt or plugins)
* @param localPluginType The type of local block (mgmt or plugins). Only used to determine whether to inject configs/deps/executions.
* @param plugins The list of plugins to modify
* @param pluginVersionOverrides The list of version overrides to apply to the plugins
* @throws ManipulationException if an error occurs.
*/
private void applyOverrides( Project project, PluginType remotePluginType, final PluginType localPluginType, final Map<ProjectVersionRef, Plugin> plugins,
private void applyOverrides( Project project, final PluginType localPluginType, final Map<ProjectVersionRef, Plugin> plugins,
final Set<Plugin> pluginVersionOverrides ) throws ManipulationException
{
if ( plugins == null )
Expand Down Expand Up @@ -418,7 +387,8 @@ else if ( commonState.isStrict() )
}
}

logger.debug( "Plugin override {} and local plugin {} with remotePluginType {} / localPluginType {}", override.getId(), plugin, remotePluginType, localPluginType );
logger.debug( "Plugin override {} and local plugin {} with remotePluginType {} / localPluginType {}", override.getId(), plugin,
PluginType.RemotePM, localPluginType );

if ( plugin != null )
{
Expand Down Expand Up @@ -495,11 +465,10 @@ else if ( pluginState.getConfigPrecedence() == Precedence.LOCAL )
while ( originalIt.hasNext() )
{
Dependency originalD = originalIt.next();
Iterator<Dependency> overrideIt = override.getDependencies().iterator();
while ( overrideIt.hasNext() )
for ( Dependency newD : override.getDependencies() )
{
Dependency newD = overrideIt.next();
if ( originalD.getGroupId().equals( newD.getGroupId() ) && originalD.getArtifactId().equals( newD.getArtifactId() ) )
if ( originalD.getGroupId().equals( newD.getGroupId() ) && originalD.getArtifactId()
.equals( newD.getArtifactId() ) )
{
logger.debug( "Removing original dependency {} in favour of {} ", originalD, newD );
originalIt.remove();
Expand Down Expand Up @@ -541,21 +510,12 @@ else if ( oldVersion != null && oldVersion.contains( "${" ) )
}
// If the plugin doesn't exist but has a configuration section in the remote inject it so we
// get the correct config.
else if ( remotePluginType == PluginType.RemotePM && localPluginType == PluginType.LocalPM && commonState.isOverrideTransitive() && ( override.getConfiguration() != null
else if ( localPluginType == PluginType.LocalPM && commonState.isOverrideTransitive() && ( override.getConfiguration() != null
|| override.getExecutions().size() > 0 ) )
{
project.getModel().getBuild().getPluginManagement().getPlugins().add( override );
logger.info( "Added plugin version: {}={}", override.getKey(), newValue );
}
// If the plugin in <plugins> doesn't exist but has a configuration section in the remote inject it so we
// get the correct config.
// TODO: Deprecated section.
else if ( remotePluginType == PluginType.RemoteP && localPluginType == PluginType.LocalP && pluginState.getInjectRemotePlugins() && ( override.getConfiguration() != null
|| override.getExecutions().size() > 0 ) )
{
project.getModel().getBuild().getPlugins().add( override );
logger.info( "For non-pluginMgmt, added plugin version : {}={}", override.getKey(), newValue );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ public enum Precedence

private Precedence configPrecedence;

/**
* Denote whether to inject plugin sections from a remote bom. This is separate to injecting
* pluginMgmt.
*/
private boolean injectRemotePlugins;

private Set<Plugin> remoteRESTplugins = new HashSet<>( );

private PluginPrecedence precedence;
Expand All @@ -102,7 +96,6 @@ public PluginState( final Properties userProps ) throws ManipulationException
public void initialise( Properties userProps ) throws ManipulationException
{
pluginMgmt = IdUtils.parseGAVs( userProps.getProperty( PLUGIN_MANAGEMENT_POM_PROPERTY ) );
injectRemotePlugins = Boolean.parseBoolean( userProps.getProperty( "injectRemotePlugins", "false" ) );
switch ( Precedence.valueOf( userProps.getProperty( "pluginManagementPrecedence",
Precedence.REMOTE.toString() ).toUpperCase() ) )
{
Expand Down Expand Up @@ -181,15 +174,6 @@ public Precedence getConfigPrecedence()
return configPrecedence;
}

/**
* @return whether to inject plugins found in the remote pom.
* @deprecated
*/
public boolean getInjectRemotePlugins()
{
return injectRemotePlugins;
}

public void setRemoteRESTOverrides( Map<ArtifactRef, String> overrides )
{
for ( ArtifactRef a : overrides.keySet() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ pluginManagement=org.commonjava.maven.ext.integration-test\:pluginMgmt2\:1.0
project.meta.skip=true
project.src.skip=true
overrideTransitive=false
injectRemotePlugins=true
strictAlignment=false
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,3 @@ assert plugin != null
assert plugin.version.text() == "3.1"

assert pom.build.pluginManagement.plugins.list().size() == 1

plugin = pom.build.plugins.plugin.find { it.artifactId.text() == "maven-bundle-plugin" }
assert plugin != null
assert plugin.version.text() == "2.5.4"

System.out.println (" pom.build.plugins.size " + pom.build.plugins.size())
assert pom.build.plugins.list().size() == 1
34 changes: 0 additions & 34 deletions integration-test/src/it/setup/pluginMgmt2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,6 @@
</plugins>
</pluginManagement>


<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.4</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-URL>${project.url}</Implementation-URL>
<Java-Version>${java.version}</Java-Version>
<Java-Vendor>${java.vendor}</Java-Vendor>
<Os-Name>${os.name}</Os-Name>
<Os-Arch>${os.arch}</Os-Arch>
<Os-Version>${os.version}</Os-Version>
<Scm-Url>${project.scm.url}</Scm-Url>
<Scm-Connection>${project.scm.connection}</Scm-Connection>
</manifestEntries>
</archive>
<instructions>
<Scm-Revision>${buildNumber}</Scm-Revision>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<configuration>
<quiet>true</quiet>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

0 comments on commit d0ece46

Please sign in to comment.