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 org.apache.maven.model.Build;
9   import org.apache.maven.project.MavenProject;
10  
11  /**
12   * Mocker of {@link MavenProject}.
13   *
14   * @since 0.4
15   */
16  public final class MavenProjectMocker {
17  
18      /**
19       * Mock of project.
20       */
21      private final MavenProject project;
22  
23      /**
24       * Ctor.
25       */
26      public MavenProjectMocker() {
27          this.project = new MavenProject();
28      }
29  
30      /**
31       * In this basedir.
32       *
33       * @param dir The directory
34       * @return This object
35       */
36      public MavenProjectMocker inBasedir(final File dir) {
37          final File parent = new File(dir, "target");
38          final Build build = new Build();
39          build.setOutputDirectory(parent.getPath());
40          this.project.setFile(parent);
41          this.project.setBuild(build);
42          return this;
43      }
44  
45      /**
46       * Mock it.
47       *
48       * @return The mock
49       * @throws Exception If something wrong happens inside
50       */
51      public MavenProject mock() throws Exception {
52          this.project.setPackaging("jar");
53          return this.project;
54      }
55  }