Skip to content

Commit

Permalink
Maven 3.9.x changes for upcoming resolver 1.9.0
Browse files Browse the repository at this point in the history
Changes:
- hook in lifecycle
- provide plexus context for parameter  injection
  • Loading branch information
cstamas committed Nov 2, 2022
1 parent 3212efe commit 0cbd9b3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
3 changes: 3 additions & 0 deletions maven-core/src/main/java/org/apache/maven/DefaultMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ private void afterSessionEnd( Collection<MavenProject> projects, MavenSession se
}
}

/**
* TODO: why is this method public?
*/
public RepositorySystemSession newRepositorySession( MavenExecutionRequest request )
{
return repositorySessionFactory.newRepositorySession( request );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.apache.maven.internal.aether;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import org.eclipse.aether.RepositorySystem;
import org.eclipse.sisu.EagerSingleton;

import static java.util.Objects.requireNonNull;

/**
* Maven internal component that bridges container "shut down" to {@link RepositorySystem#shutdown()}.
*
* @since 3.9.0
*/
@Named
@EagerSingleton
public final class ResolverLifecycle
{
private final Provider<RepositorySystem> repositorySystemProvider;

@Inject
public ResolverLifecycle( Provider<RepositorySystem> repositorySystemProvider )
{
this.repositorySystemProvider = requireNonNull( repositorySystemProvider );
}

@PreDestroy
public void shutdown()
{
repositorySystemProvider.get().shutdown();
}
}
24 changes: 22 additions & 2 deletions maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -637,7 +638,8 @@ PlexusContainer container( CliRequest cliRequest )

ContainerConfiguration cc = new DefaultContainerConfiguration().setClassWorld( cliRequest.classWorld )
.setRealm( containerRealm ).setClassPathScanning( PlexusConstants.SCANNING_INDEX ).setAutoWiring( true )
.setJSR250Lifecycle( true ).setName( "maven" );
.setJSR250Lifecycle( true ).setName( "maven" )
.setContext( plexusContext( cliRequest ) );

Set<String> exportedArtifacts = new HashSet<>( coreEntry.getExportedArtifacts() );
Set<String> exportedPackages = new HashSet<>( coreEntry.getExportedPackages() );
Expand Down Expand Up @@ -731,7 +733,8 @@ private List<CoreExtensionEntry> loadCoreExtensions( CliRequest cliRequest, Clas
.setClassPathScanning( PlexusConstants.SCANNING_INDEX ) //
.setAutoWiring( true ) //
.setJSR250Lifecycle( true ) //
.setName( "maven" );
.setName( "maven" )
.setContext( plexusContext( cliRequest ) );

DefaultPlexusContainer container = new DefaultPlexusContainer( cc, new AbstractModule()
{
Expand Down Expand Up @@ -790,6 +793,23 @@ private List<CoreExtension> readCoreExtensionsDescriptor( File extensionsFile )

}

/**
* Sets up Plexus context map, that makes possible named parameters injection into components managed by the
* container.
*
* @param cliRequest The CLI request to source system and user properties from.
* @return The "context" map to be used with Plexus Container.
* @see <a href="https://www.eclipse.org/sisu/docs/api/org.eclipse.sisu.inject/reference/org/eclipse/sisu/Parameters.html">Sisu Parameters</a>
* @see <a href="https://github.com/eclipse/sisu.plexus/wiki/Plexus-to-JSR330#configuration">Configuration</a>
*/
private Map<Object, Object> plexusContext( CliRequest cliRequest )
{
HashMap<Object, Object> result = new HashMap<>();
result.putAll( cliRequest.systemProperties );
result.putAll( cliRequest.userProperties );
return result;
}

private ClassRealm setupContainerRealm( ClassWorld classWorld, ClassRealm coreRealm, List<File> extClassPath,
List<CoreExtensionEntry> extensions )
throws Exception
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ under the License.
<securityDispatcherVersion>2.0</securityDispatcherVersion>
<cipherVersion>2.0</cipherVersion>
<jxpathVersion>1.3</jxpathVersion>
<resolverVersion>1.8.2</resolverVersion>
<resolverVersion>1.9.0-SNAPSHOT</resolverVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<xmlunitVersion>2.2.1</xmlunitVersion>
<powermockVersion>1.7.4</powermockVersion>
Expand Down

0 comments on commit 0cbd9b3

Please sign in to comment.