Mercurial > hg > graal-compiler
comparison mxtool/mx.py @ 18147:31ad929e1afd
factored out _netbeansinit_project function
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 22 Oct 2014 20:20:42 +0200 |
parents | 1700d12ba0ad |
children | c88ab4f1f04a |
comparison
equal
deleted
inserted
replaced
18146:9db0af368bb4 | 18147:31ad929e1afd |
---|---|
4095 """(re)generate NetBeans project configurations""" | 4095 """(re)generate NetBeans project configurations""" |
4096 | 4096 |
4097 for suite in suites(True): | 4097 for suite in suites(True): |
4098 _netbeansinit_suite(args, suite, refreshOnly, buildProcessorJars) | 4098 _netbeansinit_suite(args, suite, refreshOnly, buildProcessorJars) |
4099 | 4099 |
4100 def _netbeansinit_suite(args, suite, refreshOnly=False, buildProcessorJars=True): | 4100 def _netbeansinit_project(p, jdks=None, files=None, libFiles=None): |
4101 configZip = TimeStampFile(join(suite.mxDir, 'netbeans-config.zip')) | 4101 if not exists(join(p.dir, 'nbproject')): |
4102 configLibsZip = join(suite.mxDir, 'eclipse-config-libs.zip') | 4102 os.makedirs(join(p.dir, 'nbproject')) |
4103 if refreshOnly and not configZip.exists(): | 4103 |
4104 return | 4104 jdk = java(p.javaCompliance) |
4105 | 4105 assert jdk |
4106 if _check_ide_timestamp(suite, configZip, 'netbeans'): | 4106 |
4107 logv('[NetBeans configurations are up to date - skipping]') | 4107 if jdks: |
4108 return | 4108 jdks.add(jdk) |
4109 | 4109 |
4110 updated = False | 4110 out = XMLDoc() |
4111 files = [] | 4111 out.open('project', {'name' : p.name, 'default' : 'default', 'basedir' : '.'}) |
4112 libFiles = [] | 4112 out.element('description', data='Builds, tests, and runs the project ' + p.name + '.') |
4113 jdks = set() | 4113 out.element('import', {'file' : 'nbproject/build-impl.xml'}) |
4114 for p in suite.projects: | 4114 out.open('target', {'name' : '-post-compile'}) |
4115 if p.native: | 4115 out.open('exec', {'executable' : sys.executable}) |
4116 out.element('env', {'key' : 'JAVA_HOME', 'value' : jdk.jdk}) | |
4117 out.element('arg', {'value' : os.path.abspath(__file__)}) | |
4118 out.element('arg', {'value' : 'archive'}) | |
4119 out.element('arg', {'value' : '@GRAAL'}) | |
4120 out.close('exec') | |
4121 out.close('target') | |
4122 out.close('project') | |
4123 update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) | |
4124 if files: | |
4125 files.append(join(p.dir, 'build.xml')) | |
4126 | |
4127 out = XMLDoc() | |
4128 out.open('project', {'xmlns' : 'http://www.netbeans.org/ns/project/1'}) | |
4129 out.element('type', data='org.netbeans.modules.java.j2seproject') | |
4130 out.open('configuration') | |
4131 out.open('data', {'xmlns' : 'http://www.netbeans.org/ns/j2se-project/3'}) | |
4132 out.element('name', data=p.name) | |
4133 out.element('explicit-platform', {'explicit-source-supported' : 'true'}) | |
4134 out.open('source-roots') | |
4135 out.element('root', {'id' : 'src.dir'}) | |
4136 if len(p.annotation_processors()) > 0: | |
4137 out.element('root', {'id' : 'src.ap-source-output.dir', 'name' : 'Generated Packages'}) | |
4138 out.close('source-roots') | |
4139 out.open('test-roots') | |
4140 out.close('test-roots') | |
4141 out.close('data') | |
4142 | |
4143 firstDep = True | |
4144 for dep in p.all_deps([], includeLibs=False, includeAnnotationProcessors=True): | |
4145 if dep == p: | |
4116 continue | 4146 continue |
4117 | 4147 |
4118 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project | 4148 if dep.isProject(): |
4119 continue | 4149 n = dep.name.replace('.', '_') |
4120 | 4150 if firstDep: |
4121 if not exists(join(p.dir, 'nbproject')): | 4151 out.open('references', {'xmlns' : 'http://www.netbeans.org/ns/ant-project-references/1'}) |
4122 os.makedirs(join(p.dir, 'nbproject')) | 4152 firstDep = False |
4123 | 4153 |
4124 jdk = java(p.javaCompliance) | 4154 out.open('reference') |
4125 assert jdk | 4155 out.element('foreign-project', data=n) |
4126 | 4156 out.element('artifact-type', data='jar') |
4127 jdks.add(jdk) | 4157 out.element('script', data='build.xml') |
4128 | 4158 out.element('target', data='jar') |
4129 out = XMLDoc() | 4159 out.element('clean-target', data='clean') |
4130 out.open('project', {'name' : p.name, 'default' : 'default', 'basedir' : '.'}) | 4160 out.element('id', data='jar') |
4131 out.element('description', data='Builds, tests, and runs the project ' + p.name + '.') | 4161 out.close('reference') |
4132 out.element('import', {'file' : 'nbproject/build-impl.xml'}) | 4162 |
4133 out.open('target', {'name' : '-post-compile'}) | 4163 if not firstDep: |
4134 out.open('exec', {'executable' : sys.executable}) | 4164 out.close('references') |
4135 out.element('env', {'key' : 'JAVA_HOME', 'value' : jdk.jdk}) | 4165 |
4136 out.element('arg', {'value' : os.path.abspath(__file__)}) | 4166 out.close('configuration') |
4137 out.element('arg', {'value' : 'archive'}) | 4167 out.close('project') |
4138 out.element('arg', {'value' : '@GRAAL'}) | 4168 update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) |
4139 out.close('exec') | 4169 if files: |
4140 out.close('target') | |
4141 out.close('project') | |
4142 updated = update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) or updated | |
4143 files.append(join(p.dir, 'build.xml')) | |
4144 | |
4145 out = XMLDoc() | |
4146 out.open('project', {'xmlns' : 'http://www.netbeans.org/ns/project/1'}) | |
4147 out.element('type', data='org.netbeans.modules.java.j2seproject') | |
4148 out.open('configuration') | |
4149 out.open('data', {'xmlns' : 'http://www.netbeans.org/ns/j2se-project/3'}) | |
4150 out.element('name', data=p.name) | |
4151 out.element('explicit-platform', {'explicit-source-supported' : 'true'}) | |
4152 out.open('source-roots') | |
4153 out.element('root', {'id' : 'src.dir'}) | |
4154 if len(p.annotation_processors()) > 0: | |
4155 out.element('root', {'id' : 'src.ap-source-output.dir', 'name' : 'Generated Packages'}) | |
4156 out.close('source-roots') | |
4157 out.open('test-roots') | |
4158 out.close('test-roots') | |
4159 out.close('data') | |
4160 | |
4161 firstDep = True | |
4162 for dep in p.all_deps([], includeLibs=False, includeAnnotationProcessors=True): | |
4163 if dep == p: | |
4164 continue | |
4165 | |
4166 if dep.isProject(): | |
4167 n = dep.name.replace('.', '_') | |
4168 if firstDep: | |
4169 out.open('references', {'xmlns' : 'http://www.netbeans.org/ns/ant-project-references/1'}) | |
4170 firstDep = False | |
4171 | |
4172 out.open('reference') | |
4173 out.element('foreign-project', data=n) | |
4174 out.element('artifact-type', data='jar') | |
4175 out.element('script', data='build.xml') | |
4176 out.element('target', data='jar') | |
4177 out.element('clean-target', data='clean') | |
4178 out.element('id', data='jar') | |
4179 out.close('reference') | |
4180 | |
4181 if not firstDep: | |
4182 out.close('references') | |
4183 | |
4184 out.close('configuration') | |
4185 out.close('project') | |
4186 updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) or updated | |
4187 files.append(join(p.dir, 'nbproject', 'project.xml')) | 4170 files.append(join(p.dir, 'nbproject', 'project.xml')) |
4188 | 4171 |
4189 out = StringIO.StringIO() | 4172 out = StringIO.StringIO() |
4190 jdkPlatform = 'JDK_' + str(jdk.version) | 4173 jdkPlatform = 'JDK_' + str(jdk.version) |
4191 | 4174 |
4192 annotationProcessorEnabled = "false" | 4175 annotationProcessorEnabled = "false" |
4193 annotationProcessorReferences = "" | 4176 annotationProcessorSrcFolder = "" |
4194 annotationProcessorSrcFolder = "" | 4177 if len(p.annotation_processors()) > 0: |
4195 if len(p.annotation_processors()) > 0: | 4178 annotationProcessorEnabled = "true" |
4196 annotationProcessorEnabled = "true" | 4179 genSrcDir = p.source_gen_dir() |
4197 genSrcDir = p.source_gen_dir() | 4180 if not exists(genSrcDir): |
4198 if not exists(genSrcDir): | 4181 os.makedirs(genSrcDir) |
4199 os.makedirs(genSrcDir) | 4182 annotationProcessorSrcFolder = "src.ap-source-output.dir=" + genSrcDir |
4200 annotationProcessorSrcFolder = "src.ap-source-output.dir=" + genSrcDir | 4183 |
4201 | 4184 content = """ |
4202 content = """ | |
4203 annotation.processing.enabled=""" + annotationProcessorEnabled + """ | 4185 annotation.processing.enabled=""" + annotationProcessorEnabled + """ |
4204 annotation.processing.enabled.in.editor=""" + annotationProcessorEnabled + """ | 4186 annotation.processing.enabled.in.editor=""" + annotationProcessorEnabled + """ |
4205 annotation.processing.processors.list= | 4187 annotation.processing.processors.list= |
4206 annotation.processing.run.all.processors=true | 4188 annotation.processing.run.all.processors=true |
4207 application.title=""" + p.name + """ | 4189 application.title=""" + p.name + """ |
4216 build.test.classes.dir=${build.dir}/test/classes | 4198 build.test.classes.dir=${build.dir}/test/classes |
4217 build.test.results.dir=${build.dir}/test/results | 4199 build.test.results.dir=${build.dir}/test/results |
4218 # Uncomment to specify the preferred debugger connection transport: | 4200 # Uncomment to specify the preferred debugger connection transport: |
4219 #debug.transport=dt_socket | 4201 #debug.transport=dt_socket |
4220 debug.classpath=\\ | 4202 debug.classpath=\\ |
4221 ${run.classpath} | 4203 ${run.classpath} |
4222 debug.test.classpath=\\ | 4204 debug.test.classpath=\\ |
4223 ${run.test.classpath} | 4205 ${run.test.classpath} |
4224 # This directory is removed when the project is cleaned: | 4206 # This directory is removed when the project is cleaned: |
4225 dist.dir=dist | 4207 dist.dir=dist |
4226 dist.jar=${dist.dir}/""" + p.name + """.jar | 4208 dist.jar=${dist.dir}/""" + p.name + """.jar |
4227 dist.javadoc.dir=${dist.dir}/javadoc | 4209 dist.javadoc.dir=${dist.dir}/javadoc |
4228 endorsed.classpath= | 4210 endorsed.classpath= |
4233 javac.compilerargs=-XDignore.symbol.file | 4215 javac.compilerargs=-XDignore.symbol.file |
4234 javac.deprecation=false | 4216 javac.deprecation=false |
4235 javac.source=""" + str(p.javaCompliance) + """ | 4217 javac.source=""" + str(p.javaCompliance) + """ |
4236 javac.target=""" + str(p.javaCompliance) + """ | 4218 javac.target=""" + str(p.javaCompliance) + """ |
4237 javac.test.classpath=\\ | 4219 javac.test.classpath=\\ |
4238 ${javac.classpath}:\\ | 4220 ${javac.classpath}:\\ |
4239 ${build.classes.dir} | 4221 ${build.classes.dir} |
4240 javadoc.additionalparam= | 4222 javadoc.additionalparam= |
4241 javadoc.author=false | 4223 javadoc.author=false |
4242 javadoc.encoding=${source.encoding} | 4224 javadoc.encoding=${source.encoding} |
4243 javadoc.noindex=false | 4225 javadoc.noindex=false |
4244 javadoc.nonavbar=false | 4226 javadoc.nonavbar=false |
4253 meta.inf.dir=${src.dir}/META-INF | 4235 meta.inf.dir=${src.dir}/META-INF |
4254 mkdist.disabled=false | 4236 mkdist.disabled=false |
4255 platforms.""" + jdkPlatform + """.home=""" + jdk.jdk + """ | 4237 platforms.""" + jdkPlatform + """.home=""" + jdk.jdk + """ |
4256 platform.active=""" + jdkPlatform + """ | 4238 platform.active=""" + jdkPlatform + """ |
4257 run.classpath=\\ | 4239 run.classpath=\\ |
4258 ${javac.classpath}:\\ | 4240 ${javac.classpath}:\\ |
4259 ${build.classes.dir} | 4241 ${build.classes.dir} |
4260 # Space-separated list of JVM arguments used when running the project | 4242 # Space-separated list of JVM arguments used when running the project |
4261 # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value | 4243 # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value |
4262 # or test-sys-prop.name=value to set system properties for unit tests): | 4244 # or test-sys-prop.name=value to set system properties for unit tests): |
4263 run.jvmargs= | 4245 run.jvmargs= |
4264 run.test.classpath=\\ | 4246 run.test.classpath=\\ |
4265 ${javac.test.classpath}:\\ | 4247 ${javac.test.classpath}:\\ |
4266 ${build.test.classes.dir} | 4248 ${build.test.classes.dir} |
4267 test.src.dir=./test | 4249 test.src.dir=./test |
4268 """ + annotationProcessorSrcFolder + """ | 4250 """ + annotationProcessorSrcFolder + """ |
4269 source.encoding=UTF-8""".replace(':', os.pathsep).replace('/', os.sep) | 4251 source.encoding=UTF-8""".replace(':', os.pathsep).replace('/', os.sep) |
4270 print >> out, content | 4252 print >> out, content |
4271 | 4253 |
4272 mainSrc = True | 4254 mainSrc = True |
4273 for src in p.srcDirs: | 4255 for src in p.srcDirs: |
4274 srcDir = join(p.dir, src) | 4256 srcDir = join(p.dir, src) |
4275 if not exists(srcDir): | 4257 if not exists(srcDir): |
4276 os.mkdir(srcDir) | 4258 os.mkdir(srcDir) |
4277 ref = 'file.reference.' + p.name + '-' + src | 4259 ref = 'file.reference.' + p.name + '-' + src |
4278 print >> out, ref + '=' + src | 4260 print >> out, ref + '=' + src |
4279 if mainSrc: | 4261 if mainSrc: |
4280 print >> out, 'src.dir=${' + ref + '}' | 4262 print >> out, 'src.dir=${' + ref + '}' |
4281 mainSrc = False | 4263 mainSrc = False |
4282 else: | 4264 else: |
4283 print >> out, 'src.' + src + '.dir=${' + ref + '}' | 4265 print >> out, 'src.' + src + '.dir=${' + ref + '}' |
4284 | 4266 |
4285 javacClasspath = [] | 4267 javacClasspath = [] |
4286 | 4268 |
4287 deps = p.all_deps([], True) | 4269 deps = p.all_deps([], True) |
4288 annotationProcessorOnlyDeps = [] | 4270 annotationProcessorOnlyDeps = [] |
4289 if len(p.annotation_processors()) > 0: | 4271 if len(p.annotation_processors()) > 0: |
4290 for ap in p.annotation_processors(): | 4272 for ap in p.annotation_processors(): |
4291 apDep = dependency(ap) | 4273 apDep = dependency(ap) |
4292 if not apDep in deps: | 4274 if not apDep in deps: |
4293 deps.append(apDep) | 4275 deps.append(apDep) |
4294 annotationProcessorOnlyDeps.append(apDep) | 4276 annotationProcessorOnlyDeps.append(apDep) |
4295 | 4277 |
4296 annotationProcessorReferences = [] | 4278 annotationProcessorReferences = [] |
4297 | 4279 |
4298 for dep in deps: | 4280 for dep in deps: |
4299 if dep == p: | 4281 if dep == p: |
4300 continue | 4282 continue |
4301 | 4283 |
4302 if dep.isLibrary(): | 4284 if dep.isLibrary(): |
4303 path = dep.get_path(resolve=True) | 4285 path = dep.get_path(resolve=True) |
4304 if path: | 4286 if path: |
4305 if os.sep == '\\': | 4287 if os.sep == '\\': |
4306 path = path.replace('\\', '\\\\') | 4288 path = path.replace('\\', '\\\\') |
4307 ref = 'file.reference.' + dep.name + '-bin' | 4289 ref = 'file.reference.' + dep.name + '-bin' |
4308 print >> out, ref + '=' + path | 4290 print >> out, ref + '=' + path |
4291 if libFiles: | |
4309 libFiles.append(path) | 4292 libFiles.append(path) |
4310 | 4293 |
4311 elif dep.isProject(): | 4294 elif dep.isProject(): |
4312 n = dep.name.replace('.', '_') | 4295 n = dep.name.replace('.', '_') |
4313 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/') | 4296 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/') |
4314 ref = 'reference.' + n + '.jar' | 4297 ref = 'reference.' + n + '.jar' |
4315 print >> out, 'project.' + n + '=' + relDepPath | 4298 print >> out, 'project.' + n + '=' + relDepPath |
4316 print >> out, ref + '=${project.' + n + '}/dist/' + dep.name + '.jar' | 4299 print >> out, ref + '=${project.' + n + '}/dist/' + dep.name + '.jar' |
4317 | 4300 |
4318 if not dep in annotationProcessorOnlyDeps: | 4301 if not dep in annotationProcessorOnlyDeps: |
4319 javacClasspath.append('${' + ref + '}') | 4302 javacClasspath.append('${' + ref + '}') |
4320 else: | 4303 else: |
4321 annotationProcessorReferences.append('${' + ref + '}') | 4304 annotationProcessorReferences.append('${' + ref + '}') |
4322 | 4305 |
4323 print >> out, 'javac.classpath=\\\n ' + (os.pathsep + '\\\n ').join(javacClasspath) | 4306 print >> out, 'javac.classpath=\\\n ' + (os.pathsep + '\\\n ').join(javacClasspath) |
4324 print >> out, 'javac.processorpath=' + (os.pathsep + '\\\n ').join(['${javac.classpath}'] + annotationProcessorReferences) | 4307 print >> out, 'javac.processorpath=' + (os.pathsep + '\\\n ').join(['${javac.classpath}'] + annotationProcessorReferences) |
4325 print >> out, 'javac.test.processorpath=' + (os.pathsep + '\\\n ').join(['${javac.test.classpath}'] + annotationProcessorReferences) | 4308 print >> out, 'javac.test.processorpath=' + (os.pathsep + '\\\n ').join(['${javac.test.classpath}'] + annotationProcessorReferences) |
4326 | 4309 |
4327 updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated | 4310 update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) |
4328 out.close() | 4311 out.close() |
4312 if files: | |
4329 files.append(join(p.dir, 'nbproject', 'project.properties')) | 4313 files.append(join(p.dir, 'nbproject', 'project.properties')) |
4330 | 4314 |
4331 if updated: | 4315 def _netbeansinit_suite(args, suite, refreshOnly=False, buildProcessorJars=True): |
4332 log('If using NetBeans:') | 4316 configZip = TimeStampFile(join(suite.mxDir, 'netbeans-config.zip')) |
4333 # http://stackoverflow.com/questions/24720665/cant-resolve-jdk-internal-package | 4317 configLibsZip = join(suite.mxDir, 'eclipse-config-libs.zip') |
4334 log(' 1. Edit etc/netbeans.conf in your NetBeans installation and modify netbeans_default_options variable to include "-J-DCachingArchiveProvider.disableCtSym=true"') | 4318 if refreshOnly and not configZip.exists(): |
4335 log(' 2. Ensure that the following platform(s) are defined (Tools -> Java Platforms):') | 4319 return |
4336 for jdk in jdks: | 4320 |
4337 log(' JDK_' + str(jdk.version)) | 4321 if _check_ide_timestamp(suite, configZip, 'netbeans'): |
4338 log(' 3. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)') | 4322 logv('[NetBeans configurations are up to date - skipping]') |
4323 return | |
4324 | |
4325 files = [] | |
4326 libFiles = [] | |
4327 jdks = set() | |
4328 for p in suite.projects: | |
4329 if p.native: | |
4330 continue | |
4331 | |
4332 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project | |
4333 continue | |
4334 | |
4335 _netbeansinit_project(p, jdks, files, libFiles) | |
4336 | |
4337 log('If using NetBeans:') | |
4338 # http://stackoverflow.com/questions/24720665/cant-resolve-jdk-internal-package | |
4339 log(' 1. Edit etc/netbeans.conf in your NetBeans installation and modify netbeans_default_options variable to include "-J-DCachingArchiveProvider.disableCtSym=true"') | |
4340 log(' 2. Ensure that the following platform(s) are defined (Tools -> Java Platforms):') | |
4341 for jdk in jdks: | |
4342 log(' JDK_' + str(jdk.version)) | |
4343 log(' 3. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)') | |
4339 | 4344 |
4340 _zip_files(files, suite.dir, configZip.path) | 4345 _zip_files(files, suite.dir, configZip.path) |
4341 _zip_files(libFiles, suite.dir, configLibsZip) | 4346 _zip_files(libFiles, suite.dir, configLibsZip) |
4342 | 4347 |
4343 def intellijinit(args, refreshOnly=False): | 4348 def intellijinit(args, refreshOnly=False): |