}
}
@Override
public void removeP2Artifacts(final StorageItem item) {
final P2RepositoryAggregatorConfiguration configuration = getConfiguration(item.getRepositoryId());
if (configuration == null) {
return;
}
logger.debug("Updating P2 repository artifacts (remove) for [{}:{}]", item.getRepositoryId(), item.getPath());
try {
final Repository repository = repositories.getRepository(configuration.repositoryId());
final RepositoryItemUid p2RepoUid = repository.createUid(P2_REPOSITORY_ROOT_PATH);
File sourceP2Repository = null;
File destinationP2Repository = null;
try {
p2RepoUid.getLock().lock(Action.update);
// copy repository artifacts to a temporary location
destinationP2Repository = createTemporaryP2Repository();
final File artifacts = getP2Artifacts(configuration, repository);
final File tempArtifacts = new File(destinationP2Repository, artifacts.getName());
FileUtils.copyFile(artifacts, tempArtifacts);
// copy item artifacts to a temp location
sourceP2Repository = createTemporaryP2Repository();
FileUtils.copyFile(retrieveFile(repository, item.getPath()), new File(sourceP2Repository,
"artifacts.xml"));
artifactRepository.remove(sourceP2Repository.toURI(), destinationP2Repository.toURI());
// copy repository artifacts back to exposed location
FileUtils.copyFile(tempArtifacts, artifacts);
}
finally {
p2RepoUid.getLock().unlock();
FileUtils.deleteDirectory(sourceP2Repository);
FileUtils.deleteDirectory(destinationP2Repository);
}
}
catch (final Exception e) {
logger.warn(
String.format("Could not update P2 repository [%s:%s] with [%s] due to [%s]",
configuration.repositoryId(), P2_REPOSITORY_ROOT_PATH, item.getPath(), e.getMessage()),
e);
}
}