@Override public VersionsList getVersionsList( String groupId, String artifactId, String repositoryId ) throws ArchivaRestServiceException { List<String> selectedRepos = getSelectedRepos( repositoryId ); try { Collection<String> versions = getVersions( selectedRepos, groupId, artifactId ); return new VersionsList( new ArrayList<>( versions ) ); } catch ( MetadataResolutionException e ) { throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); } }
@Override public Collection<String> getProjects( String repoId, String namespace ) throws MetadataResolutionException { try { List<String> projects; Path directory = getDirectory( repoId ).resolve( namespace ); if (!(Files.exists(directory) && Files.isDirectory(directory))) { return Collections.emptyList(); } final String searchFile = PROJECT_METADATA_KEY + ".properties"; try(Stream<Path> fs = Files.list(directory)) { projects = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile)) ).map(path -> path.getFileName().toString()).collect(Collectors.toList()); } return projects; } catch ( IOException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } }
@Override public VersionsList getVersionsList( String groupId, String artifactId, String repositoryId ) throws ArchivaRestServiceException { List<String> selectedRepos = getSelectedRepos( repositoryId ); try { Collection<String> versions = getVersions( selectedRepos, groupId, artifactId ); return new VersionsList( new ArrayList<>( versions ) ); } catch ( MetadataResolutionException e ) { throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); } }
@Override public Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) throws MetadataResolutionException { try { List<String> projectVersions; Path directory = getDirectory( repoId ).resolve( namespace + "/" + projectId ); if (!(Files.exists(directory) && Files.isDirectory(directory))) { return Collections.emptyList(); } final String searchFile = PROJECT_VERSION_METADATA_KEY + ".properties"; try(Stream<Path> fs = Files.list(directory)) { projectVersions = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile)) ).map(path -> path.getFileName().toString()).collect(Collectors.toList()); } return projectVersions; } catch ( IOException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } }
@Override public List<ArtifactMetadata> getArtifacts( String repoId ) throws MetadataRepositoryException { try { List<ArtifactMetadata> artifacts = new ArrayList<>(); for ( String ns : getRootNamespaces( repoId ) ) { getArtifacts( artifacts, repoId, ns ); } return artifacts; } catch ( MetadataResolutionException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
@Override public Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) throws MetadataResolutionException { try { List<String> projectVersions = new ArrayList<>(); File directory = new File( getDirectory( repoId ), namespace + "/" + projectId ); File[] files = directory.listFiles(); if ( files != null ) { for ( File projectVersion : files ) { if ( new File( projectVersion, PROJECT_VERSION_METADATA_KEY + ".properties" ).exists() ) { projectVersions.add( projectVersion.getName() ); } } } return projectVersions; } catch ( IOException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } }
@Override public List<Artifact> getArtifactDownloadInfos( String groupId, String artifactId, String version, String repositoryId ) throws ArchivaRestServiceException { List<String> selectedRepos = getSelectedRepos( repositoryId ); List<Artifact> artifactDownloadInfos = new ArrayList<>(); try (RepositorySession session = repositorySessionFactory.createSession()) { MetadataResolver metadataResolver = session.getResolver(); for ( String repoId : selectedRepos ) { List<ArtifactMetadata> artifacts = new ArrayList<>( metadataResolver.resolveArtifacts( session, repoId, groupId, artifactId, version ) ); Collections.sort( artifacts, ArtifactMetadataVersionComparator.INSTANCE ); if ( artifacts != null && !artifacts.isEmpty() ) { return buildArtifacts( artifacts, repoId ); } } } catch ( MetadataResolutionException e ) { log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); } return artifactDownloadInfos; }
@Override public Collection<String> getProjects( String repoId, String namespace ) throws MetadataResolutionException { try { List<String> projects = new ArrayList<>(); File directory = new File( getDirectory( repoId ), namespace ); File[] files = directory.listFiles(); if ( files != null ) { for ( File project : files ) { if ( new File( project, PROJECT_METADATA_KEY + ".properties" ).exists() ) { projects.add( project.getName() ); } } } return projects; } catch ( IOException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } }
@Override public List<ArtifactMetadata> getArtifacts( String repoId ) throws MetadataRepositoryException { try { List<ArtifactMetadata> artifacts = new ArrayList<>(); for ( String ns : getRootNamespaces( repoId ) ) { getArtifacts( artifacts, repoId, ns ); } return artifacts; } catch ( MetadataResolutionException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
@Override public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException { try { File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); Set<String> versions = new HashSet<String>(); for ( Map.Entry entry : properties.entrySet() ) { String name = (String) entry.getKey(); if ( name.startsWith( "artifact:version:" ) ) { versions.add( (String) entry.getValue() ); } } return versions; } catch ( IOException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } }
@Override public List<Artifact> getArtifactDownloadInfos( String groupId, String artifactId, String version, String repositoryId ) throws ArchivaRestServiceException { List<String> selectedRepos = getSelectedRepos( repositoryId ); List<Artifact> artifactDownloadInfos = new ArrayList<>(); try (RepositorySession session = repositorySessionFactory.createSession()) { MetadataResolver metadataResolver = session.getResolver(); for ( String repoId : selectedRepos ) { List<ArtifactMetadata> artifacts = new ArrayList<>( metadataResolver.resolveArtifacts( session, repoId, groupId, artifactId, version ) ); Collections.sort( artifacts, ArtifactMetadataVersionComparator.INSTANCE ); if ( artifacts != null && !artifacts.isEmpty() ) { return buildArtifacts( artifacts, repoId ); } } } catch ( MetadataResolutionException e ) { log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); } return artifactDownloadInfos; }
@Override public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException { try { Path directory = getDirectory( repoId ).resolve( namespace + "/" + projectId + "/" + projectVersion ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); Set<String> versions = new HashSet<>( ); for ( Map.Entry entry : properties.entrySet() ) { String name = (String) entry.getKey(); if ( name.startsWith( "artifact:version:" ) ) { versions.add( (String) entry.getValue() ); } } return versions; } catch ( IOException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } }
@Override public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime ) throws MetadataRepositoryException { try { // TODO: this is quite slow - if we are to persist with this repository implementation we should build an index // of this information (eg. in Lucene, as before) List<ArtifactMetadata> artifacts = new ArrayList<>(); for ( String ns : getRootNamespaces( repoId ) ) { getArtifactsByDateRange( artifacts, repoId, ns, startTime, endTime ); } artifacts.sort(new ArtifactComparator() ); return artifacts; } catch ( MetadataResolutionException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
throw new MetadataResolutionException( e.getMessage(), e );
@Override public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime ) throws MetadataRepositoryException { try { // TODO: this is quite slow - if we are to persist with this repository implementation we should build an index // of this information (eg. in Lucene, as before) List<ArtifactMetadata> artifacts = new ArrayList<>(); for ( String ns : getRootNamespaces( repoId ) ) { getArtifactsByDateRange( artifacts, repoId, ns, startTime, endTime ); } Collections.sort( artifacts, new ArtifactComparator() ); return artifacts; } catch ( MetadataResolutionException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
throw new MetadataResolutionException( e.getMessage(), e );
/** * Walks each namespace of the given repository id and counts the artifacts. * * @param metadataRepository The repository implementation * @param repositoryId The repository Id * @param repositoryStatistics The statistics object that must be populated * @throws MetadataRepositoryException Throws the repository exception, if an error occurs while accessing the repository. */ @Override public void populateStatistics( MetadataRepository metadataRepository, String repositoryId, RepositoryStatistics repositoryStatistics ) throws MetadataRepositoryException { try { for ( String ns : metadataRepository.getRootNamespaces( repositoryId ) ) { walkRepository( metadataRepository, repositoryStatistics, repositoryId, ns ); } } catch ( MetadataResolutionException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
@Override public Collection<String> getArtifactVersions( String repositoryId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException { Set<String> versions = new LinkedHashSet<String>(); try { Node root = getJcrSession().getRootNode(); Node node = root.getNode( getProjectVersionPath( repositoryId, namespace, projectId, projectVersion ) ); for ( Node n : JcrUtils.getChildNodes( node ) ) { versions.add( n.getProperty( "version" ).getString() ); } } catch ( PathNotFoundException e ) { // ignore repo not found for now } catch ( RepositoryException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } return versions; }
throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
@Override public Collection<String> getArtifactVersions( String repositoryId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException { Set<String> versions = new LinkedHashSet<String>(); try { Node root = getJcrSession().getRootNode(); Node node = root.getNode( getProjectVersionPath( repositoryId, namespace, projectId, projectVersion ) ); for ( Node n : JcrUtils.getChildNodes( node ) ) { versions.add( n.getProperty( "version" ).getString() ); } } catch ( PathNotFoundException e ) { // ignore repo not found for now } catch ( RepositoryException e ) { throw new MetadataResolutionException( e.getMessage(), e ); } return versions; }