How do I add another project's build artifacts into a .war using gradle? - war

Related to How do I add a .properties file into my WAR using gradle? but not quite:
I've got one project, call it 'webclient' that produces:
build/out/WEB-INF/deploy/foo
build/out/client/bar.js
build/out/clientDebug/baz.js
and then I've got a war project, call it 'server' that I'm trying to include the above into the a few different directories by doing:
war {
from files(project(':webclient').file('build/out/WEB-INF')) {
into('xxx')
}
from files(project(':webclient').file('build/out/client')) {
into('yyy')
}
from files(project(':webclient').file('build/out/clientDebug')) {
into('zzz')
}
}
...but that doesn't work. I end up with all the contents under zzz/ ! Am I doing something wrong? bug in gradle (1.0-m6, btw)?

I didn't digged deeper in the details, but the files() method seems to cause the problems here. The following workaround should do the trick for you:
war{
from (project(':shared').file('build/out/WEB-INF')) {
into('xxx')
}
from (project(':shared').file('build/out/client')) {
into('yyy')
}
from (project(':shared').file('build/out/clientDebug')) {
into('zzz')
}
}

Related

CSS file is not read properly using actix-web and maud

CSS is not working via link rel attributes of maud with actix-web. Where I've made mistake(s)?
I think that position where I wrote link rel attributes is correct.
main.rs
use actix_files as fs;
use actix_web::{get, App, HttpServer, Result as AwResult};
use maud::{html, Markup};
#[get("/")]
async fn index() -> AwResult<Markup> {
Ok(html! {
head{
link rel="stylesheet" href="/static/style.css"{};
}
title{"Help me"}
p {"Blue text should be shown."}
})
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(fs::Files::new("/static", ".").show_files_listing())
.service(index)
})
.bind("0.0.0.0:80")?
.run()
.await?;
Ok(())
}
style.css
p {
color: blue;
font-size: 50px;
}
Looking at the documentation of actix_files::Files:
The first argument (mount_path) is the root URL at which the static files are served.
The second argument (serve_from) is the location on disk at which files are loaded.
You are using /static as first argument, so your files will be under http://0.0.0.0:80/static, all right.
But as second argument you set . that is the root of the project. This means that you are publishing the whole source of your project! For example, at http://0.0.0.0:80/static/src/main.rs (http://0.0.0.0:80/static/ is the mount point, ./src/main.rs is the local file) you will download the source of your binary, and you do not want that.
To fix your problem write instead:
fs::Files::new("/static", "./static")
The ./ in the second argument is optional, of course, but I like it because it reminds you that it is relative to the current working directory.

Execute minimal css rule sets with both common and specific parts using scss?

.name {
%common {
// common stuff
}
&__first-type {
#extend %common;
// first type thing
}
enter code here
&__second-type {
#extend %common;
// second type thing
}
}
I want to collapse all thing in name class
(first-type, second-type, and also a common part)
but I don't want anything more in the executed CSS file.
.name__first-type, .name__second-type {
//common thing
}
.name__first-type {
//first type thing
}
.name__second-type {
//second type thing
}
can I do this thing without separating non-executable common(%common)?
It is possible to generate those two class like this.
%name__common {
// common stuff
}
.name {
&__first-type {
#extend %name__common;
// first type thing
}
&__second-type {
#extend %name__common;
// second type thing
}
If you mater nice project architecture you can either put this %name__common{...} in partial file such as _commons.scss
or try to change your project coding style.

Migrating from QWebKitWidgets to QWebEngineWidgets with project file supporting both

I am currently adding support of QWebEngineWidgets to my older applications but I don't want to loose QWebKitWidgets. because in some embeded platforms the qt version is still 5.3. I wonder if the following solution I made by myself is correct and better solutions is also welcome.
equals(QT_MAJOR_VERSION, 5) {
lessThan(QT_MINOR_VERSION, 5) {
QT += webkitwidgets
}
greaterThan(QT_MINOR_VERSION, 4) {
QT += webenginewidgets
}
}
You can also use "else" for the alternative branch, e.g.
lessThan(QT_MINOR_VERSION, 5) {
} else {
}
or even check for a module's availability specifically
qtHaveModule(webengine) {
}

JavaFX - generate compile time error if a class doesn't exist in css

I develop an application in JavaFX. Now i've got the Problem that i would like to generate an error at compile time if a css class, e.g. for a button, which if've set in the code doesn't exist in the corresponding css file.
Example:
main.java
String sCSS = this.getClass().getResource("/main.css").toExternalForm();
scene.getStylesheets().add(sCSS);
Button btn = new Button("Hello JFXWorld...");
btn.getStyleClass().add("button"); // should show compile time error
main.css
.buttonWithWrongName {
-fx-background-color: red; }
My solution would be the following, but I'm looking for advice how I can realize it.
I include an preprocessor or create an new project or something like that which parses the css code and dynamically generates an enum (into a .jar). And this jar i could include into my Project. In the best case ant would trigger the build of the enum automatically if no preprocessor is used.
again an Example:
Css file is the same as above.
{
Do preprocessor stuff for the css file here (parse and create enum) and build it to a jar file.
}
main.java
String sCSS = this.getClass().getResource("/main.css").toExternalForm();
scene.getStylesheets().add(sCSS);
Button btn = new Button("Hello JFXWorld...");
// will throw an compile time error becaus the eMainCSS enum only contains the class ".buttonWithWrongName"
btn.getStyleClass().add(eMainCSS.button.toString());
// works fine
btn.getStyleClass().add(eMainCSS.buttonWithWrongName.toString());
I'm using Eclipse (Neon) and JDK 1.8.0.
I hope there's a solution.
Thank you for the answers.
Best Regards,
Max S.
-- Edit --
Solution:
I've used an Ant WatchTask to watch at all my less files in the project.
If I change something in the less file, ant will run a self written jar file with the file name as parameter. The jar converts the less file to a css file (with less4j) and the css file to a java file (my own parser) which contains the enum.
Note: Youre not allowed to change anything in the enum. Even if you do, after the next changes in the less file, itll be gone.
The result looks like this:
Stylesheet.less:
.button { -fx-stroke-width: (1 + 1); }
#anotherButton { -fx-stroke-width: (1 + 2); }
to Stylesheet.css:
.button { -fx-stroke-width: 2; }
#anotherButton { -fx-stroke-width: 3; }
to Stylesheet.java:
// Auto-generated java file
public enum Stylesheet {
C_BUTTON("button"),
ID_ANOTHERBUTTON("anotherButton");
private final String sValue;
Stylesheet(String sValue) {
this.sValue = sValue;
}
#Override
public String toString() {
return this.sValue;
}
}
Now the compiler will throw an error at the compile time if the class or id which i'm using in javafx doesn`t exist.
Best Regards,
Max S.

Apply compiler switches to certain files

I want to specify compiler switches for a certain directory only in premake.
Now AFAIR, I think I should have to use buildoption for the switches.
So I would await:
configuration { "vs2010" }
files { "mysubdir/**" }
buildoption { "/wd4244" }
Sadly this does not seem to work. Is this even possible with premake?
If you are using the latest development version of Premake, you can do it like this:
filter { "files:mysubdir/**" }
buildoptions { "/wd4244" }
I don't recall if per-file build options were supported in Premake 4.x, but if so it would work like this:
configuration { "mysubdir/**" }
buildoptions { "/wd4244" }

Resources