}
return dump;
}
private synchronized void saveDeployment(final File file, final boolean add) {
final Deployments deps = new Deployments();
if (file.isDirectory()) {
deps.setDir(file.getAbsolutePath());
} else {
deps.setFile(file.getAbsolutePath());
}
File config;
try {
config = SystemInstance.get().getBase().getFile(ADDITIONAL_DEPLOYMENTS, false);
} catch (final IOException e) {
config = null;
}
if (config == null || !config.getParentFile().exists()) {
LOGGER.info("can't save the added app because the conf folder doesn't exist, it will not be present next time you'll start");
return;
}
// dump it
OutputStream os = null;
try {
final AdditionalDeployments additionalDeployments;
if (config.exists() && config.length() > 0) {
final InputStream fis = IO.read(config);
try {
additionalDeployments = JaxbOpenejb.unmarshal(AdditionalDeployments.class, fis);
} finally {
IO.close(fis);
}
} else {
additionalDeployments = new AdditionalDeployments();
}
if (add) {
if (!additionalDeployments.getDeployments().contains(deps)) {
additionalDeployments.getDeployments().add(deps);
}
} else {
final Iterator<Deployments> it = additionalDeployments.getDeployments().iterator();
while (it.hasNext()) {
final Deployments current = it.next();
if (deps.getDir() != null && deps.getDir().equals(current.getDir())) {
it.remove();
break;
} else if (deps.getFile() != null && deps.getFile().equals(current.getFile())) {
it.remove();
break;
} else { // exploded dirs
final String jar = deps.getFile();
if (jar != null && jar.length() > 3 && jar.substring(0, jar.length() - 4).equals(deps.getDir())) {