Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 114563

Summary: [launching] [builders] Ant Builder doesn't build with Target set to <default>
Product: [Eclipse Project] Platform Reporter: Filip Jirsák <Filip.Jirsak>
Component: AntAssignee: Michael Rennie <Michael_Rennie>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: alexander.tress.atr, autophile, curtis.windatt.public, daniel_megert, darin.eclipse, Darin_Swanson, markus.kell.r, Michael_Rennie, noobs.temp, sptaszkiewicz
Version: 3.1.1Flags: markus.kell.r: review+
Target Milestone: 3.7 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 335860, 335861, 335967, 340864    
Attachments:
Description Flags
Patch
none
proposed fix
none
update
none
patch + regression tests none

Description Filip Jirsák CLA 2005-11-01 11:46:35 EST
When I append Ant Builder to project (by both importing Launch Configuration and
creating new launch configuration), targets for "After a 'Clean'" and "Manual
Build" are set on "<default target selected>". With this configuration, nothing
happen when activating project building or Clean (by Project -> Build All |
Build Project | Clean) - nothing is written into Console, .jar file is not
created (which may be created by my Ant task). The same Launch Configuration and
Task started via External Tools works fine.
When I set in External Builder configuration target other then default (actually
I tested selecting two targets - default and any others), save the configuration
and revert back (so only default target is set), configuration apperas the same
(text is still "<default target selected>"), but Builder works - Project ->
Build Project starts ant task, output from Ant is displayed in Console and
output (.jar file) is created.
It seems '<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS"
value="...,"/>' in .launch configuration is not set for default target, but Ant
Builder can't work right sometime when this key is not set.
Comment 1 Michael Rennie CLA 2010-04-19 11:17:48 EDT
*** Bug 223894 has been marked as a duplicate of this bug. ***
Comment 2 Michael Rennie CLA 2010-04-19 16:55:34 EDT
looks like the fix to bug 63685 might be the culprit here.

when no targets were selected we used to make the following call:
 
  setTargetsForUser(text, DEFAULT_TARGET_SELECTED, null);

this was subsequently changed to short-circuit doing nothing.
Comment 3 Szymon Ptaszkiewicz CLA 2010-04-20 04:23:45 EDT
Created attachment 165391 [details]
Patch
Comment 4 Michael Rennie CLA 2010-05-04 13:44:21 EDT
removing as RC1 candidate. Evaluating the impact of the patch and other considerations, this is much too large to consider now.

The main two reasons being:
1. the patch will cause all existing - previously valid - configurations now have errors, which is regression, and 

2. we cannot start adding in additional Ant targets suddenly, this can have a dramatic performance impact on existing Ant builders.
Comment 5 Dani Megert CLA 2010-08-30 04:41:23 EDT
Given the previous comment this doesn't look like a 3.6.x fix. This should first be put into 3.7 to gather feedback before anything is released into 3.6.x.
Comment 6 Darin Wright CLA 2010-09-01 14:10:47 EDT
This is working for me in 3.7

Steps:

* Create a new Java project called "xyz" with default settings
* Create a class in the "src" folder falled "Hello"
* Create a build.xml file in the root of the project with these contents:

<?xml version="1.0" encoding="UTF-8"?>
<project name="project-builder" default="default">
    <description>
            Builder
    </description>

    <target name="default"  description="description">
        <echo>DEFAULT</echo>
    </target>

	<target name="fullBuild">
		<echo>FULL</echo>
	</target>
	
	<target name="incrementalBuild">
		<echo>INCREMENTAL</echo>
	</target>
	
	<target name="autoBuild">
		<echo>AUTO</echo>
	</target>
	
	<target name="clean">
		<echo>CLEAN</echo>
	</target>

</project>

