/** * 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; }
/** * {@inheritDoc} */ public void preDeploy(IDeployable<?> deployable) { if (deployable != null) { String name = deployable.getShortName(); DeployableState state = DeployableState.NOT_DEPLOYED; deployables.put(name, state); String path = null; try { path = deployable.getArchive().getURL().getPath(); } catch (ArchiveException e) { logger.error("Cannot get the path of the deployable " + name, e); } Dictionary<String, Object> dictionary = new Hashtable<String, Object>(); dictionary.put(EVENT_DEPLOYABLE_NAME_KEY, name); dictionary.put(EVENT_DEPLOYABLE_STATE_KEY, state); dictionary.put(EVENT_DEPLOYABLE_PATH_KEY, path); dictionary.put(EVENT_DEPLOYABLE_SOURCE_KEY, getDeployableSource(name)); 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()); }
T unpackedDeployable = deployable.getUnpackedDeployable(); if (unpackedDeployable == null) { tmpURL = deployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get URL on deployable '" + deployable + "'"); deployable.setUnpackedDeployable(unpackedDeployable); unpackedDeployable.setOriginalDeployable(deployable); urlDeployable = unpackedDeployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get URL for the deployable '" + unpackedDeployable + "'.", e);
itResouces = deployable.getArchive().getResources(); } catch (ArchiveException e) { throw new DeployerException("Cannot get the resources on the archive '" + deployable.getArchive() + "'.", e); deployableURL = deployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get the resources on the archive '" + deployable.getArchive() + "'.", e); unpackedDeployable.setOriginalDeployable(deployable); deployable.setUnpackedDeployable(unpackedDeployable);
EARDeployable earworkingDeployable = null; T unpackedDeployable = deployable.getUnpackedDeployable(); if (unpackedDeployable != null) { workingDeployable = unpackedDeployable; archiveURL = workingDeployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get URL for the given archive", e); itResources = workingDeployable.getArchive().getResources(); } catch (ArchiveException e) { throw new DeployerException("Cannot get the resources for the deployable '" + workingDeployable + "'.", e); IDeployable unpackedSubDeployable = (IDeployable) subDeployable.getUnpackedDeployable(); if (unpackedSubDeployable != null) { try { URL archiveURLtoPack = unpackedSubDeployable.getArchive().getURL(); String san = URLUtils.shorterName(archiveURLtoPack); File packedJar = pack(unpackedSubDeployable, folder, "new-" + san);
/** * {@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); }
/** * 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); } }
if (deployable != null) { try { File file = URLUtils.urlToFile(deployable.getArchive().getURL()); deployedFiles.remove(file.getPath()); } catch (ArchiveException e) { String name = deployable.getShortName(); DeployableState state; Exception exception = null; path = deployable.getArchive().getURL().getPath(); } catch (ArchiveException e) { logger.error("Cannot get the path of the deployable " + name, e);
IDeployable<?> originalDeployable = deployable.getOriginalDeployable(); if (originalDeployable != null) { deployableURL = originalDeployable.getArchive().getURL(); } else { deployableURL = deployable.getArchive().getURL();
/** * @param osgiDeployable An OSGi deployable * @return the associated {@link Bundle} from the OSGi plateform */ private Bundle getBundle(IDeployable<OSGiDeployable> osgiDeployable) { //get the bundle key IArchiveMetadata archiveMetadata = osgiDeployable.getArchive().getMetadata(); String symbolicName = archiveMetadata.get(BUNDLE_SYMBOLIC_NAME); String version = archiveMetadata.get(BUNDLE_VERSION); //scan the OSGi platform in order to retrieve the right Bundle if (symbolicName != null && version != null) { List<Bundle> bundles = Arrays.asList(this.bundleContext.getBundles()); for (Bundle bundle: bundles) { if (bundle.getSymbolicName().equals(symbolicName) && bundle.getVersion().toString().equals(version)) { return bundle; } } } return null; } }
if (deployable != null) { try { File file = URLUtils.urlToFile(deployable.getArchive().getURL()); deployedFiles.add(file.getPath()); } catch (ArchiveException e) { String name = deployable.getShortName(); DeployableState state; Exception exception = null; path = deployable.getArchive().getURL().getPath(); } catch (ArchiveException e) { logger.error("Cannot get the path of the deployable " + name, e);
/** * @param osgiDeployable An OSGi deployable * @return the associated {@link Bundle} from the OSGi plateform */ private Bundle getBundle(IDeployable<OSGiDeployable> osgiDeployable) { //get the bundle key IArchiveMetadata archiveMetadata = osgiDeployable.getArchive().getMetadata(); String symbolicName = archiveMetadata.get(BUNDLE_SYMBOLIC_NAME); String version = archiveMetadata.get(BUNDLE_VERSION); //scan the OSGi platform in order to retrieve the right Bundle if (symbolicName != null && version != null) { List<Bundle> bundles = Arrays.asList(this.bundleContext.getBundles()); for (Bundle bundle: bundles) { if (bundle.getSymbolicName().equals(symbolicName) && bundle.getVersion().toString().equals(version)) { return bundle; } } } return null; } }
/** * 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; }
LibDeployable libDeployable = new LibDeployableImpl(deployable.getArchive()); libDeployables.add(libDeployable); allDeployables.add(libDeployable);
/** * 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; }
deployableURL = deployable.getArchive().getURL(); } catch (ArchiveException e) { throw new IllegalStateException("Cannot get the URL for the deployable '" + deployable + "'.", e);
/** * 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(); } } } }
url = deployable.getArchive().getURL(); } catch (ArchiveException e) { throw new DeployerException("Cannot get the URL for the deployable '" + deployable + "'.", e);