Bug 491133 - Provide option to not include date in @Generated
Signed-off-by: David Kral <david.k.kral@oracle.com>
Reviewed-by: Lukas Jungmann <lukas.jungmann@oracle.com>
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/PersistenceUnitProperties.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/PersistenceUnitProperties.java
index 4456453..5051e58 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/PersistenceUnitProperties.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/PersistenceUnitProperties.java
@@ -1361,6 +1361,23 @@ public class PersistenceUnitProperties {
     public static final String CANONICAL_MODEL_USE_STATIC_FACTORY_DEFAULT = "true";
 
     /**
+     * The "<code>eclipselink.canonicalmodel.generate_timestamp</code>" optional property can be used
+     * to disable usage of date in declaration of {@link javax.annotation.Generated} annotation.
+     * The default value is true.
+     *
+     * @see #CANONICAL_MODEL_GENERATE_TIMESTAMP_DEFAULT
+     */
+    public static final String CANONICAL_MODEL_GENERATE_TIMESTAMP = "eclipselink.canonicalmodel.generate_timestamp";
+
+    /**
+     * Default value for the "<code>eclipselink.canonicalmodel.generate_timestamp</code>" optional
+     * property.
+     *
+     * @see #CANONICAL_MODEL_GENERATE_TIMESTAMP
+     */
+    public static final String CANONICAL_MODEL_GENERATE_TIMESTAMP_DEFAULT = "true";
+
+    /**
      * Default caching properties - apply to all entities. May be overridden by
      * individual entity property with the same prefix. If you do not wish to
      * cache your entities, set this to "<code>false</code>".
diff --git a/jpa/org.eclipse.persistence.jpa.modelgen/src/org/eclipse/persistence/internal/jpa/modelgen/CanonicalModelProcessor.java b/jpa/org.eclipse.persistence.jpa.modelgen/src/org/eclipse/persistence/internal/jpa/modelgen/CanonicalModelProcessor.java
index 35a656e..f409e47 100644
--- a/jpa/org.eclipse.persistence.jpa.modelgen/src/org/eclipse/persistence/internal/jpa/modelgen/CanonicalModelProcessor.java
+++ b/jpa/org.eclipse.persistence.jpa.modelgen/src/org/eclipse/persistence/internal/jpa/modelgen/CanonicalModelProcessor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016 Oracle and/or its affiliates. All rights reserved.
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
  * which accompanies this distribution.
@@ -25,8 +25,15 @@
  ******************************************************************************/
 package org.eclipse.persistence.internal.jpa.modelgen;
 
+import static org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties.CANONICAL_MODEL_PREFIX;
+import static org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties.CANONICAL_MODEL_SUFFIX;
+import static org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties.CANONICAL_MODEL_SUB_PACKAGE;
+import static org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties.CANONICAL_MODEL_LOAD_XML;
 import static org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties.CANONICAL_MODEL_USE_STATIC_FACTORY;
 import static org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties.CANONICAL_MODEL_USE_STATIC_FACTORY_DEFAULT;
+import static org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties.CANONICAL_MODEL_GENERATE_TIMESTAMP;
+import static org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties.CANONICAL_MODEL_GENERATE_TIMESTAMP_DEFAULT;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML;
 
 import java.io.IOException;
 import java.io.Writer;
@@ -184,7 +191,11 @@ protected void generateCanonicalModelClass(MetadataClass metadataClass, Element
             // Write out the generation annotations.
             Date date = new Date();
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            writer.append("@Generated(value=\"EclipseLink-" + Version.getVersion() + ".v" + Version.getBuildDate() + "-r" + Version.getBuildRevision() + "\", date=\"" +  sdf.format(date) + "\")\n");
+            writer.append("@Generated(value=\"EclipseLink-" + Version.getVersion() + ".v" + Version.getBuildDate() + "-r" + Version.getBuildRevision() + "\"");
+            if (Boolean.valueOf(CanonicalModelProperties.getOption(CANONICAL_MODEL_GENERATE_TIMESTAMP, CANONICAL_MODEL_GENERATE_TIMESTAMP_DEFAULT, processingEnv.getOptions()))) {
+                writer.append(", date=\"" +  sdf.format(date) + "\"");
+            }
+            writer.append(")\n");
             writer.append("@StaticMetamodel(" + className + ".class)\n");
 
             int modifier = accessor.getAccessibleObject().getModifiers();
diff --git a/jpa/org.eclipse.persistence.jpa.modelgen/src/org/eclipse/persistence/internal/jpa/modelgen/CanonicalModelProperties.java b/jpa/org.eclipse.persistence.jpa.modelgen/src/org/eclipse/persistence/internal/jpa/modelgen/CanonicalModelProperties.java
index c9485f5..5336924 100644
--- a/jpa/org.eclipse.persistence.jpa.modelgen/src/org/eclipse/persistence/internal/jpa/modelgen/CanonicalModelProperties.java
+++ b/jpa/org.eclipse.persistence.jpa.modelgen/src/org/eclipse/persistence/internal/jpa/modelgen/CanonicalModelProperties.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016 Oracle and/or its affiliates. All rights reserved.
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
  * which accompanies this distribution.
@@ -79,6 +79,15 @@ public abstract class CanonicalModelProperties {
     public static final String CANONICAL_MODEL_USE_STATIC_FACTORY_DEFAULT = PersistenceUnitProperties.CANONICAL_MODEL_USE_STATIC_FACTORY_DEFAULT;
 
     /**
+     * This optional property can be used to avoid using of date in
+     * {@link javax.annotation.Generated} annotation
+     * The default value is true and should be left as such for full feature
+     * support.
+     */
+    public static final String CANONICAL_MODEL_GENERATE_TIMESTAMP = PersistenceUnitProperties.CANONICAL_MODEL_GENERATE_TIMESTAMP;
+    public static final String CANONICAL_MODEL_GENERATE_TIMESTAMP_DEFAULT = PersistenceUnitProperties.CANONICAL_MODEL_GENERATE_TIMESTAMP_DEFAULT;
+
+    /**
      * INTERNAL:
      */
     public static String getOption(String option, String optionDefault, Map<String, String> options) {