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.plugins.rar.internal;
20
21 /*
22 * Licensed to the Apache Software Foundation (ASF) under one
23 * or more contributor license agreements. See the NOTICE file
24 * distributed with this work for additional information
25 * regarding copyright ownership. The ASF licenses this file
26 * to you under the Apache License, Version 2.0 (the
27 * "License"); you may not use this file except in compliance
28 * with the License. You may obtain a copy of the License at
29 *
30 * http://www.apache.org/licenses/LICENSE-2.0
31 *
32 * Unless required by applicable law or agreed to in writing,
33 * software distributed under the License is distributed on an
34 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
35 * KIND, either express or implied. See the License for the
36 * specific language governing permissions and limitations
37 * under the License.
38 */
39
40 import javax.inject.Named;
41 import javax.inject.Provider;
42 import javax.inject.Singleton;
43
44 import java.util.Collections;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Map;
48
49 import org.apache.maven.lifecycle.mapping.Lifecycle;
50 import org.apache.maven.lifecycle.mapping.LifecycleMapping;
51 import org.apache.maven.lifecycle.mapping.LifecyclePhase;
52
53 /**
54 * {@code rar} packaging plugins bindings provider for {@code default} lifecycle.
55 */
56 @Singleton
57 @Named("rar")
58 public final class RarLifecycleMappingProvider implements Provider<LifecycleMapping> {
59 // Note: "this" plugin does NOT have to have version specified, as the version should be specified in
60 // effective POM, otherwise this lifecycle mapping would not be loaded at all. Hence, the version of
61 // "this" plugin (in this case maven-rar-plugin) version is NEVER considered, and will come from
62 // effective POM of project using this plugin.
63 @SuppressWarnings("checkstyle:linelength")
64 private static final String[] BINDINGS = {
65 "process-resources", "org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources",
66 "compile", "org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile",
67 "process-test-resources", "org.apache.maven.plugins:maven-resources-plugin:3.2.0:testResources",
68 "test-compile", "org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile",
69 "test", "org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test",
70 "package", "org.apache.maven.plugins:maven-rar-plugin:rar",
71 "install", "org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install",
72 "deploy", "org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy"
73 };
74
75 private final Lifecycle defaultLifecycle;
76 private final LifecycleMapping lifecycleMapping;
77
78 public RarLifecycleMappingProvider() {
79 HashMap<String, LifecyclePhase> bindings = new HashMap<>();
80 for (int i = 0; i < BINDINGS.length; i = i + 2) {
81 bindings.put(BINDINGS[i], new LifecyclePhase(BINDINGS[i + 1]));
82 }
83 this.defaultLifecycle = new Lifecycle();
84 this.defaultLifecycle.setId("default");
85 this.defaultLifecycle.setLifecyclePhases(bindings);
86
87 this.lifecycleMapping = new LifecycleMapping() {
88 @Override
89 public Map<String, Lifecycle> getLifecycles() {
90 return Collections.singletonMap("default", defaultLifecycle);
91 }
92
93 @Override
94 public List<String> getOptionalMojos(String lifecycle) {
95 return null;
96 }
97
98 @Override
99 public Map<String, String> getPhases(String lifecycle) {
100 if ("default".equals(lifecycle)) {
101 return defaultLifecycle.getPhases();
102 } else {
103 return null;
104 }
105 }
106 };
107 }
108
109 @Override
110 public LifecycleMapping get() {
111 return lifecycleMapping;
112 }
113 }