Skip to content

Commit aa2320a

Browse files
author
Jaroslav Tulach
committed
Merge pull request #275 in G/mx from ~JAROSLAV.TULACH_ORACLE.COM/mx:HintsPerProject to master
* commit '4f8356248e83ed8cc5781631c8a42e3bdbdc79d0': Up-to-date check that can notice touch of build.xml, nbproject/project.xml and nbproject/project.properties files Put NetBeans configuration files into netbeans-settings directory Moving the cfg_hints.xml into a separate file Configure the NetBeans hints per each mx project
2 parents 0868e16 + 4f83562 commit aa2320a

File tree

2 files changed

+136
-6
lines changed

2 files changed

+136
-6
lines changed

mx.py

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,12 +1609,29 @@ def eclipse_settings_sources(self):
16091609
"""
16101610
nyi('eclipse_settings_sources', self)
16111611

1612+
def netbeans_settings_sources(self):
1613+
"""
1614+
Gets a dictionary from the name of an NetBeans settings file to
1615+
the list of files providing its generated content, in overriding order
1616+
(i.e., settings from files later in the list override settings from
1617+
files earlier in the list).
1618+
A new dictionary is created each time this method is called so it's
1619+
safe for the caller to modify it.
1620+
"""
1621+
nyi('netbeans_settings_sources', self)
1622+
16121623
def eclipse_config_up_to_date(self, configZip):
16131624
"""
16141625
Determines if the zipped up Eclipse configuration
16151626
"""
16161627
return True
16171628

1629+
def netbeans_config_up_to_date(self, configZip):
1630+
"""
1631+
Determines if the zipped up NetBeans configuration
1632+
"""
1633+
return True
1634+
16181635
def get_javac_lint_overrides(self):
16191636
"""
16201637
Gets a string to be added to the -Xlint javac option.
@@ -1797,6 +1814,23 @@ def eclipse_config_up_to_date(self, configZip):
17971814
return False
17981815
return True
17991816

1817+
def netbeans_config_up_to_date(self, configZip):
1818+
for _, sources in self.netbeans_settings_sources().iteritems():
1819+
for source in sources:
1820+
if configZip.isOlderThan(source):
1821+
return False
1822+
1823+
if configZip.isOlderThan(join(self.dir, 'build.xml')):
1824+
return False
1825+
1826+
if configZip.isOlderThan(join(self.dir, 'nbproject/project.xml')):
1827+
return False
1828+
1829+
if configZip.isOlderThan(join(self.dir, 'nbproject/project.properties')):
1830+
return False
1831+
1832+
return True
1833+
18001834
def eclipse_settings_sources(self):
18011835
"""
18021836
Gets a dictionary from the name of an Eclipse settings file to
@@ -1819,6 +1853,25 @@ def eclipse_settings_sources(self):
18191853

18201854
return esdict
18211855

1856+
def netbeans_settings_sources(self):
1857+
"""
1858+
Gets a dictionary from the name of an NetBeans settings file to
1859+
the list of files providing its generated content, in overriding order
1860+
(i.e., settings from files later in the list override settings from
1861+
files earlier in the list).
1862+
A new dictionary is created each time this method is called so it's
1863+
safe for the caller to modify it.
1864+
"""
1865+
nbdict = self.suite.netbeans_settings_sources()
1866+
1867+
# check for project overrides
1868+
projectSettingsDir = join(self.dir, 'netbeans-settings')
1869+
if exists(projectSettingsDir):
1870+
for name in os.listdir(projectSettingsDir):
1871+
nbdict.setdefault(name, []).append(os.path.abspath(join(projectSettingsDir, name)))
1872+
1873+
return nbdict
1874+
18221875
def find_classes_with_annotations(self, pkgRoot, annotations, includeInnerClasses=False):
18231876
"""
18241877
Scan the sources of this project for Java source files containing a line starting with 'annotation'
@@ -6946,6 +6999,29 @@ def eclipse_settings_sources(self):
69466999
esdict.setdefault(name, []).append(os.path.abspath(join(eclipseSettingsDir, name)))
69477000
return esdict
69487001

7002+
def netbeans_settings_sources(self):
7003+
"""
7004+
Gets a dictionary from the name of an NetBeans settings file to
7005+
the list of files providing its generated content, in overriding order
7006+
(i.e., settings from files later in the list override settings from
7007+
files earlier in the list).
7008+
A new dictionary is created each time this method is called so it's
7009+
safe for the caller to modify it.
7010+
"""
7011+
esdict = {}
7012+
# start with the mxtool defaults
7013+
defaultNetBeansSuiteDir = join(_mx_suite.dir, 'netbeans-settings')
7014+
if exists(defaultNetBeansSuiteDir):
7015+
for name in os.listdir(defaultNetBeansSuiteDir):
7016+
esdict[name] = [os.path.abspath(join(defaultNetBeansSuiteDir, name))]
7017+
7018+
# append suite overrides
7019+
netBeansSettingsDir = join(self.mxDir, 'netbeans-settings')
7020+
if exists(netBeansSettingsDir):
7021+
for name in os.listdir(netBeansSettingsDir):
7022+
esdict.setdefault(name, []).append(os.path.abspath(join(netBeansSettingsDir, name)))
7023+
return esdict
7024+
69497025
"""
69507026
A pre-built suite downloaded from a Maven repository.
69517027
"""
@@ -11055,9 +11131,15 @@ def _check_ide_timestamp(suite, configZip, ide, settingsFile=None):
1105511131
return False
1105611132

