Package com.javaforge.bobber.archetype.model

Examples of com.javaforge.bobber.archetype.model.Template


            URLClassLoader archetypeJarLoader = new URLClassLoader(urls);

            Thread.currentThread().setContextClassLoader(archetypeJarLoader);
            for (Iterator i = archetype.getTemplates().iterator(); i.hasNext();)
            {
                final Template template = (Template) i.next();

                // Check the optional 'condition' property on the template.
                // If present and the variable it points to is 'true', then
                // continue processing. If it's false, then skip.
                // If condition is not specified, assume the template should
                // be processed.
                boolean shouldProcess = true;
                String condition = template.getDependsOnVar();
                String requiredValue = null;
                List options = new ArrayList();
                if (StringUtils.isNotEmpty(condition))
                {
                    //Crappy logic processing -- for now
                    boolean not = false;
                    //Allow very simple matching logic to match templates against variable values
                    int x = condition.indexOf("!=");
                    getLogger().debug("Processing Condition : " + condition);
                    if (x > -1)
                    {
                        not = true;
                        requiredValue = condition.substring(x + 2).trim();
                        options = getListOfValues(requiredValue);
                        condition = condition.substring(0, x).trim();
                    }
                    else
                    {
                        x = condition.indexOf("=");
                        if (x > -1)
                        {
                            requiredValue = condition.substring(x + 1);
                            options = getListOfValues(requiredValue);
                            condition = condition.substring(0, x);
                        }
                    }
                    getLogger().debug("Not Expr: " + not);
                    getLogger().debug("Condition Value: '" + condition + "'");
                    getLogger().debug("Required Value: '" + requiredValue + "'");
                    final Variable var = (Variable) findVariable(condition, variables);
                    if (var != null)
                    {
                        final String strValue = (String) context.get(var.getName());
                        getLogger().debug("Variable Value is: '" + strValue + "'");
                        if (requiredValue == null)
                        {
                            if (!Boolean.valueOf(strValue).booleanValue())
                            {
                                shouldProcess = false;
                            }
                        }
                        else
                        {
                            if (!options.contains(strValue))
                            {
                                shouldProcess = false;
                            }
                        }

                    }
                    else
                    {
                        getLogger().debug("Variable Value is: null");
                        shouldProcess = false;
                    }
                    if (not)
                    {
                        shouldProcess = !shouldProcess;
                    }
                }

                if (shouldProcess)
                {
                    processTemplate(template, outputDirectory, context);
                }
                else
                {
                    getLogger().debug("Condition not met, skipping " + template.getOutput());
                }
            }

        }
        catch (MalformedURLException mfe)
View Full Code Here


            if ( bobberArchetype.getTemplates() != null && bobberArchetype.getTemplates().size() > 0 )
            {
                serializer.startTag( NAMESPACE, "templates" );
                for ( Iterator iter = bobberArchetype.getTemplates().iterator(); iter.hasNext(); )
                {
                    Template o = (Template) iter.next();
                    writeTemplate( o, "template", serializer );
                }
                serializer.endTag( NAMESPACE, "templates" );
            }
            serializer.endTag( NAMESPACE, tagName );
