-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
400 additions
and
28 deletions.
There are no files selected for viewing
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
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
108 changes: 108 additions & 0 deletions
108
src/main/java/br/uff/ic/gardener/client/ClientMerge.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package br.uff.ic.gardener.client; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import br.uff.ic.gardener.ConfigurationItem; | ||
import br.uff.ic.gardener.merge.IMerge; | ||
import br.uff.ic.gardener.merge.MergeException; | ||
import br.uff.ic.gardener.merge.MergeWithRegEx; | ||
import br.uff.ic.gardener.util.FileHelper; | ||
import br.uff.ic.gardener.util.UtilStream; | ||
import br.uff.ic.gardener.workspace.Workspace; | ||
|
||
/** | ||
* classe que encapsula o trabalho de merge | ||
* @author Marcos | ||
* | ||
*/ | ||
public class ClientMerge { | ||
|
||
public class ClientMergeException extends Exception | ||
{ | ||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = 920405757395138678L; | ||
|
||
public ClientMergeException(String msg, Throwable t) { | ||
super(msg, t); | ||
} | ||
|
||
} | ||
private File pathTemp = null; | ||
|
||
private long fileID = 0; | ||
|
||
private boolean lastConflict = false; | ||
|
||
public ClientMerge() throws IOException | ||
{ | ||
pathTemp = FileHelper.createTemporaryRandomPath(); | ||
} | ||
|
||
public InputStream merge(ConfigurationItem ciServ, | ||
ConfigurationItem ciWork, Workspace workspace) throws MergeException, ClientMergeException | ||
{ | ||
lastConflict = false; | ||
IMerge realMerge = new MergeWithRegEx(); | ||
//cria arquivos | ||
File f1 = createFile(ciServ); | ||
File f2 = createFile(ciWork); | ||
File fBase = createFile(); | ||
File fDest = createFile(); | ||
//faz o merge | ||
lastConflict = realMerge.merge(f1, f2, fBase, fDest); | ||
|
||
f1.delete(); | ||
f2.delete(); | ||
fBase.delete(); | ||
try { | ||
|
||
return new FileInputStream(fDest); | ||
} catch (FileNotFoundException e) { | ||
throw new ClientMergeException("Error at create File Destiny", e); | ||
} | ||
} | ||
|
||
|
||
private File createFile() throws ClientMergeException | ||
{ | ||
File f = new File(pathTemp, Long.toString(fileID)+".tmp"); | ||
try { | ||
f.createNewFile(); | ||
fileID++; | ||
} catch (IOException e) { | ||
throw new ClientMergeException("Error in create file" + f.toString(), e); | ||
} | ||
return f; | ||
} | ||
private File createFile(ConfigurationItem ci) throws ClientMergeException { | ||
File f = createFile(); | ||
FileOutputStream fOut = null; | ||
try { | ||
fOut = new FileOutputStream(f); | ||
UtilStream.copy(ci.getItemAsInputStream(), fOut); | ||
fOut.close(); | ||
} catch (FileNotFoundException e) { | ||
throw new ClientMergeException("Cannot open file " + f.toString(), e); | ||
} catch (IOException e) { | ||
throw new ClientMergeException("File output problem: " + f.toString(), e); | ||
} | ||
|
||
return f; | ||
} | ||
|
||
public void close() | ||
{ | ||
FileHelper.deleteDirTree(pathTemp); | ||
} | ||
|
||
public boolean lastConflict() { | ||
return lastConflict; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package br.uff.ic.gardener.client; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* conflict between two files | ||
* @author Marcos | ||
* | ||
*/ | ||
public class Conflict { | ||
|
||
private URI pathA; | ||
private URI pathB; | ||
|
||
public final URI getPathA() { | ||
return pathA; | ||
} | ||
|
||
public final URI getPathB() { | ||
return pathB; | ||
} | ||
|
||
public Conflict(URI A, URI B) | ||
{ | ||
pathA = A; | ||
pathB = B; | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.