1105711133
if ide == 'eclipse':
11058-
for p in [p for p in suite.projects]:
11059-
if not p.eclipse_config_up_to_date(configZip):
11134+
for proj in [p for p in suite.projects]:
11135+
if not proj.eclipse_config_up_to_date(configZip):
11136+
return False
11137+
11138+
if ide == 'netbeans':
11139+
for proj in [p for p in suite.projects]:
11140+
if not proj.netbeans_config_up_to_date(configZip):
1106011141
return False
11142+
1106111143
return True
1106211144

1106311145
EclipseLinkedResource = namedtuple('LinkedResource', ['name', 'type', 'location'])
@@ -12027,7 +12109,7 @@ def _netbeansinit_project(p, jdks=None, files=None, libFiles=None, dists=None):
1202712109
out.close('target')
1202812110
out.close('project')
1202912111
update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n'))
12030-
if files:
12112+
if files is not None:
1203112113
files.append(join(p.dir, 'build.xml'))
1203212114

1203312115
out = XMLDoc()
@@ -12074,7 +12156,7 @@ def processDep(dep, edge):
1207412156
out.close('configuration')
1207512157
out.close('project')
1207612158
update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n'))
12077-
if files:
12159+
if files is not None:
1207812160
files.append(join(p.dir, 'nbproject', 'project.xml'))
1207912161

1208012162
out = StringIO.StringIO()
@@ -12110,6 +12192,8 @@ def processDep(dep, edge):
1211012192
annotation.processing.run.all.processors=true
1211112193
application.title=""" + p.name + """
1211212194
application.vendor=mx
12195+
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsEnabled=true
12196+
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
1211312197
build.classes.dir=${build.dir}
1211412198
build.classes.excludes=**/*.java,**/*.form
1211512199
# This directory is removed when the project is cleaned:
@@ -12274,9 +12358,18 @@ def newDepsCollector(into):
1227412358

1227512359
update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue())
1227612360
out.close()
12277-
if files:
12361+
12362+
if files is not None:
1227812363
files.append(join(p.dir, 'nbproject', 'project.properties'))
1227912364

12365+
for source in p.suite.netbeans_settings_sources().get('cfg_hints.xml'):
12366+
with open(source) as fp:
12367+
content = fp.read()
12368+
update_file(join(p.dir, 'nbproject', 'cfg_hints.xml'), content)
12369+
12370+
if files is not None:
12371+
files.append(join(p.dir, 'nbproject', 'cfg_hints.xml'))
12372+
1228012373
def _netbeansinit_suite(args, suite, refreshOnly=False, buildProcessorJars=True):
1228112374
mxOutputDir = ensure_dir_exists(suite.get_mx_output_dir())
1228212375
configZip = TimeStampFile(join(mxOutputDir, 'netbeans-config.zip'))
@@ -14847,7 +14940,7 @@ def alarm_handler(signum, frame):
1484714940
# no need to show the stack trace when the user presses CTRL-C
1484814941
abort(1, killsig=signal.SIGINT)
1484914942

14850-
version = VersionSpec("5.69.1")
14943+
version = VersionSpec("5.69.2")
1485114944

1485214945
currentUmask = None
1485314946

netbeans-settings/cfg_hints.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
<?xml version="1.0" encoding="UTF-8"?>
3+
<!DOCTYPE configuration PUBLIC "-//NetBeans//DTD Tool Configuration 1.0//EN" "http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd">
4+
<configuration>
5+
<tool kind="hints" type="text/x-java">
6+
<node name="Javac_FINALLY">
7+
<attribute name="enabled" value="true"/>
8+
</node>
9+
<node name="Javac_DIVISION_BY_ZERO">
10+
<attribute name="enabled" value="true"/>
11+
</node>
12+
<node name="Javac_OVERRIDES">
13+
<attribute name="enabled" value="true"/>
14+
</node>
15+
<node name="Javac_DEPRECATED">
16+
<attribute name="enabled" value="true"/>
17+
</node>
18+
<node name="Javac_RAWTYPES">
19+
<attribute name="enabled" value="true"/>
20+
</node>
21+
<node name="Javac_UNCHECKED">
22+
<attribute name="enabled" value="true"/>
23+
</node>
24+
<node name="Javac_EMPTY_STATEMENT_AFTER_IF">
25+
<attribute name="enabled" value="true"/>
26+
</node>
27+
<node name="Javac_SERIALIZATION">
28+
<attribute name="enabled" value="true"/>
29+
</node>
30+
<node name="Javac_FALLTHROUGH">
31+
<attribute name="enabled" value="true"/>
32+
</node>
33+
<node name="Javac_UNNECESSARY_CAST">
34+
<attribute name="enabled" value="true"/>
35+
</node>
36+
</tool>
37+
</configuration>

0 commit comments

Comments
 (0)