You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2021/09/22 13:21:00 UTC
[maven] 01/01: [MNG-6898] Convert DefaultLifecyclePluginAnalyzer to
JSR330
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch MNG-6898-DefaultLifecyclePluginAnalyzer-hack
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 644c72418cfaf93afb356969081f5e0c2b24aec6
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Wed Sep 22 15:19:03 2021 +0200
[MNG-6898] Convert DefaultLifecyclePluginAnalyzer to JSR330
https://issues.apache.org/jira/browse/MNG-6898
This is a hackish solution for the conversion.
Issue is correct, w/o hack the MavenITmng4385LifecycleMappingFromExtensionInReactorTest
IT fails, while with this hack all ITs pass.
Still, I consider this hack, and probably could be solved
on much better way as well.
---
.../maven/internal/sisu/VisibleBeansHelper.java | 67 ++++++++++++++++++++++
.../internal/DefaultLifecyclePluginAnalyzer.java | 33 +++++++----
2 files changed, 89 insertions(+), 11 deletions(-)
diff --git a/maven-core/src/main/java/org/apache/maven/internal/sisu/VisibleBeansHelper.java b/maven-core/src/main/java/org/apache/maven/internal/sisu/VisibleBeansHelper.java
new file mode 100644
index 0000000..9c16db1
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/internal/sisu/VisibleBeansHelper.java
@@ -0,0 +1,67 @@
+package org.apache.maven.internal.sisu;
+
+/*
+ * 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.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import com.google.inject.Key;
+import org.eclipse.sisu.inject.BeanLocator;
+import org.eclipse.sisu.plexus.ClassRealmManager;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Helper class for artificial lookup filtered by "visibility" (Plexus realm visibility) but not using Plexus but
+ * pure Sisu.
+ */
+@Singleton
+@Named
+public final class VisibleBeansHelper
+{
+ private final BeanLocator beanLocator;
+
+ @Inject
+ public VisibleBeansHelper( final BeanLocator beanLocator )
+ {
+ this.beanLocator = requireNonNull( beanLocator );
+ }
+
+ public <T> Map<String, T> lookupMap( final Class<T> clazz )
+ {
+ final Key<T> key = Key.get( clazz, com.google.inject.name.Named.class );
+ final Set<String> realmNames = ClassRealmManager.visibleRealmNames( ClassRealmManager.contextRealm() );
+ HashMap<String, T> result = new HashMap<>();
+ beanLocator.locate( key ).forEach( b ->
+ {
+ final String source = String.valueOf( b.getSource() );
+ if ( !source.startsWith( "ClassRealm" ) || realmNames == null || realmNames.contains( source ) )
+ {
+ result.put( ( ( com.google.inject.name.Named ) b.getKey() ).value(), b.getProvider().get() );
+ }
+ } );
+ return result;
+ }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
index f1bb442..542041b 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
@@ -27,6 +27,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.maven.internal.sisu.VisibleBeansHelper;
import org.apache.maven.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
import org.apache.maven.lifecycle.Lifecycle;
@@ -37,12 +42,12 @@ import org.apache.maven.model.InputLocation;
import org.apache.maven.model.InputSource;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
+import static java.util.Objects.requireNonNull;
+
/**
* <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
*
@@ -52,24 +57,28 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
* @author jdcasey
* @author Kristian Rosenvold (extracted class only)
*/
-@Component( role = LifeCyclePluginAnalyzer.class )
+@Singleton
+@Named
public class DefaultLifecyclePluginAnalyzer
implements LifeCyclePluginAnalyzer
{
public static final String DEFAULTLIFECYCLEBINDINGS_MODELID = "org.apache.maven:maven-core:"
+ DefaultLifecyclePluginAnalyzer.class.getPackage().getImplementationVersion() + ":default-lifecycle-bindings";
- @Requirement( role = LifecycleMapping.class )
- private Map<String, LifecycleMapping> lifecycleMappings;
+ private final VisibleBeansHelper visibleBeansHelper;
- @Requirement
- private DefaultLifecycles defaultLifeCycles;
+ private final DefaultLifecycles defaultLifeCycles;
- @Requirement
- private Logger logger;
+ private final Logger logger;
- public DefaultLifecyclePluginAnalyzer()
+ @Inject
+ public DefaultLifecyclePluginAnalyzer( final VisibleBeansHelper visibleBeansHelper,
+ final DefaultLifecycles defaultLifeCycles,
+ final Logger logger )
{
+ this.visibleBeansHelper = requireNonNull( visibleBeansHelper );
+ this.defaultLifeCycles = requireNonNull( defaultLifeCycles );
+ this.logger = requireNonNull( logger );
}
// These methods deal with construction intact Plugin object that look like they come from a standard
@@ -82,6 +91,7 @@ public class DefaultLifecyclePluginAnalyzer
// from the plugin.xml inside a plugin.
//
+ @Override
public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
{
if ( logger.isDebugEnabled() )
@@ -90,7 +100,8 @@ public class DefaultLifecyclePluginAnalyzer
+ Thread.currentThread().getContextClassLoader() );
}
- LifecycleMapping lifecycleMappingForPackaging = lifecycleMappings.get( packaging );
+ LifecycleMapping lifecycleMappingForPackaging =
+ visibleBeansHelper.lookupMap( LifecycleMapping.class ).get( packaging );
if ( lifecycleMappingForPackaging == null )
{