gradle war rename file regular exp not working - regex

Gradle war: rename files not working with regular expr.
war {
into "foo"
from ("hello/world") {
include "bar/config/*.xml"
// remove bar/ in the path
rename '(.*)/bar/config/(.*)', '$1/config/$2'
// tried
// rename 'bar/config/(.*)', 'config/$1'
}
}
Trying to rename
foo/bar/config/*.xml -> foo/config/*.xml
The entry path was not changed inside the war.

rename is operating on the file name, not the full path. To change the path you'll need access to a FileCopyDetails object. One way to do that is with filesMatching():
war {
from('hello/world') {
includeEmptyDirs = false
include 'bar/config/*.xml'
filesMatching('**/*.xml') {
it.path = it.path.replace('bar/', '')
}
}
}

Related

How to add a relative path to the database in Qt

In my project I have a database, eg Data.db. Using it in my code, I give a constant path / home / adam / cpp / etc .. I would like to use a relative path, how can I do this? in the .pro file? resources?
code:
bool LoginWindow::loginConnect()
{
loginDatabase = QSqlDatabase::addDatabase("QSQLITE");
loginDatabase.setDatabaseName("/home/jarek/ProjectInQt/BankManagment-Qt/BankManagment/sql/Login.db");
return loginDatabase.open() ? true : false;
}
I want relative path to Login.db

How do I use groovy/Gradle DSL to get a list of directories matching a pattern?

The Gradle sonar plugin has a sonar.junit.reportPaths property that needs to be a comma-separated list of directories containing the JUnit test results files.
In our case, the directories match the pattern "^.*/build/test-results/(test|(component|integration)Test)/.*$".
We wanted to generate that list using fileTree includes/matching.
But it appears that fileTree:
Returns only files, not directories.
Is limited to ant-style file globbing, not full regular expressions.
After flailing around for way longer than we should have spent on it, we finally gave up and wrote it in Java:
def junitResults() {
Set<String> testDirs = new LinkedHashSet<>()
for (File file : files(fileTree(dir: rootDir, include: "**/build/test-results/**"))) {
testDirs.add(file.getAbsolutePath().replaceAll("/build/test-results/(test|(component|integration)Test)/.*", "/build/test-results/\$1"))
}
return testDirs.toArray(new String[testDirs.size()]);
}
That has the advantage of actually working, but it looks idiosyncratic.
Does someone know how to replace that with normal-looking groovy/Gradle DSL?
Maybe something with eachDirMatch() like this
file('path/build/test-results/.').eachDirMatch(/(test|(component|integration)Test)/) { dir ->
println dir.getPath()
}
wp78de, your answer pointed me in the right direction (use file, not fileTree):
def junitResultsDirs() {
def dirs = []
rootDir.eachDirRecurse { dir ->
if (dir.absolutePath.matches("^.*/build/test-results/(test|(component|integration)Test)\$")) {
dirs << dir
}
}
return dirs;
}

UI5 - how to run Karma without allTests file, running all tests from the folder

