1 package org.apache.maven.lifecycle.providers;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.LinkedHashMap;
26
27 import javax.inject.Provider;
28
29 import org.apache.maven.lifecycle.Lifecycle;
30 import org.apache.maven.lifecycle.mapping.LifecyclePhase;
31
32
33
34
35 public abstract class AbstractLifecycleProvider
36 implements Provider<Lifecycle>
37 {
38 private final Lifecycle lifecycle;
39
40 protected AbstractLifecycleProvider( String id, String[] phases, String[] pluginBindings )
41 {
42 HashMap<String, LifecyclePhase> defaultBindings = null;
43 if ( pluginBindings != null )
44 {
45 final int len = pluginBindings.length;
46
47 if ( len < 2 || len % 2 != 0 )
48 {
49 throw new IllegalArgumentException( "Plugin bindings must have more than 0, even count of elements" );
50 }
51
52 defaultBindings = new LinkedHashMap<>( len / 2 );
53
54 for ( int i = 0; i < len; i += 2 )
55 {
56 defaultBindings.put( pluginBindings[i], new LifecyclePhase( pluginBindings[i + 1] ) );
57 }
58 }
59
60 this.lifecycle = new Lifecycle(
61 id,
62 Collections.unmodifiableList( Arrays.asList( phases ) ),
63 defaultBindings == null ? null : Collections.unmodifiableMap( defaultBindings )
64 );
65 }
66
67 @Override
68 public Lifecycle get()
69 {
70 return lifecycle;
71 }
72 }