org.apache.maven.settings.Settings Java Examples

The following examples show how to use org.apache.maven.settings.Settings. 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: MavenSettingsReader.java    From spring-init with Apache License 2.0 6 votes vote down vote up
private Settings loadSettings() {
	File settingsFile = new File(this.homeDir, ".m2/settings.xml");
	if (settingsFile.exists()) {
		log.debug("Reading settings from: " + settingsFile);
	}
	else {
		log.debug("No settings found at: " + settingsFile);
	}
	SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
	request.setUserSettingsFile(settingsFile);
	request.setSystemProperties(System.getProperties());
	try {
		return new DefaultSettingsBuilderFactory().newInstance().build(request)
				.getEffectiveSettings();
	}
	catch (SettingsBuildingException ex) {
		throw new IllegalStateException(
				"Failed to build settings from " + settingsFile, ex);
	}
}
 
Example #2
Source File: MavenUtilTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private MavenSession getMavenSession() {
    Settings settings = new Settings();
    ArtifactRepository localRepository = new MavenArtifactRepository() {
        public String getBasedir() {
            return "repository";
        }
    };

    Properties userProperties = new Properties();
    userProperties.put("user.maven.home", "/home/user/.m2");

    Properties systemProperties = new Properties();
    systemProperties.put("foo", "bar");

    return new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", systemProperties, userProperties, new Date(System.currentTimeMillis()));
}
 
Example #3
Source File: MavenPluginRepository.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system, File localRepoFile, Settings settings) {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	if (!settings.getMirrors().isEmpty()) {
		DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
		for (Mirror mirror : settings.getMirrors()) {
			mirrorSelector.add(mirror.getId(), mirror.getUrl(), "default", true, mirror.getMirrorOf(), "*");
		}
		session.setMirrorSelector(mirrorSelector);
	}
	session.setProxySelector(proxySelector);

	LocalRepository localRepo = new LocalRepository(localRepoFile);
	session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

	return session;
}
 
Example #4
Source File: SettingsIOTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyWriteSettngs() throws IOException, ManipulationException
{
    URL resource = SettingsIOTest.class.getResource( "settings.xml" );
    assertNotNull( resource );
    File originalSettingsFile = new File( resource.getFile() );
    assertTrue( originalSettingsFile.exists() );

    Settings settings = new DefaultSettingsReader().read( originalSettingsFile, Collections.emptyMap() );
    assertNull( settings.getModelEncoding() );

    File targetFile = folder.newFile( "settings.xml" );

    new SettingsIO( null ).write( settings, targetFile );
    assertFalse( FileUtils.contentEquals( targetFile, originalSettingsFile ) );
}
 
Example #5
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 #6
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 #7
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 #8
Source File: MavenSettingsReader.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
private Settings loadSettings() {
	File settingsFile = new File(this.homeDir, ".m2/settings.xml");
	if (settingsFile.exists()) {
		log.info("Reading settings from: " + settingsFile);
	}
	else {
		log.info("No settings found at: " + settingsFile);
	}
	SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
	request.setUserSettingsFile(settingsFile);
	request.setSystemProperties(System.getProperties());
	try {
		return new DefaultSettingsBuilderFactory().newInstance().build(request)
				.getEffectiveSettings();
	}
	catch (SettingsBuildingException ex) {
		throw new IllegalStateException(
				"Failed to build settings from " + settingsFile, ex);
	}
}
 
Example #9
Source File: SqlExecMojoTest.java    From sql-maven-plugin with Apache License 2.0 6 votes vote down vote up
public void test002DefaultUsernamePassword()
    throws MojoExecutionException
{

    Settings settings = new Settings();
    Server server = new Server();
    settings.addServer( server );

    mojo.setSettings( settings );

    // force a lookup of username
    mojo.setUsername( null );
    mojo.setPassword( null );

    mojo.execute();

    assertEquals( "", mojo.getUsername() );
    assertEquals( "", mojo.getPassword() );

}
 
Example #10
Source File: SqlExecMojoTest.java    From sql-maven-plugin with Apache License 2.0 6 votes vote down vote up
public void test003UsernamePasswordLookup()
    throws MojoExecutionException
{

    Settings settings = new Settings();
    Server server = new Server();
    server.setId( "somekey" );
    server.setUsername( "username" );
    server.setPassword( "password" );
    settings.addServer( server );

    mojo.setSettings( settings );

    // force a lookup of username
    mojo.setSettingsKey( "somekey" );
    mojo.setUsername( null );
    mojo.setPassword( null );

    mojo.execute();

    assertEquals( "username", mojo.getUsername() );
    assertEquals( "password", mojo.getPassword() );

}
 
Example #11
Source File: AbstractServerConnectionTest.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Gets a settings.xml file from the input File and prepares it to be
 * attached to a pom.xml
 *
 * @param fileName file object pointing to the candidate settings file
 *
 * @return the settings object
 *
 * @throws java.io.IOException - if the settings file can't be read
 */
private Settings getSettingsFile(final String fileName) throws IOException {
    Map<String, ?> options = Collections.singletonMap(SettingsReader.IS_STRICT, Boolean.TRUE);
    SettingsReader reader = new DefaultSettingsReader();
    final File settingsFile = new File(BASE_CONFIG_DIR, fileName);
    assertTrue("Could not find settings file: " + settingsFile.getAbsolutePath(), settingsFile.exists());

    Settings settings = null;
    try {
        settings = reader.read(settingsFile, options);
    } catch (SettingsParseException e) {

    }

    return settings;
}
 
Example #12
Source File: MavenPluginRepository.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private Settings loadDefaultUserSettings() {
	String userHome = System.getProperty("user.home");
    File userMavenConfigurationHome = new File(userHome, ".m2");
    String envM2Home = System.getenv("M2_HOME");
    File DEFAULT_USER_SETTINGS_FILE = new File(userMavenConfigurationHome, "settings.xml");
    File DEFAULT_GLOBAL_SETTINGS_FILE = new File(System.getProperty("maven.home", envM2Home != null ? envM2Home : ""), "conf/settings.xml");
    SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest();
    settingsBuildingRequest.setSystemProperties(System.getProperties());
    settingsBuildingRequest.setUserSettingsFile(DEFAULT_USER_SETTINGS_FILE);
    settingsBuildingRequest.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);

    DefaultSettingsBuilderFactory mvnSettingBuilderFactory = new DefaultSettingsBuilderFactory();
    DefaultSettingsBuilder settingsBuilder = mvnSettingBuilderFactory.newInstance();
    try {
		SettingsBuildingResult settingsBuildingResult = settingsBuilder.build(settingsBuildingRequest);
		Settings settings = settingsBuildingResult.getEffectiveSettings();
		return settings;
	} catch (SettingsBuildingException e) {
		e.printStackTrace();
	}
    return null;
}
 
Example #13
Source File: DefaultVersionsHelperTest.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
private DefaultVersionsHelper createHelper( String rulesUri, ArtifactMetadataSource metadataSource )
    throws MojoExecutionException
{
    final DefaultWagonManager wagonManager = new DefaultWagonManager()
    {
        public Wagon getWagon( Repository repository )
            throws UnsupportedProtocolException, WagonConfigurationException
        {
            return new FileWagon();
        }
    };

    DefaultVersionsHelper helper =
        new DefaultVersionsHelper( new DefaultArtifactFactory(), new DefaultArtifactResolver(), metadataSource, new ArrayList(),
                                   new ArrayList(),
                                   new DefaultArtifactRepository( "", "", new DefaultRepositoryLayout() ),
                                   wagonManager, new Settings(), "", rulesUri, mock( Log.class ), mock( MavenSession.class ),
                                   new DefaultPathTranslator());
    return helper;
}
 
Example #14
Source File: PGPVerifyMojoTest.java    From pgpverify-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * test that if we set a proxy, we want to ensure that it is the right one from our config
 * @throws Exception unexcpected reflection issues etc.
 */
