Bug 20336 - [ExternalTools] Need variable to identify build kind
Summary: [ExternalTools] Need variable to identify build kind
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 major (vote)
Target Milestone: 2.0 F4   Edit
Assignee: Ryan Cooper CLA
QA Contact:
URL:
Whiteboard:
Keywords: ui
Depends on:
Blocks:
 
Reported: 2002-06-14 09:42 EDT by Rodrigo Peretti CLA
Modified: 2002-09-18 13:58 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rodrigo Peretti CLA 2002-06-14 09:42:00 EDT
build F3

We need a new variable in external tools to indicate the build kind. Without 
it, the external tools builders mechanism is incomplete. If it is an easy fix 
I suggest fixing for F4.

From the newsgroup:
"
hi all,
is it possible to configure an external tool to only run when the project
is explicitly build, as opposed to the incremental build i get when i
compile?

it would be cool to be able to generate xdoclet code when i explicitly
build the project, but its just plain annoying to have it happend every
time i save

sincerely
morten wilken"
Comment 1 Nick Edgar CLA 2002-06-16 21:26:33 EDT
Agree that not being able to do this makes this feature essentially unusable.

Should be able to configure the kinds of builds for which an external tool 
builder runs.  This was originally planned, but did not make it into the UI.
Adding the UI at this stage is too risky.

Adding a variable is less risky, and would be valuable even if we did have 
such UI support.  Should consider for F4.

Ryan and Simon, please assess risk of adding this and annotate PR, preferably 
with code snippets.
Comment 2 Simon Arsenault CLA 2002-06-17 11:18:38 EDT
Would the option of only running on full builds and never on incremental builds 
be acceptable instead of the variable solution?
Comment 3 Rodrigo Peretti CLA 2002-06-17 11:24:25 EDT
It helps but does not give a lot of flexibility.
Comment 4 Ryan Cooper CLA 2002-06-17 11:57:37 EDT
I would judge the risk of adding this to be low, because although it involves 
changes to several classes, they are all minor changes and do not affect the 
behaviour of the component unless the user makes use of the new variable.

I have a potential solution. Following is a summary of the necessary code 
changes. I have a ZIP of the changes available if needed. Please comment.

ExternalTool would have the most changes:

ADD	private static final String TAG_TOOL_FULL_BUILD_ONLY = "!
{tool_show_log}"; //$NON-NLS-1$

ADD	public static final String VAR_FULL_BUILD_ONLY = "full_build_only"; //
$NON-NLS-1$

ADD	private boolean fullBuildOnly = false;

ADD	get and set methods for fullBuildOnly

ADD an argument [boolean fullBuildOnly] to the ExternalTools constructor and 
modify the constructor call in fromArgumentMap(mar args)

ADD to fromArgumentMap(Map ags):
	String sFullBuildOnly = (String)args.get(TAG_TOOL_FULL_BUILD_ONLY);
	boolean fullBuildOnly;
	if (FALSE.equals(sFullBuildOnly))
		fullBuildOnly = false;
	else
		fullBuildOnly = true;

ADD to toArgumentMap():
	if (fullBuildOnly)
		args.put(TAG_TOOL_FULL_BUILD_ONLY, TRUE);
	else
		args.put(TAG_TOOL_FULL_BUILD_ONLY, FALSE);


OTHER CHANGES:
ADD to DefaultRunnerContext.expandVariable(VariableDefinintion, StringBuffer, 
boolean):
	if (tool.VAR_FULL_BUILD_ONLY.equals(varDef.name)) {
		tool.setFullBuildOnly(true);
	} else {
		tool.setFullBuildOnly(false);
	}

