/** * Searches for a cycle in the facets inheritance. * @param component the component from which we introspect (not null) * @return null if no cycle was found, a string describing the cycle otherwise */ public static String searchForInheritanceCycle( Component component ) { String result = null; for( Component c = component.getExtendedComponent(); c != null && result == null; c = c.getExtendedComponent()) { if( c.equals( component )) result = component + " -> ... -> " + component; } return result; }
/** * Finds all the components that this component inherits from. * <p> * For commodity reasons, the result always contains the current component. * </p> * <p> * Inheritance cycles are ignored. * </p> * * @param component a non-null component * @return a non-null list (it always contains the <code>component</code> parameter) */ public static List<Component> findAllExtendedComponents( Component component ) { List<Component> result = new ArrayList<> (); for( Component c = component; c != null; c = c.getExtendedComponent()) { if( result.contains( c )) break; result.add( c ); } return result; }
/** * Finds the resource directory for an instance. * <p> * The resource directory may be the one of another component. * This is the case when a component extends another component. * </p> * <p> * An extending component can override the resource directory. * </p> * * @param applicationFilesDirectory the application's directory * @param component a component (may be null) * @return a non-null file (that may not exist) */ public static File findInstanceResourcesDirectory( File applicationFilesDirectory, Component component ) { File root = new File( applicationFilesDirectory, Constants.PROJECT_DIR_GRAPH ); File result = new File( "No recipe directory." ); Set<Component> alreadyChecked = new HashSet<> (); for( Component c = component; c != null; c = c.getExtendedComponent()) { // Prevent infinite loops for exotic cases if( alreadyChecked.contains( c )) break; alreadyChecked.add( c ); if(( result = new File( root, c.getName())).exists()) break; } return result; }
if( component.getExtendedComponent() != null ) { p = new BlockProperty( file, ParsingConstants.PROPERTY_GRAPH_EXTENDS, component.getExtendedComponent().getName()); blockComponent.getInnerBlocks().add( p );
AbstractRoboconfTransformer transformer = new InheritanceTransformer( comp, comp.getExtendedComponent(), extendingComponents, 4 ); saveImage( comp, DiagramType.INHERITANCE, transformer, section );
AbstractRoboconfTransformer transformer = new InheritanceTransformer( comp, comp.getExtendedComponent(), extendingComponents, 4 ); saveImage( comp, DiagramType.INHERITANCE, transformer, section );
Component originalComponent = ComponentHelpers.findComponent( graphs, readComponent.getName()); Assert.assertNotNull( readComponent.getName(), originalComponent ); Assert.assertEquals( readComponent.getExtendedComponent(), originalComponent.getExtendedComponent()); Assert.assertEquals( readComponent.getInstallerName(), originalComponent.getInstallerName()); Assert.assertEquals( readComponent.exportedVariables.size(), originalComponent.exportedVariables.size());
Assert.assertTrue( exportedVariables.containsKey( "VM.ip" )); Assert.assertEquals( ComponentHelpers.findComponent( g, "VM" ), vmOpenstack.getExtendedComponent()); Assert.assertNotNull( vmOpenstack.getExtendedComponent());
@Test public void testChain() { Component c = new Component( "c" ); Component comp = new Component().name( "ins" ).installerName( "my-installer" ); comp.extendComponent( c ); Assert.assertEquals( "ins", comp.getName()); Assert.assertEquals( "my-installer", comp.getInstallerName()); Assert.assertEquals( c, comp.getExtendedComponent()); }