36
36
import java .util .Properties ;
37
37
import java .util .StringTokenizer ;
38
38
import java .util .concurrent .Executors ;
39
+ import java .util .regex .Matcher ;
40
+ import java .util .regex .Pattern ;
39
41
40
42
import javax .swing .BoxLayout ;
41
43
import javax .swing .ComboBoxModel ;
71
73
import org .bcjj .gitCompare .GitFileVersionInfo ;
72
74
import org .bcjj .gitCompare .GitRepo ;
73
75
import org .bcjj .gitCompare .gui .ComboUtil .ComboName ;
76
+ import org .bcjj .gitCompare .gui .MapeoDlg .MapeoInfo ;
74
77
75
78
import net .iharder .dnd .FileDrop ;
76
79
import java .awt .Font ;
77
80
import javax .swing .JComboBox ;
78
81
import javax .swing .JCheckBox ;
82
+ import java .awt .Toolkit ;
79
83
80
84
// obtener el commit de una fecha git rev-list -1 --before="$DATE" master
81
85
/*
@@ -196,7 +200,12 @@ public class GitCompareMainWindow implements ContenedorHistorico {
196
200
private JButton btnSave ;
197
201
private String compareCommand ;
198
202
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
+
200
209
private JPanel panel_8 ;
201
210
private JTextField commitInfo ;
202
211
private JPanel panelBrachName ;
@@ -239,6 +248,7 @@ public class GitCompareMainWindow implements ContenedorHistorico {
239
248
private JPanel panelGitOptionBranch ;
240
249
private JLabel lblOptionBranch ;
241
250
private JTextField textOptionBranch ;
251
+ private JLabel lblNewLabel_1 ;
242
252
243
253
244
254
/**
@@ -309,6 +319,7 @@ protected ImageIcon createImageIcon(String path) {
309
319
*/
310
320
private void initialize () {
311
321
frmGitcompare = new JFrame ();
322
+ frmGitcompare .setIconImage (Toolkit .getDefaultToolkit ().getImage (GitCompareMainWindow .class .getResource ("/images/arrow-divide2.png" )));
312
323
frmGitcompare .setTitle ("GitCompare" );
313
324
frmGitcompare .setBounds (100 , 100 , 920 , 572 );
314
325
frmGitcompare .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
@@ -399,19 +410,28 @@ private void openProject() throws IOException {
399
410
}
400
411
Properties p =new Properties ();
401
412
InputStream r =null ;
402
- reglasMapeo =new ArrayList <String >();
413
+ confMapeoReglasMapeo =new ArrayList <String >();
403
414
try {
404
415
r =new FileInputStream (filenameValue );
405
416
p .load (r );
406
417
String branchName =p .getProperty ("branchName" );
407
418
getTextOptionBranch ().setText (branchName );
408
419
getTxtFilesDir ().setText (p .getProperty ("filesDir" ));
409
420
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 ();
411
431
for (int i =0 ;i <1000 ;i ++) {
412
432
String x =p .getProperty ("path." +i );
413
433
if (x !=null ) {
414
- reglasMapeo .add (x );
434
+ confMapeoReglasMapeo .add (x );
415
435
}
416
436
}
417
437
} catch (Exception e ) {
@@ -429,14 +449,88 @@ private void openProject() throws IOException {
429
449
}
430
450
431
451
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
+
432
518
protected void saveMaps () throws IOException {
433
519
String filenameValue =getProjectFile ();
434
520
Properties p =new Properties ();
435
521
p .setProperty ("branchName" , getTextOptionBranch ().getText ());
436
522
p .setProperty ("filesDir" , getTxtFilesDir ().getText ());
437
523
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
+
438
532
int i =0 ;
439
- for (String r :reglasMapeo ) {
533
+ for (String r :confMapeoReglasMapeo ) {
440
534
p .setProperty ("path." +i , r );
441
535
i ++;
442
536
}
@@ -585,6 +679,13 @@ public int compare(File f1, File f2) {
585
679
String fileAbsMapeado =mapearReglas (fileAbs ); // src/web/web-prod/srv/main.jsp
586
680
if (fileAbsMapeado !="!" ) {
587
681
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
+
588
689
FileVsGit fileVsGit =new FileVsGit (fich ,gitRepo ,fileAbsMapeado ,borrar ,tempF );
589
690
if (fileAbsMapeado .contains ("codigo.java" )) {
590
691
System .out .println (fileAbsMapeado );
@@ -601,10 +702,12 @@ public int compare(File f1, File f2) {
601
702
for (GitFileVersionInfo version :versionesRev ) {
602
703
i ++;
603
704
String numVer = String .format ("%03d" , i );
705
+
604
706
String tempFile =tempDirectoy +fileAbsMapeado +"--" +numVer +"--" +version .getCommitId ().substring (0 , 6 )+"--" +version .getFechaComprimidaYMDHMS ();
605
707
if (version .isBase ()) {
606
708
tempFile =tempFile +"-base" ;
607
709
}
710
+ tempFile =tempFile +ext ;
608
711
version .setTempFile (new File (tempFile ));
609
712
}
610
713
@@ -667,10 +770,10 @@ private String trimPathSymbol(String exp) {
667
770
668
771
private String mapearReglas (String fileAbs ) { //como baseDirAbsolute termina forzosamente por /, fileAbs no comenzará por /
669
772
fileAbs =StringUtils .replace (fileAbs , "\\ " , "/" );
670
- if (reglasMapeo ==null ) {
773
+ if (confMapeoReglasMapeo ==null ) {
671
774
return fileAbs ;
672
775
}
673
- for (String s :reglasMapeo ) {
776
+ for (String s :confMapeoReglasMapeo ) {
674
777
StringTokenizer st =new StringTokenizer (s ,"|" );
675
778
String buscar =trimPathSymbol (st .nextToken ())+"/" ;
676
779
String mapear =trimPathSymbol (st .nextToken ())+"/" ;
@@ -1348,7 +1451,7 @@ public void actionPerformed(ActionEvent e) {
1348
1451
1349
1452
protected String getReglasMapeoAsString () {
1350
1453
StringBuilder strReglasMapeo =new StringBuilder ();
1351
- for (String r :reglasMapeo ) {
1454
+ for (String r :confMapeoReglasMapeo ) {
1352
1455
strReglasMapeo .append (r ).append ("\r \n " );
1353
1456
}
1354
1457
return strReglasMapeo .toString ();
@@ -1380,19 +1483,24 @@ protected void openMaps() {
1380
1483
}
1381
1484
1382
1485
protected void openMaps (String reglas ) {
1383
- MapeoDlg mapeoDlg =new MapeoDlg (null ,reglas );
1486
+ MapeoDlg mapeoDlg =new MapeoDlg (null ,reglas , confMapeoFicheroParaFecha , confMapeoFicheroParaCommitId , confMapeoCommitIdExpresion , confMapeoCommitIdExpresionGroup );
1384
1487
boolean aceptado =mapeoDlg .showDialog ();
1385
1488
String respuestaReglas ="" ;
1386
1489
if (aceptado ) {
1387
- respuestaReglas =mapeoDlg .getReglasMapeo ();
1388
- respuestaReglas =StringUtils .replace (respuestaReglas , "\\ " , "/" );
1389
1490
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 );
1391
1499
} catch (Exception r ) {
1392
1500
showMessage ("" +r );
1393
1501
openMaps (respuestaReglas );
1394
-
1395
1502
}
1503
+ refreshMapeoData ();
1396
1504
}
1397
1505
}
1398
1506
@@ -1658,8 +1766,9 @@ private JPanel getPanelAccionesSeleccion() {
1658
1766
panelAccionesSeleccion .setLayout (new FlowLayout (FlowLayout .LEADING , 2 , 0 ));
1659
1767
panelAccionesSeleccion .add (getBtnCompareVsGit ());
1660
1768
panelAccionesSeleccion .add (getBtnComparebase ());
1661
- panelAccionesSeleccion .add (getBtnCopy ());
1662
1769
panelAccionesSeleccion .add (getBtnCompG ());
1770
+ panelAccionesSeleccion .add (getLblNewLabel_1 ());
1771
+ panelAccionesSeleccion .add (getBtnCopy ());
1663
1772
}
1664
1773
return panelAccionesSeleccion ;
1665
1774
}
@@ -2144,4 +2253,10 @@ private JTextField getTextOptionBranch() {
2144
2253
}
2145
2254
return textOptionBranch ;
2146
2255
}
2256
+ private JLabel getLblNewLabel_1 () {
2257
+ if (lblNewLabel_1 == null ) {
2258
+ lblNewLabel_1 = new JLabel ("-" );
2259
+ }
2260
+ return lblNewLabel_1 ;
2261
+ }
2147
2262
}
0 commit comments