Package com.norconex.commons.lang.jar

# Class JarCopier

java.lang.Object
com.norconex.commons.lang.jar.JarCopier

public class JarCopier extends Object
Performs a version-sensitive copy a Jar file or directory containing Jar files over to another directory. When in interactive mode, the user will be prompted to decide how to handle duplicate Jars. Interactive mode requires this application to be run from a command prompt.

Since:
  1.10.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `JarCopier.OnJarConflict`
  Encapsulate target jar conflict resolution options.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `STRATEGY_DELETE_COPY`
  Deprecated.
  Use `JarCopier(OnJarConflict)` instead with `JarCopier.OnJarConflict.SourceAction.COPY_IF_GREATER_OR_EQUIVALENT` and `JarCopier.OnJarConflict.TargetAction.DELETE`.
  `static final int`
  `STRATEGY_INTERACTIVE`
  Deprecated.
  Use `JarCopier(OnJarConflict)` instead.
  `static final int`
  `STRATEGY_NO_COPY`
  Deprecated.
  Use `JarCopier(OnJarConflict)` instead with `JarCopier.OnJarConflict.SourceAction.NOOP`.
  `static final int`
  `STRATEGY_PLAIN_COPY`
  Deprecated.
  Use `JarCopier(OnJarConflict)` instead with `JarCopier.OnJarConflict.SourceAction.COPY`.
  `static final int`
  `STRATEGY_RENAME_COPY`
  Deprecated.
  Use `JarCopier(OnJarConflict)` instead with `JarCopier.OnJarConflict.SourceAction.COPY_IF_GREATER_OR_EQUIVALENT` and `JarCopier.OnJarConflict.TargetAction.RENAME`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JarCopier()`
  Constructor.
  `JarCopier(int strategy)`
  Deprecated.
  Use `JarCopier(OnJarConflict)` instead.
  `JarCopier(@NonNull JarCopier.OnJarConflict onJarConflict)`
  Constructor with custom behavior for jar conflict resolution.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `copyJarDirectory(@NonNull File sourceDirectory, @NonNull File targetDirectory)`
  Copies jars from a source directory to a target one taking into consideration potential jar duplicates.
  `void`
  `copyJarDirectory(@NonNull String sourceDirectory, @NonNull String targetDirectory)`
  Copies jars from a source directory to a target one taking into consideration potential jar duplicates.
  `void`
  `copyJarFile(@NonNull JarFile sourceJarFile, @NonNull File targetDirectory)`
  Copies a single Jar to a target directory, taking into consideration Jar versions.
  `void`
  `copyJarFile(@NonNull File sourceJarFile, File targetDirectory)`
  Copies a single Jar to a target directory, taking into consideration Jar versions.
  `void`
  `copyJarFile(@NonNull String sourceJarFile, @NonNull String toDirectory)`
  Copies a single Jar to a target directory, taking into consideration Jar versions.
  `int`
  `getStrategy()`
  Deprecated.
  See `JarCopier(OnJarConflict)`.
  `static void`
  `main(String[] args)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### STRATEGY_RENAME_COPY

    @Deprecated(since="3.0.0") public static final int STRATEGY_RENAME_COPY
    Deprecated.
    Use `JarCopier(OnJarConflict)` instead with `JarCopier.OnJarConflict.SourceAction.COPY_IF_GREATER_OR_EQUIVALENT` and `JarCopier.OnJarConflict.TargetAction.RENAME`
    Copy source Jar only if greater or same version as target Jar after renaming target Jar (.bak-[timestamp]).
    See Also:
      - Constant Field Values

  - ### STRATEGY_DELETE_COPY

    @Deprecated(since="3.0.0") public static final int STRATEGY_DELETE_COPY
    Deprecated.
    Use `JarCopier(OnJarConflict)` instead with `JarCopier.OnJarConflict.SourceAction.COPY_IF_GREATER_OR_EQUIVALENT` and `JarCopier.OnJarConflict.TargetAction.DELETE`.
    Copy source Jar only if greater or same version as target Jar after deleting target Jar.
    See Also:
      - Constant Field Values

  - ### STRATEGY_NO_COPY

    @Deprecated(since="3.0.0") public static final int STRATEGY_NO_COPY
    Deprecated.
    Use `JarCopier(OnJarConflict)` instead with `JarCopier.OnJarConflict.SourceAction.NOOP`.
    Do not copy source Jar (leave target Jar as is).
    See Also:
      - Constant Field Values

  - ### STRATEGY_PLAIN_COPY

    @Deprecated(since="3.0.0") public static final int STRATEGY_PLAIN_COPY
    Deprecated.
    Use `JarCopier(OnJarConflict)` instead with `JarCopier.OnJarConflict.SourceAction.COPY`.
    Copy source Jar regardless of target Jar (may overwrite or cause mixed versions).
    See Also:
      - Constant Field Values

  - ### STRATEGY_INTERACTIVE

    @Deprecated(since="3.0.0") public static final int STRATEGY_INTERACTIVE
    Deprecated.
    Use `JarCopier(OnJarConflict)` instead.
    Interactive, let the user chose (requires execution on command prompt).
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### JarCopier

    public JarCopier()
    Constructor. Only source Jars with greater or equal versions than their existing target will be copied over, and conflicting Jars will be renamed in the target directory (suffixed with .bak-[timestamp]).

  - ### JarCopier

    public JarCopier(@NonNull @NonNull JarCopier.OnJarConflict onJarConflict)
    Constructor with custom behavior for jar conflict resolution.
    Parameters:
      `onJarConflict` - conflict resolution options
    Since:
      3.0.0

  - ### JarCopier

    @Deprecated(since="3.0.0") public JarCopier(int strategy)
    Deprecated.
    Use `JarCopier(OnJarConflict)` instead.
    Constructor.
    Parameters:
      `strategy` - the strategy to use when encountering duplicates/conflicts

