public boolean isDeployed(final String path) { return deployedApplications.containsKey(ProvisioningUtil.realLocation(path)); }
private static String fallback(final String rawLocation) { if (rawLocation.startsWith(MVN_PREFIX)) { try { final String repo1Url = quickMvnUrl(rawLocation.substring(MVN_PREFIX.length()).replace(":", "/")); final String real = realLocation(repo1Url); return real; } catch (final MalformedURLException e1) { Logger.getLogger(ProvisioningUtil.class.getName()).severe("Can't find " + rawLocation); } } else { // try url try { final File file = cacheFile(lastPart(rawLocation)); final URL url = new URL(rawLocation); InputStream is = null; try { is = new BufferedInputStream(url.openStream()); IO.copy(is, file); return file.getAbsolutePath(); } finally { IO.close(is); } } catch (final Exception e1) { // no-op } } // if it was not an url that's just a file path return rawLocation; }
private static Collection<String> extract(final String zip) throws IOException { final File tmp = new File(SystemInstance.get().getBase().getDirectory(), TEMP_DIR); if (!tmp.exists()) { try { Files.mkdirs(tmp); } catch (final Files.FileRuntimeException fre) { // ignored } } final File zipFile = new File(realLocation(zip)); final File extracted = new File(tmp, zipFile.getName().replace(".zip", "")); if (extracted.exists()) { return list(extracted); } else { Files.mkdirs(extracted); } Zips.unzip(zipFile, extracted); return list(extracted); }
/** * * @param rawLocation * @return */ public static String realLocation(final String rawLocation) { if (hasHttpOrHttpsPrefix(rawLocation)) { final File file = cacheFile(lastPart(rawLocation)); if (file.exists()) { return file.getAbsolutePath(); } String path = null; try { path = copyTryingProxies(new URI(rawLocation), file); } catch (final Exception e1) { // ignored } if (path != null) { return path; } } try { // full maven resolution final Class<?> clazz = ProvisioningUtil.class.getClassLoader().loadClass("org.apache.openejb.resolver.Resolver"); final LocationResolver instance = (LocationResolver) clazz.newInstance(); return instance.resolve(rawLocation); } catch (final Throwable e) { // NoClassDefFoundError is not an exception return fallback(rawLocation); } }
if (toCopy != null) { for (final String lib : toCopy.split(",")) { libToCopy.add(realLocation(lib.trim())); if (toExtract != null) { for (final String zip : toExtract.split(",")) { libToCopy.addAll(extract(realLocation(zip))); newFiles.add(copy(new File(lib), destination));
private synchronized File copyBinaries(final Properties props) throws OpenEJBException { final File dump = ProvisioningUtil.cacheFile(props.getProperty(OPENEJB_PATH_BINARIES, "dump.war")); if (dump.exists()) { Files.delete(dump); final String name = dump.getName(); if (name.endsWith("ar") && name.length() > 4) { final File exploded = new File(dump.getParentFile(), name.substring(0, name.length() - 4)); if (exploded.exists()) { Files.delete(exploded); } } } try { IO.copy(byte[].class.cast(props.get(OPENEJB_VALUE_BINARIES)), dump); } catch (final IOException e) { throw new OpenEJBException(e); } return dump; }
private static Collection<String> list(final File dir) { if (dir == null) { return Collections.emptyList(); } final Collection<String> libs = new ArrayList<String>(); final File[] files = dir.listFiles(); if (files == null) { return Collections.emptyList(); } for (final File file : files) { if (file.isDirectory()) { libs.addAll(list(file)); } else { libs.add(file.getAbsolutePath()); } } return libs; }
try { final Method addUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); for (final File f : ProvisioningUtil.addAdditionalLibraries()) { if (!addUrl.isAccessible()) { // set it lazily addUrl.setAccessible(true);
public static File cacheFile(final String path) { final File cacheDir = new File(SystemInstance.get().getBase().getDirectory(), cache()); if (!cacheDir.exists() && !cacheDir.mkdirs()) { throw new RuntimeException("Failed to create the directory: " + cacheDir); } return new File(cacheDir, path); }
final File file = cacheFile(parser.getArtifactPath()); if (!file.exists() || !file.canRead()) { try {
private static Collection<String> list(final File dir) { if (dir == null) { return Collections.emptyList(); } final Collection<String> libs = new ArrayList<>(); final File[] files = dir.listFiles(); if (files == null) { return Collections.emptyList(); } for (final File file : files) { if (file.isDirectory()) { libs.addAll(list(file)); } else { libs.add(file.getAbsolutePath()); } } return libs; }
for (final File f : ProvisioningUtil.addAdditionalLibraries()) { files.add(f.toURI().toURL());
public AppInfo getAppInfo(final String path) { return deployedApplications.get(ProvisioningUtil.realLocation(path).iterator().next()); }
private static Collection<String> extract(final String zip) throws IOException { final File tmp = new File(SystemInstance.get().getBase().getDirectory(), ProvisioningResolver.TEMP_DIR); if (!tmp.exists()) { try { Files.mkdirs(tmp); } catch (final Files.FileRuntimeException fre) { // ignored } } final File zipFile = new File(zip); final File extracted = new File(tmp, zipFile.getName().replace(".zip", "")); if (extracted.exists()) { return list(extracted); } else { Files.mkdirs(extracted); } Zips.unzip(zipFile, extracted); return list(extracted); }
public boolean isDeployed(final String path) { return deployedApplications.containsKey(ProvisioningUtil.realLocation(path).iterator().next()); }
protected String filteredCommand() { String val = command; int expandStart; while ((expandStart = val.indexOf("@[classpath:")) >= 0) { final int end = val.indexOf("]", expandStart); if (end < 0) { break; } final String expandable = simpleValue(val.substring(expandStart + "@[classpath:".length(), end)); final List<URL> repos = new ArrayList<>(Files.listJars(ProvisioningUtil.realLocation(expandable))); Collections.sort(repos, (o1, o2) -> o1.toExternalForm().compareTo(o2.toExternalForm())); final StringBuilder cp = new StringBuilder(); for (final URL u : repos) { cp.append(Files.toFile(u)).append(System.getProperty("path.separator")); } if (cp.length() > 0) { cp.setLength(cp.length() - System.getProperty("path.separator").length()); } val = val.substring(0, expandStart) + cp.toString() + (end < val.length() ? val.substring(end + 1) : ""); } return simpleValue(val); }
@Override public void undeploy(final String moduleId) throws UndeployException, NoSuchApplicationException { try { assembler.destroyApplication(moduleId); } catch (final NoSuchApplicationException nsae) { try { assembler.destroyApplication(realLocation(moduleId)); } catch (final Exception e) { try { assembler.destroyApplication(new File(moduleId).getAbsolutePath()); } catch (final Exception e2) { try { assembler.destroyApplication(new File(realLocation(moduleId)).getAbsolutePath()); } catch (final Exception e3) { throw nsae; } } } } saveDeployment(new File(moduleId), false); }
/** * Takes a raw unparsed string expected to be in jvm classpath syntax * and parses it, producing a collection of URIs representing the absolute * file paths of the classpath to be created. * <p/> * OS specific delimiters are supported. * * @param rawstring unparsed string in "classpath" syntax * @return URI array * @throws IOException if path cannot be resolved or file referenced does not exist */ public static URI[] resolveClasspath(final String rawstring) throws IOException { final FileUtils base = SystemInstance.get().getBase(); final String[] strings = rawstring.contains("mvn:") ? rawstring.split(";") : rawstring.split(File.pathSeparator); final Collection<URI> classpath = new LinkedList<>(); for (final String string : strings) { final Set<String> locations = ProvisioningUtil.realLocation(PropertyPlaceHolderHelper.simpleValue(string)); for (final String location : locations) { final File file = base.getFile(location, false); classpath.add(file.toURI()); } } return classpath.toArray(new URI[classpath.size()]); }
@Override public void undeploy(final String moduleId) throws UndeployException, NoSuchApplicationException { AppInfo appInfo = assembler.getAppInfo(moduleId); if (appInfo == null) { appInfo = assembler.getAppInfo(realLocation(moduleId).iterator().next()); if (appInfo == null) { appInfo = assembler.getAppInfo(new File(moduleId).getAbsolutePath()); if (appInfo == null) { appInfo = assembler.getAppInfo(new File(realLocation(moduleId).iterator().next()).getAbsolutePath()); } } } if (appInfo != null) { try { assembler.destroyApplication(appInfo); } finally { if (appInfo.properties.containsKey("save-deployment")) { saveDeployment(new File(moduleId), false); } } } else { throw new NoSuchApplicationException(moduleId); } }