private ArchetypeConfiguration createArchetypeConfiguration( Properties properties ) { ArchetypeConfiguration configuration = new ArchetypeConfiguration(); configuration.setGroupId( properties.getProperty( Constants.ARCHETYPE_GROUP_ID ) ); configuration.setArtifactId( properties.getProperty( Constants.ARCHETYPE_ARTIFACT_ID ) ); configuration.setVersion( properties.getProperty( Constants.ARCHETYPE_VERSION ) ); configuration.setUrl( properties.getProperty( Constants.ARCHETYPE_URL ) ); configuration.setDescription( properties.getProperty( Constants.ARCHETYPE_DESCRIPTION ) ); return configuration; }
public boolean confirmConfiguration( ArchetypeConfiguration archetypeConfiguration ) throws PrompterException { StringBuilder query = new StringBuilder( "Confirm archetype configuration:\n" + Constants.ARCHETYPE_GROUP_ID + "=" + archetypeConfiguration.getGroupId() + "\n" + Constants.ARCHETYPE_ARTIFACT_ID + "=" + archetypeConfiguration.getArtifactId() + "\n" + Constants.ARCHETYPE_VERSION + "=" + archetypeConfiguration.getVersion() + "\n" ); for ( Iterator<?> propertiesIter = archetypeConfiguration.getProperties().keySet().iterator(); propertiesIter.hasNext(); ) { String property = (String) propertiesIter.next(); query.append( property + "=" + archetypeConfiguration.getProperty( property ) + "\n" ); } String answer = prompter.prompt( query.toString(), "Y" ); return "Y".equalsIgnoreCase( answer ); }
private void addRequiredProperty( ArchetypeConfiguration configuration, Properties properties, String key, String defaultValue, boolean initPropertyWithDefault ) { if ( !configuration.isConfigured( key ) && configuration.getDefaultValue( key ) == null ) { addOldRequiredProperty( configuration, properties, key, defaultValue, initPropertyWithDefault ); } }
public Properties toProperties() { Properties result = new Properties(); result.putAll( properties ); result.setProperty( Constants.ARCHETYPE_GROUP_ID, StringUtils.isNotEmpty( getGroupId() ) ? getGroupId() : "" ); result.setProperty( Constants.ARCHETYPE_ARTIFACT_ID, StringUtils.isNotEmpty( getArtifactId() ) ? getArtifactId() : "" ); result.setProperty( Constants.ARCHETYPE_VERSION, StringUtils.isNotEmpty( getVersion() ) ? getVersion() : "" ); if ( StringUtils.isNotEmpty( getGoals() ) ) { result.setProperty( Constants.ARCHETYPE_POST_GENERATION_GOALS, getGoals() ); } return result; }
List<String> propertiesRequired = archetypeConfiguration.getRequiredProperties(); getLogger().debug( "Required properties before content sort: " + propertiesRequired ); Collections.sort( propertiesRequired, new RequiredPropertyComparator( archetypeConfiguration ) ); getLogger().debug( "Required properties after content sort: " + propertiesRequired ); if ( !archetypeConfiguration.isConfigured() ) if ( !archetypeConfiguration.isConfigured( requiredProperty ) ) String packageDefault = archetypeConfiguration.getDefaultValue( requiredProperty ); packageDefault = ( null == packageDefault || "".equals( packageDefault ) ) ? archetypeConfiguration.getProperty( "groupId" ) : archetypeConfiguration.getDefaultValue( requiredProperty ); archetypeConfiguration.setProperty( requiredProperty, value ); String value = archetypeConfiguration.getDefaultValue( requiredProperty ); archetypeConfiguration.getPropertyValidationRegex( requiredProperty ) ); archetypeConfiguration.setProperty( requiredProperty, value ); "Using property: " + requiredProperty + " = " + archetypeConfiguration.getProperty( requiredProperty ) ); archetypeConfiguration.setProperty( requiredProperty, archetypeConfiguration.getProperty( requiredProperty ) ); "Using property: " + requiredProperty + " = " + archetypeConfiguration.getProperty( requiredProperty ) );
configuration.setName( archetypeDescriptor.getName() ); getLogger().debug( "Adding requiredProperty " + key ); configuration.addRequiredProperty( key ); configuration.setProperty( key, value ); getLogger().debug( "Setting property " + key + "=" + value ); configuration.setProperty( key, defaultValue ); getLogger().debug( "Setting property " + key + "=" + defaultValue ); configuration.setDefaultProperty( key, defaultValue ); getLogger().debug( "Setting defaultProperty " + key + "=" + defaultValue ); configuration.setPropertyValidationRegex( key, validationRegex ); getLogger().debug( "Setting validation regular expression " + key + "=" + defaultValue ); configuration.getProperty( Constants.GROUP_ID ), true ); configuration.setProperty( Constants.ARCHETYPE_POST_GENERATION_GOALS, postGenerationGoals );
if ( !archetypeConfiguration.isConfigured() ) if ( !archetypeConfiguration.isConfigured() )// <editor-fold text="..."> if ( !archetypeConfiguration.isConfigured( Constants.GROUP_ID ) ) archetypeConfiguration.setProperty( Constants.GROUP_ID, archetypeCreationQueryer.getGroupId( archetypeConfiguration.getDefaultValue( Constants.GROUP_ID ) ) ); if ( !archetypeConfiguration.isConfigured( Constants.ARTIFACT_ID ) ) archetypeConfiguration.setProperty( Constants.ARTIFACT_ID, archetypeCreationQueryer.getArtifactId( archetypeConfiguration.getDefaultValue( Constants.ARTIFACT_ID ) ) ); if ( !archetypeConfiguration.isConfigured( Constants.VERSION ) ) archetypeConfiguration.setProperty( Constants.VERSION, archetypeCreationQueryer.getVersion( archetypeConfiguration.getDefaultValue( Constants.VERSION ) ) ); if ( !archetypeConfiguration.isConfigured( Constants.PACKAGE ) ) archetypeConfiguration.setProperty( Constants.PACKAGE, archetypeCreationQueryer.getPackage( StringUtils.isEmpty( resolvedPackage ) ? archetypeConfiguration.getDefaultValue( Constants.PACKAGE ) : resolvedPackage ) );
private void addOldRequiredProperty( ArchetypeConfiguration configuration, Properties properties, String key, String defaultValue, boolean initPropertyWithDefault ) { getLogger().debug( "Adding requiredProperty " + key ); configuration.addRequiredProperty( key ); String property = properties.getProperty( key ); if ( property != null ) { configuration.setProperty( key, property ); configuration.setDefaultProperty( key, property ); } else if ( defaultValue != null ) { if ( initPropertyWithDefault ) { configuration.setProperty( key, defaultValue ); } configuration.setDefaultProperty( key, defaultValue ); } getLogger().debug( "Setting property " + key + "=" + configuration.getProperty( key ) ); }
private void restoreCommandLineProperties( ArchetypeConfiguration archetypeConfiguration, Properties executionProperties ) { getLogger().debug( "Restoring command line properties" ); for ( String property : archetypeConfiguration.getRequiredProperties() ) { if ( executionProperties.containsKey( property ) ) { archetypeConfiguration.setProperty( property, executionProperties.getProperty( property ) ); getLogger().debug( "Restored " + property + "=" + archetypeConfiguration.getProperty( property ) ); } } }
public ArchetypeConfiguration createArchetypeConfiguration( MavenProject project, ArchetypeDefinition archetypeDefinition, Properties properties ) { getLogger().debug( "Creating ArchetypeConfiguration from ArchetypeDefinition, MavenProject and Properties" ); ArchetypeConfiguration configuration = createArchetypeConfiguration( properties ); for ( Iterator<?> requiredProperties = properties.keySet().iterator(); requiredProperties.hasNext(); ) { String requiredProperty = (String) requiredProperties.next(); if ( !requiredProperty.contains( "." ) ) { getLogger().debug( "Adding requiredProperty " + requiredProperty ); configuration.addRequiredProperty( requiredProperty ); configuration.setProperty( requiredProperty, properties.getProperty( requiredProperty ) ); getLogger().debug( "Setting property " + requiredProperty + "=" + configuration.getProperty( requiredProperty ) ); } } addRequiredProperty( configuration, properties, Constants.GROUP_ID, project.getGroupId() ); addRequiredProperty( configuration, properties, Constants.ARTIFACT_ID, project.getArtifactId() ); addRequiredProperty( configuration, properties, Constants.VERSION, project.getVersion() ); addRequiredProperty( configuration, properties, Constants.PACKAGE, null ); setProperty( configuration, properties, Constants.ARCHETYPE_GROUP_ID ); setProperty( configuration, properties, Constants.ARCHETYPE_ARTIFACT_ID ); setProperty( configuration, properties, Constants.ARCHETYPE_VERSION ); setProperty( configuration, properties, Constants.ARCHETYPE_URL ); setProperty( configuration, properties, Constants.ARCHETYPE_DESCRIPTION ); return configuration; }
public boolean confirmConfiguration( ArchetypeConfiguration archetypeConfiguration ) throws PrompterException { StringBuilder query = new StringBuilder( "Confirm properties configuration:\n" ); for ( String property : archetypeConfiguration.getRequiredProperties() ) { query.append( property + ": " + archetypeConfiguration.getProperty( property ) + "\n" ); } String answer = prompter.prompt( query.toString(), "Y" ); return "Y".equalsIgnoreCase( answer ); }
@SuppressWarnings( "checkstyle:linelength" ) public ArchetypeConfiguration createArchetypeConfiguration( org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor archetypeDescriptor, Properties properties ) { getLogger().debug( "Creating ArchetypeConfiguration from legacy descriptor and Properties" ); ArchetypeConfiguration configuration = createArchetypeConfiguration( properties ); configuration.setName( archetypeDescriptor.getId() ); addOldRequiredProperty( configuration, properties, Constants.GROUP_ID, null, false ); addOldRequiredProperty( configuration, properties, Constants.ARTIFACT_ID, null, false ); addOldRequiredProperty( configuration, properties, Constants.VERSION, "1.0-SNAPSHOT", false ); addOldRequiredProperty( configuration, properties, Constants.PACKAGE, configuration.getProperty( Constants.GROUP_ID ), true ); return configuration; }
public void removeRequiredProperty( String string ) { getRequiredProperties().remove( string ); }
public int compare( String left, String right ) { String leftDefault = archetypeConfiguration.getDefaultValue( left ); if ( ( leftDefault != null ) && leftDefault.indexOf( "${" + right + "}" ) >= 0 ) { //left contains right return 1; } String rightDefault = archetypeConfiguration.getDefaultValue( right ); if ( ( rightDefault != null ) && rightDefault.indexOf( "${" + left + "}" ) >= 0 ) { //right contains left return -1; } return comparePropertyName( left, right ); }
List<String> propertiesRequired = archetypeConfiguration.getRequiredProperties(); getLogger().debug( "Required properties before content sort: " + propertiesRequired ); Collections.sort( propertiesRequired, new RequiredPropertyComparator( archetypeConfiguration ) ); getLogger().debug( "Required properties after content sort: " + propertiesRequired ); if ( !archetypeConfiguration.isConfigured() ) if ( !archetypeConfiguration.isConfigured( requiredProperty ) ) String packageDefault = archetypeConfiguration.getDefaultValue( requiredProperty ); packageDefault = ( null == packageDefault || "".equals( packageDefault ) ) ? archetypeConfiguration.getProperty( "groupId" ) : archetypeConfiguration.getDefaultValue( requiredProperty ); archetypeConfiguration.setProperty( requiredProperty, value ); String value = archetypeConfiguration.getDefaultValue( requiredProperty ); archetypeConfiguration.getPropertyValidationRegex( requiredProperty ) ); archetypeConfiguration.setProperty( requiredProperty, value ); "Using property: " + requiredProperty + " = " + archetypeConfiguration.getProperty( requiredProperty ) ); archetypeConfiguration.setProperty( requiredProperty, archetypeConfiguration.getProperty( requiredProperty ) ); "Using property: " + requiredProperty + " = " + archetypeConfiguration.getProperty( requiredProperty ) );
configuration.setName( archetypeDescriptor.getName() ); getLogger().debug( "Adding requiredProperty " + key ); configuration.addRequiredProperty( key ); configuration.setProperty( key, value ); getLogger().debug( "Setting property " + key + "=" + value ); configuration.setProperty( key, defaultValue ); getLogger().debug( "Setting property " + key + "=" + defaultValue ); configuration.setDefaultProperty( key, defaultValue ); getLogger().debug( "Setting defaultProperty " + key + "=" + defaultValue ); configuration.setPropertyValidationRegex( key, validationRegex ); getLogger().debug( "Setting validation regular expression " + key + "=" + defaultValue ); configuration.getProperty( Constants.GROUP_ID ), true ); configuration.setProperty( Constants.ARCHETYPE_POST_GENERATION_GOALS, postGenerationGoals );
if ( !archetypeConfiguration.isConfigured() ) if ( !archetypeConfiguration.isConfigured() )// <editor-fold text="..."> if ( !archetypeConfiguration.isConfigured( Constants.GROUP_ID ) ) archetypeConfiguration.setProperty( Constants.GROUP_ID, archetypeCreationQueryer.getGroupId( archetypeConfiguration.getDefaultValue( Constants.GROUP_ID ) ) ); if ( !archetypeConfiguration.isConfigured( Constants.ARTIFACT_ID ) ) archetypeConfiguration.setProperty( Constants.ARTIFACT_ID, archetypeCreationQueryer.getArtifactId( archetypeConfiguration.getDefaultValue( Constants.ARTIFACT_ID ) ) ); if ( !archetypeConfiguration.isConfigured( Constants.VERSION ) ) archetypeConfiguration.setProperty( Constants.VERSION, archetypeCreationQueryer.getVersion( archetypeConfiguration.getDefaultValue( Constants.VERSION ) ) ); if ( !archetypeConfiguration.isConfigured( Constants.PACKAGE ) ) archetypeConfiguration.setProperty( Constants.PACKAGE, archetypeCreationQueryer.getPackage( StringUtils.isEmpty( resolvedPackage ) ? archetypeConfiguration.getDefaultValue( Constants.PACKAGE ) : resolvedPackage ) );
private void addRequiredProperty( ArchetypeConfiguration configuration, Properties properties, String key, String defaultValue ) { getLogger().debug( "Adding requiredProperty " + key ); configuration.addRequiredProperty( key ); if ( defaultValue != null ) { configuration.setDefaultProperty( key, defaultValue ); } if ( properties.getProperty( key ) != null ) { configuration.setProperty( key, properties.getProperty( key ) ); getLogger().debug( "Setting property " + key + "=" + configuration.getProperty( Constants.GROUP_ID ) ); } }
public Properties toProperties() { Properties result = new Properties(); result.putAll( properties ); result.setProperty( Constants.ARCHETYPE_GROUP_ID, StringUtils.isNotEmpty( getGroupId() ) ? getGroupId() : "" ); result.setProperty( Constants.ARCHETYPE_ARTIFACT_ID, StringUtils.isNotEmpty( getArtifactId() ) ? getArtifactId() : "" ); result.setProperty( Constants.ARCHETYPE_VERSION, StringUtils.isNotEmpty( getVersion() ) ? getVersion() : "" ); if ( StringUtils.isNotEmpty( getGoals() ) ) { result.setProperty( Constants.ARCHETYPE_POST_GENERATION_GOALS, getGoals() ); } return result; }
private void restoreCommandLineProperties( ArchetypeConfiguration archetypeConfiguration, Properties executionProperties ) { getLogger().debug( "Restoring command line properties" ); for ( String property : archetypeConfiguration.getRequiredProperties() ) { if ( executionProperties.containsKey( property ) ) { archetypeConfiguration.setProperty( property, executionProperties.getProperty( property ) ); getLogger().debug( "Restored " + property + "=" + archetypeConfiguration.getProperty( property ) ); } } }