* under the License.
*/
+import java.io.File;
import java.util.Collection;
/**
private int mergedIndexTtl;
+ private File mergedIndexDirectory;
+
public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId )
{
this.repositoriesIds = repositoriesIds;
/**
* @since 1.4-M4
*/
- public IndexMergerRequest(Collection<String> repositoriesIds, boolean packIndex, String groupId,
- String mergedIndexPath, int mergedIndexTtl)
+ public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId,
+ String mergedIndexPath, int mergedIndexTtl )
{
this.repositoriesIds = repositoriesIds;
this.packIndex = packIndex;
this.mergedIndexPath = mergedIndexPath;
}
- public int getMergedIndexTtl() {
+ public int getMergedIndexTtl()
+ {
return mergedIndexTtl;
}
- public void setMergedIndexTtl(int mergedIndexTtl) {
+ public void setMergedIndexTtl( int mergedIndexTtl )
+ {
this.mergedIndexTtl = mergedIndexTtl;
}
+ public File getMergedIndexDirectory()
+ {
+ return mergedIndexDirectory;
+ }
+
+ public void setMergedIndexDirectory( File mergedIndexDirectory )
+ {
+ this.mergedIndexDirectory = mergedIndexDirectory;
+ }
+
+ public IndexMergerRequest mergedIndexDirectory( File mergedIndexDirectory )
+ {
+ this.mergedIndexDirectory = mergedIndexDirectory;
+ return this;
+ }
+
+
@Override
public String toString()
{
sb.append( ", packIndex=" ).append( packIndex );
sb.append( ", groupId='" ).append( groupId ).append( '\'' );
sb.append( ", mergedIndexPath='" ).append( mergedIndexPath ).append( '\'' );
- sb.append( ", mergedIndexTtl='" ).append( mergedIndexTtl ).append( '\'' );
+ sb.append( ", mergedIndexTtl=" ).append( mergedIndexTtl );
+ sb.append( ", mergedIndexDirectory='" ).append( mergedIndexDirectory ).append( '\'' );
sb.append( '}' );
return sb.toString();
}
* under the License.
*/
+import com.google.common.io.Files;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.beans.RemoteRepository;
import org.apache.archiva.indexer.merger.IndexMerger;
import org.apache.archiva.indexer.merger.IndexMergerException;
import org.apache.archiva.indexer.merger.IndexMergerRequest;
+import org.apache.archiva.indexer.merger.MergedRemoteIndexesTaskJob;
import org.apache.archiva.indexer.merger.TemporaryGroupIndex;
import org.apache.archiva.indexer.search.RepositorySearch;
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
/**
*
*/
-@Service( "davResourceFactory#archiva" )
+@Service("davResourceFactory#archiva")
public class ArchivaDavResourceFactory
implements DavResourceFactory, Auditable
{
private RepositoryRequest repositoryRequest;
@Inject
- @Named( value = "repositoryProxyConnectors#default" )
+ @Named(value = "repositoryProxyConnectors#default")
private RepositoryProxyConnectors connectors;
@Inject
private ServletAuthenticator servletAuth;
@Inject
- @Named( value = "httpAuthenticator#basic" )
+ @Named(value = "httpAuthenticator#basic")
private HttpAuthenticator httpAuth;
@Inject
private Digester digestMd5;
@Inject
- @Named( value = "archivaTaskScheduler#repository" )
+ @Named(value = "archivaTaskScheduler#repository")
private RepositoryArchivaTaskScheduler scheduler;
@Inject
- @Named(value= "fileLockManager#default")
+ @Named(value = "fileLockManager#default")
private FileLockManager fileLockManager;
private ApplicationContext applicationContext;
if ( metadataChecksum.exists() )
{
LogicalResource logicalResource =
- new LogicalResource (getLogicalResource( archivaLocator, null, false ) );
+ new LogicalResource( getLogicalResource( archivaLocator, null, false ) );
resource =
new ArchivaDavResource( metadataChecksum.getAbsolutePath(), logicalResource.getPath(), null,
request.getRemoteAddr(), activePrincipal, request.getDavSession(),
- archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager );
+ archivaLocator, this, mimeTypes, auditListeners, scheduler,
+ fileLockManager );
}
}
else
{
File resourceFile = writeMergedMetadataToFile( mergedMetadata, filePath );
- LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) );
+ LogicalResource logicalResource =
+ new LogicalResource( getLogicalResource( archivaLocator, null, false ) );
resource =
new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(), null,
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() );
}
}
}
File resourceFile = new File( temporaryIndexDirectory, requestedFileName );
resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), requestedFileName, null,
request.getRemoteAddr(), activePrincipal, request.getDavSession(),
- archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager );
+ archivaLocator, this, mimeTypes, auditListeners, scheduler,
+ fileLockManager );
}
else
{
// FIXME remove this hack
// but currently managedRepository can be null in case of group
- String layout = managedRepository == null ? new ManagedRepository( ).getLayout() : managedRepository.getLayout();
+ String layout = managedRepository == null ? new ManagedRepository().getLayout() : managedRepository.getLayout();
RepositoryStorage repositoryStorage =
this.applicationContext.getBean( "repositoryStorage#" + layout, RepositoryStorage.class );
String path = repositoryStorage.getFilePath(
- useOrigResourcePath ? archivaLocator.getOrigResourcePath() : archivaLocator.getResourcePath(), managedRepository );
+ useOrigResourcePath ? archivaLocator.getOrigResourcePath() : archivaLocator.getResourcePath(),
+ managedRepository );
log.debug( "found path {} for resourcePath: '{}' with managedRepo '{}' and layout '{}'", path,
- archivaLocator.getResourcePath(), managedRepository == null ? "null" : managedRepository.getId(), layout );
+ archivaLocator.getResourcePath(), managedRepository == null ? "null" : managedRepository.getId(),
+ layout );
return path;
}
- private String evaluatePathWithVersion( ArchivaDavResourceLocator archivaLocator, ManagedRepositoryContent managedRepositoryContent, String contextPath )
+ private String evaluatePathWithVersion( ArchivaDavResourceLocator archivaLocator,
+ ManagedRepositoryContent managedRepositoryContent, String contextPath )
throws DavException
{
- String layout = managedRepositoryContent.getRepository() == null ? new ManagedRepository( ).getLayout() : managedRepositoryContent.getRepository().getLayout();
+ String layout = managedRepositoryContent.getRepository() == null
+ ? new ManagedRepository().getLayout()
+ : managedRepositoryContent.getRepository().getLayout();
RepositoryStorage repositoryStorage =
this.applicationContext.getBean( "repositoryStorage#" + layout, RepositoryStorage.class );
try
{
- return repositoryStorage.getFilePathWithVersion( archivaLocator.getResourcePath(), managedRepositoryContent );
+ return repositoryStorage.getFilePathWithVersion( archivaLocator.getResourcePath(),
+ managedRepositoryContent );
}
catch ( RelocationException e )
{
String path = e.getPath();
log.debug( "Relocation to {}", path );
- throw new BrowserRedirectException(contextPath + ( StringUtils.startsWith( path, "/" ) ? "": "/" ) + path, e.getRelocationType() );
+ throw new BrowserRedirectException( contextPath + ( StringUtils.startsWith( path, "/" ) ? "" : "/" ) + path,
+ e.getRelocationType() );
}
catch ( XMLException e )
{
if ( isAuthorized( request, managedRepositoryContent.getId() ) )
{
// Maven Centric part ask evaluation if -SNAPSHOT
- String path = evaluatePathWithVersion(archivaLocator, managedRepositoryContent, request.getContextPath());
+ String path = evaluatePathWithVersion( archivaLocator, managedRepositoryContent, request.getContextPath() );
if ( path.startsWith( "/" ) )
{
path = path.substring( 1 );
}
Set<String> authzRepos = new HashSet<String>();
+
+ String permission = WebdavMethodUtil.getMethodPermission( request.getMethod() );
+
for ( String repository : repositories )
{
try
{
- if ( servletAuth.isAuthorized( activePrincipal, repository,
- WebdavMethodUtil.getMethodPermission( request.getMethod() ) ) )
+ if ( servletAuth.isAuthorized( activePrincipal, repository, permission ) )
{
authzRepos.add( repository );
authzRepos.addAll( this.repositorySearch.getRemoteIndexingContextIds( repository ) );
}
log.info( "generate temporary merged index for repository group '{}' for repositories '{}'",
repositoryGroupConfiguration.getId(), authzRepos );
- IndexingContext indexingContext = indexMerger.buildMergedIndex(
- new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(),
- repositoryGroupConfiguration.getMergedIndexPath(),
- repositoryGroupConfiguration.getMergedIndexTtl() ) );
+
+ File tempRepoFile = Files.createTempDir();
+ tempRepoFile.deleteOnExit();
+
+ IndexMergerRequest indexMergerRequest = new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(),
+ repositoryGroupConfiguration.getMergedIndexPath(),
+ repositoryGroupConfiguration.getMergedIndexTtl() ).mergedIndexDirectory(
+ tempRepoFile );
+
+ MergedRemoteIndexesTaskJob job = new MergedRemoteIndexesTaskJob();
+
+ MergedRemoteIndexesTaskJob.MergedRemoteIndexesTaskRequest taskRequest =
+ new MergedRemoteIndexesTaskJob.MergedRemoteIndexesTaskRequest(indexMergerRequest, indexMerger);
+
+ IndexingContext indexingContext = job.execute( taskRequest ).getIndexingContext();
+
File mergedRepoDir = indexingContext.getIndexDirectoryFile();
TemporaryGroupIndex temporaryGroupIndex =
new TemporaryGroupIndex( mergedRepoDir, indexingContext.getId(), repositoryGroupConfiguration.getId(),