protected ProfileActivator[] newProfileActivators() { return new ProfileActivator[] { new JdkVersionProfileActivator(), new OperatingSystemProfileActivator(), new PropertyProfileActivator(), new FileProfileActivator().setPathTranslator( newPathTranslator() ) }; }
private static boolean isInRange( String value, List<RangeValue> range ) { int leftRelation = getRelationOrder( value, range.get( 0 ), true ); if ( leftRelation == 0 ) { return true; } if ( leftRelation < 0 ) { return false; } return getRelationOrder( value, range.get( 1 ), false ) <= 0; }
ranges.add( new RangeValue( token.replace( "[", "" ), true ) ); ranges.add( new RangeValue( token.replace( "(", "" ), false ) ); ranges.add( new RangeValue( token.replace( "]", "" ), true ) ); ranges.add( new RangeValue( token.replace( ")", "" ), false ) ); ranges.add( new RangeValue( "", false ) ); ranges.add( new RangeValue( "99999999", false ) );
boolean active = ensureAtLeastOneNonNull( os ); active = determineFamilyMatch( os.getFamily() ); active = determineNameMatch( os.getName() ); active = determineArchMatch( os.getArch() ); active = determineVersionMatch( os.getVersion() );
private boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) { boolean isActive = false; for ( ProfileActivator activator : activators ) { if ( activator.presentInConfig( profile, context, problems ) ) { isActive = true; } } for ( ProfileActivator activator : activators ) { try { if ( activator.presentInConfig( profile, context, problems ) ) { isActive &= activator.isActive( profile, context, problems ); } } catch ( RuntimeException e ) { problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ) .setMessage( "Failed to determine activation for profile " + profile.getId() ) .setLocation( profile.getLocation( "" ) ) .setException( e ) ); return false; } } return isActive; }
/** * Helper method to determine if the current OS is allowed based on the injected values for family, name, version * and arch. * * @return true if the version is allowed. */ public boolean isAllowed() { return activator.isActive( createProfile(), null, null ); }
private static int getRelationOrder( String value, RangeValue rangeValue, boolean isLeft ) { if ( rangeValue.value.length() <= 0 ) { return isLeft ? 1 : -1; } value = value.replaceAll( "[^0-9\\.\\-\\_]", "" ); List<String> valueTokens = new ArrayList<>( Arrays.asList( value.split( "[\\.\\-\\_]" ) ) ); List<String> rangeValueTokens = new ArrayList<>( Arrays.asList( rangeValue.value.split( "\\." ) ) ); addZeroTokens( valueTokens, 3 ); addZeroTokens( rangeValueTokens, 3 ); for ( int i = 0; i < 3; i++ ) { int x = Integer.parseInt( valueTokens.get( i ) ); int y = Integer.parseInt( rangeValueTokens.get( i ) ); if ( x < y ) { return -1; } else if ( x > y ) { return 1; } } if ( !rangeValue.closed ) { return isLeft ? -1 : 1; } return 0; }
protected ProfileActivator[] newProfileActivators() { return new ProfileActivator[] { new JdkVersionProfileActivator(), new OperatingSystemProfileActivator(), new PropertyProfileActivator(), new FileProfileActivator().setPathTranslator( newPathTranslator() ) }; }
boolean active = ensureAtLeastOneNonNull( os ); active = determineFamilyMatch( os.getFamily() ); active = determineNameMatch( os.getName() ); active = determineArchMatch( os.getArch() ); active = determineVersionMatch( os.getVersion() );
private boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) { boolean isActive = false; for ( ProfileActivator activator : activators ) { if ( activator.presentInConfig( profile, context, problems ) ) { isActive = true; } } for ( ProfileActivator activator : activators ) { try { if ( activator.presentInConfig( profile, context, problems ) ) { isActive &= activator.isActive( profile, context, problems ); } } catch ( RuntimeException e ) { problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ) .setMessage( "Failed to determine activation for profile " + profile.getId() ) .setLocation( profile.getLocation( "" ) ) .setException( e ) ); return false; } } return isActive; }
@Override public List<Profile> getActiveProfiles(Collection<Profile> profiles, ProfileActivationContext context, ModelProblemCollector problems) { List<Profile> activeProfiles = new ArrayList<Profile>(); for (Profile p : profiles) { String id = p.getId(); if (p.getId() != null && context.getActiveProfileIds().contains(id) && !context.getInactiveProfileIds().contains(id)) { activeProfiles.add(p); continue; } if (p.getActivation() != null && p.getActivation().isActiveByDefault() && !context.getInactiveProfileIds().contains(p.getId())) { activeProfiles.add(p); continue; } for (ProfileActivator activator : activators) { if (activator.isActive(p, context, problems)) { activeProfiles.add(p); break; } } } return activeProfiles; }
private static boolean isInRange( String value, List<RangeValue> range ) { int leftRelation = getRelationOrder( value, range.get( 0 ), true ); if ( leftRelation == 0 ) { return true; } if ( leftRelation < 0 ) { return false; } return getRelationOrder( value, range.get( 1 ), false ) <= 0; }
ranges.add( new RangeValue( token.replace( "[", "" ), true ) ); ranges.add( new RangeValue( token.replace( "(", "" ), false ) ); ranges.add( new RangeValue( token.replace( "]", "" ), true ) ); ranges.add( new RangeValue( token.replace( ")", "" ), false ) ); ranges.add( new RangeValue( "", false ) ); ranges.add( new RangeValue( "99999999", false ) );
public SettingsXmlProfileSelector() { this.activators = new ArrayList<ProfileActivator>(); activators.addAll(Arrays.asList(new JdkVersionProfileActivator(), new PropertyProfileActivator(), new OperatingSystemProfileActivator(), new FileProfileActivator().setPathTranslator(new DefaultPathTranslator()))); }
@Override public List<Profile> getActiveProfiles(Collection<Profile> profiles, ProfileActivationContext context, ModelProblemCollector problems) { List<Profile> activeProfiles = new ArrayList<Profile>(); for (Profile p : profiles) { String id = p.getId(); if (p.getId() != null && context.getActiveProfileIds().contains(id) && !context.getInactiveProfileIds().contains(id)) { activeProfiles.add(p); continue; } if (p.getActivation() != null && p.getActivation().isActiveByDefault() && !context.getInactiveProfileIds().contains(p.getId())) { activeProfiles.add(p); continue; } for (ProfileActivator activator : activators) { if (activator.isActive(p, context, problems)) { activeProfiles.add(p); break; } } } return activeProfiles; }
public SettingsXmlProfileSelector() { this.activators = new ArrayList<ProfileActivator>(); activators.addAll(Arrays.asList(new JdkVersionProfileActivator(), new PropertyProfileActivator(), new OperatingSystemProfileActivator(), new FileProfileActivator().setPathTranslator(new DefaultPathTranslator()))); }
private DefaultProfileSelector createProfileSelector() { DefaultProfileSelector selector = new DefaultProfileSelector(); selector.addProfileActivator(new FileProfileActivator() .setPathTranslator(new DefaultPathTranslator())); selector.addProfileActivator(new JdkVersionProfileActivator()); selector.addProfileActivator(new PropertyProfileActivator()); selector.addProfileActivator(new OperatingSystemProfileActivator()); return selector; }
private DefaultProfileSelector createProfileSelector() { DefaultProfileSelector selector = new DefaultProfileSelector(); selector.addProfileActivator(new FileProfileActivator() .setPathTranslator(new DefaultPathTranslator())); selector.addProfileActivator(new JdkVersionProfileActivator()); selector.addProfileActivator(new PropertyProfileActivator()); selector.addProfileActivator(new OperatingSystemProfileActivator()); return selector; }
private DefaultProfileSelector createProfileSelector() { DefaultProfileSelector selector = new DefaultProfileSelector(); selector.addProfileActivator(new FileProfileActivator() .setPathTranslator(new DefaultPathTranslator())); selector.addProfileActivator(new JdkVersionProfileActivator()); selector.addProfileActivator(new PropertyProfileActivator()); selector.addProfileActivator(new OperatingSystemProfileActivator()); return selector; }