Search in sources :

Example 11 with Settings

use of org.apache.maven.settings.Settings in project bazel by bazelbuild.

the class MavenServerFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException, RepositoryFunctionException {
    String repository = (String) skyKey.argument();
    Rule repositoryRule = null;
    try {
        repositoryRule = RepositoryFunction.getRule(repository, env);
    } catch (RepositoryNotFoundException ex) {
    // Ignored. We throw a new one below.
    }
    BlazeDirectories directories = PrecomputedValue.BLAZE_DIRECTORIES.get(env);
    if (env.valuesMissing()) {
        return null;
    }
    String serverName;
    String url;
    Map<String, FileValue> settingsFiles;
    boolean foundRepoRule = repositoryRule != null && repositoryRule.getRuleClass().equals(MavenServerRule.NAME);
    if (!foundRepoRule) {
        if (repository.equals(MavenServerValue.DEFAULT_ID)) {
            settingsFiles = getDefaultSettingsFile(directories, env);
            serverName = MavenServerValue.DEFAULT_ID;
            url = MavenConnector.getMavenCentralRemote().getUrl();
        } else {
            throw new RepositoryFunctionException(new IOException("Could not find maven repository " + repository), Transience.TRANSIENT);
        }
    } else {
        WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(repositoryRule);
        serverName = repositoryRule.getName();
        try {
            url = mapper.get("url", Type.STRING);
            if (!mapper.isAttributeValueExplicitlySpecified("settings_file")) {
                settingsFiles = getDefaultSettingsFile(directories, env);
            } else {
                PathFragment settingsFilePath = new PathFragment(mapper.get("settings_file", Type.STRING));
                RootedPath settingsPath = RootedPath.toRootedPath(directories.getWorkspace().getRelative(settingsFilePath), PathFragment.EMPTY_FRAGMENT);
                FileValue fileValue = (FileValue) env.getValue(FileValue.key(settingsPath));
                if (fileValue == null) {
                    return null;
                }
                if (!fileValue.exists()) {
                    throw new RepositoryFunctionException(new IOException("Could not find settings file " + settingsPath), Transience.TRANSIENT);
                }
                settingsFiles = ImmutableMap.<String, FileValue>builder().put(USER_KEY, fileValue).build();
            }
        } catch (EvalException e) {
            throw new RepositoryFunctionException(e, Transience.PERSISTENT);
        }
    }
    if (settingsFiles == null) {
        return null;
    }
    Fingerprint fingerprint = new Fingerprint();
    try {
        for (Map.Entry<String, FileValue> entry : settingsFiles.entrySet()) {
            fingerprint.addString(entry.getKey());
            Path path = entry.getValue().realRootedPath().asPath();
            if (path.exists()) {
                fingerprint.addBoolean(true);
                fingerprint.addBytes(path.getDigest());
            } else {
                fingerprint.addBoolean(false);
            }
        }
    } catch (IOException e) {
        throw new RepositoryFunctionException(e, Transience.TRANSIENT);
    }
    byte[] fingerprintBytes = fingerprint.digestAndReset();
    if (settingsFiles.isEmpty()) {
        return new MavenServerValue(serverName, url, new Server(), fingerprintBytes);
    }
    DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    if (settingsFiles.containsKey(SYSTEM_KEY)) {
        request.setGlobalSettingsFile(settingsFiles.get(SYSTEM_KEY).realRootedPath().asPath().getPathFile());
    }
    if (settingsFiles.containsKey(USER_KEY)) {
        request.setUserSettingsFile(settingsFiles.get(USER_KEY).realRootedPath().asPath().getPathFile());
    }
    DefaultSettingsBuilder builder = (new DefaultSettingsBuilderFactory()).newInstance();
    SettingsBuildingResult result;
    try {
        result = builder.build(request);
    } catch (SettingsBuildingException e) {
        throw new RepositoryFunctionException(new IOException("Error parsing settings files: " + e.getMessage()), Transience.TRANSIENT);
    }
    if (!result.getProblems().isEmpty()) {
        throw new RepositoryFunctionException(new IOException("Errors interpreting settings file: " + Arrays.toString(result.getProblems().toArray())), Transience.PERSISTENT);
    }
    Settings settings = result.getEffectiveSettings();
    Server server = settings.getServer(serverName);
    server = server == null ? new Server() : server;
    return new MavenServerValue(serverName, url, server, fingerprintBytes);
}
Also used : FileValue(com.google.devtools.build.lib.skyframe.FileValue) Server(org.apache.maven.settings.Server) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) RepositoryFunctionException(com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException) Settings(org.apache.maven.settings.Settings) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) Fingerprint(com.google.devtools.build.lib.util.Fingerprint) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) RepositoryNotFoundException(com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryNotFoundException) IOException(java.io.IOException) EvalException(com.google.devtools.build.lib.syntax.EvalException) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) DefaultSettingsBuilder(org.apache.maven.settings.building.DefaultSettingsBuilder) MavenServerRule(com.google.devtools.build.lib.bazel.rules.workspace.MavenServerRule) Rule(com.google.devtools.build.lib.packages.Rule) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkspaceAttributeMapper(com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper) Nullable(javax.annotation.Nullable)

Example 12 with Settings

use of org.apache.maven.settings.Settings in project gradle by gradle.

the class PomProjectInitDescriptor method generate.

@Override
public void generate(BuildInitTestFramework testFramework) {
    SingleMessageLogger.incubatingFeatureUsed("Maven to Gradle conversion");
    File pom = fileResolver.resolve("pom.xml");
    try {
        Settings settings = settingsProvider.buildSettings();
        Set<MavenProject> mavenProjects = new MavenProjectsCreator().create(settings, pom);
        new Maven2Gradle(mavenProjects, fileResolver.resolve(".")).convert();
    } catch (Exception exception) {
        throw new MavenConversionException(String.format("Could not convert Maven POM %s to a Gradle build.", pom), exception);
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MavenProjectsCreator(org.gradle.buildinit.plugins.internal.maven.MavenProjectsCreator) Maven2Gradle(org.gradle.buildinit.plugins.internal.maven.Maven2Gradle) File(java.io.File) MavenConversionException(org.gradle.buildinit.plugins.internal.maven.MavenConversionException) Settings(org.apache.maven.settings.Settings) MavenConversionException(org.gradle.buildinit.plugins.internal.maven.MavenConversionException)

Example 13 with Settings

use of org.apache.maven.settings.Settings in project spring-boot by spring-projects.

the class MavenSettingsReader method readSettings.

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);
}
Also used : SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) Settings(org.apache.maven.settings.Settings)

Example 14 with Settings

use of org.apache.maven.settings.Settings in project intellij-plugins by JetBrains.

the class GeneratorServer method createSettings.

private Settings createSettings(MavenExecutionRequest mavenExecutionRequest) throws ComponentLookupException, SettingsBuildingException {
    SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    request.setSystemProperties(request.getSystemProperties());
    request.setGlobalSettingsFile(mavenExecutionRequest.getGlobalSettingsFile());
    request.setUserSettingsFile(mavenExecutionRequest.getUserSettingsFile());
    // IDEA-87004, getEffectiveSettings contains local repo as null, but our mavenExecutionRequest already has not-null local repo
    Settings settings = plexusContainer.lookup(SettingsBuilder.class).build(request).getEffectiveSettings();
    settings.setLocalRepository(mavenExecutionRequest.getLocalRepositoryPath().getPath());
    return settings;
}
Also used : DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 15 with Settings

use of org.apache.maven.settings.Settings in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method buildSettings.

private static Settings buildSettings(SettingsBuilder builder, MavenServerSettings settings, Properties systemProperties, Properties userProperties) throws RemoteException {
    SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setGlobalSettingsFile(settings.getGlobalSettingsFile());
    settingsRequest.setUserSettingsFile(settings.getUserSettingsFile());
    settingsRequest.setSystemProperties(systemProperties);
    settingsRequest.setUserProperties(userProperties);
    Settings result = new Settings();
    try {
        result = builder.build(settingsRequest).getEffectiveSettings();
    } catch (SettingsBuildingException e) {
        Maven3ServerGlobals.getLogger().info(e);
    }
    result.setOffline(settings.isOffline());
    if (settings.getLocalRepository() != null) {
        result.setLocalRepository(settings.getLocalRepository().getPath());
    }
    if (result.getLocalRepository() == null) {
        result.setLocalRepository(new File(SystemProperties.getUserHome(), ".m2/repository").getPath());
    }
    return result;
}
Also used : File(java.io.File) Settings(org.apache.maven.settings.Settings)

Aggregations

Settings (org.apache.maven.settings.Settings)27 File (java.io.File)15 Proxy (org.apache.maven.settings.Proxy)6 IOException (java.io.IOException)5 DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)5 MavenProject (org.apache.maven.project.MavenProject)4 Server (org.apache.maven.settings.Server)4 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)4 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 MavenSession (org.apache.maven.execution.MavenSession)3 AbstractMojo (org.apache.maven.plugin.AbstractMojo)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 SiteMavenProjectStub (org.apache.maven.plugins.site.stubs.SiteMavenProjectStub)3 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)3 StringWriter (java.io.StringWriter)2 Properties (java.util.Properties)2 Maven2Gradle (org.gradle.buildinit.plugins.internal.maven.Maven2Gradle)2 MavenConversionException (org.gradle.buildinit.plugins.internal.maven.MavenConversionException)2