Skip to content

Commit 2e669bb

Browse files
committed
[MNG-7836] Support alternative syntaxes for POMs
1 parent 7c6b6ed commit 2e669bb

12 files changed

Lines changed: 426 additions & 52 deletions

File tree

.github/workflows/maven.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,21 @@ jobs:
106106
ref: ${{ env.REPO_BRANCH }}
107107
persist-credentials: false
108108

109-
- name: Download built Maven
110-
uses: actions/download-artifact@v3
111-
with:
112-
name: built-maven
113-
path: built-maven/
114-
115109
- name: Set up JDK
116110
uses: actions/setup-java@v3
117111
with:
118112
java-version: ${{ matrix.java }}
119113
distribution: 'temurin'
120114
# cache: 'maven' - don't use cache for integration tests
121115

116+
- uses: actions/checkout@v3
117+
with:
118+
path: maven/
119+
persist-credentials: false
120+
121+
- name: Build Maven
122+
run: mvn install -e -B -V -DdistributionFileName=apache-maven -DskipTests -f maven/pom.xml
123+
122124
- name: Running integration tests
123125
shell: bash
124-
run: mvn install -e -B -V -Prun-its,embedded -DmavenDistro="$GITHUB_WORKSPACE/built-maven/apache-maven-bin.zip" -f maven-integration-testing/pom.xml
126+
run: mvn install -e -B -V -Prun-its,embedded -DmavenDistro="$GITHUB_WORKSPACE/maven/apache-maven/target/apache-maven-bin.zip" -f maven-integration-testing/pom.xml

api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,54 @@
2020

2121
import java.io.IOException;
2222
import java.io.InputStream;
23+
import java.nio.file.Path;
2324

25+
import org.apache.maven.api.Session;
2426
import org.apache.maven.api.annotations.Experimental;
27+
import org.apache.maven.api.annotations.Nonnull;
28+
import org.apache.maven.api.annotations.Nullable;
2529

2630
/**
27-
* The source for a project's XML model.
31+
* Provides access to the contents of a source independently of the
32+
* backing store (e.g. file system, database, memory).
33+
* <p>
34+
* This is mainly used to parse files into objects such as
35+
* {@link org.apache.maven.api.Project},
36+
* {@link org.apache.maven.api.model.Model},
37+
* {@link org.apache.maven.api.settings.Settings}, or
38+
* {@link org.apache.maven.api.toolchain.PersistedToolchains}.
2839
*
2940
* @since 4.0.0
41+
* @see org.apache.maven.api.services.ProjectBuilder#build(Session, Source)
42+
* @see org.apache.maven.api.services.SettingsBuilder#build(Session, Source, Source, Source)
43+
* @see org.apache.maven.api.services.ToolchainsBuilder#build(Session, Source, Source)
3044
*/
3145
@Experimental
3246
public interface Source {
47+
48+
/**
49+
* Provides access the file to be parsed, if this source is backed by a file.
50+
*
51+
* @return The underlying {@code Path}, or {@code null} if this source is not backed by a file.
52+
*/
53+
@Nullable
54+
Path getPath();
55+
56+
/**
57+
* Gets a byte stream to the source contents. Closing the returned stream is the responsibility of the caller.
58+
*
59+
* @return A byte stream to the source contents, never {@code null}.
60+
* @throws IOException in case of IO issue
61+
*/
62+
@Nonnull
3363
InputStream getInputStream() throws IOException;
3464

65+
/**
66+
* Provides a user-friendly hint about the location of the source. This could be a local file path, a URI or just an
67+
* empty string. The intention is to assist users during error reporting.
68+
*
69+
* @return A user-friendly hint about the location of the source, never {@code null}.
70+
*/
71+
@Nullable
3572
String getLocation();
3673
}

api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilder.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
package org.apache.maven.api.services;
2020

2121
import org.apache.maven.api.Service;
22+
import org.apache.maven.api.Session;
2223
import org.apache.maven.api.annotations.Experimental;
24+
import org.apache.maven.api.annotations.Nonnull;
2325

