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

[MNG-7055] Fix G level metadata handling in 3.9.x #691

Merged
merged 4 commits into from
Apr 22, 2022
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
5 changes: 5 additions & 0 deletions maven-compat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ under the License.
<artifactId>wagon-provider-api</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.session.scope.internal.SessionScope;
import org.codehaus.plexus.util.FileUtils;

import static org.mockito.Mockito.mock;

/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/
Expand All @@ -34,12 +38,16 @@ public class ArtifactDeployerTest
{
private ArtifactDeployer artifactDeployer;

private SessionScope sessionScope;

protected void setUp()
throws Exception
{
super.setUp();

artifactDeployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE );

sessionScope = lookup( SessionScope.class );
}

protected String component()
Expand All @@ -50,18 +58,28 @@ protected String component()
public void testArtifactInstallation()
throws Exception
{
String artifactBasedir = new File( getBasedir(), "src/test/resources/artifact-install" ).getAbsolutePath();
sessionScope.enter();
try
{
sessionScope.seed(MavenSession.class, mock(MavenSession.class));

String artifactBasedir = new File( getBasedir(), "src/test/resources/artifact-install" ).getAbsolutePath();

Artifact artifact = createArtifact( "artifact", "1.0" );
Artifact artifact = createArtifact( "artifact", "1.0" );

File file = new File( artifactBasedir, "artifact-1.0.jar" );
assertEquals( "dummy", FileUtils.fileRead( file, "UTF-8" ).trim() );
File file = new File( artifactBasedir, "artifact-1.0.jar" );
assertEquals( "dummy", FileUtils.fileRead( file, "UTF-8" ).trim() );

artifactDeployer.deploy( file, artifact, remoteRepository(), localRepository() );
artifactDeployer.deploy( file, artifact, remoteRepository(), localRepository() );

ArtifactRepository remoteRepository = remoteRepository();
File deployedFile = new File( remoteRepository.getBasedir(), remoteRepository.pathOf( artifact ) );
assertTrue( deployedFile.exists() );
assertEquals( "dummy", FileUtils.fileRead( deployedFile, "UTF-8" ).trim() );
ArtifactRepository remoteRepository = remoteRepository();
File deployedFile = new File( remoteRepository.getBasedir(), remoteRepository.pathOf( artifact ) );
assertTrue( deployedFile.exists() );
assertEquals( "dummy", FileUtils.fileRead( deployedFile, "UTF-8" ).trim() );
}
finally
{
sessionScope.exit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.session.scope.internal.SessionScope;

import static org.mockito.Mockito.mock;

/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
Expand All @@ -32,12 +36,16 @@ public class ArtifactInstallerTest
{
private ArtifactInstaller artifactInstaller;

private SessionScope sessionScope;

protected void setUp()
throws Exception
{
super.setUp();

artifactInstaller = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE );

sessionScope = lookup( SessionScope.class );
}

protected String component()
Expand All @@ -48,14 +56,24 @@ protected String component()
public void testArtifactInstallation()
throws Exception
{
String artifactBasedir = new File( getBasedir(), "src/test/resources/artifact-install" ).getAbsolutePath();
sessionScope.enter();
try
{
sessionScope.seed(MavenSession.class, mock(MavenSession.class));

String artifactBasedir = new File( getBasedir(), "src/test/resources/artifact-install" ).getAbsolutePath();

Artifact artifact = createArtifact( "artifact", "1.0" );
Artifact artifact = createArtifact( "artifact", "1.0" );

File source = new File( artifactBasedir, "artifact-1.0.jar" );
File source = new File( artifactBasedir, "artifact-1.0.jar" );

artifactInstaller.install( source, artifact, localRepository() );
artifactInstaller.install( source, artifact, localRepository() );

assertLocalArtifactPresent( artifact );
assertLocalArtifactPresent( artifact );
}
finally
{
sessionScope.exit();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package org.apache.maven.execution.infoproviders;

/*
* 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 java.util.Objects;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Plugin;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.internal.PluginsMetadataInfoProvider;
import org.apache.maven.repository.legacy.metadata.ArtifactMetadata;
import org.eclipse.aether.artifact.Artifact;

import static java.util.Objects.requireNonNull;

/**
* Default implementation of {@link PluginsMetadataInfoProvider}.
*/
@Named
@Singleton
public class DefaultPluginsMetadataInfoProvider
implements PluginsMetadataInfoProvider
{
private final Provider<MavenSession> mavenSessionProvider;

@Inject
public DefaultPluginsMetadataInfoProvider( final Provider<MavenSession> mavenSessionProvider )
{
this.mavenSessionProvider = requireNonNull( mavenSessionProvider );
}

@Override
public PluginInfo getPluginInfo( final Artifact artifact )
{
MavenSession mavenSession = mavenSessionProvider.get();
if ( mavenSession != null )
{
MavenProject mavenProject = searchForProject( mavenSession, artifact );
if ( mavenProject != null && "maven-plugin".equals( mavenProject.getPackaging() ) )
{
Plugin plugin = searchForPluginGroupLevelRepositoryMetadata( mavenProject );

if ( plugin != null )
{
return new PluginInfo()
{
@Override
public String getPluginGroupId()
{
return artifact.getGroupId();
}

@Override
public String getPluginArtifactId()
{
return artifact.getArtifactId();
}

@Override
public String getPluginPrefix()
{
return plugin.getPrefix();
}

@Override
public String getPluginName()
{
return plugin.getName();
}
};
}
}
}

return null;
}

private MavenProject searchForProject( MavenSession mavenSession, Artifact artifact )
{
for ( MavenProject mavenProject : mavenSession.getProjects() )
{
if ( mavenProject.getArtifact() != null
&& Objects.equals( mavenProject.getGroupId(), artifact.getGroupId() )
&& Objects.equals( mavenProject.getArtifactId(), artifact.getArtifactId() ) )
{
return mavenProject;
}
}
return null;
}

private Plugin searchForPluginGroupLevelRepositoryMetadata( MavenProject mavenProject )
{
org.apache.maven.artifact.Artifact projectArtifact = mavenProject.getArtifact();
for ( ArtifactMetadata artifactMetadata : projectArtifact.getMetadataList() )
{
if ( artifactMetadata instanceof RepositoryMetadata )
{
RepositoryMetadata repositoryMetadata = (RepositoryMetadata) artifactMetadata;
Metadata metadata = repositoryMetadata.getMetadata();

for ( Plugin plugin : metadata.getPlugins() )
{
if ( Objects.equals( plugin.getArtifactId(), mavenProject.getArtifactId() ) )
{
return plugin;
}
}
}
}
return null;
}
}
28 changes: 14 additions & 14 deletions maven-core/src/main/resources/META-INF/plexus/default-bindings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Mappings to default lifecycle, specific for each packaging.
<!-- START SNIPPET: pom-lifecycle -->
<phases>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy
</deploy>
</phases>
<!-- END SNIPPET: pom-lifecycle -->
Expand Down Expand Up @@ -85,10 +85,10 @@ Mappings to default lifecycle, specific for each packaging.
org.apache.maven.plugins:maven-jar-plugin:2.4:jar
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy
</deploy>
</phases>
<!-- END SNIPPET: jar-lifecycle -->
Expand Down Expand Up @@ -129,10 +129,10 @@ Mappings to default lifecycle, specific for each packaging.
org.apache.maven.plugins:maven-ejb-plugin:2.3:ejb
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy
</deploy>
</phases>
<!-- END SNIPPET: ejb-lifecycle -->
Expand Down Expand Up @@ -177,10 +177,10 @@ Mappings to default lifecycle, specific for each packaging.
org.apache.maven.plugins:maven-plugin-plugin:3.2:addPluginArtifactMetadata
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy
</deploy>
</phases>
<!-- END SNIPPET: maven-plugin-lifecycle -->
Expand Down Expand Up @@ -221,10 +221,10 @@ Mappings to default lifecycle, specific for each packaging.
org.apache.maven.plugins:maven-war-plugin:2.2:war
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy
</deploy>
</phases>
<!-- END SNIPPET: war-lifecycle -->
Expand Down Expand Up @@ -256,10 +256,10 @@ Mappings to default lifecycle, specific for each packaging.
org.apache.maven.plugins:maven-ear-plugin:2.8:ear
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy
</deploy>
</phases>
<!-- END SNIPPET: ear-lifecycle -->
Expand Down Expand Up @@ -300,10 +300,10 @@ Mappings to default lifecycle, specific for each packaging.
org.apache.maven.plugins:maven-rar-plugin:2.2:rar
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy
</deploy>
</phases>
<!-- END SNIPPET: rar-lifecycle -->
Expand Down
Loading