diff --git a/micronaut-maven-integration-tests/src/it/test-resources-custom-dependency/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources-custom-dependency/verify.groovy index ce58b8fc6..65192ed26 100644 --- a/micronaut-maven-integration-tests/src/it/test-resources-custom-dependency/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/test-resources-custom-dependency/verify.groovy @@ -9,4 +9,6 @@ try (ServerSocket s = new ServerSocket(port as int)) { assert s != null } catch (IOException e) { assert false -} \ No newline at end of file +} + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources-disabled/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources-disabled/verify.groovy index 8d1520560..849019f81 100644 --- a/micronaut-maven-integration-tests/src/it/test-resources-disabled/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/test-resources-disabled/verify.groovy @@ -2,4 +2,6 @@ File log = new File(basedir, 'build.log') assert log.exists() assert log.text.contains("BUILD SUCCESS") assert !log.text.contains("test-resources-client") -assert !log.text.contains("Test Resources is configured in shared mode") \ No newline at end of file +assert !log.text.contains("Test Resources is configured in shared mode") + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources-failing-test/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources-failing-test/verify.groovy index c1f76a0c4..3e0bfa6ad 100644 --- a/micronaut-maven-integration-tests/src/it/test-resources-failing-test/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/test-resources-failing-test/verify.groovy @@ -10,3 +10,5 @@ try (ServerSocket s = new ServerSocket(port as int)) { } catch (IOException e) { assert false } + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources-run/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources-run/verify.groovy index 33894485f..fa8a1c41b 100644 --- a/micronaut-maven-integration-tests/src/it/test-resources-run/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/test-resources-run/verify.groovy @@ -11,3 +11,5 @@ try (ServerSocket s = new ServerSocket(port as int)) { } catch (IOException e) { assert false } + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources-shared-namespace/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources-shared-namespace/verify.groovy index 52e944590..612d22d70 100644 --- a/micronaut-maven-integration-tests/src/it/test-resources-shared-namespace/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/test-resources-shared-namespace/verify.groovy @@ -10,3 +10,5 @@ try (ServerSocket s = new ServerSocket(port as int)) { } catch (IOException e) { assert false } + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources-shared/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources-shared/verify.groovy index 1266c73b1..37f442a4e 100644 --- a/micronaut-maven-integration-tests/src/it/test-resources-shared/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/test-resources-shared/verify.groovy @@ -10,3 +10,5 @@ try (ServerSocket s = new ServerSocket(port as int)) { } catch (IOException e) { assert false } + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/invoker.properties b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/invoker.properties new file mode 100644 index 000000000..b6143bcd7 --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = -ntp -e mn:stop-testresources-service +invoker.os.family = !windows diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/pom.xml b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/pom.xml new file mode 100644 index 000000000..5546bd229 --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/pom.xml @@ -0,0 +1,173 @@ + + + 4.0.0 + io.micronaut.build.examples + test-resources-start-kill-stop + 0.1 + ${packaging} + + io.micronaut.platform + micronaut-parent + @it.micronaut.version@ + + + jar + @it.micronaut.version@ + netty + @project.version@ + io.micronaut.build.examples.Application + @micronaut.test.resources.version@ + true + @native-maven-plugin.version@ + + + + + io.micronaut + micronaut-inject + compile + + + io.micronaut.validation + micronaut-validation + compile + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + io.micronaut.test + micronaut-test-junit5 + test + + + io.micronaut + micronaut-http-client + compile + + + io.micronaut + micronaut-http-server-netty + compile + + + io.micronaut + micronaut-jackson-databind + compile + + + io.micronaut.sql + micronaut-jdbc-hikari + compile + + + jakarta.annotation + jakarta.annotation-api + compile + + + ch.qos.logback + logback-classic + runtime + + + org.yaml + snakeyaml + runtime + + + org.postgresql + postgresql + runtime + + + io.micronaut.data + micronaut-data-jdbc + compile + + + io.micronaut.testresources + micronaut-test-resources-client + provided + + + + + + io.micronaut.maven + micronaut-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + io.micronaut.data + micronaut-data-processor + ${micronaut.data.version} + + + io.micronaut + micronaut-inject + + + + + io.micronaut + micronaut-http-validation + ${micronaut.core.version} + + + io.micronaut.validation + micronaut-validation-processor + ${micronaut.validation.version} + + + io.micronaut + micronaut-inject + + + + + + -Amicronaut.processing.group=io.micronaut.build.examples + -Amicronaut.processing.module=test-resources-start-kill-stop + + + + + + + + + setup + + + central + https://repo.maven.apache.org/maven2 + + + sonatype-snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + true + + + false + + + + + + diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/setup.groovy b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/setup.groovy new file mode 100644 index 000000000..aa097b79d --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/setup.groovy @@ -0,0 +1,23 @@ +File mvnw = new File(basedir, '../../../mvnw') +assert mvnw.exists() + +String localRepo = (basedir as File).toPath().resolve("../../../target/local-repo").toFile().absolutePath + +def processBuilder = new ProcessBuilder(mvnw.absolutePath, "-ntp", "-q", "-Dmaven.repo.local=${localRepo}", "-Psetup", "mn:start-testresources-service") + .directory(basedir as File) + .inheritIO() + +Process p = processBuilder.start() +p.waitFor() + +assert p.exitValue() == 0 + +def testResourcesProcess = ProcessHandle.allProcesses() + .filter(process -> process.info().commandLine().map(c -> c.contains("TestResourcesService")).orElse(false)) + .findFirst(); + +if (testResourcesProcess.isPresent()) { + testResourcesProcess.get().destroyForcibly(); +} else { + assert false : "Test Resources Service process not found" +} \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/Application.java b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/Application.java new file mode 100644 index 000000000..3687fca50 --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/Application.java @@ -0,0 +1,50 @@ +package io.micronaut.build.examples; + +import io.micronaut.context.ApplicationContextBuilder; +import io.micronaut.context.ApplicationContextConfigurer; +import io.micronaut.context.annotation.ContextConfigurer; +import io.micronaut.context.event.StartupEvent; +import io.micronaut.runtime.Micronaut; +import io.micronaut.runtime.event.annotation.EventListener; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; + +@Singleton +public class Application { + + @Inject + private UserRepository userRepository; + + @Inject + private BookRepository bookRepository; + + @ContextConfigurer + public static class Configurer implements ApplicationContextConfigurer { + @Override + public void configure(ApplicationContextBuilder builder) { + builder.deduceEnvironment(false); + builder.banner(true); + } + } + + public static void main(String[] args) { + Micronaut.run(Application.class, args); + } + + @EventListener + public void onStart(StartupEvent event) { + if (userRepository.count() == 0) { + User admin = new User(); + admin.setName("Administrator"); + userRepository.save(admin); + } + if (bookRepository.count() == 0) { + Book book = new Book(); + book.setTitle("The Hitchhiker's Guide to the Galaxy"); + bookRepository.save(book); + } + if (System.getProperty("interrupt.on.startup") != null) { + System.exit(0); + } + } +} diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/Book.java b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/Book.java new file mode 100644 index 000000000..3e8eddb6d --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/Book.java @@ -0,0 +1,45 @@ +/* + * Copyright 2003-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.build.examples; + +import io.micronaut.data.annotation.GeneratedValue; +import io.micronaut.data.annotation.Id; +import io.micronaut.data.annotation.MappedEntity; + +@MappedEntity +public class Book { + @Id + @GeneratedValue(GeneratedValue.Type.AUTO) + private Long id; + + private String title; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/BookController.java b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/BookController.java new file mode 100644 index 000000000..1d8927736 --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/BookController.java @@ -0,0 +1,53 @@ +/* + * Copyright 2003-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.build.examples; + +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Delete; +import io.micronaut.http.annotation.Get; + +import java.util.List; + +@Controller("/") +public class BookController { + private final BookRepository bookRepository; + + public BookController(BookRepository bookRepository) { + this.bookRepository = bookRepository; + } + + @Get("/books") + public List list() { + return bookRepository.findAll(); + } + + @Get("/books/add/{title}") + public Book add(String title) { + Book book = new Book(); + book.setTitle(title); + return bookRepository.save(book); + } + + @Get("/books/{id}") + public Book get(Long id) { + return bookRepository.findById(id).orElse(null); + } + + @Delete("/books/{id}") + public void delete(Long id) { + bookRepository.deleteById(id); + } +} diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/BookRepository.java b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/BookRepository.java new file mode 100644 index 000000000..9b8963dff --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/BookRepository.java @@ -0,0 +1,28 @@ +/* + * Copyright 2003-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.build.examples; + +import io.micronaut.data.jdbc.annotation.JdbcRepository; +import io.micronaut.data.model.query.builder.sql.Dialect; +import io.micronaut.data.repository.CrudRepository; + +import java.util.List; + +@JdbcRepository(dialect = Dialect.POSTGRES) +public interface BookRepository extends CrudRepository { + @Override + List findAll(); +} diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/User.java b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/User.java new file mode 100644 index 000000000..0b450a07a --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/User.java @@ -0,0 +1,44 @@ +/* + * Copyright 2003-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.build.examples; + +import io.micronaut.data.annotation.GeneratedValue; +import io.micronaut.data.annotation.Id; +import io.micronaut.data.annotation.MappedEntity; + +@MappedEntity +public class User { + @Id + @GeneratedValue(GeneratedValue.Type.AUTO) + private Long id; + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/UserController.java b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/UserController.java new file mode 100644 index 000000000..c8359e59c --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/UserController.java @@ -0,0 +1,36 @@ +/* + * Copyright 2003-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.build.examples; + +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; + +import java.util.List; + +@Controller("/users") +public class UserController { + + private final UserRepository userRepository; + + public UserController(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Get("/") + public List list() { + return userRepository.findAll(); + } +} diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/UserRepository.java b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/UserRepository.java new file mode 100644 index 000000000..90bc664f6 --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/java/io/micronaut/build/examples/UserRepository.java @@ -0,0 +1,29 @@ +/* + * Copyright 2003-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.build.examples; + +import io.micronaut.data.jdbc.annotation.JdbcRepository; +import io.micronaut.data.model.query.builder.sql.Dialect; +import io.micronaut.data.repository.CrudRepository; + +import java.util.List; + +//@Repository("users") +@JdbcRepository(dialect = Dialect.POSTGRES) +public interface UserRepository extends CrudRepository { + @Override + List findAll(); +} diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/resources/application.yml b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/resources/application.yml new file mode 100644 index 000000000..b6dcab869 --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/resources/application.yml @@ -0,0 +1,12 @@ +micronaut: + application: + name: test-resources-start-kill-stop +netty: + default: + allocator: + max-order: 3 +datasources: + default: + schema-generate: CREATE + driverClassName: org.postgresql.Driver + dialect: POSTGRES diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/resources/logback.xml b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/resources/logback.xml new file mode 100644 index 000000000..822187082 --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/src/main/resources/logback.xml @@ -0,0 +1,15 @@ + + + + false + + + %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n + + + + + + + diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/verify.groovy new file mode 100644 index 000000000..1a1e03b46 --- /dev/null +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-kill-stop/verify.groovy @@ -0,0 +1,20 @@ +File log = new File(basedir, 'build.log') +assert log.exists() +assert log.text.contains("BUILD SUCCESS") + +String port = new File(basedir, "target/test-resources-port.txt").text +int retries = 10 +while (retries-- > 0) { + try (ServerSocket s = new ServerSocket(port as int)) { + assert s != null + break + } catch (IOException e) { + Thread.sleep(100 * (10 - retries)) + } +} + +if (retries == 0) { + assert false : "Failed to connect to Test Resources Service port $port" +} + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources-start-stop/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources-start-stop/verify.groovy index 08cbb0947..1a1e03b46 100644 --- a/micronaut-maven-integration-tests/src/it/test-resources-start-stop/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/test-resources-start-stop/verify.groovy @@ -15,4 +15,6 @@ while (retries-- > 0) { if (retries == 0) { assert false : "Failed to connect to Test Resources Service port $port" -} \ No newline at end of file +} + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-integration-tests/src/it/test-resources/verify.groovy b/micronaut-maven-integration-tests/src/it/test-resources/verify.groovy index dcf21574a..65192ed26 100644 --- a/micronaut-maven-integration-tests/src/it/test-resources/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/test-resources/verify.groovy @@ -10,3 +10,5 @@ try (ServerSocket s = new ServerSocket(port as int)) { } catch (IOException e) { assert false } + +assert !new File(basedir, ".micronaut/test-resources/test-resources.properties").exists() \ No newline at end of file diff --git a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/testresources/TestResourcesHelper.java b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/testresources/TestResourcesHelper.java index 42d7ee030..d234a7ba4 100644 --- a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/testresources/TestResourcesHelper.java +++ b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/testresources/TestResourcesHelper.java @@ -48,6 +48,7 @@ import java.util.stream.Stream; import static io.micronaut.maven.services.DependencyResolutionService.toClasspathFiles; +import static io.micronaut.testresources.buildtools.ServerUtils.PROPERTIES_FILE_NAME; import static java.util.stream.Stream.concat; /** @@ -177,6 +178,7 @@ private void doStart() throws IOException { Path source = serverSettingsDirectory.resolve(TEST_RESOURCES_PROPERTIES); Path target = projectSettingsDirectory.resolve(TEST_RESOURCES_PROPERTIES); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); + } else { log.info("Test Resources is configured in shared mode"); } @@ -296,11 +298,14 @@ public void stop(boolean quiet) throws MojoExecutionException { } try { Optional optionalServerSettings = ServerUtils.readServerSettings(getServerSettingsDirectory()); - if (optionalServerSettings.isPresent() && isServerStarted(optionalServerSettings.get().getPort())) { - log("Shutting down Micronaut Test Resources service", quiet); - doStop(); - } else { - log("Cannot find Micronaut Test Resources service settings, server may already be shutdown", quiet); + if (optionalServerSettings.isPresent()) { + if (isServerStarted(optionalServerSettings.get().getPort())) { + log("Shutting down Micronaut Test Resources service", quiet); + doStop(); + } else { + log("Cannot find Micronaut Test Resources service settings, server may already be shutdown", quiet); + Files.delete(getServerSettingsDirectory().resolve(PROPERTIES_FILE_NAME)); + } } } catch (Exception e) { throw new MojoExecutionException("Unable to stop test resources server", e); @@ -345,9 +350,6 @@ private void deleteKeepAliveFile() throws MojoExecutionException { } private Path getServerSettingsDirectory() { - if (shared) { - return ServerUtils.getDefaultSharedSettingsPath(sharedServerNamespace); - } return serverSettingsDirectoryOf(buildDirectory.toPath()); } diff --git a/micronaut-maven-plugin/src/main/resources/META-INF/plexus/components.xml b/micronaut-maven-plugin/src/main/resources/META-INF/plexus/components.xml index 8fad7a1ed..b2cbb2b33 100644 --- a/micronaut-maven-plugin/src/main/resources/META-INF/plexus/components.xml +++ b/micronaut-maven-plugin/src/main/resources/META-INF/plexus/components.xml @@ -34,7 +34,8 @@ ${project.groupId}:${project.artifactId}:${project.version}:start-testresources-service, - org.apache.maven.plugins:maven-surefire-plugin:test + org.apache.maven.plugins:maven-surefire-plugin:test, + ${project.groupId}:${project.artifactId}:${project.version}:stop-testresources-service ${project.groupId}:${project.artifactId}:${project.version}:aot-analysis @@ -92,7 +93,8 @@ ${project.groupId}:${project.artifactId}:${project.version}:start-testresources-service, - org.apache.maven.plugins:maven-surefire-plugin:test + org.apache.maven.plugins:maven-surefire-plugin:test, + ${project.groupId}:${project.artifactId}:${project.version}:stop-testresources-service ${project.groupId}:${project.artifactId}:${project.version}:aot-analysis, @@ -138,7 +140,8 @@ ${project.groupId}:${project.artifactId}:${project.version}:start-testresources-service, - org.apache.maven.plugins:maven-surefire-plugin:test + org.apache.maven.plugins:maven-surefire-plugin:test, + ${project.groupId}:${project.artifactId}:${project.version}:stop-testresources-service ${project.groupId}:${project.artifactId}:${project.version}:aot-analysis @@ -187,7 +190,8 @@ ${project.groupId}:${project.artifactId}:${project.version}:start-testresources-service, - org.apache.maven.plugins:maven-surefire-plugin:test + org.apache.maven.plugins:maven-surefire-plugin:test, + ${project.groupId}:${project.artifactId}:${project.version}:stop-testresources-service ${project.groupId}:${project.artifactId}:${project.version}:aot-analysis @@ -241,7 +245,8 @@ ${project.groupId}:${project.artifactId}:${project.version}:start-testresources-service, - org.apache.maven.plugins:maven-surefire-plugin:test + org.apache.maven.plugins:maven-surefire-plugin:test, + ${project.groupId}:${project.artifactId}:${project.version}:stop-testresources-service ${project.groupId}:${project.artifactId}:${project.version}:aot-analysis,