@Test
public void testIfProxyDeterminationWorksUsingIDs() throws Exception {

    List<Proxy> proxies = Arrays.asList(
        makeMavenProxy(null, null, "p1", true),
        makeMavenProxy(null, null, "p2", false));

    PGPVerifyMojo mojo = new PGPVerifyMojo();
    Field settings = PGPVerifyMojo.class.getDeclaredField("settings");
    settings.setAccessible(true);
    Settings mavenSettings = mock(Settings.class);
    settings.set(mojo, mavenSettings);
    Field proxyName = PGPVerifyMojo.class.getDeclaredField("proxyName");
    proxyName.setAccessible(true);

    when(mavenSettings.getProxies()).thenReturn(proxies);

    proxyName.set(mojo, "p2");
    Assert.assertEquals(mojo.getMavenProxy().getId(), "p2");
    proxyName.set(mojo, "p1");
    Assert.assertEquals(mojo.getMavenProxy().getId(), "p1");
    proxyName.set(mojo, "p3");
    Assert.assertNull(mojo.getMavenProxy());
}
 
Example #15
Source File: PGPVerifyMojoTest.java    From pgpverify-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * If the proxy is not set, it should take the first active one
 * @throws Exception unexpected reflection issue
 */
@Test
public void testIfProxyDeterminationWorksUsinFirstActive() throws Exception {
    List<Proxy> proxies = Arrays.asList(
        makeMavenProxy(null, null, "p1", false),
        makeMavenProxy(null, null, "p2", true));
    PGPVerifyMojo mojo = new PGPVerifyMojo();
    Field settings = PGPVerifyMojo.class.getDeclaredField("settings");
    settings.setAccessible(true);
    Settings mavenSettings = mock(Settings.class);
    settings.set(mojo, mavenSettings);
    Field proxyName = PGPVerifyMojo.class.getDeclaredField("proxyName");
    proxyName.setAccessible(true);

    when(mavenSettings.getProxies()).thenReturn(proxies);

    proxyName.set(mojo, null);
    Assert.assertEquals(mojo.getMavenProxy().getId(), "p2");
}
 
Example #16
Source File: JDOMSettingsConverter.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * Method updateSettings.
 *  @param settings
 * @param counter
 * @param element
 */
protected void updateSettings( final Settings settings, final IndentationCounter counter, final Element element )
{
    final IndentationCounter innerCount = new IndentationCounter( counter.getDepth() + 1 );
    findAndReplaceSimpleElement( innerCount, element, "localRepository", settings.getLocalRepository(), null );
    findAndReplaceSimpleElement( innerCount, element, "interactiveMode", String.valueOf( settings.isInteractiveMode() ), "true" );
    findAndReplaceSimpleElement( innerCount, element, "usePluginRegistry", String.valueOf( settings.isUsePluginRegistry() ), "false" );
    findAndReplaceSimpleElement( innerCount, element, "offline", !settings.isOffline() ? null : String.valueOf( settings.isOffline() ),
                                 "false" );
    iterateProxy( innerCount, element, settings.getProxies() );
    iterateServer( innerCount, element, settings.getServers() );
    iterateMirror( innerCount, element, settings.getMirrors() );
    iterateProfile( innerCount, element, settings.getProfiles() );
    findAndReplaceSimpleLists( innerCount, element, settings.getActiveProfiles(), "activeProfiles", "activeProfile" );
    findAndReplaceSimpleLists( innerCount, element, settings.getPluginGroups(), "pluginGroups", "pluginGroup" );
}
 
Example #17
Source File: ConfigurationHelperTest.java    From LicenseScout with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for the method {@link ConfigurationHelper#getExecutionDatabaseConfiguration(DatabaseConfiguration, Settings, ILSLog)}.
 * @throws Exception 
 */
@Test(expected = MojoExecutionException.class)
public void testGetExecutionDatabaseConfigurationServerIdNotFound() throws Exception {
    final Settings settings = createSettings();
    final DatabaseConfiguration databaseConfiguration = new DatabaseConfiguration("jdbcUrl", "serverId_noexisting");
    ConfigurationHelper.getExecutionDatabaseConfiguration(databaseConfiguration, settings,
            TestUtil.createTestLog());
}
 
Example #18
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 #19
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private ArtifactDescriptorResult readArtifactDescriptor(AddonId addonId) throws ArtifactDescriptorException
{
   String coords = toMavenCoords(addonId);
   RepositorySystem system = container.getRepositorySystem();
   Settings settings = getSettings();
   DefaultRepositorySystemSession session = container.setupRepoSession(system, settings);
   List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings);
   ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
   request.setArtifact(new DefaultArtifact(coords));
   request.setRepositories(repositories);

   ArtifactDescriptorResult result = system.readArtifactDescriptor(session, request);
   return result;
}
 
Example #20
Source File: ConfigurationHelperTest.java    From LicenseScout with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for the method {@link ConfigurationHelper#getExecutionDatabaseConfiguration(DatabaseConfiguration, Settings, ILSLog)}.
 * @throws Exception 
 */
@Test
public void testGetExecutionDatabaseConfigurationSuccess() throws Exception {
    final Settings settings = createSettings();
    final DatabaseConfiguration databaseConfiguration = new DatabaseConfiguration("jdbcUrl", "serverId");
    final ExecutionDatabaseConfiguration executionDatabaseConfiguration = ConfigurationHelper
            .getExecutionDatabaseConfiguration(databaseConfiguration, settings, TestUtil.createTestLog());
    Assert.assertEquals("jdbcUrl", "jdbcUrl", executionDatabaseConfiguration.getJdbcUrl());
    Assert.assertEquals("username", "serverIdusername", executionDatabaseConfiguration.getUsername());
    Assert.assertEquals("password", "serverIdpassword", executionDatabaseConfiguration.getPassword());
}
 
Example #21
Source File: ConfigurationHelper.java    From LicenseScout with Apache License 2.0 5 votes vote down vote up
/**
 * Converts Maven database configuration to execution database configuration.
 * 
 * <p>This resolves the server definition given by ID from the settings and takes the DB connection
 * credentials from there.</p>
 * 
 * @param databaseConfiguration
 * @param settings the settings.xml object
 * @param log the logger
 * @return a database configuration for the execution engine
 * @throws MojoExecutionException if the server ID is not found in settings, or username or password are not specified in the server definition
 */
public static ExecutionDatabaseConfiguration getExecutionDatabaseConfiguration(final DatabaseConfiguration databaseConfiguration,
                                                                               final Settings settings,
                                                                               final ILSLog log)
        throws MojoExecutionException {
    if (databaseConfiguration == null) {
        return null;
    }
    final ExecutionDatabaseConfiguration executionDatabaseConfiguration = new ExecutionDatabaseConfiguration();
    executionDatabaseConfiguration.setJdbcUrl(databaseConfiguration.getJdbcUrl());
    final String serverId = databaseConfiguration.getServerId();
    log.info("Resolving database server ID: " + serverId);
    final Server server = settings.getServer(serverId);
    if (server == null) {
        throw new MojoExecutionException(
                String.format("No definition found for server ID %s in settings.xml", serverId));
    }
    final String username = server.getUsername();
    final String password = server.getPassword();
    if (username == null) {
        throw new MojoExecutionException(
                String.format("No username defined in server specification with ID %s in settings.xml", serverId));
    }
    if (password == null) {
        throw new MojoExecutionException(
                String.format("No password defined in server specification with ID %s in settings.xml", serverId));
    }
    executionDatabaseConfiguration.setUsername(username);
    executionDatabaseConfiguration.setPassword(password);
    return executionDatabaseConfiguration;
}
 
Example #22
Source File: RawXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected String getActiveProxyAsHttpproxy() {
	if (getSettings() == null) {
		return null;
	}

	final Settings settings = getSettings();

	final Proxy activeProxy = settings.getActiveProxy();
	if (activeProxy == null || activeProxy.getHost() == null) {
		return null;
	}

	return createXJCProxyArgument(activeProxy.getHost(), activeProxy.getPort(), activeProxy.getUsername(),
			activeProxy.getPassword());
}
 
Example #23
Source File: ConfigurationHelperTest.java    From LicenseScout with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a settings instance for testing.
 * @return a settings instance
 * @throws SettingsBuildingException
 */
private Settings createSettings() throws SettingsBuildingException {
    DefaultSettingsBuilderFactory settingsBuilderFactory = new DefaultSettingsBuilderFactory();
    SettingsBuilder settingsBuilder = settingsBuilderFactory.newInstance();
    DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    final File userSettingsFile = new File("src/test/resources/ConfigurationHelperTest/settings.xml");
    request.setUserSettingsFile(userSettingsFile);
    SettingsBuildingResult settingsBuildingResult = settingsBuilder.build(request);
    return settingsBuildingResult.getEffectiveSettings();
}
 
Example #24
Source File: MavenSettingsReader.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
public MavenSettings readSettings() {
	Settings settings = loadSettings();
	SettingsDecryptionResult decrypted = decryptSettings(settings);
	if (!decrypted.getProblems().isEmpty()) {
		log.error(
				"Maven settings decryption failed. Some Maven repositories may be inaccessible");
		// Continue - the encrypted credentials may not be used
	}
	return new MavenSettings(settings, decrypted);
}
 
Example #25
Source File: MojoParameters.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public MojoParameters(MavenSession session, MavenProject project, MavenArchiveConfiguration archive, MavenFileFilter mavenFileFilter,
                      MavenReaderFilter mavenFilterReader, Settings settings, String sourceDirectory, String outputDirectory, List<MavenProject> reactorProjects) {
    this.archive = archive;
    this.session = session;
    this.mavenFileFilter = mavenFileFilter;
    this.mavenFilterReader = mavenFilterReader;
    this.project = project;
    this.settings = settings;

    this.sourceDirectory = sourceDirectory;
    this.outputDirectory = outputDirectory;

    this.reactorProjects = reactorProjects;
}
 
Example #26
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private MirrorSelector createMirrorSelector(Settings settings) {
	DefaultMirrorSelector selector = new DefaultMirrorSelector();
	for (Mirror mirror : settings.getMirrors()) {
		selector.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(), false,
				mirror.getMirrorOf(), mirror.getMirrorOfLayouts());
	}
	return selector;
}
 
