Skip to content

Commit

Permalink
[MNG-7600] LocalRepositoryManager is created too early
Browse files Browse the repository at this point in the history
LocalRepositoryManager needs configurations from RepositorySystemSession
so must be created after session configuration is finished.

(cherry picked from commit b1c1f75)
  • Loading branch information
slawekjaranowski committed Dec 18, 2022
1 parent ed84933 commit 8fd8a05
Showing 1 changed file with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,6 @@ else if ( request.isUpdateSnapshots() )

session.setArtifactTypeRegistry( RepositoryUtils.newArtifactTypeRegistry( artifactHandlerManager ) );

LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() );

if ( request.isUseLegacyLocalRepository() )
{
try
{
session.setLocalRepositoryManager( simpleLocalRepoMgrFactory.newInstance( session, localRepo ) );
logger.info( "Disabling enhanced local repository: using legacy is strongly discouraged to ensure"
+ " build reproducibility." );

}
catch ( NoLocalRepositoryManagerException e )
{
logger.error( "Failed to configure legacy local repository: falling back to default" );
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) );
}
}
else
{
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) );
}

if ( request.getWorkspaceReader() != null )
{
session.setWorkspaceReader( request.getWorkspaceReader() );
Expand Down Expand Up @@ -240,9 +218,35 @@ else if ( request.isUpdateSnapshots() )
mavenRepositorySystem.injectProxy( session, request.getPluginArtifactRepositories() );
mavenRepositorySystem.injectAuthentication( session, request.getPluginArtifactRepositories() );

setUpLocalRepositoryManager( request, session );

return session;
}

private void setUpLocalRepositoryManager( MavenExecutionRequest request, DefaultRepositorySystemSession session )
{
LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() );

if ( request.isUseLegacyLocalRepository() )
{
try
{
session.setLocalRepositoryManager( simpleLocalRepoMgrFactory.newInstance( session, localRepo ) );
logger.info( "Disabling enhanced local repository: using legacy is strongly discouraged to ensure"
+ " build reproducibility." );
}
catch ( NoLocalRepositoryManagerException e )
{
logger.error( "Failed to configure legacy local repository: falling back to default" );
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) );
}
}
else
{
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) );
}
}

private String getUserAgent()
{
String version = runtimeInformation.getMavenVersion();
Expand Down

0 comments on commit 8fd8a05

Please sign in to comment.