From efad6df3508634187ba538746a788b16e3a05c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20L=C3=B6nnberg?= Date: Fri, 29 Nov 2019 11:24:32 +0100 Subject: [PATCH 1/3] Adding support for file attribute in example project environment. --- .../src/com/arm/cmsis/pack/data/CpExample.java | 15 ++++++++++++--- .../src/com/arm/cmsis/pack/data/ICpExample.java | 7 +++++++ .../arm/cmsis/pack/ICpEnvironmentProvider.java | 13 +++++++++++++ .../cmsis/pack/rte/examples/IRteExampleItem.java | 7 +++++++ .../cmsis/pack/rte/examples/RteExampleItem.java | 10 ++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/CpExample.java b/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/CpExample.java index 5ad7f9d..7790e75 100644 --- a/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/CpExample.java +++ b/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/CpExample.java @@ -64,13 +64,22 @@ public String getBoardId() { @Override public String getLoadPath(String environmentName) { - if(environmentName == null) + return getEnvironmentAttribute(environmentName, CmsisConstants.LOAD); + } + + @Override + public String getProjectFolder(String environmentName) { + return getEnvironmentAttribute(environmentName, CmsisConstants.FOLDER); + } + + private String getEnvironmentAttribute(String environmentName, String attributeName) { + if (environmentName == null) return null; Collection environments = getGrandChildren(CmsisConstants.PROJECT_TAG); if (environments != null) { for (ICpItem environment : environments) { - if (environment.getName().equals(environmentName)){ - return environment.getAttribute(CmsisConstants.LOAD); + if (environment.getName().equals(environmentName)) { + return environment.getAttribute(attributeName); } } } diff --git a/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/ICpExample.java b/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/ICpExample.java index 89564aa..d1affe1 100644 --- a/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/ICpExample.java +++ b/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/ICpExample.java @@ -49,4 +49,11 @@ public interface ICpExample extends ICpItem { * @return true if contains board */ boolean containsBoard(String boardId); + + /** + * Gets the folder attribute stored in the environment tag. + * @return folder in the project, or null of it does not exist. + */ + String getProjectFolder(String environmentName); + } diff --git a/com.arm.cmsis.pack/src/com/arm/cmsis/pack/ICpEnvironmentProvider.java b/com.arm.cmsis.pack/src/com/arm/cmsis/pack/ICpEnvironmentProvider.java index e40b49b..9e54a0f 100644 --- a/com.arm.cmsis.pack/src/com/arm/cmsis/pack/ICpEnvironmentProvider.java +++ b/com.arm.cmsis.pack/src/com/arm/cmsis/pack/ICpEnvironmentProvider.java @@ -154,6 +154,19 @@ default String getEnvironment(ICpExample example) { return null; return getName(); } + + /** + * Gets the project folder, i.e., the folder attribute listed in the environment tag. + * @param example ICpExample to get the environment folder from. + * @return the project relative path to the folder listed in the environment, + * null if not supported. + */ + default String getProjectFolder(ICpExample example) { + if (example == null) + return null; + return example.getProjectFolder(getName()); + } + /** * Contributes to newly created CMSIS RTE project. It could be an additional project nature, additional files, etc. diff --git a/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java b/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java index 0fe9e14..917011a 100644 --- a/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java +++ b/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java @@ -90,4 +90,11 @@ public interface IRteExampleItem extends ICmsisMapItem { */ String getLoadPath(); + /** + * Return the folder attribute + * @return folder path, null if not supported. + */ + String getProjectFolder(); + + } diff --git a/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/RteExampleItem.java b/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/RteExampleItem.java index f08f249..7e6a21d 100644 --- a/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/RteExampleItem.java +++ b/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/RteExampleItem.java @@ -36,6 +36,7 @@ public class RteExampleItem extends CmsisMapItem implements IRt protected Boolean fImport = null; protected String fEnvironment = null; protected String fLoadPath = null; + protected String fProjectFolder = null; protected ICpPack fPack = null; // example's pack /** @@ -237,6 +238,15 @@ public String getLoadPath() { return fLoadPath; } + @Override + public String getProjectFolder() { + if (fProjectFolder == null && isSupported()) { + ICpEnvironmentProvider envProvider = CpPlugIn.getEnvironmentProvider(); + fProjectFolder = envProvider.getProjectFolder(getExample()); + } + return fProjectFolder; + } + @Override public boolean isToImport() { if(fImport == null && isSupported()) { From 7a04d77df9c8e99e8d0439c27e2e9a7282d4f826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20L=C3=B6nnberg?= Date: Mon, 2 Dec 2019 15:27:16 +0100 Subject: [PATCH 2/3] Adding default implementations for getProjectFolder() api. --- .../src/com/arm/cmsis/pack/data/ICpExample.java | 4 +++- .../src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/ICpExample.java b/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/ICpExample.java index d1affe1..f37ba87 100644 --- a/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/ICpExample.java +++ b/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/ICpExample.java @@ -54,6 +54,8 @@ public interface ICpExample extends ICpItem { * Gets the folder attribute stored in the environment tag. * @return folder in the project, or null of it does not exist. */ - String getProjectFolder(String environmentName); + default String getProjectFolder(String environmentName) { + return null; + }; } diff --git a/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java b/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java index 917011a..f24200e 100644 --- a/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java +++ b/com.arm.cmsis.pack/src/com/arm/cmsis/pack/rte/examples/IRteExampleItem.java @@ -94,7 +94,8 @@ public interface IRteExampleItem extends ICmsisMapItem { * Return the folder attribute * @return folder path, null if not supported. */ - String getProjectFolder(); - + default String getProjectFolder() { + return null; + }; } From 448151169f6f92385bb4ae04bec59a1b28d7a5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20L=C3=B6nnberg?= Date: Mon, 2 Dec 2019 15:27:49 +0100 Subject: [PATCH 3/3] Switching visibility to protected to allow client to subclass. --- .../src/com/arm/cmsis/pack/data/CpExample.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/CpExample.java b/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/CpExample.java index 7790e75..9a8b6c4 100644 --- a/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/CpExample.java +++ b/com.arm.cmsis.pack.data/src/com/arm/cmsis/pack/data/CpExample.java @@ -72,7 +72,14 @@ public String getProjectFolder(String environmentName) { return getEnvironmentAttribute(environmentName, CmsisConstants.FOLDER); } - private String getEnvironmentAttribute(String environmentName, String attributeName) { + /** + * Fetch an attribute from the environment tag of an example project. + * + * @param environmentName + * @param attributeName + * @return + */ + protected String getEnvironmentAttribute(String environmentName, String attributeName) { if (environmentName == null) return null; Collection environments = getGrandChildren(CmsisConstants.PROJECT_TAG);