001/* 002 * Copyright 2017-2022 original authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.micronaut.maven.testresources; 017 018import io.micronaut.maven.services.DependencyResolutionService; 019import org.apache.maven.execution.MavenSession; 020import org.apache.maven.plugin.MojoExecutionException; 021import org.apache.maven.plugins.annotations.Mojo; 022import org.apache.maven.plugins.annotations.ResolutionScope; 023import org.apache.maven.project.MavenProject; 024import org.apache.maven.toolchain.ToolchainManager; 025 026import javax.inject.Inject; 027 028/** 029 * Stops the Micronaut test resources server. 030 */ 031@Mojo(name = StopTestResourcesServerMojo.NAME, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) 032public class StopTestResourcesServerMojo extends AbstractTestResourcesMojo { 033 public static final String NAME = "stop-testresources-service"; 034 public static final String MICRONAUT_TEST_RESOURCES_KEEPALIVE = "keepAlive"; 035 036 private final MavenProject mavenProject; 037 038 private final MavenSession mavenSession; 039 040 private final DependencyResolutionService dependencyResolutionService; 041 042 private final ToolchainManager toolchainManager; 043 044 @Inject 045 @SuppressWarnings("CdiInjectionPointsInspection") 046 public StopTestResourcesServerMojo(MavenProject mavenProject, MavenSession mavenSession, 047 DependencyResolutionService dependencyResolutionService, ToolchainManager toolchainManager) { 048 this.mavenProject = mavenProject; 049 this.mavenSession = mavenSession; 050 this.dependencyResolutionService = dependencyResolutionService; 051 this.toolchainManager = toolchainManager; 052 } 053 054 @Override 055 public final void execute() throws MojoExecutionException { 056 var helper = new TestResourcesHelper(testResourcesEnabled, shared, buildDirectory, explicitPort, clientTimeout, 057 serverIdleTimeoutMinutes, mavenProject, mavenSession, dependencyResolutionService, toolchainManager, 058 testResourcesVersion, classpathInference, testResourcesDependencies, sharedServerNamespace, debugServer, 059 foreground); 060 helper.stop(false); 061 } 062 063}