public static Path getPackageDir(Path fpDir, String packageName, boolean existing) throws ProvisioningDescriptionException { final Path dir = fpDir.resolve(Constants.PACKAGES).resolve(packageName); if(existing && !Files.exists(dir)) { throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(dir)); } return dir; }
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); } }
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 static Path getFeaturePackDir(Path fpLayoutDir, FPID fpid, boolean existing) throws ProvisioningDescriptionException { final FeaturePackLocation fps = fpid.getLocation(); final UniverseSpec universe = fps.getUniverse(); Path fpPath = fpLayoutDir.resolve(universe.getFactory()); if (universe.getLocation() != null) { fpPath = fpPath.resolve(ensureValidFileName(universe.getLocation())); } fpPath = fpPath.resolve(ensureValidFileName(fps.getProducerName())).resolve(fps.getChannelName()).resolve(ensureValidFileName(fpid.getBuild())); if (existing && !Files.exists(fpPath)) { throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpPath)); } return fpPath; }
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(); }
throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(pkgXml));