View Full Code Here

     * @return Template
     */
    private Template parseTemplate(String tagName, XmlPullParser parser, boolean strict)
        throws IOException, XmlPullParserException
    {
        Template template = new Template();
        java.util.Set parsed = new java.util.HashSet();
        while ( parser.nextTag() == XmlPullParser.START_TAG )
        {
            if ( parser.getName().equals( "file" )  )
            {
                if ( parsed.contains( "file" ) )
                {
                    throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null );
                }
                parsed.add( "file" );
                template.setFile( getTrimmedValue( parser.nextText()) );
            }
            else if ( parser.getName().equals( "output" )  )
            {
                if ( parsed.contains( "output" ) )
                {
                    throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null );
                }
                parsed.add( "output" );
                template.setOutput( getTrimmedValue( parser.nextText()) );
            }
            else if ( parser.getName().equals( "dependsOnVar" )  )
            {
                if ( parsed.contains( "dependsOnVar" ) )
                {
                    throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null );
                }
                parsed.add( "dependsOnVar" );
                template.setDependsOnVar( getTrimmedValue( parser.nextText()) );
            }
            else
            {
                if ( strict )
                {
View Full Code Here

            urls[0] = archetypeArtifact.getFile().toURI().toURL();
            URLClassLoader archetypeJarLoader = new URLClassLoader(urls);

            Thread.currentThread().setContextClassLoader(archetypeJarLoader);
            for (Iterator i = archetype.getTemplates().iterator(); i.hasNext();) {
                final Template template = (Template) i.next();

                // Check the optional 'condition' property on the template.
                // If present and the variable it points to is 'true', then
                // continue processing. If it's false, then skip.
                // If condition is not specified, assume the template should
                // be processed.
                boolean shouldProcess = true;
                String condition = template.getDependsOnVar();
                String requiredValue=null;
                List options = new ArrayList();
                if (StringUtils.isNotEmpty(condition)) {
                    //Crappy logic processing -- for now
                    boolean not=false;
                    //Allow very simple matching logic to match templates against variable values
                    int x = condition.indexOf("!=");
                    getLogger().debug("Processing Condition : " + condition);                                       
                    if(x > -1) {
                        not=true;
                        requiredValue = condition.substring(x+2).trim();
                        options = getListOfValues(requiredValue);
                        condition = condition.substring(0, x).trim();
                    }
                    else {
                        x = condition.indexOf("=");
                        if(x > -1) {
                            requiredValue = condition.substring(x+1);
                            options = getListOfValues(requiredValue);
                            condition = condition.substring(0, x);
                        }
                    }
                    getLogger().debug("Not Expr: " + not);
                    getLogger().debug("Condition Value: '" + condition + "'");
                    getLogger().debug("Required Value: '" + requiredValue + "'");
                    final Variable var = (Variable) findVariable(condition, variables);
                    if (var != null) {
                        final String strValue = (String) context.get(var.getName());
                        getLogger().debug("Variable Value is: '" + strValue + "'");
                        if(requiredValue==null)
                        {
                            if (!Boolean.valueOf(strValue).booleanValue()) {
                                shouldProcess = false;
                            }
                        } else {
                            if(!options.contains(strValue))
                            {
                                shouldProcess = false;
                            }
                        }

                    } else {
                        getLogger().debug("Variable Value is: null");                                               
                        shouldProcess=false;
                    }
                    if(not) {
                        shouldProcess = !shouldProcess;
                    }
                }

                if (shouldProcess) {
                    processTemplate(template, outputDirectory, context);
                } else {
                    getLogger().debug("Condition not met, skipping " + template.getOutput());
                }
            }

        }
        catch (MalformedURLException mfe) {
View Full Code Here

            URLClassLoader archetypeJarLoader = new URLClassLoader(urls);

            Thread.currentThread().setContextClassLoader(archetypeJarLoader);
            for (Iterator i = archetype.getTemplates().iterator(); i.hasNext();)
            {
                final Template template = (Template) i.next();

                // Check the optional 'condition' property on the template.
                // If present and the variable it points to is 'true', then
                // continue processing. If it's false, then skip.
                // If condition is not specified, assume the template should
                // be processed.
                boolean shouldProcess = true;
                String condition = template.getDependsOnVar();
                String requiredValue = null;
                List options = new ArrayList();
                if (StringUtils.isNotEmpty(condition))
                {
                    //Crappy logic processing -- for now
                    boolean not = false;
                    //Allow very simple matching logic to match templates against variable values
                    int x = condition.indexOf("!=");
                    getLogger().debug("Processing Condition : " + condition);
                    if (x > -1)
                    {
                        not = true;
                        requiredValue = condition.substring(x + 2).trim();
                        options = getListOfValues(requiredValue);
                        condition = condition.substring(0, x).trim();
                    }
                    else
                    {
                        x = condition.indexOf("=");
                        if (x > -1)
                        {
                            requiredValue = condition.substring(x + 1);
                            options = getListOfValues(requiredValue);
                            condition = condition.substring(0, x);
                        }
                    }
                    getLogger().debug("Not Expr: " + not);
                    getLogger().debug("Condition Value: '" + condition + "'");
                    getLogger().debug("Required Value: '" + requiredValue + "'");
                    final Variable var = (Variable) findVariable(condition, variables);
                    if (var != null)
                    {
                        final String strValue = (String) context.get(var.getName());
                        getLogger().debug("Variable Value is: '" + strValue + "'");
                        if (requiredValue == null)
                        {
                            if (!Boolean.valueOf(strValue).booleanValue())
                            {
                                shouldProcess = false;
                            }
                        }
                        else
                        {
                            if (!options.contains(strValue))
                            {
                                shouldProcess = false;
                            }
                        }

                    }
                    else
                    {
                        getLogger().debug("Variable Value is: null");
                        shouldProcess = false;
                    }
                    if (not)
                    {
                        shouldProcess = !shouldProcess;
                    }
                }

                if (shouldProcess)
                {
                    processTemplate(template, outputDirectory, context);
                }
                else
                {
                    getLogger().debug("Condition not met, skipping " + template.getOutput());
                }
            }

        }
        catch (MalformedURLException mfe)
View Full Code Here

TOP

Related Classes of com.javaforge.bobber.archetype.model.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.