public void uninstall(Artifact configId) throws NoSuchConfigException, IOException {
if(!configId.isResolved()) {
throw new IllegalArgumentException("Artifact "+configId+" is not fully resolved");
}
ConfigurationInfo configurationInfo = null;
try {
configurationInfo = loadConfigurationInfo(configId);
} catch (IOException e) {
// don't really care
}
File location = repository.getLocation(configId);
IOUtil.recursiveDelete(location);
// Number of directory levels up, to check and delete empty parent directories in the repo
int dirDepth = 0;
// FIXME: Determine the repository type
// For now assume the repo is a Maven2Repository. This should not cause any harm even if it is an
// Maven1Repository, for it would be deleting the 'repository' directory if it happens to be empty.
boolean m2repo = true;
if(m2repo) {
// Check version, artifact and group directories, i.e. 3 levels up
dirDepth = 3;
}
File temp = location;
for(int i = 0; i < dirDepth; ++i) {
if((temp = temp.getParentFile()).listFiles().length == 0) {
// Directory is empty. Remove it.
temp.delete();
} else {
// Directory is not empty. No need to check any more parent directories
break;
}
}
if (configurationInfo != null) {
IOException ioException = null;
for (Iterator iterator = configurationInfo.getOwnedConfigurations().iterator(); iterator.hasNext();) {
Artifact ownedConfiguration = (Artifact) iterator.next();
try {
uninstall(ownedConfiguration);
} catch (NoSuchConfigException e) {
// ignored - already deleted or never installed