2426
/**
2527
* Builds the effective toolchains from a user toolchains file and/or a global toolchains file.
@@ -28,11 +30,27 @@
2830
public interface ToolchainsBuilder extends Service {
2931

3032
/**
31-
* Builds the effective toolchains of the specified toolchains files.
33+
* Builds the effective toolchains for the specified toolchains files.
3234
*
3335
* @param request the toolchains building request that holds the parameters, must not be {@code null}
3436
* @return the result of the toolchains building, never {@code null}
3537
* @throws ToolchainsBuilderException if the effective toolchains could not be built
3638
*/
3739
ToolchainsBuilderResult build(ToolchainsBuilderRequest request);
40+
41+
/**
42+
* Builds the effective toolchains for the specified toolchains sources.
43+
*
44+
* @param session the {@link Session}, must not be {@code null}
45+
* @param globalToolchainsSource The {@link Source} pointing to the global toolchains, must not be {@code null}
46+
* @param userToolchainsSource The {@link Source} pointing to the user toolchains, must not be {@code null}
47+
* @throws ToolchainsBuilderException if the project cannot be created
48+
* @throws IllegalArgumentException if an argument is {@code null} or invalid
49+
* @see #build(ToolchainsBuilderRequest)
50+
*/
51+
@Nonnull
52+
default ToolchainsBuilderResult build(
53+
@Nonnull Session session, @Nonnull Source globalToolchainsSource, @Nonnull Source userToolchainsSource) {
54+
return build(ToolchainsBuilderRequest.build(session, globalToolchainsSource, userToolchainsSource));
55+
}
3856
}

api/maven-api-model/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ under the License.
7676
</excludes>
7777
</configuration>
7878
</plugin>
79+
<plugin>
80+
<groupId>org.codehaus.mojo</groupId>
81+
<artifactId>build-helper-maven-plugin</artifactId>
82+
<version>3.4.0</version>
83+
<executions>
84+
<execution>
85+
<goals>
86+
<goal>attach-artifact</goal>
87+
</goals>
88+
<configuration>
89+
<artifacts>
90+
<artifact>
91+
<file>${basedir}/src/main/mdo/maven.mdo</file>
92+
<type>mdo</type>
93+
</artifact>
94+
</artifacts>
95+
</configuration>
96+
</execution>
97+
</executions>
98+
</plugin>
7999
</plugins>
80100
</build>
81101

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.api.spi;
20+
21+
import java.nio.file.Path;
22+
import java.util.Map;
23+
24+
import org.apache.maven.api.annotations.Experimental;
25+
import org.apache.maven.api.annotations.Nonnull;
26+
import org.apache.maven.api.annotations.Nullable;
27+
import org.apache.maven.api.model.Model;
28+
import org.apache.maven.api.services.Source;
29+
30+
/**
31+
* The {@code ModelParser} interface is used to locate and read {@link Model}s from the file system.
32+
* This allows plugging in additional syntaxes for the main model read by Maven when building a project.
33+
*/
34+
@Experimental
35+
public interface ModelParser {
36+
37+
/**
38+
* Locates the pom in the given directory.
39+
*
40+
* @param dir the directory to locate the pom for, never {@code null}
41+
* @return the located pom or <code>null</code> if none was found by this parser
42+
*/
43+
@Nullable
44+
Path locatePom(@Nonnull Path dir);
45+
46+
/**
47+
* Parse the model.
48+
*
49+
* @param source the source to parse, never {@code null}
50+
* @return the parsed {@link Model}, never {@code null}
51+
* @throws ModelParserException if the model cannot be parsed
52+
*/
53+
@Nonnull
54+
Model parse(@Nonnull Source source, Map<String, ?> options) throws ModelParserException;
55+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.api.spi;
20+
21+
import org.apache.maven.api.annotations.Experimental;
22+
import org.apache.maven.api.services.MavenException;
23+
24+
@Experimental
25+
public class ModelParserException extends MavenException {
26+
27+
/**
28+
* The one-based index of the line containing the error.
29+
*/
30+
private final int lineNumber;
31+
32+
/**
33+
* The one-based index of the column containing the error.
34+
*/
35+
private final int columnNumber;
36+
37+
public ModelParserException() {
38+
this(null, null);
39+
}
40+
41+
public ModelParserException(String message) {
42+
this(message, null);
43+
}
44+
45+
public ModelParserException(String message, Throwable cause) {
46+
this(message, -1, -1, cause);
47+
}
48+
49+
public ModelParserException(String message, int lineNumber, int columnNumber, Throwable cause) {
50+
super(message, cause);
51+
this.lineNumber = lineNumber;
52+
this.columnNumber = columnNumber;
53+
}
54+
55+
public ModelParserException(Throwable cause) {
56+
this(null, cause);
57+
}
58+
59+
public int getLineNumber() {
60+
return lineNumber;
61+
}
62+
63+
public int getColumnNumber() {
64+
return columnNumber;
65+
}
66+
}

0 commit comments

Comments
 (0)