[MNG-8043] Dependency properties should be provided by Maven (#1399)

Followup of MRESOLVER-484:
* move off deprecated resolver bits
* introduce non-deprecated replacements
* move existing to code to those new bits

---

https://issues.apache.org/jira/browse/MNG-8043
This commit is contained in:
Tamas Cservenak 2024-02-07 10:51:56 +01:00 committed by GitHub
parent a37cf3d37f
commit 76794c0237
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 258 additions and 726 deletions

View File

@ -92,7 +92,7 @@ public enum DependencyScope {
* System scope. * System scope.
* <p> * <p>
* Important: this scope {@code id} MUST BE KEPT in sync with label in * Important: this scope {@code id} MUST BE KEPT in sync with label in
* {@code org.eclipse.aether.util.artifact.Scopes#SYSTEM}. * {@code org.eclipse.aether.util.artifact.DependencyScopes#SYSTEM}.
*/ */
SYSTEM("system", false); SYSTEM("system", false);
@ -125,4 +125,8 @@ public enum DependencyScope {
public boolean isTransitive() { public boolean isTransitive() {
return transitive; return transitive;
} }
public boolean is(String id) {
return id().equals(id);
}
} }

View File

@ -16,29 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.maven.internal.impl.types; package org.apache.maven.api.spi;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(PomTypeProvider.NAME) public interface TypeProvider extends ExtensibleEnumProvider<Type> {}
@Singleton
public class PomTypeProvider implements Provider<Type> {
public static final String NAME = "pom";
private final Type type;
public PomTypeProvider() {
this.type = new DefaultType(NAME, Language.NONE, "pom", null, false, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -20,7 +20,7 @@ package org.apache.maven.internal.aether;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.api.services.TypeRegistry; import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.internal.impl.DefaultType; import org.apache.maven.repository.internal.type.DefaultType;
import org.eclipse.aether.artifact.ArtifactType; import org.eclipse.aether.artifact.ArtifactType;
import org.eclipse.aether.artifact.ArtifactTypeRegistry; import org.eclipse.aether.artifact.ArtifactTypeRegistry;

View File

@ -22,19 +22,24 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
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.LanguageRegistry;
import org.apache.maven.api.services.TypeRegistry; import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.api.spi.TypeProvider;
import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.LegacyArtifactHandlerManager; import org.apache.maven.artifact.handler.manager.LegacyArtifactHandlerManager;
import org.apache.maven.eventspy.AbstractEventSpy; import org.apache.maven.eventspy.AbstractEventSpy;
import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.repository.internal.type.DefaultType;
import static java.util.function.Function.identity;
import static org.apache.maven.internal.impl.Utils.nonNull; import static org.apache.maven.internal.impl.Utils.nonNull;
@Named @Named
@ -46,17 +51,16 @@ public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistr
private final ConcurrentHashMap<String, Type> usedTypes; private final ConcurrentHashMap<String, Type> usedTypes;
private final ConcurrentHashMap<String, Type> legacyTypes;
private final LegacyArtifactHandlerManager manager; private final LegacyArtifactHandlerManager manager;
@Inject @Inject
public DefaultTypeRegistry( public DefaultTypeRegistry(
Map<String, Type> types, LanguageRegistry languageRegistry, LegacyArtifactHandlerManager manager) { List<TypeProvider> providers, LanguageRegistry languageRegistry, LegacyArtifactHandlerManager manager) {
this.types = nonNull(types, "types"); this.types = nonNull(providers, "providers").stream()
.flatMap(p -> p.provides().stream())
.collect(Collectors.toMap(Type::id, identity()));
this.languageRegistry = nonNull(languageRegistry, "languageRegistry"); this.languageRegistry = nonNull(languageRegistry, "languageRegistry");
this.usedTypes = new ConcurrentHashMap<>(); this.usedTypes = new ConcurrentHashMap<>();
this.legacyTypes = new ConcurrentHashMap<>();
this.manager = nonNull(manager, "artifactHandlerManager"); this.manager = nonNull(manager, "artifactHandlerManager");
} }
@ -66,7 +70,6 @@ public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistr
ExecutionEvent executionEvent = (ExecutionEvent) event; ExecutionEvent executionEvent = (ExecutionEvent) event;
if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) { if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
usedTypes.clear(); usedTypes.clear();
legacyTypes.clear();
} }
} }
} }
@ -83,18 +86,15 @@ public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistr
return usedTypes.computeIfAbsent(id, i -> { return usedTypes.computeIfAbsent(id, i -> {
Type type = types.get(id); Type type = types.get(id);
if (type == null) { if (type == null) {
// legacy types ALWAYS return type (AHM never returns null)
type = legacyTypes.computeIfAbsent(id, k -> {
// Copy data as the ArtifactHandler is not immutable, but Type should be. // Copy data as the ArtifactHandler is not immutable, but Type should be.
ArtifactHandler handler = manager.getArtifactHandler(id); ArtifactHandler handler = manager.getArtifactHandler(id);
return new DefaultType( type = new DefaultType(
id, id,
languageRegistry.require(handler.getLanguage()), languageRegistry.require(handler.getLanguage()),
handler.getExtension(), handler.getExtension(),
handler.getClassifier(), handler.getClassifier(),
handler.isAddedToClasspath(), handler.isAddedToClasspath(),
handler.isIncludesDependencies()); handler.isIncludesDependencies());
});
} }
return type; return type;
}); });

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(BomTypeProvider.NAME)
@Singleton
public class BomTypeProvider implements Provider<Type> {
public static final String NAME = "bom";
private final Type type;
public BomTypeProvider() {
this.type = new DefaultType(NAME, Language.NONE, "pom", null, false, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(EarTypeProvider.NAME)
@Singleton
public class EarTypeProvider implements Provider<Type> {
public static final String NAME = "ear";
private final Type type;
public EarTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "ear", null, false, true);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(EjbClientTypeProvider.NAME)
@Singleton
public class EjbClientTypeProvider implements Provider<Type> {
public static final String NAME = "ejb-client";
private final Type type;
public EjbClientTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", "client", true, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(EjbTypeProvider.NAME)
@Singleton
public class EjbTypeProvider implements Provider<Type> {
public static final String NAME = "ejb";
private final Type type;
public EjbTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", null, true, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(JarTypeProvider.NAME)
@Singleton
public class JarTypeProvider implements Provider<Type> {
public static final String NAME = "jar";
private final Type type;
public JarTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", null, true, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(JavaSourceTypeProvider.NAME)
@Singleton
public class JavaSourceTypeProvider implements Provider<Type> {
public static final String NAME = "java-source";
private final Type type;
public JavaSourceTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", "sources", false, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(JavadocTypeProvider.NAME)
@Singleton
public class JavadocTypeProvider implements Provider<Type> {
public static final String NAME = "javadoc";
private final Type type;
public JavadocTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", "javadoc", true, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(MavenPluginTypeProvider.NAME)
@Singleton
public class MavenPluginTypeProvider implements Provider<Type> {
public static final String NAME = "maven-plugin";
private final Type type;
public MavenPluginTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", null, true, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(ParTypeProvider.NAME)
@Singleton
public class ParTypeProvider implements Provider<Type> {
public static final String NAME = "par";
private final Type type;
public ParTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "par", null, false, true);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(RarTypeProvider.NAME)
@Singleton
public class RarTypeProvider implements Provider<Type> {
public static final String NAME = "rar";
private final Type type;
public RarTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "rar", null, false, true);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(TestJarTypeProvider.NAME)
@Singleton
public class TestJarTypeProvider implements Provider<Type> {
public static final String NAME = "test-jar";
private final Type type;
public TestJarTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "jar", "tests", true, false);
}
@Override
public Type get() {
return type;
}
}

View File

@ -1,44 +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.types;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.internal.impl.DefaultType;
@Named(WarTypeProvider.NAME)
@Singleton
public class WarTypeProvider implements Provider<Type> {
public static final String NAME = "war";
private final Type type;
public WarTypeProvider() {
this.type = new DefaultType(NAME, Language.JAVA_FAMILY, "war", null, false, true);
}
@Override
public Type get() {
return type;
}
}

View File

@ -29,10 +29,10 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.apache.maven.RepositoryUtils; import org.apache.maven.RepositoryUtils;
import org.apache.maven.api.DependencyScope;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.PluginResolutionException; import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.repository.internal.scopes.MavenDependencyScopes;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;
@ -211,8 +211,8 @@ public class DefaultPluginDependenciesResolver implements PluginDependenciesReso
for (Dependency dependency : plugin.getDependencies()) { for (Dependency dependency : plugin.getDependencies()) {
org.eclipse.aether.graph.Dependency pluginDep = org.eclipse.aether.graph.Dependency pluginDep =
RepositoryUtils.toDependency(dependency, session.getArtifactTypeRegistry()); RepositoryUtils.toDependency(dependency, session.getArtifactTypeRegistry());
if (!MavenDependencyScopes.SYSTEM.equals(pluginDep.getScope())) { if (!DependencyScope.SYSTEM.is(pluginDep.getScope())) {
pluginDep = pluginDep.setScope(MavenDependencyScopes.RUNTIME); pluginDep = pluginDep.setScope(DependencyScope.RUNTIME.id());
} }
request.addDependency(pluginDep); request.addDependency(pluginDep);
} }

View File

@ -22,8 +22,8 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.maven.api.DependencyScope;
import org.apache.maven.plugin.PluginValidationManager; import org.apache.maven.plugin.PluginValidationManager;
import org.apache.maven.repository.internal.scopes.MavenDependencyScopes;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.resolution.ArtifactDescriptorResult; import org.eclipse.aether.resolution.ArtifactDescriptorResult;
@ -50,7 +50,7 @@ class Maven3CompatDependenciesValidator extends AbstractMavenPluginDependenciesV
for (org.eclipse.aether.graph.Dependency dependency : artifactDescriptorResult.getDependencies()) { for (org.eclipse.aether.graph.Dependency dependency : artifactDescriptorResult.getDependencies()) {
if ("org.apache.maven".equals(dependency.getArtifact().getGroupId()) if ("org.apache.maven".equals(dependency.getArtifact().getGroupId())
&& "maven-compat".equals(dependency.getArtifact().getArtifactId()) && "maven-compat".equals(dependency.getArtifact().getArtifactId())
&& !MavenDependencyScopes.TEST.equals(dependency.getScope())) { && !DependencyScope.TEST.is(dependency.getScope())) {
pluginValidationManager.reportPluginValidationIssue( pluginValidationManager.reportPluginValidationIssue(
PluginValidationManager.IssueLocality.EXTERNAL, PluginValidationManager.IssueLocality.EXTERNAL,
session, session,

View File

@ -25,8 +25,8 @@ import javax.inject.Singleton;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.maven.api.DependencyScope;
import org.apache.maven.plugin.PluginValidationManager; import org.apache.maven.plugin.PluginValidationManager;
import org.apache.maven.repository.internal.scopes.MavenDependencyScopes;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.resolution.ArtifactDescriptorResult; import org.eclipse.aether.resolution.ArtifactDescriptorResult;
@ -51,8 +51,7 @@ class MavenScopeDependenciesValidator extends AbstractMavenPluginDependenciesVal
Artifact pluginArtifact, Artifact pluginArtifact,
ArtifactDescriptorResult artifactDescriptorResult) { ArtifactDescriptorResult artifactDescriptorResult) {
Set<String> mavenArtifacts = artifactDescriptorResult.getDependencies().stream() Set<String> mavenArtifacts = artifactDescriptorResult.getDependencies().stream()
.filter(d -> !MavenDependencyScopes.PROVIDED.equals(d.getScope()) .filter(d -> !DependencyScope.PROVIDED.is(d.getScope()) && !DependencyScope.TEST.is(d.getScope()))
&& !MavenDependencyScopes.TEST.equals(d.getScope()))
.map(org.eclipse.aether.graph.Dependency::getArtifact) .map(org.eclipse.aether.graph.Dependency::getArtifact)
.filter(a -> "org.apache.maven".equals(a.getGroupId())) .filter(a -> "org.apache.maven".equals(a.getGroupId()))
.filter(a -> !DefaultPluginValidationManager.EXPECTED_PROVIDED_SCOPE_EXCLUSIONS_GA.contains( .filter(a -> !DefaultPluginValidationManager.EXPECTED_PROVIDED_SCOPE_EXCLUSIONS_GA.contains(

View File

@ -40,9 +40,9 @@ public class DefaultModelBuildingListener extends AbstractModelBuildingListener
private final MavenProject project; private final MavenProject project;
private ProjectBuildingHelper projectBuildingHelper; private final ProjectBuildingHelper projectBuildingHelper;
private ProjectBuildingRequest projectBuildingRequest; private final ProjectBuildingRequest projectBuildingRequest;
private List<ArtifactRepository> remoteRepositories; private List<ArtifactRepository> remoteRepositories;

View File

@ -29,11 +29,11 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.apache.maven.RepositoryUtils; import org.apache.maven.RepositoryUtils;
import org.apache.maven.api.DependencyScope;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Exclusion; import org.apache.maven.model.Exclusion;
import org.apache.maven.repository.internal.scopes.MavenDependencyScopes;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;
@ -130,7 +130,7 @@ public class DefaultProjectDependenciesResolver implements ProjectDependenciesRe
Dependency dependency = dependencies.get(key); Dependency dependency = dependencies.get(key);
Collection<Exclusion> exclusions = dependency != null ? dependency.getExclusions() : null; Collection<Exclusion> exclusions = dependency != null ? dependency.getExclusions() : null;
org.eclipse.aether.graph.Dependency dep = RepositoryUtils.toDependency(artifact, exclusions); org.eclipse.aether.graph.Dependency dep = RepositoryUtils.toDependency(artifact, exclusions);
if (!MavenDependencyScopes.SYSTEM.equals(dep.getScope()) if (!DependencyScope.SYSTEM.is(dep.getScope())
&& dep.getArtifact().getFile() != null) { && dep.getArtifact().getFile() != null) {
// enable re-resolution // enable re-resolution
org.eclipse.aether.artifact.Artifact art = dep.getArtifact(); org.eclipse.aether.artifact.Artifact art = dep.getArtifact();

View File

@ -18,31 +18,8 @@
*/ */
package org.apache.maven.repository.internal; package org.apache.maven.repository.internal;
import org.apache.maven.repository.internal.scopes.MavenDependencyContextRefiner;
import org.apache.maven.repository.internal.scopes.MavenScopeDeriver;
import org.apache.maven.repository.internal.scopes.MavenScopeSelector;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession.SessionBuilder;
import org.eclipse.aether.artifact.ArtifactTypeRegistry;
import org.eclipse.aether.artifact.DefaultArtifactType;
import org.eclipse.aether.collection.DependencyGraphTransformer;
import org.eclipse.aether.collection.DependencyManager;
import org.eclipse.aether.collection.DependencySelector;
import org.eclipse.aether.collection.DependencyTraverser;
import org.eclipse.aether.util.artifact.DefaultArtifactTypeRegistry;
import org.eclipse.aether.util.graph.manager.ClassicDependencyManager; import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
import org.eclipse.aether.util.graph.selector.AndDependencySelector;
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
import org.eclipse.aether.util.graph.selector.OptionalDependencySelector;
import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
import org.eclipse.aether.util.graph.transformer.ConflictResolver;
import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
import static java.util.Objects.requireNonNull;
/** /**
* A utility class to assist in setting up a Maven-like repository system. <em>Note:</em> This component is meant to * A utility class to assist in setting up a Maven-like repository system. <em>Note:</em> This component is meant to
@ -66,88 +43,13 @@ public final class MavenRepositorySystemUtils {
@Deprecated @Deprecated
public static DefaultRepositorySystemSession newSession() { public static DefaultRepositorySystemSession newSession() {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false); // no close handle DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false); // no close handle
MavenSessionBuilderSupplier builder = new MavenSessionBuilderSupplier();
DependencyTraverser depTraverser = new FatArtifactTraverser(); session.setDependencyTraverser(builder.getDependencyTraverser());
session.setDependencyTraverser(depTraverser); session.setDependencyManager(new ClassicDependencyManager()); // Maven 3 behavior
session.setDependencySelector(builder.getDependencySelector());
DependencyManager depManager = new ClassicDependencyManager(); session.setDependencyGraphTransformer(builder.getDependencyGraphTransformer());
session.setDependencyManager(depManager); session.setArtifactTypeRegistry(builder.getArtifactTypeRegistry());
session.setArtifactDescriptorPolicy(builder.getArtifactDescriptorPolicy());
DependencySelector depFilter = new AndDependencySelector(
new ScopeDependencySelector("test", "provided"),
new OptionalDependencySelector(),
new ExclusionDependencySelector());
session.setDependencySelector(depFilter);
DependencyGraphTransformer transformer = new ConflictResolver(
new NearestVersionSelector(), new MavenScopeSelector(),
new SimpleOptionalitySelector(), new MavenScopeDeriver());
transformer = new ChainedDependencyGraphTransformer(transformer, new MavenDependencyContextRefiner());
session.setDependencyGraphTransformer(transformer);
session.setArtifactTypeRegistry(newArtifactTypeRegistry());
session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
return session;
}
/**
* Creates new Maven-like {@link ArtifactTypeRegistry}. This method should not be used from Maven.
*
* @since 4.0.0
*/
public static ArtifactTypeRegistry newArtifactTypeRegistry() {
DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
stereotypes.add(new DefaultArtifactType("pom"));
stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
return stereotypes;
}
/**
* Creates a new Maven-like repository system session by initializing the session with values typical for
* Maven-based resolution. In more detail, this method configures settings relevant for the processing of dependency
* graphs, most other settings remain at their generic default value. Use the various setters to further configure
* the session with authentication, mirror, proxy and other information required for your environment.
*
* @return The new repository system session, never {@code null}.
* @since 4.0.0
*/
public static SessionBuilder newSession(SessionBuilder session, ArtifactTypeRegistry artifactTypeRegistry) {
requireNonNull(session, "null sessionBuilder");
requireNonNull(artifactTypeRegistry, "null artifactTypeRegistry");
DependencyTraverser depTraverser = new FatArtifactTraverser();
session.setDependencyTraverser(depTraverser);
DependencyManager depManager = new ClassicDependencyManager();
session.setDependencyManager(depManager);
DependencySelector depFilter = new AndDependencySelector(
new ScopeDependencySelector("test", "provided"),
new OptionalDependencySelector(),
new ExclusionDependencySelector());
session.setDependencySelector(depFilter);
DependencyGraphTransformer transformer = new ConflictResolver(
new NearestVersionSelector(), new MavenScopeSelector(),
new SimpleOptionalitySelector(), new MavenScopeDeriver());
transformer = new ChainedDependencyGraphTransformer(transformer, new MavenDependencyContextRefiner());
session.setDependencyGraphTransformer(transformer);
session.setArtifactTypeRegistry(artifactTypeRegistry);
session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
return session; return session;
} }
} }

View File

@ -20,14 +20,15 @@ package org.apache.maven.repository.internal;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.apache.maven.repository.internal.artifact.FatArtifactTraverser;
import org.apache.maven.repository.internal.scopes.MavenDependencyContextRefiner; import org.apache.maven.repository.internal.scopes.MavenDependencyContextRefiner;
import org.apache.maven.repository.internal.scopes.MavenScopeDeriver; import org.apache.maven.repository.internal.scopes.MavenScopeDeriver;
import org.apache.maven.repository.internal.scopes.MavenScopeSelector; import org.apache.maven.repository.internal.scopes.MavenScopeSelector;
import org.apache.maven.repository.internal.type.DefaultTypeProvider;
import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession.CloseableSession; import org.eclipse.aether.RepositorySystemSession.CloseableSession;
import org.eclipse.aether.RepositorySystemSession.SessionBuilder; import org.eclipse.aether.RepositorySystemSession.SessionBuilder;
import org.eclipse.aether.artifact.ArtifactTypeRegistry; import org.eclipse.aether.artifact.ArtifactTypeRegistry;
import org.eclipse.aether.artifact.DefaultArtifactType;
import org.eclipse.aether.collection.DependencyGraphTransformer; import org.eclipse.aether.collection.DependencyGraphTransformer;
import org.eclipse.aether.collection.DependencyManager; import org.eclipse.aether.collection.DependencyManager;
import org.eclipse.aether.collection.DependencySelector; import org.eclipse.aether.collection.DependencySelector;
@ -43,7 +44,6 @@ import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransform
import org.eclipse.aether.util.graph.transformer.ConflictResolver; import org.eclipse.aether.util.graph.transformer.ConflictResolver;
import org.eclipse.aether.util.graph.transformer.NearestVersionSelector; import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector; import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy; import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
@ -64,6 +64,14 @@ public class MavenSessionBuilderSupplier implements Supplier<SessionBuilder> {
this.repositorySystem = requireNonNull(repositorySystem); this.repositorySystem = requireNonNull(repositorySystem);
} }
/**
* Package protected constructor, only for use with {@link MavenRepositorySystemUtils}.
*/
@Deprecated
MavenSessionBuilderSupplier() {
this.repositorySystem = null;
}
protected DependencyTraverser getDependencyTraverser() { protected DependencyTraverser getDependencyTraverser() {
return new FatArtifactTraverser(); return new FatArtifactTraverser();
} }
@ -87,20 +95,18 @@ public class MavenSessionBuilderSupplier implements Supplier<SessionBuilder> {
new MavenDependencyContextRefiner()); new MavenDependencyContextRefiner());
} }
/**
* This method produces "surrogate" type registry that is static: it aims users that want to use
* Maven-Resolver without involving Maven Core and related things.
* <p>
* This type registry is NOT used by Maven Core: Maven replaces it during Session creation with a type registry
* that supports extending it (i.e. via Maven Extensions).
* <p>
* Important: this "static" list of types should be in-sync with core provided types.
*/
protected ArtifactTypeRegistry getArtifactTypeRegistry() { protected ArtifactTypeRegistry getArtifactTypeRegistry() {
DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry(); DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
stereotypes.add(new DefaultArtifactType("pom")); new DefaultTypeProvider().types().forEach(stereotypes::add);
stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
return stereotypes; return stereotypes;
} }

View File

@ -0,0 +1,67 @@
/*
* 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.repository.internal.artifact;
import org.eclipse.aether.collection.DependencyCollectionContext;
import org.eclipse.aether.collection.DependencyTraverser;
import org.eclipse.aether.graph.Dependency;
import static java.util.Objects.requireNonNull;
/**
* A dependency traverser that excludes the dependencies of fat artifacts from the traversal. Fat artifacts are
* artifacts that have the property {@link MavenArtifactProperties#INCLUDES_DEPENDENCIES} set to
* {@code true}.
*
* @see org.eclipse.aether.artifact.Artifact#getProperties()
* @see MavenArtifactProperties
* @since 4.0.0
*/
public final class FatArtifactTraverser implements DependencyTraverser {
public FatArtifactTraverser() {}
@Override
public boolean traverseDependency(Dependency dependency) {
requireNonNull(dependency, "dependency cannot be null");
String prop = dependency.getArtifact().getProperty(MavenArtifactProperties.INCLUDES_DEPENDENCIES, "");
return !Boolean.parseBoolean(prop);
}
@Override
public DependencyTraverser deriveChildTraverser(DependencyCollectionContext context) {
requireNonNull(context, "context cannot be null");
return this;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (null == obj || !getClass().equals(obj.getClass())) {
return false;
}
return true;
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.repository.internal.artifact;
/**
* The keys for Maven specific properties of artifacts. These properties "extend" (or supplement) the Resolver
* core properties defined in {@link org.eclipse.aether.artifact.ArtifactProperties}.
*
* @see org.eclipse.aether.artifact.ArtifactProperties
* @since 4.0.0
*/
public final class MavenArtifactProperties {
/**
* A boolean flag indicating whether the artifact presents some kind of bundle that physically includes its
* dependencies, e.g. a fat WAR.
*/
public static final String INCLUDES_DEPENDENCIES = "includesDependencies";
/**
* A boolean flag indicating whether the artifact is meant to be used for the compile/runtime/test build path of a
* consumer project.
* <p>
* Note: This property is about "build path", whatever it means in the scope of the consumer project. It is NOT
* about Java classpath or anything alike. How artifact is being consumed depends heavily on the consumer project.
* Resolver is and will remain agnostic of consumer project use cases.
*/
public static final String CONSTITUTES_BUILD_PATH = "constitutesBuildPath";
private MavenArtifactProperties() {
// hide constructor
}
}

View File

@ -37,6 +37,9 @@ import static java.util.Objects.requireNonNull;
*/ */
public final class MavenDependencyContextRefiner implements DependencyGraphTransformer { public final class MavenDependencyContextRefiner implements DependencyGraphTransformer {
public MavenDependencyContextRefiner() {}
@Override
public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context)
throws RepositoryException { throws RepositoryException {
requireNonNull(node, "node cannot be null"); requireNonNull(node, "node cannot be null");

View File

@ -22,15 +22,13 @@ 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
* over Resolver. * over Resolver. The labels are defined in {@link DependencyScope} class, these are here used only for "easier
* reachability" in internal classes.
* *
* @since 4.0.0 * @since 4.0.0
*/ */
public final class MavenDependencyScopes { public final class MavenDependencyScopes {
/**
* Important: keep this label in sync with Resolver.
*/
public static final String SYSTEM = DependencyScope.SYSTEM.id(); public static final String SYSTEM = DependencyScope.SYSTEM.id();
public static final String NONE = DependencyScope.NONE.id(); public static final String NONE = DependencyScope.NONE.id();

View File

@ -30,9 +30,6 @@ import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeDeriver;
*/ */
public final class MavenScopeDeriver extends ScopeDeriver { public final class MavenScopeDeriver extends ScopeDeriver {
/**
* Creates a new instance of this scope deriver.
*/
public MavenScopeDeriver() {} public MavenScopeDeriver() {}
@Override @Override

View File

@ -37,9 +37,6 @@ import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeSelector;
*/ */
public final class MavenScopeSelector extends ScopeSelector { public final class MavenScopeSelector extends ScopeSelector {
/**
* Creates a new instance of this scope selector.
*/
public MavenScopeSelector() {} public MavenScopeSelector() {}
@Override @Override

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.maven.internal.impl; package org.apache.maven.repository.internal.type;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -24,21 +24,25 @@ import java.util.Map;
import org.apache.maven.api.Language; import org.apache.maven.api.Language;
import org.apache.maven.api.Type; import org.apache.maven.api.Type;
import org.apache.maven.repository.internal.artifact.MavenArtifactProperties;
import org.eclipse.aether.artifact.ArtifactProperties; import org.eclipse.aether.artifact.ArtifactProperties;
import org.eclipse.aether.artifact.ArtifactType; import org.eclipse.aether.artifact.ArtifactType;
import static org.apache.maven.internal.impl.Utils.nonNull; import static java.util.Objects.requireNonNull;
/**
* Default implementation of {@link Type} and Resolver {@link ArtifactType}.
*
* @since 4.0.0
*/
public class DefaultType implements Type, ArtifactType { public class DefaultType implements Type, ArtifactType {
private final String id; private final String id;
private final Language language; 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 boolean buildPathConstituent;
private final boolean includesDependencies; private final boolean includesDependencies;
private final Map<String, String> properties;
public DefaultType( public DefaultType(
String id, String id,
@ -47,12 +51,19 @@ public class DefaultType implements Type, ArtifactType {
String classifier, String classifier,
boolean buildPathConstituent, boolean buildPathConstituent,
boolean includesDependencies) { boolean includesDependencies) {
this.id = nonNull(id, "id"); this.id = requireNonNull(id, "id");
this.language = nonNull(language, "language"); this.language = requireNonNull(language, "language");
this.extension = nonNull(extension, "extension"); this.extension = requireNonNull(extension, "extension");
this.classifier = classifier; this.classifier = classifier;
this.buildPathConstituent = buildPathConstituent; this.buildPathConstituent = buildPathConstituent;
this.includesDependencies = includesDependencies; this.includesDependencies = includesDependencies;
Map<String, String> properties = new HashMap<>();
properties.put(ArtifactProperties.TYPE, id);
properties.put(ArtifactProperties.LANGUAGE, language.id());
properties.put(MavenArtifactProperties.INCLUDES_DEPENDENCIES, Boolean.toString(includesDependencies));
properties.put(MavenArtifactProperties.CONSTITUTES_BUILD_PATH, Boolean.toString(buildPathConstituent));
this.properties = Collections.unmodifiableMap(properties);
} }
@Override @Override
@ -92,11 +103,6 @@ public class DefaultType implements Type, ArtifactType {
@Override @Override
public Map<String, String> getProperties() { public Map<String, String> getProperties() {
Map<String, String> properties = new HashMap<>(); return properties;
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

@ -0,0 +1,54 @@
/*
* 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.repository.internal.type;
import javax.inject.Named;
import java.util.Arrays;
import java.util.Collection;
import org.apache.maven.api.Language;
import org.apache.maven.api.Type;
import org.apache.maven.api.spi.TypeProvider;
@Named
public class DefaultTypeProvider implements TypeProvider {
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Collection<Type> provides() {
return (Collection) types();
}
public Collection<DefaultType> types() {
return Arrays.asList(
new DefaultType("bom", Language.NONE, "pom", null, false, false),
new DefaultType("pom", Language.NONE, "pom", null, false, false),
new DefaultType("maven-plugin", Language.JAVA_FAMILY, "jar", null, true, false),
new DefaultType("jar", Language.JAVA_FAMILY, "jar", null, true, false),
new DefaultType("ejb", Language.JAVA_FAMILY, "jar", null, true, false),
new DefaultType("ejb-client", Language.JAVA_FAMILY, "jar", "client", true, false),
new DefaultType("test-jar", Language.JAVA_FAMILY, "jar", "tests", true, false),
new DefaultType("javadoc", Language.JAVA_FAMILY, "jar", "javadoc", true, false),
new DefaultType("java-source", Language.JAVA_FAMILY, "jar", "sources", false, false),
new DefaultType("war", Language.JAVA_FAMILY, "war", null, false, true),
new DefaultType("ear", Language.JAVA_FAMILY, "ear", null, false, true),
new DefaultType("rar", Language.JAVA_FAMILY, "rar", null, false, true),
new DefaultType("par", Language.JAVA_FAMILY, "par", null, false, true));
}
}