@Test public void isSpringJdbcAvailable() { assertTrue(FeatureDetector.isSpringJdbcAvailable()); }
/** * Extract a kar from a given URI into a repository dir and resource dir and populate * shouldInstallFeatures and featureRepos * * @param repoDir directory to write the repository contents of the kar to * @param resourceDir directory to write the resource contents of the kar to */ public void extract(File repoDir, File resourceDir) { InputStream is = null; JarInputStream zipIs = null; FeatureDetector featureDetector = new FeatureDetector(); this.featureRepos = new ArrayList<URI>(); this.shouldInstallFeatures = true; try { is = karUri.toURL().openStream(); repoDir.mkdirs(); if (!repoDir.isDirectory()) { throw new RuntimeException("The KAR file " + karUri + " is already installed"); } LOGGER.debug("Uncompress the KAR file {} into directory {}", karUri, repoDir); zipIs = new JarInputStream(is); boolean scanForRepos = true; Manifest manifest = zipIs.getManifest(); if (manifest != null) { Attributes attr = manifest.getMainAttributes(); String featureStartSt = (String) attr.get(new Attributes.Name(MANIFEST_ATTR_KARAF_FEATURE_START)); if ("false".equals(featureStartSt)) { shouldInstallFeatures = false; } String featureReposAttr = (String) attr.get(new Attributes.Name(MANIFEST_ATTR_KARAF_FEATURE_REPOS)); if (featureReposAttr != null) { featureRepos.add(new URI(featureReposAttr)); scanForRepos = false; } } ZipEntry entry = zipIs.getNextEntry(); while (entry != null) { if (entry.getName().startsWith("repository")) { String path = entry.getName().substring("repository/".length()); File destFile = new File(repoDir, path); extract(zipIs, entry, destFile); if (scanForRepos && featureDetector.isFeaturesRepository(destFile)) { Map map = new HashMap<>(); String uri = Parser.pathToMaven(path, map); if (map.get("classifier") != null && ((String) map.get("classifier")).equalsIgnoreCase("features")) featureRepos.add(URI.create(uri)); else featureRepos.add(destFile.toURI()); } } if (entry.getName().startsWith("resource")) { String path = entry.getName().substring("resource/".length()); File destFile = new File(resourceDir, path); extract(zipIs, entry, destFile); } entry = zipIs.getNextEntry(); } } catch (Exception e) { throw new RuntimeException( "Error extracting kar file " + karUri + " into dir " + repoDir + ": " + e.getMessage(), e); } finally { closeStream(zipIs); closeStream(is); } }