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.invoker;
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 org.apache.maven.plugins.invoker.AbstractInvokerMojo.ToolchainPrivateManager;
41
42 /**
43 *
44 * @author Robert Scholte
45 *
46 */
47 class Selector {
48 static final int SELECTOR_MAVENVERSION = 1;
49
50 static final int SELECTOR_JREVERSION = 2;
51
52 static final int SELECTOR_OSFAMILY = 4;
53
54 static final int SELECTOR_TOOLCHAIN = 8;
55
56 static final int SELECTOR_MULTI = 16;
57
58 private final String actualMavenVersion;
59
60 private final String actualJavaVersion;
61
62 private final ToolchainPrivateManager toolchainPrivateManager;
63
64 Selector(String actualMavenVersion, String actualJavaVersion, ToolchainPrivateManager toolchainPrivateManager) {
65 this.actualMavenVersion = actualMavenVersion;
66 this.actualJavaVersion = actualJavaVersion;
67 this.toolchainPrivateManager = toolchainPrivateManager;
68 }
69
70 public int getSelection(InvokerProperties invokerProperties) {
71 if (!invokerProperties.isSelectorDefined(1)) {
72 return getGlobal(invokerProperties);
73 }
74
75 for (int selectorIndex = 1; ; selectorIndex++) {
76 if (selectorIndex > 1 && !invokerProperties.isSelectorDefined(selectorIndex)) {
77 break;
78 }
79
80 int selection = 0;
81 if (!SelectorUtils.isMavenVersion(invokerProperties.getMavenVersion(selectorIndex), actualMavenVersion)) {
82 selection |= SELECTOR_MAVENVERSION;
83 }
84
85 if (!SelectorUtils.isJreVersion(invokerProperties.getJreVersion(selectorIndex), actualJavaVersion)) {
86 selection |= SELECTOR_JREVERSION;
87 }
88
89 if (!SelectorUtils.isOsFamily(invokerProperties.getOsFamily(selectorIndex))) {
90 selection |= SELECTOR_OSFAMILY;
91 }
92
93 if (!SelectorUtils.isToolchain(toolchainPrivateManager, invokerProperties.getToolchains(selectorIndex))) {
94 selection |= SELECTOR_TOOLCHAIN;
95 }
96
97 if (selection == 0) {
98 return 0;
99 }
100 }
101 return SELECTOR_MULTI;
102 }
103
104 /**
105 * Determines whether selector conditions of the specified invoker properties match the current environment.
106 *
107 * @param invokerProperties The invoker properties to check, must not be <code>null</code>.
108 * @return <code>0</code> if the job corresponding to the properties should be run, otherwise a bitwise value
109 * representing the reason why it should be skipped.
110 */
111 private int getGlobal(InvokerProperties invokerProperties) {
112 int selection = 0;
113 if (!SelectorUtils.isMavenVersion(invokerProperties.getMavenVersion(), actualMavenVersion)) {
114 selection |= SELECTOR_MAVENVERSION;
115 }
116
117 if (!SelectorUtils.isJreVersion(invokerProperties.getJreVersion(), actualJavaVersion)) {
118 selection |= SELECTOR_JREVERSION;
119 }
120
121 if (!SelectorUtils.isOsFamily(invokerProperties.getOsFamily())) {
122 selection |= SELECTOR_OSFAMILY;
123 }
124
125 if (!SelectorUtils.isToolchain(toolchainPrivateManager, invokerProperties.getToolchains())) {
126 selection |= SELECTOR_TOOLCHAIN;
127 }
128
129 return selection;
130 }
131 }