Refine search
throw new TestContainerException(e); } catch (IOException e) { throw new TestContainerException(e);
private void deployModule(UrlDeploymentOption option) { try { URL applUrl = new URL(option.getURL()); deployModule(option.getName(), applUrl.openStream()); } catch (MalformedURLException exc) { throw new TestContainerException("Problem deploying " + option, exc); } catch (IOException exc) { throw new TestContainerException("Problem deploying " + option, exc); } }
String bundleSymbolicName = null; String bundleName = null; if (url.getPath().endsWith("/")) { URL manifestURL = new URL(url, "META-INF/MANIFEST.MF"); InputStream stream = manifestURL.openStream(); try { Manifest manifest = new Manifest(stream); throw new TestContainerException("[" + url + "] is not a valid exploded bundle", e); final Manifest manifest = jar.getManifest(); if (manifest == null) { throw new TestContainerException("[" + url + "] is not a valid bundle (manifest is missing)"); throw new TestContainerException("[" + url + "] is not a valid bundle (reading jar failed)", e); throw new TestContainerException("[" + url + "] is not a valid bundle (bundleSymbolicName and bundleName are null)");
private String downloadBundle(File workDir, String url) { try { URL realUrl = new URL(url); if (realUrl.getProtocol().equals("reference")) { return url; } File localBundle = platform.download(workDir, realUrl, url, false, true, true, false); return localBundle.toURI().toURL().toString(); } catch (MalformedURLException exc) { throw new TestContainerException(exc); } }
Properties fileNamesForUrls = loadProperties(downloadedBundlesFile); String downloadedFileName = fileNamesForUrls.getProperty(url.toExternalForm()); String hashFileName = "" + url.toExternalForm().hashCode(); if (downloadedFileName == null) { String cachingName = determineCachingName(destination, hashFileName); if (!destination.getName().equals(cachingName)) { throw new TestContainerException("File " + destination + " should have name " + cachingName); if (url.getPath().endsWith("/") && "file".equals(url.getProtocol())) { StreamUtils.streamCopy(new URL("assembly:" + url.toExternalForm()), fileChannel, progressBar); throw new TestContainerException("[" + url + "] could not be downloaded", e); if (newDestination.exists()) { if (!newDestination.delete()) { throw new TestContainerException("Cannot delete " + newDestination); throw new TestContainerException("Cannot rename " + destination + " to " + newDestination);
private String localize(String url) { try { URL realUrl = new URL(url); if (realUrl.getProtocol().equals("reference")) { // must be "reference:file:..." return new URL(realUrl.getPath()).getPath(); } else if (realUrl.getProtocol().equals("file")) { return realUrl.getPath(); } File artifact = platform.download(system.getTempFolder(), realUrl, url, false, false, false, false); return artifact.getCanonicalPath(); } catch (MalformedURLException exc) { throw new TestContainerException(exc); } catch (IOException exc) { throw new TestContainerException(exc); } }
&& carbonHomeDirectoryOption.getDistributionMavenURL() == null && carbonHomeDirectoryOption.getDistributionZipPath() == null) { throw new TestContainerException("Distribution path need to be set."); String name = system.createID(CARBON_TEST_CONTAINER); ExamSystem subsystem = system.fork(options(systemProperty(RMI_HOST_PROPERTY).value(host), systemProperty(RMI_PORT_PROPERTY).value(Integer.toString(port)), systemProperty(RMI_NAME_PROPERTY).value(name), systemProperty(EXAM_INJECT_PROPERTY).value("true"))); target = new RBCRemoteTarget(name, port, subsystem.getTimeout()); System.setProperty("java.protocol.handler.pkgs", "org.ops4j.pax.url"); URL sourceDistribution = new URL(carbonHomeDirectoryOption.getDistributionMavenURL().getURL()); ArchiveExtractor.extract(sourceDistribution, targetDirectory.toFile()); } else if (carbonHomeDirectoryOption.getDistributionZipPath() != null) { Path sourceDistribution = carbonHomeDirectoryOption.getDistributionZipPath(); ArchiveExtractor.extract(sourceDistribution, targetDirectory.toFile()); } else if (carbonHomeDirectoryOption.getDistributionDirectoryPath() != null) { Path sourceDirectory = carbonHomeDirectoryOption.getDistributionDirectoryPath(); FileUtils.copyDirectory(sourceDirectory.toFile(), targetDirectory.toFile()); started = true; } catch (IOException e) { throw new TestContainerException("Problem starting container", e);
private void installWildFlyModule(String module, File moduleDir) { try { URL moduleUrl = new URL(module); LOG.info("installing add-on module {}", module); ZipInstaller installer = new ZipInstaller(moduleUrl, moduleDir.getAbsolutePath()); installer.downloadAndInstall(); } catch (MalformedURLException exc) { throw new TestContainerException("invalid module URL: " + module, exc); } catch (IOException exc) { throw new TestContainerException(exc); } }
String url = option.getURL(); LOG.info("deploying module {}", url); URI uri = new URL(url).toURI(); String applicationName = option.getName(); String contextRoot = option.getContextRoot(); throw new TestContainerException(exc); throw new TestContainerException(exc); throw new TestContainerException(exc);
/** * Extract zip or tar.gz specified by maven url to a target Directory. * * @param sourceURL url of the archive to extract * @param targetDirectory where to extract to * @throws IOException on I/O error */ public static void extract(URL sourceURL, File targetDirectory) throws IOException { if (Constants.FILE_PROTOCOL.equals(sourceURL.getProtocol())) { String file = sourceURL.getFile(); if (file.endsWith("." + Constants.ZIP_EXTENSION)) { extractZipDistribution(sourceURL, targetDirectory); } else if (file.endsWith("." + Constants.TARGZ_EXTENSION)) { extractTarGzDistribution(sourceURL, targetDirectory); } else { throw new TestContainerException( "Unknown packaging of distribution; only zip or tar.gz could be handled."); } return; } if (sourceURL.toExternalForm().endsWith("/" + Constants.ZIP_EXTENSION)) { extractZipDistribution(sourceURL, targetDirectory); } else if (sourceURL.toExternalForm().endsWith("/" + Constants.TARGZ_EXTENSION)) { extractTarGzDistribution(sourceURL, targetDirectory); } else { throw new TestContainerException( "Unknown packaging; only zip or tar.gz could be handled. URL was " + sourceURL); } }
/** * Extract zip file in the system to a target Directory. * * @param path path of the archive to be extract * @param targetDirectory where to extract to * @throws IOException on I/O error */ public static void extract(Path path, File targetDirectory) throws IOException { if (path.toString().endsWith("." + Constants.ZIP_EXTENSION)) { extract(new ZipArchiveInputStream(new FileInputStream(path.toFile())), targetDirectory); } else { throw new TestContainerException("Unknown packaging of distribution; only zip can be handled."); } }
private File toFile(String uriString) { try { URI uri = new URI(uriString); try { return new File(uri); } catch (IllegalArgumentException exc) { InputStream is = uri.toURL().openStream(); File tempFile = File.createTempFile("pax-exam", ".tmp"); OutputStream os = new FileOutputStream(tempFile); StreamUtils.copyStream(is, os, true); return tempFile; } } catch (URISyntaxException exc) { throw new TestContainerException(exc); } catch (IOException exc) { throw new TestContainerException(exc); } }
/** * @param clazz * to find the root classes folder for. * * @return A File instance being the exact folder on disk or null, if it hasn't been found. * * @throws java.io.IOException * if a problem occurs (method crawls folders on disk..) */ public static File findClassesFolder(Class<?> clazz) throws IOException { ClassLoader classLoader = clazz.getClassLoader(); String clazzPath = convertClassToPath(clazz); URL url = classLoader.getResource(clazzPath); if (url == null || !"file".equals(url.getProtocol())) { return null; } else { try { File file = new File(url.toURI()); String fullPath = file.getCanonicalPath(); String parentDirPath = fullPath .substring(0, fullPath.length() - clazzPath.length()); return new File(parentDirPath); } catch (URISyntaxException e) { // this should not happen as the uri was obtained from getResource throw new TestContainerException(e); } } }
UnicastRemoteObject.unexportObject(registry, true); } catch (NoSuchObjectException exc) { throw new TestContainerException(exc); throw new TestContainerException("Container never started."); target = null; if (shouldDeleteRuntime()) { system.clear(); try { FileUtils.forceDelete(targetDirectory.toFile()); } catch (IOException e) { forceCleanup();
/** * Generate a random path if the unpack directory is not specified. * * @return the path to the carbon home directory * @throws IOException */ private Path retrieveFinalTargetDirectory() throws IOException { Path unpackDirectory = carbonHomeDirectoryOption.getUnpackDirectory(); if (unpackDirectory == null) { unpackDirectory = Paths.get("target", UUID.randomUUID().toString()); } boolean isCreated = unpackDirectory.toFile().exists() || unpackDirectory.toFile().mkdir(); if (!isCreated) { throw new TestContainerException("Couldn't create the directory: " + unpackDirectory.toFile().toString()); } return unpackDirectory; }
/** * Copy files specified in the carbon file copy option to the destination path. * * @param carbonHome carbon home */ private void copyFiles(Path carbonHome) { Arrays.asList(system.getOptions(CopyFileOption.class)).forEach(option -> { try { Files.copy(option.getSourcePath(), carbonHome.resolve(option.getDestinationPath()), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new TestContainerException("Error while copying configuration files", e); } }); }
@Override public void stop() { try { remoteFramework.stop(); system.clear(); } catch (RemoteException | BundleException exc) { throw new TestContainerException(exc); } frameworkFactory.join(); system.clear(); }
private void stopOrAbort() throws BundleException, InterruptedException { framework.stop(); long timeout = system.getTimeout().getValue(); Thread stopper = new Stopper(timeout); stopper.start(); stopper.join(timeout + 500); // If the framework is not stopped, then we're in trouble anyway, so we do not worry // about stopping the worker thread. if (framework.getState() != Bundle.RESOLVED) { String message = "Framework has not yet stopped after " + timeout + " ms. waitForStop did not return"; throw new TestContainerException(message); } }
@Override public void start() { ExamSystem fork = system.fork(new Option[] { systemPackage("org.ops4j.pax.exam.container.eclipse;version=" + skipSnapshotFlag(Info.getPaxExamVersion())), fork.getTempFolder()); Map<String, String> initialProperties = createFrameworkProperties(fork, setLocationProperties(createEclipseDefaults(), layout)); try { layout.create(); for (CopyFilesOption option : fork.getOptions(CopyFilesOption.class)) { option.copyTo(layout); throw new TestContainerException("Problem starting test container.", e);
private void startEmbeddedServer() { installContainer(); cm.loadSystemProperties(WILDFLY90_SYSTEM_PROPERTIES_KEY); File tempDir = system.getTempFolder(); File dataDir = new File(tempDir, "data"); dataDir.mkdir(); File configFile = new File(configTargetDir, "standalone.xml"); if (!configFile.exists()) { throw new TestContainerException(configFile + " does not exist"); } parseServerConfiguration(configFile); System.setProperty("jboss.server.data.dir", dataDir.getAbsolutePath()); validateManagementPort(); server = EmbeddedServerFactory.create(wildFlyHome, null, getSystemPackages(), null); try { server.start(); } catch (ServerStartException exc) { throw new TestContainerException("Problem starting embedded server.", exc); } }