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   * Stops the Micronaut test resources server.
31   */
32  @Mojo(name = StopTestResourcesServerMojo.NAME, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
33  public class StopTestResourcesServerMojo extends AbstractTestResourcesMojo {
34      public static final String NAME = "stop-testresources-service";
35      public static final String MICRONAUT_TEST_RESOURCES_KEEPALIVE = "keepAlive";
36  
37      private final MavenProject mavenProject;
38  
39      private final MavenSession mavenSession;
40  
41      private final DependencyResolutionService dependencyResolutionService;
42  
43      private final ToolchainManager toolchainManager;
44  
45      @Inject
46      @SuppressWarnings("CdiInjectionPointsInspection")
47      public StopTestResourcesServerMojo(MavenProject mavenProject, MavenSession mavenSession,
48                                         DependencyResolutionService dependencyResolutionService, ToolchainManager toolchainManager) {
49          this.mavenProject = mavenProject;
50          this.mavenSession = mavenSession;
51          this.dependencyResolutionService = dependencyResolutionService;
52          this.toolchainManager = toolchainManager;
53      }
54  
55      @Override
56      public final void execute() throws MojoExecutionException, MojoFailureException {
57          TestResourcesHelper helper = new TestResourcesHelper(testResourcesEnabled, keepAlive, shared, buildDirectory,
58                  explicitPort, clientTimeout, mavenProject, mavenSession,
59                  dependencyResolutionService, toolchainManager, testResourcesVersion,
60                  classpathInference, testResourcesDependencies, sharedServerNamespace);
61          helper.stop();
62      }
63  
64  }