From c18da0d9a459e8dd06b7b994d06541ae89587693 Mon Sep 17 00:00:00 2001 From: James William Dumay Date: Wed, 25 Feb 2009 05:59:22 +0000 Subject: [PATCH] RepositoryGroups almost working git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-with-new-repoapi@747671 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/DefaultRepositoryManager.java | 5 +- .../repository/GroupRepositoryManager.java | 66 ++++++++++--------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/DefaultRepositoryManager.java b/archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/DefaultRepositoryManager.java index 75954883b..bf51320f3 100644 --- a/archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/DefaultRepositoryManager.java +++ b/archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/DefaultRepositoryManager.java @@ -69,7 +69,10 @@ public class DefaultRepositoryManager implements SystemRepositoryManager FileInputStream fis = null; try { - fis = new FileInputStream(new File(repository.getLocalPath(), context.getLogicalPath())); + final File localResource = new File(repository.getLocalPath(), context.getLogicalPath()); + if (!localResource.exists()) + return false; + fis = new FileInputStream(localResource); IOUtils.copyLarge(fis, os); return true; } diff --git a/archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/GroupRepositoryManager.java b/archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/GroupRepositoryManager.java index 6a65a8c9c..19b3e6658 100644 --- a/archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/GroupRepositoryManager.java +++ b/archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/GroupRepositoryManager.java @@ -98,23 +98,9 @@ public class GroupRepositoryManager implements RepositoryManager public boolean read(ResourceContext context, OutputStream os) { - if (!isMetadataRequest(context)) - { - final RepositoryGroupConfiguration groupConfiguration = getGroupConfiguration(context.getRepositoryId()); - for (final String repositoryId : groupConfiguration.getRepositories() ) - { - final MutableResourceContext resourceContext = new MutableResourceContext(context); - resourceContext.setRepositoryId(repositoryId); - if (systemRepositoryManager.read(context, os)) - { - return true; - } - } - return false; - } - else if (isProjectReference(context.getLogicalPath())) + final RepositoryGroupConfiguration groupConfiguration = getGroupConfiguration(context.getRepositoryId()); + if (isMetadataRequest(context) && isProjectReference(context)) { - final RepositoryGroupConfiguration groupConfiguration = getGroupConfiguration(context.getRepositoryId()); ArchivaRepositoryMetadata mainMetadata = null; for (final String repositoryId : groupConfiguration.getRepositories() ) { @@ -122,7 +108,7 @@ public class GroupRepositoryManager implements RepositoryManager final MutableResourceContext resourceContext = new MutableResourceContext(context); resourceContext.setRepositoryId(repositoryId); - if (systemRepositoryManager.read(context, baos)) + if (systemRepositoryManager.read(resourceContext, baos)) { try { @@ -159,6 +145,7 @@ public class GroupRepositoryManager implements RepositoryManager RepositoryMetadataWriter.write(mainMetadata, writer); } writer.flush(); + writer.close(); return true; } catch (IOException e) @@ -170,16 +157,10 @@ public class GroupRepositoryManager implements RepositoryManager throw new RepositoryManagerException("Could complete request in repository " + context.getRepositoryId() + " for " + context.getLogicalPath(), e); } } - return false; - } - - private byte[] getMetadataAsByteArray(ArchivaRepositoryMetadata metadata) - throws RepositoryMetadataException - { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final OutputStreamWriter writer = new OutputStreamWriter(baos); - RepositoryMetadataWriter.write(metadata, writer); - return baos.toByteArray(); + else + { + return readFromGroup(groupConfiguration, context, os); + } } public boolean write(ResourceContext context, InputStream is) @@ -190,7 +171,7 @@ public class GroupRepositoryManager implements RepositoryManager public List stat(ResourceContext context) { final RepositoryGroupConfiguration groupConfiguration = getGroupConfiguration(context.getRepositoryId()); - + final LinkedHashMap statusMap = new LinkedHashMap(); for (final String repositoryId : groupConfiguration.getRepositories()) { @@ -230,6 +211,29 @@ public class GroupRepositoryManager implements RepositoryManager } } + private boolean readFromGroup(final RepositoryGroupConfiguration groupConfiguration, ResourceContext context, OutputStream os) + { + for (final String repositoryId : groupConfiguration.getRepositories()) + { + final MutableResourceContext resourceContext = new MutableResourceContext(context); + resourceContext.setRepositoryId(repositoryId); + if (systemRepositoryManager.read(resourceContext, os)) + { + return true; + } + } + return false; + } + + private byte[] getMetadataAsByteArray(ArchivaRepositoryMetadata metadata) + throws RepositoryMetadataException + { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final OutputStreamWriter writer = new OutputStreamWriter(baos); + RepositoryMetadataWriter.write(metadata, writer); + return baos.toByteArray(); + } + private RepositoryGroupConfiguration getGroupConfiguration(final String repositoryId) { return archivaConfiguration.getConfiguration().getRepositoryGroupsAsMap().get( repositoryId ); @@ -237,14 +241,14 @@ public class GroupRepositoryManager implements RepositoryManager private boolean isMetadataRequest(ResourceContext context) { - return repositoryRequest.isMetadata(context.getLogicalPath()) && context.getLogicalPath().endsWith( "metadata.xml.sha1" ) && context.getLogicalPath().endsWith( "metadata.xml.md5" ); + return repositoryRequest.isMetadata(context.getLogicalPath()) || context.getLogicalPath().endsWith( "metadata.xml.sha1" ) || context.getLogicalPath().endsWith( "metadata.xml.md5" ); } - private boolean isProjectReference( String requestedResource ) + private boolean isProjectReference( ResourceContext context ) { try { - metadataTools.toVersionedReference( requestedResource ); + metadataTools.toVersionedReference( context.getLogicalPath() ); return false; } catch ( RepositoryMetadataException re ) -- 2.39.5