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