diff options
author | Olivier Lamy <olamy@apache.org> | 2014-02-15 11:59:04 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2014-02-15 11:59:04 +0000 |
commit | b4f1eb21cfa75e692e86f04c9e68a94b54292d12 (patch) | |
tree | 59e4a996b5d8c033b6f53df1bf7178f02db2b0ad /archiva-modules/archiva-web | |
parent | 8d88a946f1afd7800b5c30b344055c2e5c0c87a3 (diff) | |
download | archiva-b4f1eb21cfa75e692e86f04c9e68a94b54292d12.tar.gz archiva-b4f1eb21cfa75e692e86f04c9e68a94b54292d12.zip |
[MRM-1804] IndexOutOfBoundsException when browsing a group with 0 or 1 repo
avoid npe
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1568621 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web')
2 files changed, 33 insertions, 15 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index 95c73a163..260e4e4a3 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -309,7 +309,8 @@ public class ArchivaDavResourceFactory { resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, managedRepositoryAdmin.getManagedRepository( - archivaLocator.getRepositoryId() ) ); + archivaLocator.getRepositoryId() ) + ); String logicalResource = getLogicalResource( archivaLocator, null, false ); resourcesInAbsolutePath.add( @@ -408,8 +409,8 @@ public class ArchivaDavResourceFactory catch ( DigesterException de ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, - "Error occurred while generating checksum files." - + de.getMessage() ); + "Error occurred while generating checksum files." + de.getMessage() + ); } } } @@ -925,7 +926,8 @@ public class ArchivaDavResourceFactory return servletAuth.isAuthenticated( request, result ) && servletAuth.isAuthorized( request, securitySession, repositoryId, WebdavMethodUtil.getMethodPermission( - request.getMethod() ) ); + request.getMethod() ) + ); } catch ( AuthenticationException e ) { @@ -972,11 +974,23 @@ public class ArchivaDavResourceFactory RepositoryGroupConfiguration repositoryGroupConfiguration ) throws DavException, RepositoryAdminException { + if ( repositoryGroupConfiguration.getRepositories() == null + || repositoryGroupConfiguration.getRepositories().isEmpty() ) + { + + return new ArchivaVirtualDavResource( new ArrayList<File>(), // + new File( System.getProperty( "appserver.base" ) + "/groups/" + + repositoryGroupConfiguration.getId() ).getPath(), // + mimeTypes, // + locator, // + this + ); + } List<File> mergedRepositoryContents = new ArrayList<File>(); // multiple repo types so we guess they are all the same type // so use the first one // FIXME add a method with group in the repository storage - String firstRepoId = repositoryGroupConfiguration.getRepositories().get( 1 ); + String firstRepoId = repositoryGroupConfiguration.getRepositories().get( 0 ); String path = getLogicalResource( locator, managedRepositoryAdmin.getManagedRepository( firstRepoId ), false ); if ( path.startsWith( "/" ) ) @@ -1012,7 +1026,8 @@ public class ArchivaDavResourceFactory { File tmpDirectory = new File( SystemUtils.getJavaIoTmpDir(), repositoryGroupConfiguration.getId() + "/" - + repositoryGroupConfiguration.getMergedIndexPath() ); + + repositoryGroupConfiguration.getMergedIndexPath() + ); if ( !tmpDirectory.exists() ) { synchronized ( tmpDirectory.getAbsolutePath() ) @@ -1056,7 +1071,8 @@ public class ArchivaDavResourceFactory repoIndexDirectory = new File( managedRepository.getRepository().getLocation(), StringUtils.isEmpty( repoIndexDirectory ) ? ".indexer" - : repoIndexDirectory ).getAbsolutePath(); + : repoIndexDirectory + ).getAbsolutePath(); } } if ( StringUtils.isEmpty( repoIndexDirectory ) ) @@ -1096,7 +1112,8 @@ public class ArchivaDavResourceFactory { if ( servletAuth.isAuthorized( activePrincipal, repository, WebdavMethodUtil.getMethodPermission( - request.getMethod() ) ) ) + request.getMethod() ) + ) ) { mergedRepositoryContents.add( resourceFile ); log.debug( "Repository '{}' accessed by '{}'", repository, activePrincipal ); @@ -1312,13 +1329,14 @@ public class ArchivaDavResourceFactory File tempRepoFile = Files.createTempDir(); tempRepoFile.deleteOnExit(); - IndexMergerRequest indexMergerRequest = new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(), - repositoryGroupConfiguration.getMergedIndexPath(), - repositoryGroupConfiguration.getMergedIndexTtl() ).mergedIndexDirectory( tempRepoFile ) - .temporary( true ); + IndexMergerRequest indexMergerRequest = + new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(), + repositoryGroupConfiguration.getMergedIndexPath(), + repositoryGroupConfiguration.getMergedIndexTtl() ).mergedIndexDirectory( + tempRepoFile ).temporary( true ); MergedRemoteIndexesTaskRequest taskRequest = - new MergedRemoteIndexesTaskRequest(indexMergerRequest, indexMerger); + new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger ); MergedRemoteIndexesTask job = new MergedRemoteIndexesTask( taskRequest ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java index 8c28a3547..d1a995ea6 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/IndexWriter.java @@ -86,7 +86,7 @@ public class IndexWriter writer.println( "ul{list-style:none;}" ); StringBuilder relative = new StringBuilder("../../"); - if ( logicalResource.length() > 0 ) + if ( logicalResource != null && logicalResource.length() > 0 ) { String tmpRelative = StringUtils.replace( logicalResource, "\\", "/" ); for (int i=0;i<tmpRelative.split("/").length;i++) @@ -109,7 +109,7 @@ public class IndexWriter writer.println( "<h3>Collection: /" + logicalResource + "</h3>" ); //Check if not root - if ( logicalResource.length() > 0 ) + if ( logicalResource != null && logicalResource.length() > 0 ) { File file = new File( logicalResource ); String parentName = file.getParent() == null ? "/" : file.getParent(); |