Skip to content

Commit

Permalink
#26518 adding sonarq feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms committed Apr 5, 2024
1 parent cc46e10 commit 14c0ba3
Showing 1 changed file with 49 additions and 30 deletions.
79 changes: 49 additions & 30 deletions dotCMS/src/main/java/org/apache/felix/framework/OSGIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,43 +556,16 @@ public void moveNewBundlesToFelixLoadFolder(final String[] pathnames) {
private void moveNewBundlesToFelixLoadFolder(final File uploadFolderFile, final String[] pathnames) {

final File deployDirectory = new File(this.getFelixDeployPath());
final File undeployDirectory = new File(this.getFelixUndeployPath());
try {

if (deployDirectory.exists() && deployDirectory.canWrite()) {

for (final String pathname : pathnames) {

final File bundle = new File(uploadFolderFile, pathname);
final File bundleDestination = new File(deployDirectory, bundle.getName());
if (ResourceCollectorUtil.isFragmentJar(bundle)) { // now we delete the bundle if it is a fragment since we already have the exported packages covered

if (bundle.delete()) {
Logger.debug(this, "Deleted the fragment bundle: " + bundle);
continue;
}
}

Logger.debug(this, "Moving the bundle: " + bundle + " to " + deployDirectory);

if (FileUtil.move(bundle, bundleDestination)) {

Try.run(()->APILocator.getSystemEventsAPI() // CLUSTER WIDE
.push(SystemEventType.OSGI_BUNDLES_LOADED, new Payload(pathnames)))
.onFailure(e -> Logger.error(OSGIUtil.this, e.getMessage()));

Logger.debug(this, "Moved the bundle: " + bundle + " to " + deployDirectory);
} else {
Logger.debug(this, "Could not move the bundle: " + bundle + " to " + deployDirectory);
}
moveBundle(uploadFolderFile, pathnames, deployDirectory, pathname);
}

final String messageKey = pathnames.length > 1? "new-osgi-plugins-installed":"new-osgi-plugin-installed";
final String successMessage = Try.of(()->LanguageUtil.get(APILocator.getCompanyAPI()
.getDefaultCompany().getLocale(), messageKey)).getOrElse(()-> "New OSGi Plugin(s) have been installed");
SystemMessageEventUtil.getInstance().pushMessage("OSGI_BUNDLES_LOADED",new SystemMessageBuilder().setMessage(successMessage)
.setLife(DateUtil.FIVE_SECOND_MILLIS)
.setSeverity(MessageSeverity.SUCCESS).create(), null);

sendOSGIBundlesLoadedMessage(pathnames);
} else {

Logger.warn(this, "The directory: " + this.getFelixDeployPath()
Expand All @@ -604,6 +577,52 @@ private void moveNewBundlesToFelixLoadFolder(final File uploadFolderFile, final
}
}

private void moveBundle(final File uploadFolderFile,
final String[] pathnames,
final File deployDirectory,
final String pathname) throws IOException {

final File bundle = new File(uploadFolderFile, pathname);
final File bundleDestination = new File(deployDirectory, bundle.getName());
if (ResourceCollectorUtil.isFragmentJar(bundle)) { // now we delete the bundle if it is a fragment since we already have the exported packages covered

Files.delete(bundle.toPath());
Logger.debug(this, "Deleted the fragment bundle: " + bundle);
return;
}

Logger.debug(this, "Moving the bundle: " + bundle + " to " + deployDirectory);

move(pathnames, deployDirectory, bundle, bundleDestination);
}

private void move(final String[] pathnames,
final File deployDirectory,
final File bundle,
final File bundleDestination) throws IOException {

if (FileUtil.move(bundle, bundleDestination)) {

Try.run(()->APILocator.getSystemEventsAPI() // CLUSTER WIDE
.push(SystemEventType.OSGI_BUNDLES_LOADED, new Payload(pathnames)))
.onFailure(e -> Logger.error(OSGIUtil.this, e.getMessage()));

Logger.debug(this, "Moved the bundle: " + bundle + " to " + deployDirectory);
} else {
Logger.debug(this, "Could not move the bundle: " + bundle + " to " + deployDirectory);
}
}

private static void sendOSGIBundlesLoadedMessage(final String[] pathnames) {

final String messageKey = pathnames.length > 1? "new-osgi-plugins-installed":"new-osgi-plugin-installed";
final String successMessage = Try.of(()->LanguageUtil.get(APILocator.getCompanyAPI()
.getDefaultCompany().getLocale(), messageKey)).getOrElse(()-> "New OSGi Plugin(s) have been installed");
SystemMessageEventUtil.getInstance().pushMessage("OSGI_BUNDLES_LOADED",new SystemMessageBuilder().setMessage(successMessage)
.setLife(DateUtil.FIVE_SECOND_MILLIS)
.setSeverity(MessageSeverity.SUCCESS).create(), null);
}

/**
* Stops the OSGi framework
*/
Expand Down

0 comments on commit 14c0ba3

Please sign in to comment.