[MNG-7553] New clean API with immutable model (#703)

This commit is contained in:
Guillaume Nodet 2022-10-02 10:41:25 +02:00 committed by GitHub
parent 1ca65c79fa
commit 2a9f39336c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
542 changed files with 41551 additions and 9316 deletions

View File

@ -7,4 +7,5 @@ load ${maven.conf}/logging
optionally ${maven.home}/lib/ext/redisson/*.jar optionally ${maven.home}/lib/ext/redisson/*.jar
optionally ${maven.home}/lib/ext/hazelcast/*.jar optionally ${maven.home}/lib/ext/hazelcast/*.jar
optionally ${maven.home}/lib/ext/*.jar optionally ${maven.home}/lib/ext/*.jar
load ${maven.home}/lib/maven-*.jar
load ${maven.home}/lib/*.jar load ${maven.home}/lib/*.jar

View File

@ -25,7 +25,7 @@ import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.apache.maven.settings.v4.SettingsXpp3Reader;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;

View File

@ -0,0 +1,55 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api</artifactId>
<version>4.0.0-alpha-1-SNAPSHOT</version>
</parent>
<artifactId>maven-api-core</artifactId>
<name>Apache Maven Core API</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-meta</artifactId>
<version>4.0.0-alpha-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-model</artifactId>
<version>4.0.0-alpha-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-settings</artifactId>
<version>4.0.0-alpha-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-toolchain</artifactId>
<version>4.0.0-alpha-1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,107 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
/**
* An artifact points to a resource such as a jar file or war application.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface Artifact
{
/**
* Returns a unique identifier for this artifact.
* The identifier is composed of groupId, artifactId, version, classifier, extension
* @return the unique identifier
*/
default String key()
{
return getGroupId()
+ ':' + getArtifactId()
+ ':' + getExtension()
+ ( getClassifier().length() > 0 ? ":" + getClassifier() : "" )
+ ':' + getVersion();
}
/**
* The groupId of the artifact.
*
* @return The groupId.
*/
@Nonnull
String getGroupId();
/**
* The artifactId of the artifact.
*
* @return The artifactId.
*/
@Nonnull
String getArtifactId();
/**
* The version of the artifact.
*
* @return The version.
*/
@Nonnull
Version getVersion();
/**
* The classifier of the artifact.
*
* @return The classifier or an empty string if none, never {@code null}.
*/
@Nonnull
String getClassifier();
/**
* The file extension of the artifact.
*
* @return The extension.
*/
@Nonnull
String getExtension();
/**
* Determines whether this artifact uses a snapshot version.
*
* @return {@code true} if the artifact is a snapshot, {@code false} otherwise.
* @see org.apache.maven.api.Session#isVersionSnapshot(String)
*/
boolean isSnapshot();
/**
* Shortcut for {@code session.createArtifactCoordinate(artifact)}
*
* @return an {@link ArtifactCoordinate}
* @see org.apache.maven.api.Session#createArtifactCoordinate(Artifact)
*/
@Nonnull
ArtifactCoordinate toCoordinate();
}

View File

@ -0,0 +1,89 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
/**
* The {@code Coordinate} object is used to point to an {@link Artifact}
* but the version may be specified as a range instead of an exact version.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface ArtifactCoordinate
{
/**
* The groupId of the artifact.
*
* @return The groupId.
*/
@Nonnull
String getGroupId();
/**
* The artifactId of the artifact.
*
* @return The artifactId.
*/
@Nonnull
String getArtifactId();
/**
* The classifier of the artifact.
*
* @return The classifier or an empty string if none, never {@code null}.
*/
@Nonnull
String getClassifier();
/**
* The version of the artifact.
*
* @return The version.
*/
@Nonnull
VersionRange getVersion();
/**
* The extension of the artifact.
*
* @return The extension or an empty string if none, never {@code null}.
*/
@Nonnull
String getExtension();
/**
* Unique id identifying this artifact
*/
default String getId()
{
return getGroupId()
+ ":" + getArtifactId()
+ ":" + getExtension()
+ ( getClassifier().isEmpty() ? "" : ":" + getClassifier() )
+ ":" + getVersion();
}
}

View File

@ -0,0 +1,48 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Nonnull;
public interface Dependency extends Artifact
{
/**
* The artifact type.
*
* @return The artifact type, never {@code null}.
*/
@Nonnull
Type getType();
Scope getScope();
boolean isOptional();
/**
* Shortcut for {@code session.createDependencyCoordinate(dependency)}
*
* @return an {@link DependencyCoordinate}
* @see org.apache.maven.api.Session#createDependencyCoordinate(Dependency)
*/
@Nonnull
DependencyCoordinate toCoordinate();
}

View File

@ -0,0 +1,54 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.annotations.Immutable;
import java.util.Collection;
/**
*
* @since 4.0
*/
@Experimental
@Immutable
public interface DependencyCoordinate extends ArtifactCoordinate
{
/**
* The type of the artifact.
*
* @return The type.
*/
@Nonnull
Type getType();
@Nonnull
Scope getScope();
@Nullable
Boolean getOptional();
@Nonnull
Collection<Exclusion> getExclusions();
}

View File

@ -0,0 +1,77 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import java.util.Optional;
/**
* Event sent by maven during various phases of the build process.
* Such events can be listened to using {@link Listener}s objects
* registered in the {@link Session}.
*
* @since 4.0
*/
@Experimental
public interface Event
{
/**
* Gets the type of the event.
*
* @return The type of the event, never {@code null}.
*/
@Nonnull
EventType getType();
/**
* Gets the session from which this event originates.
*
* @return The current session, never {@code null}.
*/
@Nonnull
Session getSession();
/**
* Gets the current project (if any).
*
* @return The current project or {@code empty()} if not applicable.
*/
@Nonnull
Optional<Project> getProject();
/**
* Gets the current mojo execution (if any).
*
* @return The current mojo execution or {@code empty()} if not applicable.
*/
@Nonnull
Optional<MojoExecution> getMojoExecution();
/**
* Gets the exception that caused the event (if any).
*
* @return The exception or {@code empty()} if none.
*/
Optional<Exception> getException();
}

View File

@ -0,0 +1,49 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* The possible types of execution events.
*
* @since 4.0
*/
@Experimental
public enum EventType
{
PROJECT_DISCOVERY_STARTED,
SESSION_STARTED,
SESSION_ENDED,
PROJECT_SKIPPED,
PROJECT_STARTED,
PROJECT_SUCCEEDED,
PROJECT_FAILED,
MOJO_SKIPPED,
MOJO_STARTED,
MOJO_SUCCEEDED,
MOJO_FAILED,
FORK_STARTED,
FORK_SUCCEEDED,
FORK_FAILED,
FORKED_PROJECT_STARTED,
FORKED_PROJECT_SUCCEEDED,
FORKED_PROJECT_FAILED,
}

View File

@ -0,0 +1,40 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nullable;
/**
* A dependency exlusion.
*
* @since 4.0
* @see DependencyCoordinate#getExclusions()
*/
@Experimental
public interface Exclusion
{
@Nullable
String getGroupId();
@Nullable
String getArtifactId();
}

View File

@ -0,0 +1,35 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* A specific {@link Toolchain} dedicated for Java.
*
* @since 4.0
*/
@Experimental
public interface JavaToolchain extends Toolchain
{
String getJavaHome();
}

View File

@ -0,0 +1,36 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Consumer;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* A listener for session events.
*
* @since 4.0
*/
@Experimental
@FunctionalInterface @Consumer
public interface Listener
{
void onEvent( @Nonnull Event event );
}

View File

@ -0,0 +1,42 @@
package org.apache.maven.api;
/*
* 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.
*/
import java.nio.file.Path;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
/**
* The local repository is used to cache artifacts downloaded from {@link RemoteRepository}
* and to hold artifacts that have been build locally.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface LocalRepository extends Repository
{
@Nonnull
Path getPath();
}

View File

@ -0,0 +1,41 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* TODO: investigate removing the Metadata api completely
*
* @since 4.0
*/
@Experimental
public interface Metadata
{
String getGroupId();
String getArtifactId();
String getVersion();
MetadataStorage getStorage();
}

View File

@ -0,0 +1,35 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* Storage location for metadata
*
* @since 4.0
*/
@Experimental
public enum MetadataStorage
{
GROUP,
ARTIFACT,
VERSION
}

View File

@ -0,0 +1,47 @@
package org.apache.maven.api;
/*
* 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.
*/
import java.util.Optional;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.model.Plugin;
import org.apache.maven.api.xml.Dom;
/**
* A {@code MojoExecution}
*/
@Experimental
public interface MojoExecution
{
@Nonnull
Plugin getPlugin();
@Nonnull
String getExecutionId();
@Nonnull
String getGoal();
@Nonnull
Optional<Dom> getConfiguration();
}

View File

@ -0,0 +1,103 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
/**
* Represents a dependency node within a Maven project's dependency collector.
*
* @since 4.0
* @see org.apache.maven.api.services.DependencyCollectorResult#getRoot()
*/
@Experimental
@Immutable
public interface Node
{
/**
* @return dependency for this node
*/
Dependency getDependency();
/**
* Gets the child nodes of this node.
*
* @return the child nodes of this node, never {@code null}
*/
@Nonnull
List<Node> getChildren();
/**
* @return repositories of this node
*/
@Nonnull
List<RemoteRepository> getRemoteRepositories();
/**
* The repository where this artifact has been downloaded from.
*/
@Nonnull
Optional<RemoteRepository> getRepository();
/**
* Traverses this node and potentially its children using the specified visitor.
*
* @param visitor The visitor to call back, must not be {@code null}.
* @return {@code true} to visit siblings nodes of this node as well, {@code false} to skip siblings.
*/
boolean accept( @Nonnull NodeVisitor visitor );
/**
* Returns a new tree starting at this node, filtering the children.
* Note that this node will not be filtered and only the children
* and its descendant will be checked.
*
* @param filter the filter to apply
* @return a new filtered graph
*/
Node filter( Predicate<Node> filter );
/**
* Returns a string representation of this dependency node.
*
* @return the string representation
*/
String asString();
/**
* Obtain a Stream containing this node and all its descendant.
*
* @return a stream containing this node and its descendant
*/
@Nonnull
default Stream<Node> stream()
{
return Stream.concat( Stream.of( this ), getChildren().stream().flatMap( Node::stream ) );
}
}

View File

@ -0,0 +1,53 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Consumer;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* Defines a hierarchical visitor for collecting dependency node trees.
*
* @since 4.0
*/
@Experimental
@Consumer
public interface NodeVisitor
{
/**
* Starts the visit to the specified dependency node.
*
* @param node the dependency node to visit
* @return <code>true</code> to visit the specified dependency node's children, <code>false</code> to skip the
* specified dependency node's children and proceed to its next sibling
*/
boolean enter( @Nonnull Node node );
/**
* Ends the visit to the specified dependency node.
*
* @param node the dependency node to visit
* @return <code>true</code> to visit the specified dependency node's next sibling, <code>false</code> to skip the
* specified dependency node's next siblings and proceed to its parent
*/
boolean leave( @Nonnull Node node );
}

View File

@ -0,0 +1,105 @@
package org.apache.maven.api;
/*
* 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.
*/
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.model.Build;
import org.apache.maven.api.model.Model;
/**
* Interface representing a Maven project.
* Projects can be built using the {@link org.apache.maven.api.services.ProjectBuilder} service.
*
* @since 4.0
*/
@Experimental
public interface Project
{
@Nonnull
String getGroupId();
@Nonnull
String getArtifactId();
@Nonnull
String getVersion();
@Nonnull
String getPackaging();
@Nonnull
Artifact getArtifact();
@Nonnull
Model getModel();
@Nonnull
default Build getBuild()
{
Build build = getModel().getBuild();
return build != null ? build : Build.newInstance();
}
/**
* Returns the path to the pom file for this project.
* A project is usually read from the file system and this will point to
* the file. In some cases, a transient project can be created which
* will not point to an actual pom file.
* @return the path of the pom
*/
@Nonnull
Optional<Path> getPomPath();
@Nonnull
default Optional<Path> getBasedir()
{
return getPomPath().map( Path::getParent );
}
@Nonnull
List<DependencyCoordinate> getDependencies();
@Nonnull
List<DependencyCoordinate> getManagedDependencies();
@Nonnull
default String getId()
{
return getModel().getId();
}
boolean isExecutionRoot();
@Nonnull
Optional<Project> getParent();
@Nonnull
List<RemoteRepository> getRemoteProjectRepositories();
@Nonnull
List<RemoteRepository> getRemotePluginRepositories();
}

View File

@ -0,0 +1,40 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
/**
* A remote repository that can be used to download or upload artifacts.
*/
@Experimental
@Immutable
public interface RemoteRepository extends Repository
{
@Nonnull
String getUrl();
@Nonnull
String getProtocol();
}

View File

@ -0,0 +1,54 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
/**
* A repository holds artifacts.
*
* @since 4.0
* @see RemoteRepository
* @see LocalRepository
*/
@Experimental
@Immutable
public interface Repository
{
/**
* Gets the identifier of this repository.
*
* @return The (case-sensitive) identifier, never {@code null}.
*/
@Nonnull
String getId();
/**
* Gets the type of the repository, for example "default".
*
* @return The (case-sensitive) type of the repository, never {@code null}.
*/
@Nonnull
String getType();
}

View File

@ -0,0 +1,31 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
*
* @since 4.0
*/
@Experimental
public interface RepositoryMetadata extends Metadata
{
}

View File

