View Javadoc
1   /*
2    * Copyright 2017-2022 original authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package io.micronaut.build.testresources;
17  
18  import io.micronaut.build.services.DependencyResolutionService;
19  import org.apache.maven.execution.MavenSession;
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.maven.plugin.MojoFailureException;
22  import org.apache.maven.plugins.annotations.Mojo;
23  import org.apache.maven.plugins.annotations.ResolutionScope;
24  import org.apache.maven.project.MavenProject;
25  import org.apache.maven.toolchain.ToolchainManager;
26  
27  import javax.inject.Inject;
28  
29  /**
30   * Starts the Micronaut test resources server.
31   */
32  @Mojo(name = StartTestResourcesServerMojo.NAME, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
33  public class StartTestResourcesServerMojo extends AbstractTestResourcesMojo {
34      public static final String NAME = "start-testresources-service";
35  
36      private final MavenProject mavenProject;
37  
38      private final MavenSession mavenSession;
39  
40      private final DependencyResolutionService dependencyResolutionService;
41  
42      private final ToolchainManager toolchainManager;
43  
44      @Inject
45      @SuppressWarnings("CdiInjectionPointsInspection")
46      public StartTestResourcesServerMojo(MavenProject mavenProject,
47                                          MavenSession mavenSession,
48                                          DependencyResolutionService dependencyResolutionService,
49                                          ToolchainManager toolchainManager) {
50          this.mavenProject = mavenProject;
51          this.mavenSession = mavenSession;
52          this.dependencyResolutionService = dependencyResolutionService;
53          this.toolchainManager = toolchainManager;
54      }
55  
56      @Override
57      public final void execute() throws MojoExecutionException, MojoFailureException {
58          TestResourcesHelper helper = new TestResourcesHelper(testResourcesEnabled, keepAlive, shared, buildDirectory,
59                  explicitPort, clientTimeout, mavenProject, mavenSession,
60                  dependencyResolutionService, toolchainManager, testResourcesVersion,
61                  classpathInference, testResourcesDependencies, sharedServerNamespace);
62          helper.start();
63  
64      }
65  
66  }