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-8215] Add location tracking for toolchains #1608

Merged
merged 2 commits into from
Aug 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions api/maven-api-toolchain/src/main/mdo/toolchains.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,51 @@
</codeSegment>
</codeSegments>
</class>
<!-- /BuildProfile support -->
<class locationTracker="locations">
<name>InputLocation</name>
<version>1.2.0+</version>
<fields>
<!-- line, column and source fields are auto-generated by Modello -->
</fields>
<codeSegments>
<codeSegment>
<version>1.2.0+</version>
<code>

@Override
public String toString() {
return getLineNumber() + " : " + getColumnNumber() + ", " + getSource();
}
</code>
</codeSegment>
</codeSegments>
</class>
<class sourceTracker="source">
<name>InputSource</name>
<version>1.2.0+</version>
<fields>
<field>
<name>location</name>
<version>1.2.0+</version>
<type>String</type>
<description>
The path/URL of the settings definition or {@code null} if unknown.
</description>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>1.2.0+</version>
<code>
@Override
public String toString() {
return getLocation();
}
</code>
</codeSegment>
</codeSegments>
</class>
</classes>
</model>

4 changes: 3 additions & 1 deletion maven-api-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ under the License.
</goals>
<phase>generate-sources</phase>
<configuration>
<version>1.1.0</version>
<version>1.2.0</version>
<basedir>${project.basedir}/../api/maven-api-toolchain</basedir>
<velocityBasedir>${project.basedir}/../src/mdo</velocityBasedir>
<models>
Expand All @@ -212,6 +212,8 @@ under the License.
<param>packageModelV3=org.apache.maven.toolchain.model</param>
<param>packageModelV4=org.apache.maven.api.toolchain</param>
<param>packageToolV4=org.apache.maven.toolchain.v4</param>
<param>locationTracking=true</param>
<param>generateLocationClasses=true</param>
</params>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.maven.api.services.xml.XmlReaderRequest;
import org.apache.maven.api.services.xml.XmlWriterException;
import org.apache.maven.api.services.xml.XmlWriterRequest;
import org.apache.maven.api.toolchain.InputSource;
import org.apache.maven.api.toolchain.PersistedToolchains;
import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;
import org.apache.maven.toolchain.v4.MavenToolchainsStaxWriter;
Expand All @@ -52,12 +53,16 @@ public PersistedToolchains read(@Nonnull XmlReaderRequest request) throws XmlRea
throw new IllegalArgumentException("reader or inputStream must be non null");
}
try {
InputSource source = null;
if (request.getModelId() != null || request.getLocation() != null) {
source = new InputSource(request.getLocation());
}
MavenToolchainsStaxReader xml = new MavenToolchainsStaxReader();
xml.setAddDefaultEntities(request.isAddDefaultEntities());
if (reader != null) {
return xml.read(reader, request.isStrict());
return xml.read(reader, request.isStrict(), source);
} else {
return xml.read(inputStream, request.isStrict());
return xml.read(inputStream, request.isStrict(), source);
}
} catch (Exception e) {
throw new XmlReaderException("Unable to read toolchains: " + getMessage(e), getLocation(e), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import java.util.Objects;

import org.apache.maven.api.toolchain.InputSource;
import org.apache.maven.toolchain.model.PersistedToolchains;
import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;

Expand All @@ -47,7 +48,8 @@ public PersistedToolchains read(File input, Map<String, ?> options) throws IOExc
Objects.requireNonNull(input, "input cannot be null");

try (InputStream in = Files.newInputStream(input.toPath())) {
return new PersistedToolchains(new MavenToolchainsStaxReader().read(in, isStrict(options)));
InputSource source = new InputSource(input.toString());
return new PersistedToolchains(new MavenToolchainsStaxReader().read(in, isStrict(options), source));
} catch (XMLStreamException e) {
throw new ToolchainsParseException(
e.getMessage(),
Expand All @@ -62,7 +64,8 @@ public PersistedToolchains read(Reader input, Map<String, ?> options) throws IOE
Objects.requireNonNull(input, "input cannot be null");

try (Reader in = input) {
return new PersistedToolchains(new MavenToolchainsStaxReader().read(in, isStrict(options)));
InputSource source = (InputSource) options.get(InputSource.class.getName());
return new PersistedToolchains(new MavenToolchainsStaxReader().read(in, isStrict(options), source));
} catch (XMLStreamException e) {
throw new ToolchainsParseException(
e.getMessage(),
Expand All @@ -77,7 +80,8 @@ public PersistedToolchains read(InputStream input, Map<String, ?> options) throw
Objects.requireNonNull(input, "input cannot be null");

try (InputStream in = input) {
return new PersistedToolchains(new MavenToolchainsStaxReader().read(in, isStrict(options)));
InputSource source = (InputSource) options.get(InputSource.class.getName());
return new PersistedToolchains(new MavenToolchainsStaxReader().read(in, isStrict(options), source));
} catch (XMLStreamException e) {
throw new ToolchainsParseException(
e.getMessage(),
Expand Down
6 changes: 6 additions & 0 deletions src/mdo/reader-stax.vm
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,13 @@ public class ${className} {
#end
break;
#elseif ( $field.to && $field.multiplicity == "*" && $Helper.isFlatItems( $field ) )
#if ( $locationTracking )
${field.name}.add(parse${field.toClass.name}(parser, strict, source));
#elseif ( $needXmlContext )
${field.name}.add(parse${field.toClass.name}(parser, strict, context));
#else
${field.name}.add(parse${field.toClass.name}(parser, strict));
#end
break;
#elseif ( $field.to && $field.multiplicity == "*" )
List<$field.to> ${field.name} = new ArrayList<>();
Expand Down