@ -0,0 +1,104 @@
package org.apache.maven.api;
/*
* 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.
*/
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
*/
@Experimental
public enum ResolutionScope
{
/**
* empty resolution scope
*/
NONE( null ),
/**
* <code>compile</code> resolution scope
* = <code>compile</code> + <code>system</code> + <code>provided</code> dependencies
*/
COMPILE( "compile", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED ),
/**
* <code>compile+runtime</code> resolution scope (Maven 3 only)
* = <code>compile</code> + <code>system</code> + <code>provided</code> + <code>runtime</code> dependencies
*/
COMPILE_PLUS_RUNTIME( "compile+runtime", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED, Scope.RUNTIME ),
/**
* <code>runtime</code> resolution scope
* = <code>compile</code> + <code>runtime</code> dependencies
*/
RUNTIME( "runtime", Scope.COMPILE, Scope.RUNTIME ),
/**
* <code>runtime+system</code> resolution scope (Maven 3 only)
* = <code>compile</code> + <code>system</code> + <code>runtime</code> dependencies
*/
RUNTIME_PLUS_SYSTEM( "runtime+system", Scope.COMPILE, Scope.SYSTEM, Scope.RUNTIME ),
/**
* <code>test</code> resolution scope
* = <code>compile</code> + <code>system</code> + <code>provided</code> + <code>runtime</code> + <code>test</code>
* dependencies
*/
TEST( "test", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED, Scope.RUNTIME, Scope.TEST );
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

@ -0,0 +1,57 @@
package org.apache.maven.api;
/*
* 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.
*/
import java.util.Locale;
import org.apache.maven.api.annotations.Experimental;
/**
* Scope for a dependency
*
* @since 4.0
*/
@Experimental
public enum Scope
{
COMPILE( "compile" ),
PROVIDED ( "provided" ),
SYSTEM( "system" ),
RUNTIME( "runtime" ),
TEST( "test" ),
IMPORT( "import" );
private final String id;
Scope( String id )
{
this.id = id;
}
public String id()
{
return this.id;
}
public static Scope get( String scope )
{
return Enum.valueOf( Scope.class, scope.toUpperCase( Locale.ROOT ) );
}
}

View File

@ -0,0 +1,37 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.ThreadSafe;
/**
* Marker interface for all services provided by the {@link Session}.
* <p>
* Services can be retrieved from the session using the
* {@link Session#getService(Class)} method.
*
* @see Session#getService(Class)
*/
@Experimental
@ThreadSafe
public interface Service
{
}

View File

@ -0,0 +1,346 @@
package org.apache.maven.api;
/*
* 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.
*/
import java.nio.file.Path;
import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Properties;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.ThreadSafe;
import org.apache.maven.api.model.Repository;
import org.apache.maven.api.services.DependencyCoordinateFactory;
import org.apache.maven.api.settings.Settings;
/**
* The session to install / deploy / resolve artifacts and dependencies.
*
* @since 4.0
*/
@Experimental
@ThreadSafe
public interface Session
{
@Nonnull
Settings getSettings();
@Nonnull
LocalRepository getLocalRepository();
@Nonnull
List<RemoteRepository> getRemoteRepositories();
@Nonnull
SessionData getData();
// TODO: investigate using Map<String, String> or Map<String, Object> for all properties in the new API
@Nonnull
Properties getUserProperties();
@Nonnull
Properties getSystemProperties();
/**
* Returns the current maven version
* @return the maven version, never {@code null}.
*/
@Nonnull
String getMavenVersion();
int getDegreeOfConcurrency();
@Nonnull
Instant getStartTime();
@Nonnull
Path getMultiModuleProjectDirectory();
@Nonnull
Path getExecutionRootDirectory();
@Nonnull
List<Project> getProjects();
/**
* Returns the plugin context for mojo being executed and the specified
* {@link Project}, never returns {@code null} as if context not present, creates it.
*
* <strong>Implementation note:</strong> while this method return type is {@link Map}, the returned map instance
* implements {@link java.util.concurrent.ConcurrentMap} as well.
*
* @throws org.apache.maven.api.services.MavenException if not called from the within a mojo execution
*/
@Nonnull
Map<String, Object> getPluginContext( @Nonnull Project project );
/**
* Retrieves the service for the interface
*
* @throws NoSuchElementException if the service could not be found
*/
@Nonnull
<T extends Service> T getService( @Nonnull Class<T> clazz );
/**
* Creates a derived session using the given local repository.
*
* @param localRepository the new local repository
* @return the derived session
* @throws NullPointerException if {@code localRepository} is null
*/
@Nonnull
Session withLocalRepository( @Nonnull LocalRepository localRepository );
/**
* Creates a derived session using the given remote repositories.
*
* @param repositories the new list of remote repositories
* @return the derived session
* @throws NullPointerException if {@code repositories} is null
*/
@Nonnull
Session withRemoteRepositories( @Nonnull List<RemoteRepository> repositories );
/**
* Register the given listener which will receive all events.
*
* @param listener the listener to register
* @throws NullPointerException if {@code listener} is null
*/
void registerListener( @Nonnull Listener listener );
/**
* Unregisters a previously registered listener.
*
* @param listener the listener to unregister
* @throws NullPointerException if {@code listener} is null
*/
void unregisterListener( @Nonnull Listener listener );
/**
* Returns the list of registered listeners.
*
* @return an immutable collection of listeners, never {@code null}
*/
@Nonnull
Collection<Listener> getListeners();
/**
* Shortcut for <code>getService(RepositoryFactory.class).createLocal(...)</code>
* @see org.apache.maven.api.services.RepositoryFactory#createLocal(Path)
*/
LocalRepository createLocalRepository( Path path );
/**
* Shortcut for <code>getService(RepositoryFactory.class).createRemote(...)</code>
* @see org.apache.maven.api.services.RepositoryFactory#createRemote(String, String)
*/
@Nonnull
RemoteRepository createRemoteRepository( @Nonnull String id, @Nonnull String url );
/**
* Shortcut for <code>getService(RepositoryFactory.class).createRemote(...)</code>
* @see org.apache.maven.api.services.RepositoryFactory#createRemote(Repository)
*/
@Nonnull
RemoteRepository createRemoteRepository( @Nonnull Repository repository );
/**
* Shortcut for <code>getService(ArtifactFactory.class).create(...)</code>
* @see org.apache.maven.api.services.ArtifactFactory#create(Session, String, String, String, String)
*/
ArtifactCoordinate createArtifactCoordinate( String groupId, String artifactId, String version, String extension );
/**
* Shortcut for <code>getService(ArtifactFactory.class).create(...)</code>
* @see org.apache.maven.api.services.ArtifactFactory#create(Session, String, String, String, String, String, String)
*/
ArtifactCoordinate createArtifactCoordinate( String groupId, String artifactId, String version, String classifier,
String extension, String type );
/**
* Shortcut for <code>getService(ArtifactFactory.class).create(...)</code>
* @see org.apache.maven.api.services.ArtifactFactory#create(Session, String, String, String, String, String, String)
*/
ArtifactCoordinate createArtifactCoordinate( Artifact artifact );
/**
* Shortcut for <code>getService(DependencyFactory.class).create(...)</code>
* @see DependencyCoordinateFactory#create(Session, ArtifactCoordinate)
*/
@Nonnull
DependencyCoordinate createDependencyCoordinate( @Nonnull ArtifactCoordinate coordinate );
/**
* Shortcut for <code>getService(ArtifactFactory.class).create(...)</code>
* @see org.apache.maven.api.services.ArtifactFactory#create(Session, String, String, String, String)
*/
Artifact createArtifact( String groupId, String artifactId, String version, String extension );
/**
* Shortcut for <code>getService(ArtifactFactory.class).create(...)</code>
* @see org.apache.maven.api.services.ArtifactFactory#create(Session, String, String, String, String, String, String)
*/
Artifact createArtifact( String groupId, String artifactId, String version, String classifier,
String extension, String type );
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
* @see org.apache.maven.api.services.ArtifactResolver#resolve(Session, Collection)
*
* @throws org.apache.maven.api.services.ArtifactResolverException if the artifact resolution failed
*/
Artifact resolveArtifact( ArtifactCoordinate coordinate );
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
* @see org.apache.maven.api.services.ArtifactResolver#resolve(Session, Collection)
*
* @throws org.apache.maven.api.services.ArtifactResolverException if the artifact resolution failed
*/
Collection<Artifact> resolveArtifacts( ArtifactCoordinate... coordinates );
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
* @see org.apache.maven.api.services.ArtifactResolver#resolve(Session, Collection)
*
* @throws org.apache.maven.api.services.ArtifactResolverException if the artifact resolution failed
*/
Collection<Artifact> resolveArtifacts( Collection<? extends ArtifactCoordinate> coordinates );
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
* @see org.apache.maven.api.services.ArtifactResolver#resolve(Session, Collection)
*
* @throws org.apache.maven.api.services.ArtifactResolverException if the artifact resolution failed
*/
Artifact resolveArtifact( Artifact artifact );
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
* @see org.apache.maven.api.services.ArtifactResolver#resolve(Session, Collection)
*
* @throws org.apache.maven.api.services.ArtifactResolverException if the artifact resolution failed
*/
Collection<Artifact> resolveArtifacts( Artifact... artifacts );
/**
* Shortcut for {@code getService(ArtifactInstaller.class).install(...)}
* @see org.apache.maven.api.services.ArtifactInstaller#install(Session, Collection)
*
* @throws org.apache.maven.api.services.ArtifactInstallerException if the artifacts installation failed
*/
void installArtifacts( Artifact... artifacts );
/**
* Shortcut for {@code getService(ArtifactInstaller.class).install(...)}
* @see org.apache.maven.api.services.ArtifactInstaller#install(Session, Collection)
*
* @throws org.apache.maven.api.services.ArtifactInstallerException if the artifacts installation failed
*/
void installArtifacts( Collection<Artifact> artifacts );
/**
* Shortcut for <code>getService(ArtifactDeployer.class).deploy(...)</code>
* @see org.apache.maven.api.services.ArtifactDeployer#deploy(Session, RemoteRepository, Collection)
*
* @throws org.apache.maven.api.services.ArtifactDeployerException if the artifacts deployment failed
*/
void deployArtifact( RemoteRepository repository, Artifact... artifacts );
/**
* Shortcut for <code>getService(ArtifactManager.class).setPath(...)</code>
* @see org.apache.maven.api.services.ArtifactManager#setPath(Artifact, Path)
*/
void setArtifactPath( @Nonnull Artifact artifact, @Nonnull Path path );
/**
* Shortcut for <code>getService(ArtifactManager.class).getPath(...)</code>
* @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
*/
@Nonnull
Optional<Path> getArtifactPath( @Nonnull Artifact artifact );
/**
* Shortcut for <code>getService(ArtifactManager.class).isSnapshot(...)</code>
* @see org.apache.maven.api.services.VersionParser#isSnapshot(String)
*/
boolean isVersionSnapshot( @Nonnull String version );
/**
* Shortcut for <code>getService(DependencyCollector.class).collect(...)</code>
* @see org.apache.maven.api.services.DependencyCollector#collect(Session, Artifact)
*
* @throws org.apache.maven.api.services.DependencyCollectorException if the dependency collection failed
*/
@Nonnull
Node collectDependencies( @Nonnull Artifact artifact );
/**
* Shortcut for <code>getService(DependencyCollector.class).collect(...)</code>
* @see org.apache.maven.api.services.DependencyCollector#collect(Session, Project)
*
* @throws org.apache.maven.api.services.DependencyCollectorException if the dependency collection failed
*/
@Nonnull
Node collectDependencies( @Nonnull Project project );
/**
* Shortcut for <code>getService(DependencyResolver.class).resolve(...)</code>
* @see org.apache.maven.api.services.DependencyCollector#collect(Session, DependencyCoordinate)
*
* @throws org.apache.maven.api.services.DependencyCollectorException if the dependency collection failed
*/
@Nonnull
Node collectDependencies( @Nonnull DependencyCoordinate dependency );
Path getPathForLocalArtifact( @Nonnull Artifact artifact );
Path getPathForLocalMetadata( Metadata metadata );
Path getPathForRemoteArtifact( RemoteRepository remote, Artifact artifact );
Path getPathForRemoteMetadata( RemoteRepository remote, Metadata metadata );
/**
* Shortcut for <code>getService(VersionParser.class).parseVersion(...)</code>
* @see org.apache.maven.api.services.VersionParser#parseVersion(String)
*
* @throws org.apache.maven.api.services.VersionParserException if the parsing failed
*/
@Nonnull
Version parseVersion( @Nonnull String version );
/**
* Shortcut for <code>getService(VersionParser.class).parseVersionRange(...)</code>
* @see org.apache.maven.api.services.VersionParser#parseVersionRange(String)
*
* @throws org.apache.maven.api.services.VersionParserException if the parsing failed
*/
@Nonnull
VersionRange parseVersionRange( @Nonnull String versionRange );
}

View File

@ -0,0 +1,86 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.annotations.Provider;
import org.apache.maven.api.annotations.ThreadSafe;
import java.util.function.Supplier;
/**
* A container for data that is specific to a session.
* All components may use this storage to associate arbitrary data with a session.
* <p>
* Unlike a cache, this session data is not subject to purging. For this same reason, session data should also not be
* abused as a cache (i.e. for storing values that can be re-calculated) to avoid memory exhaustion.
* <p>
* <strong>Note:</strong> Actual implementations must be thread-safe.
*
* @see Session#getData()
* @since 4.0
*/
@Experimental
@ThreadSafe @Provider
public interface SessionData
{
/**
* Associates the specified session data with the given key.
*
* @param key The key under which to store the session data, must not be {@code null}.
* @param value The data to associate with the key, may be {@code null} to remove the mapping.
*/
void set( @Nonnull Object key, @Nullable Object value );
/**
* Associates the specified session data with the given key if the key is currently mapped to the given value. This
* method provides an atomic compare-and-update of some key's value.
*
* @param key The key under which to store the session data, must not be {@code null}.
* @param oldValue The expected data currently associated with the key, may be {@code null}.
* @param newValue The data to associate with the key, may be {@code null} to remove the mapping.
* @return {@code true} if the key mapping was successfully updated from the old value to the new value,
* {@code false} if the current key mapping didn't match the expected value and was not updated.
*/
boolean set( @Nonnull Object key, @Nullable Object oldValue, @Nullable Object newValue );
/**
* Gets the session data associated with the specified key.
*
* @param key The key for which to retrieve the session data, must not be {@code null}.
* @return The session data associated with the key or {@code null} if none.
*/
@Nullable
Object get( @Nonnull Object key );
/**
* Retrieve of compute the data associated with the specified key.
*
* @param key The key for which to retrieve the session data, must not be {@code null}.
* @param supplier The supplier will compute the new value.
* @return The session data associated with the key.
*/
@Nullable
Object computeIfAbsent( @Nonnull Object key, @Nonnull Supplier<Object> supplier );
}

View File

@ -0,0 +1,56 @@
package org.apache.maven.api;
/*
* 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.
*/
import java.util.Map;
import org.apache.maven.api.annotations.Experimental;
/**
* Toolchain interface.
*
* @since 4.0
*/
@Experimental
public interface Toolchain
{
/**
* get the type of toolchain.
*
* @return the toolchain type
*/
String getType();
/**
* Gets the platform tool executable.
*
* @param toolName the tool platform independent tool name.
* @return file representing the tool executable, or null if the tool can not be found
*/
String findTool( String toolName );
/**
* Let the toolchain decide if it matches requirements defined
* in the toolchain plugin configuration.
* @param requirements Map&lt;String, String&gt; key value pair, may not be {@code null}
* @return {@code true} if the requirements match, otherwise {@code false}
*/
boolean matchesRequirements( Map<String, String> requirements );
}

View File

@ -0,0 +1,72 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
/**
* An artifact's{@code Type} represents a known kind of artifacts.
* Such types are often associated to an extension and possibly
* a classifier, for example {@code java-source} has a {@code jar}
* extension and a {@code sources} classifier.
* It is also used to determine if a given dependency should be
* included in the classpath or if its transitive dependencies should.
*
* @since 4.0
*/
@Experimental
@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";
/**
* Returns the dependency type name.
*
* @return the type name
*/
String getName();
/**
* Get the file extension associated to the file represented by the dependency type.
*
* @return the file extension
*/
String getExtension();
/**
* Get the classifier associated to the dependency type.
*
* @return the classifier
*/
String getClassifier();
boolean isIncludesDependencies();
boolean isAddedToClasspath();
}

View File

@ -0,0 +1,46 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* A version usually parsed using the {@link org.apache.maven.api.services.VersionParser} service.
*
* @since 4.0
* @see org.apache.maven.api.services.VersionParser#parseVersion(String)
* @see org.apache.maven.api.Session#parseVersion(String)
*/
@Experimental
public interface Version
extends Comparable<Version>
{
// TODO: add access to the version information
/**
* Returns a string representation of this version.
* @return the string representation of this version
*/
@Nonnull
String asString();
}

View File

@ -0,0 +1,50 @@
package org.apache.maven.api;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* A range of versions.
*
* @since 4.0
*/
@Experimental
public interface VersionRange
{
// TODO: add access to the version information
/**
* Determines whether the specified version is contained within this range.
*
* @param version The version to test, must not be {@code null}.
* @return {@code true} if this range contains the specified version, {@code false} otherwise.
*/
boolean contains( @Nonnull Version version );
/**
* Returns a string representation of this version range
* @return the string representation of this version range
*/
@Nonnull
String asString();
}

View File

@ -0,0 +1,168 @@
package org.apache.maven.api.plugin;
/*
* 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.
*/
import java.util.function.Supplier;
/**
* This interface supplies the API for providing feedback to the user from the <code>Mojo</code>, using standard
* <code>Maven</code> channels.<br>
* There should be no big surprises here, although you may notice that the methods accept
* <code>java.lang.CharSequence</code> rather than <code>java.lang.String</code>. This is provided mainly as a
* convenience, to enable developers to pass things like <code>java.lang.StringBuffer</code> directly into the logger,
* rather than formatting first by calling <code>toString()</code>.
*
* @since 4.0
*/
public interface Log
{
/**
* @return true if the <b>debug</b> error level is enabled
*/
boolean isDebugEnabled();
/**
* Send a message to the user in the <b>debug</b> error level.
*
* @param content
*/
void debug( CharSequence content );
/**
* Send a message (and accompanying exception) to the user in the <b>debug</b> error level.<br>
* The error's stacktrace will be output when this error level is enabled.
*
* @param content
* @param error
*/
void debug( CharSequence content, Throwable error );
/**
* Send an exception to the user in the <b>debug</b> error level.<br>
* The stack trace for this exception will be output when this error level is enabled.
*
* @param error
*/
void debug( Throwable error );
void debug( Supplier<String> content );
void debug( Supplier<String> content, Throwable error );
/**
* @return true if the <b>info</b> error level is enabled
*/
boolean isInfoEnabled();
/**
* Send a message to the user in the <b>info</b> error level.
*
* @param content
*/
void info( CharSequence content );
/**
* Send a message (and accompanying exception) to the user in the <b>info</b> error level.<br>
* The error's stacktrace will be output when this error level is enabled.
*
* @param content
* @param error
*/
void info( CharSequence content, Throwable error );
/**
* Send an exception to the user in the <b>info</b> error level.<br>
* The stack trace for this exception will be output when this error level is enabled.
*
* @param error
*/
void info( Throwable error );
void info( Supplier<String> content );
void info( Supplier<String> content, Throwable error );
/**
* @return true if the <b>warn</b> error level is enabled
*/
boolean isWarnEnabled();
/**
* Send a message to the user in the <b>warn</b> error level.
*
* @param content
*/
void warn( CharSequence content );
/**
* Send a message (and accompanying exception) to the user in the <b>warn</b> error level.<br>
* The error's stacktrace will be output when this error level is enabled.
*
* @param content
* @param error
*/
void warn( CharSequence content, Throwable error );
/**
* Send an exception to the user in the <b>warn</b> error level.<br>
* The stack trace for this exception will be output when this error level is enabled.
*
* @param error
*/
void warn( Throwable error );
void warn( Supplier<String> content );
void warn( Supplier<String> content, Throwable error );
/**
* @return true if the <b>error</b> error level is enabled
*/
boolean isErrorEnabled();
/**
* Send a message to the user in the <b>error</b> error level.
*
* @param content
*/
void error( CharSequence content );
/**
* Send a message (and accompanying exception) to the user in the <b>error</b> error level.<br>
* The error's stacktrace will be output when this error level is enabled.
*
* @param content
* @param error
*/
void error( CharSequence content, Throwable error );
/**
* Send an exception to the user in the <b>error</b> error level.<br>
* The stack trace for this exception will be output when this error level is enabled.
*
* @param error
*/
void error( Throwable error );
void error( Supplier<String> content );
void error( Supplier<String> content, Throwable error );
}

View File

@ -0,0 +1,46 @@
package org.apache.maven.api.plugin;
/*
* 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.
*/
import org.apache.maven.api.annotations.Consumer;
import org.apache.maven.api.annotations.Experimental;
/**
* This interface forms the contract required for <code>Mojos</code> to interact with the <code>Maven</code>
* infrastructure.<br>
* It features an <code>execute()</code> method, which triggers the Mojo's build-process behavior, and can throw
* a MojoException if error conditions occur.<br>
*
* @since 4.0
*/
@Experimental
@FunctionalInterface @Consumer
public interface Mojo
{
/**
* Perform whatever build-process behavior this <code>Mojo</code> implements.<br>
* This is the main trigger for the <code>Mojo</code> inside the <code>Maven</code> system, and allows
* the <code>Mojo</code> to communicate errors.
*
* @throws MojoException if a problem occurs.
*/
void execute();
}

View File

@ -0,0 +1,98 @@
package org.apache.maven.api.plugin;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.services.MavenException;
/**
* An exception occurring during the execution of a plugin.
*
* @since 4.0
*/
@Experimental
public class MojoException
extends MavenException
{
protected Object source;
protected String longMessage;
/**
* Construct a new <code>MojoExecutionException</code> exception providing the source and a short and long message:
* these messages are used to improve the message written at the end of Maven build.
*/
public MojoException( Object source, String shortMessage, String longMessage )
{
super( shortMessage );
this.source = source;
this.longMessage = longMessage;
}
/**
* Construct a new <code>MojoExecutionException</code> exception wrapping an underlying <code>Exception</code>
* and providing a <code>message</code>.
*/
public MojoException( String message, Exception cause )
{
super( message, cause );
}
/**
* Construct a new <code>MojoExecutionException</code> exception wrapping an underlying <code>Throwable</code>
* and providing a <code>message</code>.
*/
public MojoException( String message, Throwable cause )
{
super( message, cause );
}
/**
* Construct a new <code>MojoExecutionException</code> exception providing a <code>message</code>.
*/
public MojoException( String message )
{
super( message );
}
/**
* Constructs a new {@code MojoExecutionException} exception wrapping an underlying {@code Throwable}.
*
* @param cause the cause which is saved for later retrieval by the {@link #getCause()} method.
* A {@code null} value is permitted, and indicates that the cause is nonexistent or unknown.
* @since 3.8.3
*/
public MojoException( Throwable cause )
{
super( cause );
}
public String getLongMessage()
{
return longMessage;
}
public Object getSource()
{
return source;
}
}

View File

@ -0,0 +1,56 @@
package org.apache.maven.api.plugin.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.maven.api.annotations.Experimental;
/**
* Used to configure injection of Plexus components by
* <a href="/ref/current/maven-core/apidocs/org/apache/maven/plugin/MavenPluginManager.html">
* <code>MavenPluginManager.getConfiguredMojo(...)</code></a>.
*
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@Target( { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER } )
@Inherited
public @interface Component
{
/**
* role of the component to inject.
* @return the role
*/
Class<?> role() default Object.class;
/**
* hint of the component to inject.
* @return the hint
*/
String hint() default "";
}

View File

@ -0,0 +1,64 @@
package org.apache.maven.api.plugin.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.maven.api.annotations.Experimental;
/**
* Used if your Mojo needs to fork a <a href="/ref/3.0.4/maven-core/lifecycles.html">lifecycle</a>.
*
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@Target( ElementType.TYPE )
@Inherited
public @interface Execute
{
/**
* lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
* @return the phase
*/
LifecyclePhase phase() default LifecyclePhase.NONE;
/**
* goal to fork. Note that specifying a phase overrides specifying a goal. The specified <code>goal</code> must be
* another goal of the same plugin.
* @return the goal
*/
String goal() default "";
/**
* lifecycle id of the lifecycle that defines {@link #phase()}. Only valid in combination with {@link #phase()}. If
* not specified, Maven will use the lifecycle of the current build.
*
* @see <a href="https://maven.apache.org/maven-plugin-api/lifecycle-mappings.html">Lifecycle Mappings</a>
* @return the lifecycle id
*/
String lifecycle() default "";
}

View File

@ -0,0 +1,48 @@
package org.apache.maven.api.plugin.annotations;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* Component instantiation strategy.
*
* @since 4.0
*/
@Experimental
public enum InstantiationStrategy
{
PER_LOOKUP( "per-lookup" ),
SINGLETON( "singleton" ),
KEEP_ALIVE( "keep-alive" ),
POOLABLE( "poolable" );
private final String id;
InstantiationStrategy( String id )
{
this.id = id;
}
public String id()
{
return this.id;
}
}

View File

@ -0,0 +1,80 @@
package org.apache.maven.api.plugin.annotations;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* <a href="/ref/3.0.4/maven-core/lifecycles.html">Lifecycle phases</a>.
*
* @since 4.0
*/
@Experimental
public enum LifecyclePhase
{
VALIDATE( "validate" ),
INITIALIZE( "initialize" ),
GENERATE_SOURCES( "generate-sources" ),
PROCESS_SOURCES( "process-sources" ),
GENERATE_RESOURCES( "generate-resources" ),
PROCESS_RESOURCES( "process-resources" ),
COMPILE( "compile" ),
PROCESS_CLASSES( "process-classes" ),
GENERATE_TEST_SOURCES( "generate-test-sources" ),
PROCESS_TEST_SOURCES( "process-test-sources" ),
GENERATE_TEST_RESOURCES( "generate-test-resources" ),
PROCESS_TEST_RESOURCES( "process-test-resources" ),
TEST_COMPILE( "test-compile" ),
PROCESS_TEST_CLASSES( "process-test-classes" ),
TEST( "test" ),
PREPARE_PACKAGE( "prepare-package" ),
PACKAGE( "package" ),
PRE_INTEGRATION_TEST( "pre-integration-test" ),
INTEGRATION_TEST( "integration-test" ),
POST_INTEGRATION_TEST( "post-integration-test" ),
VERIFY( "verify" ),
INSTALL( "install" ),
DEPLOY( "deploy" ),
PRE_CLEAN( "pre-clean" ),
CLEAN( "clean" ),
POST_CLEAN( "post-clean" ),
PRE_SITE( "pre-site" ),
SITE( "site" ),
POST_SITE( "post-site" ),
SITE_DEPLOY( "site-deploy" ),
NONE( "" );
private final String id;
LifecyclePhase( String id )
{
this.id = id;
}
public String id()
{
return this.id;
}
}

View File

@ -0,0 +1,98 @@
package org.apache.maven.api.plugin.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.annotations.Experimental;
/**
* This annotation will mark your class as a Mojo (ie. goal in a Maven plugin).
*
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@Target( ElementType.TYPE )
@Inherited
public @interface Mojo
{
/**
* goal name (required).
* @return the goal name
*/
String name();
/**
* default phase to bind your mojo.
* @return the default phase
*/
LifecyclePhase defaultPhase() default LifecyclePhase.NONE;
/**
* the required dependency resolution scope.
* @return the required dependency resolution scope
*/
ResolutionScope requiresDependencyResolution() default ResolutionScope.NONE;
/**
* the required dependency collection scope.
* @return the required dependency collection scope
*/
ResolutionScope requiresDependencyCollection() default ResolutionScope.NONE;
/**
* your Mojo instantiation strategy. (Only <code>per-lookup</code> and <code>singleton</code> are supported)
* @return the instantiation strategy
*/
InstantiationStrategy instantiationStrategy() default InstantiationStrategy.PER_LOOKUP;
/**
* does your mojo requires a project to be executed?
* @return requires a project
*/
boolean requiresProject() default true;
/**
* if the Mojo uses the Maven project and its child modules.
* @return uses the Maven project and its child modules
*/
boolean aggregator() default false;
/**
* does this Mojo need to be online to be executed?
* @return need to be online
*/
boolean requiresOnline() default false;
/**
* configurator bean name.
* @return the configurator bean name
*/
String configurator() default "";
}

View File

@ -0,0 +1,94 @@
package org.apache.maven.api.plugin.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.maven.api.annotations.Experimental;
/**
* Used to configure your Mojo parameters to be injected by
* <a href="/ref/current/maven-core/apidocs/org/apache/maven/plugin/MavenPluginManager.html">
* <code>MavenPluginManager.getConfiguredMojo(...)</code></a>.
* <p>
* Beans injected into Mojo parameters are prepared by <a href="https://www.eclipse.org/sisu/">Sisu</a> JSR330-based
* container: this annotation is only effective on fields of the Mojo class itself, nested bean injection
* requires Sisu or JSR330 annotations.
*
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@Target( { ElementType.FIELD, ElementType.METHOD } )
@Inherited
public @interface Parameter
{
/**
* name of the bean property used to get/set the field: by default, field name is used.
* @return the name of the bean property
*/
String name() default "";
/**
* alias supported to get parameter value.
* @return the alias
*/
String alias() default "";
/**
* Property to use to retrieve a value. Can come from <code>-D</code> execution, setting properties or pom
* properties.
* @return property name
*/
String property() default "";
/**
* parameter default value, may contain <code>${...}</code> expressions which will be interpreted at
* inject time: see
* <a href="/ref/current/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html">
* PluginParameterExpressionEvaluator</a>.
* @return the default value
*/
String defaultValue() default "";
/**
* is the parameter required?
* @return <code>true</code> if the Mojo should fail when the parameter cannot be injected
*/
boolean required() default false;
/**
* Specifies that this parameter cannot be configured directly by the user (as in the case of POM-specified
* configuration). This is useful when you want to force the user to use common POM elements rather than plugin
* configurations, as in the case where you want to use the artifact's final name as a parameter. In this case, you
* want the user to modify <code>&lt;build&gt;&lt;finalName/&gt;&lt;/build&gt;</code> rather than specifying a value
* for finalName directly in the plugin configuration section. It is also useful to ensure that - for example - a
* List-typed parameter which expects items of type Artifact doesn't get a List full of Strings.
*
* @return <code>true</code> if the user should not be allowed to configure the parameter directly
*/
boolean readonly() default false;
}

View File

@ -0,0 +1,71 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.Artifact;
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* Service used to create {@link ArtifactCoordinate} objects.
*
* @since 4.0
*/
@Experimental
public interface ArtifactCoordinateFactory extends Service
{
/**
* Creates a coordinate.
*
* @param request the request holding coordinate creation parameters
* @return an {@code Artifact}, never {@code null}
* @throws IllegalArgumentException if {@code request} is null or {@code request.session} is null or invalid
*/
@Nonnull
ArtifactCoordinate create( @Nonnull ArtifactCoordinateFactoryRequest request );
@Nonnull
default ArtifactCoordinate create( @Nonnull Session session, String groupId,
String artifactId, String version, String extension )
{
return create( ArtifactCoordinateFactoryRequest.build( session, groupId, artifactId, version, extension ) );
}
@Nonnull
default ArtifactCoordinate create( @Nonnull Session session, String groupId, String artifactId, String version,
String classifier, String extension, String type )
{
return create( ArtifactCoordinateFactoryRequest.build( session, groupId, artifactId,
version, classifier, extension, type ) );
}
@Nonnull
default ArtifactCoordinate create( @Nonnull Session session, Artifact artifact )
{
return create( ArtifactCoordinateFactoryRequest.build( session,
artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion().asString(),
artifact.getClassifier(), artifact.getExtension(), null ) );
}
}

View File

@ -0,0 +1,222 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Session;
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.NotThreadSafe;
/**
* A request for creating a {@link ArtifactCoordinate} object.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface ArtifactCoordinateFactoryRequest
{
@Nonnull
Session getSession();
String getGroupId();
String getArtifactId();
String getVersion();
String getClassifier();
String getExtension();
String getType();
static ArtifactCoordinateFactoryRequest build( Session session, String groupId, String artifactId,
String version, String extension )
{
return ArtifactCoordinateFactoryRequest.builder()
.session( session )
.groupId( groupId )
.artifactId( artifactId )
.version( version )
.extension( extension )
.build();
}
static ArtifactCoordinateFactoryRequest build( Session session, String groupId, String artifactId,
String version, String classifier, String extension, String type )
{
return ArtifactCoordinateFactoryRequest.builder()
.session( session )
.groupId( groupId )
.artifactId( artifactId )
.version( version )
.classifier( classifier )
.extension( extension )
.type( type )
.build();
}
static ArtifactCoordinateFactoryRequest build( Session session, ArtifactCoordinate coordinate )
{
return ArtifactCoordinateFactoryRequest.builder()
.session( session )
.groupId( coordinate.getGroupId() )
.artifactId( coordinate.getArtifactId() )
.classifier( coordinate.getClassifier() )
.version( coordinate.getVersion().asString() )
.extension( coordinate.getExtension() )
.build();
}
static ArtifactFactoryRequestBuilder builder()
{
return new ArtifactFactoryRequestBuilder();
}
@NotThreadSafe
class ArtifactFactoryRequestBuilder
{
private Session session;
private String groupId;
private String artifactId;
private String version;
private String classifier;
private String extension;
private String type;
public ArtifactFactoryRequestBuilder session( Session session )
{
this.session = session;
return this;
}
public ArtifactFactoryRequestBuilder groupId( String groupId )
{
this.groupId = groupId;
return this;
}
public ArtifactFactoryRequestBuilder artifactId( String artifactId )
{
this.artifactId = artifactId;
return this;
}
public ArtifactFactoryRequestBuilder version( String version )
{
this.version = version;
return this;
}
public ArtifactFactoryRequestBuilder classifier( String classifier )
{
this.classifier = classifier;
return this;
}
public ArtifactFactoryRequestBuilder extension( String extension )
{
this.extension = extension;
return this;
}
public ArtifactFactoryRequestBuilder type( String type )
{
this.type = type;
return this;
}
public ArtifactCoordinateFactoryRequest build()
{
return new DefaultArtifactFactoryRequestArtifact( session, groupId, artifactId, version,
classifier, extension, type );
}
private static class DefaultArtifactFactoryRequestArtifact extends BaseRequest implements
ArtifactCoordinateFactoryRequest
{
private final String groupId;
private final String artifactId;
private final String version;
private final String classifier;
private final String extension;
private final String type;
DefaultArtifactFactoryRequestArtifact( @Nonnull Session session,
String groupId,
String artifactId,
String version,
String classifier,
String extension,
String type )
{
super( session );
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.classifier = classifier;
this.extension = extension;
this.type = type;
}
@Override
public String getGroupId()
{
return groupId;
}
@Override
public String getArtifactId()
{
return artifactId;
}
@Override
public String getVersion()
{
return version;
}
@Override
public String getClassifier()
{
return classifier;
}
@Override
public String getExtension()
{
return extension;
}
@Override
public String getType()
{
return type;
}
}
}
}

View File

@ -0,0 +1,61 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.Collection;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* Deploys {@link Artifact}s to a {@link RemoteRepository}.
*
* @since 4.0
* @see Session#deployArtifact(RemoteRepository, Artifact...)
*/
@Experimental
public interface ArtifactDeployer extends Service
{
/**
* @param request {@link ArtifactDeployerRequest}
* @throws ArtifactDeployerException if the deployment failed
*/
void deploy( @Nonnull ArtifactDeployerRequest request );
/**
* @param session the repository session
* @param repository the repository to deploy to
* @param artifacts the collection of artifacts to deploy
* @throws ArtifactDeployerException if the deployment failed
* @throws IllegalArgumentException if an argument is {@code null} or invalid
*/
default void deploy( @Nonnull Session session,
@Nonnull RemoteRepository repository,
@Nonnull Collection<Artifact> artifacts )
{
deploy( ArtifactDeployerRequest.build( session, repository, artifacts ) );
}
}

View File

