Search in sources :

Example 1 with DefinitionClassInfo

use of com.sun.identity.cli.annotation.DefinitionClassInfo in project OpenAM by OpenRock.

the class CLIDefinitionGenerator method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    for (String className : definitions) {
        try {
            Class clazz = Class.forName(className);
            Field pdtField = clazz.getDeclaredField("product");
            if (pdtField != null) {
                DefinitionClassInfo classInfo = pdtField.getAnnotation(DefinitionClassInfo.class);
                PrintStream rbOut = createResourcePrintStream(outputDir, classInfo);
                getCommonResourceStrings(rbOut, clazz);
                rbOut.println("product-name=" + classInfo.productName());
                getCommands(className, clazz, rbOut);
                rbOut.close();
            } else {
                throw new Exception("Incorrect Definiton, class=" + className + " missing product field");
            }
        } catch (Exception ex) {
            throw new MojoFailureException("An error occured while generating CLI resources", ex);
        }
    }
    Resource resource = new Resource();
    resource.setDirectory(outputDir);
    project.addResource(resource);
}
Also used : Field(java.lang.reflect.Field) PrintStream(java.io.PrintStream) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Resource(org.apache.maven.model.Resource) DefinitionClassInfo(com.sun.identity.cli.annotation.DefinitionClassInfo) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 2 with DefinitionClassInfo

use of com.sun.identity.cli.annotation.DefinitionClassInfo in project OpenAM by OpenRock.

the class CLIDefinitionBase method getProductName.

private void getProductName(Class clazz) throws CLIException {
    try {
        Field pdtField = clazz.getDeclaredField(CLIConstants.FLD_PRODUCT_NAME);
        if (pdtField != null) {
            DefinitionClassInfo classInfo = pdtField.getAnnotation(DefinitionClassInfo.class);
            rb = ResourceBundle.getBundle(classInfo.resourceBundle());
            logName = classInfo.logName();
        } else {
            throw new CLIException("Incorrect Definiton, class" + definitionClass + " missing product field", ExitCodes.INCORRECT_DEFINITION_CLASS);
        }
    } catch (NoSuchFieldException e) {
        throw new CLIException(e, ExitCodes.INCORRECT_DEFINITION_CLASS);
    }
}
Also used : Field(java.lang.reflect.Field) DefinitionClassInfo(com.sun.identity.cli.annotation.DefinitionClassInfo)

Aggregations

DefinitionClassInfo (com.sun.identity.cli.annotation.DefinitionClassInfo)2 Field (java.lang.reflect.Field)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Resource (org.apache.maven.model.Resource)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1