public void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector problems ) { String packaging = model.getPackaging(); Collection<Plugin> defaultPlugins = lifecycle.getPluginsBoundByDefaultToAllLifecycles( packaging ); if ( defaultPlugins == null ) { problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE) .setMessage( "Unknown packaging: " + packaging ) .setLocation( model.getLocation( "packaging" ))); } else if ( !defaultPlugins.isEmpty() ) { Model lifecycleModel = new Model(); lifecycleModel.setBuild( new Build() ); lifecycleModel.getBuild().getPlugins().addAll( defaultPlugins ); merger.merge( model, lifecycleModel ); } }
private boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) { for ( ProfileActivator activator : activators ) { try { if ( activator.isActive( profile, context, problems ) ) { return true; } } 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 false; }
public Object getValue( String expression ) { Object value = valueSource.getValue( expression ); if ( value != null && expression.startsWith( bannedPrefix ) ) { String msg = "The expression ${" + expression + "} is deprecated."; if ( newPrefix != null && newPrefix.length() > 0 ) { msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead."; } problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V20 ).setMessage( msg )); } return value; }
private String createFailureMessage( SpringBootCliModelProblemCollector problemCollector) { StringWriter message = new StringWriter(); PrintWriter printer = new PrintWriter(message); printer.println("Failed to determine active profiles:"); for (ModelProblemCollectorRequest problem : problemCollector.getProblems()) { printer.println(" " + problem.getMessage() + (problem.getLocation() != null ? " at " + problem.getLocation() : "")); if (problem.getException() != null) { printer.println(indentStackTrace(problem.getException(), " ")); } } return message.toString(); }
private String createFailureMessage( SpringBootCliModelProblemCollector problemCollector) { StringWriter message = new StringWriter(); PrintWriter printer = new PrintWriter(message); printer.println("Failed to determine active profiles:"); for (ModelProblemCollectorRequest problem : problemCollector.getProblems()) { printer.println( " " + problem.getMessage() + " at " + problem.getLocation()); } return message.toString(); }
public void add( ModelProblemCollectorRequest req ) { if ( !ModelProblem.Severity.WARNING.equals( req.getSeverity() ) ) { result.addMessage( req.getMessage() ); } }
public List getActiveProfiles() throws ProfileActivationException { DefaultProfileActivationContext context = new DefaultProfileActivationContext(); context.setActiveProfileIds( activatedIds ); context.setInactiveProfileIds( deactivatedIds ); context.setSystemProperties( System.getProperties() ); context.setUserProperties( requestProperties ); final List<ProfileActivationException> errors = new ArrayList<ProfileActivationException>(); List<Profile> profiles = profileSelector.getActiveProfiles( profilesById.values(), context, new ModelProblemCollector() { public void add( ModelProblemCollectorRequest req ) { if ( !ModelProblem.Severity.WARNING.equals( req.getSeverity() ) ) { errors.add( new ProfileActivationException( req.getMessage(), req.getException() ) ); } } } ); if ( !errors.isEmpty() ) { throw errors.get( 0 ); } return profiles; }
private static void addViolation( ModelProblemCollector problems, Severity severity, Version version, String fieldName, String sourceHint, String message, InputLocationTracker tracker ) { StringBuilder buffer = new StringBuilder( 256 ); buffer.append( '\'' ).append( fieldName ).append( '\'' ); if ( sourceHint != null ) { buffer.append( " for " ).append( sourceHint ); } buffer.append( ' ' ).append( message ); problems.add( new ModelProblemCollectorRequest( severity, version ).setMessage( buffer.toString() ).setLocation( getLocation( fieldName, tracker ))); }
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( Severity.ERROR, 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 public void add(ModelProblemCollectorRequest req) { this.problems.add(req); }
List<ModelProblemCollectorRequest> getProblems() { return this.problems; }
/** * {@inheritDoc} */ public void add( ModelProblemCollectorRequest req ) { this.logger.warn( req.getMessage(), req.getException() ); }