org.apache.maven.settings.Profile Java Examples

The following examples show how to use org.apache.maven.settings.Profile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenSettings.java    From spring-init with Apache License 2.0 6 votes vote down vote up
private List<Profile> determineActiveProfiles(Settings settings) {
	SpringBootCliModelProblemCollector problemCollector = new SpringBootCliModelProblemCollector();
	List<org.apache.maven.model.Profile> activeModelProfiles = createProfileSelector()
			.getActiveProfiles(createModelProfiles(settings.getProfiles()),
					new SpringBootCliProfileActivationContext(
							settings.getActiveProfiles()),
					problemCollector);
	if (!problemCollector.getProblems().isEmpty()) {
		throw new IllegalStateException(createFailureMessage(problemCollector));
	}
	List<Profile> activeProfiles = new ArrayList<Profile>();
	Map<String, Profile> profiles = settings.getProfilesAsMap();
	for (org.apache.maven.model.Profile modelProfile : activeModelProfiles) {
		activeProfiles.add(profiles.get(modelProfile.getId()));
	}
	return activeProfiles;
}
 
Example #2
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void addProfileRepos(final org.apache.maven.model.Profile profile, final List<RemoteRepository> all) {
    final List<org.apache.maven.model.Repository> repositories = profile.getRepositories();
    for (org.apache.maven.model.Repository repo : repositories) {
        final RemoteRepository.Builder repoBuilder = new RemoteRepository.Builder(repo.getId(), repo.getLayout(),
                repo.getUrl());
        org.apache.maven.model.RepositoryPolicy policy = repo.getReleases();
        if (policy != null) {
            repoBuilder.setReleasePolicy(toAetherRepoPolicy(policy));
        }
        policy = repo.getSnapshots();
        if (policy != null) {
            repoBuilder.setSnapshotPolicy(toAetherRepoPolicy(policy));
        }
        all.add(repoBuilder.build());
    }
}
 
Example #3
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
private List<Profile> determineActiveProfiles(Settings settings) {
	SpringBootCliModelProblemCollector problemCollector = new SpringBootCliModelProblemCollector();
	List<org.apache.maven.model.Profile> activeModelProfiles = createProfileSelector()
			.getActiveProfiles(createModelProfiles(settings.getProfiles()),
					new SpringBootCliProfileActivationContext(
							settings.getActiveProfiles()),
					problemCollector);
	if (!problemCollector.getProblems().isEmpty()) {
		throw new IllegalStateException(createFailureMessage(problemCollector));
	}
	List<Profile> activeProfiles = new ArrayList<Profile>();
	Map<String, Profile> profiles = settings.getProfilesAsMap();
	for (org.apache.maven.model.Profile modelProfile : activeModelProfiles) {
		activeProfiles.add(profiles.get(modelProfile.getId()));
	}
	return activeProfiles;
}
 
Example #4
Source File: MavenSettings.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private List<org.apache.maven.model.Profile> createModelProfiles(
		List<Profile> profiles) {
	List<org.apache.maven.model.Profile> modelProfiles = new ArrayList<org.apache.maven.model.Profile>();
	for (Profile profile : profiles) {
		org.apache.maven.model.Profile modelProfile = new org.apache.maven.model.Profile();
		modelProfile.setId(profile.getId());
		if (profile.getActivation() != null) {
			modelProfile
					.setActivation(createModelActivation(profile.getActivation()));
		}
		modelProfiles.add(modelProfile);
	}
	return modelProfiles;
}
 
Example #5
Source File: DependencyResolver.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private Collection<? extends ArtifactRepository> mavenRepositories(
		MavenSettings settings) {
	List<ArtifactRepository> list = new ArrayList<>();
	for (Profile profile : settings.getActiveProfiles()) {
		for (Repository repository : profile.getRepositories()) {
			addRepositoryIfMissing(list, repository.getId(), repository.getUrl(),
					repository.getReleases() != null
							? repository.getReleases().isEnabled() : true,
					repository.getSnapshots() != null
							? repository.getSnapshots().isEnabled() : false);
		}
	}
	return list;
}
 
