All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ovh.ws.jsonizer.mojo.GenerateMojo Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2012, OVH. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 */
package com.ovh.ws.jsonizer.mojo;

import java.io.File;
import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;

import com.ovh.ws.jsonizer.core.GeneratorLoader;
import com.ovh.ws.jsonizer.core.base.AnnotationStyle;
import com.ovh.ws.jsonizer.core.base.GenerationConfig;

/**
 * Downloads json schema file and generates all beans
 * 
 * @goal generate
 * @phase generate-sources
 * @see http://maven.apache.org/developers/mojo-api-specification.html
 */
public class GenerateMojo extends AbstractJsonizerMojo implements GenerationConfig {

	/**
	 * @parameter expression="${jsonizer.targetPackage}"
	 */
	private String targetPackage;

	/**
	 * Generate builder-style methods.
	 * 
	 * @parameter expression="${jsonizer.generateBuilders}" default-value="false"
	 */
	private boolean generateBuilders;

	/**
	 * Use Calendar instead of Date
	 * 
	 * @parameter expression="${jsonizer.useCalendars}" default-value="false"
	 */
	private boolean useCalendars;

	/**
	 * Add Inject annotation on the service
	 * 
	 * @parameter expression="${jsonizer.useInjection}" default-value="false"
	 */
	private boolean useInjection;

	/**
	 * Generate asynchronous method in service
	 * 
	 * @parameter expression="${jsonizer.generateAsyncMethods}" default-value="false"
	 */
	private boolean generateAsyncMethods;

	/**
	 * Generate extended return function
	 * 
	 * @parameter expression="${jsonizer.generateExtendedReturn}" default-value="false"
	 */
	private boolean generateExtendedReturn;

	/**
	 * List of schemaUrls
	 * 
	 * @parameter
	 * @required
	 */
	private List schemaUrls;

	/**
	 * The style of annotations to use in the generated Java types (jackson or none).
	 * 
	 * @parameter expression="${jsonizer.annotationStyle}" default-value="jackson"
	 */
	private String annotationStyle = "jackson";

	/**
	 * The Maven Project Object.
	 * 
	 * @parameter default-value="${project}"
	 * @readonly
	 */
	private MavenProject project;

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		try {
			project.addCompileSourceRoot(classesOutputDirectory.getPath());
			new GeneratorLoader(this).generate();

		} catch (Exception e) {
			throw new MojoExecutionException("Error generating Java code from Json Schema.", e);
		}
	}

	@Override
	public boolean isUseCalendars() {
		return useCalendars;
	}

	@Override
	public File getOutputDirectory() {
		return classesOutputDirectory;
	}

	@Override
	public List getSchemaUrls() {
		return schemaUrls;
	}

	@Override
	public String getTargetPackage() {
		return targetPackage;
	}

	@Override
	public boolean isGenerateBuilders() {
		return generateBuilders;
	}

	@Override
	public boolean isUseInjection() {
		return useInjection;
	}

	@Override
	public boolean isGenerateAsyncMethods() {
		return generateAsyncMethods;
	}

	@Override
	public boolean isGenerateExtendedReturn() {
		return generateExtendedReturn;
	}

	@Override
	public AnnotationStyle getAnnotationStyle() {
		try {
			return AnnotationStyle.valueOf(annotationStyle.toUpperCase());

		} catch (IllegalArgumentException e) {
			throw new IllegalArgumentException("Not a valid annotation style: " + annotationStyle);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy