public void install(ConfigurationData configurationData) throws IOException, InvalidConfigException {
// determine the source file/dir
File source = configurationData.getConfigurationDir();
if (!source.exists()) {
throw new InvalidConfigException("Source does not exist " + source);
} else if (!source.canRead()) {
throw new InvalidConfigException("Source is not readable " + source);
}
// determine the target location
Artifact configId = configurationData.getId();
File destination = repository.getLocation(configId);
// if directory in the correct place -- noop
if (!source.equals(destination)) {
if (destination.exists()) {
throw new ConfigurationAlreadyExistsException(configId.toString());
}
if (source.isFile()) {
// Assume this is a jar file
// copy it into the repository; repository should unpack it
repository.copyToRepository(source, configId, null);
} else if (source.isDirectory()) {
// directory is in wrong place -- directory copy
IOUtil.recursiveCopy(source, destination);
} else {
throw new InvalidConfigException("Unable to install configuration from " + source);
}
}
ExecutableConfigurationUtil.writeConfiguration(configurationData, destination);