Skip to content

Commit 34f4824

Browse files
varias mejoras
1 parent e20567c commit 34f4824

File tree

7 files changed

+325
-19
lines changed

7 files changed

+325
-19
lines changed

dist/compareToGit-0.1-boot.jar

8.08 KB
Binary file not shown.

dist/compareToGit-0.1-sources.jar

2.31 KB
Binary file not shown.

dist/compareToGit-0.1.jar

7.98 KB
Binary file not shown.

src/main/java/org/bcjj/gitCompare/GitFileVersionInfo.java

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ private void createTempFile() throws Exception {
101101
FileWriter fw=new FileWriter(tempFile);
102102
fw.write("error obteniendo fichero "+fileVsGit.getGitFile()+" idCommit:"+commitId+" Posiblemente borrado");
103103
fw.close();
104+
} finally {
105+
try {
106+
fos.close();
107+
} catch (Exception r) {
108+
//ignorar
109+
}
104110
}
105111
}
106112

src/main/java/org/bcjj/gitCompare/GitRepo.java

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Date;
77
import java.util.TimeZone;
88

9+
import org.apache.commons.lang3.StringUtils;
910
import org.eclipse.jgit.api.Git;
1011
import org.eclipse.jgit.internal.storage.file.FileRepository;
1112
import org.eclipse.jgit.lib.Constants;
@@ -37,11 +38,23 @@ public class GitRepo {
3738
private String fromCommitAuthorEmail;
3839
private File tempDir;
3940

41+
42+
public static void main(String [] s) throws Exception {
43+
GitRepo gitRepo=new GitRepo("D:/proyectos/huntfilesTest/git","33868");
44+
System.out.println("fromId:"+gitRepo.fromId);
45+
}
46+
4047
public GitRepo(String path,String fromPartialCommitId) throws Exception {
48+
path=StringUtils.replace(path, "\\", "/");
49+
path=StringUtils.replace(path,"//", "/");
50+
while (path.endsWith("/")) {
51+
path=path.substring(0,path.length()-1);
52+
}
4153
this.path=path;
4254

4355
fileRepository=new FileRepository(path + "/.git");
4456
git=new Git(fileRepository);
57+
4558
lastCommitId = fileRepository.resolve(Constants.HEAD);
4659
if (lastCommitId==null) {
4760
throw new Exception(path+" no es un repositorio git. No se resuelve HEAD");
@@ -54,6 +67,7 @@ public GitRepo(String path,String fromPartialCommitId) throws Exception {
5467
fromId=lastCommitId;
5568
this.fromPartialCommitId=fromId.getName();
5669
} else {
70+
fromPartialCommitId=fromPartialCommitId.trim();
5771
this.fromPartialCommitId=fromPartialCommitId;
5872
fromId = fileRepository.resolve(fromPartialCommitId);
5973
}

src/main/java/org/bcjj/gitCompare/gui/GitCompareMainWindow.java

+129-14
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.Properties;
3737
import java.util.StringTokenizer;
3838
import java.util.concurrent.Executors;
39+
import java.util.regex.Matcher;
40+
import java.util.regex.Pattern;
3941

4042
import javax.swing.BoxLayout;
4143
import javax.swing.ComboBoxModel;
@@ -71,11 +73,13 @@
7173
import org.bcjj.gitCompare.GitFileVersionInfo;
7274
import org.bcjj.gitCompare.GitRepo;
7375
import org.bcjj.gitCompare.gui.ComboUtil.ComboName;
76+
import org.bcjj.gitCompare.gui.MapeoDlg.MapeoInfo;
7477

7578
import net.iharder.dnd.FileDrop;
7679
import java.awt.Font;
7780
import javax.swing.JComboBox;
7881
import javax.swing.JCheckBox;
82+
import java.awt.Toolkit;
7983

8084
// obtener el commit de una fecha git rev-list -1 --before="$DATE" master
8185
/*
@@ -196,7 +200,12 @@ public class GitCompareMainWindow implements ContenedorHistorico {
196200
private JButton btnSave;
197201
private String compareCommand;
198202

199-
private List<String> reglasMapeo;
203+
private List<String> confMapeoReglasMapeo;
204+
private String confMapeoFicheroParaFecha;
205+
private String confMapeoFicheroParaCommitId;
206+
private String confMapeoCommitIdExpresion;
207+
private int confMapeoCommitIdExpresionGroup;
208+
200209
private JPanel panel_8;
201210
private JTextField commitInfo;
202211
private JPanel panelBrachName;
@@ -239,6 +248,7 @@ public class GitCompareMainWindow implements ContenedorHistorico {
239248
private JPanel panelGitOptionBranch;
240249
private JLabel lblOptionBranch;
241250
private JTextField textOptionBranch;
251+
private JLabel lblNewLabel_1;
242252

243253

244254
/**
@@ -309,6 +319,7 @@ protected ImageIcon createImageIcon(String path) {
309319
*/
310320
private void initialize() {
311321
frmGitcompare = new JFrame();
322+
frmGitcompare.setIconImage(Toolkit.getDefaultToolkit().getImage(GitCompareMainWindow.class.getResource("/images/arrow-divide2.png")));
312323
frmGitcompare.setTitle("GitCompare");
313324
frmGitcompare.setBounds(100, 100, 920, 572);
314325
frmGitcompare.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -399,19 +410,28 @@ private void openProject() throws IOException {
399410
}
400411
Properties p=new Properties();
401412
InputStream r=null;
402-
reglasMapeo=new ArrayList<String>();
413+
confMapeoReglasMapeo=new ArrayList<String>();
403414
try {
404415
r=new FileInputStream(filenameValue);
405416
p.load(r);
406417
String branchName=p.getProperty("branchName");
407418
getTextOptionBranch().setText(branchName);
408419
getTxtFilesDir().setText(p.getProperty("filesDir"));
409420
getTxtGitdirectory().setText(p.getProperty("gitDir"));
410-
refreshBranch();
421+
getTxtUserName().setText(p.getProperty("userName"));
422+
confMapeoFicheroParaFecha=p.getProperty("ficheroParaFecha","");
423+
confMapeoFicheroParaCommitId=p.getProperty("ficheroParaCommitId","");
424+
confMapeoCommitIdExpresion=p.getProperty("commitIdExpresion","");
425+
try {
426+
confMapeoCommitIdExpresionGroup=Integer.parseInt(p.getProperty("commitIdExpresionGroup","0"));
427+
} catch (Exception ee) {
428+
confMapeoCommitIdExpresionGroup=0;
429+
}
430+
refreshMapeoData();
411431
for (int i=0;i<1000;i++) {
412432
String x=p.getProperty("path."+i);
413433
if (x!=null) {
414-
reglasMapeo.add(x);
434+
confMapeoReglasMapeo.add(x);
415435
}
416436
}
417437
} catch (Exception e) {
@@ -429,14 +449,88 @@ private void openProject() throws IOException {
429449
}
430450

431451

452+
private void refreshMapeoData() {
453+
boolean ponerFecha=false;
454+
boolean puestaFecha=false;
455+
boolean ponerCommitId=false;
456+
boolean puestoCommitId=false;
457+
try {
458+
if (confMapeoFicheroParaFecha!=null && !confMapeoFicheroParaFecha.trim().equals("")) {
459+
ponerFecha=true;
460+
File fFecha=new File(confMapeoFicheroParaFecha);
461+
if (fFecha.exists() && fFecha.isFile()) {
462+
Date d=new Date(fFecha.lastModified());
463+
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm");
464+
String fec=sdf.format(d);
465+
getCmbFechaDesde().setSelectedItem(fec);
466+
puestaFecha=true;
467+
}
468+
}
469+
} catch (Exception r) {
470+
System.out.println("error al refrescar los datos de mapeo para el fichero para fecha "+r);
471+
}
472+
try {
473+
if (confMapeoFicheroParaCommitId!=null && !confMapeoFicheroParaCommitId.trim().equals("")) {
474+
ponerCommitId=true;
475+
File fCommit=new File(confMapeoFicheroParaCommitId);
476+
if (fCommit.exists() && fCommit.isFile()) {
477+
String commitId=getCommitIdFromFile(fCommit);
478+
if (commitId!=null) {
479+
getTxtCommitId().setText(commitId);
480+
puestoCommitId=true;
481+
}
482+
}
483+
}
484+
} catch (Exception r) {
485+
System.out.println("error al refrescar los datos de mapeo para el obterner el commitId "+r);
486+
}
487+
String falta="";
488+
if (ponerFecha && !puestaFecha) {
489+
falta=falta+ "No se ha establecido la fecha desde.";
490+
}
491+
if (ponerCommitId && !puestoCommitId) {
492+
falta=falta+"No se ha puesto el commitId";
493+
}
494+
if (!falta.trim().equals("")) {
495+
showMessage(falta);
496+
}
497+
refreshBranch();
498+
}
499+
500+
private String getCommitIdFromFile(File fCommit) throws IOException {
501+
String leido = FileUtils.readFileToString(fCommit);
502+
String[] lineas = leido.split("\r\n");
503+
Pattern pattern = Pattern.compile(confMapeoCommitIdExpresion);
504+
for (String txt:lineas) {
505+
try {
506+
Matcher matcher = pattern.matcher(txt);
507+
if (matcher.find()) {
508+
String encontrado=matcher.group(confMapeoCommitIdExpresionGroup);
509+
return encontrado;
510+
}
511+
} catch (Exception r) {
512+
//ignorar
513+
}
514+
}
515+
return null;
516+
}
517+
432518
protected void saveMaps() throws IOException {
433519
String filenameValue=getProjectFile();
434520
Properties p=new Properties();
435521
p.setProperty("branchName", getTextOptionBranch().getText());
436522
p.setProperty("filesDir", getTxtFilesDir().getText());
437523
p.setProperty("gitDir", getTxtGitdirectory().getText());
524+
525+
p.setProperty("ficheroParaFecha", confMapeoFicheroParaFecha);
526+
p.setProperty("ficheroParaCommitId", confMapeoFicheroParaCommitId);
527+
p.setProperty("commitIdExpresion", confMapeoCommitIdExpresion);
528+
p.setProperty("commitIdExpresionGroup", ""+confMapeoCommitIdExpresionGroup);
529+
530+
p.setProperty("userName", getTxtUserName().getText());
531+
438532
int i=0;
439-
for (String r:reglasMapeo) {
533+
for (String r:confMapeoReglasMapeo) {
440534
p.setProperty("path."+i, r);
441535
i++;
442536
}
@@ -585,6 +679,13 @@ public int compare(File f1, File f2) {
585679
String fileAbsMapeado=mapearReglas(fileAbs); // src/web/web-prod/srv/main.jsp
586680
if (fileAbsMapeado!="!") {
587681
String tempF=tempDirectoy+fileAbsMapeado;
682+
File f=new File(tempF);
683+
String soloNombre=f.getName();
684+
String ext="";
685+
if (soloNombre.lastIndexOf(".")>0) {
686+
ext=soloNombre.substring(soloNombre.lastIndexOf(".")); //incluye el punto
687+
}
688+
588689
FileVsGit fileVsGit=new FileVsGit(fich,gitRepo,fileAbsMapeado,borrar,tempF);
589690
if (fileAbsMapeado.contains("codigo.java")) {
590691
System.out.println(fileAbsMapeado);
@@ -601,10 +702,12 @@ public int compare(File f1, File f2) {
601702
for (GitFileVersionInfo version:versionesRev) {
602703
i++;
603704
String numVer = String.format("%03d", i);
705+
604706
String tempFile=tempDirectoy+fileAbsMapeado+"--"+numVer+"--"+version.getCommitId().substring(0, 6)+"--"+version.getFechaComprimidaYMDHMS();
605707
if (version.isBase()) {
606708
tempFile=tempFile+"-base";
607709
}
710+
tempFile=tempFile+ext;
608711
version.setTempFile(new File(tempFile));
609712
}
610713

@@ -667,10 +770,10 @@ private String trimPathSymbol(String exp) {
667770

668771
private String mapearReglas(String fileAbs) { //como baseDirAbsolute termina forzosamente por /, fileAbs no comenzará por /
669772
fileAbs=StringUtils.replace(fileAbs, "\\", "/");
670-
if (reglasMapeo==null) {
773+
if (confMapeoReglasMapeo==null) {
671774
return fileAbs;
672775
}
673-
for (String s:reglasMapeo) {
776+
for (String s:confMapeoReglasMapeo) {
674777
StringTokenizer st=new StringTokenizer(s,"|");
675778
String buscar=trimPathSymbol(st.nextToken())+"/";
676779
String mapear=trimPathSymbol(st.nextToken())+"/";
@@ -1348,7 +1451,7 @@ public void actionPerformed(ActionEvent e) {
13481451

13491452
protected String getReglasMapeoAsString() {
13501453
StringBuilder strReglasMapeo=new StringBuilder();
1351-
for (String r:reglasMapeo) {
1454+
for (String r:confMapeoReglasMapeo) {
13521455
strReglasMapeo.append(r).append("\r\n");
13531456
}
13541457
return strReglasMapeo.toString();
@@ -1380,19 +1483,24 @@ protected void openMaps() {
13801483
}
13811484

13821485
protected void openMaps(String reglas) {
1383-
MapeoDlg mapeoDlg=new MapeoDlg(null,reglas);
1486+
MapeoDlg mapeoDlg=new MapeoDlg(null,reglas,confMapeoFicheroParaFecha,confMapeoFicheroParaCommitId,confMapeoCommitIdExpresion,confMapeoCommitIdExpresionGroup);
13841487
boolean aceptado=mapeoDlg.showDialog();
13851488
String respuestaReglas="";
13861489
if (aceptado) {
1387-
respuestaReglas=mapeoDlg.getReglasMapeo();
1388-
respuestaReglas=StringUtils.replace(respuestaReglas, "\\", "/");
13891490
try {
1390-
reglasMapeo=listReglasMapeo(respuestaReglas);
1491+
MapeoInfo mapeoInfo=mapeoDlg.getReglasMapeo();
1492+
confMapeoFicheroParaFecha=mapeoInfo.ficheroParaFecha;
1493+
confMapeoFicheroParaCommitId=mapeoInfo.ficheroParaCommitId;
1494+
confMapeoCommitIdExpresion=mapeoInfo.commitIdExpresion;
1495+
confMapeoCommitIdExpresionGroup=mapeoInfo.commitIdExpresionGroup;
1496+
respuestaReglas=mapeoInfo.reglasMapeo;
1497+
respuestaReglas=StringUtils.replace(respuestaReglas, "\\", "/");
1498+
confMapeoReglasMapeo=listReglasMapeo(respuestaReglas);
13911499
} catch (Exception r) {
13921500
showMessage(""+r);
13931501
openMaps(respuestaReglas);
1394-
13951502
}
1503+
refreshMapeoData();
13961504
}
13971505
}
13981506

@@ -1658,8 +1766,9 @@ private JPanel getPanelAccionesSeleccion() {
16581766
panelAccionesSeleccion.setLayout(new FlowLayout(FlowLayout.LEADING, 2, 0));
16591767
panelAccionesSeleccion.add(getBtnCompareVsGit());
16601768
panelAccionesSeleccion.add(getBtnComparebase());
1661-
panelAccionesSeleccion.add(getBtnCopy());
16621769
panelAccionesSeleccion.add(getBtnCompG());
1770+
panelAccionesSeleccion.add(getLblNewLabel_1());
1771+
panelAccionesSeleccion.add(getBtnCopy());
16631772
}
16641773
return panelAccionesSeleccion;
16651774
}
@@ -2144,4 +2253,10 @@ private JTextField getTextOptionBranch() {
21442253
}
21452254
return textOptionBranch;
21462255
}
2256+
private JLabel getLblNewLabel_1() {
2257+
if (lblNewLabel_1 == null) {
2258+
lblNewLabel_1 = new JLabel("-");
2259+
}
2260+
return lblNewLabel_1;
2261+
}
21472262
}

0 commit comments

Comments
 (0)