ProvisioningLayout.Handle createHandle() { final ProvisioningLayout.Handle handle = new ProvisioningLayout.Handle(this); openHandles.incrementAndGet(); return handle; }
List<ProvisioningPlugin> plugins = loadedPlugins.get(clazz.getName()); if (plugins == null) { final ClassLoader pluginsCl = getPluginsClassLoader(); final Iterator<T> pluginIterator = ServiceLoader.load(clazz, pluginsCl).iterator(); plugins = Collections.emptyList(); thread.setContextClassLoader(getPluginsClassLoader()); try { for (ProvisioningPlugin plugin : plugins) {
private <O extends FeaturePackLayout> ProvisioningLayout(ProvisioningLayout<O> other, FeaturePackLayoutFactory<F> fpFactory, FeaturePackLayoutTransformer<F, O> transformer) throws ProvisioningException { this.layoutFactory = other.layoutFactory; this.fpFactory = fpFactory; this.config = other.config; this.options = CollectionUtils.clone(other.options); // feature-packs are processed in the reverse order and then re-ordered again // this is necessary to properly analyze and include optional package and their external dependencies int i = other.ordered.size(); ordered.ensureCapacity(i); while(--i >= 0) { final O otherFp = other.ordered.get(i); final F fp = transformer.transform(otherFp); featurePacks.put(fp.getFPID().getProducer(), fp); ordered.add(fp); } Collections.reverse(ordered); if(!other.fpPatches.isEmpty()) { fpPatches = new HashMap<>(other.fpPatches.size()); for (Map.Entry<FPID, List<O>> patchEntry : other.fpPatches.entrySet()) { final List<O> patches = patchEntry.getValue(); final List<F> convertedPatches = new ArrayList<>(patches.size()); for(O o : patches) { convertedPatches.add(transformer.transform(o)); } fpPatches.put(patchEntry.getKey(), convertedPatches); } } this.handle = other.handle; handle.incrementRefs(); }
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); } } }
protected Path newStagedDir() throws ProvisioningException { final Path stagedDir = getWorkDir().resolve(STAGED); if(Files.exists(stagedDir)) { try(DirectoryStream<Path> stream = Files.newDirectoryStream(stagedDir)) { for(Path p : stream) { IoUtils.recursiveDelete(p); } } catch (IOException e) { throw new ProvisioningException(Errors.readDirectory(stagedDir), e); } } else { try { Files.createDirectories(stagedDir); } catch (IOException e) { throw new ProvisioningException(Errors.mkdirs(stagedDir), e); } } return stagedDir; }
ProvisioningLayout(ProvisioningLayoutFactory layoutFactory, ProvisioningConfig config, FeaturePackLayoutFactory<F> fpFactory, Map<String, String> extraOptions) throws ProvisioningException { this.layoutFactory = layoutFactory; this.fpFactory = fpFactory; this.config = config; this.handle = layoutFactory.createHandle(); if(config.hasFeaturePackDeps()) { try { build(false, true); initPluginOptions(extraOptions, false); } catch(Throwable t) { handle.close(); throw t; } } }
ProvisioningLayout(ProvisioningLayoutFactory layoutFactory, ProvisioningConfig config, FeaturePackLayoutFactory<F> fpFactory, boolean initPluginOptions) throws ProvisioningException { this.layoutFactory = layoutFactory; this.fpFactory = fpFactory; this.config = config; this.handle = layoutFactory.createHandle(); if(config.hasFeaturePackDeps()) { try { build(false, true); if (initPluginOptions) { initPluginOptions(Collections.emptyMap(), false); } } catch(Throwable t) { handle.close(); throw t; } } }
private Path getTmpDir() { return tmpDir == null ? tmpDir = getWorkDir().resolve(TMP) : tmpDir; }
public Path newStagedDir() throws ProvisioningException { return handle.newStagedDir(); }
public ClassLoader getPluginsClassLoader() throws ProvisioningException { return handle.getPluginsClassLoader(); }
private Path getPatchedDir() { return patchedDir == null ? patchedDir = getWorkDir().resolve(PATCHED) : patchedDir; }
@Override public void close() { handle.close(); } }
@Override public void close() { if(refs == 0 || --refs > 0) { return; } reset(); if(workDir != null) { IoUtils.recursiveDelete(workDir); } layoutFactory.handleClosed(); } }
private void build(boolean cleanupTransitive, boolean trackProgress) throws ProvisioningException { try { doBuild(cleanupTransitive, trackProgress); } catch (ProvisioningException | RuntimeException | Error e) { handle.close(); throw e; } }
private void rebuild(ProvisioningConfig config, boolean cleanupTransitive) throws ProvisioningException { final boolean trackProgress = featurePacks.isEmpty(); featurePacks.clear(); ordered.clear(); allPatches = Collections.emptyMap(); fpPatches = Collections.emptyMap(); this.config = config; handle.reset(); fsEntryFactory = null; build(cleanupTransitive, trackProgress); }
/** * Returns a path for a temporary file-system resource. * * @param path path relative to the global tmp directory * @return temporary file-system path */ public Path getTmpPath(String... path) { return handle.getTmpPath(path); }
/** * Returns a resource path for the provisioning setup. * * @param path path to the resource relative to the global resources directory * @return file-system path for the resource * @throws ProvisioningException in case the layout does not include any resources */ public Path getResource(String... path) throws ProvisioningException { return handle.getResource(path); }