def create_content_root(source_set): root_relative_path = os.path.join(source_set.source_base, source_set.path) return TemplateData( path=root_relative_path, sources=[ TemplateData( path=root_relative_path, package_prefix=source_set.path.replace('/', '.'), is_test=source_set.is_test, ) ], exclude_paths=[ os.path.join(source_set.source_base, x) for x in source_set.excludes ], )
def create_sourcepath(base, sources): def normalize_path_pattern(path): return '%s/' % path if not path.endswith('/') else path includes = [ normalize_path_pattern(source_set.path) for source_set in sources ] excludes = [] for source_set in sources: excludes.extend(normalize_path_pattern(exclude) for exclude in source_set.excludes) return TemplateData( base = base, includes = includes, excludes = excludes, )
def _generate_project_files(self, project, ivyfile, ivysettingsfile): def create_content_root(source_set): root_relative_path = os.path.join(source_set.source_base, source_set.path) return TemplateData( path = root_relative_path, sources = [ TemplateData( path = root_relative_path, package_prefix = source_set.path.replace('/', '.'), is_test = source_set.is_test, ) ], exclude_paths = [ os.path.join(source_set.source_base, x) for x in source_set.excludes ], ) configured_module = TemplateData( root_dir = self.root_dir, path = self.module_filename, content_roots = [ create_content_root(source_set) for source_set in project.sources ], has_bash = self.options.bash, has_python = project.has_python, has_scala = project.has_scala, has_tests = project.has_tests, has_ivy = True, ivyfile = ivyfile, ivysettingsfile = ivysettingsfile, extra_components = [], ) outdir = os.path.abspath(self.options.intellij_output_dir) if not os.path.exists(outdir): os.makedirs(outdir) configured_project = TemplateData( root_dir = self.root_dir, outdir = outdir, modules = [ configured_module ], resource_extensions = self._get_resource_extensions(project), has_scala = project.has_scala, scala = TemplateData(fsc = self.options.fsc) if project.has_scala else None, extra_checkstyle_suppression_files = project.extra_checkstyle_suppression_files, extra_components = [], ) if self.options.merge: # Grab the existing components, which may include customized ones. existing_project_components = self._parse_xml_component_elements(self.project_filename) existing_module_components = self._parse_xml_component_elements(self.module_filename) # Generate (without merging in any extra components). ipr = self._generate_to_tempfile(Generator(self.project_template, project = configured_project)) iml = self._generate_to_tempfile(Generator(self.module_template, module = configured_module)) if self.options.merge: # Get the names of the components we generated, and then delete the generated files. # Clunky, but performance is not an issue, and this is an easy way to get those component names # from the templates. extra_project_components = self._get_components_to_merge(existing_project_components, ipr) extra_module_components = self._get_components_to_merge(existing_module_components, iml) os.remove(ipr) os.remove(iml) # Generate again, with the extra components. ipr = self._generate_to_tempfile(Generator(self.project_template, project = configured_project.extend(extra_components = extra_project_components))) iml = self._generate_to_tempfile(Generator(self.module_template, module = configured_module.extend(extra_components = extra_module_components))) shutil.move(ipr, self.project_filename) shutil.move(iml, self.module_filename)
def _generate_project_files(self, project, ivyfile, ivysettingsfile): def create_content_root(source_set): root_relative_path = os.path.join(source_set.source_base, source_set.path) return TemplateData( path=root_relative_path, sources=[ TemplateData( path=root_relative_path, package_prefix=source_set.path.replace('/', '.'), is_test=source_set.is_test, ) ], exclude_paths=[ os.path.join(source_set.source_base, x) for x in source_set.excludes ], ) configured_module = TemplateData( root_dir=self.root_dir, path=self.module_filename, content_roots=[ create_content_root(source_set) for source_set in project.sources ], has_bash=self.options.bash, has_python=project.has_python, has_scala=project.has_scala, has_tests=project.has_tests, has_ivy=True, ivyfile=ivyfile, ivysettingsfile=ivysettingsfile, extra_components=[], ) outdir = os.path.abspath(self.options.intellij_output_dir) if not os.path.exists(outdir): os.makedirs(outdir) configured_project = TemplateData( root_dir=self.root_dir, outdir=outdir, modules=[configured_module], resource_extensions=self._get_resource_extensions(project), has_scala=project.has_scala, scala=TemplateData( fsc=self.options.fsc) if project.has_scala else None, extra_checkstyle_suppression_files=project. extra_checkstyle_suppression_files, extra_components=[], ) if self.options.merge: # Grab the existing components, which may include customized ones. existing_project_components = self._parse_xml_component_elements( self.project_filename) existing_module_components = self._parse_xml_component_elements( self.module_filename) # Generate (without merging in any extra components). ipr = self._generate_to_tempfile( Generator(self.project_template, project=configured_project)) iml = self._generate_to_tempfile( Generator(self.module_template, module=configured_module)) if self.options.merge: # Get the names of the components we generated, and then delete the generated files. # Clunky, but performance is not an issue, and this is an easy way to get those component names # from the templates. extra_project_components = self._get_components_to_merge( existing_project_components, ipr) extra_module_components = self._get_components_to_merge( existing_module_components, iml) os.remove(ipr) os.remove(iml) # Generate again, with the extra components. ipr = self._generate_to_tempfile( Generator(self.project_template, project=configured_project.extend( extra_components=extra_project_components))) iml = self._generate_to_tempfile( Generator(self.module_template, module=configured_module.extend( extra_components=extra_module_components))) shutil.move(ipr, self.project_filename) shutil.move(iml, self.module_filename)
def _generate_project_files(self, project, ivyfile, ivysettingsfile): def create_sourcepath(base, sources): def normalize_path_pattern(path): return '%s/' % path if not path.endswith('/') else path includes = [ normalize_path_pattern(source_set.path) for source_set in sources ] excludes = [] for source_set in sources: excludes.extend(normalize_path_pattern(exclude) for exclude in source_set.excludes) return TemplateData( base = base, includes = includes, excludes = excludes, ) configured_project = TemplateData( name = self.project_name, has_python = project.has_python ) ivyconfig = dict( ivyXmlPath = os.path.relpath(ivyfile, project.root_dir), confs = '*', ivySettingsPath = 'file://%s' % ivysettingsfile, loadSettingsOnDemand = 'false', propertyFiles = '', acceptedTypes = 'jar,bundle,ejb,maven-plugin', sourceTypes = 'source', javadocTypes = '', sourceSuffixes = '', javadocSuffixes = '', alphaOrder = 'true', resolveInWorkspace = 'false', resolveBeforeLaunch = 'false', ) outdir = os.path.abspath(self.options.eclipse_output_dir) if not os.path.exists(outdir): os.makedirs(outdir) source_sets = collections.defaultdict(OrderedSet) # base -> source_set for source_set in project.sources: source_sets[source_set.source_base].add(source_set) configured_classpath = TemplateData( sourcepaths = [ create_sourcepath(base, sources) for base, sources in source_sets.items() ], has_tests = project.has_tests, has_ivy = True, ivyconfig = urllib.urlencode(ivyconfig).replace('&', '&'), outdir = os.path.relpath(outdir, self.root_dir), ) with open(self.project_filename, 'w') as output: Generator(self.project_template, project = configured_project).write(output) with open(self.classpath_filename, 'w') as output: Generator(self.classpath_template, classpath = configured_classpath).write(output) if os.path.exists(self.pydev_filename): os.remove(self.pydev_filename) if project.has_python: with open(self.pydev_filename, 'w') as output: Generator(self.pydev_template, project = configured_project).write(output)
def test_extend(self): base = TemplateData(foo = 'bar', baz = 42) self.assertEqual(base.extend(jake = 0.3), TemplateData(baz = 42, foo = 'bar', jake = 0.3))
def test_extend(self): base = TemplateData(foo='bar', baz=42) self.assertEqual(base.extend(jake=0.3), TemplateData(baz=42, foo='bar', jake=0.3))