use of org.motechproject.admin.bundles.JarInformation in project motech by motech.
the class ModuleAdminServiceImpl method getJarInformations.
private JarInformation getJarInformations(File bundleFile) throws IOException {
JarInformation jarInformation = new JarInformation(bundleFile);
jarInformation.readPOMInformation(bundleFile);
if (!isValidPluginBundle(jarInformation)) {
LOGGER.warn(jarInformation.getFilename() + " is not allowed to install as add-on");
return null;
}
return jarInformation;
}
use of org.motechproject.admin.bundles.JarInformation in project motech by motech.
the class ModuleAdminServiceImpl method installBundleFromFile.
private Bundle installBundleFromFile(File bundleFile, boolean updateExistingBundle, boolean installInBundlesDirectory) throws IOException, BundleException, DependencyResolutionException {
LOGGER.info("Starting installation process for: {}", bundleFile);
JarInformation jarInformation = getJarInformations(bundleFile);
if (jarInformation == null || jarInformation.isMotechPlatformBundle()) {
LOGGER.info("Skipping {}", bundleFile);
return null;
}
Bundle bundle = findMatchingBundle(jarInformation);
try (InputStream bundleInputStream = FileUtils.openInputStream(bundleFile)) {
if (bundle == null) {
LOGGER.info("Installing new bundle: {}", bundleFile);
if (installInBundlesDirectory) {
// install in the bundles directory
LOGGER.debug("Installing {} in the bundle directory", bundleFile);
final File installedBundleFile = bundleDirectoryManager.saveBundleStreamToFile(bundleFile.getName(), bundleInputStream);
final String bundleFileLocationAsURL = installedBundleFile.toURI().toURL().toExternalForm();
bundle = bundleContext.installBundle(bundleFileLocationAsURL);
} else {
// install from the provided location
LOGGER.debug("Installing bundle from file: {}", bundleFile);
final String bundleFileLocationAsURL = bundleFile.toURI().toURL().toExternalForm();
bundle = bundleContext.installBundle(bundleFileLocationAsURL);
}
} else if (updateExistingBundle) {
// either install from the file provided or install in the bundles directory
final File installedBundleFile = (installInBundlesDirectory) ? bundleDirectoryManager.saveBundleStreamToFile(bundleFile.getName(), bundleInputStream) : bundleFile;
LOGGER.info("Updating bundle " + bundle.getSymbolicName() + "|" + bundle.getVersion());
if (bundle.getState() == Bundle.ACTIVE) {
bundle.stop();
}
try (InputStream installedInputStream = FileUtils.openInputStream(installedBundleFile)) {
bundle.update(installedInputStream);
}
}
}
return bundle;
}
use of org.motechproject.admin.bundles.JarInformation in project motech by motech.
the class ModuleAdminServiceImpl method installWithDependenciesFromFile.
private BundleInformation installWithDependenciesFromFile(File bundleFile, boolean startBundle) throws IOException {
JarInformation jarInformation = getJarInformations(bundleFile);
List<Bundle> bundlesInstalled = new ArrayList<>();
BundleInformation bundleInformation = null;
if (jarInformation == null) {
throw new IOException("Unable to read bundleFile " + bundleFile.getAbsolutePath());
}
try {
List<ArtifactResult> artifactResults = new LinkedList<>();
bundleWatcherSuspensionService.suspendBundleProcessing();
for (Dependency dependency : jarInformation.getPomInformation().getDependencies()) {
artifactResults.addAll(resolveDependencies(dependency, jarInformation.getPomInformation()));
}
artifactResults = removeDuplicatedArtifacts(artifactResults);
bundlesInstalled = installBundlesFromArtifacts(artifactResults);
final Bundle requestedModule = installBundleFromFile(bundleFile, true, false);
if (requestedModule != null) {
if (!isFragmentBundle(requestedModule) && startBundle) {
requestedModule.start();
}
bundlesInstalled.add(requestedModule);
bundleInformation = null;
} else {
bundleInformation = new BundleInformation(null);
}
} catch (BundleException | RepositoryException e) {
throw new MotechException("Error while installing bundle and dependencies.", e);
} finally {
bundleWatcherSuspensionService.restoreBundleProcessing();
}
// start bundles after all bundles installed to avoid any dependency resolution problems.
startBundles(bundlesInstalled, startBundle);
return bundleInformation;
}
Aggregations