This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 186552 - IDE Variables are not working with maven project + custom actions
Summary: IDE Variables are not working with maven project + custom actions
Status: RESOLVED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 6.x
Hardware: All All
: P3 normal (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-23 09:35 UTC by tuxedo
Modified: 2010-07-30 03:06 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
screent1.png: IDE Variables are working with predefined actions like "Build". (33.51 KB, image/png)
2010-05-23 09:35 UTC, tuxedo
Details
screent2.png: IDE Variables are NOT working with custom actions (40.19 KB, image/png)
2010-05-23 09:35 UTC, tuxedo
Details
Patch that adds IDE Variable support to custom NB Maven goals (3.11 KB, patch)
2010-06-21 20:14 UTC, tuxedo
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description tuxedo 2010-05-23 09:35:06 UTC
Created attachment 99350 [details]
screent1.png: IDE Variables are working with predefined actions like "Build".

When having a maven project in NB6.8, IDE Variables (http://wiki.netbeans.org/IDEVariables) can be used with default actions like "build" oder "clean and build".

One can make use of a default action (i.e. "Build") specify a maven property (i.e. "mas.home") and pass the content of the IDE variable (i.e. "MAS_HOME" -> "C:\Test") to it (see screen1.png attachment).

This works quite well. The property "mas.home" cann then be used in the Maven pom.xml file ...

But when one want to use the variable in the same way with a custom action, the content of the maven property will be "${IDE_VARIABLE_NAME}". In this example: "${MAS_HOME}" instead of "C:\Test" (see screen2.png attachment)

Expected behavior: The IDE Variables can be used with the predefined actions, as well as with custom actions.
Comment 1 tuxedo 2010-05-23 09:35:49 UTC
Created attachment 99351 [details]
screent2.png: IDE Variables are NOT working with custom actions
Comment 2 tuxedo 2010-05-23 09:51:33 UTC
Tested NetBeans IDE 6.9 Beta (Build 201004200117)... Same issue here. IDE Variables are not working with custom actions ....
Comment 3 tuxedo 2010-05-23 09:53:16 UTC
Ah, forgot to mention: Is seems to be OS independant. Tested with Win7 64bit + JDK1.6.0_18 32bit as well as with Ubuntu 10.04 64bit with JDK 1.6.0_20 64bit
Comment 4 Peter Pis 2010-05-24 07:42:25 UTC
Reassigning.
Comment 5 tuxedo 2010-06-16 15:01:00 UTC
Am I allowed to set the target milestone, or is someone else setting it?
Of course I want to have the issues fixed as soon as possible :-)
Comment 6 Jesse Glick 2010-06-16 15:39:46 UTC
The assignee sets the target milestone when evaluating the issue.

Of course we would like to have bugs fixed as soon as possible, but there is quite a backlog of Maven-related bugs. If you feel comfortable playing with NetBeans source code, a patch for the issue (including a unit test if possible) would make a quick fix much more likely.
Comment 7 tuxedo 2010-06-16 15:46:53 UTC
Hehe. If someone could point me to the place/sub-project I will. I already downloaded the source. But it's too much for a NB source beginner like to to find the entry point ...
Comment 8 Jesse Glick 2010-06-16 16:06:12 UTC
Somewhere under maven/src I think.
Comment 9 tuxedo 2010-06-21 15:35:28 UTC
Tried a 2nd time to get some details about this issue with help of NB sourcecode...

I found out, that in Project "maven" in package "org.netbeans.modules.maven" in class "ActionProviderImpl", the default goals get the IDE variables in method "public void invokeAction(final String action, final Lookup lookup)".

There's a lookup for "ReplaceTokenProvider" which brings all replacement-stuff:

----
Collection<? extends ReplaceTokenProvider> replacers = project.getLookup().lookupAll(ReplaceTokenProvider.class);
        HashMap<String, String> replacements = new HashMap<String, String>();
        for (ReplaceTokenProvider prov : replacers) {
            replacements.putAll(prov.createReplacements(convertedAction, lookup));
        }


        Lookup enhanced = new ProxyLookup(lookup, Lookups.fixed(replacements));
        
        RunConfig rc = ActionToGoalUtils.createRunConfig(convertedAction, project, enhanced);
        if (rc == null) {
            Logger.getLogger(ActionProviderImpl.class.getName()).log(Level.INFO, "No handling for action: {0}. Ignoring.", action); //NOI18N

        } else {
            if (rc instanceof BeanRunConfig) {
                BeanRunConfig brc = (BeanRunConfig)rc;
                if (brc.getPreExecutionActionName() != null) {
                    RunConfig rc2 = ActionToGoalUtils.createRunConfig(brc.getPreExecutionActionName(), project, enhanced);
                    if (rc2 != null) {
                        brc.setPreExecution(rc2);
                    }
                }
            }
            setupTaskName(action, rc, lookup);
            runGoal(rc, true);
        }
----

As far as I understood, the "replacements" variable contains all keys with their related replacements. The replacements then somehow get into the runconfig via another lookup-call via a "proxy" ?!

I had a look at the custom goals. There the behevior is different. The class same class contains a inner class called "CustomAction". In the "actionPerformedMethod" the runconfig is created and passed to method "runGoal". 

----
 private final class CustomAction extends AbstractAction {

        private NetbeansActionMapping mapping;
        private boolean showUI;

        private CustomAction(String name, NetbeansActionMapping mapp, boolean showUI) {
            mapping = mapp;
            putValue(Action.NAME, name);
            this.showUI = showUI;
        }

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if (!showUI) {
                ModelRunConfig rc = new ModelRunConfig(project, mapping, mapping.getActionName(), null);
                rc.setShowDebug(MavenSettings.getDefault().isShowDebug());
                rc.setTaskDisplayName(NbBundle.getMessage(ActionProviderImpl.class, "TXT_Build"));

                setupTaskName("custom", rc, Lookup.EMPTY); //NOI18N
                runGoal(rc, true); //NOI18N

                return;
            }
            RunGoalsPanel pnl = new RunGoalsPanel();
.
.
.
.
----

If I'm right, one should get the replacements here and modify the "NetbeansActionMapping" variable instance called "mapping" accordingly.

I opened the "maven" project and set the checkmark for opening all required projects. But I still have errors in nearly all of the related projects (most of them are about junit etc.?!). So I'm currently not able to do some tests. But maybe my findings can help fixing this issue...
Comment 10 Jesse Glick 2010-06-21 16:26:42 UTC
(In reply to comment #9)
> I opened the "maven" project and set the checkmark for opening all required
> projects.

You do not need to open required projects. There will be a lot of them, mostly irrelevant to this issue.

> But I still have errors in nearly all of the related projects (most
> of them are about junit etc.?!).

Try:

  ant -Dcluster.config=java

to build the IDE, which will ensure that external libraries are downloaded etc.
Comment 11 tuxedo 2010-06-21 20:14:18 UTC
Created attachment 100288 [details]
Patch that adds IDE Variable support to custom NB Maven goals

Apply to file maven/src/org/netbeans/modules/maven/ActionProviderImpl.java
Comment 12 tuxedo 2010-06-21 20:18:28 UTC
Yeeha ... Finally I got it working. I compiled the complete project via console and opened the Maven project with NB. I still got errors about JUnit etc. But I was able to test my modification with "run" from project's context menu.

I'm not sure how to integrate a unit test for this, as the IDE Variable is coming from a live installation.

Either the fix is small enough so that no unit test is needed, or you give me again a hint on how to integrate such a test.
Comment 13 tuxedo 2010-07-29 13:51:16 UTC
Would be great if someone can can give a comment/feedback for the patch I provided 5 weeks ago...
Comment 14 Jesse Glick 2010-07-29 14:16:15 UTC
Can confirm bug, will test patch.
Comment 15 tuxedo 2010-07-29 14:19:49 UTC
Thanks a lot ...
Comment 16 Jesse Glick 2010-07-29 14:43:08 UTC
Actually using a somewhat more general patch, after some investigation.
Comment 17 Jesse Glick 2010-07-29 14:43:37 UTC
core-main #b36a1110da98
Comment 18 Quality Engineering 2010-07-30 03:06:35 UTC
Integrated into 'main-golden', will be available in build *201007300001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/b36a1110da98
User: Jesse Glick <jglick@netbeans.org>
Log: #186552: IDE Variables are not working with maven project + custom actions