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

Bug 506781

Summary: Ignore optional compile problems Java build path option not honored
Product: z_Archived Reporter: Dani Megert <daniel_megert>
Component: TychoAssignee: Project Inbox <tycho-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: jan.sievers, jarthana, Lars.Vogel
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=507055
Whiteboard:

Description Dani Megert CLA 2016-10-31 06:18:24 EDT
When using
<useProjectSettings>true</useProjectSettings>
I would expect that Tycho also honors the 'Ignore optional compile problems' Java build path option.
Comment 1 Jan Sievers CLA 2016-10-31 06:59:54 EDT
we are only passing the compiler .prefs file to the JDT compiler using 


-properties <path/to/prefs>


do you have a small example project or can you elaborate a bit more on which setting should take which effect?
Comment 2 Lars Vogel CLA 2016-10-31 10:29:01 EDT
Not small but here is an example:

Clone the rt.equinox.framework repository and import the org.eclipse.osgi bundle.

Select "felix/src" folder, right-click on it and select Properties. See that "Java Compiler" has the "Ignore optional compile problems" setting.
Comment 3 Lars Vogel CLA 2016-10-31 10:30:53 EDT
With "Ignore optional compile problems" set, JDT (seems to) ignore the project settings for the corresponding source folder. For example, an unnecessary import which is set to error, is ignored.
Comment 4 Dani Megert CLA 2016-11-01 05:20:14 EDT
(In reply to Lars Vogel from comment #3)
> With "Ignore optional compile problems" set, JDT (seems to) ignore the
> project settings for the corresponding source folder. For example, an
> unnecessary import which is set to error, is ignored.

It does not ignore the settings, but simply does not report optional compile problems.
Comment 5 Dani Megert CLA 2016-11-01 05:23:59 EDT
(In reply to Jan Sievers from comment #1)
> do you have a small example project or can you elaborate a bit more on which
> setting should take which effect?

1. paste this into the Package Explorer:
import java.util.Map;
public class Test {
}
2. set the project setting for unused imports to 'Error'
3. open the Java build path settings and expand the 'src' folder
4. toggle 'Ignore optional compile problems'
==> the error is gone.

However, the Tycho build using project settings will issue the error.
Comment 6 Jan Sievers CLA 2016-11-02 05:03:36 EDT
(In reply to Dani Megert from comment #5)
> (In reply to Jan Sievers from comment #1)
> > do you have a small example project or can you elaborate a bit more on which
> > setting should take which effect?
> 
> 1. paste this into the Package Explorer:
> import java.util.Map;
> public class Test {
> }
> 2. set the project setting for unused imports to 'Error'
> 3. open the Java build path settings and expand the 'src' folder
> 4. toggle 'Ignore optional compile problems'
> ==> the error is gone.
> 
> However, the Tycho build using project settings will issue the error.

so this is a setting saved in .classpath
Right now we do not parse .classpath as this is a derived resource as far as Tycho is concerned with build.properties as the master.

if there is a corresponding switch for the JDT core CLI we could forward it. If this is handled on the (JDT) UI level only I guess it will be hard to replicate the behaviour in Tycho
Comment 7 Dani Megert CLA 2016-11-02 13:03:40 EDT
(In reply to Jan Sievers from comment #6)
> if there is a corresponding switch for the JDT core CLI we could forward it.
> If this is handled on the (JDT) UI level only I guess it will be hard to
> replicate the behaviour in Tycho

I don't think we have an option in ECJ. Jay, please confirm.
Comment 8 Jay Arthanareeswaran CLA 2016-11-03 00:34:43 EDT
(In reply to Dani Megert from comment #7)
> I don't think we have an option in ECJ. Jay, please confirm.

I wasn't aware of this before, but we do have support for this! Here's the relevant documentation:

-nowarn -warn:none disable all warnings
-nowarn:[<directories separated by {0}>]
               specify directories from which optional problems should
               be ignored

An example would be:

-nowarn:["C:\regression\src1";"C:\regression\src2"]
Comment 9 Dani Megert CLA 2016-11-03 10:11:07 EDT
(In reply to Jay Arthanareeswaran from comment #8)
> (In reply to Dani Megert from comment #7)
> > I don't think we have an option in ECJ. Jay, please confirm.
> 
> I wasn't aware of this before, but we do have support for this! Here's the
> relevant documentation:
> 
> -nowarn -warn:none disable all warnings
> -nowarn:[<directories separated by {0}>]
>                specify directories from which optional problems should
>                be ignored
> 
> An example would be:
> 
> -nowarn:["C:\regression\src1";"C:\regression\src2"]

Can one use variables? Otherwise this will not really work.
Comment 10 Jay Arthanareeswaran CLA 2016-11-03 12:21:35 EDT
(In reply to Dani Megert from comment #9)
> Can one use variables? Otherwise this will not really work.

I am not sure what you meant by variables. In any case, the answer is: no, whoever is invoking the compiler need to pass all the source folders where this particular rule should be applied.
Comment 11 Jan Sievers CLA 2016-11-04 10:59:27 EDT
(In reply to Dani Megert from comment #9)
> (In reply to Jay Arthanareeswaran from comment #8)
> > (In reply to Dani Megert from comment #7)
> > > I don't think we have an option in ECJ. Jay, please confirm.
> > 
> > I wasn't aware of this before, but we do have support for this! Here's the
> > relevant documentation:
> > 
> > -nowarn -warn:none disable all warnings
> > -nowarn:[<directories separated by {0}>]
> >                specify directories from which optional problems should
> >                be ignored
> > 
> > An example would be:
> > 
> > -nowarn:["C:\regression\src1";"C:\regression\src2"]
> 
> Can one use variables? Otherwise this will not really work.

I just verified that you can manually configure this, see sample project

https://github.com/jsievers/tycho-demo-1/tree/bug506781/itp01

commit https://github.com/jsievers/tycho-demo-1/commit/20d9feb0a27054f1567aabd81eea243bac69470f

Essentially you can use

<compilerArgs>
 <arg>-nowarn:[${project.basedir}/src]</arg>
</compilerArgs>

(or whatever source dir you want to ignore)
Comment 12 Dani Megert CLA 2016-11-04 11:02:51 EDT
(In reply to Jan Sievers from comment #11)
> Essentially you can use
> 
> <compilerArgs>
>  <arg>-nowarn:[${project.basedir}/src]</arg>
> </compilerArgs>
> 
> (or whatever source dir you want to ignore)

Thanks, that's what I was hoping.
Comment 13 Jan Sievers CLA 2016-11-04 11:15:00 EDT
just one more hint, in case you have multiple dirs it looks like you have to use OS-specific path separator

${path.separator}