- ## Method Details

  - ### copyJarDirectory

    public void copyJarDirectory(@NonNull @NonNull String sourceDirectory, @NonNull @NonNull String targetDirectory) throws IOException
    Copies jars from a source directory to a target one taking into consideration potential jar duplicates.
    Parameters:
      `sourceDirectory` - directory to copy Jars from
      `targetDirectory` - directory to copy Jars to
    Throws:
      `IOException` - problem copying files

  - ### copyJarDirectory

    public void copyJarDirectory(@NonNull @NonNull File sourceDirectory, @NonNull @NonNull File targetDirectory) throws IOException
    Copies jars from a source directory to a target one taking into consideration potential jar duplicates.
    Parameters:
      `sourceDirectory` - directory to copy Jars from
      `targetDirectory` - directory to copy Jars to
    Throws:
      `IOException` - problem copying files

  - ### copyJarFile

    public void copyJarFile(@NonNull @NonNull String sourceJarFile, @NonNull @NonNull String toDirectory) throws IOException
    Copies a single Jar to a target directory, taking into consideration Jar versions.
    Parameters:
      `sourceJarFile` - the Jar file to copy
      `toDirectory` - directory to copy the jar into
    Throws:
      `IOException` - problem copying files

  - ### copyJarFile

    public void copyJarFile(@NonNull @NonNull File sourceJarFile, File targetDirectory) throws IOException
    Copies a single Jar to a target directory, taking into consideration Jar versions.
    Parameters:
      `sourceJarFile` - the Jar file to copy
      `targetDirectory` - directory to copy the jar into
    Throws:
      `IOException` - problem copying files

  - ### copyJarFile

    public void copyJarFile(@NonNull @NonNull JarFile sourceJarFile, @NonNull @NonNull File targetDirectory) throws IOException
    Copies a single Jar to a target directory, taking into consideration Jar versions.
    Parameters:
      `sourceJarFile` - the Jar file to copy
      `targetDirectory` - directory to copy the jar into
    Throws:
      `IOException` - problem copying files
    Since:
      3.0.0

  - ### main

    public static void main(String[] args) throws IOException
    Throws:
      `IOException`

  - ### getStrategy

    @Deprecated(since="3.0.0") public int getStrategy()
    Deprecated.
    See `JarCopier(OnJarConflict)`.
    Gets the strategy used when encountering duplicates or version conflicts.
    Returns:
      `-1`.