def execute_main():

	parser = argparse.ArgumentParser(description='Reads an xml model of a Software Product Line generated for the tool SPLConqueror and generate a clafer model.')
	
	parser.add_argument('--property', type=str, default="footprint", help='Function property to annotate feature model with')
	
	parser.add_argument('feature_model_xml_filename', metavar='F', type=str, nargs=1,
	                   help='SPLConqeuror Feature model in xml.')
	
	parser.add_argument('measurment_results_xml_filename', metavar='MR', type=str, nargs=1,
	                   help='SPLConqueror xml file with quality properties feature values.')
	
	args = parser.parse_args()
		
	xml_model = load_xml_model(args.feature_model_xml_filename[0])
	xml_model_measurementresuelt = load_xml_model(args.measurment_results_xml_filename[0])
	
	featureValues = {}
	for row in xml_model_measurementresuelt.findall('row'):
		featureValues[row.find("data[@columnname='Name']").text] = row.find("data[@columnname='Value']").text.replace(",", ".")

	for feature in get_features_and_code_units(xml_model):
		print "\t<%s id=\"%s\">" %  ( feature.get('name'), feature.get('id'))
		print "\t\t<clearedValue>%s</clearedValue>" % featureValues.get(feature.get('name'), 0)
		print "\t</%s>" % feature.get('name')

	print "</measured_values>"
    def __init__(self, feature_model_filename, load_from_xml_file=True):                    
        if load_from_xml_file == True:
            self.xml_model = load_xml_model(feature_model_filename)            
        else:
            #Run clafer on "feature_model_xml_filename"
            subprocess.check_output(["clafer", "--mode=xml", feature_model_filename], stderr=subprocess.STDOUT)
            self.xml_model = load_xml_model(feature_model_filename[:-4] + ".xml")        


        self.SPL = self.get_top_level_SPL_model()
        self.SPL_concrete = self.get_concrete_SPL_configuration()
        self._non_functional_properties =  None
        self._FeatureTypes = None
        self._xml_element_from_uniqueID ={}        
        self._parentToChild = {}
        self._childToParent = {}
        self._initialize_childParentMappings()
        assert self.SPL != None
def execute_main():

    parser = argparse.ArgumentParser(
        description=
        'Reads an xml model of a Software Product Line generated for the tool SPLConqueror and generate a clafer model.'
    )

    parser.add_argument(
        '--property',
        type=str,
        default="footprint",
        help='Function property to annotate feature model with')

    parser.add_argument('feature_model_xml_filename',
                        metavar='F',
                        type=str,
                        nargs=1,
                        help='SPLConqeuror Feature model in xml.')

    parser.add_argument(
        'measurment_results_xml_filename',
        metavar='MR',
        type=str,
        nargs=1,
        help='SPLConqueror xml file with quality properties feature values.')

    args = parser.parse_args()

    xml_model = load_xml_model(args.feature_model_xml_filename[0])
    xml_model_measurementresuelt = load_xml_model(
        args.measurment_results_xml_filename[0])

    featureValues = {}
    for row in xml_model_measurementresuelt.findall('row'):
        featureValues[row.find("data[@columnname='Name']").text] = row.find(
            "data[@columnname='Value']").text.replace(",", ".")

    for feature in get_features_and_code_units(xml_model):
        print "\t<%s id=\"%s\">" % (feature.get('name'), feature.get('id'))
        print "\t\t<clearedValue>%s</clearedValue>" % featureValues.get(
            feature.get('name'), 0)
        print "\t</%s>" % feature.get('name')

    print "</measured_values>"
def show_clafers_from_alloy_solutions(spl_transformer):
    """
    Write Back Alloy Answer as Clafer, 
        : and return a list of sets for product-level attributes in the pareto front.    
    """
    configured_product_UniqueId = spl_transformer.get_clafer_UniqueId(spl_transformer.get_concrete_instance_as_xml_element())
    configured_product_label = "this/" + configured_product_UniqueId    
    product_level_values_list =[]
    i = 1
    while(os.path.exists("alloy_solutions_" + str(i)+ ".xml")):
        
        instance_xml = load_xml_model("alloy_solutions_"+ str(i) + ".xml")
        
        top_level_product_sig = instance_xml.find("./instance/sig[@label='%s']" % configured_product_label)
        top_level_product_atom = top_level_product_sig.find("./atom")
    
        product_level_values_list.append(show_clafer((top_level_product_sig, top_level_product_atom), 0, instance_xml, spl_transformer))
        #print "\n\n Product Level Values %s " % str(product_level_values) 
        i += 1
    return product_level_values_list
Example #5
0
 def __init__(self, feature_model_xml_filename):
     self.xml_model = load_xml_model(feature_model_xml_filename)
     self.SPL = self.get_top_level_SPL_model()
     self.non_functional_properties = self.compute_nonfunctional_properties(
     )
     assert self.SPL != None
