diff --git a/org.fortiss.tooling.ext.reuse/META-INF/MANIFEST.MF b/org.fortiss.tooling.ext.reuse/META-INF/MANIFEST.MF index dd744c98f10878858210723e554db903d1980a79..9658c2116168e6279a953414db41e8df34059685 100644 --- a/org.fortiss.tooling.ext.reuse/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.ext.reuse/META-INF/MANIFEST.MF @@ -14,9 +14,9 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.emf.ecore;visibility:=reexport, org.fortiss.tooling.base;visibility:=reexport, org.fortiss.tooling.kernel;visibility:=reexport -Export-Package: - org.fortiss.tooling.ext.reuse.model, +Export-Package: org.fortiss.tooling.ext.reuse.model, org.fortiss.tooling.ext.reuse.model.impl, + org.fortiss.tooling.ext.reuse.model.util, org.fortiss.tooling.ext.reuse.service, org.fortiss.tooling.ext.reuse.storage, org.fortiss.tooling.ext.reuse.utils diff --git a/org.fortiss.tooling.ext.reuse/model/.ratings b/org.fortiss.tooling.ext.reuse/model/.ratings index b0d7f7fe907c1d8e2f05d4b5fc918a3215895bda..e7f5cccafa8ee259477ac0e37737fcddaf2df6f3 100644 --- a/org.fortiss.tooling.ext.reuse/model/.ratings +++ b/org.fortiss.tooling.ext.reuse/model/.ratings @@ -1 +1 @@ -reuse.ecore 25970c708374ed809312d31e49b682f954204d00 GREEN +reuse.ecore 44b0eed2f51c4b529a6a31b2f74025020e758b5e YELLOW diff --git a/org.fortiss.tooling.ext.reuse/model/reuse.ecore b/org.fortiss.tooling.ext.reuse/model/reuse.ecore index 25970c708374ed809312d31e49b682f954204d00..44b0eed2f51c4b529a6a31b2f74025020e758b5e 100644 --- a/org.fortiss.tooling.ext.reuse/model/reuse.ecore +++ b/org.fortiss.tooling.ext.reuse/model/reuse.ecore @@ -41,7 +41,7 @@ <details key="documentation" value="The UUID of the reuse library in which the reuse element (to which this specification is attached to) is stored. "/> </eAnnotations> </eStructuralFeatures> - <eStructuralFeatures xsi:type="ecore:EAttribute" name="lastUpdate" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDate"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="lastUpdate" eType="#//EZonedDateTime"> <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> <details key="documentation" value="The date at which the reuse element (to which this specification is attached to) was updated the latest. "/> </eAnnotations> @@ -52,4 +52,5 @@ </eAnnotations> </eStructuralFeatures> </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EZonedDateTime" instanceClassName="java.time.ZonedDateTime"/> </ecore:EPackage> diff --git a/org.fortiss.tooling.ext.reuse/model/reuse.genmodel b/org.fortiss.tooling.ext.reuse/model/reuse.genmodel index 84c5330e34e20549d18d97c50542f97833729323..498876089f665537bc435bcc3792c942654af3f8 100644 --- a/org.fortiss.tooling.ext.reuse/model/reuse.genmodel +++ b/org.fortiss.tooling.ext.reuse/model/reuse.genmodel @@ -9,6 +9,7 @@ <foreignModel>reuse.ecore</foreignModel> <genPackages prefix="AF3Reuse" basePackage="org.fortiss.tooling.ext.reuse" disposableProviderFactory="true" ecorePackage="reuse.ecore#/"> + <genDataTypes ecoreDataType="reuse.ecore#//EZonedDateTime" create="return ZonedDateTime.parse(it);"/> <genClasses ecoreClass="reuse.ecore#//ReuseLibrary"> <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference reuse.ecore#//ReuseLibrary/reuseElementList"/> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute reuse.ecore#//ReuseLibrary/libraryUUID"/> diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/.ratings b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/.ratings index 814ab789e2d9d8366405a2252956bf9cfd8e4805..24c393b125ef7427ba03d8240a3776b59cc08233 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/.ratings +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/.ratings @@ -1,2 +1,2 @@ -ReuseLibraryModelElementFactory.java d72834d2f7d337dc4bf716f5cfd957c826083517 YELLOW -ReuseLibraryUtils.java 623e28edc4ce7d5e7cb46d66ba5dcae6c86bb1bc YELLOW +ReuseLibraryModelElementFactory.java edac61169c3522577057a37b0e001153cea23e3b YELLOW +ReuseLibraryUtils.java 342fc58e50d6a86393050d5523715fa5b5971ad3 YELLOW diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryModelElementFactory.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryModelElementFactory.java index d72834d2f7d337dc4bf716f5cfd957c826083517..edac61169c3522577057a37b0e001153cea23e3b 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryModelElementFactory.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryModelElementFactory.java @@ -19,7 +19,7 @@ import static org.eclipse.emf.ecore.util.EcoreUtil.generateUUID; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtils.createReuseHashAsString; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtils.getReuseElementName; -import java.util.Date; +import java.time.ZonedDateTime; import java.util.Random; import org.eclipse.emf.common.notify.Notification; @@ -79,7 +79,7 @@ public class ReuseLibraryModelElementFactory { * @return The created reuse specification */ public static ReuseElementSpec createReuseElementSpec(EObject element, ReuseLibrary sourceLibrary) { - Date now = new Date(); + ZonedDateTime now = ZonedDateTime.now(); ReuseElementSpec spec = AF3ReuseFactory.eINSTANCE.createReuseElementSpec(); spec.setElementUUID(generateReuseUUID()); spec.setElementName(getReuseElementName(element)); @@ -97,7 +97,7 @@ public class ReuseLibraryModelElementFactory { if (feature instanceof ENamedElement) { String featureName = ((ENamedElement) feature).getName(); if (!featureName.equals("lastUpdate")) { - spec.setLastUpdate(new Date()); + spec.setLastUpdate(ZonedDateTime.now()); } } diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtils.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtils.java index 623e28edc4ce7d5e7cb46d66ba5dcae6c86bb1bc..342fc58e50d6a86393050d5523715fa5b5971ad3 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtils.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtils.java @@ -15,6 +15,7 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.ext.reuse.utils; +import static java.time.format.DateTimeFormatter.ISO_DATE_TIME; import static org.eclipse.emf.ecore.util.EcoreUtil.replace; import static org.fortiss.tooling.ext.reuse.ToolingReuseActivator.getDefault; import static org.fortiss.tooling.ext.reuse.service.ReuseProviderService.getPossibleExternalReferenceClasses; @@ -33,10 +34,9 @@ import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.getLargestID; import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.removeDuplicateIds; import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; -import java.util.Date; import java.util.List; import org.eclipse.core.runtime.CoreException; @@ -58,6 +58,9 @@ import org.fortiss.tooling.kernel.model.INamedElement; */ public class ReuseLibraryUtils { + /** Standard date format used for reuse (e.g. for lastUpdate dates) */ + public static DateTimeFormatter reuseDateFormatter = ISO_DATE_TIME; + /** * Fixes the IDs of the model containing the given {@link EObject}, since * updating reuse elements can produce duplicated IDs. @@ -321,14 +324,14 @@ public class ReuseLibraryUtils { } /** - * Returns the Last Update Date of the given reuse element as {link Date} as - * long as it has (already) a {@link ReuseElementSpec}. If this is not the case, - * null will be returned. + * Returns the Last Update Date of the given reuse element as + * {@link ZonedDateTime} as long as it has (already) a {@link ReuseElementSpec}. + * If this is not the case, null will be returned. * * @param element The target reuse element * @return The requested (update) date (or null) */ - public static Date getReuseElementLastUpdate(EObject element) { + public static ZonedDateTime getReuseElementLastUpdate(EObject element) { if (element instanceof IModelElement) { List<ReuseElementSpec> specs = getAllReuseSpecs((IModelElement) element); if (specs != null && !specs.isEmpty()) { @@ -340,18 +343,28 @@ public class ReuseLibraryUtils { } /** - * Returns the Last Update Date of the given reuse element as formatted {link - * String} as long as it has (already) a {@link ReuseElementSpec}. If this is - * not the case, an empty {@link String} will be returned. + * Returns the Last Update Date of the given reuse element as formatted + * {@link String} as long as it has (already) a {@link ReuseElementSpec}. If + * this is not the case, an empty {@link String} will be returned. * * @param element The target reuse element * @return The requested (update) date as string (or empty string) */ public static String getReuseElementLastUpdateString(EObject element) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date updateDate = getReuseElementLastUpdate(element); - if (updateDate != null) { - return dateFormat.format(updateDate); + ZonedDateTime updateDate = getReuseElementLastUpdate(element); + return getDateAsString(updateDate); + } + + /** + * Returns the given {@link ZonedDateTime} as formatted {@link String} as long + * as it is valid, otherwise an empty {@link String} will be returned. + * + * @param date The date + * @return The requested date as string (or empty string) + */ + public static String getDateAsString(ZonedDateTime date) { + if (date != null) { + return reuseDateFormatter.format(date); } return ""; } @@ -363,7 +376,7 @@ public class ReuseLibraryUtils { * @param element The target reuse element * @param newDate The new (update) date */ - public static void setReuseElementLastUpdate(EObject element, Date newDate) { + public static void setReuseElementLastUpdate(EObject element, ZonedDateTime newDate) { if (element instanceof IModelElement) { for (ReuseElementSpec spec : getAllReuseSpecs((IModelElement) element)) { spec.setLastUpdate(newDate); @@ -373,12 +386,12 @@ public class ReuseLibraryUtils { /** * Sets the Last Update Date of the given reuse element with the current {link - * Date} as long as it has (already) a {@link ReuseElementSpec}. + * ZonedDateTime} as long as it has (already) a {@link ReuseElementSpec}. * * @param element The target reuse element */ public static void setReuseElementLastUpdateNow(EObject element) { - setReuseElementLastUpdate(element, new Date()); + setReuseElementLastUpdate(element, ZonedDateTime.now()); } /** @@ -626,7 +639,7 @@ public class ReuseLibraryUtils { ReuseElementSpec referencingSpec, String newName) { // first, the information of the reference and the new element // needs to be updated and set up - Date now = new Date(); + ZonedDateTime now = ZonedDateTime.now(); referencingSpec.setLastUpdate(now); referencingSpec.setElementName(newName); referencingSpec.setElementHash(createReuseHashAsString(newElement, now)); @@ -660,9 +673,10 @@ public class ReuseLibraryUtils { // first, the information of the reference and the new element // needs to be updated and set up List<ReuseElementSpec> specs = getAllReuseSpecs((IModelElement) originalElementInLibrary); + ZonedDateTime now = ZonedDateTime.now(); if (specs.size() == 1) { // get(0) is safe due to size check - specs.get(0).setLastUpdate(new Date()); + specs.get(0).setLastUpdate(now); } else { return null; } @@ -916,7 +930,7 @@ public class ReuseLibraryUtils { * @return String of the created hash code integer (or null for an invalid * input) */ - public static String createReuseHashAsString(EObject element, Date modifyDate) { + public static String createReuseHashAsString(EObject element, ZonedDateTime modifyDate) { if (element != null && modifyDate != null) { // hashCode() does not change through element differences caused by simple // changes like name or new ports, etc. @@ -925,9 +939,7 @@ public class ReuseLibraryUtils { // e.g. if the original reuse element in the library was updated by someone else // in the meantime). int hash = element.hashCode(); - String datePattern = "yyyyMMddHHmmss"; - DateFormat dateFormat = new SimpleDateFormat(datePattern); - String dateAsString = dateFormat.format(modifyDate); + String dateAsString = getDateAsString(modifyDate); String hashString = String.valueOf(hash) + dateAsString; return hashString; }