/** * @param osgiDeployable The OSGi deployable * @param bundle Its associated Bundle to start */ protected void startBundle(OSGiDeployable osgiDeployable, Bundle bundle) { if (osgiDeployable.isStart()) { try { // Compute the options // Always respect the bundle's activation policy int options = Bundle.START_ACTIVATION_POLICY; // Enable transient bundle if required if (osgiDeployable.isStartTransient()) { options |= Bundle.START_TRANSIENT; } // Start the bundle with the options bundle.start(options); } catch (BundleException e) { logger.error("Cannot start the bundle ''{0}''.", osgiDeployable, e); } } }
/** * {@inheritDoc} */ public void preUndeploy(IDeployable<?> deployable) { Dictionary<String, Object> dictionary = new Hashtable<String, Object>(); dictionary.put(EVENT_DEPLOYABLE_NAME_KEY, deployable.getShortName()); dictionary.put(EVENT_DEPLOYABLE_CURRENT_TIME, Long.valueOf(Calendar.getInstance().getTimeInMillis())); publisher.send(dictionary); }
/** * Gets a shorter name for this deployable. * @return a shorter name based on the URL. */ public String getShortName() { IDeployable<?> deployable = this; // Gets the root deployable while (deployable.getOriginalDeployable() != null) { deployable = deployable.getOriginalDeployable(); } // Get URL String urlExternalForm; try { urlExternalForm = deployable.getArchive().getURL().toExternalForm(); } catch (ArchiveException e) { throw new IllegalStateException("Cannot get URL of the deployable '" + this + "'.", e); } // if it ends by a /, remove this last one if (urlExternalForm.charAt(urlExternalForm.length() - 1) == '/') { urlExternalForm = urlExternalForm.substring(0, urlExternalForm.length() - 1); } // get string after the last / (all URL have this, no need to test if // there is a / character) int slashPos = urlExternalForm.lastIndexOf('/'); // Return the shorter name return urlExternalForm.substring(slashPos + 1, urlExternalForm.length()); }
EARDeployable unpackedDeployable = earDeployable.getUnpackedDeployable(); if (unpackedDeployable != null) { earDeployable = unpackedDeployable; earURL = earDeployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get the URL on the EAR deployable '" + earDeployable + "'.", e); List<WARDeployable> warDeployables = earDeployable.getWARDeployables(); if (warDeployables != null && webContainerService != null) { List<URL> urls = new ArrayList<URL>(); for (WARDeployable warDeployable : warDeployables) { try { urls.add(warDeployable.getArchive().getURL()); } catch (ArchiveException e) { logger.error("Cannot get the URL from the Deployable ''{0}''", warDeployable, e); List<EJB21Deployable> ejb21Deployables = earDeployable.getEJB21Deployables(); if (ejb21Deployables != null && ejb21Service != null) { List<URL> urls = new ArrayList<URL>(); for (EJB21Deployable ejbDeployable : ejb21Deployables) { try { urls.add(ejbDeployable.getArchive().getURL()); } catch (ArchiveException e) { logger.error("Cannot get the URL from the Deployable ''{0}''", ejbDeployable, e); List<RARDeployable> rarDeployables = earDeployable.getRARDeployables(); if (rarDeployables != null && resourceService != null) { List<URL> urls = new ArrayList<URL>();
/** * If it is a bundle (in the bundle/ directory), change the type of the deployable. * @param deployable the module of this EAR * @return the updated deployable if it is a bundle module. */ protected IDeployable<?> updateDeployableIfBundle(final IDeployable<?> deployable) { // Get name within the EAR String relativeModuleName = getRelativeNameFromDeployable(deployable); String bundleDirectory = BUNDLE_DIRECTORY; // No library directory, do nothing if ("".equals(bundleDirectory)) { return deployable; } // Append a / at the end of the directory name if (!bundleDirectory.endsWith("/")) { bundleDirectory += "/"; } // It is a library if (relativeModuleName.startsWith(bundleDirectory)) { return new OSGiDeployableImpl(deployable.getArchive()); } return deployable; }
List<WARDeployable> warDeployables = earDeployable.getWARDeployables(); if (warDeployables != null) { for (WARDeployable warDeployable : warDeployables) { URL warURL = null; try { warURL = warDeployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get URL on the deployable '" + warDeployable + "'.", e); String ctxId = warURL.getFile() + warDeployable.getContextRoot();
for (IDeployable<?> internalDeployable : (EARDeployable.class.cast(deployable)).getAllDeployables()) { startRequiredServices(internalDeployable); IArchiveMetadata metadata = deployable.getArchive().getMetadata();
EARDeployable unpackedDeployable = earDeployable.getUnpackedDeployable(); if (unpackedDeployable != null) { workingDeployable = unpackedDeployable; for (EJB3Deployable ejb3 : workingDeployable.getEJB3Deployables()) { EZBContainer container = getEmbedded().findContainer(ejb3.getArchive()); logger.warn("No container found for the archive ''{0}'', creation has maybe failed", ejb3.getArchive()); continue;
final boolean resetPolicyConfiguration) throws DeployerException { List<EJBDeployable> ejbDeployables = earDeployable.getEJBDeployables(); List<URL> urls = new ArrayList<URL>(); if (ejbDeployables != null) { for (EJBDeployable ejbDeployable : ejbDeployables) { try { urls.add(ejbDeployable.getArchive().getURL()); } catch (ArchiveException e) { throw new DeployerException("Cannot get URL on the deployable '" + ejbDeployable + "'.", e);
/** * This method is called before metadata is filled. */ @Override public void beforeScan(final EjbJarArchiveMetadata ejbJarArchiveMetadata) { EasyBeansDD easyBeansDD = null; try { easyBeansDD = EasyBeansDeploymentDesc.getEasyBeansDD(ejbJarArchiveMetadata.getDeployable().getArchive()); } catch (ParsingException e) { logger.warn("Exception during parsing of easybeans.xml ", e); easyBeansDD = null; } ejbJarArchiveMetadata.setEasyBeansDD(easyBeansDD); }
/** * Allows to get the URL from the given deployable. * @param deployable the given deployable. * @return an URL object of this deployable * @throws DeployerException if the URL can't be obtained. */ protected URL getURL(final IDeployable<T> deployable) throws DeployerException { // Get URL URL url = null; try { url = deployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get URL from deployable '" + deployable + "'.", e); } // Get URL return url; }
IDeployable<?> originalDeployable = deployable.getOriginalDeployable(); if (originalDeployable != null) { deployableURL = originalDeployable.getArchive().getURL(); } else { deployableURL = deployable.getArchive().getURL();
/** * @param osgiDeployable The OSGi deployable * @param bundle Its associated Bundle to start */ protected void startBundle(OSGiDeployable osgiDeployable, Bundle bundle) { if (osgiDeployable.isStart()) { try { // Compute the options // Always respect the bundle's activation policy int options = Bundle.START_ACTIVATION_POLICY; // Enable transient bundle if required if (osgiDeployable.isStartTransient()) { options |= Bundle.START_TRANSIENT; } // Start the bundle with the options bundle.start(options); } catch (BundleException e) { logger.error("Cannot start the bundle ''{0}''.", osgiDeployable, e); } } }
/** * Unpack the given archive in the given folder, then build a local * deployable (and fill it with submodules for EAR) and then return it. * @param deployable the archive to unpack. * @param pattern the path in the pattern to use in the temp folder * @param keepExistingFiles if 'true', do not override existing files * @param earUnpackOpts options to unpack an ear * @param <T> an object implementing IDeployable * @return a new deployable (which is unpacked) * @throws DeployerException if the Deployable can't be unpacked */ public static <T extends IDeployable<T>> T unpack(final T deployable, final String pattern, final boolean keepExistingFiles, final EarUnpackOpts earUnpackOpts) throws DeployerException { File unpackedFolder = new File(createTmpFolder(pattern, deployable), deployable.getShortName()); unpackedFolder.mkdir(); return unpack(deployable, unpackedFolder, keepExistingFiles, earUnpackOpts); }
@Override public boolean equals(final Object object) { if (!(object instanceof IDeployable)) { return false; } IDeployable<T> other = (IDeployable<T>) object; try { return this.getArchive().getURL().equals(other.getArchive().getURL()); } catch (ArchiveException e) { return super.equals(object); } }
/** * Perform the right report callback depending on the callback type. * @param type The callback type * @param deployable The {@link IDeployable} */ private void reportCallback(final DeployerManagerCallbackType type, final IDeployable<?> deployable) { for (IDeployerManagerReportCallback reportCallback: this.reportCallbacks) { try { switch (type) { case PRE_DEPLOY: reportCallback.preDeploy(deployable); break; case PRE_UNDEPLOY: reportCallback.preUndeploy(deployable); break; default: break; } } catch (Throwable t) { logger.error("Error during the execution of the ''{0}'' callback for ''{1}''", type, deployable.getArchive(), t); t.printStackTrace(); } } } }
/** * If it is a library, change the type of the deployable. * @param deployable the module of this EAR * @return the new deployable if it is a library module. */ protected IDeployable<?> checkLibDeployable(final IDeployable<?> deployable) { // Get name within the EAR String relativeModuleName = getRelativeNameFromDeployable(deployable); String libraryDirectory = null; if (earInfo != null) { libraryDirectory = earInfo.getLibraryDirectory(); } else { // default value libraryDirectory = IEARInfo.DEFAULT_LIBRARY_FOLDER; } // No library directory, do nothing if ("".equals(libraryDirectory)) { return deployable; } // Append a / at the end of the directory name if (!libraryDirectory.endsWith("/")) { libraryDirectory += "/"; } // It is a library if (relativeModuleName.startsWith(libraryDirectory)) { return new LibDeployableImpl(deployable.getArchive()); } return deployable; }
url = deployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get the URL for the deployable '" + deployable + "'.", e);
/** * Perform the right callback depending on the callback type. * @param type The callback type * @param deploymentReport The {@link IDeploymentReport} */ private void reportCallback(final DeployerManagerCallbackType type, final IDeploymentReport deploymentReport) { for (IDeployerManagerReportCallback reportCallback: this.reportCallbacks) { try { switch (type) { case POST_DEPLOY: reportCallback.postDeploy(deploymentReport); break; case POST_UNDEPLOY: reportCallback.postUndeploy(deploymentReport); break; default: break; } } catch (Throwable t) { logger.error("Error during the execution of the ''{0}'' callback for ''{1}''", type, deploymentReport.getDeployable().getArchive(), t); t.printStackTrace(); } } }
type, deployable.getArchive(), t); t.printStackTrace();