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>
|
</codeSegment>
|
||||||
</codeSegments>
|
</codeSegments>
|
||||||
</class>
|
</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>
|
</classes>
|
||||||
</model>
|
</model>
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ under the License.
|
||||||
</goals>
|
</goals>
|
||||||
<phase>generate-sources</phase>
|
<phase>generate-sources</phase>
|
||||||
<configuration>
|
<configuration>
|
||||||
<version>1.1.0</version>
|
<version>1.2.0</version>
|
||||||
<basedir>${project.basedir}/../api/maven-api-toolchain</basedir>
|
<basedir>${project.basedir}/../api/maven-api-toolchain</basedir>
|
||||||
<velocityBasedir>${project.basedir}/../src/mdo</velocityBasedir>
|
<velocityBasedir>${project.basedir}/../src/mdo</velocityBasedir>
|
||||||
<models>
|
<models>
|
||||||
|
@ -212,6 +212,8 @@ under the License.
|
||||||
<param>packageModelV3=org.apache.maven.toolchain.model</param>
|
<param>packageModelV3=org.apache.maven.toolchain.model</param>
|
||||||
<param>packageModelV4=org.apache.maven.api.toolchain</param>
|
<param>packageModelV4=org.apache.maven.api.toolchain</param>
|
||||||
<param>packageToolV4=org.apache.maven.toolchain.v4</param>
|
<param>packageToolV4=org.apache.maven.toolchain.v4</param>
|
||||||
|
<param>locationTracking=true</param>
|
||||||
|
<param>generateLocationClasses=true</param>
|
||||||
</params>
|
</params>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</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.XmlReaderRequest;
|
||||||
import org.apache.maven.api.services.xml.XmlWriterException;
|
import org.apache.maven.api.services.xml.XmlWriterException;
|
||||||
import org.apache.maven.api.services.xml.XmlWriterRequest;
|
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.api.toolchain.PersistedToolchains;
|
||||||
import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;
|
import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;
|
||||||
import org.apache.maven.toolchain.v4.MavenToolchainsStaxWriter;
|
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");
|
throw new IllegalArgumentException("reader or inputStream must be non null");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
InputSource source = null;
|
||||||
|
if (request.getModelId() != null || request.getLocation() != null) {
|
||||||
|
source = new InputSource(request.getLocation());
|
||||||
|
}
|
||||||
MavenToolchainsStaxReader xml = new MavenToolchainsStaxReader();
|
MavenToolchainsStaxReader xml = new MavenToolchainsStaxReader();
|
||||||
xml.setAddDefaultEntities(request.isAddDefaultEntities());
|
xml.setAddDefaultEntities(request.isAddDefaultEntities());
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
return xml.read(reader, request.isStrict());
|
return xml.read(reader, request.isStrict(), source);
|
||||||
} else {
|
} else {
|
||||||
return xml.read(inputStream, request.isStrict());
|
return xml.read(inputStream, request.isStrict(), source);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new XmlReaderException("Unable to read toolchains: " + getMessage(e), getLocation(e), 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.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.apache.maven.api.toolchain.InputSource;
|
||||||
import org.apache.maven.toolchain.model.PersistedToolchains;
|
import org.apache.maven.toolchain.model.PersistedToolchains;
|
||||||
import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;
|
import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;
|
||||||
|
|
||||||
|
@ -47,7 +48,8 @@ public class DefaultToolchainsReader implements ToolchainsReader {
|
||||||
Objects.requireNonNull(input, "input cannot be null");
|
Objects.requireNonNull(input, "input cannot be null");
|
||||||
|
|
||||||
try (InputStream in = Files.newInputStream(input.toPath())) {
|
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) {
|
} catch (XMLStreamException e) {
|
||||||
throw new ToolchainsParseException(
|
throw new ToolchainsParseException(
|
||||||
e.getMessage(),
|
e.getMessage(),
|
||||||
|
@ -62,7 +64,8 @@ public class DefaultToolchainsReader implements ToolchainsReader {
|
||||||
Objects.requireNonNull(input, "input cannot be null");
|
Objects.requireNonNull(input, "input cannot be null");
|
||||||
|
|
||||||
try (Reader in = input) {
|
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) {
|
} catch (XMLStreamException e) {
|
||||||
throw new ToolchainsParseException(
|
throw new ToolchainsParseException(
|
||||||
e.getMessage(),
|
e.getMessage(),
|
||||||
|
@ -77,7 +80,8 @@ public class DefaultToolchainsReader implements ToolchainsReader {
|
||||||
Objects.requireNonNull(input, "input cannot be null");
|
Objects.requireNonNull(input, "input cannot be null");
|
||||||
|
|
||||||
try (InputStream in = input) {
|
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) {
|
} catch (XMLStreamException e) {
|
||||||
throw new ToolchainsParseException(
|
throw new ToolchainsParseException(
|
||||||
e.getMessage(),
|
e.getMessage(),
|
||||||
|
|
|
@ -662,7 +662,13 @@ public class ${className} {
|
||||||
#end
|
#end
|
||||||
break;
|
break;
|
||||||
#elseif ( $field.to && $field.multiplicity == "*" && $Helper.isFlatItems( $field ) )
|
#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));
|
${field.name}.add(parse${field.toClass.name}(parser, strict));
|
||||||
|
#end
|
||||||
break;
|
break;
|
||||||
#elseif ( $field.to && $field.multiplicity == "*" )
|
#elseif ( $field.to && $field.multiplicity == "*" )
|
||||||
List<$field.to> ${field.name} = new ArrayList<>();
|
List<$field.to> ${field.name} = new ArrayList<>();
|
||||||
|
|
Loading…
Reference in New Issue