mirror of https://github.com/apache/maven.git
[MNG-8215] Add location tracking for toolchains (#1608)
This commit is contained in:
parent
40e41153c2
commit
7e550efae0
|
@ -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>
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
@ -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>
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.maven.api.services.xml.XmlReaderException;
|
|||
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;
|
||||
|
@ -52,12 +53,16 @@ public class DefaultToolchainsXmlFactory implements ToolchainsXmlFactory {
|
|||
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);
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.nio.file.Files;
|
|||
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;
|
||||
|
||||
|
@ -47,7 +48,8 @@ public class DefaultToolchainsReader implements ToolchainsReader {
|
|||
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(),
|
||||
|
@ -62,7 +64,8 @@ public class DefaultToolchainsReader implements ToolchainsReader {
|
|||
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(),
|
||||
|
@ -77,7 +80,8 @@ public class DefaultToolchainsReader implements ToolchainsReader {
|
|||
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(),
|
||||
|
|
|
@ -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<>();
|
||||
|
|
Loading…
Reference in New Issue