private Settings build( SettingsBuildingRequest request ) throws IOException, XmlPullParserException { try { return settingsBuilder.build( request ).getEffectiveSettings(); } catch ( SettingsBuildingException e ) { throw (IOException) new IOException( e.getMessage() ).initCause( e ); } }
@Override public SettingsBuildingResult build( SettingsBuildingRequest request ) throws SettingsBuildingException { DefaultSettingsProblemCollector problems = new DefaultSettingsProblemCollector( null ); Source globalSettingsSource = getSettingsSource( request.getGlobalSettingsFile(), request.getGlobalSettingsSource() ); Settings globalSettings = readSettings( globalSettingsSource, request, problems ); Source userSettingsSource = getSettingsSource( request.getUserSettingsFile(), request.getUserSettingsSource() ); Settings userSettings = readSettings( userSettingsSource, request, problems ); settingsMerger.merge( userSettings, globalSettings, TrackableBase.GLOBAL_LEVEL ); problems.setSource( "" ); userSettings = interpolate( userSettings, request, problems ); // for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble String localRepository = userSettings.getLocalRepository(); if ( localRepository != null && localRepository.length() > 0 ) { File file = new File( localRepository ); if ( !file.isAbsolute() && file.getPath().startsWith( File.separator ) ) { userSettings.setLocalRepository( file.getAbsolutePath() ); } } if ( hasErrors( problems.getProblems() ) ) { throw new SettingsBuildingException( problems.getProblems() ); } return new DefaultSettingsBuildingResult( userSettings, problems.getProblems() ); }
/** * Creates a new exception with the specified problems. * * @param problems The problems that causes this exception, may be {@code null}. */ public SettingsBuildingException( List<SettingsProblem> problems ) { super( toMessage( problems ) ); this.problems = new ArrayList<>(); if ( problems != null ) { this.problems.addAll( problems ); } }
StringBuilder sb = new StringBuilder("Found ").append(e.getProblems().size()) .append(" problems while building settings.xml model from both global Maven configuration file") .append(request.getGlobalSettingsFile()).append(" and/or user configuration file: ") for (SettingsProblem problem : e.getProblems()) { sb.append(counter++).append("/ ").append(problem).append("\n");
private static Settings buildMavenSettings(Path settingsPath) throws ArtifactException { SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest(); settingsBuildingRequest.setSystemProperties(System.getProperties()); settingsBuildingRequest.setUserSettingsFile(settingsPath.toFile()); SettingsBuildingResult settingsBuildingResult; DefaultSettingsBuilderFactory mvnSettingBuilderFactory = new DefaultSettingsBuilderFactory(); DefaultSettingsBuilder settingsBuilder = mvnSettingBuilderFactory.newInstance(); try { settingsBuildingResult = settingsBuilder.build(settingsBuildingRequest); } catch (SettingsBuildingException ex) { throw new ArtifactException(ex.getLocalizedMessage()); } return settingsBuildingResult.getEffectiveSettings(); }
StringBuilder sb = new StringBuilder("Found ").append(e.getProblems().size()) .append(" problems while building settings.xml model from both global Maven configuration file") .append(request.getGlobalSettingsFile()).append(" and/or user configuration file: ") for (SettingsProblem problem : e.getProblems()) { sb.append(counter++).append("/ ").append(problem).append("\n");
/** * Obtain the Maven {@link Settings} for this {@link Maven} profile * given the specified {@link OptionsByType}. * * @param optionsByType the launch {@link OptionsByType} * * @return a new {@link Settings} */ private Settings getSettings(OptionsByType optionsByType) { SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance(); DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); request.setGlobalSettingsFile(globalSettingsFile); request.setUserSettingsFile(userSettingsFile); // we use the system-properties of the current process to resolve artifacts request.setSystemProperties(System.getProperties()); Settings settings; try { settings = settingsBuilder.build(request).getEffectiveSettings(); return settings; } catch (SettingsBuildingException e) { LOGGER.log(Level.WARNING, "Could not process settings.xml: " + e.getMessage(), e); throw new IllegalArgumentException("Could not process the settings.xml", e); } }
/** * Creates a new exception with the specified problems. * * @param problems The problems that causes this exception, may be {@code null}. */ public SettingsBuildingException( List<SettingsProblem> problems ) { super( toMessage( problems ) ); this.problems = new ArrayList<>(); if ( problems != null ) { this.problems.addAll( problems ); } }
@Override public SettingsBuildingResult build( SettingsBuildingRequest request ) throws SettingsBuildingException { DefaultSettingsProblemCollector problems = new DefaultSettingsProblemCollector( null ); Source globalSettingsSource = getSettingsSource( request.getGlobalSettingsFile(), request.getGlobalSettingsSource() ); Settings globalSettings = readSettings( globalSettingsSource, request, problems ); Source userSettingsSource = getSettingsSource( request.getUserSettingsFile(), request.getUserSettingsSource() ); Settings userSettings = readSettings( userSettingsSource, request, problems ); settingsMerger.merge( userSettings, globalSettings, TrackableBase.GLOBAL_LEVEL ); problems.setSource( "" ); userSettings = interpolate( userSettings, request, problems ); // for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble String localRepository = userSettings.getLocalRepository(); if ( localRepository != null && localRepository.length() > 0 ) { File file = new File( localRepository ); if ( !file.isAbsolute() && file.getPath().startsWith( File.separator ) ) { userSettings.setLocalRepository( file.getAbsolutePath() ); } } if ( hasErrors( problems.getProblems() ) ) { throw new SettingsBuildingException( problems.getProblems() ); } return new DefaultSettingsBuildingResult( userSettings, problems.getProblems() ); }
public Settings getSettings() throws MavenEmbedderException, ComponentLookupException { SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest(); if (this.mavenRequest.getGlobalSettingsFile() != null) { settingsBuildingRequest.setGlobalSettingsFile(new File(this.mavenRequest.getGlobalSettingsFile())); } else { settingsBuildingRequest.setGlobalSettingsFile(MavenCli.DEFAULT_GLOBAL_SETTINGS_FILE); } if (this.mavenRequest.getUserSettingsFile() != null) { settingsBuildingRequest.setUserSettingsFile(new File(this.mavenRequest.getUserSettingsFile())); } else { settingsBuildingRequest.setUserSettingsFile(MavenCli.DEFAULT_USER_SETTINGS_FILE); } settingsBuildingRequest.setUserProperties(this.mavenRequest.getUserProperties()); settingsBuildingRequest.getSystemProperties().putAll(System.getProperties()); settingsBuildingRequest.getSystemProperties().putAll(this.mavenRequest.getSystemProperties()); settingsBuildingRequest.getSystemProperties().putAll(getEnvVars()); try { return lookup(SettingsBuilder.class).build(settingsBuildingRequest).getEffectiveSettings(); } catch (SettingsBuildingException e) { throw new MavenEmbedderException(e.getMessage(), e); } }
/** * Creates a new exception with the specified problems. * * @param problems The problems that causes this exception, may be {@code null}. */ public SettingsBuildingException( List<SettingsProblem> problems ) { super( toMessage( problems ) ); this.problems = new ArrayList<SettingsProblem>(); if ( problems != null ) { this.problems.addAll( problems ); } }
public SettingsBuildingResult build( SettingsBuildingRequest request ) throws SettingsBuildingException { DefaultSettingsProblemCollector problems = new DefaultSettingsProblemCollector( null ); SettingsSource globalSettingsSource = getSettingsSource( request.getGlobalSettingsFile(), request.getGlobalSettingsSource() ); Settings globalSettings = readSettings( globalSettingsSource, request, problems ); SettingsSource userSettingsSource = getSettingsSource( request.getUserSettingsFile(), request.getUserSettingsSource() ); Settings userSettings = readSettings( userSettingsSource, request, problems ); settingsMerger.merge( userSettings, globalSettings, TrackableBase.GLOBAL_LEVEL ); problems.setSource( "" ); userSettings = interpolate( userSettings, request, problems ); // for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble String localRepository = userSettings.getLocalRepository(); if ( localRepository != null && localRepository.length() > 0 ) { File file = new File( localRepository ); if ( !file.isAbsolute() && file.getPath().startsWith( File.separator ) ) { userSettings.setLocalRepository( file.getAbsolutePath() ); } } if ( hasErrors( problems.getProblems() ) ) { throw new SettingsBuildingException( problems.getProblems() ); } return new DefaultSettingsBuildingResult( userSettings, problems.getProblems() ); }
public Settings getSettings() throws MavenEmbedderException, ComponentLookupException { SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest(); if ( this.mavenRequest.getGlobalSettingsFile() != null ) { settingsBuildingRequest.setGlobalSettingsFile( new File( this.mavenRequest.getGlobalSettingsFile() ) ); } else { settingsBuildingRequest.setGlobalSettingsFile( MavenCli.DEFAULT_GLOBAL_SETTINGS_FILE ); } if ( this.mavenRequest.getUserSettingsFile() != null ) { settingsBuildingRequest.setUserSettingsFile( new File( this.mavenRequest.getUserSettingsFile() ) ); } else { settingsBuildingRequest.setUserSettingsFile( MavenCli.DEFAULT_USER_SETTINGS_FILE ); } settingsBuildingRequest.setUserProperties( this.mavenRequest.getUserProperties() ); settingsBuildingRequest.getSystemProperties().putAll( System.getProperties() ); settingsBuildingRequest.getSystemProperties().putAll( this.mavenRequest.getSystemProperties() ); settingsBuildingRequest.getSystemProperties().putAll( getEnvVars() ); try { return lookup( SettingsBuilder.class ).build( settingsBuildingRequest ).getEffectiveSettings(); } catch ( SettingsBuildingException e ) { throw new MavenEmbedderException( e.getMessage(), e ); } }
public Settings getSettings() throws MavenEmbedderException, ComponentLookupException { SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest(); if ( this.mavenRequest.getGlobalSettingsFile() != null ) { settingsBuildingRequest.setGlobalSettingsFile( new File( this.mavenRequest.getGlobalSettingsFile() ) ); } else { settingsBuildingRequest.setGlobalSettingsFile( DEFAULT_GLOBAL_SETTINGS_FILE ); } if ( this.mavenRequest.getUserSettingsSource() != null ) { settingsBuildingRequest.setUserSettingsSource( this.mavenRequest.getUserSettingsSource() ); } else { SettingsSource userSettingsSource = MavenSettings.getUserSettingsSource(); if ( userSettingsSource != null ) { settingsBuildingRequest.setUserSettingsSource( userSettingsSource ); } } settingsBuildingRequest.setUserProperties( this.mavenRequest.getUserProperties() ); settingsBuildingRequest.getSystemProperties().putAll( System.getProperties() ); settingsBuildingRequest.getSystemProperties().putAll( this.mavenRequest.getSystemProperties() ); settingsBuildingRequest.getSystemProperties().putAll( getEnvVars() ); try { return componentProvider.lookup( SettingsBuilder.class ).build( settingsBuildingRequest ).getEffectiveSettings(); } catch ( SettingsBuildingException e ) { throw new MavenEmbedderException( e.getMessage(), e ); } }
public Settings getSettings() throws MavenEmbedderException, ComponentLookupException { SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest(); if ( this.mavenRequest.getGlobalSettingsFile() != null ) { settingsBuildingRequest.setGlobalSettingsFile( new File( this.mavenRequest.getGlobalSettingsFile() ) ); } else { settingsBuildingRequest.setGlobalSettingsFile( DEFAULT_GLOBAL_SETTINGS_FILE ); } if ( this.mavenRequest.getUserSettingsSource() != null ) { settingsBuildingRequest.setUserSettingsSource( this.mavenRequest.getUserSettingsSource() ); } else { SettingsSource userSettingsSource = MavenSettings.getUserSettingsSource(); if ( userSettingsSource != null ) { settingsBuildingRequest.setUserSettingsSource( userSettingsSource ); } } settingsBuildingRequest.setUserProperties( this.mavenRequest.getUserProperties() ); settingsBuildingRequest.getSystemProperties().putAll( System.getProperties() ); settingsBuildingRequest.getSystemProperties().putAll( this.mavenRequest.getSystemProperties() ); settingsBuildingRequest.getSystemProperties().putAll( getEnvVars() ); try { return componentProvider.lookup( SettingsBuilder.class ).build( settingsBuildingRequest ).getEffectiveSettings(); } catch ( SettingsBuildingException e ) { throw new MavenEmbedderException( e.getMessage(), e ); } }
private static synchronized Settings getSettings() { if ( settings == null ) { DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); request.setUserSettingsFile(getUserSettings()); File globalSettings = findGlobalSettings(); if(globalSettings != null) { request.setGlobalSettingsFile(globalSettings); } try { settings = settingsBuilder.build( request ).getEffectiveSettings(); } catch ( SettingsBuildingException e ) { LOGGER.warning("Could not process settings.xml: " + e.getMessage()); } SettingsDecryptionResult result = settingsDecrypter.decrypt( new DefaultSettingsDecryptionRequest( settings ) ); settings.setServers( result.getServers() ); settings.setProxies( result.getProxies() ); } return settings; }