1 /*
2 * Copyright (c) 2011-2025 Yegor Bugayenko
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met: 1) Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer. 2) Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution. 3) Neither the name of the Qulice.com nor
14 * the names of its contributors may be used to endorse or promote
15 * products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
20 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 package com.qulice.maven;
32
33 import com.qulice.spi.Environment;
34 import java.io.File;
35 import java.nio.charset.Charset;
36 import java.util.Collection;
37 import java.util.Properties;
38 import org.apache.maven.project.MavenProject;
39 import org.codehaus.plexus.context.Context;
40
41 /**
42 * Environment, passed from MOJO to validators.
43 *
44 * @since 0.3
45 */
46 @SuppressWarnings("PMD.TooManyMethods")
47 interface MavenEnvironment extends Environment {
48
49 /**
50 * Get project.
51 * @return The project
52 */
53 MavenProject project();
54
55 /**
56 * Get properties.
57 * @return The properties
58 */
59 Properties properties();
60
61 /**
62 * Get context.
63 * @return The context
64 */
65 Context context();
66
67 /**
68 * Get plugin configuration properties.
69 * @return The props
70 */
71 Properties config();
72
73 /**
74 * Get MOJO executor.
75 * @return The executor
76 */
77 MojoExecutor executor();
78
79 /**
80 * Get xpath queries for pom.xml validation.
81 * @return The asserts
82 */
83 Collection<String> asserts();
84
85 /**
86 * Wrapper of maven environment.
87 *
88 * @since 0.1
89 */
90 final class Wrap implements MavenEnvironment {
91 /**
92 * Parent environment.
93 */
94 private final Environment env;
95
96 /**
97 * Parent maven environment.
98 */
99 private final MavenEnvironment menv;
100
101 /**
102 * Public ctor.
103 * @param penv Parent env
104 * @param pmenv Parent maven env
105 */
106 Wrap(final Environment penv,
107 final MavenEnvironment pmenv) {
108 this.env = penv;
109 this.menv = pmenv;
110 }
111
112 @Override
113 public File basedir() {
114 return this.env.basedir();
115 }
116
117 @Override
118 public File tempdir() {
119 return this.env.tempdir();
120 }
121
122 @Override
123 public File outdir() {
124 return this.env.outdir();
125 }
126
127 @Override
128 public String param(final String name, final String value) {
129 return this.env.param(name, value);
130 }
131
132 @Override
133 public ClassLoader classloader() {
134 return this.env.classloader();
135 }
136
137 @Override
138 public Collection<String> classpath() {
139 return this.env.classpath();
140 }
141
142 @Override
143 public MavenProject project() {
144 return this.menv.project();
145 }
146
147 @Override
148 public Properties properties() {
149 return this.menv.properties();
150 }
151
152 @Override
153 public Context context() {
154 return this.menv.context();
155 }
156
157 @Override
158 public Properties config() {
159 return this.menv.config();
160 }
161
162 @Override
163 public MojoExecutor executor() {
164 return this.menv.executor();
165 }
166
167 @Override
168 public Collection<String> asserts() {
169 return this.menv.asserts();
170 }
171
172 @Override
173 public Collection<File> files(final String pattern) {
174 return this.env.files(pattern);
175 }
176
177 @Override
178 public boolean exclude(final String check, final String name) {
179 return this.env.exclude(check, name);
180 }
181
182 @Override
183 public Collection<String> excludes(final String checker) {
184 return this.env.excludes(checker);
185 }
186
187 @Override
188 public Charset encoding() {
189 return this.env.encoding();
190 }
191 }
192 }