def execute_main():

	parser = argparse.ArgumentParser(description='Reads an xml model of a Software Product Line generated for the tool SPLConqueror and generate a clafer model.')
	
	parser.add_argument('--scaledownby', type=float, default=1.0, help='Scaled the property by dividing y the  given value')
		
	parser.add_argument('--property', type=str, default="footprint", help='Function property to annotate feature model with')
	
	parser.add_argument('feature_model_xml_filename', metavar='F', type=str, nargs=1,
	                   help='SPLConqeuror Feature model in xml file to open.')
	
	parser.add_argument('feature_nonfunctional_properties_xml_filename', metavar='NF', type=str, nargs=1,
	                   help='SPLConqueror xml file with non functional  model of the software product line.')
	
	parser.add_argument('--fabricatebasefeature', type=str, default='',
	                   help='Fabricate a Base feature, in case there are no required features. It requires to be given a SPLConqueror XML file with detailed measurements of configurations (e.g configurations.xml)  of the software product line.')
	
	parser.add_argument('--clear_repeated_base_values', action='store_true',
						help='When there is more than one feature that is always required and they all have the same footprint, then clear all to zero except the first one.')
	
	args = parser.parse_args()
	
	
	print_abstract_IMeasurable(args, property=args.property)
	
	 
	xml_model = load_xml_model(args.feature_model_xml_filename[0])
	xml_model_nfp = load_xml_model(args.feature_nonfunctional_properties_xml_filename[0])
	
	if args.fabricatebasefeature != '':
		xml_model_configurations = load_xml_model(args.fabricatebasefeature)
	
	tab_dictionary = {}
	Constraint_Summation = []
	
	
	List_Mandatory_Base_Features = get_mandatory_base_features(xml_model)
	set_List_Mandatory_Base_Features(List_Mandatory_Base_Features)
	
	
	print "abstract %s" % xml_model.get('name')
	
	features_and_code_units = xml_model.findall("element[@type='feature']")
	features_and_code_units.extend(xml_model.findall("element[@type='code unit']") )
	features_and_code_units = sorted(features_and_code_units, key=lambda element: '_'.join([x.get('id') for x in get_path_from_root(xml_model, element)]) )
	
	for featureelement in features_and_code_units:
		# Got Indentation level.
		num_tabs = compute_tab_level(tab_dictionary, featureelement, xml_model)
	
		group_cardinality, is_exclusive_or_partial, is_or_partial  =  compute_group_cardinality(xml_model, featureelement)
		is_optional = compute_is_optional(featureelement)
		
	
		for tmp in range(num_tabs): print "\t",
		print "%s%s : IMeasurable %s" % (group_cardinality, featureelement.get('name').replace("=","_EQ_"), is_optional)
	
		
		# Print any exlcudes constraint.
		for excludes_ref  in featureelement.findall("constraints/constraint[@type='excludes']/constraint_element"):
			for tmp in range(num_tabs): print "\t",
			print "\t[ !%s ]" % ( excludes_ref.find('name').text,)
	
		# TODO Print any requires constraint.
		all_requires_constraint = featureelement.findall("constraints/constraint[@type='requires']/constraint_element")
		if all_requires_constraint != []:
			for tmp in range(num_tabs): print "\t",
			print "\t[ %s ]" %  ' && '.join([constraint_requires.find('name').text for constraint_requires  in  all_requires_constraint])
	
		
		# Print footprint, for now just print [this.footprint = 0].
		for tmp in range(num_tabs): print "\t",
		footprint = get_footprint(xml_model_nfp, featureelement, args)
			
		print "\t[ this.%s = %s]" %   (args.property ,footprint)
	
		# Add to the list of required summations.	
		Constraint_Summation.append( get_fully_qualified_name(xml_model,featureelement)  + ('.%s' % args.property ))
			
		
	if args.fabricatebasefeature != '' and len(get_mandatory_base_features(xml_model))==0:
		
		print "\tSYNTETHIC_BASE_FEATURE : IMeasurable"
		print "\t\t [ this.footprint = %s ]" % get_empty_features_footprint(xml_model_configurations)
		
	print "\ttotal_%s : integer" % args.property
	print "\t[ total_%s = %s ]" %  (args.property ,' + '.join(Constraint_Summation))
	
	print "\nsimpleConfig : %s " % xml_model.get('name')
	
	
	print "\n\n//Mandatory Features all configurations will have: %s " %  str(' '.join([x.get('name') for x in get_mandatory_base_features(xml_model)]))
 def __init__(self, feature_model_xml_filename):
     self.xml_model = load_xml_model(feature_model_xml_filename)
     self.SPL = self.get_top_level_SPL_model()
     self.non_functional_properties =  self.compute_nonfunctional_properties()
     assert self.SPL != None