Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archetype-574: Added fix to use default values on integration-test if… #31

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -132,7 +132,7 @@ public void generateArchetype( ArchetypeGenerationRequest request, File archetyp
throw new ArchetypeNotConfigured( exceptionMessage.toString(), missingProperties );
}

Context context = prepareVelocityContext( request );
Context context = prepareVelocityContext ( request, archetypeDescriptor );

String packageName = request.getPackage();
String artifactId = request.getArtifactId();
Expand Down Expand Up @@ -394,7 +394,8 @@ private boolean isArchetypeConfigured( ArchetypeDescriptor archetypeDescriptor,
{
for ( RequiredProperty requiredProperty : archetypeDescriptor.getRequiredProperties() )
{
if ( StringUtils.isEmpty( request.getProperties().getProperty( requiredProperty.getKey() ) ) )
if ( StringUtils.isEmpty( request.getProperties().getProperty( requiredProperty.getKey() ) )
&& StringUtils.isEmpty( requiredProperty.getDefaultValue() ) )
{
return false;
}
Expand All @@ -408,7 +409,7 @@ private void setParentArtifactId( Context context, String artifactId )
context.put( Constants.PARENT_ARTIFACT_ID, artifactId );
}

private Context prepareVelocityContext( ArchetypeGenerationRequest request )
private Context prepareVelocityContext( ArchetypeGenerationRequest request, ArchetypeDescriptor archetypeDescript )
{
Context context = new VelocityContext();
context.put( Constants.GROUP_ID, request.getGroupId() );
Expand Down Expand Up @@ -440,12 +441,21 @@ private Context prepareVelocityContext( ArchetypeGenerationRequest request )

String value = request.getProperties().getProperty( key );

String defaultValue = getDefaultValue( key, archetypeDescript );

if ( maybeVelocityExpression( value ) )
{
value = evaluateExpression( context, key, value );
}

context.put( key, value );
if ( StringUtils.isEmpty ( value ) )
{
context.put( key, defaultValue );
}
else
{
context.put( key, value );
}

if ( getLogger().isInfoEnabled() )
{
Expand All @@ -455,6 +465,18 @@ private Context prepareVelocityContext( ArchetypeGenerationRequest request )
return context;
}

private String getDefaultValue( String key, ArchetypeDescriptor archetypeDescriptor )
{
for ( RequiredProperty property : archetypeDescriptor.getRequiredProperties() )
{
if ( property.getKey().equals( key ) )
{
return property.getDefaultValue();
}
}
return null;
}

private boolean maybeVelocityExpression( String value )
{
return value != null && value.contains( "${" );
Expand Down