2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.tools.generator.api;
27 import org.openecomp.appc.tools.generator.impl.ModelGenerator;
28 import org.apache.maven.plugin.AbstractMojo;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31 import org.apache.maven.plugins.annotations.LifecyclePhase;
32 import org.apache.maven.plugins.annotations.Mojo;
33 import org.apache.maven.plugins.annotations.Parameter;
34 import org.apache.maven.project.MavenProject;
36 import java.io.IOException;
37 import java.nio.file.Paths;
41 defaultPhase = LifecyclePhase.GENERATE_SOURCES
43 public class MavenPlugin extends AbstractMojo {
45 @Parameter(property = "templateName", required = true)
46 private String templateName;
48 @Parameter(property = "sourceFileName")
49 private String sourceFileName;
51 @Parameter(property = "outputFileName")
52 private String outputFileName;
54 @Parameter(property = "contextBuilderClassName", required = true)
55 private String contextBuilderClassName;
57 @Parameter(property = "contextConfigFileName")
58 private String contextConfigFileName;
60 @Parameter (property = "project")
61 private MavenProject project;
64 public void execute() throws MojoExecutionException, MojoFailureException {
65 ModelGenerator generator = new ModelGenerator();
67 trace("\t === Called MavenPlugin on builder <" + contextBuilderClassName +">\n");
68 generator.execute(sourceFileName,outputFileName,templateName,contextBuilderClassName,contextConfigFileName);
69 String workDirectory = getWorkDirectory(outputFileName);
70 project.addCompileSourceRoot(workDirectory);
71 } catch (Exception e) {
73 throw new MojoExecutionException(e.getMessage());
77 private String getWorkDirectory(String outputFileName) throws IOException {
78 String workDirPath = Paths.get(outputFileName.toString()).getParent().toString();
82 private void trace(String message) {
83 getLog().info(message);