View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.maven;
6   
7   import java.io.File;
8   import java.nio.charset.Charset;
9   import java.nio.charset.StandardCharsets;
10  import java.util.Collection;
11  import java.util.Collections;
12  import java.util.Properties;
13  import org.apache.maven.project.MavenProject;
14  import org.codehaus.plexus.context.Context;
15  
16  /**
17   * FakeMavenEnvironment.
18   * A mock to MavenEnvironment.
19   *
20   * @since 0.24.1
21   */
22  final class FakeMavenEnvironment implements MavenEnvironment {
23  
24      /**
25       * Project.
26       */
27      private final MavenProject proj;
28  
29      /**
30       * Context.
31       */
32      private final Context ctx;
33  
34      /**
35       * Asserts.
36       */
37      private final Collection<String> assrts;
38  
39      FakeMavenEnvironment(
40          final MavenProject prj,
41          final Context ctx,
42          final Collection<String> asserts
43      ) {
44          this.proj = prj;
45          this.ctx = ctx;
46          this.assrts = asserts;
47      }
48  
49      @Override
50      public MavenProject project() {
51          return this.proj;
52      }
53  
54      @Override
55      public Properties properties() {
56          throw new UnsupportedOperationException("#properties()");
57      }
58  
59      @Override
60      public Context context() {
61          return this.ctx;
62      }
63  
64      @Override
65      public Properties config() {
66          throw new UnsupportedOperationException("#config()");
67      }
68  
69      @Override
70      public MojoExecutor executor() {
71          throw new UnsupportedOperationException("#executor()");
72      }
73  
74      @Override
75      public Collection<String> asserts() {
76          return this.assrts;
77      }
78  
79      @Override
80      public File basedir() {
81          return this.proj.getBasedir();
82      }
83  
84      @Override
85      public File tempdir() {
86          return new File("/tmp");
87      }
88  
89      @Override
90      public File outdir() {
91          return this.proj.getBasedir();
92      }
93  
94      @Override
95      public Collection<File> testdirs() {
96          return this.proj.getTestCompileSourceRoots().stream()
97              .map(File::new)
98              .toList();
99      }
100 
101     @Override
102     public String param(final String name, final String value) {
103         return "";
104     }
105 
106     @Override
107     public ClassLoader classloader() {
108         return ClassLoader.getSystemClassLoader();
109     }
110 
111     @Override
112     public Collection<String> classpath() {
113         return Collections.emptyList();
114     }
115 
116     @Override
117     public Collection<File> files(final String pattern) {
118         return Collections.emptyList();
119     }
120 
121     @Override
122     public boolean exclude(final String check, final String name) {
123         return true;
124     }
125 
126     @Override
127     public Collection<String> excludes(final String checker) {
128         return Collections.emptyList();
129     }
130 
131     @Override
132     public Charset encoding() {
133         return StandardCharsets.UTF_8;
134     }
135 }