michael-o commented on code in PR #1411:
URL: https://github.com/apache/maven/pull/1411#discussion_r1559972665


##########
maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java:
##########
@@ -0,0 +1,321 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.Lifecycle;
+import org.apache.maven.api.services.LifecycleRegistry;
+import org.apache.maven.api.spi.LifecycleProvider;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.*;
+import static java.util.Collections.emptyList;
+import static org.apache.maven.internal.impl.Lifecycles.*;
+
+/**
+ * TODO: this is session scoped as SPI can contribute.
+ */
+@Named
+@Singleton
+public class DefaultLifecycleRegistry
+        extends 
ExtensibleEnumRegistries.DefaultExtensibleEnumRegistry<Lifecycle, 
LifecycleProvider>
+        implements LifecycleRegistry {
+
+    public DefaultLifecycleRegistry() {
+        super(Collections.emptyList());
+    }
+
+    @Inject
+    public DefaultLifecycleRegistry(
+            List<LifecycleProvider> providers, Map<String, 
org.apache.maven.lifecycle.Lifecycle> lifecycles) {
+        super(
+                concat(providers, new LifecycleWrapperProvider(lifecycles)),
+                new CleanLifecycle(),
+                new DefaultLifecycle(),
+                new SiteLifecycle(),
+                new WrapperLifecycle());
+        // validate lifecycle
+        for (Lifecycle lifecycle : this) {
+            Set<String> set = new HashSet<>();
+            lifecycle.allPhases().forEach(phase -> {
+                if (!set.add(phase.name())) {
+                    throw new IllegalArgumentException(
+                            "Found duplicated phase '" + phase.name() + "' in 
'" + lifecycle.id() + "' lifecycle");
+                }
+            });
+        }
+    }
+
+    @Override
+    public Iterator<Lifecycle> iterator() {
+        return values.values().iterator();
+    }
+
+    @Override
+    public Stream<Lifecycle> stream() {
+        return values.values().stream();
+    }
+
+    static <T> List<T> concat(List<T> l, T t) {
+        List<T> nl = new ArrayList<>();
+        nl.addAll(l);
+        nl.add(t);
+        return nl;
+    }
+
+    @Override
+    public List<String> computePhases(Lifecycle lifecycle) {
+        Graph graph = new Graph();
+        lifecycle.phases().forEach(phase -> addPhase(graph, null, null, 
phase));
+        lifecycle.aliases().forEach(alias -> {
+            String n = alias.v3Phase();
+            String a = alias.v4Phase();
+            String[] u = a.split(":");
+            Graph.Vertex v = graph.addVertex(n);
+            if (u.length > 1) {
+                if ("pre".equals(u[0])) {
+                    graph.addEdge(graph.addVertex("$" + u[1]), v);
+                    graph.addEdge(v, graph.addVertex("$$" + u[1]));
+                } else if ("post".equals(u[0])) {
+                    graph.addEdge(graph.addVertex(u[1]), v);
+                    graph.addEdge(v, graph.addVertex("$$$" + u[1]));
+                }
+            } else {
+                graph.addEdge(graph.addVertex("$$" + u[0]), v);
+                graph.addEdge(v, graph.addVertex(u[0]));
+            }
+        });
+        List<String> allPhases = graph.visitAll();
+        Collections.reverse(allPhases);
+        List<String> computed =
+                allPhases.stream().filter(s -> 
!s.startsWith("$")).collect(Collectors.toList());
+        List<String> given = lifecycle.orderedPhases().orElse(null);
+        if (given != null) {
+            if (given.size() != computed.size()) {
+                Set<String> s1 =
+                        given.stream().filter(s -> 
!computed.contains(s)).collect(Collectors.toSet());
+                Set<String> s2 =
+                        computed.stream().filter(s -> 
!given.contains(s)).collect(Collectors.toSet());
+                throw new IllegalArgumentException(

Review Comment:
   Why is it IAE instead of ISE?



##########
maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java:
##########
@@ -0,0 +1,321 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.Lifecycle;
+import org.apache.maven.api.services.LifecycleRegistry;
+import org.apache.maven.api.spi.LifecycleProvider;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.*;
+import static java.util.Collections.emptyList;
+import static org.apache.maven.internal.impl.Lifecycles.*;
+
+/**
+ * TODO: this is session scoped as SPI can contribute.
+ */
+@Named
+@Singleton
+public class DefaultLifecycleRegistry
+        extends 
ExtensibleEnumRegistries.DefaultExtensibleEnumRegistry<Lifecycle, 
LifecycleProvider>
+        implements LifecycleRegistry {
+
+    public DefaultLifecycleRegistry() {
+        super(Collections.emptyList());
+    }
+
+    @Inject
+    public DefaultLifecycleRegistry(
+            List<LifecycleProvider> providers, Map<String, 
org.apache.maven.lifecycle.Lifecycle> lifecycles) {
+        super(
+                concat(providers, new LifecycleWrapperProvider(lifecycles)),
+                new CleanLifecycle(),
+                new DefaultLifecycle(),
+                new SiteLifecycle(),
+                new WrapperLifecycle());
+        // validate lifecycle
+        for (Lifecycle lifecycle : this) {
+            Set<String> set = new HashSet<>();
+            lifecycle.allPhases().forEach(phase -> {
+                if (!set.add(phase.name())) {
+                    throw new IllegalArgumentException(
+                            "Found duplicated phase '" + phase.name() + "' in 
'" + lifecycle.id() + "' lifecycle");
+                }
+            });
+        }
+    }
+
+    @Override
+    public Iterator<Lifecycle> iterator() {
+        return values.values().iterator();

Review Comment:
   Is this remove-safe?



##########
maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java:
##########
@@ -18,8 +18,8 @@
  */
 package org.apache.maven.lifecycle;
 
-import java.util.List;
-import java.util.Map;
+import java.util.*;

Review Comment:
   Shouldn't we avoid this?



##########
maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java:
##########
@@ -0,0 +1,321 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.Lifecycle;
+import org.apache.maven.api.services.LifecycleRegistry;
+import org.apache.maven.api.spi.LifecycleProvider;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.*;
+import static java.util.Collections.emptyList;
+import static org.apache.maven.internal.impl.Lifecycles.*;
+
+/**
+ * TODO: this is session scoped as SPI can contribute.
+ */
+@Named
+@Singleton
+public class DefaultLifecycleRegistry
+        extends 
ExtensibleEnumRegistries.DefaultExtensibleEnumRegistry<Lifecycle, 
LifecycleProvider>
+        implements LifecycleRegistry {
+
+    public DefaultLifecycleRegistry() {
+        super(Collections.emptyList());
+    }
+
+    @Inject
+    public DefaultLifecycleRegistry(
+            List<LifecycleProvider> providers, Map<String, 
org.apache.maven.lifecycle.Lifecycle> lifecycles) {
+        super(
+                concat(providers, new LifecycleWrapperProvider(lifecycles)),
+                new CleanLifecycle(),
+                new DefaultLifecycle(),
+                new SiteLifecycle(),
+                new WrapperLifecycle());
+        // validate lifecycle
+        for (Lifecycle lifecycle : this) {
+            Set<String> set = new HashSet<>();
+            lifecycle.allPhases().forEach(phase -> {
+                if (!set.add(phase.name())) {
+                    throw new IllegalArgumentException(
+                            "Found duplicated phase '" + phase.name() + "' in 
'" + lifecycle.id() + "' lifecycle");
+                }
+            });
+        }
+    }
+
+    @Override
+    public Iterator<Lifecycle> iterator() {
+        return values.values().iterator();
+    }
+
+    @Override
+    public Stream<Lifecycle> stream() {
+        return values.values().stream();
+    }
+
+    static <T> List<T> concat(List<T> l, T t) {
+        List<T> nl = new ArrayList<>();
+        nl.addAll(l);
+        nl.add(t);
+        return nl;
+    }
+
+    @Override
+    public List<String> computePhases(Lifecycle lifecycle) {
+        Graph graph = new Graph();
+        lifecycle.phases().forEach(phase -> addPhase(graph, null, null, 
phase));
+        lifecycle.aliases().forEach(alias -> {
+            String n = alias.v3Phase();
+            String a = alias.v4Phase();
+            String[] u = a.split(":");
+            Graph.Vertex v = graph.addVertex(n);
+            if (u.length > 1) {
+                if ("pre".equals(u[0])) {
+                    graph.addEdge(graph.addVertex("$" + u[1]), v);
+                    graph.addEdge(v, graph.addVertex("$$" + u[1]));
+                } else if ("post".equals(u[0])) {
+                    graph.addEdge(graph.addVertex(u[1]), v);
+                    graph.addEdge(v, graph.addVertex("$$$" + u[1]));
+                }
+            } else {
+                graph.addEdge(graph.addVertex("$$" + u[0]), v);
+                graph.addEdge(v, graph.addVertex(u[0]));
+            }
+        });
+        List<String> allPhases = graph.visitAll();
+        Collections.reverse(allPhases);
+        List<String> computed =
+                allPhases.stream().filter(s -> 
!s.startsWith("$")).collect(Collectors.toList());
+        List<String> given = lifecycle.orderedPhases().orElse(null);
+        if (given != null) {
+            if (given.size() != computed.size()) {
+                Set<String> s1 =
+                        given.stream().filter(s -> 
!computed.contains(s)).collect(Collectors.toSet());
+                Set<String> s2 =
+                        computed.stream().filter(s -> 
!given.contains(s)).collect(Collectors.toSet());
+                throw new IllegalArgumentException(
+                        "List of phases differ in size: expected " + 
computed.size() + " but received " + given.size()

Review Comment:
   , but



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to