diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java
index 888e247fe1..efad1415ad 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java
@@ -30,6 +30,14 @@ public interface Dependency extends Artifact {
@Nonnull
Type getType();
+ /**
+ * The dependency properties.
+ *
+ * @return the dependency properties, never {@code null}
+ */
+ @Nonnull
+ DependencyProperties getDependencyProperties();
+
@Nonnull
Scope getScope();
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyProperties.java b/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyProperties.java
new file mode 100644
index 0000000000..9f63416848
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyProperties.java
@@ -0,0 +1,59 @@
+/*
+ * 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.Map;
+
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Immutable;
+import org.apache.maven.api.annotations.Nonnull;
+
+/**
+ * Dependency properties supported by Maven Core.
+ *
+ * @since 4.0.0
+ */
+@Experimental
+@Immutable
+public interface DependencyProperties {
+ /**
+ * Boolean flag telling that dependency contains all of its dependencies. Value of this key should be parsed with
+ * {@link Boolean#parseBoolean(String)} to obtain value.
+ *
+ * Important: this flag must be kept in sync with resolver! (as is used during collection)
+ */
+ 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
+ Map asMap();
+
+ /**
+ * Returns {@code true} if given flag is {@code true}.
+ */
+ boolean checkFlag(@Nonnull String flag);
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Type.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Type.java
index 846a8ac23d..4401c82e11 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Type.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Type.java
@@ -20,6 +20,8 @@
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.model.Dependency;
/**
@@ -51,15 +53,17 @@ public interface Type {
* Returns the dependency type id.
* The id uniquely identifies this dependency type.
*
- * @return the id of this type
+ * @return the id of this type, never {@code null}.
*/
+ @Nonnull
String getId();
/**
* Get the file extension of artifacts of this type.
*
- * @return the file extension
+ * @return the file extension, never {@code null}.
*/
+ @Nonnull
String getExtension();
/**
@@ -67,17 +71,20 @@ public interface Type {
* The default classifier can be overridden when specifying
* the {@link Dependency#getClassifier()}.
*
- * @return the default classifier
+ * @return the default classifier, or {@code null}.
*/
+ @Nullable
String getClassifier();
/**
* Specifies if the artifact contains java classes and should be
* added to the classpath.
*
- * @return if the artifact should be added to the classpath
+ * @return if the artifact should be added to the class path
*/
- boolean isAddedToClasspath();
+ default boolean isAddedToClassPath() {
+ return getDependencyProperties().checkFlag(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT);
+ }
/**
* Specifies if the artifact already embeds its own dependencies.
@@ -86,5 +93,15 @@ public interface Type {
*
* @return if the artifact's dependencies are included in the artifact
*/
- boolean isIncludesDependencies();
+ default 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();
}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java b/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java
index fb31efcef3..53fab056e1 100644
--- a/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java
+++ b/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java
@@ -26,47 +26,61 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.maven.api.Type;
+import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.eventspy.AbstractEventSpy;
+import org.apache.maven.execution.ExecutionEvent;
+
+import static java.util.Objects.requireNonNull;
/**
*/
@Named
@Singleton
-public class DefaultArtifactHandlerManager implements ArtifactHandlerManager {
+public class DefaultArtifactHandlerManager extends AbstractEventSpy implements ArtifactHandlerManager {
+ private final TypeRegistry typeRegistry;
- private final Map artifactHandlers;
-
- private final Map allHandlers = new ConcurrentHashMap<>();
+ private final ConcurrentHashMap allHandlers;
@Inject
- public DefaultArtifactHandlerManager(Map artifactHandlers) {
- this.artifactHandlers = artifactHandlers;
+ public DefaultArtifactHandlerManager(TypeRegistry typeRegistry) {
+ this.typeRegistry = requireNonNull(typeRegistry, "null typeRegistry");
+ this.allHandlers = new ConcurrentHashMap<>();
}
- public ArtifactHandler getArtifactHandler(String type) {
- ArtifactHandler handler = allHandlers.get(type);
-
- if (handler == null) {
- handler = artifactHandlers.get(type);
-
- if (handler == null) {
- handler = new DefaultArtifactHandler(type);
- } else {
- allHandlers.put(type, handler);
+ @Override
+ public void onEvent(Object event) {
+ if (event instanceof ExecutionEvent) {
+ ExecutionEvent executionEvent = (ExecutionEvent) event;
+ if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
+ allHandlers.clear();
}
}
+ }
- return handler;
+ public ArtifactHandler getArtifactHandler(String id) {
+ return allHandlers.computeIfAbsent(id, k -> {
+ Type type = typeRegistry.getType(id);
+ return new DefaultArtifactHandler(
+ id,
+ type.getExtension(),
+ type.getClassifier(),
+ null,
+ null,
+ type.isIncludesDependencies(),
+ "none",
+ type.isAddedToClassPath()); // TODO: watch out for module path
+ });
}
public void addHandlers(Map handlers) {
- // legacy support for maven-gpg-plugin:1.0
- allHandlers.putAll(handlers);
+ throw new UnsupportedOperationException("Adding handlers programmatically is not supported anymore");
}
@Deprecated
public Set getHandlerTypes() {
- return artifactHandlers.keySet();
+ throw new UnsupportedOperationException("Querying handlers programmatically is not supported anymore");
}
}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/LegacyArtifactHandlerManager.java b/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/LegacyArtifactHandlerManager.java
new file mode 100644
index 0000000000..46e480fae5
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/LegacyArtifactHandlerManager.java
@@ -0,0 +1,72 @@
+/*
+ * 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.artifact.handler.manager;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.eventspy.AbstractEventSpy;
+import org.apache.maven.execution.ExecutionEvent;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ */
+@Named
+@Singleton
+public class LegacyArtifactHandlerManager extends AbstractEventSpy {
+ private final Map artifactHandlers;
+
+ private final Map allHandlers = new ConcurrentHashMap<>();
+
+ @Inject
+ public LegacyArtifactHandlerManager(Map artifactHandlers) {
+ this.artifactHandlers = requireNonNull(artifactHandlers);
+ }
+
+ @Override
+ public void onEvent(Object event) {
+ if (event instanceof ExecutionEvent) {
+ ExecutionEvent executionEvent = (ExecutionEvent) event;
+ if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
+ allHandlers.clear();
+ }
+ }
+ }
+
+ public ArtifactHandler getArtifactHandler(String type) {
+ requireNonNull(type, "null type");
+ ArtifactHandler handler = allHandlers.get(type);
+ if (handler == null) {
+ handler = artifactHandlers.get(type);
+ if (handler == null) {
+ handler = new DefaultArtifactHandler(type);
+ } else {
+ allHandlers.put(type, handler);
+ }
+ }
+ return handler;
+ }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/JavaSourceArtifactHandlerProvider.java b/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/JavaSourceArtifactHandlerProvider.java
deleted file mode 100644
index 467be6da8a..0000000000
--- a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/JavaSourceArtifactHandlerProvider.java
+++ /dev/null
@@ -1,47 +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.artifact.handler.providers;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Provider;
-import javax.inject.Singleton;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-
-/**
- * {@code java-source} artifact handler provider.
- */
-@Named("java-source")
-@Singleton
-public class JavaSourceArtifactHandlerProvider implements Provider {
- private final ArtifactHandler artifactHandler;
-
- @Inject
- public JavaSourceArtifactHandlerProvider() {
- this.artifactHandler =
- new DefaultArtifactHandler("java-source", "jar", "sources", null, null, false, "java", false);
- }
-
- @Override
- public ArtifactHandler get() {
- return artifactHandler;
- }
-}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/JavadocArtifactHandlerProvider.java b/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/JavadocArtifactHandlerProvider.java
deleted file mode 100644
index cdb3b08b67..0000000000
--- a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/JavadocArtifactHandlerProvider.java
+++ /dev/null
@@ -1,46 +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.artifact.handler.providers;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Provider;
-import javax.inject.Singleton;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-
-/**
- * {@code javadoc} artifact handler provider.
- */
-@Named("javadoc")
-@Singleton
-public class JavadocArtifactHandlerProvider implements Provider {
- private final ArtifactHandler artifactHandler;
-
- @Inject
- public JavadocArtifactHandlerProvider() {
- this.artifactHandler = new DefaultArtifactHandler("javadoc", "jar", "javadoc", null, null, false, "java", true);
- }
-
- @Override
- public ArtifactHandler get() {
- return artifactHandler;
- }
-}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/MavenPluginArtifactHandlerProvider.java b/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/MavenPluginArtifactHandlerProvider.java
deleted file mode 100644
index 8eb28fad09..0000000000
--- a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/MavenPluginArtifactHandlerProvider.java
+++ /dev/null
@@ -1,46 +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.artifact.handler.providers;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Provider;
-import javax.inject.Singleton;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-
-/**
- * {@code maven-plugin} artifact handler provider.
- */
-@Named("maven-plugin")
-@Singleton
-public class MavenPluginArtifactHandlerProvider implements Provider {
- private final ArtifactHandler artifactHandler;
-
- @Inject
- public MavenPluginArtifactHandlerProvider() {
- this.artifactHandler = new DefaultArtifactHandler("maven-plugin", "jar", null, null, null, false, "java", true);
- }
-
- @Override
- public ArtifactHandler get() {
- return artifactHandler;
- }
-}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/PomArtifactHandlerProvider.java b/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/PomArtifactHandlerProvider.java
deleted file mode 100644
index 12d1107d5c..0000000000
--- a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/PomArtifactHandlerProvider.java
+++ /dev/null
@@ -1,46 +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.artifact.handler.providers;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Provider;
-import javax.inject.Singleton;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-
-/**
- * {@code pom} artifact handler provider.
- */
-@Named("pom")
-@Singleton
-public class PomArtifactHandlerProvider implements Provider {
- private final ArtifactHandler artifactHandler;
-
- @Inject
- public PomArtifactHandlerProvider() {
- this.artifactHandler = new DefaultArtifactHandler("pom", null, null, null, null, false, "none", false);
- }
-
- @Override
- public ArtifactHandler get() {
- return artifactHandler;
- }
-}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/TestJarArtifactHandlerProvider.java b/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/TestJarArtifactHandlerProvider.java
deleted file mode 100644
index 160bc6783b..0000000000
--- a/maven-core/src/main/java/org/apache/maven/artifact/handler/providers/TestJarArtifactHandlerProvider.java
+++ /dev/null
@@ -1,46 +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.artifact.handler.providers;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Provider;
-import javax.inject.Singleton;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-
-/**
- * {@code test-jar} artifact handler provider.
- */
-@Named("test-jar")
-@Singleton
-public class TestJarArtifactHandlerProvider implements Provider {
- private final ArtifactHandler artifactHandler;
-
- @Inject
- public TestJarArtifactHandlerProvider() {
- this.artifactHandler = new DefaultArtifactHandler("test-jar", "jar", "tests", null, "jar", false, "java", true);
- }
-
- @Override
- public ArtifactHandler get() {
- return artifactHandler;
- }
-}
diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
index e17ab7c54b..6dd44ab79e 100644
--- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
+++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
@@ -33,6 +33,7 @@
import java.util.stream.Collectors;
import org.apache.maven.RepositoryUtils;
+import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -155,6 +156,8 @@ public class DefaultRepositorySystemSessionFactory {
private final RuntimeInformation runtimeInformation;
+ private final TypeRegistry typeRegistry;
+
@SuppressWarnings("checkstyle:ParameterNumber")
@Inject
public DefaultRepositorySystemSessionFactory(
@@ -163,13 +166,15 @@ public DefaultRepositorySystemSessionFactory(
@Nullable @Named("ide") WorkspaceReader workspaceRepository,
SettingsDecrypter settingsDecrypter,
EventSpyDispatcher eventSpyDispatcher,
- RuntimeInformation runtimeInformation) {
+ RuntimeInformation runtimeInformation,
+ TypeRegistry typeRegistry) {
this.artifactHandlerManager = artifactHandlerManager;
this.repoSystem = repoSystem;
this.workspaceRepository = workspaceRepository;
this.settingsDecrypter = settingsDecrypter;
this.eventSpyDispatcher = eventSpyDispatcher;
this.runtimeInformation = runtimeInformation;
+ this.typeRegistry = typeRegistry;
}
@Deprecated
@@ -179,7 +184,8 @@ public RepositorySystemSession newRepositorySession(MavenExecutionRequest reques
@SuppressWarnings("checkstyle:methodLength")
public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) {
- SessionBuilder session = MavenRepositorySystemUtils.newSession(repoSystem.createSessionBuilder());
+ SessionBuilder session = MavenRepositorySystemUtils.newSession(
+ repoSystem.createSessionBuilder(), new TypeRegistryAdapter(typeRegistry));
session.setCache(request.getRepositoryCache());
Map