org.apache.maven.settings.Repository Java Examples

The following examples show how to use org.apache.maven.settings.Repository. 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: JDOMSettingsConverter.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * Method updateRepository.
 *
 * @param repository
 * @param element
 * @param counter
 */
protected void updateRepository( final Repository repository, final IndentationCounter counter,
                                 final Element element )
{
    final IndentationCounter innerCount = new IndentationCounter( counter.getDepth() + 1 );
    updateRepositoryPolicy( repository.getReleases(), "releases", innerCount, element );
    updateRepositoryPolicy( repository.getSnapshots(), "snapshots", innerCount, element );
    findAndReplaceSimpleElement( innerCount, element, "id", repository.getId(),
                                 null );
    findAndReplaceSimpleElement( innerCount, element, "name", repository.getName(),
                                 null );
    findAndReplaceSimpleElement( innerCount, element, "url", repository.getUrl(),
                                 null );
    findAndReplaceSimpleElement( innerCount, element, "layout", repository.getLayout(),
                                 "default" );
}
 
Example #2
Source File: RepositoryUtils.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
public static ArtifactRepository convertFromMavenSettingsRepository(Repository repository)
{
   MavenArtifactRepository result = new MavenArtifactRepository();
   result.setId(repository.getId());
   result.setUrl(repository.getUrl());

   String layout = repository.getLayout();
   if ("default".equals(layout))
      result.setLayout(new DefaultRepositoryLayout());
   else if ("p2".equals(layout))
      result.setLayout(new P2ArtifactRepositoryLayout());

   RepositoryPolicy releases = repository.getReleases();
   if (releases != null)
      result.setReleaseUpdatePolicy(new ArtifactRepositoryPolicy(releases.isEnabled(), releases.getUpdatePolicy(),
               releases.getChecksumPolicy()));

   RepositoryPolicy snapshots = repository.getSnapshots();
   if (snapshots != null)
      result.setSnapshotUpdatePolicy(new ArtifactRepositoryPolicy(snapshots.isEnabled(),
               snapshots.getUpdatePolicy(),
               snapshots.getChecksumPolicy()));

   return result;
}
 
Example #3
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 #4
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 #5
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 #6
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() ) );
}