Java Code Examples for org.apache.maven.settings.Settings#getLocalRepository()

The following examples show how to use org.apache.maven.settings.Settings#getLocalRepository() . 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: MavenPluginRepository.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public MavenPluginRepository() {
	Settings settings = loadDefaultUserSettings();

	system = newRepositorySystem();
	String userHome = System.getProperty("user.home");
	File localRepository = new File(settings.getLocalRepository() == null ? userHome + "/.m2/repository" : settings.getLocalRepository());
	session = newRepositorySystemSession(system, localRepository, settings);

	localRepositories = new ArrayList<>();

	RemoteRepository.Builder localRepoBuilder = new RemoteRepository.Builder("local", "default", "file://" + localRepository.toString());
	localRepoBuilder.setPolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":60", RepositoryPolicy.CHECKSUM_POLICY_FAIL));
	local = localRepoBuilder.build();
	repositories.add(local);
	localRepositories.add(local);

	addRepository("central", "default", "https://repo1.maven.org/maven2/");
}
 
Example 2
Source File: MavenSettings.java    From spring-init with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link MavenSettings} instance.
 * @param settings the source settings
 * @param decryptedSettings the decrypted settings
 */
public MavenSettings(Settings settings, SettingsDecryptionResult decryptedSettings) {
	this.offline = settings.isOffline();
	this.mirrorSelector = createMirrorSelector(settings);
	this.authenticationSelector = createAuthenticationSelector(decryptedSettings);
	this.proxySelector = createProxySelector(decryptedSettings);
	this.localRepository = settings.getLocalRepository();
	this.activeProfiles = determineActiveProfiles(settings);
}
 
Example 3
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static String resolveLocalRepo(Settings settings) {
    String localRepo = System.getenv("QUARKUS_LOCAL_REPO");
    if (localRepo != null) {
        return localRepo;
    }
    localRepo = PropertyUtils.getProperty("maven.repo.local");
    if (localRepo != null) {
        return localRepo;
    }
    localRepo = settings.getLocalRepository();
    return localRepo == null ? new File(userMavenConfigurationHome, "repository").getAbsolutePath() : localRepo;
}
 
Example 4
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link MavenSettings} instance.
 * @param settings the source settings
 * @param decryptedSettings the decrypted settings
 */
public MavenSettings(Settings settings, SettingsDecryptionResult decryptedSettings) {
	this.offline = settings.isOffline();
	this.mirrorSelector = createMirrorSelector(settings);
	this.authenticationSelector = createAuthenticationSelector(decryptedSettings);
	this.proxySelector = createProxySelector(decryptedSettings);
	this.localRepository = settings.getLocalRepository();
	this.activeProfiles = determineActiveProfiles(settings);
}
 
Example 5
Source File: RunEpisodesBPlugin.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void setUp() throws Exception {
	super.setUp();

	mavenProjectBuilder = (MavenProjectBuilder) getContainer().lookup(
			MavenProjectBuilder.ROLE);
	ArtifactFactory artifactFactory = (ArtifactFactory) getContainer()
			.lookup(ArtifactFactory.ROLE);

	final Map<String, Mojo> mojos = (Map<String, Mojo>) getContainer()
			.lookupMap(Mojo.ROLE);

	for (Mojo mojo : mojos.values()) {
		if (mojo instanceof Hyperjaxb3Mojo) {
			this.mojo = (Hyperjaxb3Mojo) mojo;
		}
	}

	MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) getContainer()
			.lookup(MavenSettingsBuilder.ROLE);
	ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) getContainer()
			.lookup(ArtifactRepositoryLayout.ROLE, "default");

	Settings settings = settingsBuilder.buildSettings();

	String url = settings.getLocalRepository();

	if (!url.startsWith("file:")) {
		url = "file://" + url;
	}

	localRepository = new DefaultArtifactRepository("local", url,
			new DefaultRepositoryLayout());
}
 
Example 6
Source File: MavenContainer.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public DefaultRepositorySystemSession setupRepoSession(final RepositorySystem repoSystem, final Settings settings)
{
   DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
   session.setOffline(false);

   Proxy activeProxy = settings.getActiveProxy();
   if (activeProxy != null)
   {
      DefaultProxySelector dps = new DefaultProxySelector();
      dps.add(convertFromMavenProxy(activeProxy), activeProxy.getNonProxyHosts());
      session.setProxySelector(dps);
   }

   final DefaultMirrorSelector mirrorSelector = createMirrorSelector(settings);
   final LazyAuthenticationSelector authSelector = createAuthSelector(settings, mirrorSelector);

   session.setMirrorSelector(mirrorSelector);
   session.setAuthenticationSelector(authSelector);

   LocalRepository localRepo = new LocalRepository(new File(settings.getLocalRepository()));
   session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
   session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
   session.setCache(new DefaultRepositoryCache());
   boolean cacheNotFoundArtifacts = true;
   boolean cacheTransferErrors = true;
   session.setResolutionErrorPolicy(new SimpleResolutionErrorPolicy(cacheNotFoundArtifacts, cacheTransferErrors));
   session.setWorkspaceReader(new ClasspathWorkspaceReader());
   if (Boolean.getBoolean("org.apache.maven.log_transfer"))
   {
      session.setTransferListener(new JULMavenTransferListener());
   }
   return session;
}
 
Example 7
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 8
Source File: MavenContainer.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
public Settings getSettings()
{
   try
   {
      SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance();
      SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
      String userSettingsLocation = System.getProperty(ALT_USER_SETTINGS_XML_LOCATION);
      // TeamCity sets the settings.xml in a different system property
      String teamCitySettingsLocation = System.getProperty("teamcity.maven.userSettings.path");
      if (userSettingsLocation != null)
      {
         settingsRequest.setUserSettingsFile(new File(userSettingsLocation));
      }
      else if (teamCitySettingsLocation != null)
      {
         settingsRequest.setUserSettingsFile(new File(teamCitySettingsLocation));
      }
      else
      {
         settingsRequest.setUserSettingsFile(new File(getUserHomeDir(), "/.m2/settings.xml"));
      }
      String globalSettingsLocation = System.getProperty(ALT_GLOBAL_SETTINGS_XML_LOCATION);
      if (globalSettingsLocation != null)
      {
         settingsRequest.setGlobalSettingsFile(new File(globalSettingsLocation));
      }
      else
      {
         if (M2_HOME != null)
         {
            settingsRequest.setGlobalSettingsFile(new File(M2_HOME, "/conf/settings.xml"));
         }
      }
      SettingsBuildingResult settingsBuildingResult = settingsBuilder.build(settingsRequest);
      Settings effectiveSettings = settingsBuildingResult.getEffectiveSettings();

      if (effectiveSettings.getLocalRepository() == null)
      {
         String userRepositoryLocation = System.getProperty(ALT_LOCAL_REPOSITORY_LOCATION);
         if (userRepositoryLocation != null)
         {
            effectiveSettings.setLocalRepository(userRepositoryLocation);
         }
         else
         {
            effectiveSettings.setLocalRepository(getUserHomePath() + "/.m2/repository");
         }
      }

      return effectiveSettings;
   }
   catch (SettingsBuildingException e)
   {
      throw new RuntimeException(e);
   }
}