private RepositoryProvider getProvider( RepositoryType type ) throws RepositoryException { return repositoryProviders.stream( ).filter( repositoryProvider -> repositoryProvider.provides( ).contains( type ) ).findFirst( ).orElseThrow( ( ) -> new RepositoryException( "Repository type cannot be handled: " + type ) ); }
log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
throw new RepositoryException( "Repository not found "+repoId ); log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
private RepositoryContentProvider getProvider(final String layout, final RepositoryType repoType) throws RepositoryException { return repositoryContentProviders.stream().filter(p->p.supports( repoType ) && p.supportsLayout( layout )). findFirst().orElseThrow( ( ) -> new RepositoryException( "Could not find content provider for repository type "+repoType+" and layout "+layout ) ); }
log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
@SuppressWarnings( "unchecked" ) public <T extends Repository> Repository clone(T repo, String newId) throws RepositoryException { if (repo instanceof RemoteRepository ) { return this.clone((RemoteRepository)repo, newId); } else if (repo instanceof ManagedRepository) { return this.clone((ManagedRepository)repo, newId); } else { throw new RepositoryException("This repository class is not supported "+ repo.getClass().getName()); } }
log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
private URI getURIFromString(String uriStr) throws RepositoryException { URI uri; try { if (StringUtils.isEmpty(uriStr)) { return new URI(""); } if (uriStr.startsWith("/")) { // only absolute paths are prepended with file scheme uri = new URI("file://" + uriStr); } else { uri = new URI(uriStr); } if (uri.getScheme() != null && !"file".equals(uri.getScheme())) { log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri); throw new RepositoryException("The uri " + uriStr + " is not valid. Only file:// URI is allowed for maven."); } } catch (URISyntaxException e) { String newCfg = "file://" + uriStr; try { uri = new URI(newCfg); } catch (URISyntaxException e1) { log.error("Could not create URI from {} -> ", uriStr, newCfg); throw new RepositoryException("The config entry " + uriStr + " cannot be converted to URI."); } } log.debug("Setting location uri: {}", uri); return uri; }
log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
@SuppressWarnings( "unchecked" ) public void removeRepository(Repository repo) throws RepositoryException { if (repo instanceof RemoteRepository ) { removeRepository( (RemoteRepository)repo ); } else if (repo instanceof ManagedRepository) { removeRepository( (ManagedRepository)repo); } else { throw new RepositoryException( "Repository type not known: "+repo.getClass() ); } }
log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
private ManagedRepositoryContent getManagedRepositoryContent(String id) throws RepositoryException { org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( id ); if (repo==null) { throw new RepositoryException( "Repository not found "+id ); } return repo.getContent(); }
@Override public void beginScan( ManagedRepository repoConfig, Date whenGathered ) throws ConsumerException { try { this.repository = repositoryFactory.getManagedRepositoryContent( repoConfig.getId() ); this.repositoryDir = new File( repository.getRepoRoot() ); this.scanStartTimestamp = System.currentTimeMillis(); } catch ( RepositoryNotFoundException e ) { throw new ConsumerException( e.getMessage(), e ); } catch ( RepositoryException e ) { throw new ConsumerException( e.getMessage(), e ); } }
private ManagedRepositoryContent getManagedRepositoryContent(String id) throws RepositoryException { org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( id ); if (repo==null) { throw new RepositoryException( "Could not find repository "+id ); } return repo.getContent(); }
log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
@SuppressWarnings( "unchecked" ) @Override public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException { if (!supports( repository.getType() )) { throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." ); } if (repository instanceof ManagedRepository && ManagedRepositoryContent.class.isAssignableFrom( clazz ) ) { return (T) this.createManagedContent( (ManagedRepository) repository ); } else if (repository instanceof RemoteRepository && RemoteRepository.class.isAssignableFrom( clazz )) { return (T) this.createRemoteContent( (RemoteRepository) repository ); } else { throw new RepositoryException( "Repository flavour is not supported: "+repository.getClass().getName() ); } }
@Override public void beginScan( ManagedRepository repoConfig, Date whenGathered ) throws ConsumerException { try { ManagedRepository repo = repositoryRegistry.getManagedRepository( repoConfig.getId( ) ); if (repo==null) { throw new RepositoryNotFoundException( "Repository not found: "+repoConfig.getId() ); } this.repository = repo.getContent(); if (this.repository==null) { throw new RepositoryNotFoundException( "Repository content not found: "+repoConfig.getId() ); } this.repositoryDir = Paths.get( repository.getRepoRoot( ) ); this.scanStartTimestamp = System.currentTimeMillis( ); } catch ( RepositoryException e ) { throw new ConsumerException( e.getMessage( ), e ); } }
/** * Adds a remote repository, or overwrites the repository definition with the same id, if it exists already. * The modification is saved to the configuration immediately. * * @param remoteRepository the remote repository to add * @throws RepositoryException if an error occurs during configuration save */ public RemoteRepository putRepository( RemoteRepository remoteRepository ) throws RepositoryException { rwLock.writeLock( ).lock( ); try { Configuration configuration = getArchivaConfiguration().getConfiguration(); try { RemoteRepository repo = putRepository( remoteRepository, configuration ); getArchivaConfiguration().save(configuration); return repo; } catch ( RegistryException | IndeterminateConfigurationException e ) { log.error("Error while saving remote repository {}", e.getMessage(), e); throw new RepositoryException( "Could not save the configuration" + (e.getMessage( )==null?"":": "+e.getMessage()) ); } } finally { rwLock.writeLock( ).unlock( ); } }
log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
@Override public void deleteProject( String namespace, String projectId ) throws RepositoryException, ContentNotFoundException { ArtifactReference artifactReference = new ArtifactReference(); artifactReference.setGroupId( namespace ); artifactReference.setArtifactId( projectId ); String path = toPath( artifactReference ); File directory = new File( getRepoRoot(), path ); if ( !directory.exists() ) { throw new ContentNotFoundException( "cannot found project " + namespace + ":" + projectId ); } if ( directory.isDirectory() ) { try { FileUtils.deleteDirectory( directory ); } catch ( IOException e ) { throw new RepositoryException( e.getMessage(), e ); } } else { log.warn( "project {}:{} is not a directory", namespace, projectId ); } }