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

com.devonfw.tools.ide.migrator.file.FileMigration 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.migrator.file;

import java.io.File;
import java.util.regex.Pattern;

import com.devonfw.tools.ide.migrator.Migration;

/**
 * {@link Migration} for a single {@link File}.
 */
public abstract class FileMigration implements Migration {

  private final Pattern namePattern;

  /**
   * The constructor.
   *
   * @param namePattern the {@link Pattern} used to match the {@link File#getName() filename} to apply this migration
   *        to.
   */
  public FileMigration(Pattern namePattern) {

    super();
    this.namePattern = namePattern;
  }

  /**
   * @return the name {@link Pattern}.
   */
  public Pattern getNamePattern() {

    return this.namePattern;
  }

  @Override
  public final void migrate(File file) throws Exception {

    String name = file.getName();
    if (this.namePattern.matcher(name).matches()) {
      migrateFile(file);
    }
  }

  /**
   * @param file the matching {@link File} to migrate.
   * @throws Exception on error.
   */
  protected abstract void migrateFile(File file) throws Exception;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy