1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.api;
20
21 import java.util.Map;
22
23 import org.apache.maven.api.annotations.Experimental;
24 import org.apache.maven.api.annotations.Immutable;
25 import org.apache.maven.api.annotations.Nonnull;
26 import org.apache.maven.api.model.PluginContainer;
27
28 /**
29 * Represents the packaging of a Maven project.
30 *
31 * <p>The {@code Packaging} class defines the type of artifact that a Maven project produces during the build process.
32 * The packaging type determines the structure of the project's output and how Maven will treat the resulting artifact.</p>
33 *
34 * <p>Common packaging types include {@code jar}, {@code war}, {@code pom}, {@code maven-plugin}, {@code ear}, and others.
35 * These types influence various aspects of the build lifecycle, such as which plugins are executed and how dependencies are managed.</p>
36 *
37 * <p>The {@code Packaging} class is an immutable value object, ensuring that once a packaging type is defined, it cannot be changed.</p>
38 *
39 * <h2>Standard Packaging Types</h2>
40 * <ul>
41 * <li>{@code jar}: Packages the project as a Java Archive (JAR) file.</li>
42 * <li>{@code war}: Packages the project as a Web Application Archive (WAR) file.</li>
43 * <li>{@code pom}: Indicates that the project does not produce a deployable artifact but is used for dependency management or as an aggregator.</li>
44 * <li>{@code maven-plugin}: Packages the project as a Maven plugin.</li>
45 * </ul>
46 *
47 * <h2>Usage Example</h2>
48 *
49 * <pre>
50 * {@code
51 * Session session = ... // Obtain a Maven session
52 * Packaging packaging = session.requirePackaging("jar");
53 * System.out.println(packaging.getId()); // Outputs "jar"
54 * }
55 * </pre>
56 *
57 * @see org.apache.maven.api.Session#requirePackaging(String)
58 * @see org.apache.maven.api.Project#getPackaging()
59 * @see org.apache.maven.api.model.Model#getPackaging()
60 * @since 4.0.0
61 */
62 @Experimental
63 @Immutable
64 public interface Packaging extends ExtensibleEnum {
65 /**
66 * The packaging id.
67 */
68 @Nonnull
69 String id();
70
71 /**
72 * The language of this packaging.
73 */
74 @Nonnull
75 default Language language() {
76 return type().getLanguage();
77 }
78
79 /**
80 * The type of main artifact produced by this packaging.
81 */
82 @Nonnull
83 Type type();
84
85 /**
86 * Returns the binding to use specifically for this packaging keyed by lifecycle id.
87 * This will be used instead of the default packaging definition.
88 */
89 @Nonnull
90 Map<String, PluginContainer> plugins();
91 }