Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Created method in RepositoryTemplate createWithoutCommit which will c…
Browse files Browse the repository at this point in the history
…reate an initialized repository object.

Also, updated Template, TemplateSet, and TemplateProvider to expose generic type.
  • Loading branch information
bdemers committed Jun 28, 2011
1 parent 3c69971 commit 39d5feb
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 45 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ target/

# Intellij
*.ipr
*.iml
*.iws

# Other
.svn/
Expand All @@ -28,4 +30,4 @@ bin/
/nexus/nexus-test-harness/nexus-test-harness-its/resources/proxyRepo/nexus977tasks/2/.index/
/nexus/nexus-test-harness/nexus-test-harness-its/resources/nexus2120/files/basic/.index/
nexus/nexus-test-harness/nexus-test-harness-its/test-output
nexus/nexus-clients/nexus-rest-client-java/test-output/
nexus/nexus-clients/nexus-rest-client-java/test-output/
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public interface Configurable
void configure( Object config )
throws ConfigurationException;

/**
* Sets the configuration object without commiting it.
* @throws ConfigurationException
*/
void configureWithoutCommit( Object config )
throws ConfigurationException;

/**
* Returns true if there are some unsaved changes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public void configure( Object config )

}

public void configureWithoutCommit( Object config )
throws ConfigurationException
{
// TODO Auto-generated method stub
}

public boolean isDirty()
{
// TODO Auto-generated method stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.sonatype.nexus.configuration.application.runtime;

import org.sonatype.configuration.ConfigurationException;
import org.sonatype.configuration.validation.InvalidConfigurationException;
import org.sonatype.nexus.configuration.model.CRepository;
import org.sonatype.nexus.configuration.model.Configuration;
import org.sonatype.nexus.proxy.repository.Repository;
Expand All @@ -33,4 +34,14 @@ public interface ApplicationRuntimeConfigurationBuilder
{
Repository createRepositoryFromModel( Configuration configuration, CRepository repoConf )
throws ConfigurationException;

/**
* Creates an empty Repository object based on the role and hint.
* @param role
* @param hint
* @return
* @throws InvalidConfigurationException
*/
Repository createRepository( String role, String hint )
throws InvalidConfigurationException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Repository createRepositoryFromModel( Configuration configuration, CRepos
// ----------------------------------------
// private stuff

private Repository createRepository( String role, String hint )
public Repository createRepository( String role, String hint )
throws InvalidConfigurationException
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.sonatype.nexus.configuration.application.ApplicationConfiguration;

public abstract class AbstractTemplateProvider<T extends Template>
implements TemplateProvider
implements TemplateProvider<T>
{
@Requirement
private ApplicationConfiguration applicationConfiguration;
Expand All @@ -33,12 +33,12 @@ public ApplicationConfiguration getApplicationConfiguration()
return applicationConfiguration;
}

public Template getTemplateById( String id )
public T getTemplateById( String id )
throws NoSuchTemplateIdException
{
TemplateSet templates = getTemplates();
TemplateSet<T> templates = getTemplates();

for ( Template template : templates )
for ( T template : templates )
{
if ( StringUtils.equals( id, template.getId() ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
@ExtensionPoint
@Singleton
public interface TemplateProvider
public interface TemplateProvider<T extends Template>
{
/**
* Lists all templates.
Expand All @@ -47,7 +47,7 @@ public interface TemplateProvider

/**
* Lists all templates that fits supplied filters.
* @param clazz
* @param filters
* @return
*/
TemplateSet getTemplates( Object... filters );
Expand All @@ -59,6 +59,6 @@ public interface TemplateProvider
* @return
* @throws NoSuchTemplateIdException
*/
Template getTemplateById( String id )
T getTemplateById( String id )
throws NoSuchTemplateIdException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@
*/
package org.sonatype.nexus.templates;

import org.codehaus.plexus.util.StringUtils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import org.codehaus.plexus.util.StringUtils;

public class TemplateSet
extends HashSet<Template>
public class TemplateSet<T extends Template>
extends HashSet<T>
implements TemplateProvider
{
private static final long serialVersionUID = 552419423510140977L;

private final Object clazz;

private final TemplateSet parent;
private final TemplateSet<T> parent;

public TemplateSet( Object clazz )
{
this( clazz, null );
}

public TemplateSet( Object clazz, TemplateSet templates )
public TemplateSet( Object clazz, TemplateSet<T> templates )
{
super();

Expand All @@ -55,7 +55,7 @@ public TemplateSet( Object clazz, TemplateSet templates )
}
else
{
for ( Template template : parent )
for ( T template : parent )
{
if ( template.targetFits( clazz ) )
{
Expand All @@ -67,7 +67,7 @@ public TemplateSet( Object clazz, TemplateSet templates )
}

@Override
public boolean add( Template elem )
public boolean add( T elem )
{
if ( getClazz() != null && elem.targetFits( getClazz() ) )
{
Expand All @@ -85,24 +85,24 @@ else if ( getClazz() == null )

/**
* Picks the only one remained template in this set.
*
*
* @return
* @throws IllegalStateException
*/
public Template pick()
public T pick()
throws IllegalStateException
{
return pick( true );
}

/**
* Picks one template from this set. Will enforce that set has only one member if the forceSingleHit is true.
*
*
* @param forceSingleHit
* @return
* @throws IllegalStateException
*/
public Template pick( boolean forceSingleHit )
public T pick( boolean forceSingleHit )
throws IllegalStateException
{
if ( !forceSingleHit || size() == 1 )
Expand All @@ -120,27 +120,27 @@ public Object getClazz()
return clazz;
}

public TemplateSet getParent()
public TemplateSet<T> getParent()
{
return parent;
}

public List<Template> getTemplatesList()
public List<T> getTemplatesList()
{
return new ArrayList<Template>( this );
return new ArrayList<T>( this );
}

public TemplateSet getTemplates()
public TemplateSet<T> getTemplates()
{
return this;
}

public TemplateSet getTemplates( Object filter )
public TemplateSet<T> getTemplates( Object filter )
{
return new TemplateSet( filter, this );
}

public TemplateSet getTemplates( Object... filters )
public TemplateSet<T> getTemplates( Object... filters )
{
TemplateSet par = this;

Expand All @@ -152,10 +152,10 @@ public TemplateSet getTemplates( Object... filters )
return par;
}

public Template getTemplateById( String id )
public T getTemplateById( String id )
throws NoSuchTemplateIdException
{
for ( Template template : this )
for ( T template : this )
{
if ( StringUtils.equals( id, template.getId() ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
*/
package org.sonatype.nexus.templates.repository;

import java.io.IOException;

import org.sonatype.configuration.ConfigurationException;
import org.sonatype.nexus.configuration.model.CRepository;
import org.sonatype.nexus.configuration.model.CRepositoryCoreConfiguration;
import org.sonatype.nexus.proxy.registry.ContentClass;
import org.sonatype.nexus.proxy.repository.ConfigurableRepository;
import org.sonatype.nexus.proxy.repository.Repository;
import org.sonatype.nexus.templates.AbstractConfigurableTemplate;

import java.io.IOException;

public abstract class AbstractRepositoryTemplate
extends AbstractConfigurableTemplate
implements RepositoryTemplate
Expand Down Expand Up @@ -61,8 +62,8 @@ public AbstractRepositoryTemplate( AbstractRepositoryTemplateProvider provider,
@Override
public boolean targetFits( Object clazz )
{
return super.targetFits( clazz ) || targetIsClassAndFitsClass( clazz, getMainFacet() )
|| ( targetIsClassAndFitsClass( clazz, getContentClass().getClass() ) || getContentClass().equals( clazz ) );
return super.targetFits( clazz ) || targetIsClassAndFitsClass( clazz, getMainFacet() ) || (
targetIsClassAndFitsClass( clazz, getContentClass().getClass() ) || getContentClass().equals( clazz ) );
}

@Override
Expand Down Expand Up @@ -100,6 +101,20 @@ public ConfigurableRepository getConfigurableRepository()
return configurableRepository;
}

public Repository createWithoutCommit()
throws IOException, ConfigurationException
{
Repository repository =
getTemplateProvider().getRuntimeConfigurationBuilder().createRepository( this.getRepositoryProviderRole(), this.getRepositoryProviderHint() );

// reset the template
setCoreConfiguration( null );

repository.configureWithoutCommit( getCoreConfiguration() );

return repository;
}

public Repository create()
throws ConfigurationException, IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.codehaus.plexus.component.annotations.Requirement;
import org.sonatype.configuration.ConfigurationException;
import org.sonatype.nexus.configuration.application.NexusConfiguration;
import org.sonatype.nexus.configuration.application.runtime.ApplicationRuntimeConfigurationBuilder;
import org.sonatype.nexus.configuration.model.CRepository;
import org.sonatype.nexus.configuration.model.CRepositoryCoreConfiguration;
import org.sonatype.nexus.proxy.registry.ContentClass;
Expand All @@ -35,7 +36,7 @@

/**
* An abstract class for template providers that provides templates for Repositories.
*
*
* @author cstamas
*/
public abstract class AbstractRepositoryTemplateProvider
Expand All @@ -50,6 +51,12 @@ public abstract class AbstractRepositoryTemplateProvider
@Requirement
private RemoteProviderHintFactory remoteProviderHintFactory;

/**
* The runtime configuration builder.
*/
@Requirement
private ApplicationRuntimeConfigurationBuilder runtimeConfigurationBuilder;

protected Repository createRepository( CRepository repository )
throws ConfigurationException, IOException
{
Expand All @@ -61,17 +68,22 @@ public RemoteProviderHintFactory getRemoteProviderHintFactory()
return remoteProviderHintFactory;
}

public ApplicationRuntimeConfigurationBuilder getRuntimeConfigurationBuilder()
{
return runtimeConfigurationBuilder;
}

public Class<RepositoryTemplate> getTemplateClass()
{
return RepositoryTemplate.class;
}

public TemplateSet getTemplates( Object filter )
public TemplateSet<RepositoryTemplate> getTemplates( Object filter )
{
return getTemplates().getTemplates( filter );
}

public TemplateSet getTemplates( Object... filters )
public TemplateSet<RepositoryTemplate> getTemplates( Object... filters )
{
return getTemplates().getTemplates( filters );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class DefaultRepositoryTemplateProvider

private static final String DEFAULT_GROUP = "default_group";

public TemplateSet getTemplates()
public TemplateSet<RepositoryTemplate> getTemplates()
{
TemplateSet templates = new TemplateSet( null );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ public interface RepositoryTemplate

Repository create()
throws ConfigurationException, IOException;

/**
* Creates a Repository object without performing any validation or persistence. The Repository is NOT added to the
* repository registry, the caller of this method MUST call Repository.commit() and RepositoryRegistry.addRepository() prior to calling this method.
* @return
* @throws IOException
* @throws ConfigurationException
*/
Repository createWithoutCommit()
throws IOException, ConfigurationException;
}
Loading

0 comments on commit 39d5feb

Please sign in to comment.