Search in sources :

Example 1 with FsDiff

use of org.jboss.galleon.diff.FsDiff in project galleon by wildfly.

the class FsEntriesTestBase method assertIdentical.

protected void assertIdentical(FsEntry expected, FsEntry actual) throws ProvisioningException {
    final FsDiff diff = FsDiff.diff(expected, actual);
    if (diff.isEmpty()) {
        return;
    }
    fail(diff.toString());
}
Also used : FsDiff(org.jboss.galleon.diff.FsDiff)

Example 2 with FsDiff

use of org.jboss.galleon.diff.FsDiff in project galleon by wildfly.

the class GetChangesCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    try {
        ProvisioningManager mgr = getManager(invoc.getPmSession());
        FsDiff diff = mgr.getFsDiff();
        if (diff.isEmpty()) {
            invoc.println("No changes detected");
        } else {
            Path workingDir = Paths.get(invoc.getConfiguration().getAeshContext().getCurrentWorkingDirectory().getAbsolutePath());
            Path installation = mgr.getInstallationHome();
            PathResolver resolver = new PathResolver() {

                @Override
                public String resolve(String relativePath) {
                    Path absPath = Paths.get(installation.toString(), relativePath);
                    return workingDir.relativize(absPath).toString();
                }
            };
            FsDiff.log(diff, new Consumer<String>() {

                @Override
                public void accept(String msg) {
                    invoc.println(msg);
                }
            }, resolver);
        }
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(ex.getMessage());
    }
}
Also used : Path(java.nio.file.Path) ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) FsDiff(org.jboss.galleon.diff.FsDiff) PathResolver(org.jboss.galleon.diff.FsDiff.PathResolver) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 3 with FsDiff

use of org.jboss.galleon.diff.FsDiff in project galleon by wildfly.

the class ProvisioningManager method getDiffMergedConfig.

private ProvisioningDiffProvider getDiffMergedConfig() throws ProvisioningException {
    final FsDiff diff = getFsDiff();
    if (diff == null || diff.isEmpty()) {
        return null;
    }
    try (ProvisioningLayout<FeaturePackRuntimeBuilder> layout = layoutFactory.newConfigLayout(getProvisioningConfig(), ProvisioningRuntimeBuilder.FP_RT_FACTORY, false)) {
        final ProvisioningDiffProvider diffProvider = ProvisioningDiffProvider.newInstance(layout, getProvisionedState(), diff, log);
        layout.visitPlugins(new FeaturePackPluginVisitor<StateDiffPlugin>() {

            @Override
            public void visitPlugin(StateDiffPlugin plugin) throws ProvisioningException {
                plugin.diff(diffProvider);
            }
        }, StateDiffPlugin.class);
        return diffProvider;
    }
}
Also used : FeaturePackRuntimeBuilder(org.jboss.galleon.runtime.FeaturePackRuntimeBuilder) ProvisioningDiffProvider(org.jboss.galleon.diff.ProvisioningDiffProvider) FsDiff(org.jboss.galleon.diff.FsDiff) StateDiffPlugin(org.jboss.galleon.plugin.StateDiffPlugin)

Example 4 with FsDiff

use of org.jboss.galleon.diff.FsDiff in project galleon by wildfly.

the class ProvisioningManager method getFsDiff.

/**
 * Returns the status of the filesystem describing which files have been
 * added, removed and modified since the last provisioning state transition.
 *
 * @return current status of the filesystem
 * @throws ProvisioningException  in case of an error during the status check
 */
public FsDiff getFsDiff() throws ProvisioningException {
    final ProvisioningConfig config = getProvisioningConfig();
    if (config == null || !config.hasFeaturePackDeps()) {
        return null;
    }
    log.verbose("Detecting user changes");
    final Path hashesDir = LayoutUtils.getHashesDir(getInstallationHome());
    if (Files.exists(hashesDir)) {
        final FsEntry originalState = new FsEntry(null, hashesDir);
        readHashes(originalState, new ArrayList<>());
        final FsEntry currentState = getDefaultFsEntryFactory().forPath(getInstallationHome());
        return FsDiff.diff(originalState, currentState);
    }
    try (ProvisioningRuntime rt = getRuntime(config)) {
        rt.provision();
        final FsEntryFactory fsFactory = getDefaultFsEntryFactory();
        final FsEntry originalState = fsFactory.forPath(rt.getStagedDir());
        final FsEntry currentState = fsFactory.forPath(getInstallationHome());
        final long startTime = log.isVerboseEnabled() ? System.nanoTime() : -1;
        final FsDiff fsDiff = FsDiff.diff(originalState, currentState);
        if (startTime != -1) {
            log.verbose(Errors.tookTime("  filesystem diff", startTime));
        }
        return fsDiff;
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Path(java.nio.file.Path) FsEntry(org.jboss.galleon.diff.FsEntry) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) FsDiff(org.jboss.galleon.diff.FsDiff) FsEntryFactory(org.jboss.galleon.diff.FsEntryFactory)

Example 5 with FsDiff

use of org.jboss.galleon.diff.FsDiff in project galleon by wildfly.

the class FsDiffTestBase method assertIdentical.

protected void assertIdentical(FsEntry expected, FsEntry actual) throws ProvisioningException {
    final FsDiff diff = FsDiff.diff(expected, actual);
    if (diff.isEmpty()) {
        return;
    }
    fail(diff.toString());
}
Also used : FsDiff(org.jboss.galleon.diff.FsDiff)

Aggregations

FsDiff (org.jboss.galleon.diff.FsDiff)5 Path (java.nio.file.Path)2 ProvisioningException (org.jboss.galleon.ProvisioningException)1 ProvisioningManager (org.jboss.galleon.ProvisioningManager)1 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)1 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)1 PathResolver (org.jboss.galleon.diff.FsDiff.PathResolver)1 FsEntry (org.jboss.galleon.diff.FsEntry)1 FsEntryFactory (org.jboss.galleon.diff.FsEntryFactory)1 ProvisioningDiffProvider (org.jboss.galleon.diff.ProvisioningDiffProvider)1 StateDiffPlugin (org.jboss.galleon.plugin.StateDiffPlugin)1 FeaturePackRuntimeBuilder (org.jboss.galleon.runtime.FeaturePackRuntimeBuilder)1 ProvisioningRuntime (org.jboss.galleon.runtime.ProvisioningRuntime)1