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