public static ProvisioningConfig readUndoConfig(Path installDir, MessageWriter log) throws ProvisioningException { final Path stateDir = getUndoStateDir(installDir, log); if(stateDir == null) { throw new ProvisioningException(Errors.historyIsEmpty()); } return ProvisioningXmlParser.parse(stateDir.resolve(Constants.PROVISIONING_XML)); }
public static void assertInstallationDir(Path path) throws ProvisioningException { if (!Files.exists(path)) { return; } if (!Files.isDirectory(path)) { throw new ProvisioningException(Errors.notADir(path)); } try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { final Iterator<Path> i = stream.iterator(); if(!i.hasNext()) { return; } while (i.hasNext()) { if (i.next().getFileName().toString().equals(Constants.PROVISIONED_STATE_DIR)) { return; } } throw new ProvisioningException(Errors.homeDirNotUsable(path)); } catch (IOException e) { throw new ProvisioningException(Errors.readDirectory(path)); } }
public FeatureSpec loadFeatureSpec(String name) throws ProvisioningException { final Path specXml = dir.resolve(Constants.FEATURES).resolve(name).resolve(Constants.SPEC_XML); if (!Files.exists(specXml)) { return null; } try (BufferedReader reader = Files.newBufferedReader(specXml)) { return FeatureSpecXmlParser.getInstance().parse(reader); } catch (Exception e) { throw new ProvisioningDescriptionException(Errors.parseXml(specXml), e); } }
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); } }
public <F extends FeaturePackLayout> F resolveFeaturePack(FeaturePackLocation location, int type, FeaturePackLayoutFactory<F> factory) throws ProvisioningException { final Path fpDir = resolveFeaturePackDir(location); final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML); if (!Files.exists(fpXml)) { throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml)); } try (BufferedReader reader = Files.newBufferedReader(fpXml)) { return factory.newFeaturePack(location, FeaturePackXmlParser.getInstance().parse(reader), fpDir, type); } catch (IOException | XMLStreamException e) { throw new ProvisioningException(Errors.parseXml(fpXml), e); } }
installedHistory = Files.readAllLines(installHistoryList); } catch (IOException e) { throw new ProvisioningException(Errors.readFile(installHistoryList), e); throw new ProvisioningException(Errors.writeFile(stagedHistoryDir.resolve(Constants.HISTORY_LIST)), e); Files.createDirectory(stateDir); } catch (IOException e) { throw new ProvisioningException(Errors.mkdirs(stateDir)); throw new ProvisioningException(Errors.copyFile(installedConfig, stateDir.resolve(Constants.PROVISIONING_XML)), e); throw new ProvisioningException(Errors.writeFile(stateDir.resolve(Constants.UNDO_TASKS)), e);
throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(pkgXml)); pkgBuilder = PackageRuntime.builder(this, PackageXmlParser.getInstance().parse(reader), pkgDir, ++rt.pkgsTotal); } catch (IOException | XMLStreamException e) { throw new ProvisioningException(Errors.parseXml(pkgXml), e); throw new UnsatisfiedPackageDependencyException(getFPID(), pkgName, e); } catch(ProvisioningException e) { throw new ProvisioningException(Errors.resolvePackage(getFPID(), pkgName), e); } finally { rt.setOrigin(currentOrigin);
public static FeaturePackSpec readSpec(Path artifactZip) throws ProvisioningException { try (FileSystem zipfs = ZipUtils.newFileSystem(artifactZip)) { for(Path zipRoot : zipfs.getRootDirectories()) { final Path p = zipRoot.resolve(Constants.FEATURE_PACK_XML); if(!Files.exists(p)) { throw new ProvisioningException("Feature-pack archive does not contain " + Constants.FEATURE_PACK_XML); } try(BufferedReader reader = Files.newBufferedReader(p)) { return FeaturePackXmlParser.getInstance().parse(reader); } catch (XMLStreamException e) { throw new ProvisioningException(Errors.parseXml(p), e); } } } catch (IOException e) { throw new ProvisioningException(Errors.readFile(artifactZip), e); } return null; }
targetHash = HashUtils.hashPath(target); } catch (IOException e) { throw new ProvisioningException(Errors.hashCalculation(target), e); IoUtils.copy(added.getPath(), target); } catch (IOException e) { throw new ProvisioningException(Errors.copyFile(added.getPath(), target), e);
public static Path lookupInstallationDir(AeshContext ctx, Path install) throws ProvisioningException { if (install != null) { if (Files.exists(PathsUtils.getProvisioningXml(install))) { return install; } else { throw new ProvisioningException(Errors.homeDirNotUsable(install)); } } else { Path currentDir = PmSession.getWorkDir(ctx); while (currentDir != null) { if (Files.exists(PathsUtils.getProvisioningXml(currentDir))) { return currentDir; } currentDir = currentDir.getParent(); } throw new ProvisioningException(Errors.homeDirNotUsable(PmSession.getWorkDir(ctx))); } } }
throw new ProvisioningDescriptionException(Errors.featurePackAlreadyConfigured(producer)); throw new ProvisioningDescriptionException(Errors.featurePackAlreadyConfigured(producer)); throw new ProvisioningDescriptionException(Errors.duplicateDependencyName(origin)); } else { producerOrigins = CollectionUtils.put(producerOrigins, producer, origin);
private void patchDir(final Path fpDir, final Path patchDir) throws ProvisioningException { try { IoUtils.copy(patchDir, fpDir); } catch (IOException e) { throw new ProvisioningException(Errors.copyFile(patchDir, fpDir), e); } }
static String failedToBuildConfigSpec(String model, String name) { final StringBuilder buf = new StringBuilder(); buf.append("Failed to build configuration "); appendConfig(buf, model, name); return buf.toString(); }
static String unresolvedFeatureDep(ResolvedFeature feature, ResolvedFeatureId dep) { final StringBuilder buf = new StringBuilder(); appendFeature(buf, feature); buf.append(" has unresolved dependency on ").append(dep); return buf.toString(); }
public List<ResolvedFeature> orderFeatures(ConfigModelStack stack) throws ProvisioningException { this.specFeatures = stack.specFeatures; this.features = stack.features; try { doOrder(stack.rt); } catch (ProvisioningException e) { throw new ProvisioningException(Errors.failedToBuildConfigSpec(stack.id.getModel(), stack.id.getName()), e); } return orderedFeatures; }
public Builder excludeLayer(String layerName) throws ProvisioningDescriptionException { if(includedLayers.contains(layerName)) { throw new ProvisioningDescriptionException(Errors.configLayerCanEitherBeIncludedOrExcluded(model, getName(), layerName)); } excludedLayers = CollectionUtils.addLinked(excludedLayers, layerName); return this; }
boolean resolveCapabilityElement(ResolvedFeature feature, String paramName, CapabilityResolver capResolver) throws ProvisioningException { final ResolvedFeatureParam resolvedParam = getResolvedParam(paramName); Object value = feature.getResolvedParam(paramName); if(value == null) { value = feature.isUnset(paramName) ? null : resolvedParam.defaultValue; if (value == null) { if (capResolver.getSpec().isOptional()) { return false; } throw new ProvisioningException(Errors.capabilityMissingParameter(capResolver.getSpec(), paramName)); } } if(Constants.GLN_UNDEFINED.equals(value)) { return true; // skip GLN_UNDEFINED } return resolvedParam.type.resolveCapabilityElement(capResolver, value); }
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(); }
targetHash = HashUtils.hashPath(target); } catch (IOException e) { throw new ProvisioningException(Errors.hashCalculation(target), e); IoUtils.copy(update.getPath(), target); } catch (IOException e) { throw new ProvisioningException(Errors.copyFile(update.getPath(), target), e);
private void copyResources(Path fpDir) throws ProvisioningException { // resources should be copied last overriding the dependency resources final Path fpResources = fpDir.resolve(Constants.RESOURCES); if(Files.exists(fpResources)) { resourcesDir = getWorkDir().resolve(Constants.RESOURCES); try { IoUtils.copy(fpResources, resourcesDir); } catch (IOException e) { throw new ProvisioningException(Errors.copyFile(fpResources, resourcesDir), e); } } final Path fpPlugins = fpDir.resolve(Constants.PLUGINS); if(Files.exists(fpPlugins)) { if(pluginsDir == null) { pluginsDir = getWorkDir().resolve(Constants.PLUGINS); } try { IoUtils.copy(fpPlugins, pluginsDir); } catch (IOException e) { throw new ProvisioningException(Errors.copyFile(fpPlugins, pluginsDir), e); } } }