Index: org/hibernate/tool/hbm2x/AbstractExporter.java =================================================================== --- org/hibernate/tool/hbm2x/AbstractExporter.java (revision 16604) +++ org/hibernate/tool/hbm2x/AbstractExporter.java (working copy) @@ -30,6 +30,7 @@ private TemplateHelper vh; private Properties properties = new Properties(); private ArtifactCollector collector = new ArtifactCollector(); + private String mergeMethod = OVERWRITE; private Iterator iterator; @@ -254,4 +255,12 @@ public Cfg2JavaTool getCfg2JavaTool() { return c2j; } + + public void setMergeMethod(String mergeMethod){ + this.mergeMethod = mergeMethod; + } + + public String getMergeMethod(){ + return this.mergeMethod; + } } Index: org/hibernate/tool/hbm2x/DocExporter.java =================================================================== --- org/hibernate/tool/hbm2x/DocExporter.java (revision 16604) +++ org/hibernate/tool/hbm2x/DocExporter.java (working copy) @@ -610,7 +610,7 @@ protected void processTemplate(Map parameters, String templateName, File outputFile) { - TemplateProducer producer = new TemplateProducer(getTemplateHelper(), getArtifactCollector() ); + TemplateProducer producer = new TemplateProducer(getTemplateHelper(), getArtifactCollector(), getMergeMethod() ); producer.produce(parameters, templateName, outputFile, templateName); } Index: org/hibernate/tool/hbm2x/Exporter.java =================================================================== --- org/hibernate/tool/hbm2x/Exporter.java (revision 16604) +++ org/hibernate/tool/hbm2x/Exporter.java (working copy) @@ -13,6 +13,9 @@ * */ public interface Exporter { + + public static final String OVERWRITE = "overwrite"; + public static final String SKIP = "skip"; /** * @param cfg An Hibernate {@link org.hibernate.Configuration} or subclass instance that defines the hibernate meta model to be exported. @@ -60,4 +63,8 @@ */ public void start(); + public void setMergeMethod(String mergeMethod); + + public String getMergeMethod(); + } Index: org/hibernate/tool/hbm2x/GenericExporter.java =================================================================== --- org/hibernate/tool/hbm2x/GenericExporter.java (revision 16604) +++ org/hibernate/tool/hbm2x/GenericExporter.java (working copy) @@ -27,7 +27,7 @@ modelIterators.put( "configuration", new ModelIterator() { void process(GenericExporter ge) { - TemplateProducer producer = new TemplateProducer(ge.getTemplateHelper(),ge.getArtifactCollector()); + TemplateProducer producer = new TemplateProducer(ge.getTemplateHelper(),ge.getArtifactCollector(), ge.getMergeMethod()); producer.produce(new HashMap(), ge.getTemplateName(), new File(ge.getOutputDirectory(),ge.filePattern), ge.templateName, "Configuration"); } @@ -138,7 +138,7 @@ } protected void exportPOJO(Map additionalContext, POJOClass element) { - TemplateProducer producer = new TemplateProducer(getTemplateHelper(),getArtifactCollector()); + TemplateProducer producer = new TemplateProducer(getTemplateHelper(),getArtifactCollector(), getMergeMethod()); additionalContext.put("pojo", element); additionalContext.put("clazz", element.getDecoratedObject()); String filename = resolveFilename( element ); Index: org/hibernate/tool/hbm2x/HibernateMappingExporter.java =================================================================== --- org/hibernate/tool/hbm2x/HibernateMappingExporter.java (revision 16604) +++ org/hibernate/tool/hbm2x/HibernateMappingExporter.java (working copy) @@ -38,7 +38,7 @@ Cfg2HbmTool c2h = getCfg2HbmTool(); Configuration cfg = getConfiguration(); if(c2h.isImportData(cfg) && (c2h.isNamedQueries(cfg)) && (c2h.isNamedSQLQueries(cfg)) && (c2h.isFilterDefinitions(cfg))) { - TemplateProducer producer = new TemplateProducer(getTemplateHelper(),getArtifactCollector()); + TemplateProducer producer = new TemplateProducer(getTemplateHelper(),getArtifactCollector(), getMergeMethod()); producer.produce(new HashMap(), "hbm/generalhbm.hbm.ftl", new File(getOutputDirectory(),"GeneralHbmSettings.hbm.xml"), getTemplateName(), "General Settings"); } } Index: org/hibernate/tool/hbm2x/TemplateProducer.java =================================================================== --- org/hibernate/tool/hbm2x/TemplateProducer.java (revision 16604) +++ org/hibernate/tool/hbm2x/TemplateProducer.java (working copy) @@ -17,13 +17,22 @@ private static final Log log = LogFactory.getLog(TemplateProducer.class); private final TemplateHelper th; private ArtifactCollector ac; + private String mergeMethod; - public TemplateProducer(TemplateHelper th, ArtifactCollector ac) { + /*public TemplateProducer(TemplateHelper th, ArtifactCollector ac) { + this(th, ac, Exporter.OVERWRITE); + }*/ + + public TemplateProducer(TemplateHelper th, ArtifactCollector ac, String mergeMethod) { this.th = th; this.ac = ac; + this.mergeMethod = mergeMethod; } public void produce(Map additionalContext, String templateName, File destination, String identifier, String fileType, String rootContext) { + if (Exporter.SKIP.equalsIgnoreCase(mergeMethod) && destination.exists()){ + log.warn("Skipped creation for file " + destination + " as the file already exists."); + } String tempResult = produceToString( additionalContext, templateName, rootContext );