Author: rfelden
Date: Mon Aug  6 16:56:49 2007
New Revision: 14

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D14&repname=3D=
fix_apply
Log:
added replaced files automatic backup

Modified:
    trunk/fixapplier/src/main/java/org/jahia/fixapplier/controller/MyContro=
ller.java
    trunk/fixapplier/src/main/java/org/jahia/fixapplier/model/MyDataModel.j=
ava
    trunk/fixapplier/src/main/java/org/jahia/fixapplier/views/gui/Preferenc=
es.form
    trunk/fixapplier/src/main/java/org/jahia/fixapplier/views/gui/Preferenc=
es.java
    trunk/fixapplier/src/main/resources/org/jahia/fixapplier/views/gui/gui.=
properties

Modified: trunk/fixapplier/src/main/java/org/jahia/fixapplier/controller/My=
Controller.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/fixapplier/src/=
main/java/org/jahia/fixapplier/controller/MyController.java&rev=3D14&repnam=
e=3Dfix_apply
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/fixapplier/src/main/java/org/jahia/fixapplier/controller/MyContro=
ller.java (original)
+++ trunk/fixapplier/src/main/java/org/jahia/fixapplier/controller/MyContro=
ller.java Mon Aug  6 16:56:49 2007
@@ -38,6 +38,7 @@
     private Properties settings ;
 =

     private PrintStream logStream ;
+    private File backupFolder ;
 =

     /**
      * Constructor, first call of the application.
@@ -354,6 +355,20 @@
     }
 =

     /**
+     * Set the backup folder.
+     *
+     * @param backup the backup folder location as a file
+     */
+    public void setBackupFolder(File backup) {
+        if (backup =3D=3D null || !backup.exists() || backup.isFile()) {
+            printUI("invalid project location");
+        } else {
+            dataModel.setBackup(backup);
+            settings.setProperty("project.backup", backup.getAbsolutePath(=
)) ;
+        }
+    }
+
+    /**
      * Get the current project location as a String (path).
      *
      * @return the absolute path to the project
@@ -368,6 +383,20 @@
     }
 =

     /**
+     * Get the folder used for backuping replaced files.
+     *
+     * @return the folder absolute path
+     */
+    public String getBackupFolder() {
+        File project =3D dataModel.getProject() ;
+        if (project =3D=3D null) {
+            return "" ;
+        } else {
+            return project.getAbsolutePath() ;
+        }
+    }
+
+    /**
      * Get fix information once unzipped.
      */
     public void getFixInfo() {
@@ -555,6 +584,9 @@
             String targetPath =3D StringUtils.replaceFirstToken(neu.getAbs=
olutePath(), dataModel.temp().getAbsolutePath() + File.separator + "output"=
, dataModel.getProject().getAbsolutePath()) ;
             File destination =3D new File(targetPath) ;
 =

+            // backup copy
+            backup(destination) ;
+
             // this is the text merge
             checkConfiguration(neu, destination) ;
             =

@@ -584,6 +616,30 @@
     }
 =

     /**
+     * Back up the replaced file.
+     *
+     * @param destination the file to replace
+     */
+    private void backup(File destination) {
+        // backup if the file already exists
+        if (dataModel.getBackup() !=3D null && destination.exists()) {
+            if (!dataModel.getBackup().exists()) {
+                dataModel.getBackup().mkdirs() ;
+            }
+            if (backupFolder =3D=3D null) {
+                backupFolder =3D new File(dataModel.getBackup(), dataModel=
.getFix().getProjectName()+"_"+dataModel.getFix().getTarget()) ;
+            } else if (!backupFolder.getName().equals(dataModel.getFix().g=
etProjectName()+"_"+dataModel.getFix().getTarget())) {
+                backupFolder =3D new File(dataModel.getBackup(), dataModel=
.getFix().getProjectName()+"_"+dataModel.getFix().getTarget()) ;
+            }
+            if (!backupFolder.exists()) {
+                backupFolder.mkdirs() ;
+            }
+            File backupCopy =3D new File(backupFolder, destination.getName=
()) ;
+            Tools.copy(destination, backupCopy) ;
+        }
+    }
+
+    /**
      * This concerns the merge file merging. It checks a given update file=
 and its existing copy,
      * and modifies the processed file resulting from the smart merge betw=
een these two. To do so, it uses
      * the .old file that should be included if merging has to be done.

Modified: trunk/fixapplier/src/main/java/org/jahia/fixapplier/model/MyDataM=
odel.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/fixapplier/src/=
main/java/org/jahia/fixapplier/model/MyDataModel.java&rev=3D14&repname=3Dfi=
x_apply
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/fixapplier/src/main/java/org/jahia/fixapplier/model/MyDataModel.j=
ava (original)
+++ trunk/fixapplier/src/main/java/org/jahia/fixapplier/model/MyDataModel.j=
ava Mon Aug  6 16:56:49 2007
@@ -40,6 +40,7 @@
     private File temp ;
     private File archives ;
     private File home ;
+    private File backup ;
 =

 =

     public MyDataModel() {
@@ -118,6 +119,14 @@
         this.project =3D project;
     }
 =

+    public File getBackup() {
+        return backup;
+    }
+
+    public void setBackup(File backup) {
+        this.backup =3D backup;
+    }
+
     public void setAppcast(Appcast appcast) {
         this.appcast =3D appcast ;
     }

Modified: trunk/fixapplier/src/main/java/org/jahia/fixapplier/views/gui/Pre=
ferences.form
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/fixapplier/src/=
main/java/org/jahia/fixapplier/views/gui/Preferences.form&rev=3D14&repname=
=3Dfix_apply
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/fixapplier/src/main/java/org/jahia/fixapplier/views/gui/Preferenc=
es.form (original)
+++ trunk/fixapplier/src/main/java/org/jahia/fixapplier/views/gui/Preferenc=
es.form Mon Aug  6 16:56:49 2007
@@ -129,6 +129,26 @@
               <text value=3D""/>
             </properties>
           </component>
+          <component id=3D"e0787" class=3D"javax.swing.JLabel">
+            <constraints>
+              <grid row=3D"4" column=3D"0" row-span=3D"1" col-span=3D"1" v=
size-policy=3D"0" hsize-policy=3D"0" anchor=3D"4" fill=3D"0" indent=3D"0" u=
se-parent-layout=3D"false"/>
+              <gridbag top=3D"10" left=3D"5" bottom=3D"10" right=3D"5" wei=
ghtx=3D"0.1" weighty=3D"0.0"/>
+            </constraints>
+            <properties>
+              <text resource-bundle=3D"org/jahia/fixapplier/views/gui/gui"=
 key=3D"prefs.backup"/>
+            </properties>
+          </component>
+          <component id=3D"3f05b" class=3D"javax.swing.JTextField" binding=
=3D"backup">
+            <constraints>
+              <grid row=3D"4" column=3D"1" row-span=3D"1" col-span=3D"1" v=
size-policy=3D"0" hsize-policy=3D"6" anchor=3D"8" fill=3D"1" indent=3D"0" u=
se-parent-layout=3D"false">
+                <preferred-size width=3D"150" height=3D"-1"/>
+              </grid>
+              <gridbag top=3D"10" left=3D"5" bottom=3D"10" right=3D"10" we=
ightx=3D"1.0" weighty=3D"0.0"/>
+            </constraints>
+            <properties>
+              <text value=3D""/>
+            </properties>
+          </component>
         </children>
       </grid>
     </children>

Modified: trunk/fixapplier/src/main/java/org/jahia/fixapplier/views/gui/Pre=
ferences.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/fixapplier/src/=
main/java/org/jahia/fixapplier/views/gui/Preferences.java&rev=3D14&repname=
=3Dfix_apply
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/fixapplier/src/main/java/org/jahia/fixapplier/views/gui/Preferenc=
es.java (original)
+++ trunk/fixapplier/src/main/java/org/jahia/fixapplier/views/gui/Preferenc=
es.java Mon Aug  6 16:56:49 2007
@@ -17,6 +17,7 @@
     private JTextField appcast;
     private JCheckBox appcastDefault;
     private JCheckBox yesToAll;
+    private JTextField backup;
 =

     public Preferences(final MyController controller) {
         this.controller =3D controller;
@@ -38,6 +39,17 @@
             }
         });
 =

+        backup.addMouseListener(new MouseAdapter() {
+            public void mouseClicked(MouseEvent e) {
+                if (e.getClickCount() > 1) {
+                    File dir =3D GUITools.selectLocation(contentPane, Reso=
urceBundle.getBundle("org/jahia/fixapplier/views/gui/gui").getString("prefs=
.selectProject"), "", true);
+                    if (dir !=3D null) {
+                        backup.setText(dir.getAbsolutePath());
+                    }
+                }
+            }
+        });
+
         buttonOK.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 onOK();
@@ -72,6 +84,7 @@
         appcast.setText(controller.getAppcastURI());
         appcastDefault.setSelected(controller.isAppcastDefault());
         yesToAll.setSelected(controller.isYesToAll());
+        backup.setText(controller.getBackupFolder());
         setVisible(true);
     }
 =

@@ -80,6 +93,7 @@
         controller.setAppcastURI(appcast.getText());
         controller.setAppcastDefault(appcastDefault.isSelected());
         controller.setYesToAll(yesToAll.isSelected());
+        controller.setBackupFolder(new File(backup.getText())) ;
         dispose();
     }
 =


Modified: trunk/fixapplier/src/main/resources/org/jahia/fixapplier/views/gu=
i/gui.properties
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/fixapplier/src/=
main/resources/org/jahia/fixapplier/views/gui/gui.properties&rev=3D14&repna=
me=3Dfix_apply
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/fixapplier/src/main/resources/org/jahia/fixapplier/views/gui/gui.=
properties (original)
+++ trunk/fixapplier/src/main/resources/org/jahia/fixapplier/views/gui/gui.=
properties Mon Aug  6 16:56:49 2007
@@ -36,6 +36,9 @@
 prefs.selectProject =3D Select project location
 prefs.appcast =3D Appcast URI
 prefs.appcastDefault =3D Make appcast default
+prefs.yesToAll =3D <html>Always overwrite<P>existing properties<html>
+prefs.backup =3D Backup folder
+prefs.selectBackup =3D Select backup folder
 =

 historyOn.title =3D History on...
 historyOn.enterId =3D <html>Please enter the id of the fix you want inform=
ation about.<P>(filename without .zip extension)</html>
@@ -48,5 +51,3 @@
 =

 about.box.title =3D About Fix Applier
 about.box =3D Fix Applier version
-
-prefs.yesToAll =3D <html>Always overwrite<P>existing properties<html>
\ No newline at end of file

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to