r1192 - in trunk: wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin
Author: mfortun Date: 2011-08-28 16:33:49 +0200 (Sun, 28 Aug 2011) New Revision: 1192 Url: http://nuiton.org/repositories/revision/wikitty/1192 Log: * correct synchronise to save wikitty service targeted only if needed *add a new goal that clean properties dir created by wikitty service over file system Added: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPCleanMojo.java Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java 2011-08-26 17:48:28 UTC (rev 1191) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java 2011-08-28 14:33:49 UTC (rev 1192) @@ -65,7 +65,8 @@ public class WikittyPublicationSynchronize { /** to use log facility, just put in your code: log.info(\"...\"); */ - final static private Log log = LogFactory.getLog(WikittyPublicationSynchronize.class); + final static private Log log = LogFactory + .getLog(WikittyPublicationSynchronize.class); /** * Key for the other uri, usefull in the case of commit/update with a file @@ -117,21 +118,18 @@ */ static public String HESSIAN_URI_PREFIX = "hessian"; - /** * The file name of the wikitty service property */ static public String WIKITTY_FILE_SERVICE = "ws.properties"; - + /* - * Two flag for commit/update mechanism - * if main true and flag commit false and if service is servive over - * file system, so write property to "know" the last service used to - * synchronise + * Two flag for commit/update mechanism if main true and flag commit false + * and if service is servive over file system, so write property to "know" + * the last service used to synchronise */ - static protected boolean MAIN_ENABLE=false; - static protected boolean FLAG_COMMIT_UPDATE=false; - + static protected boolean MAIN_ENABLE = false; + static protected boolean FLAG_COMMIT_UPDATE = false; static { applicationConfig = new ApplicationConfig(); @@ -141,7 +139,7 @@ * correct encoding */ FileUtil.ENCODING = "UTF-8"; - + /* * TODO mfortun-2011-04-14 construct option def instance to initialize * correctly application config @@ -181,7 +179,6 @@ "org.nuiton.wikitty.publication.synchro.WikittyPublication#update"); } - /* * Class don't have to be instantiate */ @@ -195,13 +192,13 @@ */ static public void main(String[] args) throws Exception { MAIN_ENABLE = true; - + // parsing applicationConfig.parse(args); // execution applicationConfig.doAction(0); } - + static public void synchronisation(String origin, String target) throws URISyntaxException { @@ -215,13 +212,11 @@ synchronisationServices(origin, target, isRecur, isDelete, isExisting); } - - + static public void synchronisationServices(String origin, String target, boolean isRecur, boolean isDelete, boolean isExisting) throws URISyntaxException { - // update operation is the default operation boolean isUpdate = !isDelete && !isExisting; @@ -509,8 +504,7 @@ WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS .getKey(), WikittyPublicationFileSystem.class .getName()); - - + writeProperty(url); } else if (uri.getScheme().equals(CAJO_URI_PREFIX)) { result.setOption( @@ -569,9 +563,9 @@ static protected void commitUpdateDelegate(String label, boolean isCommit, String... uriFileSystem) throws Exception { - + FLAG_COMMIT_UPDATE = true; - + File currentDir = new File(FileUtil.getCurrentDirectory() .getAbsolutePath()); @@ -659,7 +653,7 @@ File workingDir = new File(originUri.getPath()); homeProperty = WikittyPublicationFileSystem .getWikittyPublicationProperties(workingDir, - WIKITTY_FILE_SERVICE); + WIKITTY_FILE_SERVICE); wikittyServiceInter = (String) homeProperty .get(WIKITTY_SERVICE_INTERLOCUTEUR); @@ -715,71 +709,74 @@ + "''wp [update|commit] [--norecursion] [--delete|--existing] [URI file]''"; System.out.println(usage); } - - + /** - * Called when syncrhonising with file system, used to store info about - * the "other" service used. Infos used when try to commit - * update from a service over file system + * Called when syncrhonising with file system, used to store info about the + * "other" service used. Infos used when try to commit update from a service + * over file system + * * @param label */ protected static void writeProperty(String ur) { - try { - URI uri = new URI(ur); - String label = uri.getFragment(); - - File homeFile = new File(uri.getPath()); - - - File homeProperty = new File(homeFile.getAbsolutePath() - + File.separator - + WikittyPublicationFileSystem.PROPERTY_DIRECTORY); - if (!homeProperty.exists()) { - homeProperty.mkdir(); - } + // Only if not commit/update and syncrhonising from main + if (!FLAG_COMMIT_UPDATE && MAIN_ENABLE) { + try { + URI uri = new URI(ur); + String label = uri.getFragment(); - // write/update the "home property file" - PropertiesExtended propertyWikittyService; - - propertyWikittyService = WikittyPublicationFileSystem - .getWikittyPublicationProperties(homeFile, - WIKITTY_FILE_SERVICE); + File homeFile = new File(uri.getPath()); - // the original label use to create if not exist - if (!propertyWikittyService - .containsKey(WikittyPublicationSynchronize.LABEL_KEY)) { - log.debug("Writing home property label" - + propertyWikittyService.getOrigin()); - propertyWikittyService.setProperty( - WikittyPublicationSynchronize.LABEL_KEY, label); - } - // the service use to update or commit - String uriService = applicationConfig - .getOption(WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR); - if (uriService != null) { - log.debug("Writing home property service on:" - + propertyWikittyService.getOrigin() + " uri" - + uriService); + File homeProperty = new File(homeFile.getAbsolutePath() + + File.separator + + WikittyPublicationFileSystem.PROPERTY_DIRECTORY); - propertyWikittyService - .setProperty( - WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR, - uriService); - } + if (!homeProperty.exists()) { + homeProperty.mkdir(); + } - propertyWikittyService.store(); + // write/update the "home property file" + PropertiesExtended propertyWikittyService; - } catch (Exception e) { - //TODO mfortun-2011-08-25 - if (log.isErrorEnabled()) { - log.error("Error while writing properties for commit update", e); + propertyWikittyService = WikittyPublicationFileSystem + .getWikittyPublicationProperties(homeFile, + WIKITTY_FILE_SERVICE); + + // the original label use to create if not exist + if (!propertyWikittyService + .containsKey(WikittyPublicationSynchronize.LABEL_KEY)) { + log.debug("Writing home property label" + + propertyWikittyService.getOrigin()); + propertyWikittyService.setProperty( + WikittyPublicationSynchronize.LABEL_KEY, label); + } + // the service use to update or commit + String uriService = applicationConfig + .getOption(WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR); + if (uriService != null) { + log.debug("Writing home property service on:" + + propertyWikittyService.getOrigin() + " uri" + + uriService); + + propertyWikittyService + .setProperty( + WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR, + uriService); + } + + propertyWikittyService.store(); + + } catch (Exception e) { + // TODO mfortun-2011-08-25 + if (log.isErrorEnabled()) { + log.error( + "Error while writing properties for commit update", + e); + } } } - } - - + /** * Use to search and return the home property that containt informations * about wikitty service use to synchronise a wikitty publication file @@ -803,7 +800,8 @@ // adress of the interlocuteur File propertyDirectory = new File(start.getCanonicalPath() - + File.separator + WikittyPublicationFileSystem.PROPERTY_DIRECTORY); + + File.separator + + WikittyPublicationFileSystem.PROPERTY_DIRECTORY); if (propertyDirectory.exists()) { File propertie = new File(propertyDirectory.getCanonicalPath() Added: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPCleanMojo.java =================================================================== --- trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPCleanMojo.java (rev 0) +++ trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPCleanMojo.java 2011-08-28 14:33:49 UTC (rev 1192) @@ -0,0 +1,57 @@ +package org.nuiton.wikitty.plugin; + +import java.io.File; +import java.io.FileFilter; +import java.util.List; + +import org.nuiton.util.FileUtil; +import org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem; + +/** + * Goal to remove properties files used by WikittyService over file system to + * ensure transformation wikitty-file. Delete ".wp" dirs. + * + * @author mfortun <manoel.fortun@gmail.com> + * @version + * @goal clean + * @requiresProject true + * @requiresOnline true + * @requiresDependencyResolution runtime + * @since 3.2 + */ +public class WPCleanMojo extends AbstractWPMojo { + + protected FileFilter propertiesDirFilter = new FileFilter() { + + @Override + public boolean accept(File pathname) { + return pathname.isDirectory() + && pathname.getName().equals( + WikittyPublicationFileSystem.PROPERTY_DIRECTORY); + + } + }; + + @Override + protected void init() throws Exception { + + } + + @Override + protected void doAction() throws Exception { + + File baseDir = project.getBasedir(); + // filter all properties dir + List<File> propertiesDir = FileUtil.getFilteredElements(baseDir, + propertiesDirFilter, true); + // delete them + for (File fipropsdir : propertiesDir) { + if (getLog().isDebugEnabled()) { + getLog().debug("Delete dir:" + fipropsdir); + } + FileUtil.deleteRecursively(fipropsdir); + } + + } + +}
participants (1)
-
mfortun@users.nuiton.org