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 170176 - dependency profile activation
Summary: dependency profile activation
Status: RESOLVED WONTFIX
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Milos Kleint
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-11 09:14 UTC by vhusainov
Modified: 2009-11-02 11:03 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample projects (5.33 KB, application/x-compressed)
2009-08-12 11:39 UTC, vhusainov
Details
netbeans 1 (117.87 KB, image/png)
2009-08-12 11:40 UTC, vhusainov
Details
netbeans 2 (51.00 KB, image/png)
2009-08-12 11:41 UTC, vhusainov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vhusainov 2009-08-11 09:14:36 UTC
I'm working on  multimodule project, which has 2 profiles. By default I'm using profile which builds regular jar files
with simple dependency hierarchy. But my second profile builds osgi bundles, where some dependencies may become optional
as I embed them into bundle jar. Other projects which use jar's from this multimodule project may use osgi bundles or
regular jars. The only way to specify what profile of dependency with it's own dependency set is to declare some
environment variable or to specify user property in command line "-Dproperty=<value>". And it all works from command
line. But there is no such option to specify user property for project when project loading netbeans (it could be great
to make it using project configuration). But also I've  found out that if I start netbeans from command line with needed
environment property specified, Netbeans uses this propery for maven project loading. And it activates needed profile.
But it gets wrong dependency list. It seems like dependency profiles don't get activated. I've tried to debug some part
of code and in NbProjectImpl's method getOriginalMavenProject() there is line
getEmbedder().readProjectWithDependencies(req); After this call I'm looking at dependencies and it shows wrong
dependency list. So maybe there is some problem with embedder is there? Or maybe I'm doing something wrong. But the same
thing works from command line. And MavenProject instance shows correct activated profiles.
Comment 1 Milos Kleint 2009-08-11 09:46:25 UTC
activating projects loaded in the IDE based on property would be an enhancement. However the fact that the dependencies
from activated profile are missing is more serious.

Instead of passing a property to the IDE JVM, can you try the following:
1. go to the project's properties dialog, the Configurations panel
2. click enable configurations checkbox, activate the profile you want.
3. apply the changes and close the dialog.

Now check what dependencies the project has, then try experimenting with the Set Configuration action from project's
popup. Does the project change?

The property base activation is not implemented, as it would not make much sense on single project. The current
Configurations setup should allow you to manually activate any profile (or combination of profiles).
The only feasible option for property based activation could be global props defined in options, however these would
then apply not only to currently opened projects but any projects encountered by the IDE (we process even closed
projects in some circumstances) It's unclear if some unforseen side effects could emerge or not..

If the problem persists for you, I would need a sample project demonstrating the problem. Thanks.
Comment 2 vhusainov 2009-08-12 11:38:28 UTC
Playing with configurations didn't help. So I've made two sample projects. And made couple of screenshots.

First project is called maven-dependency. It does nothing, but it has 2 profiles. The default profile has beansbinding
as a simple dependency. The second profile (osgi-bundle) has beansbinding as an optional dependency (it includes
dependency jar inside of maven-dependency using maven-bundle-plugin). Second profile can be activated using profile id
or by property called env.osgi_bundle with value "true". Also second profile adds classifier to dependency, but it
doesn't change anything (just shows difference).

Second project (maven-client) uses first project as dependency. It also does nothing, but depending on scenario it may
use maven-dependency with default profile or with osgi-bundle profile. To show difference I'm running
maven-dependency-plugin. And in command line if don't use property (env.osgi_bundle) I've got:
(For maven-dependency)
> mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-dependency
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree]
[INFO] org.sample.maven:maven-dependency:jar:0.1-SNAPSHOT
[INFO] \- net.java.dev.beansbinding:beansbinding:jar:1.2.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

(For maven-client)
> mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-client
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree]
[INFO] org.sample.maven:maven-client:jar:0.1-SNAPSHOT
[INFO] \- org.sample.maven:maven-dependency:jar:bundle:0.1-SNAPSHOT:compile
[INFO]    \- net.java.dev.beansbinding:beansbinding:jar:1.2.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

With property I've got:
(For maven-dependency. Nothing should change from previous run because of beansbinding is it's direct dependency)
> mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-dependency
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree]
[INFO] org.sample.maven:maven-dependency:jar:0.1-SNAPSHOT
[INFO] \- net.java.dev.beansbinding:beansbinding:jar:1.2.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