Example #27
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 #28
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private VersionRangeResult getVersions(RepositorySystem system, Settings settings, RepositorySystemSession session,
         List<RemoteRepository> repositories,
         String addonName,
         String version)
{
   try
   {
      String[] split = addonName.split(",");
      if (split.length == 2)
      {
         version = split[1];
      }
      if (version == null || version.isEmpty())
      {
         version = "[,)";
      }
      else if (!version.matches("(\\(|\\[).*?(\\)|\\])"))
      {
         version = "[" + version + "]";
      }

      Artifact artifact = new DefaultArtifact(toMavenCoords(AddonId.from(addonName, version)));
      VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, repositories, null);
      VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
      return rangeResult;
   }
   catch (Exception e)
   {
      throw new RuntimeException("Failed to look up versions for [" + addonName + "]", e);
   }
}
 
Example #29
Source File: DockerAssemblyManagerTest.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private MojoParameters mockMojoParams(MavenProject project) {
    Settings settings = new Settings();
    ArtifactRepository localRepository = new MavenArtifactRepository() {
        @Mock
        public String getBasedir() {
            return "repository";
        }
    };
    @SuppressWarnings("deprecation")
    MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date());
    return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
 
Example #30
Source File: MojoParameters.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
public MojoParameters(MavenSession session, MavenProject project, MavenArchiveConfiguration archive, MavenFileFilter mavenFileFilter,
        MavenReaderFilter mavenFilterReader, Settings settings, String sourceDirectory, String outputDirectory, List<MavenProject> reactorProjects) {
    this.archive = archive;
    this.session = session;
    this.mavenFileFilter = mavenFileFilter;
    this.mavenFilterReader = mavenFilterReader;
    this.project = project;
    this.settings = settings;

    this.sourceDirectory = sourceDirectory;
    this.outputDirectory = outputDirectory;
    
    this.reactorProjects = reactorProjects;
}