Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8006] SPI to contribute to effective properties and more #1384

Merged
merged 20 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.maven.api.annotations.Experimental;
Expand Down Expand Up @@ -133,4 +134,10 @@ default String getId() {

@Nonnull
List<RemoteRepository> getRemotePluginRepositories();

/**
* Returns the effective project properties.
*/
@Nonnull
Map<String, String> getProperties();
gnodet marked this conversation as resolved.
Show resolved Hide resolved
}
17 changes: 13 additions & 4 deletions api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.annotations.ThreadSafe;
import org.apache.maven.api.model.Repository;
import org.apache.maven.api.services.DependencyCoordinateFactory;
Expand Down Expand Up @@ -55,23 +56,31 @@ public interface Session {
SessionData getData();

/**
* Gets the user properties to use for interpolation. The user properties have been configured directly by the user,
* e.g. via the {@code -Dkey=value} parameter on the command line.
* Gets the immutable user properties to use for interpolation. The user properties have been configured directly
* by the user, e.g. via the {@code -Dkey=value} parameter on the command line.
*
* @return the user properties, never {@code null}
*/
@Nonnull
Map<String, String> getUserProperties();

/**
* Gets the system properties to use for interpolation. The system properties are collected from the runtime
* environment such as {@link System#getProperties()} and environment variables.
* Gets the immutable system properties to use for interpolation. The system properties are collected from the
* runtime environment such as {@link System#getProperties()} and environment variables.
*
* @return the system properties, never {@code null}
*/
@Nonnull
Map<String, String> getSystemProperties();

/**
* Gets the effective properties to use for interpolation.
*
* @return the effective properties, never {@code null}
gnodet marked this conversation as resolved.
Show resolved Hide resolved
*/
@Nonnull
Map<String, String> getEffectiveProperties(@Nullable Project project);
gnodet marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the current maven version
* @return the maven version, never {@code null}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.api.services;

import java.util.Map;

import org.apache.maven.api.*;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;

/**
* @since 4.0.0
*/
@Experimental
public interface Properties extends Service {

/**
* Creates a {@link org.apache.maven.api.Project} from a POM file.
gnodet marked this conversation as resolved.
Show resolved Hide resolved
*
* @param project {@link Project} or {@code null}.
* @return the {@link Map} containing the effective properties.
* @throws IllegalArgumentException if an argument is {@code null} or invalid
*/
@Nonnull
Map<String, String> effectiveProperties(@Nonnull Session session, @Nullable Project project);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.api.spi.session;

import java.util.Map;

import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;

/**
* Component able to contribute to Maven session effective properties. This SPI component is invoked
* very early, while there is no session created yet.
*/
@Experimental
public interface EffectivePropertyContributor {
/**
* Invoked just before session is created with a mutable map that carries collected effective properties so far.
* Values set here will override everything coming from {@link Session#getSystemProperties()} and
* {@link Session#getUserProperties()} and can be queried via {@link Session#getEffectiveProperties()}.
*
* @param effectiveProperties The mutable effective properties, never {@code null}.
*/
void contribute(Map<String, Object> effectiveProperties);
}
8 changes: 4 additions & 4 deletions maven-core/src/main/java/org/apache/maven/DefaultMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.graph.GraphBuilder;
import org.apache.maven.graph.ProjectSelector;
import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory;
import org.apache.maven.internal.aether.MavenChainedWorkspaceReader;
import org.apache.maven.internal.impl.DefaultSessionFactory;
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.lifecycle.LifecycleExecutionException;
Expand All @@ -71,6 +69,8 @@
import org.apache.maven.model.superpom.SuperPomProvider;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.MavenProject;
import org.apache.maven.resolver.MavenChainedWorkspaceReader;
import org.apache.maven.resolver.RepositorySystemSessionFactory;
import org.apache.maven.session.scope.internal.SessionScope;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession.CloseableSession;
Expand Down Expand Up @@ -99,7 +99,7 @@ public class DefaultMaven implements Maven {

private final SessionScope sessionScope;

private final DefaultRepositorySystemSessionFactory repositorySessionFactory;
private final RepositorySystemSessionFactory repositorySessionFactory;

private final GraphBuilder graphBuilder;

Expand All @@ -123,7 +123,7 @@ public DefaultMaven(
ExecutionEventCatapult eventCatapult,
LegacySupport legacySupport,
SessionScope sessionScope,
DefaultRepositorySystemSessionFactory repositorySessionFactory,
RepositorySystemSessionFactory repositorySessionFactory,
@Named(GraphBuilder.HINT) GraphBuilder graphBuilder,
BuildResumptionAnalyzer buildResumptionAnalyzer,
BuildResumptionDataRepository buildResumptionDataRepository,
Expand Down
Loading
Loading