[MNG-8026] Maven drives regarding scopes (#1391)

Changes:
* new types for build path, path scope, dependency scope, language
* introduce "extensible enum" and provides registries, SPI providers, etc...
---------
Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
This commit is contained in:
Tamas Cservenak 2024-02-05 10:42:51 +01:00 committed by GitHub
parent b3ec995848
commit 3f9fec2307
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
55 changed files with 1065 additions and 477 deletions

View File

@ -30,16 +30,8 @@ public interface Dependency extends Artifact {
@Nonnull @Nonnull
Type getType(); Type getType();
/**
* The dependency properties.
*
* @return the dependency properties, never {@code null}
*/
@Nonnull @Nonnull
DependencyProperties getDependencyProperties(); DependencyScope getScope();
@Nonnull
Scope getScope();
boolean isOptional(); boolean isOptional();

View File

@ -41,7 +41,7 @@ public interface DependencyCoordinate extends ArtifactCoordinate {
Type getType(); Type getType();
@Nonnull @Nonnull
Scope getScope(); DependencyScope getScope();
@Nullable @Nullable
Boolean getOptional(); Boolean getOptional();

View File

@ -0,0 +1,128 @@
/*
* 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;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
/**
* Dependency scope.
* This represents at which time the dependency will be used, for example, at compile time only,
* at run time or at test time. For a given dependency, the scope is directly derived from the
* {@link org.apache.maven.api.model.Dependency#getScope()} and will be used when using {@link PathScope}
* and the {@link org.apache.maven.api.services.DependencyResolver}.
*
* @since 4.0.0
* @see org.apache.maven.api.model.Dependency#getScope()
* @see org.apache.maven.api.services.DependencyResolver
*/
@Experimental
@Immutable
public enum DependencyScope {
/**
* None. Allows you to declare dependencies (for example to alter reactor build order) but in reality dependencies
* in this scope are not part of any path scope.
*/
NONE("none", false),
/**
* Empty scope.
*/
EMPTY("", false),
/**
* Compile only.
*/
COMPILE_ONLY("compile-only", false),
/**
* Compile, runtime and test.
*/
COMPILE("compile", true),
/**
* Runtime and test.
*/
RUNTIME("runtime", true),
/**
* Provided.
*/
PROVIDED("provided", false),
/**
* Test compile only.
*/
TEST_ONLY("test-only", false),
/**
* Test compile and test runtime.
*/
TEST("test", false),
/**
* Test runtime.
*/
TEST_RUNTIME("test-runtime", true),
/**
* System scope.
* <p>
* Important: this scope {@code id} MUST BE KEPT in sync with label in
* {@code org.eclipse.aether.util.artifact.Scopes#SYSTEM}.
*/
SYSTEM("system", false);
private static final Map<String, DependencyScope> IDS = Collections.unmodifiableMap(
Stream.of(DependencyScope.values()).collect(Collectors.toMap(s -> s.id, s -> s)));
public static DependencyScope forId(String id) {
return IDS.get(id);
}
private final String id;
private final boolean transitive;
DependencyScope(String id, boolean transitive) {
this.id = id;
this.transitive = transitive;
}
/**
* The {@code id} uniquely represents a value for this extensible enum.
* This id should be used to compute the equality and hash code for the instance.
*
* @return the id
*/
@Nonnull
public String id() {
return id;
}
public boolean isTransitive() {
return transitive;
}
}

View File

@ -0,0 +1,37 @@
/*
* 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;
import org.apache.maven.api.annotations.Nonnull;
/**
* Implementation must have {@code equals()} and {@code hashCode()} implemented, so implementations of this interface
* can be used as keys.
*/
public interface ExtensibleEnum {
/**
* The {@code id} uniquely represents a value for this extensible enum.
* This id should be used to compute the equality and hash code for the instance.
*
* @return the id
*/
@Nonnull
String id();
}

View File

@ -0,0 +1,100 @@
/*
* 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;
import java.util.*;
abstract class ExtensibleEnums {
static Language language(String id) {
return new DefaultLanguage(id);
}
static PathScope pathScope(String id, ProjectScope projectScope, DependencyScope... dependencyScopes) {
return new DefaultPathScope(id, projectScope, dependencyScopes);
}
static ProjectScope projectScope(String id) {
return new DefaultProjectScope(id);
}
private static class DefaultExtensibleEnum implements ExtensibleEnum {
private final String id;
DefaultExtensibleEnum(String id) {
this.id = Objects.requireNonNull(id);
}
public String id() {
return id;
}
@Override
public int hashCode() {
return id().hashCode();
}
@Override
public boolean equals(Object obj) {
return obj != null && getClass() == obj.getClass() && id().equals(((DefaultExtensibleEnum) obj).id());
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + id() + "]";
}
}
private static class DefaultPathScope extends DefaultExtensibleEnum implements PathScope {
private final ProjectScope projectScope;
private final Set<DependencyScope> dependencyScopes;
DefaultPathScope(String id, ProjectScope projectScope, DependencyScope... dependencyScopes) {
super(id);
this.projectScope = Objects.requireNonNull(projectScope);
this.dependencyScopes =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(Objects.requireNonNull(dependencyScopes))));
}
@Override
public ProjectScope projectScope() {
return projectScope;
}
@Override
public Set<DependencyScope> dependencyScopes() {
return dependencyScopes;
}
}
private static class DefaultProjectScope extends DefaultExtensibleEnum implements ProjectScope {
DefaultProjectScope(String id) {
super(id);
}
}
private static class DefaultLanguage extends DefaultExtensibleEnum implements Language {
DefaultLanguage(String id) {
super(id);
}
}
}

View File

@ -0,0 +1,50 @@
/*
* 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;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import static org.apache.maven.api.ExtensibleEnums.language;
/**
* Language.
* <p>
* This extensible enum has two defined values, {@link #NONE} and {@link #JAVA_FAMILY},
* but can be extended by registering a {@code org.apache.maven.api.spi.LanguageProvider}.
* <p>
* Implementation must have {@code equals()} and {@code hashCode()} implemented, so implementations of this interface
* can be used as keys.
*
* @since 4.0.0
*/
@Experimental
@Immutable
@SuppressWarnings("checkstyle:InterfaceIsType")
public interface Language extends ExtensibleEnum {
/**
* The "none" language. It is not versioned, family is same to itself, and compatible with itself only.
* In turn, every {@link Language} implementation must be compatible with {@code NONE} language.
*/
Language NONE = language("none");
// TODO: this should be moved out from here to Java Support (builtin into core)
Language JAVA_FAMILY = language("java");
}

View File

@ -18,42 +18,38 @@
*/ */
package org.apache.maven.api; package org.apache.maven.api;
import java.util.Map;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable; import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
/** /**
* Dependency properties supported by Maven Core. * Interface representing a Maven project packaging.
* <p>
* TODO: define how to plug in new packaging definitions using the SPI.
* the packaging are currently defined by Maven 3 {@code Provider<LifecycleMapping>}
* *
* @since 4.0.0 * @since 4.0.0
*/ */
@Experimental @Experimental
@Immutable @Immutable
public interface DependencyProperties { public interface Packaging extends ExtensibleEnum {
/** /**
* Boolean flag telling that dependency contains all of its dependencies. Value of this key should be parsed with * The packaging id.
* {@link Boolean#parseBoolean(String)} to obtain value.
* <p>
* <em>Important: this flag must be kept in sync with resolver! (as is used during collection)</em>
*/
String FLAG_INCLUDES_DEPENDENCIES = "includesDependencies";
/**
* Boolean flag telling that dependency is meant to be placed on class path. Value of this key should be parsed with
* {@link Boolean#parseBoolean(String)} to obtain value.
*/
String FLAG_CLASS_PATH_CONSTITUENT = "classPathConstituent";
/**
* Returns immutable "map view" of all the properties.
*/ */
@Nonnull @Nonnull
Map<String, String> asMap(); String id();
/** /**
* Returns {@code true} if given flag is {@code true}. * The language of this packaging.
*/ */
boolean checkFlag(@Nonnull String flag); @Nonnull
default Language language() {
return getType().getLanguage();
}
/**
* The type of main artifact produced by this packaging.
*/
@Nonnull
Type getType();
} }

View File

@ -0,0 +1,84 @@
/*
* 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;
import java.util.*;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
import static org.apache.maven.api.ExtensibleEnums.pathScope;
/**
* Path scope.
* A path scope is used to determine the kind of build or class path that will be built when resolving
* dependencies using the {@link org.apache.maven.api.services.DependencyResolver} service.
* <p>
* This extensible enum has four defined values, {@link #MAIN_COMPILE}, {@link #MAIN_RUNTIME},
* {@link #TEST_COMPILE} and {@link #TEST_RUNTIME}, but can be extended by registering a
* {@code org.apache.maven.api.spi.PathScopeProvider}.
* <p>
* Implementation must have {@code equals()} and {@code hashCode()} implemented, so implementations of this interface
* can be used as keys.
*
* @since 4.0.0
* @see org.apache.maven.api.services.DependencyResolver
* @see DependencyScope
*/
@Experimental
@Immutable
public interface PathScope extends ExtensibleEnum {
@Nonnull
ProjectScope projectScope();
@Nonnull
Set<DependencyScope> dependencyScopes();
PathScope MAIN_COMPILE = pathScope(
"main-compile",
ProjectScope.MAIN,
DependencyScope.EMPTY,
DependencyScope.COMPILE_ONLY,
DependencyScope.COMPILE,
DependencyScope.PROVIDED);
PathScope MAIN_RUNTIME = pathScope(
"main-runtime", ProjectScope.MAIN, DependencyScope.EMPTY, DependencyScope.COMPILE, DependencyScope.RUNTIME);
PathScope TEST_COMPILE = pathScope(
"test-compile",
ProjectScope.TEST,
DependencyScope.EMPTY,
DependencyScope.COMPILE,
DependencyScope.PROVIDED,
DependencyScope.TEST_ONLY,
DependencyScope.TEST);
PathScope TEST_RUNTIME = pathScope(
"test-runtime",
ProjectScope.TEST,
DependencyScope.EMPTY,
DependencyScope.COMPILE,
DependencyScope.RUNTIME,
DependencyScope.PROVIDED,
DependencyScope.TEST,
DependencyScope.TEST_RUNTIME);
}

View File

@ -76,7 +76,17 @@ public interface Project {
* @see #getArtifacts() * @see #getArtifacts()
*/ */
@Nonnull @Nonnull
String getPackaging(); Packaging getPackaging();
/**
* Returns the project language. It is by default determined by {@link #getPackaging()}.
*
* @see #getPackaging()
*/
@Nonnull
default Language getLanguage() {
return getPackaging().language();
}
/** /**
* Returns the project POM artifact, which is the artifact of the POM of this project. Every project have a POM * Returns the project POM artifact, which is the artifact of the POM of this project. Every project have a POM

View File

@ -18,49 +18,36 @@
*/ */
package org.apache.maven.api; package org.apache.maven.api;
import java.util.HashMap;
import java.util.Map;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import static org.apache.maven.api.ExtensibleEnums.projectScope;
/** /**
* Scope for a dependency * Project scope.
* Defines the type of source files to compile, usually either the one that compose the output package
* (i.e. the <i>main</i> artifact) or the ones that will be used when building <i>tests</i>).
* <p>
* This extensible enum has two defined values, {@link #MAIN} and {@link #TEST},
* but can be extended by registering a {@code org.apache.maven.api.spi.ProjectScopeProvider}.
* <p>
* Implementation must have {@code equals()} and {@code hashCode()} implemented, so implementations of this interface
* can be used as keys.
* *
* @since 4.0.0 * @since 4.0.0
*/ */
@Experimental @Experimental
public enum Scope { @Immutable
EMPTY(""), @SuppressWarnings("checkstyle:InterfaceIsType")
COMPILE_ONLY("compile-only"), public interface ProjectScope extends ExtensibleEnum {
COMPILE("compile"),
RUNTIME("runtime"),
PROVIDED("provided"),
TEST_COMPILE_ONLY("test-compile-only"),
TEST("test"),
TEST_RUNTIME("test-runtime"),
IMPORT("import"); // TODO: v4: remove import scope somehow
private final String id; /**
* Main scope.
*/
ProjectScope MAIN = projectScope("main");
private static final Map<String, Scope> SCOPES; /**
* Test scope.
static { */
Map<String, Scope> scopes = new HashMap<>(); ProjectScope TEST = projectScope("test");
for (Scope s : Scope.values()) {
scopes.put(s.id, s);
}
SCOPES = scopes;
}
Scope(String id) {
this.id = id;
}
public String id() {
return this.id;
}
public static Scope get(String scope) {
return SCOPES.get(scope);
}
} }

View File

@ -1,97 +0,0 @@
/*
* 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;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.api.annotations.Experimental;
/**
* Dependencies resolution scopes available before
* <a href="/ref/current/maven-core/apidocs/org/apache/maven/lifecycle/internal/MojoExecutor.html">mojo execution</a>.
*
* Important note: The {@code id} values of this enum correspond to constants of
* {@code org.apache.maven.artifact.Artifact} class and MUST BE KEPT IN SYNC.
*
* @since 4.0.0
*/
@Experimental
public enum ResolutionScope {
/**
* <code>compile</code> resolution scope
* = <code>compile-only</code> + <code>compile</code> + <code>provided</code> dependencies
*/
PROJECT_COMPILE("project-compile", Scope.EMPTY, Scope.COMPILE_ONLY, Scope.COMPILE, Scope.PROVIDED),
/**
* <code>runtime</code> resolution scope
* = <code>compile</code> + <code>runtime</code> dependencies
*/
PROJECT_RUNTIME("project-runtime", Scope.EMPTY, Scope.COMPILE, Scope.RUNTIME),
/**
* <code>test-compile</code> resolution scope
* = <code>compile-only</code> + <code>compile</code> + <code>provided</code> + <code>test-compile-only</code> + <code>test</code>
* dependencies
*/
TEST_COMPILE(
"test-compile",
Scope.EMPTY,
Scope.COMPILE_ONLY,
Scope.COMPILE,
Scope.PROVIDED,
Scope.TEST_COMPILE_ONLY,
Scope.TEST),
/**
* <code>test</code> resolution scope
* = <code>compile</code> + <code>runtime</code> + <code>provided</code> + <code>test</code> + <code>test-runtime</code>
* dependencies
*/
TEST_RUNTIME(
"test-runtime", Scope.EMPTY, Scope.COMPILE, Scope.RUNTIME, Scope.PROVIDED, Scope.TEST, Scope.TEST_RUNTIME);
private static final Map<String, ResolutionScope> VALUES =
Stream.of(ResolutionScope.values()).collect(Collectors.toMap(ResolutionScope::id, s -> s));
public static ResolutionScope fromString(String id) {
return Optional.ofNullable(VALUES.get(id))
.orElseThrow(() -> new IllegalArgumentException("Unknown resolution scope " + id));
}
private final String id;
private final Set<Scope> scopes;
ResolutionScope(String id, Scope... scopes) {
this.id = id;
this.scopes = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(scopes)));
}
public String id() {
return this.id;
}
public Set<Scope> scopes() {
return scopes;
}
}

View File

@ -385,6 +385,9 @@ Artifact createArtifact(
* Checks whether a given artifact version is considered a {@code SNAPSHOT} or not. * Checks whether a given artifact version is considered a {@code SNAPSHOT} or not.
* <p> * <p>
* Shortcut for {@code getService(ArtifactManager.class).isSnapshot(...)}. * Shortcut for {@code getService(ArtifactManager.class).isSnapshot(...)}.
* <p>
* In case there is {@link Artifact} in scope, the recommended way to perform this check is
* use of {@link Artifact#isSnapshot()} instead.
* *
* @see org.apache.maven.api.services.VersionParser#isSnapshot(String) * @see org.apache.maven.api.services.VersionParser#isSnapshot(String)
*/ */
@ -424,11 +427,11 @@ Artifact createArtifact(
/** /**
* Shortcut for {@code getService(DependencyResolver.class).flatten(...)}. * Shortcut for {@code getService(DependencyResolver.class).flatten(...)}.
* *
* @see org.apache.maven.api.services.DependencyResolver#flatten(Session, Node, ResolutionScope) * @see org.apache.maven.api.services.DependencyResolver#flatten(Session, Node, PathScope)
* @throws org.apache.maven.api.services.DependencyResolverException if the dependency flattening failed * @throws org.apache.maven.api.services.DependencyResolverException if the dependency flattening failed
*/ */
@Nonnull @Nonnull
List<Node> flattenDependencies(@Nonnull Node node, @Nonnull ResolutionScope scope); List<Node> flattenDependencies(@Nonnull Node node, @Nonnull PathScope scope);
@Nonnull @Nonnull
List<Path> resolveDependencies(@Nonnull DependencyCoordinate dependencyCoordinate); List<Path> resolveDependencies(@Nonnull DependencyCoordinate dependencyCoordinate);
@ -437,7 +440,7 @@ Artifact createArtifact(
List<Path> resolveDependencies(@Nonnull List<DependencyCoordinate> dependencyCoordinates); List<Path> resolveDependencies(@Nonnull List<DependencyCoordinate> dependencyCoordinates);
@Nonnull @Nonnull
List<Path> resolveDependencies(@Nonnull Project project, @Nonnull ResolutionScope scope); List<Path> resolveDependencies(@Nonnull Project project, @Nonnull PathScope scope);
/** /**
* Resolves an artifact's meta version (if any) to a concrete version. For example, resolves "1.0-SNAPSHOT" * Resolves an artifact's meta version (if any) to a concrete version. For example, resolves "1.0-SNAPSHOT"
@ -498,4 +501,16 @@ Artifact createArtifact(
*/ */
@Nonnull @Nonnull
VersionConstraint parseVersionConstraint(@Nonnull String versionConstraint); VersionConstraint parseVersionConstraint(@Nonnull String versionConstraint);
Type requireType(String id);
Language requireLanguage(String id);
Packaging requirePackaging(String id);
ProjectScope requireProjectScope(String id);
DependencyScope requireDependencyScope(String id);
PathScope requirePathScope(String id);
} }

View File

@ -30,21 +30,17 @@
* <p> * <p>
* It provides information about the file type (or extension) of the associated artifact, * It provides information about the file type (or extension) of the associated artifact,
* its default classifier, and how the artifact will be used in the build when creating * its default classifier, and how the artifact will be used in the build when creating
* classpaths. * various build paths.
* <p> * <p>
* For example, the type {@code java-source} has a {@code jar} extension and a * For example, the type {@code java-source} has a {@code jar} extension and a
* {@code sources} classifier. The artifact and its dependencies should be added * {@code sources} classifier. The artifact and its dependencies should be added
* to the classpath. * to the build path.
* *
* @since 4.0.0 * @since 4.0.0
*/ */
@Experimental @Experimental
@Immutable @Immutable
public interface Type { public interface Type extends ExtensibleEnum {
String LANGUAGE_NONE = "none";
String LANGUAGE_JAVA = "java";
/** /**
* Returns the dependency type id. * Returns the dependency type id.
* The id uniquely identifies this <i>dependency type</i>. * The id uniquely identifies this <i>dependency type</i>.
@ -52,14 +48,15 @@ public interface Type {
* @return the id of this type, never {@code null}. * @return the id of this type, never {@code null}.
*/ */
@Nonnull @Nonnull
String getId(); String id();
/** /**
* Returns the dependency type language. * Returns the dependency type language.
* *
* @return the language of this type, never {@code null}. * @return the language of this type, never {@code null}.
*/ */
String getLanguage(); @Nonnull
Language getLanguage();
/** /**
* Get the file extension of artifacts of this type. * Get the file extension of artifacts of this type.
@ -80,14 +77,11 @@ public interface Type {
String getClassifier(); String getClassifier();
/** /**
* Specifies if the artifact contains java classes and should be * Specifies if the artifact should be added to the build path.
* added to the classpath.
* *
* @return if the artifact should be added to the class path * @return if the artifact should be added to the build path
*/ */
default boolean isAddedToClassPath() { boolean isBuildPathConstituent();
return getDependencyProperties().checkFlag(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT);
}
/** /**
* Specifies if the artifact already embeds its own dependencies. * Specifies if the artifact already embeds its own dependencies.
@ -96,15 +90,5 @@ default boolean isAddedToClassPath() {
* *
* @return if the artifact's dependencies are included in the artifact * @return if the artifact's dependencies are included in the artifact
*/ */
default boolean isIncludesDependencies() { boolean isIncludesDependencies();
return getDependencyProperties().checkFlag(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES);
}
/**
* Gets the default properties associated with this dependency type.
*
* @return the default properties, never {@code null}.
*/
@Nonnull
DependencyProperties getDependencyProperties();
} }

View File

@ -89,7 +89,7 @@ static DependencyCoordinateFactoryRequest build(@Nonnull Session session, @Nonnu
.version(dependency.getVersion().asString()) .version(dependency.getVersion().asString())
.classifier(dependency.getClassifier()) .classifier(dependency.getClassifier())
.extension(dependency.getExtension()) .extension(dependency.getExtension())
.type(dependency.getType().getId()) .type(dependency.getType().id())
.scope(dependency.getScope().id()) .scope(dependency.getScope().id())
.optional(dependency.isOptional()) .optional(dependency.isOptional())
.build(); .build();

View File

@ -22,8 +22,8 @@
import org.apache.maven.api.DependencyCoordinate; import org.apache.maven.api.DependencyCoordinate;
import org.apache.maven.api.Node; import org.apache.maven.api.Node;
import org.apache.maven.api.PathScope;
import org.apache.maven.api.Project; import org.apache.maven.api.Project;
import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.Service; import org.apache.maven.api.Service;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
@ -35,7 +35,7 @@
@Experimental @Experimental
public interface DependencyResolver extends Service { public interface DependencyResolver extends Service {
List<Node> flatten(Session session, Node node, ResolutionScope scope) throws DependencyResolverException; List<Node> flatten(Session session, Node node, PathScope scope) throws DependencyResolverException;
/** /**
* This method collects, flattens and resolves the dependencies. * This method collects, flattens and resolves the dependencies.
@ -47,7 +47,7 @@ public interface DependencyResolver extends Service {
* @throws ArtifactResolverException * @throws ArtifactResolverException
* *
* @see DependencyCollector#collect(DependencyCollectorRequest) * @see DependencyCollector#collect(DependencyCollectorRequest)
* @see #flatten(Session, Node, ResolutionScope) * @see #flatten(Session, Node, PathScope)
* @see ArtifactResolver#resolve(ArtifactResolverRequest) * @see ArtifactResolver#resolve(ArtifactResolverRequest)
*/ */
DependencyResolverResult resolve(DependencyResolverRequest request) DependencyResolverResult resolve(DependencyResolverRequest request)
@ -60,7 +60,7 @@ default DependencyResolverResult resolve(@Nonnull Session session, @Nonnull Proj
@Nonnull @Nonnull
default DependencyResolverResult resolve( default DependencyResolverResult resolve(
@Nonnull Session session, @Nonnull Project project, @Nonnull ResolutionScope scope) { @Nonnull Session session, @Nonnull Project project, @Nonnull PathScope scope) {
return resolve(DependencyResolverRequest.build(session, project, scope)); return resolve(DependencyResolverRequest.build(session, project, scope));
} }
@ -71,7 +71,7 @@ default DependencyResolverResult resolve(@Nonnull Session session, @Nonnull Depe
@Nonnull @Nonnull
default DependencyResolverResult resolve( default DependencyResolverResult resolve(
@Nonnull Session session, @Nonnull DependencyCoordinate dependency, @Nonnull ResolutionScope scope) { @Nonnull Session session, @Nonnull DependencyCoordinate dependency, @Nonnull PathScope scope) {
return resolve(DependencyResolverRequest.build(session, dependency, scope)); return resolve(DependencyResolverRequest.build(session, dependency, scope));
} }
@ -83,9 +83,7 @@ default DependencyResolverResult resolve(
@Nonnull @Nonnull
default DependencyResolverResult resolve( default DependencyResolverResult resolve(
@Nonnull Session session, @Nonnull Session session, @Nonnull List<DependencyCoordinate> dependencies, @Nonnull PathScope scope) {
@Nonnull List<DependencyCoordinate> dependencies,
@Nonnull ResolutionScope scope) {
return resolve(DependencyResolverRequest.build(session, dependencies, scope)); return resolve(DependencyResolverRequest.build(session, dependencies, scope));
} }
} }

View File

@ -23,8 +23,8 @@
import org.apache.maven.api.Artifact; import org.apache.maven.api.Artifact;
import org.apache.maven.api.DependencyCoordinate; import org.apache.maven.api.DependencyCoordinate;
import org.apache.maven.api.PathScope;
import org.apache.maven.api.Project; import org.apache.maven.api.Project;
import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
@ -35,7 +35,7 @@
public interface DependencyResolverRequest extends DependencyCollectorRequest { public interface DependencyResolverRequest extends DependencyCollectorRequest {
@Nonnull @Nonnull
ResolutionScope getResolutionScope(); PathScope getPathScope();
@Nonnull @Nonnull
static DependencyResolverRequestBuilder builder() { static DependencyResolverRequestBuilder builder() {
@ -44,50 +44,49 @@ static DependencyResolverRequestBuilder builder() {
@Nonnull @Nonnull
static DependencyResolverRequest build(Session session, Project project) { static DependencyResolverRequest build(Session session, Project project) {
return build(session, project, ResolutionScope.PROJECT_RUNTIME); return build(session, project, PathScope.MAIN_RUNTIME);
} }
@Nonnull @Nonnull
static DependencyResolverRequest build(Session session, Project project, ResolutionScope scope) { static DependencyResolverRequest build(Session session, Project project, PathScope scope) {
return new DependencyResolverRequestBuilder() return new DependencyResolverRequestBuilder()
.session(session) .session(session)
.project(project) .project(project)
.resolutionScope(scope) .pathScope(scope)
.build(); .build();
} }
@Nonnull @Nonnull
static DependencyResolverRequest build(Session session, DependencyCoordinate dependency) { static DependencyResolverRequest build(Session session, DependencyCoordinate dependency) {
return build(session, dependency, ResolutionScope.PROJECT_RUNTIME); return build(session, dependency, PathScope.MAIN_RUNTIME);
} }
@Nonnull @Nonnull
static DependencyResolverRequest build(Session session, DependencyCoordinate dependency, ResolutionScope scope) { static DependencyResolverRequest build(Session session, DependencyCoordinate dependency, PathScope scope) {
return new DependencyResolverRequestBuilder() return new DependencyResolverRequestBuilder()
.session(session) .session(session)
.dependency(dependency) .dependency(dependency)
.resolutionScope(scope) .pathScope(scope)
.build(); .build();
} }
@Nonnull @Nonnull
static DependencyResolverRequest build(Session session, List<DependencyCoordinate> dependencies) { static DependencyResolverRequest build(Session session, List<DependencyCoordinate> dependencies) {
return build(session, dependencies, ResolutionScope.PROJECT_RUNTIME); return build(session, dependencies, PathScope.MAIN_RUNTIME);
} }
@Nonnull @Nonnull
static DependencyResolverRequest build( static DependencyResolverRequest build(Session session, List<DependencyCoordinate> dependencies, PathScope scope) {
Session session, List<DependencyCoordinate> dependencies, ResolutionScope scope) {
return new DependencyResolverRequestBuilder() return new DependencyResolverRequestBuilder()
.session(session) .session(session)
.dependencies(dependencies) .dependencies(dependencies)
.resolutionScope(scope) .pathScope(scope)
.build(); .build();
} }
@NotThreadSafe @NotThreadSafe
class DependencyResolverRequestBuilder extends DependencyCollectorRequestBuilder { class DependencyResolverRequestBuilder extends DependencyCollectorRequestBuilder {
ResolutionScope resolutionScope; PathScope pathScope;
@Nonnull @Nonnull
@Override @Override
@ -154,20 +153,20 @@ public DependencyResolverRequestBuilder verbose(boolean verbose) {
} }
@Nonnull @Nonnull
public DependencyResolverRequestBuilder resolutionScope(@Nonnull ResolutionScope resolutionScope) { public DependencyResolverRequestBuilder pathScope(@Nonnull PathScope pathScope) {
this.resolutionScope = resolutionScope; this.pathScope = pathScope;
return this; return this;
} }
@Override @Override
public DependencyResolverRequest build() { public DependencyResolverRequest build() {
return new DefaultDependencyResolverRequest( return new DefaultDependencyResolverRequest(
session, project, rootArtifact, root, dependencies, managedDependencies, verbose, resolutionScope); session, project, rootArtifact, root, dependencies, managedDependencies, verbose, pathScope);
} }
static class DefaultDependencyResolverRequest extends DefaultDependencyCollectorRequest static class DefaultDependencyResolverRequest extends DefaultDependencyCollectorRequest
implements DependencyResolverRequest { implements DependencyResolverRequest {
private final ResolutionScope resolutionScope; private final PathScope pathScope;
DefaultDependencyResolverRequest( DefaultDependencyResolverRequest(
Session session, Session session,
@ -177,9 +176,9 @@ static class DefaultDependencyResolverRequest extends DefaultDependencyCollector
Collection<DependencyCoordinate> dependencies, Collection<DependencyCoordinate> dependencies,
Collection<DependencyCoordinate> managedDependencies, Collection<DependencyCoordinate> managedDependencies,
boolean verbose, boolean verbose,
ResolutionScope resolutionScope) { PathScope pathScope) {
super(session, project, rootArtifact, root, dependencies, managedDependencies, verbose); super(session, project, rootArtifact, root, dependencies, managedDependencies, verbose);
this.resolutionScope = nonNull(resolutionScope, "resolutionScope cannot be null"); this.pathScope = nonNull(pathScope, "pathScope cannot be null");
if (verbose) { if (verbose) {
throw new IllegalArgumentException("verbose cannot be true for resolving dependencies"); throw new IllegalArgumentException("verbose cannot be true for resolving dependencies");
} }
@ -187,8 +186,8 @@ static class DefaultDependencyResolverRequest extends DefaultDependencyCollector
@Nonnull @Nonnull
@Override @Override
public ResolutionScope getResolutionScope() { public PathScope getPathScope() {
return resolutionScope; return pathScope;
} }
} }
} }

View File

@ -0,0 +1,34 @@
/*
* 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.Optional;
import org.apache.maven.api.ExtensibleEnum;
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Nonnull;
public interface ExtensibleEnumRegistry<T extends ExtensibleEnum> extends Service {
@Nonnull
Optional<T> lookup(String id);
default T require(String id) {
return lookup(id).orElseThrow(() -> new IllegalArgumentException("Unknown extensible enum value '" + id + "'"));
}
}

View File

@ -0,0 +1,23 @@
/*
* 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 org.apache.maven.api.Language;
public interface LanguageRegistry extends ExtensibleEnumRegistry<Language> {}

View File

@ -0,0 +1,23 @@
/*
* 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 org.apache.maven.api.Packaging;
public interface PackagingRegistry extends ExtensibleEnumRegistry<Packaging> {}

View File

@ -0,0 +1,23 @@
/*
* 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 org.apache.maven.api.PathScope;
public interface PathScopeRegistry extends ExtensibleEnumRegistry<PathScope> {}

View File

@ -0,0 +1,26 @@
/*
* 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 org.apache.maven.api.ProjectScope;
/**
* Manager for {@link ProjectScope}.
*/
public interface ProjectScopeRegistry extends ExtensibleEnumRegistry<ProjectScope> {}

View File

@ -18,7 +18,6 @@
*/ */
package org.apache.maven.api.services; package org.apache.maven.api.services;
import org.apache.maven.api.Service;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
@ -29,7 +28,7 @@
* @since 4.0.0 * @since 4.0.0
*/ */
@Experimental @Experimental
public interface TypeRegistry extends Service { public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
/** /**
* Obtain the {@link Type} from the specified {@code id}. * Obtain the {@link Type} from the specified {@code id}.
@ -40,5 +39,5 @@ public interface TypeRegistry extends Service {
* @return the type * @return the type
*/ */
@Nonnull @Nonnull
Type getType(@Nonnull String id); Type require(@Nonnull String id);
} }

View File

@ -0,0 +1,28 @@
/*
* 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;
import java.util.Collection;
import org.apache.maven.api.ExtensibleEnum;
public interface ExtensibleEnumProvider<T extends ExtensibleEnum> {
Collection<T> provides();
}

View File

@ -0,0 +1,23 @@
/*
* 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;
import org.apache.maven.api.Language;
public interface LanguageProvider extends ExtensibleEnumProvider<Language> {}

View File

@ -0,0 +1,23 @@
/*
* 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;
import org.apache.maven.api.PathScope;
public interface PathScopeProvider extends ExtensibleEnumProvider<PathScope> {}

View File

@ -0,0 +1,23 @@
/*
* 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;
import org.apache.maven.api.ProjectScope;
public interface ProjectScopeProvider extends ExtensibleEnumProvider<ProjectScope> {}

View File

@ -53,5 +53,9 @@ public interface ArtifactHandler {
String getLanguage(); String getLanguage();
/**
* IMPORTANT: this is WRONGLY NAMED method (and/or remnant for Maven2).
* Its meaning is "is added to build path", that is used to create classpath/modulepath/etc.
*/
boolean isAddedToClasspath(); boolean isAddedToClasspath();
} }

View File

@ -62,7 +62,7 @@ public void onEvent(Object event) {
public ArtifactHandler getArtifactHandler(String id) { public ArtifactHandler getArtifactHandler(String id) {
return allHandlers.computeIfAbsent(id, k -> { return allHandlers.computeIfAbsent(id, k -> {
Type type = typeRegistry.getType(id); Type type = typeRegistry.require(id);
return new DefaultArtifactHandler( return new DefaultArtifactHandler(
id, id,
type.getExtension(), type.getExtension(),
@ -70,9 +70,13 @@ public ArtifactHandler getArtifactHandler(String id) {
null, null,
null, null,
type.isIncludesDependencies(), type.isIncludesDependencies(),
type.getLanguage(), type.getLanguage().id(),
type.isAddedToClassPath()); // TODO: watch out for module path type.isBuildPathConstituent());
}); });
// Note: here, type decides is artifact added to "build path" (for example during resolution)
// and "build path" is intermediate data that is used to create actual Java classpath/modulepath
// but to create those, proper filtering should happen via Type properties.
} }
public void addHandlers(Map<String, ArtifactHandler> handlers) { public void addHandlers(Map<String, ArtifactHandler> handlers) {

View File

@ -35,17 +35,18 @@ class TypeRegistryAdapter implements ArtifactTypeRegistry {
@Override @Override
public ArtifactType get(String typeId) { public ArtifactType get(String typeId) {
Type type = typeRegistry.getType(typeId); Type type = typeRegistry.require(typeId);
if (type instanceof ArtifactType) { if (type instanceof ArtifactType) {
return (ArtifactType) type; return (ArtifactType) type;
} }
if (type != null) { if (type != null) {
return new DefaultType( return new DefaultType(
type.getId(), type.id(),
type.getLanguage(), type.getLanguage(),
type.getExtension(), type.getExtension(),
type.getClassifier(), type.getClassifier(),
type.getDependencyProperties()); type.isBuildPathConstituent(),
type.isIncludesDependencies());
} }
return null; return null;
} }

View File

@ -462,7 +462,7 @@ public Node collectDependencies(@Nonnull DependencyCoordinate dependency) {
@Nonnull @Nonnull
@Override @Override
public List<Node> flattenDependencies(@Nonnull Node node, @Nonnull ResolutionScope scope) { public List<Node> flattenDependencies(@Nonnull Node node, @Nonnull PathScope scope) {
return getService(DependencyResolver.class).flatten(this, node, scope); return getService(DependencyResolver.class).flatten(this, node, scope);
} }
@ -477,7 +477,7 @@ public List<Path> resolveDependencies(List<DependencyCoordinate> dependencies) {
} }
@Override @Override
public List<Path> resolveDependencies(Project project, ResolutionScope scope) { public List<Path> resolveDependencies(Project project, PathScope scope) {
return getService(DependencyResolver.class) return getService(DependencyResolver.class)
.resolve(this, project, scope) .resolve(this, project, scope)
.getPaths(); .getPaths();
@ -518,4 +518,34 @@ public Version resolveVersion(ArtifactCoordinate artifact) {
public List<Version> resolveVersionRange(ArtifactCoordinate artifact) { public List<Version> resolveVersionRange(ArtifactCoordinate artifact) {
return getService(VersionRangeResolver.class).resolve(this, artifact).getVersions(); return getService(VersionRangeResolver.class).resolve(this, artifact).getVersions();
} }
@Override
public Type requireType(String id) {
return getService(TypeRegistry.class).require(id);
}
@Override
public Language requireLanguage(String id) {
return getService(LanguageRegistry.class).require(id);
}
@Override
public Packaging requirePackaging(String id) {
return getService(PackagingRegistry.class).require(id);
}
@Override
public ProjectScope requireProjectScope(String id) {
return getService(ProjectScopeRegistry.class).require(id);
}
@Override
public DependencyScope requireDependencyScope(String id) {
return DependencyScope.forId(id);
}
@Override
public PathScope requirePathScope(String id) {
return getService(PathScopeRegistry.class).require(id);
}
} }

View File

@ -23,13 +23,11 @@
import org.apache.maven.api.Artifact; import org.apache.maven.api.Artifact;
import org.apache.maven.api.Dependency; import org.apache.maven.api.Dependency;
import org.apache.maven.api.DependencyCoordinate; import org.apache.maven.api.DependencyCoordinate;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.DependencyScope;
import org.apache.maven.api.Scope;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.api.Version; import org.apache.maven.api.Version;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable; import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.repository.internal.DefaultModelVersionParser; import org.apache.maven.repository.internal.DefaultModelVersionParser;
import org.eclipse.aether.artifact.ArtifactProperties; import org.eclipse.aether.artifact.ArtifactProperties;
@ -38,15 +36,12 @@
public class DefaultDependency implements Dependency { public class DefaultDependency implements Dependency {
private final InternalSession session; private final InternalSession session;
private final org.eclipse.aether.graph.Dependency dependency; private final org.eclipse.aether.graph.Dependency dependency;
private final DependencyProperties dependencyProperties;
private final String key; private final String key;
public DefaultDependency( public DefaultDependency(
@Nonnull InternalSession session, @Nonnull org.eclipse.aether.graph.Dependency dependency) { @Nonnull InternalSession session, @Nonnull org.eclipse.aether.graph.Dependency dependency) {
this.session = nonNull(session, "session"); this.session = nonNull(session, "session");
this.dependency = nonNull(dependency, "dependency"); this.dependency = nonNull(dependency, "dependency");
this.dependencyProperties =
new DefaultDependencyProperties(dependency.getArtifact().getProperties());
this.key = getGroupId() this.key = getGroupId()
+ ':' + ':'
+ getArtifactId() + getArtifactId()
@ -102,12 +97,7 @@ public Type getType() {
String type = dependency String type = dependency
.getArtifact() .getArtifact()
.getProperty(ArtifactProperties.TYPE, dependency.getArtifact().getExtension()); .getProperty(ArtifactProperties.TYPE, dependency.getArtifact().getExtension());
return session.getService(TypeRegistry.class).getType(type); return session.requireType(type);
}
@Override
public DependencyProperties getDependencyProperties() {
return dependencyProperties;
} }
@Override @Override
@ -117,8 +107,8 @@ public boolean isSnapshot() {
@Nonnull @Nonnull
@Override @Override
public Scope getScope() { public DependencyScope getScope() {
return Scope.get(dependency.getScope()); return session.requireDependencyScope(dependency.getScope());
} }
@Nullable @Nullable

View File

@ -23,7 +23,6 @@
import org.apache.maven.api.*; import org.apache.maven.api.*;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable; import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.services.TypeRegistry;
import org.eclipse.aether.artifact.ArtifactProperties; import org.eclipse.aether.artifact.ArtifactProperties;
import static org.apache.maven.internal.impl.Utils.nonNull; import static org.apache.maven.internal.impl.Utils.nonNull;
@ -73,13 +72,13 @@ public Type getType() {
String type = dependency String type = dependency
.getArtifact() .getArtifact()
.getProperty(ArtifactProperties.TYPE, dependency.getArtifact().getExtension()); .getProperty(ArtifactProperties.TYPE, dependency.getArtifact().getExtension());
return session.getService(TypeRegistry.class).getType(type); return session.requireType(type);
} }
@Nonnull @Nonnull
@Override @Override
public Scope getScope() { public DependencyScope getScope() {
return Scope.get(dependency.getScope()); return session.requireDependencyScope(dependency.getScope());
} }
@Nullable @Nullable

View File

@ -1,66 +0,0 @@
/*
* 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.internal.impl;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.maven.api.DependencyProperties;
import org.apache.maven.api.annotations.Nonnull;
import static org.apache.maven.internal.impl.Utils.nonNull;
/**
* Default implementation of artifact properties.
*/
public class DefaultDependencyProperties implements DependencyProperties {
private final Map<String, String> properties;
public DefaultDependencyProperties(String... flags) {
this(Arrays.asList(flags));
}
public DefaultDependencyProperties(@Nonnull Collection<String> flags) {
nonNull(flags, "flags");
HashMap<String, String> map = new HashMap<>();
for (String flag : flags) {
map.put(flag, Boolean.TRUE.toString());
}
this.properties = Collections.unmodifiableMap(map);
}
public DefaultDependencyProperties(@Nonnull Map<String, String> properties) {
this.properties = Collections.unmodifiableMap(nonNull(properties, "properties"));
}
@Nonnull
@Override
public Map<String, String> asMap() {
return properties;
}
@Override
public boolean checkFlag(@Nonnull String flag) {
nonNull(flag, "flag");
return Boolean.parseBoolean(properties.getOrDefault(flag, ""));
}
}

View File

@ -33,14 +33,7 @@
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.maven.api.Artifact; import org.apache.maven.api.*;
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Dependency;
import org.apache.maven.api.Node;
import org.apache.maven.api.Project;
import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.Scope;
import org.apache.maven.api.Session;
import org.apache.maven.api.services.*; import org.apache.maven.api.services.*;
import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.internal.LifecycleDependencyResolver; import org.apache.maven.lifecycle.internal.LifecycleDependencyResolver;
@ -58,7 +51,7 @@
public class DefaultDependencyResolver implements DependencyResolver { public class DefaultDependencyResolver implements DependencyResolver {
@Override @Override
public List<Node> flatten(Session s, Node node, ResolutionScope scope) throws DependencyResolverException { public List<Node> flatten(Session s, Node node, PathScope scope) throws DependencyResolverException {
InternalSession session = InternalSession.from(s); InternalSession session = InternalSession.from(s);
DependencyNode root = cast(AbstractNode.class, node, "node").getDependencyNode(); DependencyNode root = cast(AbstractNode.class, node, "node").getDependencyNode();
List<DependencyNode> dependencies = session.getRepositorySystem() List<DependencyNode> dependencies = session.getRepositorySystem()
@ -67,8 +60,9 @@ public List<Node> flatten(Session s, Node node, ResolutionScope scope) throws De
return map(dependencies, session::getNode); return map(dependencies, session::getNode);
} }
private static DependencyFilter getScopeDependencyFilter(ResolutionScope scope) { private static DependencyFilter getScopeDependencyFilter(PathScope scope) {
Set<String> scopes = scope.scopes().stream().map(Scope::id).collect(Collectors.toSet()); Set<String> scopes =
scope.dependencyScopes().stream().map(DependencyScope::id).collect(Collectors.toSet());
return (n, p) -> { return (n, p) -> {
org.eclipse.aether.graph.Dependency d = n.getDependency(); org.eclipse.aether.graph.Dependency d = n.getDependency();
return d == null || scopes.contains(d.getScope()); return d == null || scopes.contains(d.getScope());
@ -83,7 +77,7 @@ public DependencyResolverResult resolve(DependencyResolverRequest request)
if (request.getProject().isPresent()) { if (request.getProject().isPresent()) {
DependencyResolutionResult result = resolveDependencies( DependencyResolutionResult result = resolveDependencies(
request.getSession(), request.getProject().get(), request.getResolutionScope()); request.getSession(), request.getProject().get(), request.getPathScope());
Map<org.eclipse.aether.graph.Dependency, org.eclipse.aether.graph.DependencyNode> nodes = stream( Map<org.eclipse.aether.graph.Dependency, org.eclipse.aether.graph.DependencyNode> nodes = stream(
result.getDependencyGraph()) result.getDependencyGraph())
@ -106,7 +100,7 @@ public DependencyResolverResult resolve(DependencyResolverRequest request)
DependencyCollectorResult collectorResult = DependencyCollectorResult collectorResult =
session.getService(DependencyCollector.class).collect(request); session.getService(DependencyCollector.class).collect(request);
List<Node> nodes = flatten(session, collectorResult.getRoot(), request.getResolutionScope()); List<Node> nodes = flatten(session, collectorResult.getRoot(), request.getPathScope());
List<Dependency> deps = List<Dependency> deps =
nodes.stream().map(Node::getDependency).filter(Objects::nonNull).collect(Collectors.toList()); nodes.stream().map(Node::getDependency).filter(Objects::nonNull).collect(Collectors.toList());
List<ArtifactCoordinate> coordinates = List<ArtifactCoordinate> coordinates =
@ -130,7 +124,7 @@ private Stream<DependencyNode> stream(DependencyNode node) {
return Stream.concat(Stream.of(node), node.getChildren().stream().flatMap(this::stream)); return Stream.concat(Stream.of(node), node.getChildren().stream().flatMap(this::stream));
} }
private DependencyResolutionResult resolveDependencies(Session session, Project project, ResolutionScope scope) { private DependencyResolutionResult resolveDependencies(Session session, Project project, PathScope scope) {
Collection<String> toResolve = toScopes(scope); Collection<String> toResolve = toScopes(scope);
try { try {
LifecycleDependencyResolver lifecycleDependencyResolver = LifecycleDependencyResolver lifecycleDependencyResolver =
@ -151,8 +145,8 @@ private MavenProject getMavenProject(Project project) {
return ((DefaultProject) project).getProject(); return ((DefaultProject) project).getProject();
} }
private Collection<String> toScopes(ResolutionScope scope) { private Collection<String> toScopes(PathScope scope) {
return map(scope.scopes(), Scope::id); return map(scope.dependencyScopes(), DependencyScope::id);
} }
static class DefaultDependencyResolverResult implements DependencyResolverResult { static class DefaultDependencyResolverResult implements DependencyResolverResult {

View File

@ -0,0 +1,73 @@
/*
* 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.internal.impl;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.Map;
import java.util.Optional;
import org.apache.maven.api.Packaging;
import org.apache.maven.api.Type;
import org.apache.maven.api.services.PackagingRegistry;
import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
/**
* TODO: this is session scoped as SPI can contribute.
*/
@Named
@Singleton
public class DefaultPackagingRegistry implements PackagingRegistry {
private final Map<String, LifecycleMapping> lifecycleMappings;
private final TypeRegistry typeRegistry;
@Inject
public DefaultPackagingRegistry(Map<String, LifecycleMapping> lifecycleMappings, TypeRegistry typeRegistry) {
this.lifecycleMappings = lifecycleMappings;
this.typeRegistry = typeRegistry;
}
@Override
public Optional<Packaging> lookup(String id) {
LifecycleMapping lifecycleMapping = lifecycleMappings.get(id);
if (lifecycleMapping == null) {
return Optional.empty();
}
Type type = typeRegistry.lookup(id).orElse(null);
if (type == null) {
return Optional.empty();
}
return Optional.of(new Packaging() {
@Override
public String id() {
return id;
}
@Override
public Type getType() {
return type;
}
});
}
}

View File

@ -27,7 +27,6 @@
import org.apache.maven.api.annotations.Nullable; import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.model.DependencyManagement; import org.apache.maven.api.model.DependencyManagement;
import org.apache.maven.api.model.Model; import org.apache.maven.api.model.Model;
import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifact; import org.apache.maven.project.artifact.ProjectArtifact;
import org.eclipse.aether.util.artifact.ArtifactIdUtils; import org.eclipse.aether.util.artifact.ArtifactIdUtils;
@ -38,10 +37,12 @@ public class DefaultProject implements Project {
private final InternalSession session; private final InternalSession session;
private final MavenProject project; private final MavenProject project;
private final Packaging packaging;
public DefaultProject(InternalSession session, MavenProject project) { public DefaultProject(InternalSession session, MavenProject project) {
this.session = session; this.session = session;
this.project = project; this.project = project;
this.packaging = session.requirePackaging(project.getPackaging());
} }
public InternalSession getSession() { public InternalSession getSession() {
@ -86,8 +87,8 @@ public List<Artifact> getArtifacts() {
@Nonnull @Nonnull
@Override @Override
public String getPackaging() { public Packaging getPackaging() {
return project.getPackaging(); return packaging;
} }
@Nonnull @Nonnull
@ -175,13 +176,13 @@ public String getExtension() {
@Override @Override
public Type getType() { public Type getType() {
String type = dependency.getType(); String type = dependency.getType();
return session.getService(TypeRegistry.class).getType(type); return session.requireType(type);
} }
@Nonnull @Nonnull
@Override @Override
public Scope getScope() { public DependencyScope getScope() {
return Scope.get(dependency.getScope()); return session.requireDependencyScope(dependency.getScope());
} }
@Override @Override

View File

@ -18,10 +18,11 @@
*/ */
package org.apache.maven.internal.impl; package org.apache.maven.internal.impl;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.eclipse.aether.artifact.ArtifactProperties; import org.eclipse.aether.artifact.ArtifactProperties;
import org.eclipse.aether.artifact.ArtifactType; import org.eclipse.aether.artifact.ArtifactType;
@ -29,37 +30,44 @@
import static org.apache.maven.internal.impl.Utils.nonNull; import static org.apache.maven.internal.impl.Utils.nonNull;
public class DefaultType implements Type, ArtifactType { public class DefaultType implements Type, ArtifactType {
private final String id;
private final Language language;
private final String extension; private final String extension;
private final String classifier; private final String classifier;
private final boolean buildPathConstituent;
private final DependencyProperties dependencyProperties; private final boolean includesDependencies;
public DefaultType( public DefaultType(
String id, String id,
String language, Language language,
String extension, String extension,
String classifier, String classifier,
DependencyProperties dependencyProperties) { boolean buildPathConstituent,
nonNull(id, "id"); boolean includesDependencies) {
nonNull(language, "language"); this.id = nonNull(id, "id");
this.language = nonNull(language, "language");
this.extension = nonNull(extension, "extension"); this.extension = nonNull(extension, "extension");
this.classifier = classifier; this.classifier = classifier;
nonNull(dependencyProperties, "dependencyProperties"); this.buildPathConstituent = buildPathConstituent;
HashMap<String, String> props = new HashMap<>(dependencyProperties.asMap()); this.includesDependencies = includesDependencies;
props.put(ArtifactProperties.TYPE, id); }
props.put(ArtifactProperties.LANGUAGE, language);
this.dependencyProperties = new DefaultDependencyProperties(props); @Override
public String id() {
return id;
} }
@Override @Override
public String getId() { public String getId() {
return dependencyProperties.asMap().get(ArtifactProperties.TYPE); return id();
} }
@Override @Override
public String getLanguage() { public Language getLanguage() {
return dependencyProperties.asMap().get(ArtifactProperties.LANGUAGE); return language;
} }
@Override @Override
@ -73,12 +81,22 @@ public String getClassifier() {
} }
@Override @Override
public DependencyProperties getDependencyProperties() { public boolean isBuildPathConstituent() {
return dependencyProperties; return this.buildPathConstituent;
}
@Override
public boolean isIncludesDependencies() {
return this.includesDependencies;
} }
@Override @Override
public Map<String, String> getProperties() { public Map<String, String> getProperties() {
return getDependencyProperties().asMap(); Map<String, String> properties = new HashMap<>();
properties.put(ArtifactProperties.TYPE, this.id);
properties.put(ArtifactProperties.LANGUAGE, this.language.id());
properties.put(ArtifactProperties.INCLUDES_DEPENDENCIES, String.valueOf(includesDependencies));
properties.put(ArtifactProperties.CONSTITUTES_BUILD_PATH, String.valueOf(buildPathConstituent));
return Collections.unmodifiableMap(properties);
} }
} }

View File

@ -22,13 +22,13 @@
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.maven.api.DependencyProperties;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.api.annotations.Nonnull; 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.services.TypeRegistry;
import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.LegacyArtifactHandlerManager; import org.apache.maven.artifact.handler.manager.LegacyArtifactHandlerManager;
@ -42,6 +42,8 @@
public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistry { public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistry {
private final Map<String, Type> types; private final Map<String, Type> types;
private final LanguageRegistry languageRegistry;
private final ConcurrentHashMap<String, Type> usedTypes; private final ConcurrentHashMap<String, Type> usedTypes;
private final ConcurrentHashMap<String, Type> legacyTypes; private final ConcurrentHashMap<String, Type> legacyTypes;
@ -49,8 +51,10 @@ public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistr
private final LegacyArtifactHandlerManager manager; private final LegacyArtifactHandlerManager manager;
@Inject @Inject
public DefaultTypeRegistry(Map<String, Type> types, LegacyArtifactHandlerManager manager) { public DefaultTypeRegistry(
Map<String, Type> types, LanguageRegistry languageRegistry, LegacyArtifactHandlerManager manager) {
this.types = nonNull(types, "types"); this.types = nonNull(types, "types");
this.languageRegistry = nonNull(languageRegistry, "languageRegistry");
this.usedTypes = new ConcurrentHashMap<>(); this.usedTypes = new ConcurrentHashMap<>();
this.legacyTypes = new ConcurrentHashMap<>(); this.legacyTypes = new ConcurrentHashMap<>();
this.manager = nonNull(manager, "artifactHandlerManager"); this.manager = nonNull(manager, "artifactHandlerManager");
@ -67,9 +71,14 @@ public void onEvent(Object event) {
} }
} }
@Override
public Optional<Type> lookup(String id) {
return Optional.of(require(id));
}
@Override @Override
@Nonnull @Nonnull
public Type getType(String id) { public Type require(String id) {
nonNull(id, "id"); nonNull(id, "id");
return usedTypes.computeIfAbsent(id, i -> { return usedTypes.computeIfAbsent(id, i -> {
Type type = types.get(id); Type type = types.get(id);
@ -78,19 +87,13 @@ public Type getType(String id) {
type = legacyTypes.computeIfAbsent(id, k -> { type = legacyTypes.computeIfAbsent(id, k -> {
// Copy data as the ArtifactHandler is not immutable, but Type should be. // Copy data as the ArtifactHandler is not immutable, but Type should be.
ArtifactHandler handler = manager.getArtifactHandler(id); ArtifactHandler handler = manager.getArtifactHandler(id);
ArrayList<String> flags = new ArrayList<>();
if (handler.isAddedToClasspath()) {
flags.add(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT);
}
if (handler.isIncludesDependencies()) {
flags.add(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES);
}
return new DefaultType( return new DefaultType(
id, id,
handler.getLanguage(), languageRegistry.require(handler.getLanguage()),
handler.getExtension(), handler.getExtension(),
handler.getClassifier(), handler.getClassifier(),
new DefaultDependencyProperties(flags)); handler.isAddedToClasspath(),
handler.isIncludesDependencies());
}); });
} }
return type; return type;

View File

@ -0,0 +1,92 @@
/*
* 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.internal.impl;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.SessionScoped;
import org.apache.maven.api.*;
import org.apache.maven.api.services.*;
import org.apache.maven.api.spi.*;
public class ExtensibleEnumRegistries {
@Named
@SessionScoped
public static class DefaultPathScopeRegistry extends DefaultExtensibleEnumRegistry<PathScope, PathScopeProvider>
implements PathScopeRegistry {
@Inject
public DefaultPathScopeRegistry(List<PathScopeProvider> providers) {
super(
providers,
PathScope.MAIN_COMPILE,
PathScope.MAIN_RUNTIME,
PathScope.TEST_COMPILE,
PathScope.TEST_RUNTIME);
}
}
@Named
@SessionScoped
public static class DefaultProjectScopeRegistry
extends DefaultExtensibleEnumRegistry<ProjectScope, ProjectScopeProvider> implements ProjectScopeRegistry {
@Inject
public DefaultProjectScopeRegistry(List<ProjectScopeProvider> providers) {
super(providers, ProjectScope.MAIN, ProjectScope.TEST);
}
}
@Named
@Singleton
public static class DefaultLanguageRegistry extends DefaultExtensibleEnumRegistry<Language, LanguageProvider>
implements LanguageRegistry {
@Inject
public DefaultLanguageRegistry(List<LanguageProvider> providers) {
super(providers, Language.NONE, Language.JAVA_FAMILY);
}
}
static class DefaultExtensibleEnumRegistry<T extends ExtensibleEnum, P extends ExtensibleEnumProvider<T>>
implements ExtensibleEnumRegistry<T> {
private final Map<String, T> values;
DefaultExtensibleEnumRegistry(List<P> providers, T... builtinValues) {
values = Stream.<T>concat(
Stream.of(builtinValues), providers.stream().flatMap(p -> p.provides().stream()))
.collect(Collectors.toMap(t -> t.id(), t -> t));
}
@Override
public Optional<T> lookup(String id) {
return Optional.ofNullable(values.get(id));
}
}
}

View File

@ -22,8 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(BomTypeProvider.NAME) @Named(BomTypeProvider.NAME)
@ -34,7 +34,7 @@ public class BomTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public BomTypeProvider() { public BomTypeProvider() {
this.type = new DefaultType(NAME, Type.LANGUAGE_NONE, "pom", null, new DefaultDependencyProperties()); this.type = new DefaultType(NAME, Language.NONE, "pom", null, false, false);
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(EarTypeProvider.NAME) @Named(EarTypeProvider.NAME)
@ -35,12 +34,7 @@ public class EarTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public EarTypeProvider() { public EarTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "ear", null, false, true);
NAME,
Type.LANGUAGE_JAVA,
"ear",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(EjbClientTypeProvider.NAME) @Named(EjbClientTypeProvider.NAME)
@ -35,12 +34,7 @@ public class EjbClientTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public EjbClientTypeProvider() { public EjbClientTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", "client", true, false);
NAME,
Type.LANGUAGE_JAVA,
"jar",
"client",
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(EjbTypeProvider.NAME) @Named(EjbTypeProvider.NAME)
@ -35,12 +34,7 @@ public class EjbTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public EjbTypeProvider() { public EjbTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", null, true, false);
NAME,
Type.LANGUAGE_JAVA,
"jar",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(JarTypeProvider.NAME) @Named(JarTypeProvider.NAME)
@ -35,12 +34,7 @@ public class JarTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public JarTypeProvider() { public JarTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", null, true, false);
NAME,
Type.LANGUAGE_JAVA,
"jar",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
} }
@Override @Override

View File

@ -22,8 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(JavaSourceTypeProvider.NAME) @Named(JavaSourceTypeProvider.NAME)
@ -34,7 +34,7 @@ public class JavaSourceTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public JavaSourceTypeProvider() { public JavaSourceTypeProvider() {
this.type = new DefaultType(NAME, Type.LANGUAGE_JAVA, "jar", "sources", new DefaultDependencyProperties()); this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", "sources", false, false);
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(JavadocTypeProvider.NAME) @Named(JavadocTypeProvider.NAME)
@ -35,12 +34,7 @@ public class JavadocTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public JavadocTypeProvider() { public JavadocTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", "javadoc", true, false);
NAME,
Type.LANGUAGE_JAVA,
"jar",
"javadoc",
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(MavenPluginTypeProvider.NAME) @Named(MavenPluginTypeProvider.NAME)
@ -35,12 +34,7 @@ public class MavenPluginTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public MavenPluginTypeProvider() { public MavenPluginTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", null, true, false);
NAME,
Type.LANGUAGE_JAVA,
"jar",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(ParTypeProvider.NAME) @Named(ParTypeProvider.NAME)
@ -35,12 +34,7 @@ public class ParTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public ParTypeProvider() { public ParTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "par", null, false, true);
NAME,
Type.LANGUAGE_JAVA,
"par",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
} }
@Override @Override

View File

@ -22,8 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(PomTypeProvider.NAME) @Named(PomTypeProvider.NAME)
@ -34,7 +34,7 @@ public class PomTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public PomTypeProvider() { public PomTypeProvider() {
this.type = new DefaultType(NAME, Type.LANGUAGE_NONE, "pom", null, new DefaultDependencyProperties()); this.type = new DefaultType(NAME, Language.NONE, "pom", null, false, false);
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(RarTypeProvider.NAME) @Named(RarTypeProvider.NAME)
@ -35,12 +34,7 @@ public class RarTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public RarTypeProvider() { public RarTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "rar", null, false, true);
NAME,
Type.LANGUAGE_JAVA,
"rar",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(TestJarTypeProvider.NAME) @Named(TestJarTypeProvider.NAME)
@ -35,12 +34,7 @@ public class TestJarTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public TestJarTypeProvider() { public TestJarTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", "tests", true, false);
NAME,
Type.LANGUAGE_JAVA,
"jar",
"tests",
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
} }
@Override @Override

View File

@ -22,9 +22,8 @@
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyProperties; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultDependencyProperties;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.internal.impl.DefaultType;
@Named(WarTypeProvider.NAME) @Named(WarTypeProvider.NAME)
@ -35,12 +34,7 @@ public class WarTypeProvider implements Provider<Type> {
private final Type type; private final Type type;
public WarTypeProvider() { public WarTypeProvider() {
this.type = new DefaultType( this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "war", null, false, true);
NAME,
Type.LANGUAGE_JAVA,
"war",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
} }
@Override @Override

View File

@ -34,6 +34,7 @@
import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.internal.impl.DefaultLookup;
import org.apache.maven.internal.impl.DefaultSessionFactory; import org.apache.maven.internal.impl.DefaultSessionFactory;
import org.apache.maven.model.Build; import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
@ -149,7 +150,7 @@ protected MavenSession createMavenSession(File pom, Properties executionProperti
initRepoSession(configuration); initRepoSession(configuration);
DefaultSessionFactory defaultSessionFactory = DefaultSessionFactory defaultSessionFactory =
new DefaultSessionFactory(mock(RepositorySystem.class), null, null, null); new DefaultSessionFactory(mock(RepositorySystem.class), null, new DefaultLookup(container), null);
MavenSession session = new MavenSession( MavenSession session = new MavenSession(
getContainer(), configuration.getRepositorySession(), request, new DefaultMavenExecutionResult()); getContainer(), configuration.getRepositorySession(), request, new DefaultMavenExecutionResult());

View File

@ -30,13 +30,7 @@
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.maven.api.Artifact; import org.apache.maven.api.*;
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Dependency;
import org.apache.maven.api.Node;
import org.apache.maven.api.Project;
import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.Session;
import org.apache.maven.api.services.DependencyResolver; import org.apache.maven.api.services.DependencyResolver;
import org.apache.maven.api.services.DependencyResolverResult; import org.apache.maven.api.services.DependencyResolverResult;
import org.apache.maven.api.services.ProjectBuilder; import org.apache.maven.api.services.ProjectBuilder;
@ -200,7 +194,7 @@ void testProjectDependencies() {
assertNotNull(root); assertNotNull(root);
DependencyResolverResult result = DependencyResolverResult result =
session.getService(DependencyResolver.class).resolve(session, project, ResolutionScope.PROJECT_RUNTIME); session.getService(DependencyResolver.class).resolve(session, project, PathScope.MAIN_RUNTIME);
assertNotNull(result); assertNotNull(result);
List<Dependency> deps = new ArrayList<>(result.getDependencies().keySet()); List<Dependency> deps = new ArrayList<>(result.getDependencies().keySet());
List<Dependency> deps2 = result.getNodes().stream() List<Dependency> deps2 = result.getNodes().stream()

View File

@ -18,7 +18,7 @@
*/ */
package org.apache.maven.repository.internal.scopes; package org.apache.maven.repository.internal.scopes;
import org.eclipse.aether.util.artifact.DependencyScopes; import org.apache.maven.api.DependencyScope;
/** /**
* The dependency scopes used for Java dependencies in Maven. This class defines labels only, that are doing pass-thru * The dependency scopes used for Java dependencies in Maven. This class defines labels only, that are doing pass-thru
@ -31,21 +31,23 @@ public final class MavenDependencyScopes {
/** /**
* Important: keep this label in sync with Resolver. * Important: keep this label in sync with Resolver.
*/ */
public static final String SYSTEM = DependencyScopes.SYSTEM; public static final String SYSTEM = DependencyScope.SYSTEM.id();
public static final String COMPILE_ONLY = "compile-only"; public static final String NONE = DependencyScope.NONE.id();
public static final String COMPILE = "compile"; public static final String COMPILE_ONLY = DependencyScope.COMPILE_ONLY.id();
public static final String PROVIDED = "provided"; public static final String COMPILE = DependencyScope.COMPILE.id();
public static final String RUNTIME = "runtime"; public static final String PROVIDED = DependencyScope.PROVIDED.id();
public static final String TEST_ONLY = "test-only"; public static final String RUNTIME = DependencyScope.RUNTIME.id();
public static final String TEST = "test"; public static final String TEST_ONLY = DependencyScope.TEST_ONLY.id();
public static final String TEST_RUNTIME = "test-runtime"; public static final String TEST = DependencyScope.TEST.id();
public static final String TEST_RUNTIME = DependencyScope.TEST_RUNTIME.id();
private MavenDependencyScopes() { private MavenDependencyScopes() {
// hide constructor // hide constructor