public void export(Path file) throws Exception { ProvisioningXmlWriter.getInstance().write(config, file); }
protected ElementNode toElement(ProvisioningConfig config) { final ElementNode install = addElement(null, Element.INSTALLATION); writeUniverseSpecs(config, install); final ElementNode transitives = addElement(install, Element.TRANSITIVE); for(FeaturePackConfig dep : config.getTransitiveDeps()) { writeFeaturePackConfig(addElement(transitives, Element.FEATURE_PACK), config.getUserConfiguredLocation(dep.getLocation()), dep, config.originOf(dep.getLocation().getProducer())); final ElementNode fpElement = addElement(install, Element.FEATURE_PACK); writeFeaturePackConfig(fpElement, config.getUserConfiguredLocation(fp.getLocation()), fp, config.originOf(fp.getLocation().getProducer())); writeConfigCustomizations(install, Element.INSTALLATION.getNamespace(), config); final String[] names = pluginOptions.keySet().toArray(new String[pluginOptions.size()]); Arrays.sort(names); final ElementNode optionsE = addElement(install, Element.OPTIONS); for(String name : names) { final ElementNode optionE = addElement(optionsE, Element.OPTION); addAttribute(optionE, Attribute.NAME, name); final String value = pluginOptions.get(name); if(value != null) { addAttribute(optionE, Attribute.VALUE, value);
private static void writeUniverseConfig(ElementNode universesEl, String name, String factory, String location) { final ElementNode universeEl = addElement(universesEl, Element.UNIVERSE.getLocalName(), universesEl.getNamespace()); if(name != null) { addAttribute(universeEl, Attribute.NAME, name); } addAttribute(universeEl, Attribute.FACTORY, factory); if(location != null) { addAttribute(universeEl, Attribute.LOCATION, location); } }
static void writeFeaturePackConfig(ElementNode fp, FeaturePackLocation location, FeaturePackConfig featurePack, String origin) { addAttribute(fp, Attribute.LOCATION, location.toString()); if(origin != null) { addElement(fp, Element.ORIGIN.getLocalName(), ns).addChild(new TextNode(origin)); final ElementNode patches = addElement(fp, Element.PATCHES.getLocalName(), ns); for(FPID patchId : featurePack.getPatches()) { final ElementNode patch = addElement(patches, Element.PATCH.getLocalName(), ns); addAttribute(patch, Attribute.ID, patchId.toString()); writeConfigCustomizations(fp, ns, featurePack); packages = addElement(fp, Element.PACKAGES.getLocalName(), ns); addAttribute(packages, Attribute.INHERIT, FALSE); packages = addElement(fp, Element.PACKAGES.getLocalName(), ns); final ElementNode exclude = addElement(packages, Element.EXCLUDE.getLocalName(), ns); addAttribute(exclude, Attribute.NAME, excluded); packages = addElement(fp, Element.PACKAGES.getLocalName(), ns); final ElementNode include = addElement(packages, Element.INCLUDE.getLocalName(), ns); addAttribute(include, Attribute.NAME, included.getName());
addAttribute(fp, Attribute.LOCATION, fpSpec.getFPID().toString()); ProvisioningXmlWriter.writeUniverseSpecs(fpSpec, fp); for(FeaturePackConfig dep : fpSpec.getTransitiveDeps()) { final ElementNode depElement = addElement(transitives, Element.DEPENDENCY); ProvisioningXmlWriter.writeFeaturePackConfig(depElement, fpSpec.getUserConfiguredLocation(dep.getLocation()), dep, fpSpec.originOf(dep.getLocation().getProducer())); for (FeaturePackConfig dep : fpSpec.getFeaturePackDeps()) { final ElementNode depElement = addElement(deps, Element.DEPENDENCY); ProvisioningXmlWriter.writeFeaturePackConfig(depElement, fpSpec.getUserConfiguredLocation(dep.getLocation()), dep, fpSpec.originOf(dep.getLocation().getProducer())); ProvisioningXmlWriter.writeConfigCustomizations(fp, Element.FEATURE_PACK.getNamespace(), fpSpec);
static void writeUniverseSpecs(FeaturePackDepsConfig fpDeps, final ElementNode parent) { ElementNode universesEl = null; UniverseSpec universeSpec = fpDeps.getDefaultUniverse(); if(universeSpec != null) { universesEl = addElement(parent, Element.UNIVERSES.getLocalName(), parent.getNamespace()); writeUniverseConfig(universesEl, null, universeSpec.getFactory(), universeSpec.getLocation()); } if(fpDeps.hasUniverseNamedSpecs()) { if(universesEl == null) { universesEl = addElement(parent, Element.UNIVERSES.getLocalName(), parent.getNamespace()); } for(Map.Entry<String, UniverseSpec> universe : fpDeps.getUniverseNamedSpecs().entrySet()) { writeUniverseConfig(universesEl, universe.getKey(), universe.getValue().getFactory(), universe.getValue().getLocation()); } } }
defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns); addAttribute(defConfigsE, Attribute.INHERIT, FALSE); defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns); addAttribute(defConfigsE, Attribute.INHERIT_UNNAMED_MODELS, FALSE); defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns); final ElementNode exclude = addElement(defConfigsE, Element.EXCLUDE.getLocalName(), ns); addAttribute(exclude, Attribute.MODEL, excluded.getKey()); if(!excluded.getValue()) { addAttribute(exclude, Attribute.NAMED_MODELS_ONLY, FALSE); defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns); final ElementNode included = addElement(defConfigsE, Element.INCLUDE.getLocalName(), ns); addAttribute(included, Attribute.MODEL, modelName); defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns); final ElementNode excluded = addElement(defConfigsE, Element.EXCLUDE.getLocalName(), ns); if(configId.getModel() != null) { addAttribute(excluded, Attribute.MODEL, configId.getModel()); addAttribute(excluded, Attribute.NAME, configId.getName()); defConfigsE = addElement(parent, Element.DEFAULT_CONFIGS.getLocalName(), ns);
/** * Add named universe spec to the provisioning configuration * * @param name universe name * @param universeSpec universe spec * @throws ProvisioningException in case of an error */ public void addUniverse(String name, UniverseSpec universeSpec) throws ProvisioningException { final ProvisioningConfig config = ProvisioningConfig.builder(getProvisioningConfig()).addUniverse(name, universeSpec).build(); try { ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(home)); } catch (Exception e) { throw new ProvisioningException(Errors.writeFile(PathsUtils.getProvisioningXml(home)), e); } this.provisioningConfig = config; }
@Override protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException { if (file != null) { final Path targetFile = file.toPath(); try { getManager(invoc.getPmSession()).exportProvisioningConfig(targetFile); } catch (ProvisioningException | IOException e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } invoc.println("Provisioning file generated in " + targetFile); } else { ByteArrayOutputStream output = null; try { ProvisioningConfig config = getManager(invoc.getPmSession()).getProvisioningConfig(); output = new ByteArrayOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)); ProvisioningXmlWriter.getInstance().write(config, writer); } catch (Exception e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } try { invoc.println(output.toString(StandardCharsets.UTF_8.name())); } catch (UnsupportedEncodingException e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } } }
/** * Removes universe spec associated with the name from the provisioning configuration * @param name name of the universe spec or null for the default universe spec * @throws ProvisioningException in case of an error */ public void removeUniverse(String name) throws ProvisioningException { ProvisioningConfig config = getProvisioningConfig(); if(config == null || !config.hasUniverse(name)) { return; } config = ProvisioningConfig.builder(config).removeUniverse(name).build(); try { ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(home)); } catch (Exception e) { throw new ProvisioningException(Errors.writeFile(PathsUtils.getProvisioningXml(home)), e); } this.provisioningConfig = config; }
@Override protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException { if (file != null) { final Path targetFile = file.toPath(); State session = invoc.getPmSession().getState(); try { session.export(targetFile); } catch (Exception ex) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), ex); } invoc.println("Provisioning file generated in " + targetFile); } else { ByteArrayOutputStream output = null; try { ProvisioningConfig config = invoc.getPmSession().getState().getConfig(); output = new ByteArrayOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)); ProvisioningXmlWriter.getInstance().write(config, writer); } catch (Exception e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } try { invoc.println(output.toString(StandardCharsets.UTF_8.name())); } catch (UnsupportedEncodingException e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } } }
ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(stagedDir)); } catch (XMLStreamException | IOException e) { throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisioningXml(stagedDir)), e);