diff options
author | Olivier Lamy <olamy@apache.org> | 2013-12-26 12:56:18 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2013-12-26 12:56:18 +0000 |
commit | 04d1d172a6bb67a4a10f36f2498cac22e2163f4a (patch) | |
tree | bd8833cdc9fc09316ad25f568682e0ce24b74928 | |
parent | 3c2817d54508704f21b343dce0592b2c3b70134f (diff) | |
download | archiva-04d1d172a6bb67a4a10f36f2498cac22e2163f4a.tar.gz archiva-04d1d172a6bb67a4a10f36f2498cac22e2163f4a.zip |
fix mapping with modelmapper
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1553476 13f79535-47bb-0310-9956-ffa450edef68
11 files changed, 77 insertions, 86 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml index 99e37c8ee..25e2d15ef 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml @@ -180,23 +180,10 @@ </dependency> <dependency> - <groupId>net.sf.beanlib</groupId> - <artifactId>beanlib</artifactId> - <exclusions> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - <exclusion> - <groupId>aopalliance</groupId> - <artifactId>aopalliance</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - </exclusions> + <groupId>org.modelmapper</groupId> + <artifactId>modelmapper</artifactId> </dependency> + <dependency> <groupId>org.codehaus.woodstox</groupId> <artifactId>woodstox-core-asl</artifactId> diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java index bd19e65b2..8e1b8a812 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java @@ -26,6 +26,7 @@ import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.common.utils.VersionUtil; +import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.RepositorySessionFactory; @@ -46,6 +47,8 @@ import org.apache.archiva.security.ArchivaSecurityException; import org.apache.archiva.security.PrincipalNotFoundException; import org.apache.archiva.security.UserRepositories; import org.apache.commons.lang.StringUtils; +import org.modelmapper.ModelMapper; +import org.modelmapper.PropertyMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; @@ -83,7 +86,7 @@ public abstract class AbstractRestService * FIXME: this could be multiple implementations and needs to be configured. */ @Inject - @Named(value = "repositorySessionFactory") + @Named( value = "repositorySessionFactory" ) protected RepositorySessionFactory repositorySessionFactory; @Inject @@ -96,7 +99,7 @@ public abstract class AbstractRestService protected RepositoryContentFactory repositoryContentFactory; @Inject - @Named(value = "archivaTaskScheduler#repository") + @Named( value = "archivaTaskScheduler#repository" ) protected DefaultRepositoryArchivaTaskScheduler repositoryTaskScheduler; @@ -312,4 +315,31 @@ public abstract class AbstractRestService } return true; } + + private static class ModelMapperHolder + { + private static ModelMapper MODEL_MAPPER = new ModelMapper(); + + static + { + MODEL_MAPPER.addMappings( new SearchResultHitMap() ); + } + } + + + private static class SearchResultHitMap + extends PropertyMap<SearchResultHit, Artifact> + { + protected void configure() + { + skip().setId( null ); + } + } + + ; + + protected ModelMapper getModelMapper() + { + return ModelMapperHolder.MODEL_MAPPER; + } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java index c43f85047..c5383bb28 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java @@ -18,7 +18,6 @@ package org.apache.archiva.rest.services; * under the License. */ -import net.sf.beanlib.provider.replicator.BeanReplicator; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.RepositoryCommonValidator; import org.apache.archiva.admin.model.beans.ManagedRepository; @@ -170,7 +169,7 @@ public class DefaultManagedRepositoriesService if ( stats != null ) { ArchivaRepositoryStatistics archivaRepositoryStatistics = - new BeanReplicator().replicateBean( stats, ArchivaRepositoryStatistics.class ); + getModelMapper().map( stats, ArchivaRepositoryStatistics.class ); archivaRepositoryStatistics.setDuration( archivaRepositoryStatistics.getScanEndTime().getTime() - archivaRepositoryStatistics.getScanStartTime().getTime() ); archivaRepositoryStatistics.setLastScanDate( diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java index a2bca4d2f..1b214be22 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java @@ -19,16 +19,15 @@ package org.apache.archiva.rest.services; */ import org.apache.archiva.admin.model.RepositoryAdminException; -import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration; import org.apache.archiva.admin.model.beans.LdapConfiguration; +import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration; import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin; import org.apache.archiva.redback.authentication.Authenticator; import org.apache.archiva.redback.common.ldap.connection.LdapConnection; -import org.apache.archiva.redback.common.ldap.user.LdapUserMapper; -import org.apache.archiva.redback.common.ldap.connection.DefaultLdapConnection; import org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration; import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory; import org.apache.archiva.redback.common.ldap.connection.LdapException; +import org.apache.archiva.redback.common.ldap.user.LdapUserMapper; import org.apache.archiva.redback.components.cache.Cache; import org.apache.archiva.redback.policy.CookieSettings; import org.apache.archiva.redback.policy.PasswordRule; @@ -40,7 +39,6 @@ import org.apache.archiva.rest.api.model.RedbackImplementationsInformations; import org.apache.archiva.rest.api.model.UserManagerImplementationInformation; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.RedbackRuntimeConfigurationService; - import org.apache.commons.lang.StringUtils; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java index 2f4fc210c..bc1f2cc57 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java @@ -19,7 +19,6 @@ package org.apache.archiva.rest.services; * under the License. */ -import net.sf.beanlib.provider.replicator.BeanReplicator; import org.apache.archiva.indexer.search.RepositorySearch; import org.apache.archiva.indexer.search.RepositorySearchException; import org.apache.archiva.indexer.search.SearchFields; @@ -139,7 +138,7 @@ public class DefaultSearchService { return Collections.emptyList(); } - SearchFields searchField = new BeanReplicator().replicateBean( searchRequest, SearchFields.class ); + SearchFields searchField = getModelMapper().map( searchRequest, SearchFields.class ); SearchResultLimits limits = new SearchResultLimits( 0 ); // if no repos set we use ones available for the user @@ -219,7 +218,7 @@ public class DefaultSearchService for ( String version : hit.getVersions() ) { - Artifact versionned = new BeanReplicator().replicateBean( hit, Artifact.class ); + Artifact versionned = getModelMapper().map( hit, Artifact.class ); if ( StringUtils.isNotBlank( version ) ) { diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml index da6bfcb77..4371b0efb 100644 --- a/archiva-modules/plugins/maven2-repository/pom.xml +++ b/archiva-modules/plugins/maven2-repository/pom.xml @@ -141,22 +141,8 @@ <artifactId>wagon-provider-api</artifactId> </dependency> <dependency> - <groupId>net.sf.beanlib</groupId> - <artifactId>beanlib</artifactId> - <exclusions> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - <exclusion> - <groupId>aopalliance</groupId> - <artifactId>aopalliance</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - </exclusions> + <groupId>org.modelmapper</groupId> + <artifactId>modelmapper</artifactId> </dependency> <dependency> <groupId>org.apache.maven.wagon</groupId> @@ -270,7 +256,7 @@ org.sonatype.aether.repository, org.sonatype.aether.util, org.sonatype.aether.util.artifact, - net.sf.beanlib.provider.replicator, + org.modelmapper, org.apache.archiva.maven2.model, org.sonatype.aether.util.graph.selector, org.apache.archiva.metadata.model.maven2, diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java index 49edbe5b2..82c8aa873 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/TreeDependencyNodeVisitor.java @@ -18,9 +18,9 @@ package org.apache.archiva.dependency.tree.maven2; * under the License. */ -import net.sf.beanlib.provider.replicator.BeanReplicator; import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.maven2.model.TreeEntry; +import org.modelmapper.ModelMapper; import org.sonatype.aether.graph.DependencyNode; import org.sonatype.aether.graph.DependencyVisitor; @@ -49,7 +49,7 @@ public class TreeDependencyNodeVisitor public boolean visitEnter( DependencyNode dependencyNode ) { TreeEntry entry = new TreeEntry( - new BeanReplicator().replicateBean( dependencyNode.getDependency().getArtifact(), Artifact.class ) ); + getModelMapper().map( dependencyNode.getDependency().getArtifact(), Artifact.class ) ); entry.getArtifact().setScope( dependencyNode.getDependency().getScope() ); entry.setParent( currentEntry ); currentEntry = entry; @@ -71,4 +71,14 @@ public class TreeDependencyNodeVisitor currentEntry = currentEntry.getParent(); return true; } + + private static class ModelMapperHolder + { + private static ModelMapper MODEL_MAPPER = new ModelMapper(); + } + + protected ModelMapper getModelMapper() + { + return ModelMapperHolder.MODEL_MAPPER; + } } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/MockRepoAdmin.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/MockRepoAdmin.java index 3a5e991aa..eeb7b1c71 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/MockRepoAdmin.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/MockRepoAdmin.java @@ -18,7 +18,6 @@ package org.apache.archiva.configuration; * under the License. */ -import net.sf.beanlib.provider.replicator.BeanReplicator; import org.apache.archiva.admin.model.AuditInformation; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.ManagedRepository; @@ -33,6 +32,7 @@ import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorOrderComparat import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import org.apache.commons.lang.StringUtils; import org.apache.maven.index.context.IndexingContext; +import org.modelmapper.ModelMapper; import org.springframework.stereotype.Service; import javax.inject.Inject; @@ -279,7 +279,7 @@ public class MockRepoAdmin { return proxyConnectorConfiguration == null ? null - : new BeanReplicator().replicateBean( proxyConnectorConfiguration, ProxyConnector.class ); + : new ModelMapper().map( proxyConnectorConfiguration, ProxyConnector.class ); } public List<ProxyConnectorRule> getProxyConnectorRules() diff --git a/archiva-modules/plugins/metadata-store-cassandra/pom.xml b/archiva-modules/plugins/metadata-store-cassandra/pom.xml index 87acba6f4..733535090 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/pom.xml +++ b/archiva-modules/plugins/metadata-store-cassandra/pom.xml @@ -69,22 +69,8 @@ </dependency> <dependency> - <groupId>net.sf.beanlib</groupId> - <artifactId>beanlib</artifactId> - <exclusions> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - <exclusion> - <groupId>aopalliance</groupId> - <artifactId>aopalliance</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - </exclusions> + <groupId>org.modelmapper</groupId> + <artifactId>modelmapper</artifactId> </dependency> <dependency> diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java index 6ab95bba0..4db61b0c8 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java @@ -23,7 +23,6 @@ import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.netflix.astyanax.entitystore.EntityManager; -import net.sf.beanlib.provider.replicator.BeanReplicator; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.FacetedMetadata; @@ -42,6 +41,7 @@ import org.apache.archiva.metadata.repository.cassandra.model.Project; import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel; import org.apache.archiva.metadata.repository.cassandra.model.Repository; import org.apache.commons.lang.StringUtils; +import org.modelmapper.ModelMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -870,7 +870,7 @@ public class CassandraMetadataRepository if ( projectVersionMetadataModel == null ) { projectVersionMetadataModel = - new BeanReplicator().replicateBean( versionMetadata, ProjectVersionMetadataModel.class ); + getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class ); projectVersionMetadataModel.setRowId( key ); } projectVersionMetadataModel.setProjectId( projectId ); @@ -1162,7 +1162,7 @@ public class CassandraMetadataRepository for ( ArtifactMetadataModel model : artifactMetadataModels ) { - ArtifactMetadata artifactMetadata = new BeanReplicator().replicateBean( model, ArtifactMetadata.class ); + ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class ); populateFacets( artifactMetadata ); artifactMetadatas.add( artifactMetadata ); } @@ -1269,7 +1269,7 @@ public class CassandraMetadataRepository for ( ArtifactMetadataModel model : artifactMetadataModels ) { - ArtifactMetadata artifactMetadata = new BeanReplicator().replicateBean( model, ArtifactMetadata.class ); + ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class ); populateFacets( artifactMetadata ); artifactMetadatas.add( artifactMetadata ); } @@ -1380,7 +1380,7 @@ public class CassandraMetadataRepository for ( ArtifactMetadataModel model : artifactMetadataModels ) { - ArtifactMetadata artifactMetadata = new BeanReplicator().replicateBean( model, ArtifactMetadata.class ); + ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class ); populateFacets( artifactMetadata ); artifactMetadatas.add( artifactMetadata ); } @@ -1450,7 +1450,7 @@ public class CassandraMetadataRepository } ProjectVersionMetadata projectVersionMetadata = - new BeanReplicator().replicateBean( projectVersionMetadataModel, ProjectVersionMetadata.class ); + getModelMapper().map( projectVersionMetadataModel, ProjectVersionMetadata.class ); logger.debug( "getProjectVersion repoId: '{}', namespace: '{}', projectId: '{}', projectVersion: {} -> {}", repoId, namespace, projectId, projectVersion, projectVersionMetadata ); @@ -1630,7 +1630,7 @@ public class CassandraMetadataRepository for ( ArtifactMetadataModel model : artifactMetadataModels ) { - ArtifactMetadata artifactMetadata = new BeanReplicator().replicateBean( model, ArtifactMetadata.class ); + ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class ); populateFacets( artifactMetadata ); artifactMetadatas.add( artifactMetadata ); } @@ -1751,4 +1751,15 @@ public class CassandraMetadataRepository throw new IllegalArgumentException( "Access using " + aClass + " is not supported on the cassandra metadata storage" ); } + + + private static class ModelMapperHolder + { + private static ModelMapper MODEL_MAPPER = new ModelMapper(); + } + + protected ModelMapper getModelMapper() + { + return ModelMapperHolder.MODEL_MAPPER; + } } @@ -581,21 +581,6 @@ </dependency> <dependency> - <groupId>net.sf.beanlib</groupId> - <artifactId>beanlib</artifactId> - <version>5.0.2beta</version> - <exclusions> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - <exclusion> - <groupId>aopalliance</groupId> - <artifactId>aopalliance</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec.version}</version> |