* Select the project's Builder properties
* Add a new Ant builder that references the given build file
* By default the default targets are selected for "After a clean" (Full build) and "Manual build"
* Press OK
* Turn off auto build
* Modify the source file
* Press CTRL-B, the default target runs
* Select "Project > Clean" (select just the project "xyz", press OK
* Default target runs
Comment 7 Michael Rennie CLA 2010-11-22 11:40:45 EST
(In reply to comment #6)
> This is working for me in 3.7

This is not working for me in I20101116-0800

using the following:

<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="default">
    <target name="default">
    	<echo>DEFAULT</echo>
    </target>
    <target name="inc">
    	<echo>INC</echo>
    </target>
	<target name="clean">
		<echo>CLEAN</echo>
	</target>
	<target name="full">
		<echo>FULL</echo>
	</target>
	<target name="auto">
		<echo>AUTO</echo>
	</target>
</project>

in file builder.ent

Steps

1. create the aforementioned file
2. create a new builder for the desired project, and point it to the build file created in step 1. Do not change to any other tabs or do anything, just click OK to create the new builder.
3. turn off auto-build
4. Press Ctrl+B you get:
Buildfile: /home/mrennie/workspaces/workspace/P3/builder.ent

default:
        [echo] DEFAULT
BUILD SUCCESSFUL
Total time: 145 milliseconds
5. Project > Clean, nothing happens
6. Project > Build Project, nothing happens
Comment 8 Michael Rennie CLA 2010-11-22 12:26:53 EST
(In reply to comment #7)

> This is not working for me in I20101116-0800

This works very strangely in 3.6.2 (M20101117-1123) as well.

Using the steps from comment #7, I get nothing happening after a Clean, and only sometimes do I get anything for a full build / project build. It seems that there may be a selection problem, because if I do the following I can always get build output for full / project build

1. select the project, Project > Clean...
2. Project > Build project, you get:
Buildfile: /home/mrennie/workspaces/workspace-3.6.1/AntTest/builder.ent

default:
        [echo] DEFAULT
BUILD SUCCESSFUL
Total time: 137 milliseconds
3. Project > Clean, Project > Build project, nothing happens

NB: if you go to the package / project explorer and re-select (the already selected) project before step 3, then it will work.
Comment 9 Dani Megert CLA 2010-11-23 03:04:57 EST
No idea whether related or not, but thought I mention it here: bug 323588.
Comment 10 Szymon Ptaszkiewicz CLA 2010-11-24 09:04:07 EST
There is also bug 207883 that seems to be quite similar to this one.
Comment 11 Michael Rennie CLA 2010-11-29 13:12:41 EST
> (In reply to comment #8)
> 
> This works very strangely in 3.6.2 (M20101117-1123) as well.

I tested this again in a fresh workspace. I think there is a lot of confusion around how the build framework works that makes this appear to not work.

Steps
1. create a new workspace
2. create a new project
3. create builder.ent as mentioned in comment #7
4. turn off autobuild
5. add builder.ent to the project as an Ant builder. Don't change any of the settings, press OK

At this point the project has no previous built state

6. Ctrl+B ( or Project > Build Project) - default target runs [OK]
7. Project > Clean, select the project, uncheck 'start build immediately' - nothing happens [OK]
8. Ctrl+B (or Project > Build Project) - default target run [OK]
9. Project > Clean , select project, check 'start build immediately' - default target runs [OK]
10. Ctrl+B (or Project > Build Project) - nothing happens, because the project is built (has a built state) [OK]
11. Create a class file as mentioned in comment #6
12. edit the class, save, Ctrl+b (or Project > Build Project) default target runs [OK]

I think the confusion comes in when a user tries to get the Ant builder to run when there is a built state for the project - meaning the project has already been built and no changes have been made to it since the last time the builder ran. In this case all build commands will do nothing except for Project > Clean, even then if 'start build immediately' is unchecked the clean build command will do nothing. These are the expected results.

I am wondering now if I fell victim to the same problem in comment #7 step 5:

> 5. Project > Clean, nothing happens

where I forgot to check on 'start build immediately'

I am getting the feeling that trying to get the Ant builder to run successively without cleaning the project or making changes to it is what is throwing people off.
Comment 12 Michael Rennie CLA 2010-11-29 16:59:48 EST
I did find a failing case:

steps from comment #11 with a change to step 5:

5a. go to the targets tab and remove the default target from the After a Clean section

Once this has been done the Project > Build Project command will not do anything regardless of cleans between build attempts. However the Ctrl+B (Project > Build All) will still work.

The problem is that Project > Build Project triggers an incremental build (build trigger == 10), so if there are no changes in the project, even cleaning it ahead of time will not cause a build.

The problem appears to be in the code AntBuilderTargetsTab#performApply(..).
In there we only set the INCREMENTAL build trigger for manual builds and I don't see any history describing why. I would assume we would set the FULL *and* INCREMENTAL triggers.

Darin S, do you recall any history on why we only set INCREMENTAL for a trigger kind on Manual as opposed to INCREMENTAL *and* FULL?
Comment 13 Michael Rennie CLA 2010-11-29 17:06:04 EST
Created attachment 184083 [details]
proposed fix

This patch fixes up AntBuilderTargetsTab and ExternalToolsBuilderTab to set the FULL kind for Manual as well as INCREMENTAL.

It fixes the use case mentioned in the previous comment and does not always cause a full build (what we want) - it only causes a full build when a clean has been done since the last build, incremental building works as it did before.

The only related bug to the handling of the build types is bug 63685.
Comment 14 Michael Rennie CLA 2011-01-24 12:57:05 EST
applied patch to HEAD for 3.7M5
Comment 15 Michael Rennie CLA 2011-01-31 16:11:38 EST
*** Bug 160895 has been marked as a duplicate of this bug. ***
Comment 16 Michael Rennie CLA 2011-01-31 16:11:50 EST
*** Bug 196811 has been marked as a duplicate of this bug. ***
Comment 17 Michael Rennie CLA 2011-02-02 14:28:09 EST
*** Bug 335998 has been marked as a duplicate of this bug. ***
Comment 18 Michael Rennie CLA 2011-02-02 14:29:36 EST
Reopening.

The proposed fix, while it does cause the correct build kind to occur, causes a UI quirk as outlined in bug 335998.
Comment 19 Michael Rennie CLA 2011-02-02 17:10:41 EST
Created attachment 188199 [details]
update

This patch changes the solution a bit, so that the launch configuration backing the builder is no longer affected - no longer causing bug 335998.

Instead of adding the 'full' build kind to the configuration, this patch moves the solution to BuilderCoreUtils#configureTriggers(...), where we actually write out the build command for the project based on what is in the configuration. 

So now when we are configuring the build command, if the clean targets are not to be used (config value is null and 'full' is not set as a build kind) and we have manual targets specified (default or specific), we add an entry in the build command that it should answer 'yes' to running for full builds, and a build argument so we know where to collect the targets from when the builder actually runs.
Comment 20 Michael Rennie CLA 2011-02-09 13:03:49 EST
Created attachment 188608 [details]
patch + regression tests

This is an updated patch that has regression tests for the new behavior.

The tests can be found in BuilderCoreUtilsTests in the Ant UI test bundle.
Comment 21 Michael Rennie CLA 2011-02-11 12:19:51 EST
applied patch with tests to HEAD

Markus, please review.
Comment 22 Michael Rennie CLA 2011-02-11 12:29:02 EST
I also updated the test script to highlight expected results from the target build kinds: http://wiki.eclipse.org/Ant/Test_Script#External_Tools
Comment 23 Markus Keller CLA 2011-02-17 05:58:11 EST
In HEAD, bug 335998 is still present. Just start with a new builder with "after clean" and "manual" set to default target, and then remove the "after clean" target. When you edit the build again, the "after clean" target is set to default.

I also noticed that the Project > Clean... command is not available when the workspace only contains a project with an ant builder whose "during a clean" target is not configured. In that case, the "after clean" target is never executed.

But as soon as I add another builder, the Clean... action becomes available. The first build after a clean then executes the "after clean" target. That looks a bit strange. I would expect that either Clean... is always enabled, or that the "after clean" target is always disabled, as long as no "during a clean" target has been configured.
Comment 24 Michael Rennie CLA 2011-02-17 11:26:47 EST
Checking the patch + commit, I found that part of the fix was not included (the changes to AntBuildersTargetTab specifically) - perhaps I was stung by bug 294650.

I have committed these missing changes to HEAD.
Comment 25 Markus Keller CLA 2011-02-18 14:44:15 EST
I've checked the changes in HEAD of ExternalToolBuilder, BuilderCoreUtils, AntBuilderTargetsTab, ExternalToolsBuilderTab.

The behavior seems right to me and the changes look good, except for a possible NPE in BuilderCoreUtils#configureTriggers(..):

"newCommand.getArguments()" can return null, so for complete safety, you have to insert this before calling args.put(..):

			if (args == null)
				args = new HashMap(1);
Comment 26 Michael Rennie CLA 2011-02-22 10:20:00 EST
(In reply to comment #25)
> "newCommand.getArguments()" can return null, so for complete safety, you have
> to insert this before calling args.put(..):
> 
>             if (args == null)
>                 args = new HashMap(1);

Good idea. I have added the suggested null check to HEAD.
Comment 27 Michael Rennie CLA 2011-02-22 10:22:52 EST
Thanks for verifying Markus.