Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* de.unkrig.patch - An enhanced version of the UNIX PATCH utility
*
* Copyright (c) 2011, Arno Unkrig
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package de.unkrig.zz.patch;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import de.unkrig.commons.file.ExceptionHandler;
import de.unkrig.commons.file.contentstransformation.ContentsTransformations;
import de.unkrig.commons.file.contentstransformation.ContentsTransformer;
import de.unkrig.commons.file.contentstransformation.SelectiveContentsTransformer;
import de.unkrig.commons.file.filetransformation.FileTransformations;
import de.unkrig.commons.file.filetransformation.FileTransformations.ArchiveCombiner;
import de.unkrig.commons.file.filetransformation.FileTransformations.DirectoryCombiner;
import de.unkrig.commons.file.filetransformation.FileTransformations.NameAndContents;
import de.unkrig.commons.file.filetransformation.FileTransformer;
import de.unkrig.commons.file.org.apache.commons.compress.archivers.ArchiveFormatFactory;
import de.unkrig.commons.file.org.apache.commons.compress.compressors.CompressionFormatFactory;
import de.unkrig.commons.lang.protocol.ConsumerWhichThrows;
import de.unkrig.commons.lang.protocol.Predicate;
import de.unkrig.commons.lang.protocol.PredicateUtil;
import de.unkrig.commons.nullanalysis.Nullable;
import de.unkrig.commons.text.pattern.Glob;
import de.unkrig.commons.text.pattern.IncludeExclude;
/**
* Implementation of a PATCH utility with the following features:
*
*
Transforms regular files, directory trees, and optionally entries in ZIP files (also in nested ones)
*
Reads patch files in NORMAL, CONTEXT and UNIFIED diff format
*
Can replace the contents of files from "update files"
*
Can do search-and-replace within files (SED like)
*
Can transform out-of-place or in-place
*
Optionally keeps copies of the original files
*
Can remove files
*
Can rename files
*
Can add files
*
*/
public
class Patch {
private static final Logger LOGGER = Logger.getLogger(Patch.class.getName());
private static
class ContentsTransformation {
public Predicate super String> pathPredicate;
public ContentsTransformer contentsTransformer;
ContentsTransformation(Predicate super String> pathPredicate, ContentsTransformer contentsTransformer) {
this.pathPredicate = pathPredicate;
this.contentsTransformer = contentsTransformer;
}
}
private
interface Combiner extends DirectoryCombiner, ArchiveCombiner {}
private static final Combiner
DEFAULT_COMBINER = new Combiner() {
@Override public void
combineDirectory(
String directoryPath,
ConsumerWhichThrows super NameAndContents, ? extends IOException> memberAdder
) {}
@Override public void
combineArchive(
String archivePath,
ConsumerWhichThrows super NameAndContents, ? extends IOException> entryAdder
) {}
};
private boolean saveSpace = true;
private boolean keepOriginals;
private final List contentsTransformations = new ArrayList();
private Predicate super String> fileAndArchiveEntryRemoval = PredicateUtil.never();
private final IncludeExclude fileAndArchiveEntryRenaming = new IncludeExclude();
private Combiner combiner = Patch.DEFAULT_COMBINER;
private Predicate super String> lookIntoFormat = PredicateUtil.always();
@Nullable private Comparator