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.plugins.annotations.LifecyclePhase; 022import org.apache.maven.plugins.annotations.Mojo; 023import org.apache.maven.plugins.annotations.ResolutionScope; 024import org.apache.maven.project.MavenProject; 025 026import javax.inject.Inject; 027import java.io.File; 028import java.util.Arrays; 029import java.util.List; 030 031/** 032 * Generates a sample <code>aot.properties</code> showcasing all the possible values along with a description. 033 */ 034@Mojo(name = AotSampleMojo.NAME, defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) 035public class AotSampleMojo 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 public AotSampleMojo(CompilerService compilerService, ExecutorService executorService, MavenProject mavenProject, 042 DependencyResolutionService dependencyResolutionService) { 043 super(compilerService, executorService, mavenProject, dependencyResolutionService); 044 } 045 046 @Override 047 protected List<String> getExtraArgs() { 048 return Arrays.asList( 049 "--config", 050 outputFile(SAMPLE_AOT_PROPERTIES_FILE_NAME).getAbsolutePath() 051 ); 052 } 053 054 @Override 055 protected void onSuccess(File outputDir) { 056 var sampleFile = new File(outputDir, SAMPLE_AOT_PROPERTIES_FILE_NAME); 057 if (sampleFile.exists()) { 058 getLog().info("Sample configuration file written to " + sampleFile); 059 } 060 } 061 062 @Override 063 String getName() { 064 return NAME; 065 } 066}