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.aot; 017 018import io.micronaut.maven.services.CompilerService; 019import io.micronaut.maven.services.DependencyResolutionService; 020import io.micronaut.maven.services.ExecutorService; 021import org.apache.maven.execution.MavenSession; 022import org.apache.maven.project.MavenProject; 023import org.apache.maven.toolchain.ToolchainManager; 024 025import javax.inject.Inject; 026import java.io.File; 027import java.util.List; 028 029/** 030 * Shared implementation for the AOT sample configuration goal. 031 * 032 * @author Álvaro Sánchez-Mariscal 033 * @since 3.2.0 034 */ 035public abstract class AbstractAotSampleMojo extends AbstractMicronautAotCliMojo { 036 037 public static final String SAMPLE_AOT_PROPERTIES_FILE_NAME = "aot.properties"; 038 public static final String NAME = "aot-sample-config"; 039 040 @Inject 041 protected AbstractAotSampleMojo(CompilerService compilerService, 042 ExecutorService executorService, 043 MavenProject mavenProject, 044 DependencyResolutionService dependencyResolutionService, 045 MavenSession mavenSession, 046 ToolchainManager toolchainManager) { 047 super(compilerService, executorService, mavenProject, dependencyResolutionService, mavenSession, toolchainManager); 048 } 049 050 @Override 051 protected List<String> getExtraArgs() { 052 return List.of( 053 "--config", 054 outputFile(SAMPLE_AOT_PROPERTIES_FILE_NAME).getAbsolutePath() 055 ); 056 } 057 058 @Override 059 protected void onSuccess(File outputDir) { 060 File sampleFile = new File(outputDir, SAMPLE_AOT_PROPERTIES_FILE_NAME); 061 if (sampleFile.exists()) { 062 getLog().info("Sample configuration file written to " + sampleFile); 063 } 064 } 065 066 @Override 067 String getName() { 068 return NAME; 069 } 070}