Example #6
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Profile getProfile(String name, Settings settings) throws BootstrapMavenException {
    final Profile profile = settings.getProfilesAsMap().get(name);
    if (profile == null) {
        unrecognizedProfile(name, true);
    }
    return profile;
}
 
Example #7
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private List<org.apache.maven.model.Profile> createModelProfiles(
		List<Profile> profiles) {
	List<org.apache.maven.model.Profile> modelProfiles = new ArrayList<org.apache.maven.model.Profile>();
	for (Profile profile : profiles) {
		org.apache.maven.model.Profile modelProfile = new org.apache.maven.model.Profile();
		modelProfile.setId(profile.getId());
		if (profile.getActivation() != null) {
			modelProfile
					.setActivation(createModelActivation(profile.getActivation()));
		}
		modelProfiles.add(modelProfile);
	}
	return modelProfiles;
}
 
Example #8
Source File: DependencyResolver.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private Collection<? extends ArtifactRepository> mavenRepositories(
		MavenSettings settings) {
	List<ArtifactRepository> list = new ArrayList<>();
	for (Profile profile : settings.getActiveProfiles()) {
		for (Repository repository : profile.getRepositories()) {
			addRepositoryIfMissing(list, repository.getId(), repository.getUrl(),
					repository.getReleases() != null
							? repository.getReleases().isEnabled() : true,
					repository.getSnapshots() != null
							? repository.getSnapshots().isEnabled() : false);
		}
	}
	return list;
}
 
Example #9
Source File: JDOMSettingsConverter.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
/**
 * Method updateProfile.
 *
 * @param profile
 * @param element
 * @param counter
 */
protected void updateProfile( final Profile profile, final IndentationCounter counter, final Element element )
{
    final IndentationCounter innerCount = new IndentationCounter( counter.getDepth() + 1 );
    updateActivation( profile.getActivation(), innerCount, element );
    findAndReplaceProperties( innerCount, element, "properties", profile.getProperties() );
    iterateRepository( innerCount, element, profile.getRepositories(), "repositories", "repository" );
    iterateRepository( innerCount, element, profile.getPluginRepositories(), "pluginRepositories", "pluginRepository" );
    findAndReplaceSimpleElement( innerCount, element, "id", profile.getId(), "default" );
}
 
Example #10
Source File: MavenSettings.java    From spring-init with Apache License 2.0 4 votes vote down vote up
public List<Profile> getActiveProfiles() {
	return this.activeProfiles;
}
 
Example #11
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
public List<Profile> getActiveProfiles() {
	return this.activeProfiles;
}
 
Example #12
Source File: MavenLocationExpander.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
private void addSettingsProfileRepositoriesTo( final Set<Location> locs, final Settings settings,
                                               final List<String> activeProfiles,
                                               final MirrorSelector mirrorSelector )
    throws MalformedURLException
{
    if ( settings != null )
    {
        final Map<String, Profile> profiles = settings.getProfilesAsMap();
        if ( profiles != null && activeProfiles != null && !activeProfiles.isEmpty() )
        {
            final LinkedHashSet<String> active = new LinkedHashSet<>( activeProfiles );

            final List<String> settingsActiveProfiles = settings.getActiveProfiles();
            if ( settingsActiveProfiles != null && !settingsActiveProfiles.isEmpty() )
            {
                active.addAll( settingsActiveProfiles );
            }

            for ( final String profileId : active )
            {
                final Profile profile = profiles.get( profileId );
                if ( profile != null )
                {
                    final List<Repository> repositories = profile.getRepositories();
                    if ( repositories != null )
                    {
                        final List<Mirror> mirrors = settings.getMirrors();
                        final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
                        for ( final Repository repo : repositories )
                        {
                            String id = repo.getId();
                            String url = repo.getUrl();

                            if ( mirrors != null )
                            {
                                final ArtifactRepositoryPolicy snapshots = convertPolicy( repo.getSnapshots() );
                                final ArtifactRepositoryPolicy releases = convertPolicy( repo.getReleases() );

                                final MavenArtifactRepository arepo =
                                    new MavenArtifactRepository( id, url, layout, snapshots, releases );

                                final Mirror mirror =
                                    mirrorSelector == null ? null : mirrorSelector.getMirror( arepo, mirrors );

                                if ( mirror != null )
                                {
                                    id = mirror.getId();
                                    url = mirror.getUrl();
                                }

                                SimpleHttpLocation addition = new SimpleHttpLocation( id, url, snapshots.isEnabled(), releases.isEnabled(), true, false, null );

                                addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60);

                                locs.add (addition);
                            }
                        }
                    }

                }
            }
        }
    }
}
 
Example #13
Source File: SettingsIO.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
public void update( Settings settings, File settingsFile )
    throws ManipulationException
{
    try
    {
        Settings defaultSettings = new Settings();

        if ( settingsFile.exists() )
        {
            DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
            settingsRequest.setGlobalSettingsFile( settingsFile );
            defaultSettings = settingsBuilder.build( settingsRequest ).getEffectiveSettings();
        }

        for ( Profile profile : settings.getProfiles() )
        {
            defaultSettings.getProfiles().removeIf( profile1 -> profile1.getId().equals( profile.getId() ) );
            defaultSettings.addProfile( profile );
        }
        for ( String activeProfile : settings.getActiveProfiles() )
        {
            defaultSettings.getActiveProfiles().removeIf( s -> s.equals( activeProfile ) );
            defaultSettings.addActiveProfile( activeProfile );
        }
        for ( Mirror mirror : settings.getMirrors() )
        {
            defaultSettings.addMirror( mirror );
        }
        for ( Proxy proxy : settings.getProxies() )
        {
            defaultSettings.addProxy( proxy );
        }
        for ( Server server : settings.getServers() )
        {
            defaultSettings.addServer( server );
        }
        for ( String pluginGroup : settings.getPluginGroups() )
        {
            defaultSettings.addPluginGroup( pluginGroup );
        }
        if ( settings.getLocalRepository() != null )
        {
            defaultSettings.setLocalRepository( settings.getLocalRepository() );
        }

        write( defaultSettings, settingsFile );
    }
    catch ( SettingsBuildingException e )
    {
        throw new ManipulationException( "Failed to build existing settings.xml for repo removal backup.", settingsFile, e.getMessage(), e );
    }
}
 
Example #14
Source File: MavenLocationExpanderTest.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
@Test
public void useActiveSettingsProfileRepos()
    throws Exception
{
    final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();

    final ArtifactRepositoryPolicy snapshots =
        new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY,
                                      ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );

    final ArtifactRepositoryPolicy releases =
        new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER,
                                      ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );

    final File localRepo = File.createTempFile( "local.repo.", ".dir" );
    localRepo.deleteOnExit();

    final ArtifactRepository local =
        new MavenArtifactRepository( "local", localRepo.toURI()
                                                       .toString(), layout, snapshots, releases );

    final Repository remote = new Repository();
    remote.setId( "remote" );
    remote.setUrl( "http:///repo.maven.apache.org/maven2" );

    final Profile profile = new Profile();
    profile.setId( "test" );
    profile.addRepository( remote );

    final Settings settings = new Settings();
    settings.addProfile( profile );

    final MavenLocationExpander ex =
        new MavenLocationExpander( Collections.<Location> emptyList(),
                                   Collections.<ArtifactRepository> emptyList(), local,
                                   new DefaultMirrorSelector(), settings,
                                   Collections.<String> singletonList( profile.getId() ) );

    final List<Location> result = ex.expand( MavenLocationExpander.EXPANSION_TARGET );

    assertThat( result.size(), equalTo( 2 ) );

    final Iterator<Location> iterator = result.iterator();
    Location loc = iterator.next();

    assertThat( loc.getName(), equalTo( local.getId() ) );
    assertThat( loc.getUri(), equalTo( local.getUrl() ) );

    loc = iterator.next();

    assertThat( loc.getName(), equalTo( remote.getId() ) );
    assertThat( loc.getUri(), equalTo( remote.getUrl() ) );
}