[MNG-7962] Return language to Type (#1341)

Returns the language property to Type

---

https://issues.apache.org/jira/browse/MNG-7962
This commit is contained in:
Tamas Cservenak 2023-12-14 11:51:16 +01:00 committed by GitHub
parent eee9514d3d
commit a1fe9fc387
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 72 additions and 22 deletions

View File

@ -42,12 +42,8 @@ import org.apache.maven.api.model.Dependency;
@Immutable
public interface Type {
String POM = "pom";
String JAR = "jar";
String JAVA_SOURCE = "java-source";
String JAVADOC = "javadoc";
String MAVEN_PLUGIN = "maven-plugin";
String TEST_JAR = "test-jar";
String LANGUAGE_NONE = "none";
String LANGUAGE_JAVA = "java";
/**
* Returns the dependency type id.
@ -58,6 +54,13 @@ public interface Type {
@Nonnull
String getId();
/**
* Returns the dependency type language.
*
* @return the language of this type, never {@code null}.
*/
String getLanguage();
/**
* Get the file extension of artifacts of this type.
*

View File

@ -70,7 +70,7 @@ public class DefaultArtifactHandlerManager extends AbstractEventSpy implements A
null,
null,
type.isIncludesDependencies(),
"none",
type.getLanguage(),
type.isAddedToClassPath()); // TODO: watch out for module path
});
}

View File

@ -30,7 +30,7 @@ public class TypeRegistryAdapter implements ArtifactTypeRegistry {
private final TypeRegistry typeRegistry;
public TypeRegistryAdapter(TypeRegistry typeRegistry) {
this.typeRegistry = requireNonNull(typeRegistry, "null typeRegistry");
this.typeRegistry = requireNonNull(typeRegistry, "typeRegistry");
}
@Override
@ -41,7 +41,11 @@ public class TypeRegistryAdapter implements ArtifactTypeRegistry {
}
if (type != null) {
return new DefaultType(
type.getId(), type.getExtension(), type.getClassifier(), type.getDependencyProperties());
type.getId(),
type.getLanguage(),
type.getExtension(),
type.getClassifier(),
type.getDependencyProperties());
}
return null;
}

View File

@ -35,13 +35,20 @@ public class DefaultType implements Type, ArtifactType {
private final DependencyProperties dependencyProperties;
public DefaultType(String id, String extension, String classifier, DependencyProperties dependencyProperties) {
public DefaultType(
String id,
String language,
String extension,
String classifier,
DependencyProperties dependencyProperties) {
nonNull(id, "id");
nonNull(language, "language");
this.extension = nonNull(extension, "extension");
this.classifier = classifier;
nonNull(dependencyProperties, "dependencyProperties");
HashMap<String, String> props = new HashMap<>(dependencyProperties.asMap());
props.put(ArtifactProperties.TYPE, id);
props.put(ArtifactProperties.LANGUAGE, language);
this.dependencyProperties = new DefaultDependencyProperties(props);
}
@ -50,6 +57,11 @@ public class DefaultType implements Type, ArtifactType {
return dependencyProperties.asMap().get(ArtifactProperties.TYPE);
}
@Override
public String getLanguage() {
return dependencyProperties.asMap().get(ArtifactProperties.LANGUAGE);
}
@Override
public String getExtension() {
return extension;

View File

@ -87,6 +87,7 @@ public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistr
}
return new DefaultType(
id,
handler.getLanguage(),
handler.getExtension(),
handler.getClassifier(),
new DefaultDependencyProperties(flags));

View File

@ -34,7 +34,7 @@ public class BomTypeProvider implements Provider<Type> {
private final Type type;
public BomTypeProvider() {
this.type = new DefaultType(NAME, "pom", null, new DefaultDependencyProperties());
this.type = new DefaultType(NAME, Type.LANGUAGE_NONE, "pom", null, new DefaultDependencyProperties());
}
@Override

View File

@ -36,7 +36,11 @@ public class EarTypeProvider implements Provider<Type> {
public EarTypeProvider() {
this.type = new DefaultType(
NAME, "ear", null, new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
NAME,
Type.LANGUAGE_JAVA,
"ear",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
}
@Override

View File

@ -37,6 +37,7 @@ public class EjbClientTypeProvider implements Provider<Type> {
public EjbClientTypeProvider() {
this.type = new DefaultType(
NAME,
Type.LANGUAGE_JAVA,
"jar",
"client",
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));

View File

@ -36,7 +36,11 @@ public class EjbTypeProvider implements Provider<Type> {
public EjbTypeProvider() {
this.type = new DefaultType(
NAME, "jar", null, new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
NAME,
Type.LANGUAGE_JAVA,
"jar",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
}
@Override

View File

@ -36,7 +36,11 @@ public class JarTypeProvider implements Provider<Type> {
public JarTypeProvider() {
this.type = new DefaultType(
NAME, "jar", null, new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
NAME,
Type.LANGUAGE_JAVA,
"jar",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
}
@Override

View File

@ -34,7 +34,7 @@ public class JavaSourceTypeProvider implements Provider<Type> {
private final Type type;
public JavaSourceTypeProvider() {
this.type = new DefaultType(NAME, "jar", "sources", new DefaultDependencyProperties());
this.type = new DefaultType(NAME, Type.LANGUAGE_JAVA, "jar", "sources", new DefaultDependencyProperties());
}
@Override

View File

@ -37,6 +37,7 @@ public class JavadocTypeProvider implements Provider<Type> {
public JavadocTypeProvider() {
this.type = new DefaultType(
NAME,
Type.LANGUAGE_JAVA,
"jar",
"javadoc",
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));

View File

@ -36,7 +36,11 @@ public class MavenPluginTypeProvider implements Provider<Type> {
public MavenPluginTypeProvider() {
this.type = new DefaultType(
NAME, "jar", null, new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
NAME,
Type.LANGUAGE_JAVA,
"jar",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));
}
@Override

View File

@ -36,7 +36,11 @@ public class ParTypeProvider implements Provider<Type> {
public ParTypeProvider() {
this.type = new DefaultType(
NAME, "par", null, new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
NAME,
Type.LANGUAGE_JAVA,
"par",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
}
@Override

View File

@ -34,7 +34,7 @@ public class PomTypeProvider implements Provider<Type> {
private final Type type;
public PomTypeProvider() {
this.type = new DefaultType(NAME, "pom", null, new DefaultDependencyProperties());
this.type = new DefaultType(NAME, Type.LANGUAGE_NONE, "pom", null, new DefaultDependencyProperties());
}
@Override

View File

@ -36,7 +36,11 @@ public class RarTypeProvider implements Provider<Type> {
public RarTypeProvider() {
this.type = new DefaultType(
NAME, "rar", null, new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
NAME,
Type.LANGUAGE_JAVA,
"rar",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
}
@Override

View File

@ -37,6 +37,7 @@ public class TestJarTypeProvider implements Provider<Type> {
public TestJarTypeProvider() {
this.type = new DefaultType(
NAME,
Type.LANGUAGE_JAVA,
"jar",
"tests",
new DefaultDependencyProperties(DependencyProperties.FLAG_CLASS_PATH_CONSTITUENT));

View File

@ -36,7 +36,11 @@ public class WarTypeProvider implements Provider<Type> {
public WarTypeProvider() {
this.type = new DefaultType(
NAME, "war", null, new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
NAME,
Type.LANGUAGE_JAVA,
"war",
null,
new DefaultDependencyProperties(DependencyProperties.FLAG_INCLUDES_DEPENDENCIES));
}
@Override

View File

@ -79,8 +79,7 @@ class ArtifactHandlerTest {
// Packaging/Directory is Maven1 remnant!!!
// assertEquals(handler.getPackaging(), packaging, type + " packaging");
assertEquals(handler.getClassifier(), classifier, type + " classifier");
// Language is unused
// assertEquals(handler.getLanguage(), language, type + " language");
assertEquals(handler.getLanguage(), language, type + " language");
assertEquals(
handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath");
assertEquals(