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

org.codingmatters.value.objects.maven.plugin.PhpMojo Maven / Gradle / Ivy

The newest version!
package org.codingmatters.value.objects.maven.plugin;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codingmatters.value.objects.exception.LowLevelSyntaxException;
import org.codingmatters.value.objects.php.generator.SpecPhpGenerator;
import org.codingmatters.value.objects.php.generator.SpecReaderPhp;
import org.codingmatters.value.objects.spec.Spec;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

@Mojo(name = "generate-php")
public class PhpMojo extends AbstractGenerationMojo {

    @Parameter(defaultValue = "true", alias = "output-dir")
    private boolean useTypeHintingReturnType;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        this.getLog().info( "generating PHP value objects with configuration:" );
        this.getLog().info( "\t- destination package :" + this.getDestinationPackage() );
        this.getLog().info( "\t- specification file  :" + this.getInputSpecification().getAbsolutePath() );
        this.getLog().info( "\t- to output directory : " + this.getOutputDirectory().getAbsolutePath() );
        this.getLog().info( "\t- use type hinting: " + this.useTypeHintingReturnType );
        try( InputStream in = new FileInputStream( this.getInputSpecification() ) ) {
            Spec spec = new SpecReaderPhp().read( in );
            new SpecPhpGenerator( spec, this.getDestinationPackage(), this.getOutputDirectory(), useTypeHintingReturnType ).generate();
        } catch( IOException e ) {
            throw new MojoFailureException( "Something went wrong while reading spec: " + this.getInputSpecification().getAbsolutePath(), e );
        } catch( LowLevelSyntaxException e ) {
            throw new MojoFailureException( "Unparsable specification file : " + this.getInputSpecification().getAbsolutePath(), e );
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy