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; 021 022import org.apache.maven.execution.MavenSession; 023import org.apache.maven.plugins.annotations.LifecyclePhase; 024import org.apache.maven.plugins.annotations.Mojo; 025import org.apache.maven.plugins.annotations.ResolutionScope; 026import org.apache.maven.project.MavenProject; 027import org.apache.maven.toolchain.ToolchainManager; 028 029import javax.inject.Inject; 030import java.io.File; 031import java.util.Arrays; 032import java.util.List; 033 034/** 035 * Generates a sample <code>aot.properties</code> showcasing all the possible values along with a description. 036 */ 037@Mojo(name = AotSampleMojo.NAME, defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) 038public class AotSampleMojo extends AbstractMicronautAotCliMojo { 039 040 public static final String SAMPLE_AOT_PROPERTIES_FILE_NAME = "aot.properties"; 041 public static final String NAME = "aot-sample-config"; 042 043 @Inject 044 public AotSampleMojo(CompilerService compilerService, ExecutorService executorService, MavenProject mavenProject, 045 DependencyResolutionService dependencyResolutionService, 046 MavenSession mavenSession, ToolchainManager toolchainManager) { 047 super(compilerService, executorService, mavenProject, dependencyResolutionService, mavenSession, toolchainManager); 048 } 049 050 @Override 051 protected List<String> getExtraArgs() { 052 return Arrays.asList( 053 "--config", 054 outputFile(SAMPLE_AOT_PROPERTIES_FILE_NAME).getAbsolutePath() 055 ); 056 } 057 058 @Override 059 protected void onSuccess(File outputDir) { 060 var 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}