private static void processPackages(FeaturePackDescription.Builder fpBuilder, Path packagesDir, String encoding) throws ProvisioningDescriptionException { assertDirectory(packagesDir); try (DirectoryStream<Path> stream = Files.newDirectoryStream(packagesDir)) { for(Path path : stream) { fpBuilder.addPackage(processPackage(path, encoding)); } } catch (IOException e) { failedToReadDirectory(packagesDir, e); } }
public static FeaturePackDescription describeFeaturePackZip(Path artifactZip) throws IOException, ProvisioningDescriptionException { try (FileSystem zipfs = ZipUtils.newFileSystem(artifactZip)) { for(Path zipRoot : zipfs.getRootDirectories()) { return describeFeaturePack(zipRoot, "UTF-8"); } } return null; }
@SuppressWarnings("unchecked") public T addLocalFeaturePack(Path path) throws ProvisioningException { if (path == null) { return (T) this; } try { FeaturePackDescription featurePackLayout = FeaturePackDescriber.describeFeaturePackZip(path); getLocalFeaturePacks().put(featurePackLayout.getFPID(), path); return (T) this; } catch (IOException e) { throw new ProvisioningException(e); } }
@Override protected String getId(PmSession session) throws CommandExecutionException { String filePath = (String) getValue(FILE_OPTION_NAME); if (filePath == null) { filePath = getOptionValue(FILE_OPTION_NAME); if (filePath == null) { return super.getId(session); } } Path path; try { path = Util.resolvePath(session.getAeshContext(), filePath); } catch (IOException ex) { throw new CommandExecutionException(ex.getMessage()); } if (!Files.exists(path)) { return null; } try { return FeaturePackDescriber.readSpec(path).getFPID().toString(); } catch (ProvisioningException ex) { throw new CommandExecutionException(session, CliErrors.retrieveFeaturePackID(), ex); } }
public static FeaturePackDescription describeFeaturePack(Path fpDir, String encoding) throws ProvisioningDescriptionException { assertDirectory(fpDir); final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML); if(!Files.exists(fpXml)) { throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml)); } final FeaturePackDescription.Builder layoutBuilder; try (Reader is = Files.newBufferedReader(fpXml, Charset.forName(encoding))) { final FeaturePackSpec.Builder specBuilder = FeaturePackSpec.builder(); XmlParsers.parse(is, specBuilder); layoutBuilder = FeaturePackDescription.builder(specBuilder); } catch (IOException e) { throw new ProvisioningDescriptionException(Errors.openFile(fpXml)); } catch (XMLStreamException e) { throw new ProvisioningDescriptionException(Errors.parseXml(fpXml), e); } final Path packagesDir = fpDir.resolve(Constants.PACKAGES); if(Files.exists(packagesDir)) { processPackages(layoutBuilder, packagesDir, encoding); } return layoutBuilder.build(); }
private static PackageSpec processPackage(Path pkgDir, String encoding) throws ProvisioningDescriptionException { assertDirectory(pkgDir); final Path pkgXml = pkgDir.resolve(Constants.PACKAGE_XML); if(!Files.exists(pkgXml)) { throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(pkgXml)); } try (Reader in = Files.newBufferedReader(pkgXml, Charset.forName(encoding))) { return PackageXmlParser.getInstance().parse(in); } catch (IOException e) { throw new ProvisioningDescriptionException(Errors.openFile(pkgXml), e); } catch (XMLStreamException e) { throw new ProvisioningDescriptionException(Errors.parseXml(pkgXml), e); } }
/** * Adds feature-pack archive to the local provisioning feature-pack cache. * Optionally, installs the feature-pack archive to the universe repository. * * @param featurePack feature-pack archive * @param installInUniverse whether to install the feature-pack into the universe repository * @return feature-pack location which was added to the local cache * @throws ProvisioningException in case of a failure */ public synchronized FeaturePackLocation addLocal(Path featurePack, boolean installInUniverse) throws ProvisioningException { final FPID fpid = FeaturePackDescriber.readSpec(featurePack).getFPID(); cacheManager.put(featurePack, fpid); if(!installInUniverse) { return fpid.getLocation(); } if(universeInstallers == null) { universeInstallers = UniverseFeaturePackInstaller.load(); } final Universe<?> universe = universeResolver.getUniverse(fpid.getUniverse()); final UniverseFeaturePackInstaller fpInstaller = universeInstallers.get(universe.getFactoryId()); if(fpInstaller == null) { throw new ProvisioningException(Errors.featurePackInstallerNotFound(universe.getFactoryId(), universeInstallers.keySet())); } fpInstaller.install(universe, fpid, featurePack); return fpid.getLocation(); }