View Javadoc
1   /*
2    * Copyright 2017-2022 original authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package io.micronaut.build.aot;
17  
18  import io.micronaut.build.services.CompilerService;
19  import io.micronaut.build.services.DependencyResolutionService;
20  import io.micronaut.build.services.ExecutorService;
21  import org.apache.maven.execution.MavenSession;
22  import org.apache.maven.plugins.annotations.LifecyclePhase;
23  import org.apache.maven.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.ResolutionScope;
25  import org.apache.maven.project.MavenProject;
26  import org.eclipse.aether.RepositorySystem;
27  
28  import javax.inject.Inject;
29  import java.io.File;
30  import java.util.Arrays;
31  import java.util.List;
32  
33  /**
34   * Generates a sample <code>aot.properties</code> showcasing all the possible values along with a description.
35   */
36  @Mojo(name = AotSampleMojo.NAME, defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
37  public class AotSampleMojo extends AbstractMicronautAotCliMojo {
38  
39      public static final String SAMPLE_AOT_PROPERTIES_FILE_NAME = "aot.properties";
40      public static final String NAME = "aot-sample-config";
41  
42      @Inject
43      public AotSampleMojo(CompilerService compilerService, ExecutorService executorService, MavenProject mavenProject,
44                           MavenSession mavenSession, RepositorySystem repositorySystem,
45                           DependencyResolutionService dependencyResolutionService) {
46          super(compilerService, executorService, mavenProject, mavenSession, repositorySystem, dependencyResolutionService);
47      }
48  
49      @Override
50      protected List<String> getExtraArgs() {
51          return Arrays.asList(
52                  "--config",
53                  outputFile(SAMPLE_AOT_PROPERTIES_FILE_NAME).getAbsolutePath()
54          );
55      }
56  
57      @Override
58      protected void onSuccess(File outputDir) {
59          File sampleFile = new File(outputDir, SAMPLE_AOT_PROPERTIES_FILE_NAME);
60          if (sampleFile.exists()) {
61              getLog().info("Sample configuration file written to " + sampleFile);
62          }
63      }
64  
65      @Override
66      String getName() {
67          return NAME;
68      }
69  }