Delete all subdirectory except a subtree - build.gradle

I'm new.
I'm trying to create a gradle task that delete all directory except a subset of those.
this is my situation
src/main/java
test/package1
test/package2
com/package3
com/package4
it/package5
and here my code:
task deleteFolders(type: Delete){
group = 'build'
if(currentTask == "deleteFolders"){
def ftree=fileTree(dir: "$javaDir").exclude('test/package2')
ftree.exclude('test/package1')
ftree.visit { FileVisitDetails details ->
delete details.file
}
}
but this code delete everything, also the packages inside "exclude".
trying with this other code
task deleteFolders{//(type: Delete)
group = 'build'
if(currentTask == "deleteFolders"){
delete fileTree(dir: "$javaDir").matching {
exclude 'test/package1/**'
exclude 'test/package2/**'
}
}
everything work but the com folder is still there empty (i want to remove it).
so, can someone help me to reach this result ?
src/main/java
test/package1
test/package2
thanks a lot Leo

Maybe you can try the way as follows:
deleteTask = { dealFilePath, destFileName ->
file(dealFilePath).list().each {
f ->
if (!f.contains(destFileName)) {
delete "${dealFilePath}/${f}"
}
}
}

Related

PlatformIO Possible key upload_flags & upload_command string option

I work with STM32F429ZI and PlatformIO and i need to upload firmware to specific address like 0x08020000 for example. And I can't find in docs on platformio which key for upload_flags I can use for it, or how I can modify upload_command for it. Thanks.
Right solution is add mbed_app.json to your project root with:
{
"target_overrides": {
"*": {
"target.mbed_app_start" : "0x08020000",
"target.mbed_app_size" : "0x000A0000"
}
}
}
https://os.mbed.com/docs/mbed-os/v5.15/reference/bootloader-configuration.html
This parameters expand to:
MEMORY
{
FLASH (rx) : ORIGIN = 0x8020000, LENGTH = 0xa0000
...
}
on your .ld script and you don't need to change upload_flags and upload_command.

Additional partitions in buildroot

I'd like to know if it's possible to add more partitions in the partition table, and how.
I've tested to change the genimage.cfg but it seems that support/scripts/genimage.sh doesn't create it.
Thank you in advance.
Using the genimage.cfg script is the right way to go.
If it does not work, you might be modifying the wrong config file; genimage is usually invoked by a script specified as
Make sure to modify the right config file however, the one used by the script defined in the BR2_ROOTFS_POST_IMAGE_SCRIPT option, under System configuration-> Custom scripts to run after creating filesystem images in menuconfig.
For example, I modified mine (specifically boards/raspberrypi3-64/genimage-raspberrypi3-64.cfg to accomodate for an extra ext4 partition.
image boot.vfat {
vfat {
files = {
"bcm2710-rpi-3-b.dtb",
"bcm2710-rpi-3-b-plus.dtb",
"bcm2837-rpi-3-b.dtb",
"rpi-firmware/bootcode.bin",
"rpi-firmware/cmdline.txt",
"rpi-firmware/config.txt",
"rpi-firmware/fixup.dat",
"rpi-firmware/start.elf",
"rpi-firmware/overlays",
"Image"
}
}
size = 32M
}
image sdcard.img {
hdimage {
}
partition boot {
partition-type = 0xC
bootable = "true"
image = "boot.vfat"
}
partition rootfs {
partition-type = 0x83
image = "rootfs.ext4"
}
partition log {
partition-type = 0x83
image = "log.ext4"
}
}

Issue with iterating using DescendantsOrSelf

I just recently upgraded Umbraco from 4.7.2 to 7.1.9 and now in the process of slowly converting all legacy macroscripts to partial view macros. I have come across a few issues when using DescendantsOrSelf to iterate through nodes.
I have a macro that generates the side menu for my site (intranet). With version 4 the macro worked as expected on the whole site displaying the appropriate menu on the homepage and different side menu's on the child pages.
After the upgrade the below condition:
var model = GetParentSideMenu(CurrentPage);
#if (CurrentPage.AncestorsOrSelf("umbSomePageType").Where("Visible").First().HasValue("PageName") && CurrentPage.AncestorsOrSelf("umbSomePageType").Where("Visible").First().Id != model.Id)
{ ... }
#functions
{
public dynamic GetParentSideMenu(dynamic model)
{
if (model.Level > 1)
{
do
{
if (model.umbSideMenuLinks.Count() > 0)
{
return model;
}
if (model.Level > 1) {
model = model.Up();
} else { break; }
} while (model.Up() != null);
return model;
}
else return model;
}
}
Generates the following error when rendered on the homepage:
System.InvalidOperationException {"Sequence contains no elements"}
Inner Exception is null
The understanding here is that the page being rendered is not "umbSomePageType" so this condition should be false and move on but instead it throws the above exception.
The macro works fine when rendered on a "umbSomePageType" page but as the user is allowed to have further sub pages of a another type under "umbSomePageType" I have to manually check the "DocumentTypeAlias" and make sure the other if statements checking for that type of sub page are not executed because I get the same error as above.
Another issue I am facing is this doesn't return an iterable collection when it used to before in v4:
#if (model.DescendantsOrSelf("umbSideMenuLinks").Where("Visible").Count() > 0)
{
foreach (var item in model.DescendantsOrSelf("umbSideMenuLinks").Where("Visible").First().Children)
{ ... }
.... }
The if condition returns true but the foreach is unable to get any elements to iterate through.
Any help here will be greatly appreciated.
Thank You.
I was able to find a solution to the first problem I specified above. The error was occurring in the "if" condition due to the "CurrentPage" being a dynamic object, "FirstOrDefault()" needs to be used instead of "First()".
The second issue still stands and to further detail that issue if you have the following directory structure:
Root Folder/Homepage
- Second Level Folder
-- SideMenuLinks (umbSideMenuLinks)
-- SomePage...
- SideMenuLinks (umbSideMenuLinks)
In the above case if I am on the "HomePage" and I want to render the "SideMenuLinks" pertaining to the homepage and I use "DecedantOrSelf" it will go from the root folder to the second level folder and to the "SideMenuLinks" instead of first checking it "Self" which is the behaviour I desire. This is something that worked in Umbraco v4 but in v7 it drills into the sub directories first.
Maybe if I reorder/sort the SideMenuLinks so they appear before the "Second Level Folder" ?
Haven't tried that yet.
UPDATE: So I just tried the sorting and if I sort the tree this way:
Root Folder/Homepage
- SideMenuLinks (umbSideMenuLinks)
- Second Level Folder
-- SideMenuLinks (umbSideMenuLinks)
-- SomePage...
It starts to work. In the future we will have to create the page structure this to make sure that the correct SideMenuLinks are hit.

atg.repository.RemovedItemException when trying to add an item to Repository

I have used InternalProfileFormHandler to add an item InternalProfileRepository. It has successfully added the item(user:iuser310002) to the intended repository. Once added, I have accessed dyn/admin to open the repository and removed item I have just added by using <remove-item item-descriptor="user" id="iuser310002" />. Then I have used invoked InternalProfileFormHandler again to add one more item. However this time, I have got an atg.repository.RemovedItemException saying that Attempt to use an item which has been removed: user:iuser310002.
I'm not sure why it is trying to create a new user with same id as before and even if I did, why an item which is removed should cause this issue. I'm using default idGenerator /atg/dynamo/service/IdGenerator for InternalProfileRepository so I don't think I would be generating same id.
Here is the code that succesfully created item once and failing from second time...
FormHandlerInvoker invoker = new FormHandlerInvoker("/atg/userprofiling/InternalProfileFormHandler", Nucleus.getSystemNucleus());
try {
String paramName;
int paramCounter = 1;
while((paramName = (String) getCurrentTestParams().get("param" + paramCounter)) != null)
{
invoker.addInput(paramName, (String) getCurrentTestParams().get("value" + paramCounter));
paramCounter++;
}
} catch (ServletException e) {
e.printStackTrace();
}
FormHandlerInvocationResult result;
ProfileFormHandler formHandler = null;
try {
result = invoker.invoke();
formHandler =
(ProfileFormHandler)result.getDefaultFormHandler();
formHandler.handleCreate(result.getRequest(), result.getResponse());
}
Following is the exception log... which is caused by formHandler.handleCreate method invocation.
atg.repository.RemovedItemException: Attempt to use an item which has been removed: user:iuser310002
at atg.adapter.gsa.ItemTransactionState.<init>(ItemTransactionState.java:385)
at atg.adapter.gsa.GSAItem.getItemTransactionState(GSAItem.java:2421)
at atg.adapter.gsa.GSAItem.getItemTransactionState(GSAItem.java:2364)
at atg.adapter.gsa.GSAItem.getItemTransactionStateUnchecked(GSAItem.java:2600)
at atg.adapter.gsa.GSAItem.getPropertyValue(GSAItem.java:1511)
at atg.repository.RepositoryItemImpl.getPropertyValue(RepositoryItemImpl.java:151)
at atg.adapter.composite.CompositeItem.createPropertyQuery(CompositeItem.java:739)
at atg.adapter.composite.CompositeItem.getPropertyLinkedItem(CompositeItem.java:630)
at atg.adapter.composite.CompositeItem.getContributingItem(CompositeItem.java:577)
at atg.adapter.composite.CompositeItem.findContributingItem(CompositeItem.java:561)
at atg.adapter.composite.MutableCompositeItem.findContributingItem(MutableCompositeItem.java:971)
at atg.adapter.composite.MutableCompositeItem.getOrCreateContributingItem(MutableCompositeItem.java:985)
at atg.adapter.composite.MutableCompositeItem.setPropertyValue(MutableCompositeItem.java:210)
at atg.userprofiling.ProfileForm.updateProfileAttributes(ProfileForm.java:3761)
at atg.userprofiling.ProfileForm.updateProfileAttributes(ProfileForm.java:3528)
at atg.userprofiling.ProfileForm.createUser(ProfileForm.java:1507)
at atg.userprofiling.ProfileForm.handleCreate(ProfileForm.java:1214)
at atg.userprofiling.ProfileFormHandler.handleCreate(ProfileFormHandler.java:402)
at atg.scenario.userprofiling.ScenarioProfileFormHandler.handleCreate(ScenarioProfileFormHandler.java:599)
at atg.test.steps.CreateInternalUserStep.runTest(CreateInternalUserStep.java:45)
After some digging around, I figured out the reason. Along with creating user, a session is also being created for the same user automatically. The user could be found by going to this path in dyn/admin. /atg/dynamo/servlet/sessiontracking/GenericSessionManager/notdefined/atg/userprofiling/Profile/
Next time when I'm deleting the item in InternalProfileRepository, the item is being deleted successfully but the session object still exists.
When I call the formhandler.handleCreate again, it is checking if the profile object exists. When it found the user, it is trying to update the same user instead of creating a new one. Hence I'm getting the RemovedItemException.
However, I'm not quite sure if that is what is expected.

Magento: Disable module for any particular store

Suppose, I have 3 stores.
I want to disable a module in Store 2. I only want it to be enabled in Store 1 and Store 3.
I see that I can do it by:-
Going to System -> Configuration -> Advanced
Selecting desired store from Current Configuration Scope dropdown list.
But this does not work fully.
And, I also don't want to check store in the module code itself or create system configuration field for the module to check/uncheck store to enable/disable.
What I am expecting is by adding some code in app/etc/modules/MyNamespace_MyModule.xml. Can we do it this way?
To disable a module on the store scope, I've found it's possible to do it like this:
Move app/code/core/Mage/Core/Model/Config.php to app/code/local/Mage/Core/Model/Config.php
Inside Config.php find the method "loadModulesConfiguration" Don't change anything, but add the following code to make the method look like this.
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
$disableLocalModules = !$this->_canUseLocalModules();
if ($mergeToObject === null) {
$mergeToObject = clone $this->_prototype;
$mergeToObject->loadString('<config/>');
}
if ($mergeModel === null) {
$mergeModel = clone $this->_prototype;
}
$modules = $this->getNode('modules')->children();
foreach ($modules as $modName=>$module) {
if ($module->is('active')) {
// Begin additional code
if((bool)$module->restricted) {
$restricted = explode(',', (string)$module->restricted);
$runCode = (isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'default');
if(in_array($runCode, $restricted)) {
continue;
}
}
// End additional code
if ($disableLocalModules && ('local' === (string)$module->codePool)) {
continue;
}
if (!is_array($fileName)) {
$fileName = array($fileName);
}
foreach ($fileName as $configFile) {
$configFile = $this->getModuleDir('etc', $modName).DS.$configFile;
if ($mergeModel->loadFile($configFile)) {
$mergeToObject->extend($mergeModel, true);
}
}
}
}
return $mergeToObject;
}
The new code will cause the method to also check for a new node in the module xml file, <restricted>. If the node exists, the value would be a comma separated list of store codes that you do NOT want the module to load on. If you have multiple stores, the $_SERVER variable "MAGE_RUN_CODE" should be set with the current store code. If it's not set, the script will fallback to assuming the store code is "default" which is what it is by default unless for some bizarre reason you decide to change that in the backend.
A modules xml file could then look like this:
<?xml version="1.0"?>
<config>
<modules>
<MyPackage_MyModule>
<active>false</active>
<restricted>mystore1,mystore4,mystore5</restricted>
<codePool>local</codePool>
</MyPackage_MyModule>
</modules>
</config>
With this, the module will not even load while on the stores with a store code of mystore1, mystore4, or mystore5. The <restricted> tag is entirely optional, if you omit it the module will load as it normally would.
This configuration just disables module output in layout for frontend, but module controllers, event observers, admin pages, etc still working.
Also don't forget to specify your module name in layout files definition, otherwise all the layout file content will be loaded for a particular store:
<config>
<layout>
<module_alias module="Module_Name">
<file>yourlayoutfile.xml</file>
</module_alias>
</layout>
</config>
If you are developing a module and want to disable full its functionality on the frontent for a particular store, then you should create a configuration field of "Yes/No" type and check its value via Mage::getStoreConfigFlag('config/field/path') in your module code.
I was using Eric solution for a while. In my case I disabled certain module responsible for Layered Navigation in one of my shops - thus returning to default Layered Navigation behaviour.
And it looked like its working, but after a while I've noticed that layered navigation options stopped to appear where they should. Soon I've noticed that in fact the module that should not work on this shop continued to work. Then I realized that when I disable configuration cache Eric's solution works, but after enabling it again it stops.
After a while I realized it had to work that way, with configuration cache enabled, because Eric's solution includes (or not) specified config files in global xml only while this xml is being generated. Then its cached and called from cache only. So when it was generated from site which should use some module it was included, and then used also on site which wasn't suppose to use it.
Anyway I worked out another solution, based on Eric's code (using restricted in modules config). I thought Magento should decide what to load when class is being requested. Then it could check what is current MAGE_RUN_CODE and use it dynamically.
There is a method in Mage_Core_Model_Config which is responsible for getting class name: getGroupedClassName.
Here is the code I used there:
if (strpos($className, 'Pneumatig_') !== false) {
$var = substr($className, 0, strpos($className, '_', strpos($className, '_') + 1));
if (isset($this->_xml->modules->$var)) {
if ((bool)$this->_xml->modules->$var->restricted === true) {
$code = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'default';
if (strpos((string)$this->_xml->modules->$var->restricted, $code) !== false) {
$className = '';
}
}
}
}
This Pneumatig condition is because all my modules start from Company name, so i wanted to avoid not necessary processing, but its optional, code should work without it, or you can change it to anything else.
Then I get actual module name [Company]_[Module], and then check if its enabled in _xml (which is current configuration object). If it is restricted I clear $className so it force Magento to load the default in next line.
And this code is added just before is empty condition:
// Second - if entity is not rewritten then use class prefix to form class name
if (empty($className)) {
if (!empty($config)) {
$className = $config->getClassName();
}
if (empty($className)) {
$className = 'mage_'.$group.'_'.$groupType;
}
if (!empty($class)) {
$className .= '_'.$class;
}
$className = uc_words($className);
}
$this->_classNameCache[$groupRootNode][$group][$class] = $className;
return $className;
And for your convenience i paste whole getGroupedClassName code:
public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
{
if (empty($groupRootNode)) {
$groupRootNode = 'global/'.$groupType.'s';
}
$classArr = explode('/', trim($classId));
$group = $classArr[0];
$class = !empty($classArr[1]) ? $classArr[1] : null;
if (isset($this->_classNameCache[$groupRootNode][$group][$class])) {
return $this->_classNameCache[$groupRootNode][$group][$class];
}
$config = $this->_xml->global->{$groupType.'s'}->{$group};
// First - check maybe the entity class was rewritten
$className = null;
if (isset($config->rewrite->$class)) {
$className = (string)$config->rewrite->$class;
} else {
/**
* Backwards compatibility for pre-MMDB extensions.
* In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So <deprecatedNode> is left
* to keep name of previously used nodes, that still may be used by non-updated extensions.
*/
if (isset($config->deprecatedNode)) {
$deprecatedNode = $config->deprecatedNode;
$configOld = $this->_xml->global->{$groupType.'s'}->$deprecatedNode;
if (isset($configOld->rewrite->$class)) {
$className = (string) $configOld->rewrite->$class;
}
}
}
//START CHECKING IF CLASS MODULE IS ENABLED
if (strpos($className, 'Pneumatig_') !== false) {
$var = substr($className, 0, strpos($className, '_', strpos($className, '_') + 1));
if (isset($this->_xml->modules->$var)) {
if ((bool)$this->_xml->modules->$var->restricted === true) {
$code = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'default';
if (strpos((string)$this->_xml->modules->$var->restricted, $code) !== false) {
$className = '';
}
}
}
}
//END CHECKING IF CLASS MODULE IS ENABLED
// Second - if entity is not rewritten then use class prefix to form class name
if (empty($className)) {
if (!empty($config)) {
$className = $config->getClassName();
}
if (empty($className)) {
$className = 'mage_'.$group.'_'.$groupType;
}
if (!empty($class)) {
$className .= '_'.$class;
}
$className = uc_words($className);
}
$this->_classNameCache[$groupRootNode][$group][$class] = $className;
return $className;
}
My clients install of Magento 1.8.1.0 has a problematic module that breaks another site's menu on a multi-store setup. The solution above posted by Eric Hainer didn't work for this install, so I altered it slightly:
Instead of using $_SERVER['MAGE_RUN_CODE'], I used $_SERVER['SERVER_NAME']. Worked like a charm. :)
So instead of:
$runCode = (isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'default');
use:
$runCode = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'www.site1.com');
and instead of:
<restricted>mystore1,mystore4,mystore5</restricted>
use:
<restricted>www.site2.com,www.site3.com</restricted>
obviously changing "www.site1.com", "www.site2.com", and "www.site3.com" with your own locations.
Thanks for the idea Eric :)
Also interesting solution ,
http://inchoo.net/ecommerce/magento/how-to-activatedeactivate-magento-module-per-a-website-level/