From 0ddf3be40dd3cb1d9dab4519b9cbf0f9b777c9c0 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Sun, 13 Mar 2022 19:07:26 +0100 Subject: [PATCH 1/2] [MNG-7055] Fix G level metadata handling (#555) Maven Artifact Transfer silently prevents group level metadata to reach Resolver and causes metadata loss on install/deploy. Fix is to "bridge" this from maven-resolver-provider (and core) by reusing the actual metadata that m-plugin-p:addPluginArtifactMetadata mojo adds, but m-a-t filters out. This is backport of commit d141957ff5a3c08ae53c68e4ba19b49055f717c4 to maven-3.9.x branch. --- maven-compat/pom.xml | 5 + .../deployer/ArtifactDeployerTest.java | 36 +++-- .../installer/ArtifactInstallerTest.java | 28 +++- .../DefaultPluginsMetadataInfoProvider.java | 137 ++++++++++++++++++ .../META-INF/plexus/default-bindings.xml | 28 ++-- .../repository/internal/PluginsMetadata.java | 117 +++++++++++++++ .../internal/PluginsMetadataGenerator.java | 130 +++++++++++++++++ .../PluginsMetadataGeneratorFactory.java | 67 +++++++++ .../internal/PluginsMetadataInfoProvider.java | 47 ++++++ 9 files changed, 567 insertions(+), 28 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/execution/infoproviders/DefaultPluginsMetadataInfoProvider.java create mode 100644 maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadata.java create mode 100644 maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java create mode 100644 maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGeneratorFactory.java create mode 100644 maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataInfoProvider.java diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 4f79ac828cda..ed7bce84d794 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -99,6 +99,11 @@ under the License. wagon-provider-api + + org.mockito + mockito-core + test + org.apache.maven.wagon wagon-file diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java index f929f4801b8a..ed0a43cf78f6 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java @@ -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 Jason van Zyl */ @@ -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() @@ -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(); + } } } \ No newline at end of file diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java index 21bfb2b70b81..66ba9e968f97 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/installer/ArtifactInstallerTest.java @@ -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 Jason van Zyl @@ -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() @@ -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(); + } } } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/execution/infoproviders/DefaultPluginsMetadataInfoProvider.java b/maven-core/src/main/java/org/apache/maven/execution/infoproviders/DefaultPluginsMetadataInfoProvider.java new file mode 100644 index 000000000000..616a3a88a4bf --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/execution/infoproviders/DefaultPluginsMetadataInfoProvider.java @@ -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 mavenSessionProvider; + + @Inject + public DefaultPluginsMetadataInfoProvider( final Provider 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; + } +} diff --git a/maven-core/src/main/resources/META-INF/plexus/default-bindings.xml b/maven-core/src/main/resources/META-INF/plexus/default-bindings.xml index 4a303db572bc..e35f931596dd 100644 --- a/maven-core/src/main/resources/META-INF/plexus/default-bindings.xml +++ b/maven-core/src/main/resources/META-INF/plexus/default-bindings.xml @@ -41,10 +41,10 @@ Mappings to default lifecycle, specific for each packaging. - org.apache.maven.plugins:maven-install-plugin:2.4:install + org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install - org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy + org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy @@ -85,10 +85,10 @@ Mappings to default lifecycle, specific for each packaging. org.apache.maven.plugins:maven-jar-plugin:2.4:jar - org.apache.maven.plugins:maven-install-plugin:2.4:install + org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install - org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy + org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy @@ -129,10 +129,10 @@ Mappings to default lifecycle, specific for each packaging. org.apache.maven.plugins:maven-ejb-plugin:2.3:ejb - org.apache.maven.plugins:maven-install-plugin:2.4:install + org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install - org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy + org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy @@ -177,10 +177,10 @@ Mappings to default lifecycle, specific for each packaging. org.apache.maven.plugins:maven-plugin-plugin:3.2:addPluginArtifactMetadata - org.apache.maven.plugins:maven-install-plugin:2.4:install + org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install - org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy + org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy @@ -221,10 +221,10 @@ Mappings to default lifecycle, specific for each packaging. org.apache.maven.plugins:maven-war-plugin:2.2:war - org.apache.maven.plugins:maven-install-plugin:2.4:install + org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install - org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy + org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy @@ -256,10 +256,10 @@ Mappings to default lifecycle, specific for each packaging. org.apache.maven.plugins:maven-ear-plugin:2.8:ear - org.apache.maven.plugins:maven-install-plugin:2.4:install + org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install - org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy + org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy @@ -300,10 +300,10 @@ Mappings to default lifecycle, specific for each packaging. org.apache.maven.plugins:maven-rar-plugin:2.2:rar - org.apache.maven.plugins:maven-install-plugin:2.4:install + org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install - org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy + org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2:deploy diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadata.java new file mode 100644 index 000000000000..7a6c45abfe79 --- /dev/null +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadata.java @@ -0,0 +1,117 @@ +package org.apache.maven.repository.internal; + +/* + * 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.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; + +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.Plugin; +import org.apache.maven.repository.internal.PluginsMetadataInfoProvider.PluginInfo; +import org.eclipse.aether.artifact.Artifact; + +/** + * Plugin G level metadata. + */ +final class PluginsMetadata + extends MavenMetadata +{ + private final PluginInfo pluginInfo; + + PluginsMetadata( PluginInfo pluginInfo, Date timestamp ) + { + super( createRepositoryMetadata( pluginInfo ), null, timestamp ); + this.pluginInfo = pluginInfo; + } + + PluginsMetadata( PluginInfo pluginInfo, File file, Date timestamp ) + { + super( createRepositoryMetadata( pluginInfo ), file, timestamp ); + this.pluginInfo = pluginInfo; + } + + private static Metadata createRepositoryMetadata( PluginInfo pluginInfo ) + { + Metadata result = new Metadata(); + Plugin plugin = new Plugin(); + plugin.setPrefix( pluginInfo.getPluginPrefix() ); + plugin.setArtifactId( pluginInfo.getPluginArtifactId() ); + plugin.setName( pluginInfo.getPluginName() ); + result.getPlugins().add( plugin ); + return result; + } + + @Override + protected void merge( Metadata recessive ) + { + List recessivePlugins = recessive.getPlugins(); + List plugins = metadata.getPlugins(); + if ( !plugins.isEmpty() ) + { + LinkedHashMap mergedPlugins = new LinkedHashMap<>(); + recessivePlugins.forEach( p -> mergedPlugins.put( p.getPrefix(), p ) ); + plugins.forEach( p -> mergedPlugins.put( p.getPrefix(), p ) ); + metadata.setPlugins( new ArrayList<>( mergedPlugins.values() ) ); + } + } + + public Object getKey() + { + return getGroupId(); + } + + public static Object getKey( Artifact artifact ) + { + return artifact.getGroupId(); + } + + @Override + public MavenMetadata setFile( File file ) + { + return new PluginsMetadata( pluginInfo, file, timestamp ); + } + + @Override + public String getGroupId() + { + return pluginInfo.getPluginGroupId(); + } + + @Override + public String getArtifactId() + { + return ""; + } + + @Override + public String getVersion() + { + return ""; + } + + @Override + public Nature getNature() + { + return Nature.RELEASE_OR_SNAPSHOT; + } +} diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java new file mode 100644 index 000000000000..4f355686517c --- /dev/null +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGenerator.java @@ -0,0 +1,130 @@ +package org.apache.maven.repository.internal; + +/* + * 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.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.maven.repository.internal.PluginsMetadataInfoProvider.PluginInfo; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.deployment.DeployRequest; +import org.eclipse.aether.impl.MetadataGenerator; +import org.eclipse.aether.installation.InstallRequest; +import org.eclipse.aether.metadata.Metadata; +import org.eclipse.aether.util.ConfigUtils; + +import static java.util.Objects.requireNonNull; + +/** + * Plugin G level metadata. + */ +class PluginsMetadataGenerator + implements MetadataGenerator +{ + private final PluginsMetadataInfoProvider pluginsMetadataInfoProvider; + + private final Map plugins; + + private final Map processedPlugins; + + private final Date timestamp; + + PluginsMetadataGenerator( PluginsMetadataInfoProvider pluginsMetadataInfoProvider, + RepositorySystemSession session, + InstallRequest request ) + { + this( pluginsMetadataInfoProvider, session, request.getMetadata() ); + } + + PluginsMetadataGenerator( PluginsMetadataInfoProvider pluginsMetadataInfoProvider, + RepositorySystemSession session, + DeployRequest request ) + { + this( pluginsMetadataInfoProvider, session, request.getMetadata() ); + } + + private PluginsMetadataGenerator( PluginsMetadataInfoProvider pluginsMetadataInfoProvider, + RepositorySystemSession session, + Collection metadatas ) + { + this.pluginsMetadataInfoProvider = requireNonNull( pluginsMetadataInfoProvider ); + this.plugins = new LinkedHashMap<>(); + this.processedPlugins = new LinkedHashMap<>(); + this.timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" ); + + /* + * NOTE: This should be considered a quirk to support interop with Maven's legacy ArtifactDeployer which + * processes one artifact at a time and hence cannot associate the artifacts from the same project to use the + * same version index. Allowing the caller to pass in metadata from a previous deployment allows to re-establish + * the association between the artifacts of the same project. + */ + for ( Iterator it = metadatas.iterator(); it.hasNext(); ) + { + Metadata metadata = it.next(); + if ( metadata instanceof PluginsMetadata ) + { + it.remove(); + PluginsMetadata pluginMetadata = ( PluginsMetadata ) metadata; + processedPlugins.put( pluginMetadata.getKey(), pluginMetadata ); + } + } + } + + @Override + public Collection prepare( Collection artifacts ) + { + return Collections.emptyList(); + } + + @Override + public Artifact transformArtifact( Artifact artifact ) + { + return artifact; + } + + @Override + public Collection finish( Collection artifacts ) + { + for ( Artifact artifact : artifacts ) + { + PluginInfo pluginInfo = pluginsMetadataInfoProvider.getPluginInfo( artifact ); + if ( pluginInfo != null ) + { + Object key = PluginsMetadata.getKey( artifact ); + if ( processedPlugins.get( key ) == null ) + { + PluginsMetadata pluginMetadata = plugins.get( key ); + if ( pluginMetadata == null ) + { + pluginMetadata = new PluginsMetadata( pluginInfo, timestamp ); + plugins.put( key, pluginMetadata ); + } + } + } + } + + return plugins.values(); + } +} diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGeneratorFactory.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGeneratorFactory.java new file mode 100644 index 000000000000..19d499b25772 --- /dev/null +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataGeneratorFactory.java @@ -0,0 +1,67 @@ +package org.apache.maven.repository.internal; + +/* + * 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.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.deployment.DeployRequest; +import org.eclipse.aether.impl.MetadataGenerator; +import org.eclipse.aether.impl.MetadataGeneratorFactory; +import org.eclipse.aether.installation.InstallRequest; + +import static java.util.Objects.requireNonNull; + +/** + * Plugin G level metadata. + */ +@Named( "plugins" ) +@Singleton +public class PluginsMetadataGeneratorFactory + implements MetadataGeneratorFactory +{ + private final PluginsMetadataInfoProvider pluginsMetadataInfoProvider; + + @Inject + public PluginsMetadataGeneratorFactory( PluginsMetadataInfoProvider pluginsMetadataInfoProvider ) + { + this.pluginsMetadataInfoProvider = requireNonNull( pluginsMetadataInfoProvider ); + } + + @Override + public MetadataGenerator newInstance( RepositorySystemSession session, InstallRequest request ) + { + return new PluginsMetadataGenerator( pluginsMetadataInfoProvider, session, request ); + } + + @Override + public MetadataGenerator newInstance( RepositorySystemSession session, DeployRequest request ) + { + return new PluginsMetadataGenerator( pluginsMetadataInfoProvider, session, request ); + } + + @Override + public float getPriority() + { + return 5; + } +} diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataInfoProvider.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataInfoProvider.java new file mode 100644 index 000000000000..806fa46348be --- /dev/null +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadataInfoProvider.java @@ -0,0 +1,47 @@ +package org.apache.maven.repository.internal; + +/* + * 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 org.eclipse.aether.artifact.Artifact; + +/** + * Plugin G level metadata provider. + */ +public interface PluginsMetadataInfoProvider +{ + /** + * The required data for G level metadata. + */ + interface PluginInfo + { + String getPluginGroupId(); + + String getPluginArtifactId(); + + String getPluginPrefix(); + + String getPluginName(); + } + + /** + * Returns {@link PluginInfo} corresponding for passed in {@link Artifact}, or {@code null}. + */ + PluginInfo getPluginInfo( Artifact artifact ); +} From 765df54a9cd4a5c8e9a3810275750aaf471b7fed Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Sun, 13 Mar 2022 19:20:05 +0100 Subject: [PATCH 2/2] Pull in master Jenkinsfile --- Jenkinsfile | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4d411dbbde7c..60d4e8e2315b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,16 +21,16 @@ properties([buildDiscarder(logRotator(artifactNumToKeepStr: '5', numToKeepStr: e def buildOs = 'linux' def buildJdk = '8' -def buildMvn = '3.6.0' +def buildMvn = '3.6.3' def runITsOses = ['linux', 'windows'] -def runITsJdks = ['7', '8', '11','17'] -def runITsMvn = '3.6.0' +def runITsJdks = ['8', '11', '16', '17'] +def runITsMvn = '3.6.3' def runITscommand = "mvn clean install -Prun-its,embedded -B -U -V" // -DmavenDistro=... -Dmaven.test.failure.ignore=true def tests try { -def osNode = jenkinsEnv.labelForOS(buildOs) +def osNode = jenkinsEnv.labelForOS(buildOs) node(jenkinsEnv.nodeSelection(osNode)) { dir('build') { stage('Checkout') { @@ -52,17 +52,16 @@ node(jenkinsEnv.nodeSelection(osNode)) { withMaven(jdk: jdkName, maven: mvnName, mavenLocalRepo:"${WORK_DIR}/.repository", options:[ artifactsPublisher(disabled: false), junitPublisher(ignoreAttachments: false), - findbugsPublisher(disabled: false), - openTasksPublisher(disabled: false), - dependenciesFingerprintPublisher(), - invokerPublisher(), - pipelineGraphPublisher() - ]) { - sh "mvn clean ${MAVEN_GOAL} -B -U -e -fae -V -Dmaven.test.failure.ignore=true" + findbugsPublisher(disabled: true), + openTasksPublisher(disabled: true), + dependenciesFingerprintPublisher(disabled: false), + invokerPublisher(disabled: true), + pipelineGraphPublisher(disabled: false) + ], publisherStrategy: 'EXPLICIT') { + sh "mvn clean ${MAVEN_GOAL} -B -U -e -fae -V -Dmaven.test.failure.ignore -PversionlessMavenDist" } dir ('apache-maven/target') { - sh "mv apache-maven-*-bin.zip apache-maven-dist.zip" - stash includes: 'apache-maven-dist.zip', name: 'dist' + stash includes: 'apache-maven-bin.zip', name: 'maven-dist' } } @@ -91,21 +90,19 @@ for (String os in runITsOses) { def WORK_DIR=pwd() checkout tests if (isUnix()) { - sh "rm -rvf $WORK_DIR/apache-maven-dist.zip $WORK_DIR/it-local-repo" + sh "rm -rvf $WORK_DIR/dists $WORK_DIR/it-local-repo" } else { bat "if exist it-local-repo rmdir /s /q it-local-repo" - bat "if exist apache-maven-dist.zip del /q apache-maven-dist.zip" + bat "if exist dists rmdir /s /q dists" + } + dir('dists') { + unstash 'maven-dist' } - unstash 'dist' try { withMaven(jdk: jdkName, maven: mvnName, mavenLocalRepo:"${WORK_DIR}/it-local-repo", options:[ junitPublisher(ignoreAttachments: false) ]) { - String cmd = "${runITscommand} -DmavenDistro=$WORK_DIR/apache-maven-dist.zip -Dmaven.test.failure.ignore=true" - if (stageId.endsWith('-jdk7')) { - // Java 7u80 has TLS 1.2 disabled by default: need to explicitly enable - cmd = "${cmd} -Dhttps.protocols=TLSv1.2" - } + String cmd = "${runITscommand} -DmavenDistro=$WORK_DIR/dists/apache-maven-bin.zip -Dmaven.test.failure.ignore" if (isUnix()) { sh 'df -hT' @@ -160,8 +157,8 @@ parallel(runITsTasks) } finally { // notify completion stage("Notifications") { - jenkinsNotify() - } + jenkinsNotify() + } } def archiveDirs(stageId, archives) {