SubJavaVersionProfileActivator implements ProfileActivator { @Override public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) { Activation activation = profile.getActivation(); if ( activation == null ) { return false; } String jdk = activation.getJdk(); if ( jdk == null ) { return false; } String version = context.getSystemProperties().get( "java.version" ); if ( version == null || version.length() <= 0 ) { problems.add( new ModelProblemCollectorRequest( ModelProblem.Severity.ERROR, ModelProblem.Version.BASE ) .setMessage( "Failed to determine Java version for profile " + profile.getId() ) .setLocation( activation.getLocation( "jdk" ) ) ); return false; } if ( jdk.startsWith( "!" ) ) { return !version.startsWith( jdk.substring( 1 ) ); } else if ( isRange( jdk ) ) { return isInRange( version, getRange( jdk ) ); } else { return version.startsWith( jdk ); } }  @Override boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ); @Override boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems );  }
@Test public void notActivatedSubJavaVersion4digitsRangeAndVersion() { SubJavaVersionProfileActivator activator = new SubJavaVersionProfileActivator(); Profile profile = new Profile(); profile.setId( "test" ); profile.setActivation( new Activation(){ @Override public String getJdk() { return "[1.8,1.8.0_200)"; } } ); ProfileActivationContext context = new DefaultProfileActivationContext(){ @Override public Map<String, String> getSystemProperties() { Map<String,String> props = new HashMap<>(); props.put( "java.version", "1.8.0_222-b10" ); return props; } }; boolean activated = activator.isActive( profile, context, null); assertThat("Activated", activated, is(false)); }
@Test public void activatedSubJavaVersion4digitsRangeAndVersion() { SubJavaVersionProfileActivator activator = new SubJavaVersionProfileActivator(); Profile profile = new Profile(); profile.setId( "test" ); profile.setActivation( new Activation(){ @Override public String getJdk() { return "[1.8,1.8.0_200)"; } } ); ProfileActivationContext context = new DefaultProfileActivationContext(){ @Override public Map<String, String> getSystemProperties() { Map<String,String> props = new HashMap<>(); props.put( "java.version", "1.8.0_199-b24" ); return props; } }; boolean activated = activator.isActive( profile, context, null); assertThat("Not Activated", activated, is(true)); }
@Test public void notActivatedSubJavaVersion2digitsRange() { SubJavaVersionProfileActivator activator = new SubJavaVersionProfileActivator(); Profile profile = new Profile(); profile.setId( "test" ); profile.setActivation( new Activation(){ @Override public String getJdk() { return "[1.9,)"; } } ); ProfileActivationContext context = new DefaultProfileActivationContext(){ @Override public Map<String, String> getSystemProperties() { Map<String,String> props = new HashMap<>(); props.put( "java.version", "1.8.0_222-b10" ); return props; } }; boolean activated = activator.isActive( profile, context, null); assertThat("Activated", activated, is(false)); }
@Test public void notActivatedSubJavaVersion4digitsRangeAnd2digitsVersion() { SubJavaVersionProfileActivator activator = new SubJavaVersionProfileActivator(); Profile profile = new Profile(); profile.setId( "test" ); profile.setActivation( new Activation(){ @Override public String getJdk() { return "[1.8,1.8.0_200)"; } } ); ProfileActivationContext context = new DefaultProfileActivationContext(){ @Override public Map<String, String> getSystemProperties() { Map<String,String> props = new HashMap<>(); props.put( "java.version", "1.8" ); return props; } }; boolean activated = activator.isActive( profile, context, null); assertThat("Not Activated", activated, is(true)); }
@Test public void notActivatedSubJavaVersion4digitsRangeMinAnd2digitsVersion() { SubJavaVersionProfileActivator activator = new SubJavaVersionProfileActivator(); Profile profile = new Profile(); profile.setId( "test" ); profile.setActivation( new Activation(){ @Override public String getJdk() { return "[1.8.0_200,)"; } } ); ProfileActivationContext context = new DefaultProfileActivationContext(){ @Override public Map<String, String> getSystemProperties() { Map<String,String> props = new HashMap<>(); props.put( "java.version", "1.8" ); return props; } }; boolean activated = activator.isActive( profile, context, null); assertThat("Activated", activated, is(false)); }
@Test public void activatedSubJavaVersion4digitsRangeMinAnd2digitsVersion() { SubJavaVersionProfileActivator activator = new SubJavaVersionProfileActivator(); Profile profile = new Profile(); profile.setId( "test" ); profile.setActivation( new Activation(){ @Override public String getJdk() { return "[1.8.0_200,)"; } } ); ProfileActivationContext context = new DefaultProfileActivationContext(){ @Override public Map<String, String> getSystemProperties() { Map<String,String> props = new HashMap<>(); props.put( "java.version", "1.9" ); return props; } }; boolean activated = activator.isActive( profile, context, null); assertThat("Activated", activated, is(true)); }
@Test public void activatedSubJavaVersion4digitsRangeMinAnd4digitsVersion() { SubJavaVersionProfileActivator activator = new SubJavaVersionProfileActivator(); Profile profile = new Profile(); profile.setId( "test" ); profile.setActivation( new Activation(){ @Override public String getJdk() { return "[1.8.0_200,)"; } } ); ProfileActivationContext context = new DefaultProfileActivationContext(){ @Override public Map<String, String> getSystemProperties() { Map<String,String> props = new HashMap<>(); props.put( "java.version", "1.8.0_201" ); return props; } }; boolean activated = activator.isActive( profile, context, null); assertThat("Not Activated", activated, is(true)); }
@Test public void notActivatedSubJavaVersion4digitsRangeMinAnd4digitsVersion() { SubJavaVersionProfileActivator activator = new SubJavaVersionProfileActivator(); Profile profile = new Profile(); profile.setId( "test" ); profile.setActivation( new Activation(){ @Override public String getJdk() { return "[1.8.0_200,)"; } } ); ProfileActivationContext context = new DefaultProfileActivationContext(){ @Override public Map<String, String> getSystemProperties() { Map<String,String> props = new HashMap<>(); props.put( "java.version", "1.8.0_199" ); return props; } }; boolean activated = activator.isActive( profile, context, null); assertThat("Activated", activated, is(false)); }