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-8043] Dependency properties should be provided by Maven #1399

Merged
merged 9 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public enum DependencyScope {
* System scope.
* <p>
* Important: this scope {@code id} MUST BE KEPT in sync with label in
* {@code org.eclipse.aether.util.artifact.Scopes#SYSTEM}.
* {@code org.eclipse.aether.util.artifact.DependencyScopes#SYSTEM}.
gnodet marked this conversation as resolved.
Show resolved Hide resolved
*/
SYSTEM("system", false);

Expand Down Expand Up @@ -125,4 +125,8 @@ public String id() {
public boolean isTransitive() {
return transitive;
}

public boolean is(String id) {
return id().equals(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.internal.impl.types;
package org.apache.maven.api.spi;

import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;

@Named(PomTypeProvider.NAME)
@Singleton
public class PomTypeProvider implements Provider<Type> {
public static final String NAME = "pom";

private final Type type;

public PomTypeProvider() {
this.type = new DefaultType(NAME, Language.NONE, "pom", null, false, false);
}

@Override
public Type get() {
return type;
}
}
public interface TypeProvider extends ExtensibleEnumProvider<Type> {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.apache.maven.api.Type;
import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.internal.impl.DefaultType;
import org.apache.maven.repository.internal.type.DefaultType;
import org.eclipse.aether.artifact.ArtifactType;
import org.eclipse.aether.artifact.ArtifactTypeRegistry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@
import javax.inject.Named;
import javax.inject.Singleton;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.apache.maven.api.Type;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.services.LanguageRegistry;
import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.api.spi.TypeProvider;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.LegacyArtifactHandlerManager;
import org.apache.maven.eventspy.AbstractEventSpy;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.repository.internal.type.DefaultType;

import static java.util.function.Function.identity;
import static org.apache.maven.internal.impl.Utils.nonNull;

@Named
Expand All @@ -46,17 +51,16 @@ public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistr

private final ConcurrentHashMap<String, Type> usedTypes;

private final ConcurrentHashMap<String, Type> legacyTypes;

private final LegacyArtifactHandlerManager manager;

@Inject
public DefaultTypeRegistry(
Map<String, Type> types, LanguageRegistry languageRegistry, LegacyArtifactHandlerManager manager) {
this.types = nonNull(types, "types");
List<TypeProvider> providers, LanguageRegistry languageRegistry, LegacyArtifactHandlerManager manager) {
this.types = nonNull(providers, "providers").stream()
.flatMap(p -> p.provides().stream())
.collect(Collectors.toMap(Type::id, identity()));
this.languageRegistry = nonNull(languageRegistry, "languageRegistry");
this.usedTypes = new ConcurrentHashMap<>();
this.legacyTypes = new ConcurrentHashMap<>();
this.manager = nonNull(manager, "artifactHandlerManager");
}

Expand All @@ -66,7 +70,6 @@ public void onEvent(Object event) {
ExecutionEvent executionEvent = (ExecutionEvent) event;
if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
usedTypes.clear();
legacyTypes.clear();
}
}
}
Expand All @@ -83,18 +86,15 @@ public Type require(String id) {
return usedTypes.computeIfAbsent(id, i -> {
Type type = types.get(id);
if (type == null) {
// legacy types ALWAYS return type (AHM never returns null)
type = legacyTypes.computeIfAbsent(id, k -> {
// Copy data as the ArtifactHandler is not immutable, but Type should be.
ArtifactHandler handler = manager.getArtifactHandler(id);
return new DefaultType(
id,
languageRegistry.require(handler.getLanguage()),
handler.getExtension(),
handler.getClassifier(),
handler.isAddedToClasspath(),
handler.isIncludesDependencies());
});
// Copy data as the ArtifactHandler is not immutable, but Type should be.
ArtifactHandler handler = manager.getArtifactHandler(id);
type = new DefaultType(
id,
languageRegistry.require(handler.getLanguage()),
handler.getExtension(),
handler.getClassifier(),
handler.isAddedToClasspath(),
handler.isIncludesDependencies());
}
return type;
});
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.