View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.lifecycle.internal.concurrent;
20  
21  import java.util.Collection;
22  import java.util.Collections;
23  import java.util.List;
24  import java.util.stream.Collectors;
25  import java.util.stream.Stream;
26  
27  import org.apache.maven.api.Lifecycle;
28  import org.apache.maven.api.model.Plugin;
29  import org.apache.maven.plugin.descriptor.PluginDescriptor;
30  
31  class PluginLifecycle implements Lifecycle {
32      private final org.apache.maven.api.plugin.descriptor.lifecycle.Lifecycle lifecycleOverlay;
33      private final PluginDescriptor pluginDescriptor;
34  
35      PluginLifecycle(
36              org.apache.maven.api.plugin.descriptor.lifecycle.Lifecycle lifecycleOverlay,
37              PluginDescriptor pluginDescriptor) {
38          this.lifecycleOverlay = lifecycleOverlay;
39          this.pluginDescriptor = pluginDescriptor;
40      }
41  
42      @Override
43      public String id() {
44          return lifecycleOverlay.getId();
45      }
46  
47      @Override
48      public Collection<Phase> phases() {
49          return lifecycleOverlay.getPhases().stream()
50                  .map(phase -> new Phase() {
51                      @Override
52                      public String name() {
53                          return phase.getId();
54                      }
55  
56                      @Override
57                      public List<Plugin> plugins() {
58                          return Collections.singletonList(Plugin.newBuilder()
59                                  .groupId(pluginDescriptor.getGroupId())
60                                  .artifactId(pluginDescriptor.getArtifactId())
61                                  .version(pluginDescriptor.getVersion())
62                                  .configuration(phase.getConfiguration())
63                                  .executions(phase.getExecutions().stream()
64                                          .map(exec -> org.apache.maven.api.model.PluginExecution.newBuilder()
65                                                  .goals(exec.getGoals())
66                                                  .configuration(exec.getConfiguration())
67                                                  .build())
68                                          .collect(Collectors.toList()))
69                                  .build());
70                      }
71  
72                      @Override
73                      public Collection<Link> links() {
74                          return Collections.emptyList();
75                      }
76  
77                      @Override
78                      public List<Phase> phases() {
79                          return Collections.emptyList();
80                      }
81  
82                      @Override
83                      public Stream<Phase> allPhases() {
84                          return Stream.concat(Stream.of(this), phases().stream().flatMap(Phase::allPhases));
85                      }
86                  })
87                  .collect(Collectors.toList());
88      }
89  
90      @Override
91      public Collection<Alias> aliases() {
92          return Collections.emptyList();
93      }
94  }