Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make gradle plugin respect Netbeans Configurations #313

Open
MarceloRuiz opened this issue Jan 23, 2017 · 15 comments
Open

Make gradle plugin respect Netbeans Configurations #313

MarceloRuiz opened this issue Jan 23, 2017 · 15 comments

Comments

@MarceloRuiz
Copy link

It seems the Gradle plugin ignores different Netbeans Configuration. Usually Netbeans runs the Default Profile, but one can create a new configuration (for example, "Headless" to run tests in headless mode) and set a system property in that configuration (like headless=true).

Even though the output shows the JVM is started with that property correctly set, it seems the plugin is not configured to pass that configuration to gradle, nor the application arguments for that matter.

The current workaround is setting that in the build file :

tasks.withType(Test) {
    systemProperties System.getProperties()
    args System.getProperty("exec.args").split()
}

It is my expectation that the plugin will honor the Netbeans Configuration settings out of the box when running the project (same behavior that Netbeans has with running maven or ant projects).

Thanks!

@kelemen
Copy link
Owner

kelemen commented Jan 23, 2017

Can you describe what exactly you are doing (what you write into where) and your expectation (where do you expect to see what precisely)? Because I'm unaware any bug where configurations of other profiles are not honored.

Anyway, if you set a JVM argument, that is a JVM argument for the build script. That won't be passed to tasks which happen to spawn another Java process (like test). Also, I would recommend you to use project properties instead of using JVM arguments for performace reason.

@MarceloRuiz
Copy link
Author

What I'm doing exactly is:

  • My project has a dependency to openjfx-monocle to be able to run tests in headless mode (useful for running tests in Jenkins).

  • I go to the dropbox in Netbeans' toolbar that sets the project configuration (right of redo and undo menu buttons) and select "Customize..."

  • Click on add profile and name it "headless". Select that profile and go to Built-In Tasks, select "Test" in dropbox menu, unclick Inherit, in the text area for JVM Arguments I type: "headless=true" and finally click the "OK" button to save the changes.

  • I configure my tests to be aware of the expected headless system property with a @BeforeClass method:

@BeforeClass
public static void setupHeadlessMode() {
  if (! Boolean.getBoolean("headless")) {
    throw new RuntimeException("It should be headless!");
  }
}

My expectation is that when I select "headless" in the dropbox menu in the Netbeans toolbar and run the tests, I should not receive the RuntimeException.

@kelemen
Copy link
Owner

kelemen commented Jan 23, 2017

This won't work for two reasons:

  1. To set a system property, you have to add the JVM argument: -Dheadless=true
  2. This will only set the system property for the build script itself not for the started task. You have to forward the system property to your test tasks. Though I would recommend project properties instead of system properties (as that would be more efficient). To set one, you have to add "-Pheadless=true" in the arguments (not the JVM arguments).

@MarceloRuiz
Copy link
Author

Thanks for getting back to me. I made the mistake when I wrote this issue to forget the "-D" before the property (which is what I did use in my test).
I tried to use the properties section as you suggested, but it does not work. Is there anything else I need to do?
Thanks!

@kelemen
Copy link
Owner

kelemen commented Jan 23, 2017

If you are using -Pheadless, you will have to forward it to the test task manually. For example like this:

if (project.hasProperty('headless') {
    test.systemProperty 'headless', project.headless
}

@MarceloRuiz
Copy link
Author

Thanks for the answer. I don't know what I am doing wrong, but your suggestion does not work for me.
I added a println to confirm the project has the headless property, but Boolean.getBoolean("headless") in my code always returns false.

@wadechandler
Copy link

wadechandler commented Jan 24, 2017 via email

@MarceloRuiz
Copy link
Author

@wadechandler
Thanks for your answer. That is exactly what I was doing and it was working. I was just trying to follow kelemen's suggestion to translate the project property (which is set correctly) to the system property just for the test. Do you happen to know why the other approach was not working?
Thanks!

@wadechandler
Copy link

wadechandler commented Jan 24, 2017 via email

@kelemen
Copy link
Owner

kelemen commented Jan 24, 2017

@MarceloRuiz Can you create a sample project and share it on Github (commit NB generated files as well except files within .nb-gradle/private/)? That way I can be sure what you are doing.

@MarceloRuiz
Copy link
Author

@kelemen

Hi Attila,
Sorry I couldn't answer this before. Here is a sample project as you requested (not in github):
sample project here
Thanks,
Marcelo.

@kelemen
Copy link
Owner

kelemen commented Feb 7, 2017

You have set "-Pheadless=true" for the default profile (I assume this was not the case in your real project). Anyway, you only set "-Pheadless" for the "Build" action. You have to add this for every test related built-in task (test, test single, debug test single method, ...). Sadly, there is no way at the moment to define arguments passed for all built-in tasks (or possibly even custom tasks). Though, it wouldn't be too hard to add.

@MarceloRuiz
Copy link
Author

Thanks for getting back to me. In my real project I had a new profile for headless operation with the property set to each of those tasks you mentioned. Maybe I was too tried when I created the sample project. What I ended up doing is tweaking the gradle build file for test tasks and setting the system properties needed to run headless tests there.

@kelemen
Copy link
Owner

kelemen commented Feb 9, 2017

The project you have linked works for me as expected and if I configure "-Pheadless=true" for the test command, it will print "It is headless!".

By the way, you are writting this:

tasks.withType(Test) {
    testLogging {
        showStandardStreams = true
    }

    if (project.hasProperty('headless')) {
        test.systemProperty 'headless', project.headless
    }
}

If you are doing it this way, you should remove the test. from your to refer to the test task to be configured.

@MarceloRuiz
Copy link
Author

Thanks Attila!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants