/** * Constructor. * @param app */ public InstanceContext( AbstractApplication app ) { this.name = app.getName(); this.qualifier = app instanceof ApplicationTemplate ? ((ApplicationTemplate) app).getVersion() : null; }
/** * Finds the icon associated with an application or application template. * @param app an application (not null) * @return an existing file, or null if no icon was found */ public static File findIcon( AbstractApplication app ) { return findIcon( app.getDirectory()); }
/** * Finds all the components of an application or a template. * <p> * Inheritance cycles are ignored. * </p> * * @param app an application or a template (not null) * @return a non-null list of components */ public static List<Component> findAllComponents( AbstractApplication app ) { List<Component> result = new ArrayList<> (); if( app.getGraphs() != null ) result.addAll( findAllComponents( app.getGraphs())); return result; }
/** * Finds the resource directories for scoped instances. * @param applicationFilesDirectory the application's directory * @param graph the graph * @return a non-null map (key = component, value = directory) */ public static Map<Component,File> findScopedInstancesDirectories( AbstractApplication absApp ) { Map<Component,File> result = new HashMap<> (); for( Component c : ComponentHelpers.findAllComponents( absApp.getGraphs())) { // Target? if( ! ComponentHelpers.isTarget( c )) continue; // Is there a resources directory? File dir = ResourceUtils.findInstanceResourcesDirectory( absApp.getDirectory(), c ); if( ! dir.exists()) continue; result.put( c, dir ); } return result; } }
/** * Gets all the instances of an application. * @param application an application (not null) * @return a non-null list of instances * <p> * The result is a list made up of ordered lists.<br> * root-0, child-0-1, child-0-2, child-0-1-1, etc.<br> * root-1, child-1-1, child-1-2, child-1-1-1, etc.<br> * </p> * <p> * It means the resulting list can be considered as valid for starting instances * from the root instances to the bottom leaves. * </p> */ public static List<Instance> getAllInstances( AbstractApplication application ) { List<Instance> result = new ArrayList<> (); for( Instance instance : application.getRootInstances()) result.addAll( InstanceHelpers.buildHierarchicalList( instance )); return result; }
/** * Finds all the scoped instances from an application. * @return a non-null list */ public static List<Instance> findAllScopedInstances( AbstractApplication app ) { List<Instance> instanceList = new ArrayList<> (); List<Instance> todo = new ArrayList<> (); todo.addAll( app.getRootInstances()); while( ! todo.isEmpty()) { Instance current = todo.remove( 0 ); todo.addAll( current.getChildren()); if( isTarget( current )) instanceList.add( current ); } return instanceList; }
/** * Finds the URL to access the icon of an application or templates. * @param app an application or an application template * @return the empty string if no icon was found, a string otherwise */ public static String findIconUrl( AbstractApplication app ) { StringBuilder sb = new StringBuilder(); File iconFile = findIcon( app ); if( iconFile != null ) { sb.append( "/" ); sb.append( app.getName()); if( app instanceof ApplicationTemplate ) { sb.append( "/" ); sb.append(((ApplicationTemplate) app).getVersion()); } sb.append( "/" ); sb.append( iconFile.getName()); } return sb.toString(); }
/** * Determines whether an instance name is not already used by a sibling instance. * @param application the application (not null) * @param parentInstance the parent instance (can be null to indicate a root instance) * @param nameToSearch the name to search * @return true if a child instance of <code>parentInstance</code> has the same name, false otherwise */ public static boolean hasChildWithThisName( AbstractApplication application, Instance parentInstance, String nameToSearch ) { boolean hasAlreadyAChildWithThisName = false; Collection<Instance> list = parentInstance == null ? application.getRootInstances() : parentInstance.getChildren(); for( Iterator<Instance> it = list.iterator(); it.hasNext() && ! hasAlreadyAChildWithThisName; ) { hasAlreadyAChildWithThisName = Objects.equals( nameToSearch, it.next().getName()); } return hasAlreadyAChildWithThisName; }
/** * Finds a component by name. * @param app an application (not null) * @param name the component name (not null) * @return a component (can be null) */ public static Component findComponent( AbstractApplication app, String name ) { Graphs graphs = app.getGraphs(); return findComponent( graphs, name ); }
File commandsDirectory = new File( this.context.getApp().getDirectory(), Constants.PROJECT_DIR_COMMANDS ); File commandFileToExecute;
@Override public void applicationWasDeleted( AbstractApplication app ) throws IOException { String name = app.getName(); String qualifier = app instanceof ApplicationTemplate ? ((ApplicationTemplate) app).getVersion() : null;
currentList.addAll( application.getRootInstances());
protected ManagedApplication resolveManagedApplication( Manager manager, AbstractCommandInstruction instr ) throws CommandException { String appName = instr.getApplication().getName(); ManagedApplication ma = manager.applicationMngr().findManagedApplicationByName( appName ); if( ma == null ) throw new CommandException( "Application " + appName + " could not be found." ); return ma; }
&& ComponentHelpers.findAllAncestors( childInstance.getComponent()).isEmpty()) { application.getRootInstances().add( childInstance ); success = true;