1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.invoker;
20
21 import org.apache.maven.plugins.invoker.AbstractInvokerMojo.ToolchainPrivateManager;
22
23
24
25
26
27
28 class Selector {
29 static final int SELECTOR_MAVENVERSION = 1;
30
31 static final int SELECTOR_JREVERSION = 2;
32
33 static final int SELECTOR_OSFAMILY = 4;
34
35 static final int SELECTOR_TOOLCHAIN = 8;
36
37 static final int SELECTOR_MULTI = 16;
38
39 private final String actualMavenVersion;
40
41 private final String actualJavaVersion;
42
43 private final ToolchainPrivateManager toolchainPrivateManager;
44
45 Selector(String actualMavenVersion, String actualJavaVersion, ToolchainPrivateManager toolchainPrivateManager) {
46 this.actualMavenVersion = actualMavenVersion;
47 this.actualJavaVersion = actualJavaVersion;
48 this.toolchainPrivateManager = toolchainPrivateManager;
49 }
50
51 public int getSelection(InvokerProperties invokerProperties) {
52 if (!invokerProperties.isSelectorDefined(1)) {
53 return getGlobal(invokerProperties);
54 }
55
56 for (int selectorIndex = 1; ; selectorIndex++) {
57 if (selectorIndex > 1 && !invokerProperties.isSelectorDefined(selectorIndex)) {
58 break;
59 }
60
61 int selection = 0;
62 if (!SelectorUtils.isMavenVersion(invokerProperties.getMavenVersion(selectorIndex), actualMavenVersion)) {
63 selection |= SELECTOR_MAVENVERSION;
64 }
65
66 if (!SelectorUtils.isJreVersion(invokerProperties.getJreVersion(selectorIndex), actualJavaVersion)) {
67 selection |= SELECTOR_JREVERSION;
68 }
69
70 if (!SelectorUtils.isOsFamily(invokerProperties.getOsFamily(selectorIndex))) {
71 selection |= SELECTOR_OSFAMILY;
72 }
73
74 if (!SelectorUtils.isToolchain(toolchainPrivateManager, invokerProperties.getToolchains(selectorIndex))) {
75 selection |= SELECTOR_TOOLCHAIN;
76 }
77
78 if (selection == 0) {
79 return 0;
80 }
81 }
82 return SELECTOR_MULTI;
83 }
84
85
86
87
88
89
90
91
92 private int getGlobal(InvokerProperties invokerProperties) {
93 int selection = 0;
94 if (!SelectorUtils.isMavenVersion(invokerProperties.getMavenVersion(), actualMavenVersion)) {
95 selection |= SELECTOR_MAVENVERSION;
96 }
97
98 if (!SelectorUtils.isJreVersion(invokerProperties.getJreVersion(), actualJavaVersion)) {
99 selection |= SELECTOR_JREVERSION;
100 }
101
102 if (!SelectorUtils.isOsFamily(invokerProperties.getOsFamily())) {
103 selection |= SELECTOR_OSFAMILY;
104 }
105
106 if (!SelectorUtils.isToolchain(toolchainPrivateManager, invokerProperties.getToolchains())) {
107 selection |= SELECTOR_TOOLCHAIN;
108 }
109
110 return selection;
111 }
112 }