ExternalToolBuilder.build(...):
ExternalTool tool = ExternalTool.fromArgumentMap(args);
if (tool != null) {
/* ADD THE FOLLOWING IF BLOCK */
	if (kind != IncrementalProjectBuilder.FULL_BUILD && 
tool.getFullBuildOnly()) { 
		return null; 
	}
		
ADD to EditDialog.okPressed():
	// Set the tool's fullBuildOnly flag to be true 
	// if ExternalTool.VAR_FULL_BUILD_ONLY was one of
	// the tool's arguments, or to false otherwise.
	String temp = argumentsField.getText().trim();
	int index  = temp.indexOf(ExternalTool.VAR_FULL_BUILD_ONLY);
	if (index > 0) {
		tool.setFullBuildOnly(true);	
	} else {
		tool.setFullBuildOnly(false);
	}
Comment 5 Nick Edgar CLA 2002-06-17 12:07:44 EDT
This looks like adding a variable to the command line changes when the tool is 
run, rather than simply expanding the variable to indicate the type of build.

Although we would like to be able to say when a tool runs, this should be done 
through new UI, not through a variable.

Also, we have 3 kinds of build: full, incremental and autobuild.
It may well be that a tool wants to run for full and manual incremental builds 
but not autobuilds.  

We should add a variable, e.g. ${BUILD_KIND} which simply expands 
to "full", "incremental" or "auto" accordingly.
This can then be used within an Ant script to trigger the appropriate target.
Or, the script could define targets with the same name and the command line 
could just specify: -target ${BUILD_KIND}.
Comment 6 Nick Edgar CLA 2002-06-17 13:15:10 EDT
Adding the ${BUILD_KIND} variable does not address the original problem, unless 
the user is willing to wrap the javadoc tool in an Ant script.

The right solution is to add 3 checkboxes, with defaults as follows:

Run on: [X] Full build  [ ] Manual incremental build  [ ] Auto-build

These would only appear on the new/edit external tool builder dialog, not the 
regular new/edit external tool dialog.

This change is too large and too late to consider for 2.0 though.

The best we could do is add the ${BUILD_KIND} variable and require external 
tool builders to use Ant.

Comment 7 Ryan Cooper CLA 2002-06-18 09:33:04 EDT
Running an empty ant script takes about 2 seconds. If we add the build kind 
variable and pass it through, and the script checks it and does nothing for 
the "wrong" kinds of builds, there will still be a 2 second delay for 
the "wrong" builds.

With this in mind, are we gaining enough from adding the build kind variable to 
make it worthwhile to add it for 2.0? Or should we wait until we can add a full 
(checkbox) solution after 2.0?
Comment 8 Jim des Rivieres CLA 2002-06-18 13:17:52 EDT
The main problem here is that were are not providing a parameter (Nick's 
${BUILD_KIND}) that allows the tool script to determine what kind of build is 
being done. This functionality was in the original plan but was never 
implemented. With that variable, it is easy for a user to tailor their 
builder's behavior to the different kinds of builds. This variable should be 
added. Introducing a new parameter should be straightforward (the substitution 
mechanism is already there and working). This would makes the functionality 
useable.

Ryan's observation that it is taking a long time (2 seconds) to invoke a 
trivial Ant script suggests that there is another problem. It is hard to 
believe why Ant should be so slow, especially given that Ant is being invoked 
from the same OS process. However, this is a different problem, and should be 
entered as a separate bug report.
Comment 9 Simon Arsenault CLA 2002-06-18 13:40:43 EDT
True, it was mentionned in the original design document the "build type" 
variable, I must have missed it.

Nevertheless, even if we provided this variable, it does not solve the original 
problem - running an external EXE program (not an Ant script).

We can provide the variable, but more importantly, tools need an new attribute 
on what build type they should run - that away we avoid all the overhead of 
setting up running the tool.

Given we are so close to freezing the code for release 2.0, the best option is 
to disable external tools in the build process for now until it can be properly 
done after release 2.0
Comment 10 Rodrigo Peretti CLA 2002-06-18 13:51:50 EDT
Users could run an EXE or batch files using Ant scripts as a workaround if 
only the variable ${BUILD_KIND} was provided. I'm not sure disabling external 
tools is an option at this point.
Comment 11 Rodrigo Peretti CLA 2002-06-18 14:08:30 EDT
About the 2 seconds problem. It does not seem alarming but we do need more 
investigation on it. Every time an Ant script is run we create a new 
classloader and put all the necessary JARs in the classpath (ant.jar, 
xerces.jar, etc...). Given it has to load all the necessary classes again and 
again it might be where the time is going. We do that for the user to be able 
to extend the Ant classpath at runtime. But I agree there could be some kind 
of optimization in this area after 2.0. See bug 20557.
Comment 12 Nick Edgar CLA 2002-06-18 14:55:40 EDT
Should add the variable.  It should be possible to set up a batch file to test 
the variable without the overhead of invoking Ant.
Comment 13 Nick Edgar CLA 2002-06-18 15:00:32 EDT
Should call it "build type", ${build_type} instead of "build kind" as per the 
original proposal.

To simplify the fix, we can keep the same UI for the interactive external tool 
dialog and the external tool builder dialog, just change how this variable is 
bound.  When run interactively, it can be bound to "none".
When run as a builder, it should be bound to "full", "incremental" or "auto".

Comment 14 Simon Arsenault CLA 2002-06-19 14:01:48 EDT
Ryan made the requested changes as per Nick's comments above.

Checked by Tod and Simon