I am currently preparing some unit tests POC for out UI5 web application. To run them, we would like to use Karma runner. In its installation guide, I see this
All tests should be listed in specific files. You can, for example, collect all unit tests in an allTests.js file. With the help of this file, Karma can find all tests that belong to specific modules or components.
client: {
openui5: {
tests: [
'test/unit/allTests',
'test/integration/AllJourneys'
Using the allTests.js file, I am indeed able to execute unit tests. However, now I am thinking if its absolutely necessary to use this allTests.js file - because now, when we add new .js test to our test scope, we also need to add its path to the allTests.js file which seems like the extra work (and source of problem if its forgotten).
I think much better would be if all .js files from the "test/unit" path were executed by Karma without the need to collect them all in a single file. However, I haven't found online any way to do it and my experiments are failing so far. For example, I deleted openui5/tests section of the configuration file and tried to define loaded tests in files section like this
files: ['https://openui5.hana.ondemand.com/1.65.1/resources/sap-ui-core.js', 'test/unit/*.js'],
Could someone advise? Is it possible to bypass allTests.js file and if yes, how to do it? Thank you.
In the end, we did as Ji aSH recommended - at the start of each test run, we run a script that collects the names of all .js files in the test/unit folder and creates allTests.js file from them. Like this
const fs = require('fs');
const path = require('path');
// List all files in a directory in Node.js recursively in a synchronous fashion
const walkSync = function (dir, filelist) {
if (dir[dir.length - 1] != path.sep) dir = dir.concat(path.sep)
const files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function (file) {
if (fs.statSync(path.join(dir, file)).isDirectory()) {
filelist = walkSync(path.join(dir, file), filelist);
}
else {
if (path.extname(file) === '.js' && path.basename(file) !== 'allTests.js') {
const filePath = `\n '${dir}${path.basename(file, '.js')}'`;
filelist.push(filePath.replace('webapp', path.join('xxx', 'xxxxl')));
}
}
});
return filelist;
};
const testFiles = walkSync(path.join('webapp', 'test', 'unit'), null);
const fileContent = `sap.ui.define([${testFiles},\n], () => { 'use strict'; });\n`;
fs.writeFileSync(path.join('webapp', 'test', 'unit', 'allTests.js'), fileContent);

Find folder of the current javascript macro in iMacros?

I want to be able to reference the iMacros folder from my javascrip script in order to write:
retcode = iimPlay(folder + "/macro1.iim");
retcode = iimPlay(folder + "/macro2.iim");
instead of
retcode = iimPlay("test/macro1.iim");
retcode = iimPlay("test/macro2.iim");
I know it is possible in vbs but I don't know if that is the case in javascript.
it works in a similar way with javascript, here is example of the code:
var folder="c:\\data\\"
iimPlay(folder+"1.iim");
this code will run the 1.iim script from c:\data folder
You can make use of inbuilt !FOLDER_DATASOURCE variable to get folder of current javascript macro.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
var folderPath = iimGetExtract();
//Remove 'Datasources' from end of folder path string
folderPath = folderPath.slice(0,-11);
//Append 'Macros' to end of above path
folderPath = folderPath+"Macros\\";
alert(folderPath);
Performing above steps in single command.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
//Remove 'Datasources' from end of folder path string and append 'Macros'
var folderPath = iimGetExtract().slice(0,-11)+"Macros\\";
alert(folderPath);
Another possible approach is to replace 'Datasources' with 'Macros' in folder path.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
//Replace 'Datasources' with 'Macros' in folder path string
var folderPath = iimGetExtract().replace("Datasources","Macros\\");
alert(folderPath);
However it may create problem if folder path contains 'Datasources' anywhere else. You may use any of above methods as per your choice.
Once you get folder path of 'Macros' folder, you can use it like.
retcode = iimPlay(folderPath + "macro1.iim");

How can I control infile and outfile passed to compiler when specifying files to compile with django-pipeline?

I've written a rudimentary requirejs compiler for Django-Pipeline and I'm trying to polish it up but I'm stuck with a certain problem. I've noticed the same "problem" with the SASS compiler so I wonder if this is a setting I'm missing or something.
PIPELINE_CSS = {
'main': {
'source_filenames': (
'sass/main.scss',
),
'output_filename': 'css/crushcode.css',
'extra_context': {
'media': 'screen,projection',
}
}
}
PIPELINE_JS = {
'requirejs': {
'source_filenames': (
'js/lib/requirejs-2.0.4.js',
),
'output_filename': 'js/require.js',
'extra_context': {
'data': '/static/js/bootstrap'
}
}
}
Both of these create an output file in the source directory of the same name as the input file, with the extension changed to output_extension of the respective compiler class. For SASS, this is ok as the extension is .css so you end up with main.css next to your main.scss, but with my requirejs plugin the first time I ran it, because the extensions are the same, I actually overwrote my original file (Nothing lost of course, thankyou version control).
I noticed that infile and outfile were both pointing to:
APP_ROOT/static/js/lib/require-2.0.4.js
when I would have thought outfile should point to output_filename in the settings.
The easy fix was to change the output_extension of my custom compiler class to be 'optimized.js', but at this point I'm adding a .gitignore for every compiled file, and not to mention collectstatic then brings everything across, and also creates the desired output_filename file in the target directory.
What I was hoping for was that collectstatic would simply create the js/require.js file in my STATIC_ROOT directory.
It feels like I'm doing something wrong here, any tips? Is this expected behaviour? If so, what's the best should I go about changing it?