@ -0,0 +1,48 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* An artifact could not correctly being deployed.
*
* @since 4.0
*/
@Experimental
public class ArtifactDeployerException
extends MavenException
{
/**
*
*/
private static final long serialVersionUID = 7421964724059077698L;
/**
* @param message The message of the error.
* @param e {@link Exception}
*/
public ArtifactDeployerException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,153 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
import java.util.Collection;
import org.apache.maven.api.Session;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.RemoteRepository;
import static org.apache.maven.api.services.BaseRequest.nonNull;
/**
* A request for deploying one or more artifacts to a remote repository.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface ArtifactDeployerRequest
{
@Nonnull
Session getSession();
@Nonnull
RemoteRepository getRepository();
@Nonnull
Collection<Artifact> getArtifacts();
int getRetryFailedDeploymentCount();
@Nonnull
static ArtifactDeployerRequestBuilder builder()
{
return new ArtifactDeployerRequestBuilder();
}
@Nonnull
static ArtifactDeployerRequest build( @Nonnull Session session,
@Nonnull RemoteRepository repository,
@Nonnull Collection<Artifact> artifacts )
{
return builder()
.session( nonNull( session, "session can not be null" ) )
.repository( repository )
.artifacts( artifacts )
.build();
}
class ArtifactDeployerRequestBuilder
{
Session session;
RemoteRepository repository;
Collection<Artifact> artifacts;
int retryFailedDeploymentCount;
@Nonnull
public ArtifactDeployerRequestBuilder session( Session session )
{
this.session = session;
return this;
}
@Nonnull
public ArtifactDeployerRequestBuilder repository( RemoteRepository repository )
{
this.repository = repository;
return this;
}
public ArtifactDeployerRequestBuilder artifacts( Collection<Artifact> artifacts )
{
this.artifacts = artifacts;
return this;
}
public ArtifactDeployerRequestBuilder retryFailedDeploymentCount( int retryFailedDeploymentCount )
{
this.retryFailedDeploymentCount = retryFailedDeploymentCount;
return this;
}
@Nonnull
public ArtifactDeployerRequest build()
{
return new DefaultArtifactDeployerRequest( session, repository, artifacts, retryFailedDeploymentCount );
}
private static class DefaultArtifactDeployerRequest extends BaseRequest
implements ArtifactDeployerRequest
{
private final RemoteRepository repository;
private final Collection<Artifact> artifacts;
private final int retryFailedDeploymentCount;
DefaultArtifactDeployerRequest( @Nonnull Session session,
@Nonnull RemoteRepository repository,
@Nonnull Collection<Artifact> artifacts,
int retryFailedDeploymentCount )
{
super( session );
this.repository = nonNull( repository, "repository can not be null" );
this.artifacts = nonNull( artifacts, "artifacts can not be null" );
this.retryFailedDeploymentCount = retryFailedDeploymentCount;
}
@Nonnull
@Override
public RemoteRepository getRepository()
{
return repository;
}
@Nonnull
@Override
public Collection<Artifact> getArtifacts()
{
return artifacts;
}
@Override
public int getRetryFailedDeploymentCount()
{
return retryFailedDeploymentCount;
}
}
}
}

View File

@ -0,0 +1,61 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* Service used to create {@link Artifact} objects.
*
* @since 4.0
*/
@Experimental
public interface ArtifactFactory extends Service
{
/**
* Creates an artifact.
*
* @param request the request holding artifact creation parameters
* @return an {@code Artifact}, never {@code null}
* @throws IllegalArgumentException if {@code request} is null or {@code request.session} is null or invalid
*/
@Nonnull
Artifact create( @Nonnull ArtifactFactoryRequest request );
@Nonnull
default Artifact create( @Nonnull Session session, String groupId,
String artifactId, String version, String extension )
{
return create( ArtifactFactoryRequest.build( session, groupId, artifactId, version, extension ) );
}
@Nonnull
default Artifact create( @Nonnull Session session, String groupId, String artifactId, String version,
String classifier, String extension, String type )
{
return create( ArtifactFactoryRequest.build( session, groupId, artifactId,
version, classifier, extension, type ) );
}
}

View File

@ -0,0 +1,208 @@
package org.apache.maven.api.services;
/*
* 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.
*/
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.Session;
import org.apache.maven.api.annotations.NotThreadSafe;
/**
*
*
* @since 4.0
*/
@Experimental
@Immutable
public interface ArtifactFactoryRequest
{
@Nonnull
Session getSession();
String getGroupId();
String getArtifactId();
String getVersion();
String getClassifier();
String getExtension();
String getType();
static ArtifactFactoryRequest build( Session session, String groupId, String artifactId,
String version, String extension )
{
return ArtifactFactoryRequest.builder()
.session( session )
.groupId( groupId )
.artifactId( artifactId )
.version( version )
.extension( extension )
.build();
}
static ArtifactFactoryRequest build( Session session, String groupId, String artifactId,
String version, String classifier, String extension, String type )
{
return ArtifactFactoryRequest.builder()
.session( session )
.groupId( groupId )
.artifactId( artifactId )
.version( version )
.classifier( classifier )
.extension( extension )
.type( type )
.build();
}
static ArtifactFactoryRequestBuilder builder()
{
return new ArtifactFactoryRequestBuilder();
}
@NotThreadSafe
class ArtifactFactoryRequestBuilder
{
private Session session;
private String groupId;
private String artifactId;
private String version;
private String classifier;
private String extension;
private String type;
public ArtifactFactoryRequestBuilder session( Session session )
{
this.session = session;
return this;
}
public ArtifactFactoryRequestBuilder groupId( String groupId )
{
this.groupId = groupId;
return this;
}
public ArtifactFactoryRequestBuilder artifactId( String artifactId )
{
this.artifactId = artifactId;
return this;
}
public ArtifactFactoryRequestBuilder version( String version )
{
this.version = version;
return this;
}
public ArtifactFactoryRequestBuilder classifier( String classifier )
{
this.classifier = classifier;
return this;
}
public ArtifactFactoryRequestBuilder extension( String extension )
{
this.extension = extension;
return this;
}
public ArtifactFactoryRequestBuilder type( String type )
{
this.type = type;
return this;
}
public ArtifactFactoryRequest build()
{
return new DefaultArtifactFactoryRequest( session, groupId, artifactId, version,
classifier, extension, type );
}
private static class DefaultArtifactFactoryRequest extends BaseRequest implements ArtifactFactoryRequest
{
private final String groupId;
private final String artifactId;
private final String version;
private final String classifier;
private final String extension;
private final String type;
DefaultArtifactFactoryRequest( @Nonnull Session session,
String groupId,
String artifactId,
String version,
String classifier,
String extension,
String type )
{
super( session );
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.classifier = classifier;
this.extension = extension;
this.type = type;
}
@Override
public String getGroupId()
{
return groupId;
}
@Override
public String getArtifactId()
{
return artifactId;
}
@Override
public String getVersion()
{
return version;
}
@Override
public String getClassifier()
{
return classifier;
}
@Override
public String getExtension()
{
return extension;
}
@Override
public String getType()
{
return type;
}
}
}
}

View File

@ -0,0 +1,74 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.Collection;
import java.util.Collections;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.annotations.Experimental;
/**
* Installs {@link Artifact}s to the local repository.
*
* @since 4.0
* @see Session#withLocalRepository(org.apache.maven.api.LocalRepository)
*/
@Experimental
public interface ArtifactInstaller extends Service
{
/**
* @param request {@link ArtifactInstallerRequest}
* @throws ArtifactInstallerException in case of an error.
* @throws IllegalArgumentException in case {@code request} is {@code null}.
*/
void install( ArtifactInstallerRequest request );
/**
* @param session the repository session
* @param artifact the {@link Artifact} to install
* @throws ArtifactInstallerException In case of an error which can be the a given artifact can not be found or the
* installation has failed.
* @throws IllegalArgumentException in case of parameter {@code session} is {@code null} or
* {@code artifact} is {@code null}.
*/
default void install( Session session, Artifact artifact )
{
install( session, Collections.singletonList( artifact ) );
}
/**
* @param session the repository session
* @param artifacts Collection of {@link Artifact MavenArtifacts}
* @throws ArtifactInstallerException In case of an error which can be the a given artifact can not be found or the
* installation has failed.
* @throws IllegalArgumentException in case of parameter {@code request} is {@code null} or parameter
* {@code localRepository} is {@code null} or {@code localRepository} is not a directory
* or parameter {@code mavenArtifacts} is {@code null} or
* {@code mavenArtifacts.isEmpty()} is {@code true}.
*/
default void install( Session session, Collection<Artifact> artifacts )
{
install( ArtifactInstallerRequest.build( session, artifacts ) );
}
}

View File

@ -0,0 +1,46 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* @since 4.0
*/
@Experimental
public class ArtifactInstallerException
extends MavenException
{
/**
*
*/
private static final long serialVersionUID = 3652561971360586373L;
/**
* @param message The message of the error.
* @param e {@link Exception}
*/
public ArtifactInstallerException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,113 @@
package org.apache.maven.api.services;
/*
* 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.
*/
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.NotThreadSafe;
import org.apache.maven.api.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import org.apache.maven.api.Session;
import org.apache.maven.api.Artifact;
/**
* A request for installing one or more artifacts in the local repository.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface ArtifactInstallerRequest
{
@Nonnull
Session getSession();
@Nonnull
Collection<Artifact> getArtifacts();
@Nonnull
static ArtifactInstallerRequestBuilder builder()
{
return new ArtifactInstallerRequestBuilder();
}
@Nonnull
static ArtifactInstallerRequest build( Session session, Collection<Artifact> artifacts )
{
return builder()
.session( session )
.artifacts( artifacts )
.build();
}
@NotThreadSafe
class ArtifactInstallerRequestBuilder
{
Session session;
Collection<Artifact> artifacts = Collections.emptyList();
@Nonnull
public ArtifactInstallerRequestBuilder session( @Nonnull Session session )
{
this.session = session;
return this;
}
@Nonnull
public ArtifactInstallerRequestBuilder artifacts( @Nullable Collection<Artifact> artifacts )
{
this.artifacts = artifacts != null ? artifacts : Collections.emptyList();
return this;
}
@Nonnull
public ArtifactInstallerRequest build()
{
return new DefaultArtifactInstallerRequest( session, artifacts );
}
static class DefaultArtifactInstallerRequest extends BaseRequest
implements ArtifactInstallerRequest
{
private final Collection<Artifact> artifacts;
DefaultArtifactInstallerRequest( @Nonnull Session session,
@Nonnull Collection<Artifact> artifacts )
{
super( session );
this.artifacts = nonNull( artifacts, "artifacts can not be null" );
}
@Nonnull
@Override
public Collection<Artifact> getArtifacts()
{
return artifacts;
}
}
}
}

View File

@ -0,0 +1,64 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.Metadata;
/**
*
* @since 4.0
*/
@Experimental
public interface ArtifactManager extends Service
{
/**
* Returns the path of the file previously associated to this artifact
* or {@code Optional.empty()} if no path has been associated.
*/
@Nonnull
Optional<Path> getPath( @Nonnull Artifact artifact );
/**
* Associates the given file path to the artifact.
*/
void setPath( @Nonnull Artifact artifact, Path path );
/**
* TODO: investigate removing the Metadata api completely
*/
@Nonnull
Collection<Metadata> getAttachedMetadatas( @Nonnull Artifact artifact );
/**
* TODO: investigate removing the Metadata api completely
*/
void attachMetadata( @Nonnull Artifact artifact, @Nonnull Metadata metadata );
}

View File

@ -0,0 +1,61 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.Collection;
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
/**
* Resolves the artifact, i.e download the file when required and attach it to the artifact
*
* @since 4.0
*/
@Experimental
public interface ArtifactResolver extends Service
{
/**
* @param request {@link ArtifactResolverRequest}
* @return {@link ArtifactResolverResult}
* @throws ArtifactResolverException in case of an error.
* @throws IllegalArgumentException in case of parameter {@code buildingRequest} is {@code null} or
* parameter {@code mavenArtifact} is {@code null} or invalid.
*/
ArtifactResolverResult resolve( ArtifactResolverRequest request );
/**
* @param session {@link Session}
* @param coordinates array of {@link ArtifactCoordinate}
* @return {@link ArtifactResolverResult}
* @throws ArtifactResolverException in case of an error.
* @throws IllegalArgumentException in case of parameter {@code buildingRequest} is {@code null} or
* parameter {@code coordinate} is {@code null} or invalid.
*/
default ArtifactResolverResult resolve( Session session,
Collection<? extends ArtifactCoordinate> coordinates )
{
return resolve( ArtifactResolverRequest.build( session, coordinates ) );
}
}

View File

@ -0,0 +1,45 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
*
*
* @since 4.0
*/
@Experimental
public class ArtifactResolverException
extends MavenException
{
private static final long serialVersionUID = 7252294837746943917L;
/**
* @param message The message for the exception.
* @param e The exception itself.
*/
public ArtifactResolverException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,108 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.Collection;
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Session;
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.NotThreadSafe;
/**
* A request for resolving an artifact.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface ArtifactResolverRequest
{
@Nonnull
Session getSession();
@Nonnull
Collection<? extends ArtifactCoordinate> getCoordinates();
@Nonnull
static ArtifactResolverRequestBuilder builder()
{
return new ArtifactResolverRequestBuilder();
}
@Nonnull
static ArtifactResolverRequest build( Session session, Collection<? extends ArtifactCoordinate> coordinates )
{
return builder()
.session( session )
.coordinates( coordinates )
.build();
}
@NotThreadSafe
class ArtifactResolverRequestBuilder
{
Session session;
Collection<? extends ArtifactCoordinate> coordinates;
@Nonnull
public ArtifactResolverRequestBuilder session( Session session )
{
this.session = session;
return this;
}
@Nonnull
public ArtifactResolverRequestBuilder coordinates( Collection<? extends ArtifactCoordinate> coordinates )
{
this.coordinates = coordinates;
return this;
}
@Nonnull
public ArtifactResolverRequest build()
{
return new DefaultArtifactResolverRequest( session, coordinates );
}
private static class DefaultArtifactResolverRequest extends BaseRequest implements ArtifactResolverRequest
{
@Nonnull
private final Collection<? extends ArtifactCoordinate> coordinates;
DefaultArtifactResolverRequest( @Nonnull Session session,
@Nonnull Collection<? extends ArtifactCoordinate> coordinates )
{
super( session );
this.coordinates = nonNull( coordinates, "coordinates can not be null" );
}
@Nonnull
@Override
public Collection<? extends ArtifactCoordinate> getCoordinates()
{
return coordinates;
}
}
}
}

View File

@ -0,0 +1,43 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.nio.file.Path;
import java.util.Map;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* The Artifact Result
*
* @since 4.0
*/
@Experimental
public interface ArtifactResolverResult
{
/**
* @return {@link Artifact}
*/
@Nonnull
Map<Artifact, Path> getArtifacts();
}

View File

@ -0,0 +1,67 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.apache.maven.api.Session;
/**
* Base class for requests.
*
* @since 4.0
*/
@Experimental
abstract class BaseRequest
{
private final Session session;
protected BaseRequest( @Nonnull Session session )
{
this.session = nonNull( session, "session can not be null" );
}
@Nonnull
public Session getSession()
{
return session;
}
public static <T> T nonNull( T obj, String message )
{
if ( obj == null )
{
throw new IllegalArgumentException( message );
}
return obj;
}
protected static <T> Collection<T> unmodifiable( Collection<T> obj )
{
return obj != null && !obj.isEmpty()
? Collections.unmodifiableCollection( new ArrayList<>( obj ) ) : Collections.emptyList();
}
}

View File

@ -0,0 +1,117 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.Session;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.DependencyCoordinate;
import org.apache.maven.api.Project;
/**
* The DependencyCollector service can be used to collect dependencies
* for a given artifact and builds a graph of them.
* The dependencies collection mechanism will not download any artifacts,
* and only the pom files will be downloaded.
*
* @since 4.0
*/
@Experimental
public interface DependencyCollector extends Service
{
/**
* Collects the transitive dependencies and builds a dependency graph.
* Note that this operation is only concerned about determining the coordinates of the
* transitive dependencies and does not actually resolve the artifact files.
*
* @param request The dependency collection request, must not be {@code null}.
* @return The collection result, never {@code null}.
* @throws DependencyCollectorException If the dependency tree could not be built.
* @throws IllegalArgumentException if an argument is null or invalid
*
* @see DependencyCollector#collect(Session, Project)
* @see DependencyCollector#collect(Session, DependencyCoordinate)
* @see DependencyCollector#collect(Session, Artifact)
*/
@Nonnull
DependencyCollectorResult collect( @Nonnull DependencyCollectorRequest request );
/**
* Collects the transitive dependencies of some artifacts and builds a dependency graph. Note that this operation is
* only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the
* artifact files.
*
* @param session The {@link Session}, must not be {@code null}.
* @param root The Maven Dependency, must not be {@code null}.
* @return The collection result, never {@code null}.
* @throws DependencyCollectorException If the dependency tree could not be built.
* @throws IllegalArgumentException if an argument is null or invalid
* @see #collect(DependencyCollectorRequest)
*/
@Nonnull
default DependencyCollectorResult collect( @Nonnull Session session,
@Nonnull DependencyCoordinate root )
{
return collect( DependencyCollectorRequest.build( session, root ) );
}
/**
* Collects the transitive dependencies of some artifacts and builds a dependency graph. Note that this operation is
* only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the
* artifact files.
*
* @param session The {@link Session}, must not be {@code null}.
* @param project The {@link Project}, must not be {@code null}.
* @return The collection result, never {@code null}.
* @throws DependencyCollectorException If the dependency tree could not be built.
* @throws IllegalArgumentException if an argument is null or invalid
* @see #collect(DependencyCollectorRequest)
*/
@Nonnull
default DependencyCollectorResult collect( @Nonnull Session session,
@Nonnull Project project )
{
return collect( DependencyCollectorRequest.build( session, project ) );
}
/**
* Collects the transitive dependencies of some artifacts and builds a dependency graph. Note that this operation is
* only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the
* artifact files.
*
* @param session The {@link Session}, must not be {@code null}.
* @param artifact The {@link Artifact}, must not be {@code null}.
* @return The collection result, never {@code null}.
* @throws DependencyCollectorException If the dependency tree could not be built.
* @throws IllegalArgumentException if an argument is null or invalid
* @see #collect(DependencyCollectorRequest)
*/
@Nonnull
default DependencyCollectorResult collect( @Nonnull Session session,
@Nonnull Artifact artifact )
{
return collect( DependencyCollectorRequest.build( session, artifact ) );
}
}

View File

@ -0,0 +1,47 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* Thrown in case of bad artifact descriptors, version ranges or other
* issues encountered during calculation of the dependency graph.
*
* @since 4.0
*/
@Experimental
public class DependencyCollectorException
extends MavenException
{
/**
*
*/
private static final long serialVersionUID = -3134726259840210686L;
/**
* @param message The message you would give for the exception.
* @param cause The cause which is related to the message.
*/
public DependencyCollectorException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -0,0 +1,331 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.DependencyCoordinate;
import org.apache.maven.api.Project;
import org.apache.maven.api.Session;
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.NotThreadSafe;
import org.apache.maven.api.annotations.Nullable;
import static org.apache.maven.api.services.BaseRequest.nonNull;
/**
* A request to collect the transitive dependencies and to build a dependency graph from them. There are three ways to
* create a dependency graph. First, only the root dependency can be given. Second, a root dependency and direct
* dependencies can be specified in which case the specified direct dependencies are merged with the direct dependencies
* retrieved from the artifact descriptor of the root dependency. And last, only direct dependencies can be specified in
* which case the root node of the resulting graph has no associated dependency.
*
* @since 4.0
* @see DependencyCollector#collect(DependencyCollectorRequest)
*/
@Experimental
@Immutable
public interface DependencyCollectorRequest
{
@Nonnull
Session getSession();
@Nonnull
Optional<Artifact> getRootArtifact();
@Nonnull
Optional<DependencyCoordinate> getRoot();
@Nonnull
Collection<DependencyCoordinate> getDependencies();
@Nonnull
Collection<DependencyCoordinate> getManagedDependencies();
boolean getVerbose();
@Nonnull
static DependencyCollectorRequest build( @Nonnull Session session, Artifact root )
{
return builder()
.session( nonNull( session, "session can not be null" ) )
.rootArtifact( nonNull( root, "root can not be null" ) )
.build();
}
@Nonnull
static DependencyCollectorRequest build( @Nonnull Session session, @Nonnull DependencyCoordinate root )
{
return builder()
.session( nonNull( session, "session can not be null" ) )
.root( nonNull( root, "root can not be null" ) )
.build();
}
@Nonnull
static DependencyCollectorRequest build( @Nonnull Session session, @Nonnull Project project )
{
nonNull( session, "session can not be null" );
nonNull( project, "project can not be null" );
return builder()
.session( session )
.rootArtifact( project.getArtifact() )
.dependencies( project.getDependencies() )
.managedDependencies( project.getManagedDependencies() )
.build();
}
@Nonnull
static DependencyCollectorRequestBuilder builder()
{
return new DependencyCollectorRequestBuilder();
}
@NotThreadSafe
class DependencyCollectorRequestBuilder
{
Session session;
Artifact rootArtifact;
DependencyCoordinate root;
List<DependencyCoordinate> dependencies = Collections.emptyList();
List<DependencyCoordinate> managedDependencies = Collections.emptyList();
boolean verbose;
@Nonnull
public DependencyCollectorRequestBuilder session( @Nonnull Session session )
{
this.session = session;
return this;
}
/**
* Sets the root artifact for the dependency graph.
* This must not be confused with {@link #root(DependencyCoordinate)}: The root <em>dependency</em>, like any
* other specified dependency, will be subject to dependency collection/resolution, i.e. should have an artifact
* descriptor and a corresponding artifact file. The root <em>artifact</em> on the other hand is only used
* as a label for the root node of the graph in case no root dependency was specified. As such, the configured
* root artifact is ignored if {@link #root(DependencyCoordinate)} has been set.
*
* @param rootArtifact The root artifact for the dependency graph, may be {@code null}.
* @return This request for chaining, never {@code null}.
*/
@Nonnull
public DependencyCollectorRequestBuilder rootArtifact( @Nullable Artifact rootArtifact )
{
this.rootArtifact = rootArtifact;
return this;
}
/**
* @param root The root dependency
* @return This request for chaining, never {@code null}.
*/
@Nonnull
public DependencyCollectorRequestBuilder root( @Nonnull DependencyCoordinate root )
{
this.root = root;
return this;
}
/**
* Sets the direct dependencies. If both a root dependency and direct dependencies are given in the request, the
* direct dependencies from the request will be merged with the direct dependencies from the root dependency's
* artifact descriptor, giving higher priority to the dependencies from the request.
*
* @param dependencies The direct dependencies, may be {@code null}.
* @return This request for chaining, never {@code null}.
*/
@Nonnull
public DependencyCollectorRequestBuilder dependencies( @Nullable List<DependencyCoordinate> dependencies )
{
this.dependencies = ( dependencies != null ) ? dependencies : Collections.emptyList();
return this;
}
/**
* Adds the specified direct dependency.
*
* @param dependency The dependency to add, may be {@code null}.
* @return This request for chaining, never {@code null}.
*/
@Nonnull
public DependencyCollectorRequestBuilder dependency( @Nullable DependencyCoordinate dependency )
{
if ( dependency != null )
{
if ( this.dependencies.isEmpty() )
{
this.dependencies = new ArrayList<>();
}
this.dependencies.add( dependency );
}
return this;
}
/**
* Sets the dependency management to apply to transitive dependencies. To clarify, this management does not
* apply to
* the direct dependencies of the root node.
*
* @param managedDependencies The dependency management, may be {@code null}.
* @return This request for chaining, never {@code null}.
*/
@Nonnull
public DependencyCollectorRequestBuilder managedDependencies(
@Nullable List<DependencyCoordinate> managedDependencies )
{
this.managedDependencies = ( managedDependencies != null ) ? managedDependencies : Collections.emptyList();
return this;
}
/**
* Adds the specified managed dependency.
*
* @param managedDependency The managed dependency to add, may be {@code null} in which case the call
* will have no effect.
* @return This request for chaining, never {@code null}.
*/
@Nonnull
public DependencyCollectorRequestBuilder managedDependency( @Nullable DependencyCoordinate managedDependency )
{
if ( managedDependency != null )
{
if ( this.managedDependencies.isEmpty() )
{
this.managedDependencies = new ArrayList<>();
}
this.managedDependencies.add( managedDependency );
}
return this;
}
/**
* Specifies that the collection should be verbose.
*
* @param verbose whether the collection should be verbose or not.
* @return This request for chaining, never {@code null}.
*/
@Nonnull
public DependencyCollectorRequestBuilder verbose( boolean verbose )
{
this.verbose = verbose;
return this;
}
@Nonnull
public DependencyCollectorRequest build()
{
return new DefaultDependencyCollectorRequest(
session,
rootArtifact,
root,
dependencies,
managedDependencies,
verbose );
}
static class DefaultDependencyCollectorRequest extends BaseRequest
implements DependencyCollectorRequest
{
private final Artifact rootArtifact;
private final DependencyCoordinate root;
private final Collection<DependencyCoordinate> dependencies;
private final Collection<DependencyCoordinate> managedDependencies;
private final boolean verbose;
/**
* Creates a request with the specified properties.
*
* @param session {@link Session}
* @param rootArtifact The root dependency whose transitive dependencies should be collected, may be {@code
* null}.
*/
DefaultDependencyCollectorRequest(
@Nonnull Session session,
@Nullable Artifact rootArtifact,
@Nullable DependencyCoordinate root,
@Nonnull Collection<DependencyCoordinate> dependencies,
@Nonnull Collection<DependencyCoordinate> managedDependencies,
boolean verbose )
{
super( session );
this.rootArtifact = rootArtifact;
this.root = root;
this.dependencies = unmodifiable( dependencies );
this.managedDependencies = unmodifiable( managedDependencies );
this.verbose = verbose;
}
@Nonnull
@Override
public Optional<Artifact> getRootArtifact()
{
return Optional.ofNullable( rootArtifact );
}
@Nonnull
@Override
public Optional<DependencyCoordinate> getRoot()
{
return Optional.ofNullable( root );
}
@Nonnull
@Override
public Collection<DependencyCoordinate> getDependencies()
{
return dependencies;
}
@Nonnull
@Override
public Collection<DependencyCoordinate> getManagedDependencies()
{
return managedDependencies;
}
@Override
public boolean getVerbose()
{
return verbose;
}
@Nonnull
@Override
public String toString()
{
return getRoot() + " -> " + getDependencies();
}
}
}
}

View File

@ -0,0 +1,50 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.List;
import org.apache.maven.api.Node;
import org.apache.maven.api.annotations.Experimental;
/**
* The result of a dependency collection request.
*
* @since 4.0
* @see DependencyCollector#collect(DependencyCollectorRequest)
*/
@Experimental
public interface DependencyCollectorResult
{
/**
* Gets the exceptions that occurred while building the dependency graph.
*
* @return The exceptions that occurred, never {@code null}.
*/
List<Exception> getExceptions();
/**
* Gets the root node of the dependency graph.
*
* @return The root node of the dependency graph or {@code null} if none.
*/
Node getRoot();
}

View File

@ -0,0 +1,89 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.DependencyCoordinate;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.model.Dependency;
import org.apache.maven.api.model.Plugin;
import org.apache.maven.api.model.ReportPlugin;
/**
*
* @since 4.0
*/
@Experimental
public interface DependencyCoordinateFactory extends Service
{
/**
* Creates a new {@link DependencyCoordinate} object from the request.
*
* @param request the request containing the various data
* @return a new {@link DependencyCoordinate} object.
*
* @throws IllegalArgumentException if {@code request} is null or
* if {@code request.getSession()} is null or invalid
*/
@Nonnull
DependencyCoordinate create( @Nonnull DependencyCoordinateFactoryRequest request );
@Nonnull
default DependencyCoordinate create( @Nonnull Session session, @Nonnull ArtifactCoordinate coordinate )
{
return create( DependencyCoordinateFactoryRequest.build( session, coordinate ) );
}
@Nonnull
default DependencyCoordinate create( @Nonnull Session session, @Nonnull org.apache.maven.api.Dependency dependency )
{
return create( DependencyCoordinateFactoryRequest.build( session, dependency ) );
}
@Nonnull
default DependencyCoordinate create( @Nonnull Session session, Dependency dependency )
{
return create( DependencyCoordinateFactoryRequest.build( session,
dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(),
dependency.getClassifier(), null, dependency.getType() ) );
}
@Nonnull
default DependencyCoordinate create( @Nonnull Session session, Plugin plugin )
{
// TODO: hard coded string
return create( DependencyCoordinateFactoryRequest.build( session,
plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(),
null, null, "maven-plugin" ) );
}
@Nonnull
default DependencyCoordinate create( @Nonnull Session session, ReportPlugin reportPlugin )
{
// TODO: hard coded string
return create( DependencyCoordinateFactoryRequest.build( session,
reportPlugin.getGroupId(), reportPlugin.getArtifactId(), reportPlugin.getVersion(),
null, null, "maven-plugin" ) );
}
}

View File

@ -0,0 +1,292 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Dependency;
import org.apache.maven.api.Exclusion;
import org.apache.maven.api.Session;
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.NotThreadSafe;
/**
*
* @since 4.0
*/
@Experimental
@Immutable
public interface DependencyCoordinateFactoryRequest extends ArtifactCoordinateFactoryRequest
{
String getScope();
boolean isOptional();
@Nonnull
Collection<Exclusion> getExclusions();
static DependencyCoordinateFactoryRequest build( Session session, String groupId, String artifactId,
String version, String classifier, String extension, String type )
{
return DependencyCoordinateFactoryRequest.builder()
.session( session )
.groupId( groupId )
.artifactId( artifactId )
.version( version )
.classifier( classifier )
.extension( extension )
.type( type )
.build();
}
static DependencyCoordinateFactoryRequest build( Session session, ArtifactCoordinate coordinate )
{
return builder()
.session( session )
.groupId( coordinate.getGroupId() )
.artifactId( coordinate.getArtifactId() )
.version( coordinate.getVersion().asString() )
.classifier( coordinate.getClassifier() )
.extension( coordinate.getExtension() )
.build();
}
static DependencyCoordinateFactoryRequest build( Session session, Dependency dependency )
{
return builder()
.session( session )
.groupId( dependency.getGroupId() )
.artifactId( dependency.getArtifactId() )
.version( dependency.getVersion().asString() )
.classifier( dependency.getClassifier() )
.extension( dependency.getExtension() )
.type( dependency.getType().getName() )
.scope( dependency.getScope().id() )
.optional( dependency.isOptional() )
.build();
}
static DependencyCoordinateFactoryRequestBuilder builder()
{
return new DependencyCoordinateFactoryRequestBuilder();
}
@NotThreadSafe
class DependencyCoordinateFactoryRequestBuilder
{
private Session session;
private String groupId;
private String artifactId;
private String version;
private String classifier;
private String extension;
private String type;
private String scope;
private boolean optional;
private Collection<Exclusion> exclusions = Collections.emptyList();
public DependencyCoordinateFactoryRequestBuilder session( Session session )
{
this.session = session;
return this;
}
public DependencyCoordinateFactoryRequestBuilder groupId( String groupId )
{
this.groupId = groupId;
return this;
}
public DependencyCoordinateFactoryRequestBuilder artifactId( String artifactId )
{
this.artifactId = artifactId;
return this;
}
public DependencyCoordinateFactoryRequestBuilder version( String version )
{
this.version = version;
return this;
}
public DependencyCoordinateFactoryRequestBuilder classifier( String classifier )
{
this.classifier = classifier;
return this;
}
public DependencyCoordinateFactoryRequestBuilder extension( String extension )
{
this.extension = extension;
return this;
}
public DependencyCoordinateFactoryRequestBuilder type( String type )
{
this.type = type;
return this;
}
public DependencyCoordinateFactoryRequestBuilder scope( String scope )
{
this.scope = scope;
return this;
}
public DependencyCoordinateFactoryRequestBuilder optional( boolean optional )
{
this.optional = optional;
return this;
}
public DependencyCoordinateFactoryRequestBuilder exclusions( Collection<Exclusion> exclusions )
{
if ( exclusions != null )
{
if ( this.exclusions.isEmpty() )
{
this.exclusions = new ArrayList<>();
}
this.exclusions.addAll( exclusions );
}
return this;
}
public DependencyCoordinateFactoryRequestBuilder exclusion( Exclusion exclusion )
{
if ( exclusion != null )
{
if ( this.exclusions.isEmpty() )
{
this.exclusions = new ArrayList<>();
}
this.exclusions.add( exclusion );
}
return this;
}
public DependencyCoordinateFactoryRequest build()
{
return new DefaultDependencyCoordinateFactoryRequest( session, groupId, artifactId, version,
classifier, extension, type, scope, optional, exclusions );
}
private static class DefaultDependencyCoordinateFactoryRequest
extends BaseRequest
implements DependencyCoordinateFactoryRequest
{
private final String groupId;
private final String artifactId;
private final String version;
private final String classifier;
private final String extension;
private final String type;
private final String scope;
private final boolean optional;
private final Collection<Exclusion> exclusions;
@SuppressWarnings( "checkstyle:ParameterNumber" )
private DefaultDependencyCoordinateFactoryRequest(
@Nonnull Session session, String groupId,
String artifactId,
String version,
String classifier,
String extension,
String type,
String scope,
boolean optional,
Collection<Exclusion> exclusions )
{
super( session );
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.classifier = classifier;
this.extension = extension;
this.type = type;
this.scope = scope;
this.optional = optional;
this.exclusions = exclusions;
}
@Override
public String getGroupId()
{
return groupId;
}
@Override
public String getArtifactId()
{
return artifactId;
}
@Override
public String getVersion()
{
return version;
}
@Override
public String getClassifier()
{
return classifier;
}
@Override
public String getExtension()
{
return extension;
}
@Override
public String getType()
{
return type;
}
@Override
public String getScope()
{
return scope;
}
@Override
public boolean isOptional()
{
return optional;
}
@Nonnull
@Override
public Collection<Exclusion> getExclusions()
{
return exclusions;
}
}
}
}

View File

@ -0,0 +1,48 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.nio.file.Path;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.LocalRepository;
import org.apache.maven.api.Metadata;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
/**
*
* @since 4.0
*/
@Experimental
public interface LocalRepositoryManager extends Service
{
Path getPathForLocalArtifact( Session session, LocalRepository local, Artifact artifact );
Path getPathForLocalMetadata( Session session, LocalRepository local, Metadata metadata );
Path getPathForRemoteArtifact( Session session, LocalRepository local, RemoteRepository remote, Artifact artifact );
Path getPathForRemoteMetadata( Session session, LocalRepository local, RemoteRepository remote, Metadata metadata );
}

View File

@ -0,0 +1,38 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.List;
import java.util.Map;
import org.apache.maven.api.Service;
public interface Lookup extends Service
{
<T> T lookup( Class<T> type );
<T> T lookup( Class<T> type, String name );
<T> List<T> lookupList( Class<T> type );
<T> Map<String, T> lookupMap( Class<T> type );
}

View File

@ -0,0 +1,50 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* The Exception class throw by the {@link Lookup} service.
*
* @since 4.0
*/
@Experimental
public class LookupException
extends MavenException
{
/**
* @param message The message to give.
* @param e The {@link Exception}.
*/
public LookupException( String message, Exception e )
{
super( message, e );
}
/**
* @param e The {@link Exception}.
*/
public LookupException( Exception e )
{
super( e );
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.settings; package org.apache.maven.api.services;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
@ -19,37 +19,33 @@ package org.apache.maven.settings;
* under the License. * under the License.
*/ */
import java.io.File; import org.apache.maven.api.annotations.Experimental;
/** /**
* To handle runtime information like local repository or profiles. * Base class for all maven exceptions.
* *
* @since 4.0
*/ */
@Deprecated @Experimental
public class RuntimeInfo public class MavenException extends RuntimeException
{ {
@SuppressWarnings( "checkstyle:constantname" ) public MavenException()
public static final String userHome = System.getProperty( "user.home" );
@SuppressWarnings( "checkstyle:constantname" )
public static final File userMavenConfigurationHome = new File( userHome, ".m2" );
public static final File DEFAULT_USER_SETTINGS_FILE = new File( userMavenConfigurationHome, "settings.xml" );
private File settings;
public RuntimeInfo()
{ {
this.settings = DEFAULT_USER_SETTINGS_FILE;
} }
public RuntimeInfo( File settings ) public MavenException( String message )
{ {
this.settings = settings; super( message );
} }
public File getFile() public MavenException( String message, Throwable cause )
{ {
return settings; super( message, cause );
} }
public MavenException( Throwable cause )
{
super( cause );
}
} }

View File

@ -0,0 +1,157 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Nonnull;
/**
* Message builder that supports configurable styling.
*
* @since 4.0
* @see MessageBuilderFactory
*/
public interface MessageBuilder
{
/**
* Append message content in success style.
* By default, bold green
* @param message the message to append
* @return the current builder
*/
@Nonnull
MessageBuilder success( Object message );
/**
* Append message content in warning style.
* By default, bold yellow
* @param message the message to append
* @return the current builder
*/
@Nonnull
MessageBuilder warning( Object message );
/**
* Append message content in failure style.
* By default, bold red
* @param message the message to append
* @return the current builder
*/
@Nonnull
MessageBuilder failure( Object message );
/**
* Append message content in strong style.
* By default, bold
* @param message the message to append
* @return the current builder
*/
@Nonnull
MessageBuilder strong( Object message );
/**
* Append message content in mojo style.
* By default, green
* @param message the message to append
* @return the current builder
*/
@Nonnull
MessageBuilder mojo( Object message );
/**
* Append message content in project style.
* By default, cyan
* @param message the message to append
* @return the current builder
*/
@Nonnull
MessageBuilder project( Object message );
//
// message building methods modelled after Ansi methods
//
/**
* Append content to the message buffer.
* @param value the content to append
* @param offset the index of the first {@code char} to append
* @param len the number of {@code char}s to append
* @return the current builder
*/
@Nonnull
MessageBuilder a( char[] value, int offset, int len );
/**
* Append content to the message buffer.
* @param value the content to append
* @return the current builder
*/
@Nonnull
MessageBuilder a( char[] value );
/**
* Append content to the message buffer.
* @param value the content to append
* @param start the starting index of the subsequence to be appended
* @param end the end index of the subsequence to be appended
* @return the current builder
*/
@Nonnull
MessageBuilder a( CharSequence value, int start, int end );
/**
* Append content to the message buffer.
* @param value the content to append
* @return the current builder
*/
@Nonnull
MessageBuilder a( CharSequence value );
/**
* Append content to the message buffer.
* @param value the content to append
* @return the current builder
*/
@Nonnull
MessageBuilder a( Object value );
/**
* Append newline to the message buffer.
* @return the current builder
*/
@Nonnull
MessageBuilder newline();
/**
* Append formatted content to the buffer.
* @see String#format(String, Object...)
* @param pattern a <a href="../util/Formatter.html#syntax">format string</a>
* @param args arguments referenced by the format specifiers in the format string.
* @return the current builder
*/
@Nonnull
MessageBuilder format( String pattern, Object... args );
/**
* Return the built message.
* @return the message
*/
@Nonnull
String build();
}

View File

@ -0,0 +1,71 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* A factory for {@link MessageBuilder}.
*
* @since 4.0
*/
@Experimental
public interface MessageBuilderFactory extends Service
{
/**
* Checks if the underlying output does support styling or not.
* @return whether color styling is supported or not
*/
boolean isColorEnabled();
/**
* Returns the terminal width or <code>-1</code> if not supported.
* @return the terminal width
*/
int getTerminalWidth();
/**
* Creates a new message builder.
* @return a new message builder
*/
@Nonnull
MessageBuilder builder();
/**
* Creates a new message builder backed by the given string builder.
* @param stringBuilder a string builder
* @return a new message builder
*/
@Nonnull
MessageBuilder builder( @Nonnull StringBuilder stringBuilder );
/**
* Creates a new message builder of the specified size.
* @param size the initial size of the message builder buffer
* @return a new message builder
*/
@Nonnull
default MessageBuilder builder( int size )
{
return builder( new StringBuilder( size ) );
}
}

View File

@ -0,0 +1,110 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import java.nio.file.Path;
import org.apache.maven.api.Session;
import org.apache.maven.api.Artifact;
/**
* @since 4.0
*/
@Experimental
public interface ProjectBuilder extends Service
{
/**
* Creates a {@link org.apache.maven.api.Project} from a POM file.
*
* @param request {@link ProjectBuilderRequest}
* @return the {@link ProjectBuilderResult} containing the built project and possible errors
* @throws ProjectBuilderException if the project can not be created
* @throws IllegalArgumentException if an argument is {@code null} or invalid
*/
@Nonnull
ProjectBuilderResult build( ProjectBuilderRequest request );
/**
* Creates a {@link org.apache.maven.api.Project} from a POM file.
*
* @param session The {@link Session}, must not be {@code null}.
* @param source The {@link ProjectBuilderSource}, must not be {@code null}.
* @throws ProjectBuilderException if the project can not be created
* @throws IllegalArgumentException if an argument is {@code null} or invalid
* @see #build(ProjectBuilderRequest)
*/
@Nonnull
default ProjectBuilderResult build( @Nonnull Session session, @Nonnull ProjectBuilderSource source )
{
return build( ProjectBuilderRequest.build( session, source ) );
}
/**
* Creates a {@link org.apache.maven.api.Project} from a POM file.
*
* @param session The {@link Session}, must not be {@code null}.
* @param path The {@link Path}, must not be {@code null}.
* @throws ProjectBuilderException if the project can not be created
* @throws IllegalArgumentException if an argument is {@code null} or invalid
* @see #build(ProjectBuilderRequest)
*/
@Nonnull
default ProjectBuilderResult build( @Nonnull Session session, @Nonnull Path path )
{
return build( ProjectBuilderRequest.build( session, path ) );
}
/**
* Creates a {@link org.apache.maven.api.Project} from an artifact.
*
* @param session The {@link Session}, must not be {@code null}.
* @param artifact The {@link Artifact}, must not be {@code null}.
* @throws ProjectBuilderException if the project can not be created
* @throws IllegalArgumentException if an argument is {@code null} or invalid
* @see #build(ProjectBuilderRequest)
*/
@Nonnull
default ProjectBuilderResult build( @Nonnull Session session, @Nonnull Artifact artifact )
{
return build( ProjectBuilderRequest.build( session, artifact ) );
}
/**
* Creates a {@link org.apache.maven.api.Project} from a coordinate.
*
* @param session The {@link Session}, must not be {@code null}.
* @param coordinate The {@link ArtifactCoordinate}, must not be {@code null}.
* @throws ProjectBuilderException if the project can not be created
* @throws IllegalArgumentException if an argument is {@code null} or invalid
* @see #build(ProjectBuilderRequest)
*/
@Nonnull
default ProjectBuilderResult build( @Nonnull Session session, @Nonnull ArtifactCoordinate coordinate )
{
return build( ProjectBuilderRequest.build( session, coordinate ) );
}
}

View File

@ -0,0 +1,42 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* The Exception class throw by the {@link ProjectBuilder} service.
*
* @since 4.0
*/
@Experimental
public class ProjectBuilderException
extends MavenException
{
/**
* @param message The message to give.
* @param e The {@link Exception}.
*/
public ProjectBuilderException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,90 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* Describes a problem that was encountered during project building. A problem can either be an exception that was
* thrown or a simple string message. In addition, a problem carries a hint about its source.
*
* @since 4.0
*/
@Experimental
public interface ProjectBuilderProblem
{
/**
* Gets the hint about the source of the problem. While the syntax of this hint is unspecified and depends on the
* creator of the problem, the general expectation is that the hint provides sufficient information to the user to
* track the problem back to its origin. A concrete example for such a source hint can be the file path or URL from
* which the settings were read.
*
* @return The hint about the source of the problem or an empty string if unknown, never {@code null}.
*/
String getSource();
/**
* Gets the one-based index of the line containing the problem. The line number should refer to some text file that
* is given by {@link #getSource()}.
*
* @return The one-based index of the line containing the problem or a non-positive value if unknown.
*/
int getLineNumber();
/**
* Gets the one-based index of the column containing the problem. The column number should refer to some text file
* that is given by {@link #getSource()}.
*
* @return The one-based index of the column containing the problem or non-positive value if unknown.
*/
int getColumnNumber();
/**
* Gets the location of the problem. The location is a user-friendly combination of the values from
* {@link #getSource()}, {@link #getLineNumber()} and {@link #getColumnNumber()}. The exact syntax of the returned
* value is undefined.
*
* @return The location of the problem, never {@code null}.
*/
String getLocation();
/**
* Gets the exception that caused this problem (if any).
*
* @return The exception that caused this problem or {@code null} if not applicable.
*/
Exception getException();
/**
* Gets the message that describes this problem.
*
* @return The message describing this problem, never {@code null}.
*/
String getMessage();
/**
* Gets the severity level of this problem.
*
* @return The severity level of this problem, never {@code null}.
*/
ProjectBuilderProblemSeverity getSeverity();
}

View File

@ -0,0 +1,37 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* The different severity levels for a problem, in decreasing order.
*
* @since 4.0
*/
@Experimental
public enum ProjectBuilderProblemSeverity
{
FATAL, //
ERROR, //
WARNING //
}

View File

@ -0,0 +1,262 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.ArtifactCoordinate;
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.NotThreadSafe;
import org.apache.maven.api.annotations.Nullable;
import java.nio.file.Path;
import java.util.Optional;
import org.apache.maven.api.Session;
import org.apache.maven.api.Artifact;
import static org.apache.maven.api.services.BaseRequest.nonNull;
/**
* Request used to build a {@link org.apache.maven.api.Project} using
* the {@link ProjectBuilder} service.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface ProjectBuilderRequest
{
@Nonnull
Session getSession();
@Nonnull
Optional<Path> getPath();
@Nonnull
Optional<ProjectBuilderSource> getSource();
@Nonnull
Optional<Artifact> getArtifact();
@Nonnull
Optional<ArtifactCoordinate> getCoordinate();
boolean isAllowStubModel();
boolean isRecursive();
boolean isProcessPlugins();
boolean isResolveDependencies();
@Nonnull
static ProjectBuilderRequest build( @Nonnull Session session, @Nonnull ProjectBuilderSource source )
{
return builder()
.session( nonNull( session, "session can not be null" ) )
.source( nonNull( source, "source can not be null" ) )
.build();
}
@Nonnull
static ProjectBuilderRequest build( @Nonnull Session session, @Nonnull Path path )
{
return builder()
.session( nonNull( session, "session can not be null" ) )
.path( nonNull( path, "path can not be null" ) )
.build();
}
@Nonnull
static ProjectBuilderRequest build( @Nonnull Session session, @Nonnull Artifact artifact )
{
return builder()
.session( nonNull( session, "session can not be null" ) )
.artifact( nonNull( artifact, "artifact can not be null" ) )
.build();
}
@Nonnull
static ProjectBuilderRequest build( @Nonnull Session session, @Nonnull ArtifactCoordinate coordinate )
{
return builder()
.session( nonNull( session, "session can not be null" ) )
.coordinate( nonNull( coordinate, "coordinate can not be null" ) )
.build();
}
@Nonnull
static ProjectBuilderRequestBuilder builder()
{
return new ProjectBuilderRequestBuilder();
}
@NotThreadSafe
class ProjectBuilderRequestBuilder
{
Session session;
Path path;
ProjectBuilderSource source;
Artifact artifact;
ArtifactCoordinate coordinate;
boolean allowStubModel;
boolean recursive;
boolean processPlugins = true;
boolean resolveDependencies = true;
public ProjectBuilderRequestBuilder session( Session session )
{
this.session = session;
return this;
}
public ProjectBuilderRequestBuilder path( Path path )
{
this.path = path;
return this;
}
public ProjectBuilderRequestBuilder source( ProjectBuilderSource source )
{
this.source = source;
return this;
}
public ProjectBuilderRequestBuilder artifact( Artifact artifact )
{
this.artifact = artifact;
return this;
}
public ProjectBuilderRequestBuilder coordinate( ArtifactCoordinate coordinate )
{
this.coordinate = coordinate;
return this;
}
public ProjectBuilderRequestBuilder processPlugins( boolean processPlugins )
{
this.processPlugins = processPlugins;
return this;
}
public ProjectBuilderRequestBuilder resolveDependencies( boolean resolveDependencies )
{
this.resolveDependencies = resolveDependencies;
return this;
}
public ProjectBuilderRequest build()
{
return new DefaultProjectBuilderRequest( session, path, source, artifact, coordinate,
allowStubModel, recursive, processPlugins, resolveDependencies );
}
private static class DefaultProjectBuilderRequest extends BaseRequest
implements ProjectBuilderRequest
{
private final Path path;
private final ProjectBuilderSource source;
private final Artifact artifact;
private final ArtifactCoordinate coordinate;
private final boolean allowStubModel;
private final boolean recursive;
private final boolean processPlugins;
private final boolean resolveDependencies;
@SuppressWarnings( "checkstyle:ParameterNumber" )
DefaultProjectBuilderRequest( @Nonnull Session session,
@Nullable Path path,
@Nullable ProjectBuilderSource source,
@Nullable Artifact artifact,
@Nullable ArtifactCoordinate coordinate,
boolean allowStubModel,
boolean recursive,
boolean processPlugins,
boolean resolveDependencies )
{
super( session );
this.path = path;
this.source = source;
this.artifact = artifact;
this.coordinate = coordinate;
this.allowStubModel = allowStubModel;
this.recursive = recursive;
this.processPlugins = processPlugins;
this.resolveDependencies = resolveDependencies;
}
@Nonnull
@Override
public Optional<Path> getPath()
{
return Optional.ofNullable( path );
}
@Nonnull
@Override
public Optional<ProjectBuilderSource> getSource()
{
return Optional.ofNullable( source );
}
@Nonnull
@Override
public Optional<Artifact> getArtifact()
{
return Optional.ofNullable( artifact );
}
@Nonnull
@Override
public Optional<ArtifactCoordinate> getCoordinate()
{
return Optional.ofNullable( coordinate );
}
@Override
public boolean isAllowStubModel()
{
return allowStubModel;
}
@Override
public boolean isRecursive()
{
return recursive;
}
@Override
public boolean isProcessPlugins()
{
return processPlugins;
}
@Override
public boolean isResolveDependencies()
{
return resolveDependencies;
}
}
}
}

View File

@ -0,0 +1,83 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;
import org.apache.maven.api.Project;
/**
* Result of a project build call.
*
* @since 4.0
*/
@Experimental
public interface ProjectBuilderResult
{
/**
* Gets the identifier of the project that could not be built. The general format of the identifier is {@code
* <groupId>:<artifactId>:<version>} but some of these coordinates may still be unknown at the point the exception
* is thrown so this information is merely meant to assist the user.
*
* @return The identifier of the project or an empty string if not known, never {@code null}.
*/
@Nonnull
String getProjectId();
/**
* Gets the POM file from which the project was built.
*
* @return The optional POM file.
*/
@Nonnull
Optional<Path> getPomFile();
/**
* Gets the project that was built.
*
* @return The project that was built or {@code null} if an error occurred and this result accompanies a
* {@link ProjectBuilderException}.
*/
@Nonnull
Optional<Project> getProject();
/**
* Gets the problems that were encountered during the project building.
*
* @return The problems that were encountered during the project building, can be empty but never {@code null}.
*/
@Nonnull
Collection<ProjectBuilderProblem> getProblems();
/**
* Gets the result of the dependency resolution for the project.
*
* @return The result of the dependency resolution for the project.
*/
@Nonnull
Optional<DependencyCollectorResult> getDependencyResolverResult();
}

View File

@ -0,0 +1,38 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.io.IOException;
import java.io.InputStream;
import org.apache.maven.api.annotations.Experimental;
/**
* The source for a project's XML model.
*
* @since 4.0
*/
@Experimental
public interface ProjectBuilderSource
{
InputStream getInputStream() throws IOException;
String getLocation();
}

View File

@ -0,0 +1,93 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.Node;
import org.apache.maven.api.Project;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.Session;
/**
* Interface to manage the project during its lifecycle.
*
* @since 4.0
*/
@Experimental
public interface ProjectManager extends Service
{
/**
* Returns the path to the resolved file in the local repository
* if the artifact has been resolved.
*
* @return the path of the resolved artifact
*/
@Nonnull
Optional<Path> getPath( Project project );
@Nonnull
Collection<Artifact> getAttachedArtifacts( Project project );
default void attachArtifact( Session session, Project project, Path path )
{
String name = path.getFileName().toString();
int dot = name.lastIndexOf( '.' );
String ext = dot >= 1 ? name.substring( dot + 1 ) : "";
Artifact artifact = session.createArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), ext );
attachArtifact( project, artifact, path );
}
default void attachArtifact( Session session, Project project, String type, Path path )
{
Artifact artifact = session.createArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), null, null, type );
attachArtifact( project, artifact, path );
}
void attachArtifact( Project project, Artifact artifact, Path path );
List<String> getCompileSourceRoots( Project project );
void addCompileSourceRoot( Project project, String sourceRoot );
List<String> getTestCompileSourceRoots( Project project );
void addTestCompileSourceRoot( Project project, String sourceRoot );
List<RemoteRepository> getRepositories( Project project );
List<Artifact> getResolvedDependencies( Project project, ResolutionScope scope );
Node getCollectedDependencies( Project project, ResolutionScope scope );
void setProperty( Project project, String key, String value );
}

View File

@ -0,0 +1,106 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.List;
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Experimental;
/**
* Service used to interact with the end user.
*
* @since 4.0
*/
@Experimental
public interface Prompter extends Service
{
/**
* Prompts the user for a string.
*
* @param message the message to display to the user
* @return the string entered by the user
* @throws PrompterException if an exception occurs
*/
default String prompt( String message )
throws PrompterException
{
return prompt( message, null, null );
}
/**
* Prompts the user for a string using a default value.
*
* @param message the message to display
* @param defaultReply the default reply value
* @return the string entered by the user
* @throws PrompterException if an exception occurs
*/
default String prompt( String message, String defaultReply )
throws PrompterException
{
return prompt( message, null, defaultReply );
}
/**
* Prompts the user for a string using a list of possible values.
*
* @param message the message to display
* @param possibleValues the list of possible values
* @return the string entered by the user
* @throws PrompterException if an exception occurs
*/
default String prompt( String message, List<String> possibleValues )
throws PrompterException
{
return prompt( message, possibleValues, null );
}
/**
* Prompts the user for a string using a list of possible values and a default reply.
*
* @param message the message to display
* @param possibleValues the list of possible values
* @param defaultReply the default reply value
* @return the string entered by the user
* @throws PrompterException if an exception occurs
*/
String prompt( String message, List<String> possibleValues, String defaultReply )
throws PrompterException;
/**
* Prompts the user for a password.
*
* @param message the message to display
* @return the password entered by the user
* @throws PrompterException if an exception occurs
*/
String promptForPassword( String message )
throws PrompterException;
/**
* Displays a message to the user.
*
* @param message the message to display
* @throws PrompterException if an exception occurs
*/
void showMessage( String message )
throws PrompterException;
}

View File

@ -0,0 +1,42 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* The Exception class throw by the {@link Prompter} service.
*
* @since 4.0
*/
@Experimental
public class PrompterException
extends MavenException
{
/**
* @param message The message to give.
* @param e The {@link Exception}.
*/
public PrompterException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,49 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.nio.file.Path;
import org.apache.maven.api.LocalRepository;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.model.Repository;
/**
* Factory service to create {@link LocalRepository} or {@link RemoteRepository} objects.
*
* @since 4.0
*/
@Experimental
public interface RepositoryFactory extends Service
{
@Nonnull
LocalRepository createLocal( @Nonnull Path path );
@Nonnull
RemoteRepository createRemote( @Nonnull String id, @Nonnull String url );
@Nonnull
RemoteRepository createRemote( @Nonnull Repository repository );
}

View File

@ -0,0 +1,33 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Consumer;
import org.apache.maven.api.annotations.Experimental;
/**
* @since 4.0
*/
@Experimental
@Consumer
public interface ToolchainFactory
{
// TODO: implement ToolchainFactory
}

View File

@ -0,0 +1,82 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.Toolchain;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* Service to manage {@link Toolchain}s.
*
* @since 4.0
*/
@Experimental
public interface ToolchainManager extends Service
{
/**
*
* @param session
* @param type
* @param requirements
* @return the selected {@link Toolchain}s
* @throws ToolchainManagerException if an exception occurs
*/
@Nonnull
List<Toolchain> getToolchains( @Nonnull Session session, String type, Map<String, String> requirements );
/**
*
* @param session
* @param type
* @return the selected {@link Toolchain}
* @throws ToolchainManagerException if an exception occurs
*/
@Nonnull
Optional<Toolchain> getToolchainFromBuildContext( @Nonnull Session session, String type )
throws ToolchainManagerException;
/**
*
* @param session
* @param type
* @return the selected {@link Toolchain}s
* @throws ToolchainManagerException if an exception occurs
*/
@Nonnull
List<Toolchain> getToolchainsForType( @Nonnull Session session, String type )
throws ToolchainManagerException;
/**
*
* @param session
* @param toolchain
* @throws ToolchainManagerException if an exception occurs
*/
void storeToolchainToBuildContext( @Nonnull Session session, Toolchain toolchain )
throws ToolchainManagerException;
}

View File

@ -0,0 +1,42 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* The Exception class throw by the {@link ToolchainManager}.
*
* @since 4.0
*/
@Experimental
public class ToolchainManagerException
extends MavenException
{
/**
* @param message The message to give.
* @param e The {@link Exception}.
*/
public ToolchainManagerException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,47 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.Service;
import org.apache.maven.api.Type;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* Access to {@link Type} registry.
*
* @since 4.0
*/
@Experimental
public interface TypeRegistry extends Service
{
/**
* Obtain the {@link Type} from the specified {@code id}.
* If no type is known for {@code id}, the registry will
* create a custom {@code Type} for it.
*
* @param id the id of the type to retrieve
* @return the type
*/
@Nonnull
Type getType( @Nonnull String id );
}

View File

@ -0,0 +1,62 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.Service;
import org.apache.maven.api.Version;
import org.apache.maven.api.VersionRange;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/**
* Service interface to parse {@link Version} and {@link VersionRange}.
*
* @since 4.0
*/
@Experimental
public interface VersionParser extends Service
{
/**
* Parses the specified version string, for example "1.0".
*
* @param version The version string to parse, must not be {@code null}.
* @return The parsed version, never {@code null}.
* @throws VersionParserException If the string violates the syntax rules of this scheme.
* @see org.apache.maven.api.Session#parseVersion(String)
*/
@Nonnull
Version parseVersion( @Nonnull String version );
/**
* Parses the specified version range specification, for example "[1.0,2.0)".
*
* @param range The range specification to parse, must not be {@code null}.
* @return The parsed version range, never {@code null}.
* @throws VersionParserException If the range specification violates the syntax rules of this scheme.
*/
@Nonnull
VersionRange parseVersionRange( @Nonnull String range );
/**
* Checks whether a given artifact version is considered a {@code SNAPSHOT} or not.
*/
boolean isSnapshot( @Nonnull String version );
}

View File

@ -0,0 +1,42 @@
package org.apache.maven.api.services;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
/**
* The Exception class thrown by {@link VersionParser}.
*
* @since 4.0
*/
@Experimental
public class VersionParserException
extends MavenException
{
/**
* @param message The message to give.
* @param e The {@link Exception}.
*/
public VersionParserException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,34 @@
package org.apache.maven.api.services.xml;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.model.Model;
/**
* Reads or writes a {@link Model} using XML.
*
* @since 4.0
*/
@Experimental
public interface ModelXmlFactory extends XmlFactory<Model>
{
}

View File

@ -0,0 +1,34 @@
package org.apache.maven.api.services.xml;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.settings.Settings;
/**
* Reads and writes a {@link Settings} object to/from XML.
*
* @since 4.0
*/
@Experimental
public interface SettingsXmlFactory extends XmlFactory<Settings>
{
}

View File

@ -0,0 +1,34 @@
package org.apache.maven.api.services.xml;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.toolchain.PersistedToolchains;
/**
* Reads and writes a {@link PersistedToolchains} object to/from XML.
*
* @since 4.0
*/
@Experimental
public interface ToolchainsXmlFactory extends XmlFactory<PersistedToolchains>
{
}

View File

@ -0,0 +1,98 @@
package org.apache.maven.api.services.xml;
/*
* 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.
*/
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Path;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.Service;
/**
* Generic interface to read/write objects to/from XML.
*
* @param <T> the object type to read/write
* @since 4.0
*/
@Experimental
public interface XmlFactory<T> extends Service
{
@Nonnull
default T read( @Nonnull Path path ) throws XmlReaderException
{
return read( path, true );
}
@Nonnull
default T read( @Nonnull Path path, boolean strict ) throws XmlReaderException
{
return read( XmlReaderRequest.builder().path( path ).strict( strict ).build() );
}
@Nonnull
default T read( @Nonnull InputStream input ) throws XmlReaderException
{
return read( input, true );
}
@Nonnull
default T read( @Nonnull InputStream input, boolean strict ) throws XmlReaderException
{
return read( XmlReaderRequest.builder().inputStream( input ).strict( strict ).build() );
}
@Nonnull
default T read( @Nonnull Reader reader ) throws XmlReaderException
{
return read( reader, true );
}
@Nonnull
default T read( @Nonnull Reader reader, boolean strict ) throws XmlReaderException
{
return read( XmlReaderRequest.builder().reader( reader ).strict( strict ).build() );
}
@Nonnull
T read( @Nonnull XmlReaderRequest request ) throws XmlReaderException;
default void write( @Nonnull T content, @Nonnull Path path ) throws XmlWriterException
{
write( XmlWriterRequest.<T>builder().content( content ).path( path ).build() );
}
default void write( @Nonnull T content, @Nonnull OutputStream outputStream ) throws XmlWriterException
{
write( XmlWriterRequest.<T>builder().content( content ).outputStream( outputStream ).build() );
}
default void write( @Nonnull T content, @Nonnull Writer writer ) throws XmlWriterException
{
write( XmlWriterRequest.<T>builder().content( content ).writer( writer ).build() );
}
void write( @Nonnull XmlWriterRequest<T> request ) throws XmlWriterException;
}

View File

@ -0,0 +1,44 @@
package org.apache.maven.api.services.xml;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.services.MavenException;
/**
* An exception thrown during the reading of an xml file.
*
* @since 4.0
*/
@Experimental
public class XmlReaderException
extends MavenException
{
/**
* @param message The message for the exception.
* @param e The exception itself.
*/
public XmlReaderException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,236 @@
package org.apache.maven.api.services.xml;
/*
* 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.
*/
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
import java.nio.file.Path;
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.NotThreadSafe;
/**
* An XML reader request.
*
* @since 4.0
*/
@Experimental
@Immutable
public interface XmlReaderRequest
{
Path getPath();
URL getURL();
InputStream getInputStream();
Reader getReader();
Transformer getTransformer();
boolean isStrict();
String getModelId();
String getLocation();
boolean isAddDefaultEntities();
interface Transformer
{
/**
* Interpolate the value read from the xml document
*
* @param source The source value
* @param fieldName A description of the field being interpolated. The implementation may use this to
* log stuff.
* @return The interpolated value.
*/
String transform( String source, String fieldName );
}
@Nonnull
static XmlReaderRequestBuilder builder()
{
return new XmlReaderRequestBuilder();
}
@NotThreadSafe
class XmlReaderRequestBuilder
{
Path path;
URL url;
InputStream inputStream;
Reader reader;
Transformer transformer;
boolean strict;
String modelId;
String location;
boolean addDefaultEntities = true;
public XmlReaderRequestBuilder path( Path path )
{
this.path = path;
return this;
}
public XmlReaderRequestBuilder url( URL url )
{
this.url = url;
return this;
}
public XmlReaderRequestBuilder inputStream( InputStream inputStream )
{
this.inputStream = inputStream;
return this;
}
public XmlReaderRequestBuilder reader( Reader reader )
{
this.reader = reader;
return this;
}
public XmlReaderRequestBuilder transformer( Transformer transformer )
{
this.transformer = transformer;
return this;
}
public XmlReaderRequestBuilder strict( boolean strict )
{
this.strict = strict;
return this;
}
public XmlReaderRequestBuilder modelId( String modelId )
{
this.modelId = modelId;
return this;
}
public XmlReaderRequestBuilder location( String location )
{
this.location = location;
return this;
}
public XmlReaderRequestBuilder addDefaultEntities( boolean addDefaultEntities )
{
this.addDefaultEntities = addDefaultEntities;
return this;
}
public XmlReaderRequest build()
{
return new DefaultXmlReaderRequest( path, url, inputStream, reader, transformer, strict,
modelId, location, addDefaultEntities );
}
private static class DefaultXmlReaderRequest implements XmlReaderRequest
{
final Path path;
final URL url;
final InputStream inputStream;
final Reader reader;
final Transformer transformer;
final boolean strict;
final String modelId;
final String location;
final boolean addDefaultEntities;
@SuppressWarnings( "checkstyle:ParameterNumber" )
DefaultXmlReaderRequest( Path path, URL url, InputStream inputStream, Reader reader,
Transformer transformer, boolean strict,
String modelId, String location,
boolean addDefaultEntities )
{
this.path = path;
this.url = url;
this.inputStream = inputStream;
this.reader = reader;
this.transformer = transformer;
this.strict = strict;
this.modelId = modelId;
this.location = location;
this.addDefaultEntities = addDefaultEntities;
}
@Override
public Path getPath()
{
return path;
}
@Override
public URL getURL()
{
return null;
}
@Override
public InputStream getInputStream()
{
return inputStream;
}
public Reader getReader()
{
return reader;
}
@Override
public Transformer getTransformer()
{
return transformer;
}
@Override
public boolean isStrict()
{
return strict;
}
@Override
public String getModelId()
{
return modelId;
}
@Override
public String getLocation()
{
return location;
}
@Override
public boolean isAddDefaultEntities()
{
return addDefaultEntities;
}
}
}
}

View File

@ -0,0 +1,44 @@
package org.apache.maven.api.services.xml;
/*
* 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.
*/
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.services.MavenException;
/**
* An exception thrown during the writing of an xml file.
*
* @since 4.0
*/
@Experimental
public class XmlWriterException
extends MavenException
{
/**
* @param message The message for the exception.
* @param e The exception itself.
*/
public XmlWriterException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,127 @@
package org.apache.maven.api.services.xml;
/*
* 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.
*/
import java.io.OutputStream;
import java.io.Writer;
import java.nio.file.Path;
import org.apache.maven.api.annotations.Experimental;
/**
* An XML writer request.
*
* @since 4.0
* @param <T> the object type to read
*/
@Experimental
public interface XmlWriterRequest<T>
{
Path getPath();
OutputStream getOutputStream();
Writer getWriter();
T getContent();
static <T> XmlWriterRequestBuilder<T> builder()
{
return new XmlWriterRequestBuilder<>();
}
class XmlWriterRequestBuilder<T>
{
Path path;
OutputStream outputStream;
Writer writer;
T content;
public XmlWriterRequestBuilder<T> path( Path path )
{
this.path = path;
return this;
}
public XmlWriterRequestBuilder<T> outputStream( OutputStream outputStream )
{
this.outputStream = outputStream;
return this;
}
public XmlWriterRequestBuilder<T> writer( Writer writer )
{
this.writer = writer;
return this;
}
public XmlWriterRequestBuilder<T> content( T content )
{
this.content = content;
return this;
}
public XmlWriterRequest<T> build()
{
return new DefaultXmlWriterRequest<>( path, outputStream, writer, content );
}
private static class DefaultXmlWriterRequest<T> implements XmlWriterRequest<T>
{
final Path path;
final OutputStream outputStream;
final Writer writer;
final T content;
DefaultXmlWriterRequest( Path path, OutputStream outputStream, Writer writer, T content )
{
this.path = path;
this.outputStream = outputStream;
this.writer = writer;
this.content = content;
}
@Override
public Path getPath()
{
return path;
}
@Override
public OutputStream getOutputStream()
{
return outputStream;
}
@Override
public Writer getWriter()
{
return writer;
}
@Override
public T getContent()
{
return content;
}
}
}
}

View File

@ -0,0 +1,32 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api</artifactId>
<version>4.0.0-alpha-1-SNAPSHOT</version>
</parent>
<artifactId>maven-api-meta</artifactId>
<name>Maven API Meta annotations</name>
</project>

View File

@ -0,0 +1,47 @@
package org.apache.maven.api.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* A type implemented by, or extended by maven plugins or extensions.
* Maven plugins or extensions may provide implementations of those types which will be used by maven.
* <p>
* A type can be marked {@link Consumer} or {@link Provider} but not both. A type is assumed to be
* {@link Consumer} if it is not marked either {@link Consumer} or {@link Provider}.
* <p>
* A package can be marked {@link Provider}. In this case, all types in the package are considered
* to be a provider type regardless of whether they are marked {@link Consumer} or {@link Provider}.
*
* @see Provider
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@Target( { ElementType.TYPE, ElementType.PACKAGE } )
public @interface Consumer
{
}

View File

@ -0,0 +1,37 @@
package org.apache.maven.api.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* This annotation tags types that are part of an experimental API.
* Classes or methods annotated with this annotation may be changed / removed without notice.
*
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
public @interface Experimental
{
}

View File

@ -0,0 +1,39 @@
package org.apache.maven.api.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation indicates that a type is automatically generated.
*
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@Target( ElementType.TYPE )
public @interface Generated
{
}

View File

@ -0,0 +1,43 @@
package org.apache.maven.api.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The {@code Immutable} annotation indicates that the object is immutable, i.e.
* none of its field can be changed. This also ensures that the type is
* {@link ThreadSafe}.
*
* @see ThreadSafe
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@ThreadSafe
@Target( ElementType.TYPE )
public @interface Immutable
{
}

View File

@ -0,0 +1,44 @@
package org.apache.maven.api.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The annotated element must not be null.
* <p>
* Annotated fields must not be null after construction has completed.
* <p>
* When this annotation is applied to a method it applies to the method return value.
*
* @see Nullable
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@Target( { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD } )
public @interface Nonnull
{
}

View File

@ -0,0 +1,41 @@
package org.apache.maven.api.annotations;
/*
* 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.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation indicates that the annotated type is <bold>not</bold> threadsafe
* and should only be used by a single thread.
*
* @see ThreadSafe
* @since 4.0
*/
@Experimental
@Documented
@Retention( RetentionPolicy.CLASS )
@Target( ElementType.TYPE )
public @interface NotThreadSafe
{
}

Some files were not shown because too many files have changed in this diff Show More