Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8084] Move ModelBuilder and resolver provider to v4 api #1457

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.api;

import java.util.*;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.model.Plugin;

/**
* Lifecycle definition
*
* @since 4.0.0
*/
@Experimental
@Immutable
public interface Lifecycle extends ExtensibleEnum {

String CLEAN = "clean";

String DEFAULT = "default";

String SITE = "site";

String WRAPPER = "wrapper";

/**
* Name or identifier of this lifecycle.
*
* @return the unique identifier for this lifecycle
*/
@Override
String id();

/**
* Collection of phases for this lifecycle
*/
Collection<Phase> phases();

/**
* Pre-ordered list of phases.
* If not provided, a default order will be computed.
*/
default Optional<List<String>> orderedPhases() {
return Optional.empty();
}

/**
* A phase in the lifecycle.
*/
interface Phase {
String name();

List<Plugin> plugins();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.api;

import java.util.Map;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
Expand Down Expand Up @@ -55,9 +57,9 @@ default Language language() {
Type type();

/**
* Returns the binding to use specifically for this packaging.
* This will be merged to the default packaging definition.
* Returns the binding to use specifically for this packaging keyed by lifecycle id.
* This will be used instead of the default packaging definition.
*/
@Nonnull
PluginContainer plugins();
Map<String, PluginContainer> plugins();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
@Immutable
public interface PathScope extends ExtensibleEnum {

// TODO: what if I simply want all dependencies ?
@Nonnull
ProjectScope projectScope();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,10 @@
public @interface Execute {
/**
* Lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
* For custom lifecycle phase ids use {@link #customPhase()} instead.
* Only one of {@link #customPhase()} and {@link #phase()} must be set.
* @return the phase
*/
@Nonnull
LifecyclePhase phase() default LifecyclePhase.NONE;

/**
* Custom lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
* This element should only be used for non-standard phases. For standard phases rather use {@link #phase()}.
* Only one of {@link #customPhase()} and {@link #phase()} must be set.
* @return the custom phase id
*/
@Nonnull
String customPhase() default "";
String phase() default "";

/**
* Goal to fork. Note that specifying a phase overrides specifying a goal. The specified <code>goal</code> must be
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* @return the default phase
*/
@Nonnull
LifecyclePhase defaultPhase() default LifecyclePhase.NONE;
String defaultPhase() default "";

/**
* does your mojo requires a project to be executed?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.api.services;

import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import org.apache.maven.api.Lifecycle;

public interface LifecycleRegistry extends ExtensibleEnumRegistry<Lifecycle>, Iterable<Lifecycle> {
default Stream<Lifecycle> stream() {
return StreamSupport.stream(spliterator(), false);
}

List<String> computePhases(Lifecycle lifecycle);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.api.services;

import java.util.List;

import org.apache.maven.api.Service;
import org.apache.maven.api.model.Model;

public interface ModelBuilder extends Service {

List<String> VALID_MODEL_VERSIONS = List.of("4.0.0", "4.1.0");

ModelBuilderResult build(ModelBuilderRequest request) throws ModelBuilderException;

ModelTransformerContextBuilder newTransformerContextBuilder();

Model buildRawModel(ModelBuilderRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.api.services;

import java.util.Collections;
import java.util.List;

import org.apache.maven.api.annotations.Experimental;

/**
* The Exception class throw by the {@link ProjectBuilder} service.
*
* @since 4.0.0
*/
@Experimental
public class ModelBuilderException extends MavenException {

private final ModelBuilderResult result;

/**
* Creates a new exception from the specified interim result and its associated problems.
*
* @param result The interim result, may be {@code null}.
*/
public ModelBuilderException(ModelBuilderResult result) {
super(result.toString());
this.result = result;
}

/**
* Gets the interim result of the model building up to the point where it failed.
*
* @return The interim model building result or {@code null} if not available.
*/
public ModelBuilderResult getResult() {
return result;
}

/**
* Gets the identifier of the POM whose effective model 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 POM or an empty string if not known, never {@code null}.
*/
public String getModelId() {
if (result == null || result.getModelIds().isEmpty()) {
return "";
}
return result.getModelIds().get(0);
}

/**
* Gets the problems that caused this exception.
*
* @return The problems that caused this exception, never {@code null}.
*/
public List<ModelProblem> getProblems() {
if (result == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(result.getProblems());
}
}