All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.devonfw.tools.ide.configurator.merge.FallbackMerger Maven / Gradle / Ivy

Go to download

Code for configurator the creates or updates configuration of IDEs (Eclipse, etc.).

There is a newer version: 3.0.0-beta25
Show newest version
package com.devonfw.tools.ide.configurator.merge;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

import com.devonfw.tools.ide.configurator.resolve.VariableResolver;

/**
 * Implementation of {@link FileTypeMerger} to use as fallback. It can not actually merge but will simply overwrite the
 * files.
 *
 * @since 3.0.0
 */
public class FallbackMerger extends FileTypeMerger {

  @Override
  public void merge(File setupFile, File updateFile, VariableResolver resolver, File workspaceFile) {

    if (updateFile.exists()) {
      copy(updateFile, workspaceFile);
    } else if (setupFile.exists() && !workspaceFile.exists()) {
      copy(setupFile, workspaceFile);
    }
  }

  @Override
  public void inverseMerge(File workspaceFile, VariableResolver resolver, boolean addNewProperties, File updateFile) {

    // nothing by default, we could copy the workspace file back to the update file if it exists...
  }

  private void copy(File sourceFile, File targetFile) {

    ensureParentDirecotryExists(targetFile);
    try {
      Files.copy(sourceFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (Exception e) {
      throw new IllegalStateException("Failed to copy file " + sourceFile + " to " + targetFile, e);
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy