From c5c4cc94e2ff3bb8623662102625fe30d0c4b443 Mon Sep 17 00:00:00 2001 From: John Casey Date: Mon, 3 Feb 2014 16:26:37 -0600 Subject: [PATCH] split parent injection/relocation into separate modder from toolchain, and added implied activation of parent-realignment when toolchain-realignment is active. Two tests are failing...trying to figure out why still. --- src/main/java/com/redhat/rcm/version/Cli.java | 74 +++++++--------- .../rcm/version/mgr/VersionManager.java | 88 ++++++++++--------- .../rcm/version/mgr/mod/ParentModder.java | 85 ++++++++++++++++++ .../rcm/version/mgr/mod/ProjectModder.java | 30 ++++++- .../rcm/version/mgr/mod/ToolchainModder.java | 60 ------------- .../version/mgr/session/SessionBuilder.java | 14 ++- .../rcm/version/mgr/verify/BomVerifier.java | 14 ++- .../version/mgr/ToolchainManagementTest.java | 38 -------- .../rcm/version/mgr/mod/ParentModderTest.java | 67 ++++++++++++++ .../version/testutil/TestProjectFixture.java | 15 ++-- 10 files changed, 272 insertions(+), 213 deletions(-) create mode 100644 src/main/java/com/redhat/rcm/version/mgr/mod/ParentModder.java create mode 100644 src/test/java/com/redhat/rcm/version/mgr/mod/ParentModderTest.java diff --git a/src/main/java/com/redhat/rcm/version/Cli.java b/src/main/java/com/redhat/rcm/version/Cli.java index f8c90db..508a30a 100644 --- a/src/main/java/com/redhat/rcm/version/Cli.java +++ b/src/main/java/com/redhat/rcm/version/Cli.java @@ -233,8 +233,7 @@ public class Cli public static final String USE_EFFECTIVE_POMS_PROPERTY = "use-effective-poms"; - private static final File DEFAULT_BOOTSTRAP_CONFIG = new File( System.getProperty( "user.home" ), - ".vman.boot.properties" ); + private static final File DEFAULT_BOOTSTRAP_CONFIG = new File( System.getProperty( "user.home" ), ".vman.boot.properties" ); private static VersionManager vman; @@ -275,8 +274,7 @@ public static void main( final String[] args ) { parser.parseArgument( args ); - final boolean useLog = - !( cli.noLogFile || cli.testConfig || /*cli.help ||*/cli.helpModders || cli.showVersion || cli.helpReporters ); + final boolean useLog = !( cli.noLogFile || cli.testConfig || /*cli.help ||*/cli.helpModders || cli.showVersion || cli.helpReporters ); // System.out.printf( "--no-console: %s \n--no-log-file: %s \n--test-config: %s\n--help: %s\n--help-modifications: %s\n--version: %s\n\nUse logfile? %s\n\n", // cli.noConsole, cli.noLogFile, cli.testConfig, cli.help, cli.helpModders, @@ -426,8 +424,7 @@ private void testConfigAndPrintDiags() } System.out.println(); - System.out.printf( "Errors:\n-------------------------------------------------\n%s\n\n", - errors.isEmpty() ? "-NONE" : join( errors, "\n\n" ) ); + System.out.printf( "Errors:\n-------------------------------------------------\n%s\n\n", errors.isEmpty() ? "-NONE" : join( errors, "\n\n" ) ); System.out.println(); } @@ -461,8 +458,7 @@ private static void configureLogging( boolean useConsole, final boolean useLogFi final File dir = logFile.getParentFile(); if ( dir != null && !dir.isDirectory() && !dir.mkdirs() ) { - throw new RuntimeException( "Failed to create parent directory for logfile: " - + dir.getAbsolutePath() ); + throw new RuntimeException( "Failed to create parent directory for logfile: " + dir.getAbsolutePath() ); } final Handler fhandler = new FileHandler( logFile.getPath(), false ); fhandler.setFormatter( new VManFormatter() ); @@ -474,8 +470,7 @@ private static void configureLogging( boolean useConsole, final boolean useLogFi final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter( sw ); e.printStackTrace( pw ); - System.out.printf( "ERROR: Failed to initialize log file: %s. Reason: %s\n\n%s\n\n", logFile, - e.getMessage(), sw.toString() ); + System.out.printf( "ERROR: Failed to initialize log file: %s. Reason: %s\n\n%s\n\n", logFile, e.getMessage(), sw.toString() ); throw new RuntimeException( "Failed to initialize logfile." ); } @@ -501,7 +496,8 @@ public int run() final VersionManagerSession session = initSession(); - if ( session.getModderKeys().contains( "bom-realignment" ) && ( boms == null || boms.isEmpty() ) ) + if ( session.getModderKeys() + .contains( "bom-realignment" ) && ( boms == null || boms.isEmpty() ) ) { logger.error( "You must specify at least one BOM." ); return -2; @@ -510,9 +506,8 @@ public int run() if ( session.getErrors() .isEmpty() ) { - logger.info( "Modifying POM(s).\n\nTarget:\n\t" + target + "\n\nBOMs:\n\t" - + StringUtils.join( boms.iterator(), "\n\t" ) + "\n\nWorkspace:\n\t" + workspace + "\n\nReports:\n\t" - + reports ); + logger.info( "Modifying POM(s).\n\nTarget:\n\t" + target + "\n\nBOMs:\n\t" + StringUtils.join( boms.iterator(), "\n\t" ) + + "\n\nWorkspace:\n\t" + workspace + "\n\nReports:\n\t" + reports ); if ( target.isDirectory() ) { @@ -529,8 +524,7 @@ public int run() if ( capturePom != null && capturePom.exists() ) { - logger.warn( "\n\n\n\n\nMissing dependency/plugin information has been captured in:\n\n\t" - + capturePom.getAbsolutePath() + "\n\n\n\n" ); + logger.warn( "\n\n\n\n\nMissing dependency/plugin information has been captured in:\n\n\t" + capturePom.getAbsolutePath() + "\n\n\n\n" ); } final List errors = session.getErrors(); @@ -567,20 +561,19 @@ private VersionManagerSession initSession() final Logger logger = LoggerFactory.getLogger( getClass() ); logger.info( "modifications = " + join( modders, " " ) ); - final SessionBuilder builder = - new SessionBuilder( workspace, reports ).withVersionSuffix( versionSuffix ) - .withVersionModifier( versionModifier ) - .withRemovedPlugins( removedPlugins ) - .withRemovedTests( removedTests ) - .withExtensionsWhitelist( extensionsWhitelist ) - .withModders( modders ) - .withPreserveFiles( preserveFiles ) - .withStrict( strict ) - .withCoordinateRelocations( relocatedCoords ) - .withPropertyMappings( propertyMappings ) - .withExcludedModulePoms( pomExcludeModules ) - .withUseEffectivePoms( useEffectivePoms ) - .withUserProperties( reportProperties ); + final SessionBuilder builder = new SessionBuilder( workspace, reports ).withVersionSuffix( versionSuffix ) + .withVersionModifier( versionModifier ) + .withRemovedPlugins( removedPlugins ) + .withRemovedTests( removedTests ) + .withExtensionsWhitelist( extensionsWhitelist ) + .withModders( modders ) + .withPreserveFiles( preserveFiles ) + .withStrict( strict ) + .withCoordinateRelocations( relocatedCoords ) + .withPropertyMappings( propertyMappings ) + .withExcludedModulePoms( pomExcludeModules ) + .withUseEffectivePoms( useEffectivePoms ) + .withUserProperties( reportProperties ); final VersionManagerSession session = builder.build(); @@ -592,8 +585,7 @@ private VersionManagerSession initSession() } catch ( final MalformedURLException e ) { - throw new VManException( "Cannot initialize remote repositories: %s. Error: %s", e, remoteRepositories, - e.getMessage() ); + throw new VManException( "Cannot initialize remote repositories: %s. Error: %s", e, remoteRepositories, e.getMessage() ); } } @@ -772,8 +764,7 @@ private static void printTextLine( final String line, final String indent, final } } - private static void printKVLine( final String key, final String value, final String fmt, final int valMax, - final PrintWriter pw ) + private static void printKVLine( final String key, final String value, final String fmt, final int valMax, final PrintWriter pw ) { final List lines = new ArrayList(); @@ -892,7 +883,7 @@ else if ( key.startsWith( "+" ) ) if ( loadStandards ) { - mods.addAll( Arrays.asList( ProjectModder.STANDARD_MODIFICATIONS ) ); + mods.addAll( ProjectModder.STANDARD_MODIFICATIONS ); } modders = mods; @@ -1091,15 +1082,12 @@ private void loadConfiguration() if ( !strict ) { - strict = - Boolean.valueOf( props.getProperty( STRICT_MODE_PROPERTY, Boolean.toString( Boolean.FALSE ) ) ); + strict = Boolean.valueOf( props.getProperty( STRICT_MODE_PROPERTY, Boolean.toString( Boolean.FALSE ) ) ); } if ( !useEffectivePoms ) { - useEffectivePoms = - Boolean.valueOf( props.getProperty( USE_EFFECTIVE_POMS_PROPERTY, - Boolean.toString( Boolean.FALSE ) ) ); + useEffectivePoms = Boolean.valueOf( props.getProperty( USE_EFFECTIVE_POMS_PROPERTY, Boolean.toString( Boolean.FALSE ) ) ); } if ( truststorePath == null ) @@ -1205,16 +1193,14 @@ else if ( DEFAULT_BOOTSTRAP_CONFIG.exists() && DEFAULT_BOOTSTRAP_CONFIG.canRead( logger.info( "Reading configuration from: " + configLocation ); try { - final File file = - getFile( configLocation, new File( System.getProperty( "java.io.tmpdir" ) ), true ); + final File file = getFile( configLocation, new File( System.getProperty( "java.io.tmpdir" ) ), true ); logger.info( "...downloaded to file: " + file ); return file; } catch ( final VManException e ) { - logger.error( "Failed to download configuration from: " + configLocation + ". Reason: " - + e.getMessage(), e ); + logger.error( "Failed to download configuration from: " + configLocation + ". Reason: " + e.getMessage(), e ); throw e; } } diff --git a/src/main/java/com/redhat/rcm/version/mgr/VersionManager.java b/src/main/java/com/redhat/rcm/version/mgr/VersionManager.java index 33d27d9..03e1578 100644 --- a/src/main/java/com/redhat/rcm/version/mgr/VersionManager.java +++ b/src/main/java/com/redhat/rcm/version/mgr/VersionManager.java @@ -18,6 +18,7 @@ package com.redhat.rcm.version.mgr; +import static com.redhat.rcm.version.mgr.mod.ProjectModder.IMPLIED_MODIFICATIONS; import static com.redhat.rcm.version.util.InputUtils.getIncludedSubpaths; import static com.redhat.rcm.version.util.PomUtils.writeModifiedPom; import static org.apache.commons.io.IOUtils.closeQuietly; @@ -156,9 +157,8 @@ public void generateReports( final File reportsDir, final VersionManagerSession } } - public Set modifyVersions( final File dir, final String pomNamePattern, final String pomExcludePattern, - final List boms, final String toolchain, - final VersionManagerSession session ) + public Set modifyVersions( final File dir, final String pomNamePattern, final String pomExcludePattern, final List boms, + final String toolchain, final VersionManagerSession session ) throws VManException { final String[] includedSubpaths = getIncludedSubpaths( dir, pomNamePattern, pomExcludePattern, session ); @@ -189,15 +189,13 @@ public Set modifyVersions( final File dir, final String pomNamePattern, fi final Set outFiles = modVersions( dir, session, session.isPreserveFiles(), pomFileArray ); - logger.info( "Modified " + outFiles.size() + " POM versions in directory.\n\n\tDirectory: " + dir - + "\n\tBOMs:\t" + StringUtils.join( boms.iterator(), "\n\t\t" ) + "\n\tPOM Backups: " - + session.getBackups() + "\n\n" ); + logger.info( "Modified " + outFiles.size() + " POM versions in directory.\n\n\tDirectory: " + dir + "\n\tBOMs:\t" + + StringUtils.join( boms.iterator(), "\n\t\t" ) + "\n\tPOM Backups: " + session.getBackups() + "\n\n" ); return outFiles; } - public Set modifyVersions( File pom, final List boms, final String toolchain, - final VersionManagerSession session ) + public Set modifyVersions( File pom, final List boms, final String toolchain, final VersionManagerSession session ) throws VManException { try @@ -218,15 +216,13 @@ public Set modifyVersions( File pom, final List boms, final String .next(); logger.info( "Modified POM versions.\n\n\tTop POM: " + out + "\n\tBOMs:\t" - + ( boms == null ? "-NONE-" : StringUtils.join( boms.iterator(), "\n\t\t" ) ) + "\n\tPOM Backups: " - + session.getBackups() + "\n\n" ); + + ( boms == null ? "-NONE-" : StringUtils.join( boms.iterator(), "\n\t\t" ) ) + "\n\tPOM Backups: " + session.getBackups() + "\n\n" ); } return result; } - public void configureSession( final List boms, final String toolchain, final VersionManagerSession session, - final File... pomFiles ) + public void configureSession( final List boms, final String toolchain, final VersionManagerSession session, final File... pomFiles ) throws VManException { sessionConfigurator.configureSession( boms, toolchain, session, pomFiles ); @@ -262,13 +258,11 @@ protected LinkedHashSet loadProjectWithModules( final File topPom, fina } catch ( final IOException e ) { - session.addError( new VManException( "Failed to build model for POM: %s.\n--> %s", e, pom, - e.getMessage() ) ); + session.addError( new VManException( "Failed to build model for POM: %s.\n--> %s", e, pom, e.getMessage() ) ); } catch ( final XmlPullParserException e ) { - session.addError( new VManException( "Failed to build model for POM: %s.\n--> %s", e, pom, - e.getMessage() ) ); + session.addError( new VManException( "Failed to build model for POM: %s.\n--> %s", e, pom, e.getMessage() ) ); } finally { @@ -293,8 +287,7 @@ protected LinkedHashSet loadProjectWithModules( final File topPom, fina } catch ( final ModelBuildingException e ) { - session.addError( new VManException( "Failed to build model for POM: %s.\n--> %s", e, pom, - e.getMessage() ) ); + session.addError( new VManException( "Failed to build model for POM: %s.\n--> %s", e, pom, e.getMessage() ) ); } if ( mbResult == null ) @@ -358,15 +351,13 @@ protected List peekAtPomHierarchy( final File topPom, final VersionMana parent = parent.getCanonicalFile(); if ( parent.getParentFile() .getCanonicalPath() - .startsWith( topDir ) && parent.exists() && !seen.contains( parent ) - && !pendingPoms.contains( parent ) ) + .startsWith( topDir ) && parent.exists() && !seen.contains( parent ) && !pendingPoms.contains( parent ) ) { pendingPoms.add( parent ); } else { - logger.info( "Skipping reference to non-existent parent relativePath: '" + relPath + "' in: " - + pom ); + logger.info( "Skipping reference to non-existent parent relativePath: '" + relPath + "' in: " + pom ); } } @@ -386,8 +377,7 @@ protected List peekAtPomHierarchy( final File topPom, final VersionMana if ( modPom.getParentFile() .getCanonicalPath() - .startsWith( topDir ) && modPom.exists() && !seen.contains( modPom ) - && !pendingPoms.contains( modPom ) ) + .startsWith( topDir ) && modPom.exists() && !seen.contains( modPom ) && !pendingPoms.contains( modPom ) ) { pendingPoms.addLast( modPom ); } @@ -407,8 +397,7 @@ protected List peekAtPomHierarchy( final File topPom, final VersionMana return peeked; } - private synchronized ModelBuildingRequest newModelBuildingRequest( final File pom, - final VersionManagerSession session ) + private synchronized ModelBuildingRequest newModelBuildingRequest( final File pom, final VersionManagerSession session ) { if ( baseMbr == null ) { @@ -424,16 +413,14 @@ private synchronized ModelBuildingRequest newModelBuildingRequest( final File po final DefaultModelBuildingRequest req = new DefaultModelBuildingRequest( baseMbr ); req.setModelSource( new FileModelSource( pom ) ); - final VManModelResolver resolver = - new VManModelResolver( session, pom, artifactResolver, remoteRepositoryManager ); + final VManModelResolver resolver = new VManModelResolver( session, pom, artifactResolver, remoteRepositoryManager ); req.setModelResolver( resolver ); return req; } - private Set modVersions( final File basedir, final VersionManagerSession session, final boolean preserveDirs, - final File... pomFiles ) + private Set modVersions( final File basedir, final VersionManagerSession session, final boolean preserveDirs, final File... pomFiles ) { final Set result = new LinkedHashSet(); @@ -479,7 +466,8 @@ private Set modVersions( final File basedir, final VersionManagerSession s { logger.info( "Modifying '" + project.getKey() + "'..." ); - final List modderKeys = session.getModderKeys(); + List modderKeys = session.getModderKeys(); + modderKeys = calculateActualModderKeys( modderKeys ); Collections.sort( modderKeys, ProjectModder.KEY_COMPARATOR ); boolean changed = false; @@ -495,9 +483,8 @@ private Set modVersions( final File basedir, final VersionManagerSession s continue; } - logger.info( "Modifying '" + project.getKey() + " using: '" + key + "' with modder " - + modder.getClass() - .getName() ); + logger.info( "Modifying '" + project.getKey() + " using: '" + key + "' with modder " + modder.getClass() + .getName() ); changed = modder.inject( project, session ) || changed; } } @@ -554,16 +541,36 @@ private Set modVersions( final File basedir, final VersionManagerSession s capturer.captureMissing( session ); logger.warn( "\n\n\n\nMissing version information has been logged to:\n\n\t" + session.getCapturePom() - .getAbsolutePath() - + "\n\n\n\n" ); + .getAbsolutePath() + "\n\n\n\n" ); } return result; } - private File writePom( final Model model, final ProjectKey originalCoord, final String originalVersion, - final File pom, final File basedir, final VersionManagerSession session, - final boolean preserveDirs ) + private List calculateActualModderKeys( final List modders ) + { + final List keys = new ArrayList( modders ); + for ( final String key : modders ) + { + final Set implications = IMPLIED_MODIFICATIONS.get( key ); + if ( implications != null ) + { + final int idx = keys.indexOf( key ); + for ( final String implied : implications ) + { + if ( !keys.contains( implied ) ) + { + keys.add( idx, implied ); + } + } + } + } + + return keys; + } + + private File writePom( final Model model, final ProjectKey originalCoord, final String originalVersion, final File pom, final File basedir, + final VersionManagerSession session, final boolean preserveDirs ) { File backup = pom; @@ -590,8 +597,7 @@ private File writePom( final Model model, final ProjectKey originalCoord, final } catch ( final IOException e ) { - session.addError( new VManException( "Error making backup of POM: %s.\n\tTarget: %s\n\tReason: %s", e, - pom, backup, e.getMessage() ) ); + session.addError( new VManException( "Error making backup of POM: %s.\n\tTarget: %s\n\tReason: %s", e, pom, backup, e.getMessage() ) ); return null; } } diff --git a/src/main/java/com/redhat/rcm/version/mgr/mod/ParentModder.java b/src/main/java/com/redhat/rcm/version/mgr/mod/ParentModder.java new file mode 100644 index 0000000..5f0987f --- /dev/null +++ b/src/main/java/com/redhat/rcm/version/mgr/mod/ParentModder.java @@ -0,0 +1,85 @@ +package com.redhat.rcm.version.mgr.mod; + +import org.apache.maven.mae.project.key.FullProjectKey; +import org.apache.maven.mae.project.key.VersionlessProjectKey; +import org.apache.maven.model.Model; +import org.apache.maven.model.Parent; +import org.codehaus.plexus.component.annotations.Component; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.redhat.rcm.version.mgr.session.VersionManagerSession; +import com.redhat.rcm.version.model.Project; + +@Component( role = ProjectModder.class, hint = "parent-realignment" ) +public class ParentModder + implements ProjectModder +{ + + private final Logger logger = LoggerFactory.getLogger( getClass() ); + + @Override + public String getDescription() + { + return "Set the project's parent GAV using the declared toolchain GAV"; + } + + @Override + public boolean inject( final Project project, final VersionManagerSession session ) + { + final Model model = project.getModel(); + final FullProjectKey toolchainKey = session.getToolchainKey(); + + boolean changed = false; + Parent parent = model.getParent(); + + if ( toolchainKey != null ) + { + if ( parent == null ) + { + logger.info( "Injecting toolchain as parent for: " + project.getKey() ); + + parent = new Parent(); + parent.setGroupId( toolchainKey.getGroupId() ); + parent.setArtifactId( toolchainKey.getArtifactId() ); + parent.setVersion( toolchainKey.getVersion() ); + + model.setParent( parent ); + // session.addProject( project ); + + changed = true; + } + else + { + final FullProjectKey fullParentKey = new FullProjectKey( parent ); + final FullProjectKey relocation = session.getRelocation( fullParentKey ); + if ( relocation != null ) + { + logger.info( "Relocating parent: " + parent + " to: " + relocation ); + + parent.setGroupId( relocation.getGroupId() ); + parent.setArtifactId( relocation.getArtifactId() ); + parent.setVersion( relocation.getVersion() ); + changed = true; + } + + final VersionlessProjectKey vtk = new VersionlessProjectKey( toolchainKey.getGroupId(), toolchainKey.getArtifactId() ); + + final VersionlessProjectKey vpk = new VersionlessProjectKey( parent ); + + if ( vtk.equals( vpk ) && !toolchainKey.equals( fullParentKey ) ) + { + parent.setVersion( toolchainKey.getVersion() ); + changed = true; + } + } + } + else + { + logger.info( "Toolchain not specified. Skipping toolchain-parent injection..." ); + } + + return changed; + } + +} diff --git a/src/main/java/com/redhat/rcm/version/mgr/mod/ProjectModder.java b/src/main/java/com/redhat/rcm/version/mgr/mod/ProjectModder.java index 737c9cf..ef4ae66 100644 --- a/src/main/java/com/redhat/rcm/version/mgr/mod/ProjectModder.java +++ b/src/main/java/com/redhat/rcm/version/mgr/mod/ProjectModder.java @@ -18,7 +18,13 @@ package com.redhat.rcm.version.mgr.mod; +import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import com.redhat.rcm.version.mgr.session.VersionManagerSession; import com.redhat.rcm.version.model.Project; @@ -27,9 +33,29 @@ public interface ProjectModder { String STANDARD_MODS_ALIAS = "[standard]"; - String[] STANDARD_MODIFICATIONS = { "version-suffix", "toolchain-realignment", "bom-realignment", "repo-removal" }; + List STANDARD_MODIFICATIONS = new ArrayList() + { + { + add( "version-suffix" ); + add( "parent-realignment" ); + add( "toolchain-realignment" ); + add( "bom-realignment" ); + add( "repo-removal" ); + } + + private static final long serialVersionUID = 1L; + }; + + String[] MODIFICATION_ORDER = { "version-suffix", "version", "bom-realignment", "parent-realignment", "toolchain-realignment" }; - String[] MODIFICATION_ORDER = { "version-suffix", "version", "bom-realignment" }; + Map> IMPLIED_MODIFICATIONS = new HashMap>() + { + { + put( "toolchain-realignment", Collections.singleton( "parent-realignment" ) ); + } + + private static final long serialVersionUID = 1L; + }; Comparator KEY_COMPARATOR = new Comparator() { diff --git a/src/main/java/com/redhat/rcm/version/mgr/mod/ToolchainModder.java b/src/main/java/com/redhat/rcm/version/mgr/mod/ToolchainModder.java index 1af6d50..7b26f1a 100644 --- a/src/main/java/com/redhat/rcm/version/mgr/mod/ToolchainModder.java +++ b/src/main/java/com/redhat/rcm/version/mgr/mod/ToolchainModder.java @@ -33,7 +33,6 @@ import org.apache.maven.model.BuildBase; import org.apache.maven.model.Model; import org.apache.maven.model.ModelBase; -import org.apache.maven.model.Parent; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; import org.apache.maven.model.Profile; @@ -72,8 +71,6 @@ public boolean inject( final Project project, final VersionManagerSession sessio return changed; } - changed = attemptToolchainParentInjection( project, session ) || changed; - final Set pluginRefs = new HashSet(); pluginRefs.addAll( session.getChildPluginReferences( new VersionlessProjectKey( project.getKey() ) ) ); @@ -185,63 +182,6 @@ private boolean adjustReportPlugins( final Project project, final List pluginRefs, final VersionManagerSession session ) { logger.info( "Injecting pluginManagement section from toolchain for: " + project.getKey() ); diff --git a/src/main/java/com/redhat/rcm/version/mgr/session/SessionBuilder.java b/src/main/java/com/redhat/rcm/version/mgr/session/SessionBuilder.java index 695cf8e..890065a 100644 --- a/src/main/java/com/redhat/rcm/version/mgr/session/SessionBuilder.java +++ b/src/main/java/com/redhat/rcm/version/mgr/session/SessionBuilder.java @@ -17,6 +17,8 @@ package com.redhat.rcm.version.mgr.session; +import static com.redhat.rcm.version.mgr.mod.ProjectModder.STANDARD_MODIFICATIONS; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -31,13 +33,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.redhat.rcm.version.mgr.mod.ProjectModder; - public final class SessionBuilder { - public static final List STANDARD = - new ArrayList( Arrays.asList( ProjectModder.STANDARD_MODIFICATIONS ) ); - private final Logger logger = LoggerFactory.getLogger( getClass() ); private final File workspace; @@ -56,7 +53,7 @@ public final class SessionBuilder private Collection extensionsWhitelist = new HashSet(); - private final List modders = new ArrayList( STANDARD ); + private final List modders = new ArrayList( STANDARD_MODIFICATIONS ); private boolean preserveFiles = false; @@ -88,9 +85,8 @@ public SessionBuilder( final File workspace, final File reports ) public VersionManagerSession build() { final VersionManagerSession sess = - new VersionManagerSession( workspace, reports, versionSuffix, versionModifier, removedPlugins, - removedTests, extensionsWhitelist, modders, preserveFiles, strict, - useEffectivePoms, coordinateRelocations, propertyMappings, excludedModulePoms, + new VersionManagerSession( workspace, reports, versionSuffix, versionModifier, removedPlugins, removedTests, extensionsWhitelist, + modders, preserveFiles, strict, useEffectivePoms, coordinateRelocations, propertyMappings, excludedModulePoms, userProperties ); sess.setLocalRepositoryDirectory( localRepo == null ? new File( workspace, "local-repository" ) : localRepo ); diff --git a/src/main/java/com/redhat/rcm/version/mgr/verify/BomVerifier.java b/src/main/java/com/redhat/rcm/version/mgr/verify/BomVerifier.java index 7c48ea1..479e8c6 100644 --- a/src/main/java/com/redhat/rcm/version/mgr/verify/BomVerifier.java +++ b/src/main/java/com/redhat/rcm/version/mgr/verify/BomVerifier.java @@ -29,7 +29,7 @@ import com.redhat.rcm.version.util.CollectionToString; import com.redhat.rcm.version.util.ObjectToString; -@Component( role = ProjectVerifier.class, hint = "BOM-realignment" ) +@Component( role = ProjectVerifier.class, hint = "bom-realignment" ) public class BomVerifier implements ProjectVerifier { @@ -37,16 +37,12 @@ public class BomVerifier @Override public void verify( final Project project, final VersionManagerSession session ) { - Set missing = session.getMissingVersions( project.getKey() ); + final Set missing = session.getMissingVersions( project.getKey() ); if ( missing != null && !missing.isEmpty() ) { - session.addError( new VManException( - "The following dependencies were NOT found in a BOM.\nProject: %s\nFile: %s\nDependencies:\n\n%s\n", - project.getKey(), - project.getPom(), - new CollectionToString( - missing, - new ObjectToString() ) ) ); + session.addError( new VManException( "The following dependencies were NOT found in a BOM.\nProject: %s\nFile: %s\nDependencies:\n\n%s\n", + project.getKey(), project.getPom(), + new CollectionToString( missing, new ObjectToString() ) ) ); } } diff --git a/src/test/java/com/redhat/rcm/version/mgr/ToolchainManagementTest.java b/src/test/java/com/redhat/rcm/version/mgr/ToolchainManagementTest.java index e83ae44..adf4e2f 100644 --- a/src/test/java/com/redhat/rcm/version/mgr/ToolchainManagementTest.java +++ b/src/test/java/com/redhat/rcm/version/mgr/ToolchainManagementTest.java @@ -105,44 +105,6 @@ public void teardown() LoggingFixture.flushLogging(); } - @Test - public void relocateParent() - throws Throwable - { - final String path = "relocate-parent.pom"; - final Model original = loadModel( TOOLCHAIN_TEST_POMS + path ); - - final String toolchainPath = EMPTY_TOOLCHAIN_PATH; - final Model toolchainModel = loadModel( toolchainPath ); - final MavenProject toolchainProject = new MavenProject( toolchainModel ); - toolchainProject.setOriginalModel( toolchainModel ); - - Parent parent = original.getParent(); - assertThat( parent, notNullValue() ); - assertThat( parent.getArtifactId(), equalTo( "old-parent" ) ); - assertThat( parent.getVersion(), equalTo( "1.0" ) ); - - final Project project = new Project( original ); - final SessionBuilder builder = - new SessionBuilder( workspace, reports ).withCoordinateRelocation( "org.test:old-parent:1.0", "org.test:new-parent:2.0" ); - - final VersionManagerSession session = builder.build(); - session.setToolchain( new File( toolchainPath ), toolchainProject ); - - final boolean changed = new ToolchainModder().inject( project, session ); - - dumpModel( project.getModel() ); - - assertThat( changed, equalTo( true ) ); - assertNoErrors( session ); - - parent = project.getModel() - .getParent(); - assertThat( parent, notNullValue() ); - assertThat( parent.getArtifactId(), equalTo( "new-parent" ) ); - assertThat( parent.getVersion(), equalTo( "2.0" ) ); - } - @Test public void relocatePlugin() throws Throwable diff --git a/src/test/java/com/redhat/rcm/version/mgr/mod/ParentModderTest.java b/src/test/java/com/redhat/rcm/version/mgr/mod/ParentModderTest.java new file mode 100644 index 0000000..a0525f4 --- /dev/null +++ b/src/test/java/com/redhat/rcm/version/mgr/mod/ParentModderTest.java @@ -0,0 +1,67 @@ +package com.redhat.rcm.version.mgr.mod; + +import static com.redhat.rcm.version.testutil.TestProjectFixture.dumpModel; +import static com.redhat.rcm.version.testutil.TestProjectFixture.loadModel; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + +import java.io.File; + +import org.apache.maven.model.Model; +import org.apache.maven.model.Parent; +import org.apache.maven.project.MavenProject; +import org.junit.Test; + +import com.redhat.rcm.version.mgr.AbstractVersionManagerTest; +import com.redhat.rcm.version.mgr.session.SessionBuilder; +import com.redhat.rcm.version.mgr.session.VersionManagerSession; +import com.redhat.rcm.version.model.Project; + +public class ParentModderTest + extends AbstractVersionManagerTest +{ + + private static final String TOOLCHAIN_TEST_POMS = "toolchain/"; + + private static final String EMPTY_TOOLCHAIN_PATH = TOOLCHAIN_TEST_POMS + "toolchain-empty-1.0.pom"; + + @Test + public void relocateParent() + throws Throwable + { + final String path = "relocate-parent.pom"; + final Model original = loadModel( TOOLCHAIN_TEST_POMS + path ); + + final String toolchainPath = EMPTY_TOOLCHAIN_PATH; + final Model toolchainModel = loadModel( toolchainPath ); + final MavenProject toolchainProject = new MavenProject( toolchainModel ); + toolchainProject.setOriginalModel( toolchainModel ); + + Parent parent = original.getParent(); + assertThat( parent, notNullValue() ); + assertThat( parent.getArtifactId(), equalTo( "old-parent" ) ); + assertThat( parent.getVersion(), equalTo( "1.0" ) ); + + final Project project = new Project( original ); + final SessionBuilder builder = + new SessionBuilder( workspace, reports ).withCoordinateRelocation( "org.test:old-parent:1.0", "org.test:new-parent:2.0" ); + + final VersionManagerSession session = builder.build(); + session.setToolchain( new File( toolchainPath ), toolchainProject ); + + final boolean changed = new ParentModder().inject( project, session ); + + dumpModel( project.getModel() ); + + assertThat( changed, equalTo( true ) ); + assertNoErrors( session ); + + parent = project.getModel() + .getParent(); + assertThat( parent, notNullValue() ); + assertThat( parent.getArtifactId(), equalTo( "new-parent" ) ); + assertThat( parent.getVersion(), equalTo( "2.0" ) ); + } + +} diff --git a/src/test/java/com/redhat/rcm/version/testutil/TestProjectFixture.java b/src/test/java/com/redhat/rcm/version/testutil/TestProjectFixture.java index 7a52d6c..84f5c30 100644 --- a/src/test/java/com/redhat/rcm/version/testutil/TestProjectFixture.java +++ b/src/test/java/com/redhat/rcm/version/testutil/TestProjectFixture.java @@ -27,7 +27,6 @@ import java.io.StringWriter; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -82,25 +81,21 @@ public TestVersionManager getVman() // setCurrentProjects( session, Arrays.asList( models ) ); // } // - public static VersionManagerSession newVersionManagerSession( final File workspace, final File reports, - final String suffix, final String modifier ) + public static VersionManagerSession newVersionManagerSession( final File workspace, final File reports, final String suffix, final String modifier ) { return new SessionBuilder( workspace, reports ).withVersionSuffix( suffix ) .withVersionModifier( modifier ) .build(); } - public static VersionManagerSession newVersionManagerSession( final File workspace, final File reports, - final String suffix ) + public static VersionManagerSession newVersionManagerSession( final File workspace, final File reports, final String suffix ) { return new SessionBuilder( workspace, reports ).withVersionSuffix( suffix ) .build(); } - public static VersionManagerSession newVersionManagerSession( final File workspace, final File reports, - final String suffix, - final Collection removedPlugins, - final Collection removedTests ) + public static VersionManagerSession newVersionManagerSession( final File workspace, final File reports, final String suffix, + final Collection removedPlugins, final Collection removedTests ) { return new SessionBuilder( workspace, reports ).withVersionSuffix( suffix ) .withRemovedPlugins( removedPlugins ) @@ -110,7 +105,7 @@ public static VersionManagerSession newVersionManagerSession( final File workspa public static Set getStandardModders() { - return new HashSet( Arrays.asList( ProjectModder.STANDARD_MODIFICATIONS ) ); + return new HashSet( ProjectModder.STANDARD_MODIFICATIONS ); } public static File getResourceFile( final String path )