String contextKey = "remote-" + remoteRepository.getId( ); Path repoDir = remoteRepository.getLocalPath(); if ( !Files.exists( repoDir ) ) if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) ) RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( ); indexDirectory = getIndexPath(remoteRepository); String remoteIndexUrl = calculateIndexRemoteUrl( remoteRepository.getLocation( ), rif ); try remoteRepository.getId( ) ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory ); return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl );
protected String addParameters( String path, RemoteRepository remoteRepository ) { if ( remoteRepository.getExtraParameters().isEmpty() ) { return path; } boolean question = false; StringBuilder res = new StringBuilder( path == null ? "" : path ); for ( Entry<String, String> entry : remoteRepository.getExtraParameters().entrySet() ) { if ( !question ) { res.append( '?' ).append( entry.getKey() ).append( '=' ).append( entry.getValue() ); } } return res.toString(); }
public RemoteRepositoryContent getRemoteRepositoryContent( RemoteRepository mRepo ) throws RepositoryException { final String id = mRepo.getId(); RemoteRepositoryContent content = remoteContentMap.get( id ); if ( content != null && content.getRepository()==mRepo) { return content; } RepositoryContentProvider contentProvider = getProvider( mRepo.getLayout( ), mRepo.getType( ) ); content = contentProvider.createRemoteContent( mRepo ); if (content==null) { throw new RepositoryException( "Could not create repository content instance for "+mRepo.getId() ); } RemoteRepositoryContent previousContent = remoteContentMap.put( id, content ); if (previousContent!=null) { previousContent.setRepository( null ); } return content; }
@SuppressWarnings( "unchecked" ) private void updateRepositoryReferences( RepositoryProvider provider, RemoteRepository repo, RemoteRepositoryConfiguration cfg, Configuration configuration) throws RepositoryException { if ( repo instanceof EditableRemoteRepository && repo.getContent() == null) { EditableRemoteRepository editableRepo = (EditableRemoteRepository) repo; editableRepo.setContent( repositoryContentFactory.getRemoteRepositoryContent( repo ) ); if (repo.supportsFeature(IndexCreationFeature.class) && repo.getIndexingContext()==null ) { createIndexingContext(editableRepo); } } }
@Override public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException { if (!supports( repository.getType() )) { throw new RepositoryException( "Repository type "+repository.getType()+" is not supported by this implementation." ); } if (!supportsLayout( repository.getLayout() )) { throw new RepositoryException( "Repository layout "+repository.getLayout()+" is not supported by this implementation." ); } RemoteDefaultRepositoryContent content = new RemoteDefaultRepositoryContent(artifactMappingProviders); content.setRepository( repository ); return content; }
cfg.setType(remoteRepository.getType().toString()); cfg.setId(remoteRepository.getId()); cfg.setName(remoteRepository.getName()); cfg.setDescription(remoteRepository.getDescription()); cfg.setUrl(remoteRepository.getLocation().toString()); cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000); cfg.setCheckPath(remoteRepository.getCheckPath()); RepositoryCredentials creds = remoteRepository.getLoginCredentials(); if (creds != null) { if (creds instanceof PasswordCredentials) { cfg.setLayout(remoteRepository.getLayout()); cfg.setExtraParameters(remoteRepository.getExtraParameters()); cfg.setExtraHeaders(remoteRepository.getExtraHeaders()); cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition()); IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get(); cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath())); cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath())); RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get(); cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString()); cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
if ( this.runningRemoteDownloadIds.contains( this.remoteRepository.getId() ) ) this.remoteRepository.getId() ); return; this.runningRemoteDownloadIds.add( this.remoteRepository.getId() ); log.info( "start download remote index for remote repository {}", this.remoteRepository.getId() ); if (this.remoteRepository.getIndexingContext()==null) { throw new IndexNotFoundException("No index context set for repository "+remoteRepository.getId()); if (this.remoteRepository.getType()!= RepositoryType.MAVEN) { throw new RepositoryException("Bad repository type"); if (!this.remoteRepository.supportsFeature(RemoteIndexFeature.class)) { throw new RepositoryException("Repository does not support RemotIndexFeature "+remoteRepository.getId()); RemoteIndexFeature rif = this.remoteRepository.getFeature(RemoteIndexFeature.class).get(); IndexingContext indexingContext = this.remoteRepository.getIndexingContext().getBaseContext(IndexingContext.class); String wagonProtocol = this.remoteRepository.getLocation().getScheme(); new WagonFactoryRequest( wagonProtocol, this.remoteRepository.getExtraHeaders() ).networkProxy( this.networkProxy ) ); wagon.setTimeout( (int)remoteRepository.getTimeout().toMillis()); if ( this.remoteRepository.getLoginCredentials()!=null && this.remoteRepository.getLoginCredentials() instanceof PasswordCredentials )
if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) ) RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( ); if ( StringUtils.isNotBlank( rif.getProxyId( ) ) ) new WagonFactoryRequest( wagonProtocol, remoteRepository.getExtraHeaders( ) ).networkProxy( networkProxy ) ); int readTimeout = (int) rif.getDownloadTimeout( ).toMillis( ) * 1000; wagon.setReadTimeout( readTimeout ); wagon.setTimeout( (int) remoteRepository.getTimeout( ).toMillis( ) * 1000 ); if ( remoteRepository.getLoginCredentials( ) != null && ( remoteRepository.getLoginCredentials( ) instanceof PasswordCredentials ) ) PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials( ); authenticationInfo = new AuthenticationInfo( ); authenticationInfo.setUserName( creds.getUsername( ) ); authenticationInfo.setPassword( new String( creds.getPassword( ) ) ); wagon.connect( new org.apache.maven.wagon.repository.Repository( remoteRepository.getId( ), baseIndexUrl ), authenticationInfo, proxyInfo ); log.error( "Could not login to the remote proxy for updating index of {}", remoteRepository.getId( ), e ); throw new IndexUpdateFailedException( "Login in to proxy failed while updating remote repository " + remoteRepository.getId( ), e ); log.error( "Connection error during index update for remote repository {}", remoteRepository.getId( ), e ); throw new IndexUpdateFailedException( "Connection error during index update for remote repository " + remoteRepository.getId( ), e ); log.error( "URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId( ), remoteUpdateUri, e );
final NetworkProxy proxyConnector = this.networkProxyMap.get( remoteRepository.getId() ); ProxyInfo networkProxy = null; if ( proxyConnector != null ) + " to connect to remote repository " + remoteRepository.getLocation(); if ( networkProxy.getNonProxyHosts() != null ) RepositoryCredentials creds = remoteRepository.getLoginCredentials(); String username = ""; String password = ""; log.debug( "Using username {} to connect to remote repository {}", username, remoteRepository.getLocation() ); authInfo = new AuthenticationInfo(); authInfo.setUserName( username ); int timeoutInMilliseconds = ((int)remoteRepository.getTimeout().getSeconds())*1000; new org.apache.maven.wagon.repository.Repository( remoteRepository.getId(), remoteRepository.getLocation().toString() ); if ( networkProxy != null ) log.error( "Could not connect to {}:{} ", remoteRepository.getName(), e.getMessage() ); connected = false;
try String protocol = getProtocol( remoteRepository.getLocation().toString() ); final NetworkProxy networkProxy = this.networkProxyMap.get( remoteRepository.getId() ); new WagonFactoryRequest( "wagon#" + protocol, remoteRepository.getExtraHeaders() ).networkProxy( networkProxy ) ); log.info( "Retrieving {} from {}", artifactPath, remoteRepository.getName() );
@PostConstruct public void startup() throws DownloadRemoteIndexException, UnsupportedBaseContextException { archivaConfiguration.addListener( this ); // TODO add indexContexts even if null for ( org.apache.archiva.repository.RemoteRepository remoteRepository : repositoryRegistry.getRemoteRepositories() ) { String contextKey = "remote-" + remoteRepository.getId(); IndexingContext context = remoteRepository.getIndexingContext().getBaseContext(IndexingContext.class); if ( context == null ) { continue; } RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get(); // TODO record jobs from configuration if ( rif.isDownloadRemoteIndex() && StringUtils.isNotEmpty( remoteRepository.getSchedulingDefinition() ) ) { boolean fullDownload = context.getIndexDirectoryFile().list().length == 0; scheduleDownloadRemote( remoteRepository.getId(), false, fullDownload ); } } }
@Override public String getId( ) { return repository.getId( ); }
return; if (!remoteRepo.supportsFeature(RemoteIndexFeature.class)) { log.warn("ignore scheduleDownloadRemote for repo with id {}. Does not support remote index.", repositoryId); return; RemoteIndexFeature rif = remoteRepo.getFeature(RemoteIndexFeature.class).get(); NetworkProxy networkProxy = null; if ( StringUtils.isNotBlank( rif.getProxyId() ) ) log.info( "schedule download remote index for repository {}", remoteRepo.getId() ); remoteRepo.getId(), remoteRepo.getSchedulingDefinition()); try CronTrigger cronTrigger = new CronTrigger( remoteRepo.getSchedulingDefinition()); taskScheduler.schedule( new DownloadRemoteIndexTask( downloadRemoteIndexTaskRequest, this.runningRemoteDownloadIds ), remoteRepo.getId() ); taskScheduler.schedule( new DownloadRemoteIndexTask( downloadRemoteIndexTaskRequest, this.runningRemoteDownloadIds ),
try final String id = remoteRepository.getId(); if (managedRepositories.containsKey( id )) { throw new RepositoryException( "There exists a managed repository with id "+id+". Could not update with remote repository." ); originRepo.close(); final RepositoryProvider provider = getProvider( remoteRepository.getType() ); newCfg = provider.getRemoteConfiguration( remoteRepository ); updateRepositoryReferences( provider, remoteRepository, newCfg, configuration );
String username = ""; String password = ""; RepositoryCredentials repCred = remoteRepository.getRepository().getLoginCredentials(); if (repCred!=null && repCred instanceof PasswordCredentials) { PasswordCredentials pwdCred = (PasswordCredentials) repCred; long timeoutInMilliseconds = remoteRepository.getRepository().getTimeout().toMillis(); log.warn( "Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage() ); connected = false;
private void resolve( ResolveRequest resolveRequest ) { RepositorySystem system = mavenSystemManager.getRepositorySystem(); RepositorySystemSession session = MavenSystemManager.newRepositorySystemSession( resolveRequest.localRepoDir ); org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact( resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version ); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot( new Dependency( artifact, "" ) ); // add remote repositories for ( RemoteRepository remoteRepository : resolveRequest.remoteRepositories ) { org.eclipse.aether.repository.RemoteRepository repo = new org.eclipse.aether.repository.RemoteRepository.Builder( remoteRepository.getId( ), "default", remoteRepository.getLocation( ).toString() ).build( ); collectRequest.addRepository(repo); } collectRequest.setRequestContext( "project" ); //collectRequest.addRepository( repo ); try { CollectResult collectResult = system.collectDependencies( session, collectRequest ); collectResult.getRoot().accept( resolveRequest.dependencyVisitor ); log.debug("Collected dependency results for resolve"); } catch ( DependencyCollectionException e ) { log.error( "Error while collecting dependencies (resolve): {}", e.getMessage(), e ); } }
private void doRemoveRepo(RemoteRepository repo, Configuration configuration) { repo.close(); RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById(repo.getId()); if (cfg != null) { configuration.removeRemoteRepository(cfg); } List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(configuration.getProxyConnectors()); for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) { if (StringUtils.equals(proxyConnector.getTargetRepoId(), repo.getId())) { configuration.removeProxyConnector(proxyConnector); } } }
@Override public RepositoryURL getURL( ) { try { return new RepositoryURL( repository.getLocation( ).toString( ) ); } catch ( Exception e ) { log.error( "Could not convert location url {}", repository.getLocation( ) ); return new RepositoryURL( "" ); } }
if (repo.getType()==RepositoryType.MAVEN) { try { IndexingContext context = repo.getIndexingContext() != null ? repo.getIndexingContext().getBaseContext(IndexingContext.class) : null; if (context!=null && context.isSearchable()) { ids.add(remoteId);
/** * Creates a new repository instance with the same settings as this one. The cloned repository is not * registered or saved to the configuration. * * @param repo The origin repository * @return The cloned repository. */ public RemoteRepository clone( RemoteRepository repo, String newId) throws RepositoryException { if (managedRepositories.containsKey(newId) || remoteRepositories.containsKey(newId)) { throw new RepositoryException("The given id exists already "+newId); } RepositoryProvider provider = getProvider(repo.getType()); RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration(repo); cfg.setId(newId); RemoteRepository cloned = provider.createRemoteInstance(cfg); cloned.addListener(this); return cloned; }