Class SVNPatchTarget
- java.lang.Object
-
- org.tmatesoft.svn.core.internal.wc.patch.SVNPatchTarget
-
public class SVNPatchTarget extends java.lang.Object- Version:
- 1.3
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.FileabsPathprivate booleanaddedprivate java.io.FilecanonPathFromPatchfileprivate intcurrentLineprivate booleandeletedprivate booleaneofprivate java.lang.StringeolStrprivate java.lang.StringeolStyleprivate booleanexecutableprivate java.io.RandomAccessFilefileprivate booleanhadRejectsprivate java.util.Listhunksprivate java.util.Mapkeywordsprivate SVNNodeKindkindprivate java.util.Listlinesprivate booleanlocalModsprivate static intMAX_FUZZprivate booleanmodifiedprivate booleanparentDirExistsprivate SVNPatchpatchprivate java.io.OutputStreampatchedprivate java.io.FilepatchedPathprivate java.io.OutputStreampatchedRawprivate SVNPatchFileStreamrejectprivate java.io.FilerejectPathprivate java.io.FilerelPathprivate booleanskippedprivate SVNPatchFileStreamstream
-
Constructor Summary
Constructors Modifier Constructor Description privateSVNPatchTarget()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyHunk(SVNPatchHunkInfo hi)Write the modified text of hunk described by HI to the patched stream of TARGET.static SVNPatchTargetapplyPatch(SVNPatch patch, java.io.File absWCPath, int stripCount, SVNAdminArea wc)Apply a PATCH to a working copy at ABS_WC_PATH.voidcopyLinesToTarget(int line)Copy lines to the patched stream until the specified LINE has been reached.static java.lang.String[]decomposePath(java.io.File path)private static java.lang.StringdetectFileEOL(java.io.RandomAccessFile file)Detect the EOL marker used in file and return it.java.io.FilegetAbsPath()java.io.FilegetCanonPathFromPatchfile()private java.io.FilegetChildPath(java.io.File basePath, java.io.File childPath)intgetCurrentLine()java.lang.StringgetEolStr()java.lang.StringgetEolStyle()java.io.RandomAccessFilegetFile()SVNPatchHunkInfogetHunkInfo(SVNPatchHunk hunk, int fuzz)Determine the line at which a HUNK applies to the TARGET file, and return an appropriate hunk_info object in *HI, allocated from RESULT_POOL.java.util.ListgetHunks()java.util.MapgetKeywords()SVNNodeKindgetKind()java.util.ListgetLines()SVNPatchgetPatch()java.io.OutputStreamgetPatched()java.io.FilegetPatchedPath()java.io.OutputStreamgetPatchedRaw()SVNPatchFileStreamgetReject()java.io.FilegetRejectPath()java.io.FilegetRelPath()SVNPatchFileStreamgetStream()static SVNPatchTargetinitPatchTarget(SVNPatch patch, java.io.File baseDir, int stripCount, SVNAdminArea wc)Attempt to initialize a patch TARGET structure for a target file described by PATCH.voidinstallPatchedTarget(java.io.File absWCPath, boolean dryRun, SVNAdminArea wc)Install a patched TARGET into the working copy at ABS_WC_PATH.booleanisAdded()static booleanisChildPath(java.io.File baseFile, java.io.File file)booleanisDeleted()booleanisEof()booleanisExecutable()booleanisHadRejects()booleanisLocalMods()booleanisModified()booleanisParentDirExists()booleanisSkipped()private booleanmatchHunk(SVNPatchHunk hunk, int fuzz)Indicate in *MATCHED whether the original text of HUNK matches the patch TARGET at its current line.voidreadLine(java.lang.StringBuffer line)Read a *LINE from TARGET.voidrejectHunk(SVNPatchHunkInfo hi)Write the diff text of the hunk described by HI to the reject stream of TARGET, and mark TARGET as having had rejects.private voidresolveTargetPath(java.io.File pathFromPatchfile, java.io.File absWCPath, int stripCount, SVNAdminArea wc)Resolve the exact path for a patch TARGET at path PATH_FROM_PATCHFILE, which is the path of the target as it appeared in the patch file.intscanForMatch(SVNPatchHunk hunk, boolean matchFirst, int upperLine, int fuzz)Scan lines of TARGET for a match of the original text of HUNK, up to but not including the specified UPPER_LINE.voidseekToLine(int line)Seek to the specified LINE in TARGET.voidsendPatchNotification(SVNAdminArea wc)Use client context CTX to send a suitable notification for a patch TARGET.static java.io.FilestripPath(java.io.File path, int stripCount)private voidtryWrite(java.io.OutputStream stream, java.lang.StringBuffer buffer)Attempt to write LEN bytes of DATA to STREAM, the underlying file of which is at ABSPATH.
-
-
-
Field Detail
-
MAX_FUZZ
private static final int MAX_FUZZ
- See Also:
- Constant Field Values
-
patch
private SVNPatch patch
-
lines
private java.util.List lines
-
hunks
private java.util.List hunks
-
localMods
private boolean localMods
-
executable
private boolean executable
-
skipped
private boolean skipped
-
eolStr
private java.lang.String eolStr
-
keywords
private java.util.Map keywords
-
eolStyle
private java.lang.String eolStyle
-
kind
private SVNNodeKind kind
-
currentLine
private int currentLine
-
modified
private boolean modified
-
hadRejects
private boolean hadRejects
-
deleted
private boolean deleted
-
eof
private boolean eof
-
added
private boolean added
-
absPath
private java.io.File absPath
-
relPath
private java.io.File relPath
-
canonPathFromPatchfile
private java.io.File canonPathFromPatchfile
-
file
private java.io.RandomAccessFile file
-
stream
private SVNPatchFileStream stream
-
patchedPath
private java.io.File patchedPath
-
patchedRaw
private java.io.OutputStream patchedRaw
-
patched
private java.io.OutputStream patched
-
rejectPath
private java.io.File rejectPath
-
reject
private SVNPatchFileStream reject
-
parentDirExists
private boolean parentDirExists
-
-
Method Detail
-
isLocalMods
public boolean isLocalMods()
-
getEolStr
public java.lang.String getEolStr()
-
getKeywords
public java.util.Map getKeywords()
-
getEolStyle
public java.lang.String getEolStyle()
-
getFile
public java.io.RandomAccessFile getFile()
-
getPatchedRaw
public java.io.OutputStream getPatchedRaw()
-
getCanonPathFromPatchfile
public java.io.File getCanonPathFromPatchfile()
-
getPatch
public SVNPatch getPatch()
-
getCurrentLine
public int getCurrentLine()
-
isModified
public boolean isModified()
-
isEof
public boolean isEof()
-
getLines
public java.util.List getLines()
-
isSkipped
public boolean isSkipped()
-
getHunks
public java.util.List getHunks()
-
getKind
public SVNNodeKind getKind()
-
getStream
public SVNPatchFileStream getStream()
-
getPatched
public java.io.OutputStream getPatched()
-
getReject
public SVNPatchFileStream getReject()
-
getPatchedPath
public java.io.File getPatchedPath()
-
isAdded
public boolean isAdded()
-
isDeleted
public boolean isDeleted()
-
isExecutable
public boolean isExecutable()
-
getRejectPath
public java.io.File getRejectPath()
-
getAbsPath
public java.io.File getAbsPath()
-
getRelPath
public java.io.File getRelPath()
-
isHadRejects
public boolean isHadRejects()
-
isParentDirExists
public boolean isParentDirExists()
-
initPatchTarget
public static SVNPatchTarget initPatchTarget(SVNPatch patch, java.io.File baseDir, int stripCount, SVNAdminArea wc) throws SVNException, java.io.IOException
Attempt to initialize a patch TARGET structure for a target file described by PATCH. Use client context CTX to send notifiations and retrieve WC_CTX. STRIP_COUNT specifies the number of leading path components which should be stripped from target paths in the patch. Upon success, return the patch target structure. Else, return NULL.- Throws:
SVNExceptionjava.io.IOException
-
detectFileEOL
private static java.lang.String detectFileEOL(java.io.RandomAccessFile file) throws java.io.IOExceptionDetect the EOL marker used in file and return it. If it cannot be detected, return NULL. The file is searched starting at the current file cursor position. The first EOL marker found will be returnd. So if the file has inconsistent EOL markers, this won't be detected. Upon return, the original file cursor position is always preserved, even if an error is thrown.- Throws:
java.io.IOException
-
resolveTargetPath
private void resolveTargetPath(java.io.File pathFromPatchfile, java.io.File absWCPath, int stripCount, SVNAdminArea wc) throws SVNException, java.io.IOExceptionResolve the exact path for a patch TARGET at path PATH_FROM_PATCHFILE, which is the path of the target as it appeared in the patch file. Put a canonicalized version of PATH_FROM_PATCHFILE into TARGET->CANON_PATH_FROM_PATCHFILE. WC_CTX is a context for the working copy the patch is applied to. If possible, determine TARGET->WC_PATH, TARGET->ABS_PATH, TARGET->KIND, TARGET->ADDED, and TARGET->PARENT_DIR_EXISTS. Indicate in TARGET->SKIPPED whether the target should be skipped. STRIP_COUNT specifies the number of leading path components which should be stripped from target paths in the patch.- Throws:
SVNExceptionjava.io.IOException
-
isChildPath
public static boolean isChildPath(java.io.File baseFile, java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
getChildPath
private java.io.File getChildPath(java.io.File basePath, java.io.File childPath) throws java.io.IOException- Throws:
java.io.IOException
-
stripPath
public static java.io.File stripPath(java.io.File path, int stripCount)
-
rejectHunk
public void rejectHunk(SVNPatchHunkInfo hi) throws SVNException, java.io.IOException
Write the diff text of the hunk described by HI to the reject stream of TARGET, and mark TARGET as having had rejects.- Throws:
java.io.IOExceptionSVNException
-
applyHunk
public void applyHunk(SVNPatchHunkInfo hi) throws SVNException, java.io.IOException
Write the modified text of hunk described by HI to the patched stream of TARGET.- Throws:
SVNExceptionjava.io.IOException
-
seekToLine
public void seekToLine(int line) throws SVNException, java.io.IOExceptionSeek to the specified LINE in TARGET. Mark any lines not read before in TARGET->LINES.- Throws:
SVNExceptionjava.io.IOException
-
readLine
public void readLine(java.lang.StringBuffer line) throws SVNException, java.io.IOExceptionRead a *LINE from TARGET. If the line has not been read before mark the line in TARGET->LINES.- Throws:
SVNExceptionjava.io.IOException
-
copyLinesToTarget
public void copyLinesToTarget(int line) throws SVNException, java.io.IOExceptionCopy lines to the patched stream until the specified LINE has been reached. Indicate in *EOF whether end-of-file was encountered while reading from the target. If LINE is zero, copy lines until end-of-file has been reached.- Throws:
java.io.IOExceptionSVNException
-
installPatchedTarget
public void installPatchedTarget(java.io.File absWCPath, boolean dryRun, SVNAdminArea wc) throws SVNExceptionInstall a patched TARGET into the working copy at ABS_WC_PATH. Use client context CTX to retrieve WC_CTX, and possibly doing notifications. If DRY_RUN is TRUE, don't modify the working copy.- Throws:
SVNException
-
decomposePath
public static java.lang.String[] decomposePath(java.io.File path)
-
applyPatch
public static SVNPatchTarget applyPatch(SVNPatch patch, java.io.File absWCPath, int stripCount, SVNAdminArea wc) throws SVNException, java.io.IOException
Apply a PATCH to a working copy at ABS_WC_PATH. STRIP_COUNT specifies the number of leading path components which should be stripped from target paths in the patch.- Throws:
SVNExceptionjava.io.IOException
-
getHunkInfo
public SVNPatchHunkInfo getHunkInfo(SVNPatchHunk hunk, int fuzz) throws SVNException, java.io.IOException
Determine the line at which a HUNK applies to the TARGET file, and return an appropriate hunk_info object in *HI, allocated from RESULT_POOL. Use fuzz factor FUZZ. Set HI->FUZZ to FUZZ. If no correct line can be determined, set HI->REJECTED to TRUE. When this function returns, neither TARGET->CURRENT_LINE nor the file offset in the target file will have changed.- Throws:
SVNExceptionjava.io.IOException
-
scanForMatch
public int scanForMatch(SVNPatchHunk hunk, boolean matchFirst, int upperLine, int fuzz) throws SVNException, java.io.IOException
Scan lines of TARGET for a match of the original text of HUNK, up to but not including the specified UPPER_LINE. Use fuzz factor FUZZ. If UPPER_LINE is zero scan until EOF occurs when reading from TARGET. Return the line at which HUNK was matched in *MATCHED_LINE. If the hunk did not match at all, set *MATCHED_LINE to zero. If the hunk matched multiple times, and MATCH_FIRST is TRUE, return the line number at which the first match occured in *MATCHED_LINE. If the hunk matched multiple times, and MATCH_FIRST is FALSE, return the line number at which the last match occured in *MATCHED_LINE.- Throws:
SVNExceptionjava.io.IOException
-
matchHunk
private boolean matchHunk(SVNPatchHunk hunk, int fuzz) throws SVNException, java.io.IOException
Indicate in *MATCHED whether the original text of HUNK matches the patch TARGET at its current line. Lines within FUZZ lines of the start or end of HUNK will always match. When this function returns, neither TARGET->CURRENT_LINE nor the file offset in the target file will have changed. HUNK->ORIGINAL_TEXT will be reset.- Throws:
SVNExceptionjava.io.IOException
-
tryWrite
private void tryWrite(java.io.OutputStream stream, java.lang.StringBuffer buffer) throws java.io.IOExceptionAttempt to write LEN bytes of DATA to STREAM, the underlying file of which is at ABSPATH. Fail if not all bytes could be written to the stream.- Throws:
java.io.IOException
-
sendPatchNotification
public void sendPatchNotification(SVNAdminArea wc) throws SVNException
Use client context CTX to send a suitable notification for a patch TARGET.- Throws:
SVNException
-
-