diff options
author | Brett Porter <brett@apache.org> | 2009-11-28 14:28:30 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2009-11-28 14:28:30 +0000 |
commit | 3d61eecdc490f6a75784502d289e0989dc36d53f (patch) | |
tree | aad17b291c5bee435fb188981e28ddd03c929c35 /archiva-modules/metadata | |
parent | 61745667ab1f4775ca2b73ccfae6f7a53d6fc305 (diff) | |
download | archiva-3d61eecdc490f6a75784502d289e0989dc36d53f.tar.gz archiva-3d61eecdc490f6a75784502d289e0989dc36d53f.zip |
[MRM-1283] improve performance of on-demand resolution from storage. Still could be improved.
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885095 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/metadata')
7 files changed, 187 insertions, 28 deletions
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java index 09b3fd93f..5ba2b79de 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java @@ -19,12 +19,15 @@ package org.apache.archiva.metadata.repository; * under the License. */ +import java.util.ArrayList; import java.util.Collection; import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; +import org.apache.archiva.metadata.repository.filter.ExcludesFilter; +import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver; /** * @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver" @@ -44,7 +47,7 @@ public class DefaultMetadataResolver * * @plexus.requirement role-hint="maven2" */ - private MetadataResolver storageResolver; + private StorageMetadataResolver storageResolver; public ProjectMetadata getProject( String repoId, String namespace, String projectId ) { @@ -104,56 +107,79 @@ public class DefaultMetadataResolver public Collection<String> getRootNamespaces( String repoId ) { - Collection<String> rootNamespaces = metadataRepository.getRootNamespaces( repoId ); - - // TODO: may want caching on this - Collection<String> storageRootNamespaces = storageResolver.getRootNamespaces( repoId ); - if ( storageRootNamespaces != null && !storageRootNamespaces.equals( rootNamespaces ) ) + Collection<String> namespaces = metadataRepository.getRootNamespaces( repoId ); + Collection<String> storageNamespaces = + storageResolver.getRootNamespaces( repoId, new ExcludesFilter<String>( namespaces ) ); + if ( storageNamespaces != null && !storageNamespaces.isEmpty() ) { - // TODO: update the metadata repository - rootNamespaces = storageRootNamespaces; + for ( String n : storageNamespaces ) + { + metadataRepository.updateNamespace( repoId, n ); + } + namespaces = new ArrayList<String>( namespaces ); + namespaces.addAll( storageNamespaces ); } - - return rootNamespaces; + return namespaces; } public Collection<String> getNamespaces( String repoId, String namespace ) { Collection<String> namespaces = metadataRepository.getNamespaces( repoId, namespace ); - // TODO: may want caching on this - Collection<String> storageNamespaces = storageResolver.getNamespaces( repoId, namespace ); - if ( storageNamespaces != null && !storageNamespaces.equals( namespaces ) ) + Collection<String> storageNamespaces = + storageResolver.getNamespaces( repoId, namespace, new ExcludesFilter<String>( namespaces ) ); + if ( storageNamespaces != null && !storageNamespaces.isEmpty() ) { - // TODO: update the metadata repository - namespaces = storageNamespaces; + for ( String n : storageNamespaces ) + { + metadataRepository.updateNamespace( repoId, namespace + "." + n ); + } + namespaces = new ArrayList<String>( namespaces ); + namespaces.addAll( storageNamespaces ); } - return namespaces; } public Collection<String> getProjects( String repoId, String namespace ) { Collection<String> projects = metadataRepository.getProjects( repoId, namespace ); - // TODO: may want caching on this - Collection<String> storageProjects = storageResolver.getProjects( repoId, namespace ); - if ( storageProjects != null && !storageProjects.equals( projects ) ) + Collection<String> storageProjects = + storageResolver.getProjects( repoId, namespace, new ExcludesFilter<String>( projects ) ); + if ( storageProjects != null && !storageProjects.isEmpty() ) { - // TODO: update the metadata repository - projects = storageProjects; + for ( String projectId : storageProjects ) + { + ProjectMetadata projectMetadata = storageResolver.getProject( repoId, namespace, projectId ); + if ( projectMetadata != null ) + { + metadataRepository.updateProject( repoId, projectMetadata ); + } + } + projects = new ArrayList<String>( projects ); + projects.addAll( storageProjects ); } - return projects; } public Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) + throws MetadataResolverException { Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId ); - // TODO: may want caching on this - Collection<String> storageProjectVersions = storageResolver.getProjectVersions( repoId, namespace, projectId ); - if ( storageProjectVersions != null && !storageProjectVersions.equals( projectVersions ) ) + Collection<String> storageProjectVersions = storageResolver.getProjectVersions( repoId, namespace, projectId, + new ExcludesFilter<String>( + projectVersions ) ); + if ( storageProjectVersions != null && !storageProjectVersions.isEmpty() ) { - // TODO: update the metadata repository - projectVersions = storageProjectVersions; + for ( String projectVersion : storageProjectVersions ) + { + ProjectVersionMetadata versionMetadata = + storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion ); + if ( versionMetadata != null ) + { + metadataRepository.updateProjectVersion( repoId, namespace, projectId, versionMetadata ); + } + } + projectVersions = new ArrayList<String>( projectVersions ); + projectVersions.addAll( storageProjectVersions ); } return projectVersions; } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index a41016be3..3428320f9 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -30,6 +30,7 @@ public interface MetadataRepository /** * Update metadata for a particular project in the metadata repository, or create it if it does not already exist. * + * @param repoId the repository the project is in * @param project the project metadata to create or update */ void updateProject( String repoId, ProjectMetadata project ); @@ -42,4 +43,6 @@ public interface MetadataRepository void updateProjectReference( String repoId, String namespace, String projectId, String projectVersion, ProjectVersionReference reference ); + + void updateNamespace( String repoId, String namespace ); } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java index 2f957c813..d804b60fc 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java @@ -54,5 +54,6 @@ public interface MetadataResolver Collection<String> getProjects( String repoId, String namespace ); - Collection<String> getProjectVersions( String repoId, String namespace, String projectId ); + Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) + throws MetadataResolverException; } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/AllFilter.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/AllFilter.java new file mode 100644 index 000000000..f3f571f2f --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/AllFilter.java @@ -0,0 +1,29 @@ +package org.apache.archiva.metadata.repository.filter; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class AllFilter<T> + implements Filter<T> +{ + public boolean accept( T value ) + { + return true; + } +}
\ No newline at end of file diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/ExcludesFilter.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/ExcludesFilter.java new file mode 100644 index 000000000..d97c4ed99 --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/ExcludesFilter.java @@ -0,0 +1,38 @@ +package org.apache.archiva.metadata.repository.filter; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Collection; + +public class ExcludesFilter<T> + implements Filter<T> +{ + private Collection<T> excludes; + + public ExcludesFilter( Collection<T> excludes ) + { + this.excludes = excludes; + } + + public boolean accept( T value ) + { + return !excludes.contains( value ); + } +} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/Filter.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/Filter.java new file mode 100644 index 000000000..88344e8b3 --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/filter/Filter.java @@ -0,0 +1,25 @@ +package org.apache.archiva.metadata.repository.filter; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public interface Filter<T> +{ + boolean accept( T value ); +} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/StorageMetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/StorageMetadataResolver.java new file mode 100644 index 000000000..a83bb9ca1 --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/StorageMetadataResolver.java @@ -0,0 +1,37 @@ +package org.apache.archiva.metadata.repository.storage; + +import java.util.Collection; + +import org.apache.archiva.metadata.repository.MetadataResolver; +import org.apache.archiva.metadata.repository.filter.Filter; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public interface StorageMetadataResolver + extends MetadataResolver +{ + Collection<String> getRootNamespaces( String repoId, Filter<String> filter ); + + Collection<String> getNamespaces( String repoId, String namespace, Filter<String> filter ); + + Collection<String> getProjects( String repoId, String namespace, Filter<String> filter ); + + Collection<String> getProjectVersions( String repoId, String namespace, String projectId, Filter<String> filter ); +} |