Last active
December 26, 2015 01:18
-
-
Save mnadeem/7069974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class SVNCMSystem | |
{ | |
private static final String RECENT_CHANGES_FILES = "RecentChanges"; | |
private static final String ERROR_LOGS_FILES = "ErrorLogs"; | |
private static final String PROPERTIES_FILES = ".xml"; | |
private static final String TXT_FILES = ".txt"; | |
private static final String ZIP_FILES = ".zip"; | |
private static final String DIRECTORY_SEPARATOR = "/"; | |
public static synchronized void cmUpdate(String file, String payload) throws IOException, InterruptedException | |
{ | |
if (isNotIgnorable(file)) | |
{ | |
Process addProcess = Runtime.getRuntime().exec("svn add " + file); | |
processOutput(addProcess); | |
Process commitProcess = Runtime.getRuntime().exec("svn commit -m 'Commiting' " + file); | |
processOutput(commitProcess); | |
} | |
} | |
public static synchronized void cmEdit(String file, String payload) throws IOException, InterruptedException | |
{ | |
if (isNotIgnorable(file)) | |
{ | |
Process addProcess = Runtime.getRuntime().exec("svn add " + file); | |
String status = processOutput(addProcess); | |
if (isParentNotFoundError(status, file)) | |
{ | |
file = getParent(file); | |
cmEdit(file, payload); | |
} | |
Process commitProcess = Runtime.getRuntime().exec("svn commit -m 'Commiting' " + file); | |
processOutput(commitProcess); | |
} | |
} | |
public static synchronized void cmPreDelete(String file, String payload) throws IOException, InterruptedException | |
{ | |
Process updateProcess = Runtime.getRuntime().exec("svn update " + getParent(file)); | |
processOutput(updateProcess); | |
} | |
public static synchronized void cmDelete(String file, String payload) throws IOException, InterruptedException | |
{ | |
Process deleteProcess = Runtime.getRuntime().exec("svn delete --force " + file); | |
processOutput(deleteProcess); | |
Process commitProcess = Runtime.getRuntime().exec("svn commit -m 'Deleting' " + getParent(file)); | |
processOutput(commitProcess); | |
} | |
public static boolean isNotIgnorable(String file) | |
{ | |
return !(file.contains(RECENT_CHANGES_FILES) || file.contains(ERROR_LOGS_FILES) || file.contains(ZIP_FILES)); | |
} | |
private static synchronized String processOutput(Process process) throws IOException, InterruptedException | |
{ | |
InputStreamReader errorProcessStreamReader = new InputStreamReader(process.getErrorStream()); | |
BufferedReader errprProcessBufferReader = new BufferedReader((errorProcessStreamReader)); | |
String errorProcessLineString; | |
while ((errorProcessLineString = errprProcessBufferReader.readLine()) != null) | |
{ | |
return errorProcessLineString; | |
} | |
return ""; | |
} | |
private static String getParent(String file) | |
{ | |
return file.substring(0, file.lastIndexOf(DIRECTORY_SEPARATOR)); | |
} | |
public static boolean isParentNotFoundError(String status, String file) | |
{ | |
return ((!status.isEmpty()) && (isContainsFiles(file))); | |
} | |
private static boolean isContainsFiles(String file) | |
{ | |
return ((file.contains(TXT_FILES)) || (file.contains(PROPERTIES_FILES)) || (file.contains(ZIP_FILES))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment