Author: rfelden
Date: Wed Jun 13 16:15:33 2007
New Revision: 58
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D58&repname=3D=
jahia_upgrade
Log:
fix applier : properties merge on its way...
Modified:
trunk/apply/fixapplier/pom.xml
trunk/apply/fixapplier/src/main/java/org/jahia/fixapplier/controller/My=
Controller.java
trunk/apply/utils/pom.xml
trunk/apply/utils/src/main/java/org/jahia/utils/configuration/Merger.ja=
va
trunk/create/tools/src/main/java/org/jahia/tools/FolderZipper.java
trunk/linecounter/src/main/java/linecounter/LineCounter.java
Modified: trunk/apply/fixapplier/pom.xml
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/apply/fixapplie=
r/pom.xml&rev=3D58&repname=3Djahia_upgrade
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=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/apply/fixapplier/pom.xml (original)
+++ trunk/apply/fixapplier/pom.xml Wed Jun 13 16:15:33 2007
@@ -69,7 +69,7 @@
=
<dependencies>
=
- <dependency>
+ <dependency>
<groupId>org.jahia</groupId>
<artifactId>utils</artifactId>
<version>1.0</version>
Modified: trunk/apply/fixapplier/src/main/java/org/jahia/fixapplier/control=
ler/MyController.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/apply/fixapplie=
r/src/main/java/org/jahia/fixapplier/controller/MyController.java&rev=3D58&=
repname=3Djahia_upgrade
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=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/apply/fixapplier/src/main/java/org/jahia/fixapplier/controller/My=
Controller.java (original)
+++ trunk/apply/fixapplier/src/main/java/org/jahia/fixapplier/controller/My=
Controller.java Wed Jun 13 16:15:33 2007
@@ -8,6 +8,7 @@
import org.jahia.fixapplier.views.ViewAdapter;
import org.jahia.fixapplier.views.gui.MainWindow;
import org.jahia.utils.StringUtils;
+import org.jahia.utils.configuration.Merger;
import org.jahia.utils.appcast.MyAppcastHandler;
import org.jahia.utils.appcast.Appcast;
import org.jahia.utils.appcast.AppcastItem;
@@ -523,11 +524,17 @@
replaceFile(files[i]) ;
}
=
- // file processing TODO text merge
+ // file processing
} else {
+ if (neu.getName().endsWith(".old")) {
+ return ;
+ }
String targetPath =3D StringUtils.replaceFirstToken(neu.getAbs=
olutePath(), dataModel.temp().getAbsolutePath() + File.separator + "output"=
, dataModel.getProject().getAbsolutePath()) ;
File destination =3D new File(targetPath) ;
+
+ // this is the text merge
checkConfiguration(neu, destination) ;
+ =
File parentPath =3D destination.getParentFile() ;
parentPath.mkdirs() ;
Tools.copy(neu, destination) ;
@@ -545,7 +552,7 @@
* @param update the update file
* @param existing the file to update (not always existing)
*/
- private void checkConfiguration(File update, final File existing) {
+ private void checkConfiguration(File update, File existing) {
// if this does not concern configuration, abort
if (!(update.getName().endsWith(".properties") ||
update.getName().endsWith(".xml") ||
@@ -563,8 +570,11 @@
return ;
}
=
-
// now the hard part TODO OOO OOO
+ File old =3D new File(update.getParentFile(), update.getName()+".o=
ld") ;
+ if (Merger.mergeConfiguration(update, old, existing)) {
+ out("configuration merging for the file '"+update.getName()+"'=
encountered issues");
+ }
=
}
=
Modified: trunk/apply/utils/pom.xml
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/apply/utils/pom=
.xml&rev=3D58&repname=3Djahia_upgrade
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=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/apply/utils/pom.xml (original)
+++ trunk/apply/utils/pom.xml Wed Jun 13 16:15:33 2007
@@ -36,6 +36,14 @@
</build>
=
<dependencies>
+
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.4</version>
+ <scope>compile</scope>
+ </dependency>
+
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
Modified: trunk/apply/utils/src/main/java/org/jahia/utils/configuration/Mer=
ger.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/apply/utils/src=
/main/java/org/jahia/utils/configuration/Merger.java&rev=3D58&repname=3Djah=
ia_upgrade
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=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/apply/utils/src/main/java/org/jahia/utils/configuration/Merger.ja=
va (original)
+++ trunk/apply/utils/src/main/java/org/jahia/utils/configuration/Merger.ja=
va Wed Jun 13 16:15:33 2007
@@ -1,12 +1,102 @@
package org.jahia.utils.configuration;
=
+import org.apache.commons.configuration.*;
+import org.apache.commons.configuration.plist.PropertyListConfiguration;
+
+import java.io.File;
+import java.util.Iterator;
+
/**
* This is the configuration merger.
- * TODO OOO OOO
*
* @author Romain Felden
* @version 2007-06-12
*/
public class Merger {
=
+ /**
+ * This static method uses three files to determine which merging has =
to be done
+ * in order to crete a hybrid configuration file.
+ * It works with XML, .properties and .plist files.
+ *
+ * @param update the file that will be used to patch (will be modified=
if needed)
+ * @param old the standard previous version file
+ * @param existing the existing file
+ * @return true if the merging happened, false otherwise
+ */
+ public static boolean mergeConfiguration(final File update, final File=
old, final File existing) {
+ // check the files first
+ if (update =3D=3D null || !update.exists() ||
+ existing =3D=3D null || !existing.exists() ||
+ old =3D=3D null || !old.exists()) {
+ return false ;
+ }
+
+ FileConfiguration updateConfiguration =3D null ;
+ Configuration updateConfigCopy =3D null ;
+ Configuration oldConfiguration =3D null ;
+ Configuration existingConfiguration =3D null ;
+
+ try {
+ // load the configurations from the files
+
+ if (update.getName().endsWith(".properties")) {
+ updateConfiguration =3D new PropertiesConfiguration(update=
) ;
+ updateConfigCopy =3D new PropertiesConfiguration(update) ;
+ oldConfiguration =3D new PropertiesConfiguration(old) ;
+ existingConfiguration =3D new PropertiesConfiguration(exis=
ting) ;
+ }
+ // not yet functional
+ /*else if (update.getName().endsWith(".xml")) {
+ updateConfiguration =3D new XMLConfiguration(update) ;
+ updateConfigCopy =3D new XMLConfiguration(update) ;
+ oldConfiguration =3D new XMLConfiguration(old) ;
+ existingConfiguration =3D new XMLConfiguration(existing) ;
+ }*/
+ else if (update.getName().endsWith(".plist")) {
+ updateConfiguration =3D new PropertyListConfiguration(upda=
te) ;
+ updateConfigCopy =3D new PropertyListConfiguration(update)=
;
+ oldConfiguration =3D new PropertyListConfiguration(old) ;
+ existingConfiguration =3D new PropertyListConfiguration(ex=
isting) ;
+ }
+
+ // unknown case
+ else {
+ return false ;
+ }
+
+ // set all the properties
+ Iterator it =3D updateConfigCopy.getKeys() ;
+ while (it.hasNext()) {
+ String key =3D it.next().toString() ;
+ Object updateValue =3D updateConfiguration.getProperty(key=
) ;
+ Object oldValue =3D oldConfiguration.getProperty(key) ;
+ Object existingValue =3D existingConfiguration.getProperty=
(key) ;
+
+ // if the key did not exist previously, neither in the ori=
ginal version
+ // nor at the client's, skip this property
+ // (the update value will be used)
+ if (oldValue =3D=3D null || existingValue =3D=3D null) {
+ }
+
+ // if the new value has not changed since last version,
+ // either keep the existing one if it exists, or leave it
+ // untouched in the updateConfiguration
+ else if (oldValue.equals(updateValue) && !existingValue.eq=
uals("")) {
+ updateConfiguration.setProperty(key, existingValue);
+ }
+ }
+
+ // save the data into the updater file
+ updateConfiguration.save(update) ;
+ } catch (ConfigurationException e) {
+ e.printStackTrace();
+ return false ;
+ } catch (NullPointerException npe) {
+ npe.printStackTrace() ;
+ }
+ return true ;
+
+ }
+
}
Modified: trunk/create/tools/src/main/java/org/jahia/tools/FolderZipper.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/create/tools/sr=
c/main/java/org/jahia/tools/FolderZipper.java&rev=3D58&repname=3Djahia_upgr=
ade
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=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/create/tools/src/main/java/org/jahia/tools/FolderZipper.java (ori=
ginal)
+++ trunk/create/tools/src/main/java/org/jahia/tools/FolderZipper.java Wed =
Jun 13 16:15:33 2007
@@ -127,6 +127,7 @@
while ((len =3D in.read(buf)) > 0) {
zip.write(buf, 0, len);
}
+ in.close() ;
}
catch (Exception ex){
ex.printStackTrace();
Modified: trunk/linecounter/src/main/java/linecounter/LineCounter.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/linecounter/src=
/main/java/linecounter/LineCounter.java&rev=3D58&repname=3Djahia_upgrade
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=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/linecounter/src/main/java/linecounter/LineCounter.java (original)
+++ trunk/linecounter/src/main/java/linecounter/LineCounter.java Wed Jun 13=
16:15:33 2007
@@ -12,21 +12,21 @@
public class LineCounter {
public static void main(String[] args) {
long total =3D 0 ;
- for (int i =3D 0; i < args.length; i++) {
- File file =3D new File(args[i]) ;
+ for (String arg : args) {
+ File file =3D new File(arg);
if (!file.exists()) {
- System.err.println("This is not a valid file name, retry u=
sing the absolute path.") ;
+ System.err.println("\n" + arg + " is not a valid file name=
, retry using the absolute path.");
} else {
try {
- long time =3D System.currentTimeMillis() ;
- System.out.println("\nAnalyzing "+file.getAbsolutePath=
()) ;
- long lines =3D countLinesRec(file, false) ;
- total +=3D lines ;
- System.out.println("\nThis contains " + lines + " line=
s") ;
- System.out.println("(calculated in " + (System.current=
TimeMillis() - time) + " ms)") ;
+ long time =3D System.currentTimeMillis();
+ System.out.println("\nAnalyzing " + file.getAbsolutePa=
th());
+ long lines =3D countLinesRec(file, false);
+ total +=3D lines;
+ System.out.println("\nThis contains " + lines + " line=
s");
+ System.out.println("(calculated in " + (System.current=
TimeMillis() - time) + " ms)");
} catch (IOException e) {
- System.err.println("\nAn error occurred!") ;
- e.printStackTrace() ;
+ System.err.println("\nAn error occurred!");
+ e.printStackTrace();
}
}
}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list