(For maven-client)
> mvn -Denv.osgi_bundle=true dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-client
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree]
[INFO] org.sample.maven:maven-client:jar:0.1-SNAPSHOT
[INFO] \- org.sample.maven:maven-dependency:jar:bundle:0.1-SNAPSHOT:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

After it I've started experimenting in netbeans. Because of it is not possible to specify a property for project
configuration, I've experimented with environment variables. At the first snapshot you can see netbeans started without
environment variable. You can see that both projects have default profiles activated. Everything is correct.
At the second snapshot I've started netbeans with environment variable specified. We have maven-dependency project with
osgi-bundle activated. But it shows no dependencies (thats wrong). Maven-dependency profile has no profiles, but it
should get maven-dependency artifact with no additional dependencies, but it shows both maven-dependency and beansbinding.
Comment 3 vhusainov 2009-08-12 11:39:36 UTC
Created attachment 86142 [details]
Sample projects
Comment 4 vhusainov 2009-08-12 11:40:34 UTC
Created attachment 86143 [details]
netbeans 1
Comment 5 vhusainov 2009-08-12 11:41:41 UTC
Created attachment 86144 [details]
netbeans 2
Comment 6 vhusainov 2009-08-12 11:47:09 UTC
I've made a mistake in my last sentence. I wanted to say: Maven-client project has no profiles, but it
should get maven-dependency artifact with no additional dependencies, but it shows both maven-dependency and beansbinding.
Comment 7 Milos Kleint 2009-08-12 13:34:13 UTC
just a couple of comments:
1. if things would works as you suggest (I'm not saying it's wrong) in project that uses the bundle dependency only, you
would never get the beansbinding.jar on IDE's classpath. the IDE doesn't perform any build steps of the project, which
are probably necessary in this case as the beansbinding jar is part of the osgi bundle jar.
2. activating the osgi-bundle profile in the dependency project via enabling configurations + activating profile in
properties dialog seems to work fine and builds the bundle.
3. activating the osgi-bundle profile in the client project doesn't work as the profile is not present in the client
project and therefor ignored by the maven embedder which does the loading.
4. when a classifier dependency is used, we don't link the projects togetherin the IDE. the classifier dependency could
be anything (like an obfuscated jar, or source jar, or random zip file) and could have unpleasant side effects.

I'm personally not very happy about thet fact that a pom in the local/remote repository mutates it's content based on a
random property from the command line. Apart from running the risk of profile name clashes that could produce irrational
side effect, it feels strange to me as a concept.

I'll see if adding properties to the project configuration element allows proper loading or not. If not, the issue is
probably wontfix.
Comment 8 vhusainov 2009-08-12 17:11:26 UTC
Oh, yes activting profiles of the project works fine right in ide. My main issue was with dependency profile.
Actually I'don't like that there is no way in maven to activate dependency profile right in project that is using
dependency (It could be like <dependency>...<profile>...</profile></dependency>). And declaring property is the only way
to do it. I think that it is something wrong with embedder if I set the same properties in both ways (clean maven and
embedder) and get different result.
I think that it is common situations. I've seen couple of other projects with different dependency set depending on profile.
Comment 9 Milos Kleint 2009-08-13 10:11:58 UTC
http://hg.netbeans.org/main/rev/a4fde9ee0cec allows including properties in the project loading loop. However it doesn't
seem to produce the effect you want. So either the maven embedder we use is broken, or the released version has this
feature/bug that was removed in new code.

By new code I mean the maven-embedder (a 1 year old svn trunk snapshot) used by netbeans. It would be interesting if you
could try with latest dev builds of maven (3.0-SNAPSHOT) and see if the described behaviour is supported or not. I'm
personally having a bad feeling about it and would assume a separate project shall be setup for the osgi bundle or have
the beans-binding project artifact automatically include the osgi manifest headers.
I'm closing the issue as LATER, as we cannot do much o our side now apart from upgrading to the newest maven embedder
which won't happen in near future I'm afraid. We will wait for at least a beta (preferably final) version of 3.0


http://hg.netbeans.org/main/rev/a4fde9ee0cec doesn't add any UI, you need to manually it to the nb-configurations.xml
file. A sample setup: 

<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
    <config-data xmlns="http://www.netbeans.org/ns/maven-config-data/1">
        <configurations>
            <configuration id="osgi-bundle">
                <property name="osgi_bundle.prop">true</property>
            </configuration>
        </configurations>
    </config-data>
</project-shared-configuration>
Comment 10 Quality Engineering 2009-11-02 11:03:17 UTC
NetBeans.org Migration: changing resolution from LATER to WONTFIX