mirror of https://github.com/apache/maven.git
[MNG-7820] Remove dependency on plexus-utils StringUtils / FileUtils (#1243)
Co-authored-by: crazyhzm <crazyhzm@apache.org>
This commit is contained in:
parent
ce8fc3a31c
commit
34b0591f03
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.maven.profiles.activation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.maven.model.Activation;
|
||||
|
@ -29,8 +30,6 @@ import org.codehaus.plexus.interpolation.MapBasedValueSource;
|
|||
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
|
||||
import org.codehaus.plexus.logging.LogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* FileProfileActivator
|
||||
|
@ -62,16 +61,18 @@ public class FileProfileActivator extends DetectedProfileActivator implements Lo
|
|||
|
||||
try {
|
||||
if (fileString != null && !fileString.isEmpty()) {
|
||||
fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
|
||||
return FileUtils.fileExists(fileString);
|
||||
fileString = interpolator.interpolate(fileString, "").replace("\\", "/");
|
||||
File file = new File(fileString);
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
// check if the file is missing, if it is then the profile will be active
|
||||
fileString = actFile.getMissing();
|
||||
|
||||
if (fileString != null && !fileString.isEmpty()) {
|
||||
fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
|
||||
return !FileUtils.fileExists(fileString);
|
||||
fileString = interpolator.interpolate(fileString, "").replace("\\", "/");
|
||||
File file = new File(fileString);
|
||||
return !file.exists();
|
||||
}
|
||||
} catch (InterpolationException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
|
|||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
import org.apache.maven.model.Activation;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* JdkPrefixProfileActivator
|
||||
|
@ -77,6 +76,7 @@ public class JdkPrefixProfileActivator extends DetectedProfileActivator {
|
|||
|
||||
protected boolean canDetectActivation(Profile profile) {
|
||||
return profile.getActivation() != null
|
||||
&& StringUtils.isNotEmpty(profile.getActivation().getJdk());
|
||||
&& profile.getActivation().getJdk() != null
|
||||
&& !profile.getActivation().getJdk().isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,11 @@ import javax.inject.Singleton;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -53,7 +58,6 @@ import org.codehaus.plexus.PlexusContainer;
|
|||
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.eclipse.aether.ConfigurationProperties;
|
||||
import org.eclipse.aether.util.ConfigUtils;
|
||||
|
||||
|
@ -453,7 +457,11 @@ public class DefaultWagonManager implements WagonManager {
|
|||
// then we will use a brute force copy and delete the temporary file.
|
||||
if (!temp.renameTo(destination)) {
|
||||
try {
|
||||
FileUtils.copyFile(temp, destination);
|
||||
Files.copy(
|
||||
temp.toPath(),
|
||||
destination.toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
StandardCopyOption.COPY_ATTRIBUTES);
|
||||
|
||||
if (!temp.delete()) {
|
||||
temp.deleteOnExit();
|
||||
|
@ -533,7 +541,9 @@ public class DefaultWagonManager implements WagonManager {
|
|||
// TODO shouldn't need a file intermediary - improve wagon to take a stream
|
||||
File temp = File.createTempFile("maven-artifact", null);
|
||||
temp.deleteOnExit();
|
||||
FileUtils.fileWrite(temp.getAbsolutePath(), "UTF-8", sums.get(extension));
|
||||
byte[] bytes = sums.get(extension).getBytes(StandardCharsets.UTF_8);
|
||||
Files.write(
|
||||
Paths.get(temp.getAbsolutePath()), bytes, StandardOpenOption.APPEND, StandardOpenOption.CREATE);
|
||||
|
||||
temporaryFiles.add(temp);
|
||||
wagon.put(temp, remotePath + "." + extension);
|
||||
|
@ -612,8 +622,8 @@ public class DefaultWagonManager implements WagonManager {
|
|||
File tempChecksumFile = new File(tempDestination + checksumFileExtension + ".tmp");
|
||||
tempChecksumFile.deleteOnExit();
|
||||
wagon.get(remotePath + checksumFileExtension, tempChecksumFile);
|
||||
|
||||
String expectedChecksum = FileUtils.fileRead(tempChecksumFile, "UTF-8");
|
||||
byte[] bytes = Files.readAllBytes(tempChecksumFile.toPath());
|
||||
String expectedChecksum = new String(bytes, StandardCharsets.UTF_8);
|
||||
|
||||
// remove whitespaces at the end
|
||||
expectedChecksum = expectedChecksum.trim();
|
||||
|
@ -636,7 +646,12 @@ public class DefaultWagonManager implements WagonManager {
|
|||
if (checksumFile.exists()) {
|
||||
checksumFile.delete(); // ignore if failed as we will overwrite
|
||||
}
|
||||
FileUtils.copyFile(tempChecksumFile, checksumFile);
|
||||
Files.copy(
|
||||
tempChecksumFile.toPath(),
|
||||
checksumFile.toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
StandardCopyOption.COPY_ATTRIBUTES);
|
||||
|
||||
if (!tempChecksumFile.delete()) {
|
||||
tempChecksumFile.deleteOnExit();
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ import org.apache.maven.wagon.proxy.ProxyUtils;
|
|||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.repository.AuthenticationContext;
|
||||
import org.eclipse.aether.repository.AuthenticationSelector;
|
||||
|
@ -475,7 +474,7 @@ public class LegacyRepositorySystem implements RepositorySystem {
|
|||
repository.setId(mirror.getId());
|
||||
repository.setUrl(mirror.getUrl());
|
||||
|
||||
if (StringUtils.isNotEmpty(mirror.getLayout())) {
|
||||
if (mirror.getLayout() != null && !mirror.getLayout().isEmpty()) {
|
||||
repository.setLayout(getLayout(mirror.getLayout()));
|
||||
}
|
||||
|
||||
|
@ -557,7 +556,8 @@ public class LegacyRepositorySystem implements RepositorySystem {
|
|||
if (proxies != null && repository.getProtocol() != null) {
|
||||
for (org.apache.maven.settings.Proxy proxy : proxies) {
|
||||
if (proxy.isActive() && repository.getProtocol().equalsIgnoreCase(proxy.getProtocol())) {
|
||||
if (StringUtils.isNotEmpty(proxy.getNonProxyHosts())) {
|
||||
if (proxy.getNonProxyHosts() != null
|
||||
&& !proxy.getNonProxyHosts().isEmpty()) {
|
||||
ProxyInfo pi = new ProxyInfo();
|
||||
pi.setNonProxyHosts(proxy.getNonProxyHosts());
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.apache.maven.artifact.repository.metadata.Snapshot;
|
|||
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -117,7 +116,7 @@ public class SnapshotTransformation extends AbstractVersionTransformation {
|
|||
if (snapshot != null) {
|
||||
if (snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0) {
|
||||
String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
|
||||
version = StringUtils.replace(baseVersion, Artifact.SNAPSHOT_VERSION, newVersion);
|
||||
version = baseVersion.replace(Artifact.SNAPSHOT_VERSION, newVersion);
|
||||
} else {
|
||||
version = baseVersion;
|
||||
}
|
||||
|
|
|
@ -26,11 +26,12 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.XmlStreamReader;
|
||||
|
||||
/**
|
||||
* Handles deserialization of metadata from some kind of textual format like XML.
|
||||
|
@ -43,7 +44,7 @@ public class DefaultMetadataReader implements MetadataReader {
|
|||
public Metadata read(File input, Map<String, ?> options) throws IOException {
|
||||
Objects.requireNonNull(input, "input cannot be null");
|
||||
|
||||
return read(ReaderFactory.newXmlReader(input), options);
|
||||
return read(new XmlStreamReader(Files.newInputStream(input.toPath())), options);
|
||||
}
|
||||
|
||||
public Metadata read(Reader input, Map<String, ?> options) throws IOException {
|
||||
|
|
|
@ -55,7 +55,6 @@ import org.apache.maven.model.Dependency;
|
|||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.repository.Proxy;
|
||||
import org.apache.maven.settings.Mirror;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.repository.AuthenticationContext;
|
||||
import org.eclipse.aether.repository.AuthenticationSelector;
|
||||
|
@ -211,7 +210,7 @@ public class MavenRepositorySystem {
|
|||
repository.setId(mirror.getId());
|
||||
repository.setUrl(mirror.getUrl());
|
||||
|
||||
if (StringUtils.isNotEmpty(mirror.getLayout())) {
|
||||
if (mirror.getLayout() != null && !mirror.getLayout().isEmpty()) {
|
||||
repository.setLayout(getLayout(mirror.getLayout()));
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ import org.apache.maven.project.ProjectBuildingException;
|
|||
import org.apache.maven.project.collector.MultiModuleCollectionStrategy;
|
||||
import org.apache.maven.project.collector.PomlessCollectionStrategy;
|
||||
import org.apache.maven.project.collector.RequestPomCollectionStrategy;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -202,7 +201,7 @@ public class DefaultGraphBuilder implements GraphBuilder {
|
|||
throws MavenExecutionException {
|
||||
List<MavenProject> result = projects;
|
||||
|
||||
if (StringUtils.isNotEmpty(request.getResumeFrom())) {
|
||||
if (request.getResumeFrom() != null && !request.getResumeFrom().isEmpty()) {
|
||||
File reactorDirectory = projectSelector.getBaseDirectoryFromRequest(request);
|
||||
|
||||
String selector = request.getResumeFrom();
|
||||
|
|
|
@ -60,7 +60,6 @@ import org.apache.maven.plugin.lifecycle.Phase;
|
|||
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
|
||||
|
@ -317,8 +316,10 @@ public class DefaultLifecycleExecutionPlanCalculator implements LifecycleExecuti
|
|||
if (parameterConfiguration != null) {
|
||||
Map<String, String> attributes = new HashMap<>(parameterConfiguration.getAttributes());
|
||||
|
||||
if (StringUtils.isEmpty(parameterConfiguration.getAttribute("implementation"))
|
||||
&& StringUtils.isNotEmpty(parameter.getImplementation())) {
|
||||
String attributeForImplementation = parameterConfiguration.getAttribute("implementation");
|
||||
String parameterForImplementation = parameter.getImplementation();
|
||||
if ((attributeForImplementation == null || attributeForImplementation.isEmpty())
|
||||
&& ((parameterForImplementation != null) && !parameterForImplementation.isEmpty())) {
|
||||
attributes.put("implementation", parameter.getImplementation());
|
||||
}
|
||||
|
||||
|
@ -376,7 +377,8 @@ public class DefaultLifecycleExecutionPlanCalculator implements LifecycleExecuti
|
|||
|
||||
List<MojoExecution> forkedExecutions;
|
||||
|
||||
if (StringUtils.isNotEmpty(mojoDescriptor.getExecutePhase())) {
|
||||
if (mojoDescriptor.getExecutePhase() != null
|
||||
&& !mojoDescriptor.getExecutePhase().isEmpty()) {
|
||||
forkedExecutions =
|
||||
calculateForkedLifecycle(mojoExecution, session, forkedProject, alreadyPlannedExecutions);
|
||||
} else {
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.apache.maven.model.Plugin;
|
|||
import org.apache.maven.model.PluginExecution;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -208,7 +207,7 @@ public class DefaultLifecyclePluginAnalyzer implements LifeCyclePluginAnalyzer {
|
|||
private GoalSpec parseGoalSpec(String goalSpec) {
|
||||
GoalSpec gs = new GoalSpec();
|
||||
|
||||
String[] p = StringUtils.split(goalSpec.trim(), ":");
|
||||
String[] p = goalSpec.trim().split(":");
|
||||
|
||||
if (p.length == 3) {
|
||||
// <groupId>:<artifactId>:<goal>
|
||||
|
|
|
@ -23,8 +23,8 @@ import javax.inject.Named;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleNotFoundException;
|
||||
|
@ -38,7 +38,6 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
|||
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -71,8 +70,14 @@ public class DefaultLifecycleTaskSegmentCalculator implements LifecycleTaskSegme
|
|||
|
||||
List<String> tasks = session.getGoals();
|
||||
|
||||
if ((tasks == null || tasks.isEmpty()) && !StringUtils.isEmpty(rootProject.getDefaultGoal())) {
|
||||
tasks = Arrays.asList(StringUtils.split(rootProject.getDefaultGoal()));
|
||||
if ((tasks == null || tasks.isEmpty())
|
||||
&& (rootProject.getDefaultGoal() != null
|
||||
&& !rootProject.getDefaultGoal().isEmpty())) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(rootProject.getDefaultGoal());
|
||||
tasks = new ArrayList<>();
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
tasks.add(tokenizer.nextToken());
|
||||
}
|
||||
}
|
||||
|
||||
return calculateTaskSegments(session, tasks);
|
||||
|
|
|
@ -28,8 +28,6 @@ import java.util.Optional;
|
|||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Mojo (goals) bindings to a lifecycle phase.
|
||||
*
|
||||
|
@ -57,7 +55,7 @@ public class LifecyclePhase {
|
|||
mojos = new ArrayList<>();
|
||||
|
||||
if (goals != null && !goals.isEmpty()) {
|
||||
String[] mojoGoals = StringUtils.split(goals, ",");
|
||||
String[] mojoGoals = goals.split(",");
|
||||
mojos = Arrays.stream(mojoGoals).map(fromGoalIntoLifecycleMojo).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.maven.plugin;
|
|||
|
||||
import org.apache.maven.project.DuplicateArtifactAttachmentException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Exception in the plugin manager.
|
||||
|
@ -65,7 +64,7 @@ public class PluginExecutionException extends PluginManagerException {
|
|||
message = "Mojo execution failed";
|
||||
}
|
||||
|
||||
if (cause != null && StringUtils.isNotEmpty(cause.getMessage())) {
|
||||
if (cause != null && cause.getMessage() != null && !cause.getMessage().isEmpty()) {
|
||||
message += ": " + cause.getMessage();
|
||||
} else {
|
||||
message += ".";
|
||||
|
|
|
@ -99,7 +99,6 @@ import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
|
|||
import org.codehaus.plexus.configuration.PlexusConfiguration;
|
||||
import org.codehaus.plexus.configuration.PlexusConfigurationException;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
|
@ -193,7 +192,10 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
|
|||
|
||||
PluginDescriptor descriptor = extractPluginDescriptor(pluginArtifact, plugin);
|
||||
|
||||
if (StringUtils.isBlank(descriptor.getRequiredMavenVersion())) {
|
||||
boolean isBlankVersion = descriptor.getRequiredMavenVersion() == null
|
||||
|| descriptor.getRequiredMavenVersion().trim().isEmpty();
|
||||
|
||||
if (isBlankVersion) {
|
||||
// only take value from underlying POM if plugin descriptor has no explicit Maven requirement
|
||||
descriptor.setRequiredMavenVersion(artifact.getProperty("requiredMavenVersion", null));
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.apache.maven.RepositoryUtils;
|
|||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.PluginResolutionException;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
|
@ -240,7 +239,7 @@ public class DefaultPluginDependenciesResolver implements PluginDependenciesReso
|
|||
org.eclipse.aether.artifact.Artifact art = dep.getArtifact();
|
||||
|
||||
buffer.append(art);
|
||||
if (StringUtils.isNotEmpty(dep.getScope())) {
|
||||
if (dep.getScope() != null && !dep.getScope().isEmpty()) {
|
||||
buffer.append(':').append(dep.getScope());
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import javax.inject.Singleton;
|
|||
import org.apache.maven.plugin.MavenPluginPrerequisitesChecker;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.rtinfo.RuntimeInformation;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -44,7 +43,11 @@ public class MavenPluginMavenPrerequisiteChecker implements MavenPluginPrerequis
|
|||
@Override
|
||||
public void accept(PluginDescriptor pluginDescriptor) {
|
||||
String requiredMavenVersion = pluginDescriptor.getRequiredMavenVersion();
|
||||
if (StringUtils.isNotBlank(requiredMavenVersion)) {
|
||||
|
||||
boolean isBlankVersion =
|
||||
requiredMavenVersion == null || requiredMavenVersion.trim().isEmpty();
|
||||
|
||||
if (!isBlankVersion) {
|
||||
boolean isRequirementMet = false;
|
||||
try {
|
||||
isRequirementMet = runtimeInformation.isMavenVersion(requiredMavenVersion);
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.apache.maven.plugin.version.PluginVersionRequest;
|
|||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolver;
|
||||
import org.apache.maven.plugin.version.PluginVersionResult;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.RepositoryEvent;
|
||||
import org.eclipse.aether.RepositoryEvent.EventType;
|
||||
import org.eclipse.aether.RepositoryListener;
|
||||
|
@ -299,15 +298,21 @@ public class DefaultPluginVersionResolver implements PluginVersionResolver {
|
|||
private void mergeMetadata(Versions versions, Metadata source, ArtifactRepository repository) {
|
||||
Versioning versioning = source.getVersioning();
|
||||
if (versioning != null) {
|
||||
String timestamp = StringUtils.clean(versioning.getLastUpdated());
|
||||
String timestamp = versioning.getLastUpdated() == null
|
||||
? ""
|
||||
: versioning.getLastUpdated().trim();
|
||||
|
||||
if (StringUtils.isNotEmpty(versioning.getRelease()) && timestamp.compareTo(versions.releaseTimestamp) > 0) {
|
||||
if (versioning.getRelease() != null
|
||||
&& !versioning.getRelease().isEmpty()
|
||||
&& timestamp.compareTo(versions.releaseTimestamp) > 0) {
|
||||
versions.releaseVersion = versioning.getRelease();
|
||||
versions.releaseTimestamp = timestamp;
|
||||
versions.releaseRepository = repository;
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(versioning.getLatest()) && timestamp.compareTo(versions.latestTimestamp) > 0) {
|
||||
if (versioning.getLatest() != null
|
||||
&& !versioning.getLatest().isEmpty()
|
||||
&& timestamp.compareTo(versions.latestTimestamp) > 0) {
|
||||
versions.latestVersion = versioning.getLatest();
|
||||
versions.latestTimestamp = timestamp;
|
||||
versions.latestRepository = repository;
|
||||
|
|
|
@ -24,17 +24,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.maven.RepositoryUtils;
|
||||
|
@ -72,7 +62,6 @@ import org.apache.maven.model.root.RootLocator;
|
|||
import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
|
||||
import org.apache.maven.repository.internal.ModelCacheFactory;
|
||||
import org.codehaus.plexus.util.Os;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.RequestTrace;
|
||||
|
@ -91,6 +80,7 @@ import org.slf4j.LoggerFactory;
|
|||
@Named
|
||||
@Singleton
|
||||
public class DefaultProjectBuilder implements ProjectBuilder {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final ModelBuilder modelBuilder;
|
||||
private final ModelProcessor modelProcessor;
|
||||
|
@ -739,7 +729,7 @@ public class DefaultProjectBuilder implements ProjectBuilder {
|
|||
if (extensions != null) {
|
||||
for (Extension ext : extensions) {
|
||||
String version;
|
||||
if (StringUtils.isEmpty(ext.getVersion())) {
|
||||
if (ext.getVersion() == null || ext.getVersion().isEmpty()) {
|
||||
version = "RELEASE";
|
||||
} else {
|
||||
version = ext.getVersion();
|
||||
|
@ -821,7 +811,10 @@ public class DefaultProjectBuilder implements ProjectBuilder {
|
|||
&& project.getDistributionManagement().getRepository() != null) {
|
||||
try {
|
||||
DeploymentRepository r = project.getDistributionManagement().getRepository();
|
||||
if (!StringUtils.isEmpty(r.getId()) && !StringUtils.isEmpty(r.getUrl())) {
|
||||
if (r.getId() != null
|
||||
&& !r.getId().isEmpty()
|
||||
&& r.getUrl() != null
|
||||
&& !r.getUrl().isEmpty()) {
|
||||
ArtifactRepository repo = MavenRepositorySystem.buildArtifactRepository(r);
|
||||
repositorySystem.injectProxy(projectBuildingRequest.getRepositorySession(), Arrays.asList(repo));
|
||||
repositorySystem.injectAuthentication(
|
||||
|
@ -839,7 +832,10 @@ public class DefaultProjectBuilder implements ProjectBuilder {
|
|||
&& project.getDistributionManagement().getSnapshotRepository() != null) {
|
||||
try {
|
||||
DeploymentRepository r = project.getDistributionManagement().getSnapshotRepository();
|
||||
if (!StringUtils.isEmpty(r.getId()) && !StringUtils.isEmpty(r.getUrl())) {
|
||||
if (r.getId() != null
|
||||
&& !r.getId().isEmpty()
|
||||
&& r.getUrl() != null
|
||||
&& !r.getUrl().isEmpty()) {
|
||||
ArtifactRepository repo = MavenRepositorySystem.buildArtifactRepository(r);
|
||||
repositorySystem.injectProxy(projectBuildingRequest.getRepositorySession(), Arrays.asList(repo));
|
||||
repositorySystem.injectAuthentication(
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.apache.maven.artifact.Artifact;
|
|||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
import org.apache.maven.model.Exclusion;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
|
@ -101,9 +100,12 @@ public class DefaultProjectDependenciesResolver implements ProjectDependenciesRe
|
|||
|
||||
if (project.getDependencyArtifacts() == null) {
|
||||
for (Dependency dependency : project.getDependencies()) {
|
||||
if (StringUtils.isEmpty(dependency.getGroupId())
|
||||
|| StringUtils.isEmpty(dependency.getArtifactId())
|
||||
|| StringUtils.isEmpty(dependency.getVersion())) {
|
||||
if (dependency.getGroupId() == null
|
||||
|| dependency.getGroupId().isEmpty()
|
||||
|| dependency.getArtifactId() == null
|
||||
|| dependency.getArtifactId().isEmpty()
|
||||
|| dependency.getVersion() == null
|
||||
|| dependency.getVersion().isEmpty()) {
|
||||
// guard against case where best-effort resolution for invalid models is requested
|
||||
continue;
|
||||
}
|
||||
|
@ -224,7 +226,7 @@ public class DefaultProjectDependenciesResolver implements ProjectDependenciesRe
|
|||
org.eclipse.aether.artifact.Artifact art = dep.getArtifact();
|
||||
|
||||
buffer.append(art);
|
||||
if (StringUtils.isNotEmpty(dep.getScope())) {
|
||||
if (dep.getScope() != null && !dep.getScope().isEmpty()) {
|
||||
buffer.append(':').append(dep.getScope());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ package org.apache.maven.toolchain.java;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -31,7 +33,6 @@ import org.apache.maven.toolchain.RequirementMatcherFactory;
|
|||
import org.apache.maven.toolchain.ToolchainFactory;
|
||||
import org.apache.maven.toolchain.ToolchainPrivate;
|
||||
import org.apache.maven.toolchain.model.ToolchainModel;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -86,12 +87,12 @@ public class JavaToolchainFactory implements ToolchainFactory {
|
|||
throw new MisconfiguredToolchainException(
|
||||
"Java toolchain without the " + JavaToolchainImpl.KEY_JAVAHOME + " configuration element.");
|
||||
}
|
||||
File normal = new File(FileUtils.normalize(javahome.getValue()));
|
||||
if (normal.exists()) {
|
||||
jtc.setJavaHome(FileUtils.normalize(javahome.getValue()));
|
||||
Path normal = Paths.get(javahome.getValue()).normalize();
|
||||
if (Files.exists(normal)) {
|
||||
jtc.setJavaHome(Paths.get(javahome.getValue()).normalize().toString());
|
||||
} else {
|
||||
throw new MisconfiguredToolchainException(
|
||||
"Non-existing JDK home configuration at " + normal.getAbsolutePath());
|
||||
"Non-existing JDK home configuration at " + normal.toAbsolutePath());
|
||||
}
|
||||
|
||||
return jtc;
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.maven.toolchain.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.apache.maven.toolchain.DefaultToolchain;
|
||||
import org.apache.maven.toolchain.model.ToolchainModel;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.Os;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
|
@ -53,25 +54,24 @@ public class JavaToolchainImpl extends DefaultToolchain implements JavaToolchain
|
|||
}
|
||||
|
||||
public String findTool(String toolName) {
|
||||
File toRet = findTool(toolName, new File(FileUtils.normalize(getJavaHome())));
|
||||
Path toRet = findTool(toolName, Paths.get(getJavaHome()).normalize());
|
||||
if (toRet != null) {
|
||||
return toRet.getAbsolutePath();
|
||||
return toRet.toAbsolutePath().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static File findTool(String toolName, File installDir) {
|
||||
File bin = new File(installDir, "bin"); // NOI18N
|
||||
if (bin.exists()) {
|
||||
boolean isWindows = Os.isFamily("windows"); // NOI18N
|
||||
if (isWindows) {
|
||||
File tool = new File(bin, toolName + ".exe");
|
||||
if (tool.exists()) {
|
||||
private static Path findTool(String toolName, Path installDir) {
|
||||
Path bin = installDir.resolve("bin"); // NOI18N
|
||||
if (Files.isDirectory(bin)) {
|
||||
if (Os.isFamily("windows")) { // NOI18N
|
||||
Path tool = bin.resolve(toolName + ".exe");
|
||||
if (Files.exists(tool)) {
|
||||
return tool;
|
||||
}
|
||||
}
|
||||
File tool = new File(bin, toolName);
|
||||
if (tool.exists()) {
|
||||
Path tool = bin.resolve(toolName);
|
||||
if (Files.exists(tool)) {
|
||||
return tool;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.maven.settings;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -34,8 +35,7 @@ import org.apache.maven.project.harness.PomTestWrapper;
|
|||
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
||||
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
|
||||
import org.codehaus.plexus.testing.PlexusTest;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import org.codehaus.plexus.util.xml.XmlStreamReader;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
|
||||
import org.eclipse.aether.repository.LocalRepository;
|
||||
|
@ -120,10 +120,10 @@ class PomConstructionWithSettingsTest {
|
|||
return new PomTestWrapper(pomFile, projectBuilder.build(pomFile, config).getProject());
|
||||
}
|
||||
|
||||
private static Settings readSettingsFile(File settingsFile) throws IOException, XmlPullParserException {
|
||||
private static Settings readSettingsFile(File settingsFile) throws IOException, XMLStreamException {
|
||||
Settings settings = null;
|
||||
|
||||
try (Reader reader = ReaderFactory.newXmlReader(settingsFile)) {
|
||||
try (Reader reader = new XmlStreamReader(settingsFile)) {
|
||||
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
|
||||
|
||||
settings = modelReader.read(reader);
|
||||
|
|
|
@ -107,7 +107,6 @@ import org.codehaus.plexus.interpolation.AbstractValueSource;
|
|||
import org.codehaus.plexus.interpolation.BasicInterpolator;
|
||||
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
|
||||
import org.codehaus.plexus.logging.LoggerManager;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.DefaultRepositoryCache;
|
||||
import org.eclipse.aether.transfer.TransferListener;
|
||||
import org.slf4j.ILoggerFactory;
|
||||
|
@ -851,7 +850,7 @@ public class MavenCli {
|
|||
List<File> jars = new ArrayList<>();
|
||||
|
||||
if (extClassPath != null && !extClassPath.isEmpty()) {
|
||||
for (String jar : StringUtils.split(extClassPath, File.pathSeparator)) {
|
||||
for (String jar : extClassPath.split(File.pathSeparator)) {
|
||||
File file = resolveFile(new File(jar), cliRequest.workingDirectory);
|
||||
|
||||
slf4jLogger.debug(" included '{}'", file);
|
||||
|
@ -1051,7 +1050,7 @@ public class MavenCli {
|
|||
ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
|
||||
String referenceKey = "";
|
||||
|
||||
if (StringUtils.isNotEmpty(summary.getReference())) {
|
||||
if (summary.getReference() != null && !summary.getReference().isEmpty()) {
|
||||
referenceKey =
|
||||
references.computeIfAbsent(summary.getReference(), k -> "[Help " + (references.size() + 1) + "]");
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.apache.maven.logwrapper.MavenSlf4jWrapperFactory;
|
|||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -436,9 +435,9 @@ public class ExecutionEventLogger extends AbstractExecutionListener {
|
|||
|
||||
private void appendForkInfo(MessageBuilder buffer, MojoDescriptor md) {
|
||||
StringBuilder buff = new StringBuilder();
|
||||
if (StringUtils.isNotEmpty(md.getExecutePhase())) {
|
||||
if (md.getExecutePhase() != null && !md.getExecutePhase().isEmpty()) {
|
||||
// forked phase
|
||||
if (StringUtils.isNotEmpty(md.getExecuteLifecycle())) {
|
||||
if (md.getExecuteLifecycle() != null && !md.getExecuteLifecycle().isEmpty()) {
|
||||
buff.append('[');
|
||||
buff.append(md.getExecuteLifecycle());
|
||||
buff.append(']');
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
package org.apache.maven.cli.logging;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.maven.cli.logging.impl.UnsupportedSlf4jBindingConfiguration;
|
||||
import org.codehaus.plexus.util.PropertyUtils;
|
||||
import org.slf4j.ILoggerFactory;
|
||||
|
||||
/**
|
||||
|
@ -47,8 +47,14 @@ public class Slf4jConfigurationFactory {
|
|||
while (resources.hasMoreElements()) {
|
||||
URL resource = resources.nextElement();
|
||||
try {
|
||||
Properties conf = PropertyUtils.loadProperties(resource.openStream());
|
||||
String impl = conf.getProperty(slf4jBinding);
|
||||
InputStream is = resource.openStream();
|
||||
final Properties properties = new Properties();
|
||||
if (is != null) {
|
||||
try (InputStream in = is) {
|
||||
properties.load(in);
|
||||
}
|
||||
}
|
||||
String impl = properties.getProperty(slf4jBinding);
|
||||
if (impl != null) {
|
||||
return (Slf4jConfiguration) Class.forName(impl).newInstance();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.apache.maven.api.model.Reporting;
|
|||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.merge.MavenModelMerger;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Handles inheritance of model values.
|
||||
|
@ -136,10 +135,17 @@ public class DefaultInheritanceAssembler implements InheritanceAssembler {
|
|||
Object childDirectory = context.get(CHILD_DIRECTORY);
|
||||
Object childPathAdjustment = context.get(CHILD_PATH_ADJUSTMENT);
|
||||
|
||||
if (StringUtils.isBlank(parentUrl)
|
||||
|| childDirectory == null
|
||||
|| childPathAdjustment == null
|
||||
|| !appendPath) {
|
||||
boolean isBlankParentUrl = true;
|
||||
|
||||
if (parentUrl != null) {
|
||||
for (int i = 0; i < parentUrl.length(); i++) {
|
||||
if (!Character.isWhitespace(parentUrl.charAt(i))) {
|
||||
isBlankParentUrl = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlankParentUrl || childDirectory == null || childPathAdjustment == null || !appendPath) {
|
||||
return parentUrl;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,13 @@ import java.io.IOException;
|
|||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.maven.api.model.Model;
|
||||
import org.apache.maven.model.v4.MavenXpp3Writer;
|
||||
import org.codehaus.plexus.util.WriterFactory;
|
||||
import org.codehaus.plexus.util.xml.XmlStreamWriter;
|
||||
|
||||
/**
|
||||
* Handles serialization of a model into some kind of textual format like XML.
|
||||
|
@ -48,7 +49,7 @@ public class DefaultModelWriter implements ModelWriter {
|
|||
|
||||
output.getParentFile().mkdirs();
|
||||
|
||||
write(WriterFactory.newXmlWriter(output), options, model);
|
||||
write(new XmlStreamWriter(Files.newOutputStream(output.toPath())), options, model);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,7 +68,6 @@ public class DefaultModelWriter implements ModelWriter {
|
|||
Objects.requireNonNull(model, "model cannot be null");
|
||||
|
||||
String encoding = model.getModelEncoding();
|
||||
// TODO Use StringUtils here
|
||||
if (encoding == null || encoding.length() <= 0) {
|
||||
encoding = "UTF-8";
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ import org.apache.maven.api.model.RepositoryBase;
|
|||
import org.apache.maven.api.model.Scm;
|
||||
import org.apache.maven.api.model.Site;
|
||||
import org.apache.maven.model.v4.MavenMerger;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The domain-specific model merger for the Maven POM, overriding generic code from parent class when necessary with
|
||||
|
@ -453,9 +452,9 @@ public class MavenModelMerger extends MavenMerger {
|
|||
Site.Builder builder, Site target, Site source, boolean sourceDominant, Map<Object, Object> context) {}
|
||||
|
||||
protected boolean isSiteEmpty(Site site) {
|
||||
return StringUtils.isEmpty(site.getId())
|
||||
&& StringUtils.isEmpty(site.getName())
|
||||
&& StringUtils.isEmpty(site.getUrl());
|
||||
return (site.getId() == null || site.getId().isEmpty())
|
||||
&& (site.getName() == null || site.getName().isEmpty())
|
||||
&& (site.getUrl() == null || site.getUrl().isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.apache.maven.api.model.Plugin;
|
|||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.merge.MavenModelMerger;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Handles normalization of a model.
|
||||
|
@ -138,7 +137,7 @@ public class DefaultModelNormalizer implements ModelNormalizer {
|
|||
|
||||
private Dependency injectDependency(Dependency d) {
|
||||
// we cannot set this directly in the MDO due to the interactions with dependency management
|
||||
return StringUtils.isEmpty(d.getScope()) ? d.withScope("compile") : d;
|
||||
return (d.getScope() == null || d.getScope().isEmpty()) ? d.withScope("compile") : d;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
|||
import org.apache.maven.model.path.ProfileActivationFilePathInterpolator;
|
||||
import org.apache.maven.model.profile.ProfileActivationContext;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Determines profile activation based on the existence/absence of some file.
|
||||
|
@ -75,10 +74,10 @@ public class FileProfileActivator implements ProfileActivator {
|
|||
String path;
|
||||
boolean missing;
|
||||
|
||||
if (StringUtils.isNotEmpty(file.getExists())) {
|
||||
if (file.getExists() != null && !file.getExists().isEmpty()) {
|
||||
path = file.getExists();
|
||||
missing = false;
|
||||
} else if (StringUtils.isNotEmpty(file.getMissing())) {
|
||||
} else if (file.getMissing() != null && !file.getMissing().isEmpty()) {
|
||||
path = file.getMissing();
|
||||
missing = true;
|
||||
} else {
|
||||
|
|
|
@ -60,7 +60,6 @@ import org.apache.maven.model.building.ModelProblemCollector;
|
|||
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||
import org.apache.maven.model.interpolation.ModelVersionProcessor;
|
||||
import org.apache.maven.model.v4.MavenModelVersion;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -301,10 +300,10 @@ public class DefaultModelValidator implements ModelValidator {
|
|||
String path;
|
||||
boolean missing;
|
||||
|
||||
if (StringUtils.isNotEmpty(file.getExists())) {
|
||||
if (file.getExists() != null && !file.getExists().isEmpty()) {
|
||||
path = file.getExists();
|
||||
missing = false;
|
||||
} else if (StringUtils.isNotEmpty(file.getMissing())) {
|
||||
} else if (file.getMissing() != null && !file.getMissing().isEmpty()) {
|
||||
path = file.getMissing();
|
||||
missing = true;
|
||||
} else {
|
||||
|
@ -446,7 +445,17 @@ public class DefaultModelValidator implements ModelValidator {
|
|||
|
||||
for (int i = 0, n = m.getModules().size(); i < n; i++) {
|
||||
String module = m.getModules().get(i);
|
||||
if (StringUtils.isBlank(module)) {
|
||||
|
||||
boolean isBlankModule = true;
|
||||
if (module != null) {
|
||||
for (int j = 0; j < module.length(); j++) {
|
||||
if (!Character.isWhitespace(module.charAt(j))) {
|
||||
isBlankModule = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlankModule) {
|
||||
addViolation(
|
||||
problems,
|
||||
Severity.ERROR,
|
||||
|
@ -600,7 +609,8 @@ public class DefaultModelValidator implements ModelValidator {
|
|||
key,
|
||||
"must be 'pom' to import the managed dependencies.",
|
||||
dependency);
|
||||
} else if (StringUtils.isNotEmpty(dependency.getClassifier())) {
|
||||
} else if (dependency.getClassifier() != null
|
||||
&& !dependency.getClassifier().isEmpty()) {
|
||||
addViolation(
|
||||
problems,
|
||||
errOn30,
|
||||
|
@ -893,7 +903,7 @@ public class DefaultModelValidator implements ModelValidator {
|
|||
d);
|
||||
}
|
||||
}
|
||||
} else if (StringUtils.isNotEmpty(d.getSystemPath())) {
|
||||
} else if (d.getSystemPath() != null && !d.getSystemPath().isEmpty()) {
|
||||
addViolation(
|
||||
problems,
|
||||
Severity.ERROR,
|
||||
|
@ -1547,8 +1557,8 @@ public class DefaultModelValidator implements ModelValidator {
|
|||
*/
|
||||
private static int compareModelVersions(String first, String second) {
|
||||
// we use a dedicated comparator because we control our model version scheme.
|
||||
String[] firstSegments = StringUtils.split(first, ".");
|
||||
String[] secondSegments = StringUtils.split(second, ".");
|
||||
String[] firstSegments = first.split("\\.");
|
||||
String[] secondSegments = second.split("\\.");
|
||||
for (int i = 0; i < Math.max(firstSegments.length, secondSegments.length); i++) {
|
||||
int result = Long.valueOf(i < firstSegments.length ? firstSegments[i] : "0")
|
||||
.compareTo(Long.valueOf(i < secondSegments.length ? secondSegments[i] : "0"));
|
||||
|
@ -1735,7 +1745,9 @@ public class DefaultModelValidator implements ModelValidator {
|
|||
}
|
||||
|
||||
private static boolean equals(String s1, String s2) {
|
||||
return StringUtils.clean(s1).equals(StringUtils.clean(s2));
|
||||
String c1 = s1 == null ? "" : s1.trim();
|
||||
String c2 = s2 == null ? "" : s2.trim();
|
||||
return c1.equals(c2);
|
||||
}
|
||||
|
||||
private static Severity getSeverity(ModelBuildingRequest request, int errorThreshold) {
|
||||
|
|
|
@ -18,16 +18,16 @@
|
|||
*/
|
||||
package org.apache.maven.model.io.xpp3;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
|
||||
import org.codehaus.plexus.util.xml.pull.MXParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
public class MavenXpp3Reader {
|
||||
private boolean addDefaultEntities = true;
|
||||
|
@ -52,32 +52,35 @@ public class MavenXpp3Reader {
|
|||
} // -- boolean getAddDefaultEntities()
|
||||
|
||||
/**
|
||||
* @see ReaderFactory#newXmlReader
|
||||
*
|
||||
* @param reader a reader object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Model
|
||||
*/
|
||||
public Model read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser =
|
||||
addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
|
||||
parser.setInput(reader);
|
||||
public Model read(Reader reader, boolean strict) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
XMLStreamReader parser = null;
|
||||
try {
|
||||
parser = factory.createXMLStreamReader(reader);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return read(parser, strict);
|
||||
} // -- Model read( Reader, boolean )
|
||||
|
||||
/**
|
||||
* @see ReaderFactory#newXmlReader
|
||||
*
|
||||
* @param reader a reader object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Model
|
||||
*/
|
||||
public Model read(Reader reader) throws IOException, XmlPullParserException {
|
||||
public Model read(Reader reader) throws IOException, XMLStreamException {
|
||||
return read(reader, true);
|
||||
} // -- Model read( Reader )
|
||||
|
||||
|
@ -87,12 +90,16 @@ public class MavenXpp3Reader {
|
|||
* @param in a in object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Model
|
||||
*/
|
||||
public Model read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
|
||||
return read(ReaderFactory.newXmlReader(in), strict);
|
||||
public Model read(InputStream in, boolean strict) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
StreamSource streamSource = new StreamSource(in, null);
|
||||
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
|
||||
return read(parser, strict);
|
||||
} // -- Model read( InputStream, boolean )
|
||||
|
||||
/**
|
||||
|
@ -100,12 +107,16 @@ public class MavenXpp3Reader {
|
|||
*
|
||||
* @param in a in object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Model
|
||||
*/
|
||||
public Model read(InputStream in) throws IOException, XmlPullParserException {
|
||||
return read(ReaderFactory.newXmlReader(in));
|
||||
public Model read(InputStream in) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
StreamSource streamSource = new StreamSource(in, null);
|
||||
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
|
||||
return read(parser, true);
|
||||
} // -- Model read( InputStream )
|
||||
|
||||
/**
|
||||
|
@ -114,11 +125,11 @@ public class MavenXpp3Reader {
|
|||
* @param parser a parser object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Model
|
||||
*/
|
||||
public Model read(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
|
||||
public Model read(XMLStreamReader parser, boolean strict) throws IOException, XMLStreamException {
|
||||
org.apache.maven.model.v4.MavenXpp3Reader reader = contentTransformer != null
|
||||
? new org.apache.maven.model.v4.MavenXpp3Reader(contentTransformer::transform)
|
||||
: new org.apache.maven.model.v4.MavenXpp3Reader();
|
||||
|
|
|
@ -18,16 +18,17 @@
|
|||
*/
|
||||
package org.apache.maven.model.io.xpp3;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.apache.maven.model.InputSource;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
|
||||
import org.codehaus.plexus.util.xml.pull.MXParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
public class MavenXpp3ReaderEx {
|
||||
private boolean addDefaultEntities = true;
|
||||
|
@ -52,73 +53,73 @@ public class MavenXpp3ReaderEx {
|
|||
} // -- boolean getAddDefaultEntities()
|
||||
|
||||
/**
|
||||
* @param reader a reader object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* any.
|
||||
* @param reader a reader object
|
||||
* @param strict a strict object
|
||||
* @return Model
|
||||
* @throws IOException IOException if an I/O error occurs while reading from the underlying source
|
||||
* @throws XMLStreamException XMLStreamException if an error occurs while parser xml
|
||||
*/
|
||||
public Model read(Reader reader, boolean strict, InputSource source) throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser =
|
||||
addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
|
||||
parser.setInput(reader);
|
||||
return read(parser, strict, source);
|
||||
public Model read(Reader reader, boolean strict, InputSource source) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
try {
|
||||
XMLStreamReader parser = factory.createXMLStreamReader(reader);
|
||||
return read(parser, strict, source);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} // -- Model read( Reader, boolean )
|
||||
|
||||
/**
|
||||
* @param reader a reader object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* any.
|
||||
* @param reader a reader object
|
||||
* @return Model
|
||||
* @throws IOException IOException if an I/O error occurs while reading from the underlying source
|
||||
* @throws XMLStreamException XMLStreamException if an error occurs while parser xml
|
||||
*/
|
||||
public Model read(Reader reader, InputSource source) throws IOException, XmlPullParserException {
|
||||
public Model read(Reader reader, InputSource source) throws IOException, XMLStreamException {
|
||||
return read(reader, true, source);
|
||||
} // -- Model read( Reader )
|
||||
|
||||
/**
|
||||
* Method read.
|
||||
*
|
||||
* @param in a in object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* any.
|
||||
* @param in a in object
|
||||
* @param strict a strict object
|
||||
* @return Model
|
||||
* @throws IOException IOException if an I/O error occurs while reading from the underlying source
|
||||
* @throws XMLStreamException XMLStreamException if an error occurs while parser xml
|
||||
*/
|
||||
public Model read(InputStream in, boolean strict, InputSource source) throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser =
|
||||
addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
|
||||
parser.setInput(in, null);
|
||||
public Model read(InputStream in, boolean strict, InputSource source) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
StreamSource streamSource = new StreamSource(in, null);
|
||||
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
|
||||
return read(parser, strict, source);
|
||||
} // -- Model read( InputStream, boolean )
|
||||
|
||||
/**
|
||||
* Method read.
|
||||
*
|
||||
* @param in a in object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* any.
|
||||
* @param in a in object
|
||||
* @return Model
|
||||
* @throws IOException IOException if an I/O error occurs while reading from the underlying source
|
||||
* @throws XMLStreamException XMLStreamException if an error occurs while parser xml
|
||||
*/
|
||||
public Model read(InputStream in, InputSource source) throws IOException, XmlPullParserException {
|
||||
public Model read(InputStream in, InputSource source) throws IOException, XMLStreamException {
|
||||
return read(in, true, source);
|
||||
} // -- Model read( InputStream )
|
||||
|
||||
/**
|
||||
* Method read.
|
||||
*
|
||||
* @param parser a parser object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* any.
|
||||
* @param parser a parser object
|
||||
* @param strict a strict object
|
||||
* @return Model
|
||||
* @throws IOException IOException if an I/O error occurs while reading from the underlying source
|
||||
* @throws XMLStreamException XMLStreamException if an error occurs while parser xml
|
||||
*/
|
||||
public Model read(XmlPullParser parser, boolean strict, InputSource source)
|
||||
throws IOException, XmlPullParserException {
|
||||
public Model read(XMLStreamReader parser, boolean strict, InputSource source)
|
||||
throws IOException, XMLStreamException {
|
||||
org.apache.maven.model.v4.MavenXpp3ReaderEx reader = contentTransformer != null
|
||||
? new org.apache.maven.model.v4.MavenXpp3ReaderEx(contentTransformer::transform)
|
||||
: new org.apache.maven.model.v4.MavenXpp3ReaderEx();
|
||||
|
@ -131,7 +132,7 @@ public class MavenXpp3ReaderEx {
|
|||
/**
|
||||
* Sets the state of the "add default entities" flag.
|
||||
*
|
||||
* @param addDefaultEntities a addDefaultEntities object.
|
||||
* @param addDefaultEntities a addDefaultEntities object
|
||||
*/
|
||||
public void setAddDefaultEntities(boolean addDefaultEntities) {
|
||||
this.addDefaultEntities = addDefaultEntities;
|
||||
|
@ -140,10 +141,11 @@ public class MavenXpp3ReaderEx {
|
|||
public interface ContentTransformer {
|
||||
/**
|
||||
* Interpolate the value read from the xpp3 document
|
||||
* @param source The source value
|
||||
* @param fieldName A description of the field being interpolated. The implementation may use this to
|
||||
* log stuff.
|
||||
* @return The interpolated value.
|
||||
*
|
||||
* @param source the source value
|
||||
* @param fieldName a description of the field being interpolated. The implementation may use this to
|
||||
* log stuff
|
||||
* @return the interpolated value
|
||||
*/
|
||||
String transform(String source, String fieldName);
|
||||
}
|
||||
|
|
|
@ -18,22 +18,6 @@
|
|||
*/
|
||||
package org.apache.maven.model.v4;
|
||||
|
||||
/*
|
||||
* Copyright The Codehaus Foundation.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -46,7 +30,6 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.maven.api.model.InputSource;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
|
@ -75,13 +58,13 @@ public class Xpp3DomPerfTest {
|
|||
}
|
||||
|
||||
@Benchmark
|
||||
public int readWithXpp3(AdditionState state) throws IOException, XmlPullParserException {
|
||||
public int readWithXpp3(AdditionState state) throws IOException {
|
||||
int i = 0;
|
||||
for (Path pom : state.poms) {
|
||||
try (InputStream is = Files.newInputStream(pom)) {
|
||||
new MavenXpp3ReaderEx().read(is, true, new InputSource("id", pom.toString()));
|
||||
i++;
|
||||
} catch (XmlPullParserException e) {
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException("Error parsing: " + pom, e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.codehaus.plexus.component.repository.ComponentDependency;
|
|||
import org.codehaus.plexus.component.repository.ComponentRequirement;
|
||||
import org.codehaus.plexus.configuration.PlexusConfiguration;
|
||||
import org.codehaus.plexus.configuration.PlexusConfigurationException;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.XmlStreamReader;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
@ -41,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
class PluginDescriptorBuilderTest {
|
||||
|
||||
private PluginDescriptor build(String resource) throws IOException, PlexusConfigurationException {
|
||||
Reader reader = ReaderFactory.newXmlReader(getClass().getResourceAsStream(resource));
|
||||
Reader reader = new XmlStreamReader(getClass().getResourceAsStream(resource));
|
||||
|
||||
return new PluginDescriptorBuilder().build(reader);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.apache.maven.artifact.repository.metadata.Snapshot;
|
|||
import org.apache.maven.artifact.repository.metadata.SnapshotVersion;
|
||||
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||
import org.apache.maven.artifact.repository.metadata.io.MetadataStaxReader;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.RepositoryCache;
|
||||
import org.eclipse.aether.RepositoryEvent;
|
||||
import org.eclipse.aether.RepositoryEvent.EventType;
|
||||
|
@ -211,7 +210,7 @@ public class DefaultVersionResolver implements VersionResolver {
|
|||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(result.getVersion())) {
|
||||
if (result.getVersion() == null || result.getVersion().isEmpty()) {
|
||||
throw new VersionResolutionException(result);
|
||||
}
|
||||
}
|
||||
|
@ -297,16 +296,16 @@ public class DefaultVersionResolver implements VersionResolver {
|
|||
|
||||
private void merge(
|
||||
Artifact artifact, Map<String, VersionInfo> infos, Versioning versioning, ArtifactRepository repository) {
|
||||
if (StringUtils.isNotEmpty(versioning.getRelease())) {
|
||||
if (versioning.getRelease() != null && !versioning.getRelease().isEmpty()) {
|
||||
merge(RELEASE, infos, versioning.getLastUpdated(), versioning.getRelease(), repository);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(versioning.getLatest())) {
|
||||
if (versioning.getLatest() != null && !versioning.getLatest().isEmpty()) {
|
||||
merge(LATEST, infos, versioning.getLastUpdated(), versioning.getLatest(), repository);
|
||||
}
|
||||
|
||||
for (SnapshotVersion sv : versioning.getSnapshotVersions()) {
|
||||
if (StringUtils.isNotEmpty(sv.getVersion())) {
|
||||
if (sv.getVersion() != null && !sv.getVersion().isEmpty()) {
|
||||
String key = getKey(sv.getClassifier(), sv.getExtension());
|
||||
merge(SNAPSHOT + key, infos, sv.getUpdated(), sv.getVersion(), repository);
|
||||
}
|
||||
|
@ -353,7 +352,7 @@ public class DefaultVersionResolver implements VersionResolver {
|
|||
}
|
||||
|
||||
private String getKey(String classifier, String extension) {
|
||||
return StringUtils.clean(classifier) + ':' + StringUtils.clean(extension);
|
||||
return (classifier == null ? "" : classifier.trim()) + ':' + (extension == null ? "" : extension.trim());
|
||||
}
|
||||
|
||||
private ArtifactRepository getRepository(
|
||||
|
|
|
@ -41,7 +41,6 @@ public final class RelocatedArtifact extends AbstractArtifact {
|
|||
|
||||
RelocatedArtifact(Artifact artifact, String groupId, String artifactId, String version, String message) {
|
||||
this.artifact = Objects.requireNonNull(artifact, "artifact cannot be null");
|
||||
// TODO Use StringUtils here
|
||||
this.groupId = (groupId != null && groupId.length() > 0) ? groupId : null;
|
||||
this.artifactId = (artifactId != null && artifactId.length() > 0) ? artifactId : null;
|
||||
this.version = (version != null && version.length() > 0) ? version : null;
|
||||
|
|
|
@ -18,15 +18,16 @@
|
|||
*/
|
||||
package org.apache.maven.settings.io.xpp3;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
|
||||
import org.codehaus.plexus.util.xml.pull.MXParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
@Deprecated
|
||||
public class SettingsXpp3Reader {
|
||||
|
@ -55,25 +56,30 @@ public class SettingsXpp3Reader {
|
|||
* @param reader a reader object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Settings
|
||||
*/
|
||||
public Settings read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser =
|
||||
addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
|
||||
parser.setInput(reader);
|
||||
public Settings read(Reader reader, boolean strict) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
XMLStreamReader parser = null;
|
||||
try {
|
||||
parser = factory.createXMLStreamReader(reader);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return read(parser, strict);
|
||||
} // -- Model read( Reader, boolean )
|
||||
|
||||
/**
|
||||
* @param reader a reader object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Model
|
||||
*/
|
||||
public Settings read(Reader reader) throws IOException, XmlPullParserException {
|
||||
public Settings read(Reader reader) throws IOException, XMLStreamException {
|
||||
return read(reader, true);
|
||||
} // -- Model read( Reader )
|
||||
|
||||
|
@ -83,14 +89,15 @@ public class SettingsXpp3Reader {
|
|||
* @param in a in object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Settings
|
||||
*/
|
||||
public Settings read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser =
|
||||
addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
|
||||
parser.setInput(in, null);
|
||||
public Settings read(InputStream in, boolean strict) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
StreamSource streamSource = new StreamSource(in, null);
|
||||
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
|
||||
return read(parser, strict);
|
||||
} // -- Model read( InputStream, boolean )
|
||||
|
||||
|
@ -99,11 +106,11 @@ public class SettingsXpp3Reader {
|
|||
*
|
||||
* @param in a in object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Settings
|
||||
*/
|
||||
public Settings read(InputStream in) throws IOException, XmlPullParserException {
|
||||
public Settings read(InputStream in) throws IOException, XMLStreamException {
|
||||
return read(in, true);
|
||||
} // -- Model read( InputStream )
|
||||
|
||||
|
@ -113,18 +120,18 @@ public class SettingsXpp3Reader {
|
|||
* @param parser a parser object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return Settings
|
||||
*/
|
||||
public Settings read(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
|
||||
public Settings read(XMLStreamReader parser, boolean strict) throws IOException, XMLStreamException {
|
||||
org.apache.maven.settings.v4.SettingsXpp3Reader reader = contentTransformer != null
|
||||
? new org.apache.maven.settings.v4.SettingsXpp3Reader(contentTransformer::transform)
|
||||
: new org.apache.maven.settings.v4.SettingsXpp3Reader();
|
||||
reader.setAddDefaultEntities(addDefaultEntities);
|
||||
org.apache.maven.api.settings.Settings settings = reader.read(parser, strict);
|
||||
return new Settings(settings);
|
||||
} // -- Model read( XmlPullParser, boolean )
|
||||
} // -- Model read( XMLStreamReader, boolean )
|
||||
|
||||
/**
|
||||
* Sets the state of the "add default entities" flag.
|
||||
|
|
|
@ -50,6 +50,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Collections;
|
||||
import org.apache.maven.api.annotations.Generated;
|
||||
import org.apache.maven.internal.xml.XmlNodeBuilder;
|
||||
import ${packageModelV4}.InputSource;
|
||||
|
@ -57,11 +58,10 @@ import ${packageModelV4}.InputLocation;
|
|||
#foreach ( $class in $model.allClasses )
|
||||
import ${packageModelV4}.${class.name};
|
||||
#end
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
|
||||
import org.codehaus.plexus.util.xml.pull.MXParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
@Deprecated
|
||||
@Generated
|
||||
|
@ -71,6 +71,277 @@ public class ${className} {
|
|||
|
||||
private final ContentTransformer contentTransformer;
|
||||
|
||||
/**
|
||||
* XSI namespace
|
||||
*/
|
||||
private static final String XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
|
||||
|
||||
private static final Map<String, String> DEFAULT_ENTITIES;
|
||||
|
||||
static {
|
||||
Map<String, String> entities = new HashMap<>();
|
||||
entities.put("nbsp", "\u00a0");
|
||||
entities.put("iexcl", "\u00a1");
|
||||
entities.put("cent", "\u00a2");
|
||||
entities.put("pound", "\u00a3");
|
||||
entities.put("curren", "\u00a4");
|
||||
entities.put("yen", "\u00a5");
|
||||
entities.put("brvbar", "\u00a6");
|
||||
entities.put("sect", "\u00a7");
|
||||
entities.put("uml", "\u00a8");
|
||||
entities.put("copy", "\u00a9");
|
||||
entities.put("ordf", "\u00aa");
|
||||
entities.put("laquo", "\u00ab");
|
||||
entities.put("not", "\u00ac");
|
||||
entities.put("shy", "\u00ad");
|
||||
entities.put("reg", "\u00ae");
|
||||
entities.put("macr", "\u00af");
|
||||
entities.put("deg", "\u00b0");
|
||||
entities.put("plusmn", "\u00b1");
|
||||
entities.put("sup2", "\u00b2");
|
||||
entities.put("sup3", "\u00b3");
|
||||
entities.put("acute", "\u00b4");
|
||||
entities.put("micro", "\u00b5");
|
||||
entities.put("para", "\u00b6");
|
||||
entities.put("middot", "\u00b7");
|
||||
entities.put("cedil", "\u00b8");
|
||||
entities.put("sup1", "\u00b9");
|
||||
entities.put("ordm", "\u00ba");
|
||||
entities.put("raquo", "\u00bb");
|
||||
entities.put("frac14", "\u00bc");
|
||||
entities.put("frac12", "\u00bd");
|
||||
entities.put("frac34", "\u00be");
|
||||
entities.put("iquest", "\u00bf");
|
||||
entities.put("Agrave", "\u00c0");
|
||||
entities.put("Aacute", "\u00c1");
|
||||
entities.put("Acirc", "\u00c2");
|
||||
entities.put("Atilde", "\u00c3");
|
||||
entities.put("Auml", "\u00c4");
|
||||
entities.put("Aring", "\u00c5");
|
||||
entities.put("AElig", "\u00c6");
|
||||
entities.put("Ccedil", "\u00c7");
|
||||
entities.put("Egrave", "\u00c8");
|
||||
entities.put("Eacute", "\u00c9");
|
||||
entities.put("Ecirc", "\u00ca");
|
||||
entities.put("Euml", "\u00cb");
|
||||
entities.put("Igrave", "\u00cc");
|
||||
entities.put("Iacute", "\u00cd");
|
||||
entities.put("Icirc", "\u00ce");
|
||||
entities.put("Iuml", "\u00cf");
|
||||
entities.put("ETH", "\u00d0");
|
||||
entities.put("Ntilde", "\u00d1");
|
||||
entities.put("Ograve", "\u00d2");
|
||||
entities.put("Oacute", "\u00d3");
|
||||
entities.put("Ocirc", "\u00d4");
|
||||
entities.put("Otilde", "\u00d5");
|
||||
entities.put("Ouml", "\u00d6");
|
||||
entities.put("times", "\u00d7");
|
||||
entities.put("Oslash", "\u00d8");
|
||||
entities.put("Ugrave", "\u00d9");
|
||||
entities.put("Uacute", "\u00da");
|
||||
entities.put("Ucirc", "\u00db");
|
||||
entities.put("Uuml", "\u00dc");
|
||||
entities.put("Yacute", "\u00dd");
|
||||
entities.put("THORN", "\u00de");
|
||||
entities.put("szlig", "\u00df");
|
||||
entities.put("agrave", "\u00e0");
|
||||
entities.put("aacute", "\u00e1");
|
||||
entities.put("acirc", "\u00e2");
|
||||
entities.put("atilde", "\u00e3");
|
||||
entities.put("auml", "\u00e4");
|
||||
entities.put("aring", "\u00e5");
|
||||
entities.put("aelig", "\u00e6");
|
||||
entities.put("ccedil", "\u00e7");
|
||||
entities.put("egrave", "\u00e8");
|
||||
entities.put("eacute", "\u00e9");
|
||||
entities.put("ecirc", "\u00ea");
|
||||
entities.put("euml", "\u00eb");
|
||||
entities.put("igrave", "\u00ec");
|
||||
entities.put("iacute", "\u00ed");
|
||||
entities.put("icirc", "\u00ee");
|
||||
entities.put("iuml", "\u00ef");
|
||||
entities.put("eth", "\u00f0");
|
||||
entities.put("ntilde", "\u00f1");
|
||||
entities.put("ograve", "\u00f2");
|
||||
entities.put("oacute", "\u00f3");
|
||||
entities.put("ocirc", "\u00f4");
|
||||
entities.put("otilde", "\u00f5");
|
||||
entities.put("ouml", "\u00f6");
|
||||
entities.put("divide", "\u00f7");
|
||||
entities.put("oslash", "\u00f8");
|
||||
entities.put("ugrave", "\u00f9");
|
||||
entities.put("uacute", "\u00fa");
|
||||
entities.put("ucirc", "\u00fb");
|
||||
entities.put("uuml", "\u00fc");
|
||||
entities.put("yacute", "\u00fd");
|
||||
entities.put("thorn", "\u00fe");
|
||||
entities.put("yuml", "\u00ff");
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Special entities
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
entities.put("OElig", "\u0152");
|
||||
entities.put("oelig", "\u0153");
|
||||
entities.put("Scaron", "\u0160");
|
||||
entities.put("scaron", "\u0161");
|
||||
entities.put("Yuml", "\u0178");
|
||||
entities.put("circ", "\u02c6");
|
||||
entities.put("tilde", "\u02dc");
|
||||
entities.put("ensp", "\u2002");
|
||||
entities.put("emsp", "\u2003");
|
||||
entities.put("thinsp", "\u2009");
|
||||
entities.put("zwnj", "\u200c");
|
||||
entities.put("zwj", "\u200d");
|
||||
entities.put("lrm", "\u200e");
|
||||
entities.put("rlm", "\u200f");
|
||||
entities.put("ndash", "\u2013");
|
||||
entities.put("mdash", "\u2014");
|
||||
entities.put("lsquo", "\u2018");
|
||||
entities.put("rsquo", "\u2019");
|
||||
entities.put("sbquo", "\u201a");
|
||||
entities.put("ldquo", "\u201c");
|
||||
entities.put("rdquo", "\u201d");
|
||||
entities.put("bdquo", "\u201e");
|
||||
entities.put("dagger", "\u2020");
|
||||
entities.put("Dagger", "\u2021");
|
||||
entities.put("permil", "\u2030");
|
||||
entities.put("lsaquo", "\u2039");
|
||||
entities.put("rsaquo", "\u203a");
|
||||
entities.put("euro", "\u20ac");
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Symbol entities
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
entities.put("fnof", "\u0192");
|
||||
entities.put("Alpha", "\u0391");
|
||||
entities.put("Beta", "\u0392");
|
||||
entities.put("Gamma", "\u0393");
|
||||
entities.put("Delta", "\u0394");
|
||||
entities.put("Epsilon", "\u0395");
|
||||
entities.put("Zeta", "\u0396");
|
||||
entities.put("Eta", "\u0397");
|
||||
entities.put("Theta", "\u0398");
|
||||
entities.put("Iota", "\u0399");
|
||||
entities.put("Kappa", "\u039a");
|
||||
entities.put("Lambda", "\u039b");
|
||||
entities.put("Mu", "\u039c");
|
||||
entities.put("Nu", "\u039d");
|
||||
entities.put("Xi", "\u039e");
|
||||
entities.put("Omicron", "\u039f");
|
||||
entities.put("Pi", "\u03a0");
|
||||
entities.put("Rho", "\u03a1");
|
||||
entities.put("Sigma", "\u03a3");
|
||||
entities.put("Tau", "\u03a4");
|
||||
entities.put("Upsilon", "\u03a5");
|
||||
entities.put("Phi", "\u03a6");
|
||||
entities.put("Chi", "\u03a7");
|
||||
entities.put("Psi", "\u03a8");
|
||||
entities.put("Omega", "\u03a9");
|
||||
entities.put("alpha", "\u03b1");
|
||||
entities.put("beta", "\u03b2");
|
||||
entities.put("gamma", "\u03b3");
|
||||
entities.put("delta", "\u03b4");
|
||||
entities.put("epsilon", "\u03b5");
|
||||
entities.put("zeta", "\u03b6");
|
||||
entities.put("eta", "\u03b7");
|
||||
entities.put("theta", "\u03b8");
|
||||
entities.put("iota", "\u03b9");
|
||||
entities.put("kappa", "\u03ba");
|
||||
entities.put("lambda", "\u03bb");
|
||||
entities.put("mu", "\u03bc");
|
||||
entities.put("nu", "\u03bd");
|
||||
entities.put("xi", "\u03be");
|
||||
entities.put("omicron", "\u03bf");
|
||||
entities.put("pi", "\u03c0");
|
||||
entities.put("rho", "\u03c1");
|
||||
entities.put("sigmaf", "\u03c2");
|
||||
entities.put("sigma", "\u03c3");
|
||||
entities.put("tau", "\u03c4");
|
||||
entities.put("upsilon", "\u03c5");
|
||||
entities.put("phi", "\u03c6");
|
||||
entities.put("chi", "\u03c7");
|
||||
entities.put("psi", "\u03c8");
|
||||
entities.put("omega", "\u03c9");
|
||||
entities.put("thetasym", "\u03d1");
|
||||
entities.put("upsih", "\u03d2");
|
||||
entities.put("piv", "\u03d6");
|
||||
entities.put("bull", "\u2022");
|
||||
entities.put("hellip", "\u2026");
|
||||
entities.put("prime", "\u2032");
|
||||
entities.put("Prime", "\u2033");
|
||||
entities.put("oline", "\u203e");
|
||||
entities.put("frasl", "\u2044");
|
||||
entities.put("weierp", "\u2118");
|
||||
entities.put("image", "\u2111");
|
||||
entities.put("real", "\u211c");
|
||||
entities.put("trade", "\u2122");
|
||||
entities.put("alefsym", "\u2135");
|
||||
entities.put("larr", "\u2190");
|
||||
entities.put("uarr", "\u2191");
|
||||
entities.put("rarr", "\u2192");
|
||||
entities.put("darr", "\u2193");
|
||||
entities.put("harr", "\u2194");
|
||||
entities.put("crarr", "\u21b5");
|
||||
entities.put("lArr", "\u21d0");
|
||||
entities.put("uArr", "\u21d1");
|
||||
entities.put("rArr", "\u21d2");
|
||||
entities.put("dArr", "\u21d3");
|
||||
entities.put("hArr", "\u21d4");
|
||||
entities.put("forall", "\u2200");
|
||||
entities.put("part", "\u2202");
|
||||
entities.put("exist", "\u2203");
|
||||
entities.put("empty", "\u2205");
|
||||
entities.put("nabla", "\u2207");
|
||||
entities.put("isin", "\u2208");
|
||||
entities.put("notin", "\u2209");
|
||||
entities.put("ni", "\u220b");
|
||||
entities.put("prod", "\u220f");
|
||||
entities.put("sum", "\u2211");
|
||||
entities.put("minus", "\u2212");
|
||||
entities.put("lowast", "\u2217");
|
||||
entities.put("radic", "\u221a");
|
||||
entities.put("prop", "\u221d");
|
||||
entities.put("infin", "\u221e");
|
||||
entities.put("ang", "\u2220");
|
||||
entities.put("and", "\u2227");
|
||||
entities.put("or", "\u2228");
|
||||
entities.put("cap", "\u2229");
|
||||
entities.put("cup", "\u222a");
|
||||
entities.put("int", "\u222b");
|
||||
entities.put("there4", "\u2234");
|
||||
entities.put("sim", "\u223c");
|
||||
entities.put("cong", "\u2245");
|
||||
entities.put("asymp", "\u2248");
|
||||
entities.put("ne", "\u2260");
|
||||
entities.put("equiv", "\u2261");
|
||||
entities.put("le", "\u2264");
|
||||
entities.put("ge", "\u2265");
|
||||
entities.put("sub", "\u2282");
|
||||
entities.put("sup", "\u2283");
|
||||
entities.put("nsub", "\u2284");
|
||||
entities.put("sube", "\u2286");
|
||||
entities.put("supe", "\u2287");
|
||||
entities.put("oplus", "\u2295");
|
||||
entities.put("otimes", "\u2297");
|
||||
entities.put("perp", "\u22a5");
|
||||
entities.put("sdot", "\u22c5");
|
||||
entities.put("lceil", "\u2308");
|
||||
entities.put("rceil", "\u2309");
|
||||
entities.put("lfloor", "\u230a");
|
||||
entities.put("rfloor", "\u230b");
|
||||
entities.put("lang", "\u2329");
|
||||
entities.put("rang", "\u232a");
|
||||
entities.put("loz", "\u25ca");
|
||||
entities.put("spades", "\u2660");
|
||||
entities.put("clubs", "\u2663");
|
||||
entities.put("hearts", "\u2665");
|
||||
entities.put("diams", "\u2666");
|
||||
DEFAULT_ENTITIES = Collections.unmodifiableMap(entities);
|
||||
}
|
||||
|
||||
|
||||
public ${className}() {
|
||||
this((s, f) -> s);
|
||||
}
|
||||
|
@ -98,18 +369,23 @@ public class ${className} {
|
|||
} //-- void setAddDefaultEntities(boolean)
|
||||
|
||||
/**
|
||||
* @see ReaderFactory#newXmlReader
|
||||
*
|
||||
* @param reader a reader object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return ${root.name}
|
||||
*/
|
||||
public ${root.name} read(Reader reader, boolean strict, InputSource source) throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
|
||||
parser.setInput(reader);
|
||||
public ${root.name} read(Reader reader, boolean strict, InputSource source) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
XMLStreamReader parser = null;
|
||||
try {
|
||||
parser = factory.createXMLStreamReader(reader);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return read(parser, strict, source);
|
||||
} //-- ${root.name} read(Reader, boolean)
|
||||
|
||||
|
@ -119,12 +395,16 @@ public class ${className} {
|
|||
* @param in a in object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return ${root.name}
|
||||
*/
|
||||
public ${root.name} read(InputStream in, boolean strict, InputSource source) throws IOException, XmlPullParserException {
|
||||
return read(ReaderFactory.newXmlReader(in), strict, source);
|
||||
public ${root.name} read(InputStream in, boolean strict, InputSource source) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
StreamSource streamSource = new StreamSource(in, null);
|
||||
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
|
||||
return read(parser, strict, source);
|
||||
} //-- ${root.name} read(InputStream, boolean)
|
||||
|
||||
/**
|
||||
|
@ -133,21 +413,21 @@ public class ${className} {
|
|||
* @param parser a parser object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return ${root.name}
|
||||
*/
|
||||
public ${root.name} read(XmlPullParser parser, boolean strict, InputSource source) throws IOException, XmlPullParserException {
|
||||
public ${root.name} read(XMLStreamReader parser, boolean strict, InputSource source) throws IOException, XMLStreamException {
|
||||
$rootUcapName $rootLcapName = null;
|
||||
int eventType = parser.getEventType();
|
||||
boolean parsed = false;
|
||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
while (eventType != XMLStreamReader.END_DOCUMENT) {
|
||||
if (eventType == XMLStreamReader.START_ELEMENT) {
|
||||
if (strict && ! "${rootTag}".equals(parser.getName())) {
|
||||
throw new XmlPullParserException("Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser, null);
|
||||
throw new XMLStreamException("Expected root element '${rootTag}' but found '" + parser.getLocalName() + "'", parser.getLocation(), null);
|
||||
} else if (parsed) {
|
||||
// fallback, already expected a XmlPullParserException due to invalid XML
|
||||
throw new XmlPullParserException("Duplicated tag: '${rootTag}'", parser, null);
|
||||
// fallback, already expected a XMLStreamException due to invalid XML
|
||||
throw new XMLStreamException("Duplicated tag: '${rootTag}'", parser.getLocation(), null);
|
||||
}
|
||||
$rootLcapName = parse${rootUcapName}(parser, strict, source);
|
||||
parsed = true;
|
||||
|
@ -157,8 +437,8 @@ public class ${className} {
|
|||
if (parsed) {
|
||||
return $rootLcapName;
|
||||
}
|
||||
throw new XmlPullParserException("Expected root element '${rootTag}' but found no element at all: invalid XML document", parser, null);
|
||||
} //-- ${root.name} read(XmlPullParser, boolean)
|
||||
throw new XMLStreamException("Expected root element '${rootTag}' but found no element at all: invalid XML document", parser.getLocation(), null);
|
||||
} //-- ${root.name} read(XMLStreamReader, boolean)
|
||||
|
||||
#foreach ( $class in $model.allClasses )
|
||||
#if ( $class.name != "InputSource" && $class.name != "InputLocation" )
|
||||
|
@ -166,14 +446,14 @@ public class ${className} {
|
|||
#set ( $classLcapName = $Helper.uncapitalise( $class.name ) )
|
||||
#set ( $ancestors = $Helper.ancestors( $class ) )
|
||||
#set ( $allFields = $Helper.xmlFields( $class ) )
|
||||
private ${classUcapName} parse${classUcapName}(XmlPullParser parser, boolean strict, InputSource source) throws IOException, XmlPullParserException {
|
||||
String tagName = parser.getName();
|
||||
private ${classUcapName} parse${classUcapName}(XMLStreamReader parser, boolean strict, InputSource source) throws IOException, XMLStreamException {
|
||||
String tagName = parser.getLocalName();
|
||||
${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder(true);
|
||||
${classLcapName}.location("", new InputLocation(parser.getLineNumber(), parser.getColumnNumber(), source));
|
||||
${classLcapName}.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
|
||||
for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
|
||||
String name = parser.getAttributeName(i);
|
||||
String value = parser.getAttributeValue(i);
|
||||
if (name.indexOf(':') >= 0) {
|
||||
String name = parser.getAttributeLocalName(i);
|
||||
String value = parser.getAttributeNamespace(i);
|
||||
if (XSI_NAMESPACE.equals(value)) {
|
||||
// just ignore attributes with non-default namespace (for example: xmlns:xsi)
|
||||
#if ( $class == $root )
|
||||
} else if ("xmlns".equals(name)) {
|
||||
|
@ -184,7 +464,7 @@ public class ${className} {
|
|||
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
|
||||
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
|
||||
} else if ("$fieldTagName".equals(name)) {
|
||||
${classLcapName}.location(name, new InputLocation(parser.getLineNumber(), parser.getColumnNumber(), source));
|
||||
${classLcapName}.location(name, new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
|
||||
#if ( $field.type == "String" )
|
||||
${classLcapName}.${field.name}(interpolatedTrimmed(value, "$fieldTagName"));
|
||||
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
|
||||
|
@ -199,13 +479,13 @@ public class ${className} {
|
|||
}
|
||||
}
|
||||
Set<String> parsed = new HashSet<>();
|
||||
while ((strict ? parser.nextTag() : nextTag(parser)) == XmlPullParser.START_TAG) {
|
||||
String childName = unalias(parser.getName());
|
||||
while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
|
||||
String childName = unalias(parser.getLocalName());
|
||||
if (!parsed.add(childName)) {
|
||||
throw new XmlPullParserException("Duplicated tag: '" + childName + "'", parser, null);
|
||||
throw new XMLStreamException("Duplicated tag: '" + childName + "'", parser.getLocation(), null);
|
||||
}
|
||||
int line = parser.getLineNumber();
|
||||
int column = parser.getColumnNumber();
|
||||
int line = parser.getLocation().getLineNumber();
|
||||
int column = parser.getLocation().getColumnNumber();
|
||||
Map<Object, InputLocation> locations = null;
|
||||
switch (childName) {
|
||||
#set( $ift = "if" )
|
||||
|
@ -218,24 +498,24 @@ public class ${className} {
|
|||
#set ( $fieldCapName = $Helper.capitalise($field.name))
|
||||
case "${fieldTagName}": {
|
||||
#if ( $field.type == "String" )
|
||||
${classLcapName}.${field.name}(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
|
||||
${classLcapName}.${field.name}(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"));
|
||||
break;
|
||||
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
|
||||
${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, ${field.defaultValue}));
|
||||
${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"), "${fieldTagName}", parser, ${field.defaultValue}));
|
||||
break;
|
||||
#elseif ( $field.type == "int" )
|
||||
${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, strict, ${field.defaultValue}));
|
||||
${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"), "${fieldTagName}", parser, strict, ${field.defaultValue}));
|
||||
break;
|
||||
#elseif ( $field.type == "DOM" )
|
||||
${classLcapName}.${field.name}(XmlNodeBuilder.build(parser, true));
|
||||
${classLcapName}.${field.name}(XmlNodeBuilder.build(parser));
|
||||
break;
|
||||
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
|
||||
List<String> ${field.name} = new ArrayList<>();
|
||||
locations = new HashMap<>();
|
||||
while (parser.nextTag() == XmlPullParser.START_TAG) {
|
||||
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
|
||||
if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
|
||||
locations.put(Integer.valueOf(locations.size()), new InputLocation(parser.getLineNumber(), parser.getColumnNumber(), source));
|
||||
${field.name}.add(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
|
||||
locations.put(Integer.valueOf(locations.size()), new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
|
||||
${field.name}.add(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"));
|
||||
} else {
|
||||
checkUnknownElement(parser, strict);
|
||||
}
|
||||
|
@ -245,10 +525,10 @@ public class ${className} {
|
|||
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
|
||||
Map<String, String> ${field.name} = new LinkedHashMap<>();
|
||||
locations = new HashMap<>();
|
||||
while (parser.nextTag() == XmlPullParser.START_TAG) {
|
||||
String key = parser.getName();
|
||||
String value = parser.nextText().trim();
|
||||
locations.put(key, new InputLocation(parser.getLineNumber(), parser.getColumnNumber(), source));
|
||||
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
|
||||
String key = parser.getLocalName();
|
||||
String value = nextText(parser, strict).trim();
|
||||
locations.put(key, new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
|
||||
${field.name}.put(key, value);
|
||||
}
|
||||
${classLcapName}.${field.name}(${field.name});
|
||||
|
@ -258,7 +538,7 @@ public class ${className} {
|
|||
break;
|
||||
#elseif ( $field.to && $field.multiplicity == "*" )
|
||||
List<$field.to> ${field.name} = new ArrayList<>();
|
||||
while (parser.nextTag() == XmlPullParser.START_TAG) {
|
||||
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
|
||||
if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
|
||||
${field.name}.add(parse${field.toClass.name}(parser, strict, source));
|
||||
} else {
|
||||
|
@ -283,7 +563,7 @@ public class ${className} {
|
|||
${classLcapName}.location(childName, new InputLocation(line, column, source, locations));
|
||||
}
|
||||
#if ( $class == $root )
|
||||
${classLcapName}.modelEncoding(parser.getInputEncoding());
|
||||
${classLcapName}.modelEncoding(parser.getEncoding());
|
||||
#end
|
||||
return ${classLcapName}.build();
|
||||
}
|
||||
|
@ -317,40 +597,40 @@ public class ${className} {
|
|||
* @param strict a strict object.
|
||||
* @param tagName a tagName object.
|
||||
* @param attribute a attribute object.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @throws IOException IOException if any.
|
||||
*/
|
||||
private void checkUnknownAttribute(XmlPullParser parser, String attribute, String tagName, boolean strict) throws XmlPullParserException, IOException {
|
||||
private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException, IOException {
|
||||
// strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
|
||||
if (strict) {
|
||||
throw new XmlPullParserException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null);
|
||||
throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
|
||||
}
|
||||
} //-- void checkUnknownAttribute(XmlPullParser, String, String, boolean)
|
||||
} //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)
|
||||
|
||||
/**
|
||||
* Method checkUnknownElement.
|
||||
*
|
||||
* @param parser a parser object.
|
||||
* @param strict a strict object.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @throws IOException IOException if any.
|
||||
*/
|
||||
private void checkUnknownElement(XmlPullParser parser, boolean strict) throws XmlPullParserException, IOException {
|
||||
private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException, IOException {
|
||||
if (strict) {
|
||||
throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
|
||||
throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
|
||||
}
|
||||
|
||||
for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XMLStreamReader.START_ELEMENT) {
|
||||
unrecognizedTagCount++;
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XMLStreamReader.END_ELEMENT) {
|
||||
unrecognizedTagCount--;
|
||||
}
|
||||
}
|
||||
} //-- void checkUnknownElement(XmlPullParser, boolean)
|
||||
} //-- void checkUnknownElement(XMLStreamReader, boolean)
|
||||
|
||||
/**
|
||||
* Method getTrimmedValue.
|
||||
|
@ -381,20 +661,26 @@ public class ${className} {
|
|||
*
|
||||
* @param parser a parser object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return int
|
||||
*/
|
||||
private int nextTag(XmlPullParser parser) throws IOException, XmlPullParserException {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
eventType = parser.next();
|
||||
private int nextTag(XMLStreamReader parser) throws IOException, XMLStreamException {
|
||||
while (true) {
|
||||
int next = parser.next();
|
||||
switch (next) {
|
||||
case XMLStreamReader.SPACE:
|
||||
case XMLStreamReader.COMMENT:
|
||||
case XMLStreamReader.PROCESSING_INSTRUCTION:
|
||||
case XMLStreamReader.CDATA:
|
||||
case XMLStreamReader.CHARACTERS:
|
||||
continue;
|
||||
case XMLStreamReader.START_ELEMENT:
|
||||
case XMLStreamReader.END_ELEMENT:
|
||||
return next;
|
||||
}
|
||||
}
|
||||
if (eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG) {
|
||||
throw new XmlPullParserException("expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null);
|
||||
}
|
||||
return eventType;
|
||||
} //-- int nextTag(XmlPullParser)
|
||||
} //-- int nextTag(XMLStreamReader)
|
||||
|
||||
#foreach ( $class in $model.allClasses )
|
||||
#foreach ( $field in $class.getFields($version) )
|
||||
|
@ -413,16 +699,16 @@ public class ${className} {
|
|||
* @param defaultValue a defaultValue object.
|
||||
* @param parser a parser object.
|
||||
* @param attribute a attribute object.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean getBooleanValue(String s, String attribute, XmlPullParser parser, boolean defaultValue) throws XmlPullParserException {
|
||||
private boolean getBooleanValue(String s, String attribute, XMLStreamReader parser, boolean defaultValue) throws XMLStreamException {
|
||||
if (s != null && s.length() != 0) {
|
||||
return Boolean.valueOf(s).booleanValue();
|
||||
}
|
||||
return defaultValue;
|
||||
} //-- boolean getBooleanValue(String, String, XmlPullParser, String)
|
||||
} //-- boolean getBooleanValue(String, String, XMLStreamReader, String)
|
||||
|
||||
#end
|
||||
#if ( $hasIntegerField )
|
||||
|
@ -433,22 +719,22 @@ public class ${className} {
|
|||
* @param strict a strict object.
|
||||
* @param parser a parser object.
|
||||
* @param attribute a attribute object.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return int
|
||||
*/
|
||||
private int getIntegerValue(String s, String attribute, XmlPullParser parser, boolean strict, int defaultValue) throws XmlPullParserException {
|
||||
private int getIntegerValue(String s, String attribute, XMLStreamReader parser, boolean strict, int defaultValue) throws XMLStreamException {
|
||||
if (s != null) {
|
||||
try {
|
||||
return Integer.valueOf(s).intValue();
|
||||
} catch (NumberFormatException nfe) {
|
||||
if (strict) {
|
||||
throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be an integer", parser, nfe);
|
||||
throw new XMLStreamException("Unable to parse element '" + attribute + "', must be an integer", parser.getLocation(), nfe);
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
} //-- int getIntegerValue(String, String, XmlPullParser, boolean)
|
||||
} //-- int getIntegerValue(String, String, XMLStreamReader, boolean)
|
||||
|
||||
#end
|
||||
public static interface ContentTransformer {
|
||||
|
@ -462,4 +748,38 @@ public class ${className} {
|
|||
String transform(String source, String fieldName);
|
||||
}
|
||||
|
||||
private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
|
||||
int eventType = parser.getEventType();
|
||||
if (eventType != XMLStreamReader.START_ELEMENT) {
|
||||
throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
|
||||
}
|
||||
eventType = parser.next();
|
||||
StringBuilder result = new StringBuilder();
|
||||
while (true) {
|
||||
if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
|
||||
result.append(parser.getText());
|
||||
} else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
|
||||
String val = null;
|
||||
if (strict) {
|
||||
throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
|
||||
} else if (addDefaultEntities) {
|
||||
val = DEFAULT_ENTITIES.get(parser.getLocalName());
|
||||
}
|
||||
if (val != null) {
|
||||
result.append(val);
|
||||
} else {
|
||||
result.append("&").append(parser.getLocalName()).append(";");
|
||||
}
|
||||
} else if (eventType != XMLStreamReader.COMMENT) {
|
||||
break;
|
||||
}
|
||||
eventType = parser.next();
|
||||
}
|
||||
if (eventType != XMLStreamReader.END_ELEMENT) {
|
||||
throw new XMLStreamException(
|
||||
"TEXT must be immediately followed by END_ELEMENT and not " + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,16 +50,16 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Collections;
|
||||
import org.apache.maven.api.annotations.Generated;
|
||||
import org.apache.maven.internal.xml.XmlNodeBuilder;
|
||||
#foreach ( $class in $model.allClasses )
|
||||
import ${packageModelV4}.${class.name};
|
||||
#end
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
|
||||
import org.codehaus.plexus.util.xml.pull.MXParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
@Deprecated
|
||||
@Generated
|
||||
|
@ -69,6 +69,277 @@ public class ${className} {
|
|||
|
||||
private final ContentTransformer contentTransformer;
|
||||
|
||||
/**
|
||||
* XSI namespace
|
||||
*/
|
||||
private static final String XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
|
||||
|
||||
private static final Map<String, String> DEFAULT_ENTITIES;
|
||||
|
||||
static {
|
||||
Map<String, String> entities = new HashMap<>();
|
||||
entities.put("nbsp", "\u00a0");
|
||||
entities.put("iexcl", "\u00a1");
|
||||
entities.put("cent", "\u00a2");
|
||||
entities.put("pound", "\u00a3");
|
||||
entities.put("curren", "\u00a4");
|
||||
entities.put("yen", "\u00a5");
|
||||
entities.put("brvbar", "\u00a6");
|
||||
entities.put("sect", "\u00a7");
|
||||
entities.put("uml", "\u00a8");
|
||||
entities.put("copy", "\u00a9");
|
||||
entities.put("ordf", "\u00aa");
|
||||
entities.put("laquo", "\u00ab");
|
||||
entities.put("not", "\u00ac");
|
||||
entities.put("shy", "\u00ad");
|
||||
entities.put("reg", "\u00ae");
|
||||
entities.put("macr", "\u00af");
|
||||
entities.put("deg", "\u00b0");
|
||||
entities.put("plusmn", "\u00b1");
|
||||
entities.put("sup2", "\u00b2");
|
||||
entities.put("sup3", "\u00b3");
|
||||
entities.put("acute", "\u00b4");
|
||||
entities.put("micro", "\u00b5");
|
||||
entities.put("para", "\u00b6");
|
||||
entities.put("middot", "\u00b7");
|
||||
entities.put("cedil", "\u00b8");
|
||||
entities.put("sup1", "\u00b9");
|
||||
entities.put("ordm", "\u00ba");
|
||||
entities.put("raquo", "\u00bb");
|
||||
entities.put("frac14", "\u00bc");
|
||||
entities.put("frac12", "\u00bd");
|
||||
entities.put("frac34", "\u00be");
|
||||
entities.put("iquest", "\u00bf");
|
||||
entities.put("Agrave", "\u00c0");
|
||||
entities.put("Aacute", "\u00c1");
|
||||
entities.put("Acirc", "\u00c2");
|
||||
entities.put("Atilde", "\u00c3");
|
||||
entities.put("Auml", "\u00c4");
|
||||
entities.put("Aring", "\u00c5");
|
||||
entities.put("AElig", "\u00c6");
|
||||
entities.put("Ccedil", "\u00c7");
|
||||
entities.put("Egrave", "\u00c8");
|
||||
entities.put("Eacute", "\u00c9");
|
||||
entities.put("Ecirc", "\u00ca");
|
||||
entities.put("Euml", "\u00cb");
|
||||
entities.put("Igrave", "\u00cc");
|
||||
entities.put("Iacute", "\u00cd");
|
||||
entities.put("Icirc", "\u00ce");
|
||||
entities.put("Iuml", "\u00cf");
|
||||
entities.put("ETH", "\u00d0");
|
||||
entities.put("Ntilde", "\u00d1");
|
||||
entities.put("Ograve", "\u00d2");
|
||||
entities.put("Oacute", "\u00d3");
|
||||
entities.put("Ocirc", "\u00d4");
|
||||
entities.put("Otilde", "\u00d5");
|
||||
entities.put("Ouml", "\u00d6");
|
||||
entities.put("times", "\u00d7");
|
||||
entities.put("Oslash", "\u00d8");
|
||||
entities.put("Ugrave", "\u00d9");
|
||||
entities.put("Uacute", "\u00da");
|
||||
entities.put("Ucirc", "\u00db");
|
||||
entities.put("Uuml", "\u00dc");
|
||||
entities.put("Yacute", "\u00dd");
|
||||
entities.put("THORN", "\u00de");
|
||||
entities.put("szlig", "\u00df");
|
||||
entities.put("agrave", "\u00e0");
|
||||
entities.put("aacute", "\u00e1");
|
||||
entities.put("acirc", "\u00e2");
|
||||
entities.put("atilde", "\u00e3");
|
||||
entities.put("auml", "\u00e4");
|
||||
entities.put("aring", "\u00e5");
|
||||
entities.put("aelig", "\u00e6");
|
||||
entities.put("ccedil", "\u00e7");
|
||||
entities.put("egrave", "\u00e8");
|
||||
entities.put("eacute", "\u00e9");
|
||||
entities.put("ecirc", "\u00ea");
|
||||
entities.put("euml", "\u00eb");
|
||||
entities.put("igrave", "\u00ec");
|
||||
entities.put("iacute", "\u00ed");
|
||||
entities.put("icirc", "\u00ee");
|
||||
entities.put("iuml", "\u00ef");
|
||||
entities.put("eth", "\u00f0");
|
||||
entities.put("ntilde", "\u00f1");
|
||||
entities.put("ograve", "\u00f2");
|
||||
entities.put("oacute", "\u00f3");
|
||||
entities.put("ocirc", "\u00f4");
|
||||
entities.put("otilde", "\u00f5");
|
||||
entities.put("ouml", "\u00f6");
|
||||
entities.put("divide", "\u00f7");
|
||||
entities.put("oslash", "\u00f8");
|
||||
entities.put("ugrave", "\u00f9");
|
||||
entities.put("uacute", "\u00fa");
|
||||
entities.put("ucirc", "\u00fb");
|
||||
entities.put("uuml", "\u00fc");
|
||||
entities.put("yacute", "\u00fd");
|
||||
entities.put("thorn", "\u00fe");
|
||||
entities.put("yuml", "\u00ff");
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Special entities
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
entities.put("OElig", "\u0152");
|
||||
entities.put("oelig", "\u0153");
|
||||
entities.put("Scaron", "\u0160");
|
||||
entities.put("scaron", "\u0161");
|
||||
entities.put("Yuml", "\u0178");
|
||||
entities.put("circ", "\u02c6");
|
||||
entities.put("tilde", "\u02dc");
|
||||
entities.put("ensp", "\u2002");
|
||||
entities.put("emsp", "\u2003");
|
||||
entities.put("thinsp", "\u2009");
|
||||
entities.put("zwnj", "\u200c");
|
||||
entities.put("zwj", "\u200d");
|
||||
entities.put("lrm", "\u200e");
|
||||
entities.put("rlm", "\u200f");
|
||||
entities.put("ndash", "\u2013");
|
||||
entities.put("mdash", "\u2014");
|
||||
entities.put("lsquo", "\u2018");
|
||||
entities.put("rsquo", "\u2019");
|
||||
entities.put("sbquo", "\u201a");
|
||||
entities.put("ldquo", "\u201c");
|
||||
entities.put("rdquo", "\u201d");
|
||||
entities.put("bdquo", "\u201e");
|
||||
entities.put("dagger", "\u2020");
|
||||
entities.put("Dagger", "\u2021");
|
||||
entities.put("permil", "\u2030");
|
||||
entities.put("lsaquo", "\u2039");
|
||||
entities.put("rsaquo", "\u203a");
|
||||
entities.put("euro", "\u20ac");
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Symbol entities
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
entities.put("fnof", "\u0192");
|
||||
entities.put("Alpha", "\u0391");
|
||||
entities.put("Beta", "\u0392");
|
||||
entities.put("Gamma", "\u0393");
|
||||
entities.put("Delta", "\u0394");
|
||||
entities.put("Epsilon", "\u0395");
|
||||
entities.put("Zeta", "\u0396");
|
||||
entities.put("Eta", "\u0397");
|
||||
entities.put("Theta", "\u0398");
|
||||
entities.put("Iota", "\u0399");
|
||||
entities.put("Kappa", "\u039a");
|
||||
entities.put("Lambda", "\u039b");
|
||||
entities.put("Mu", "\u039c");
|
||||
entities.put("Nu", "\u039d");
|
||||
entities.put("Xi", "\u039e");
|
||||
entities.put("Omicron", "\u039f");
|
||||
entities.put("Pi", "\u03a0");
|
||||
entities.put("Rho", "\u03a1");
|
||||
entities.put("Sigma", "\u03a3");
|
||||
entities.put("Tau", "\u03a4");
|
||||
entities.put("Upsilon", "\u03a5");
|
||||
entities.put("Phi", "\u03a6");
|
||||
entities.put("Chi", "\u03a7");
|
||||
entities.put("Psi", "\u03a8");
|
||||
entities.put("Omega", "\u03a9");
|
||||
entities.put("alpha", "\u03b1");
|
||||
entities.put("beta", "\u03b2");
|
||||
entities.put("gamma", "\u03b3");
|
||||
entities.put("delta", "\u03b4");
|
||||
entities.put("epsilon", "\u03b5");
|
||||
entities.put("zeta", "\u03b6");
|
||||
entities.put("eta", "\u03b7");
|
||||
entities.put("theta", "\u03b8");
|
||||
entities.put("iota", "\u03b9");
|
||||
entities.put("kappa", "\u03ba");
|
||||
entities.put("lambda", "\u03bb");
|
||||
entities.put("mu", "\u03bc");
|
||||
entities.put("nu", "\u03bd");
|
||||
entities.put("xi", "\u03be");
|
||||
entities.put("omicron", "\u03bf");
|
||||
entities.put("pi", "\u03c0");
|
||||
entities.put("rho", "\u03c1");
|
||||
entities.put("sigmaf", "\u03c2");
|
||||
entities.put("sigma", "\u03c3");
|
||||
entities.put("tau", "\u03c4");
|
||||
entities.put("upsilon", "\u03c5");
|
||||
entities.put("phi", "\u03c6");
|
||||
entities.put("chi", "\u03c7");
|
||||
entities.put("psi", "\u03c8");
|
||||
entities.put("omega", "\u03c9");
|
||||
entities.put("thetasym", "\u03d1");
|
||||
entities.put("upsih", "\u03d2");
|
||||
entities.put("piv", "\u03d6");
|
||||
entities.put("bull", "\u2022");
|
||||
entities.put("hellip", "\u2026");
|
||||
entities.put("prime", "\u2032");
|
||||
entities.put("Prime", "\u2033");
|
||||
entities.put("oline", "\u203e");
|
||||
entities.put("frasl", "\u2044");
|
||||
entities.put("weierp", "\u2118");
|
||||
entities.put("image", "\u2111");
|
||||
entities.put("real", "\u211c");
|
||||
entities.put("trade", "\u2122");
|
||||
entities.put("alefsym", "\u2135");
|
||||
entities.put("larr", "\u2190");
|
||||
entities.put("uarr", "\u2191");
|
||||
entities.put("rarr", "\u2192");
|
||||
entities.put("darr", "\u2193");
|
||||
entities.put("harr", "\u2194");
|
||||
entities.put("crarr", "\u21b5");
|
||||
entities.put("lArr", "\u21d0");
|
||||
entities.put("uArr", "\u21d1");
|
||||
entities.put("rArr", "\u21d2");
|
||||
entities.put("dArr", "\u21d3");
|
||||
entities.put("hArr", "\u21d4");
|
||||
entities.put("forall", "\u2200");
|
||||
entities.put("part", "\u2202");
|
||||
entities.put("exist", "\u2203");
|
||||
entities.put("empty", "\u2205");
|
||||
entities.put("nabla", "\u2207");
|
||||
entities.put("isin", "\u2208");
|
||||
entities.put("notin", "\u2209");
|
||||
entities.put("ni", "\u220b");
|
||||
entities.put("prod", "\u220f");
|
||||
entities.put("sum", "\u2211");
|
||||
entities.put("minus", "\u2212");
|
||||
entities.put("lowast", "\u2217");
|
||||
entities.put("radic", "\u221a");
|
||||
entities.put("prop", "\u221d");
|
||||
entities.put("infin", "\u221e");
|
||||
entities.put("ang", "\u2220");
|
||||
entities.put("and", "\u2227");
|
||||
entities.put("or", "\u2228");
|
||||
entities.put("cap", "\u2229");
|
||||
entities.put("cup", "\u222a");
|
||||
entities.put("int", "\u222b");
|
||||
entities.put("there4", "\u2234");
|
||||
entities.put("sim", "\u223c");
|
||||
entities.put("cong", "\u2245");
|
||||
entities.put("asymp", "\u2248");
|
||||
entities.put("ne", "\u2260");
|
||||
entities.put("equiv", "\u2261");
|
||||
entities.put("le", "\u2264");
|
||||
entities.put("ge", "\u2265");
|
||||
entities.put("sub", "\u2282");
|
||||
entities.put("sup", "\u2283");
|
||||
entities.put("nsub", "\u2284");
|
||||
entities.put("sube", "\u2286");
|
||||
entities.put("supe", "\u2287");
|
||||
entities.put("oplus", "\u2295");
|
||||
entities.put("otimes", "\u2297");
|
||||
entities.put("perp", "\u22a5");
|
||||
entities.put("sdot", "\u22c5");
|
||||
entities.put("lceil", "\u2308");
|
||||
entities.put("rceil", "\u2309");
|
||||
entities.put("lfloor", "\u230a");
|
||||
entities.put("rfloor", "\u230b");
|
||||
entities.put("lang", "\u2329");
|
||||
entities.put("rang", "\u232a");
|
||||
entities.put("loz", "\u25ca");
|
||||
entities.put("spades", "\u2660");
|
||||
entities.put("clubs", "\u2663");
|
||||
entities.put("hearts", "\u2665");
|
||||
entities.put("diams", "\u2666");
|
||||
DEFAULT_ENTITIES = Collections.unmodifiableMap(entities);
|
||||
}
|
||||
|
||||
|
||||
public ${className}() {
|
||||
this((s, f) -> s);
|
||||
}
|
||||
|
@ -96,32 +367,44 @@ public class ${className} {
|
|||
} //-- void setAddDefaultEntities(boolean)
|
||||
|
||||
/**
|
||||
* @see ReaderFactory#newXmlReader
|
||||
*
|
||||
* @param reader a reader object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return ${root.name}
|
||||
*/
|
||||
public ${root.name} read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
|
||||
parser.setInput(reader);
|
||||
public ${root.name} read(Reader reader, boolean strict) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
XMLStreamReader parser = null;
|
||||
try {
|
||||
parser = factory.createXMLStreamReader(reader);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return read(parser, strict);
|
||||
} //-- ${root.name} read(Reader, boolean)
|
||||
|
||||
/**
|
||||
* @see ReaderFactory#newXmlReader
|
||||
*
|
||||
* @param reader a reader object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return ${root.name}
|
||||
*/
|
||||
public ${root.name} read(Reader reader) throws IOException, XmlPullParserException {
|
||||
return read(reader, true);
|
||||
public ${root.name} read(Reader reader) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
XMLStreamReader parser = null;
|
||||
try {
|
||||
parser = factory.createXMLStreamReader(reader);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return read(parser,true);
|
||||
} //-- ${root.name} read(Reader)
|
||||
|
||||
/**
|
||||
|
@ -130,12 +413,16 @@ public class ${className} {
|
|||
* @param in a in object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return ${root.name}
|
||||
*/
|
||||
public ${root.name} read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
|
||||
return read(ReaderFactory.newXmlReader(in), strict);
|
||||
public ${root.name} read(InputStream in, boolean strict) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
StreamSource streamSource = new StreamSource(in, null);
|
||||
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
|
||||
return read(parser, strict);
|
||||
} //-- ${root.name} read(InputStream, boolean)
|
||||
|
||||
/**
|
||||
|
@ -143,12 +430,16 @@ public class ${className} {
|
|||
*
|
||||
* @param in a in object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return ${root.name}
|
||||
*/
|
||||
public ${root.name} read(InputStream in) throws IOException, XmlPullParserException {
|
||||
return read(ReaderFactory.newXmlReader(in));
|
||||
public ${root.name} read(InputStream in) throws IOException, XMLStreamException {
|
||||
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
|
||||
StreamSource streamSource = new StreamSource(in, null);
|
||||
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
|
||||
return read(parser,true);
|
||||
} //-- ${root.name} read(InputStream)
|
||||
|
||||
/**
|
||||
|
@ -157,22 +448,22 @@ public class ${className} {
|
|||
* @param parser a parser object.
|
||||
* @param strict a strict object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return ${root.name}
|
||||
*/
|
||||
public ${root.name} read(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
|
||||
public ${root.name} read(XMLStreamReader parser, boolean strict) throws IOException, XMLStreamException {
|
||||
$rootUcapName $rootLcapName = null;
|
||||
int eventType = parser.getEventType();
|
||||
boolean parsed = false;
|
||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (strict && ! "${rootTag}".equals(parser.getName())) {
|
||||
throw new XmlPullParserException("Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser, null);
|
||||
while (eventType != XMLStreamReader.END_DOCUMENT) {
|
||||
if (eventType == XMLStreamReader.START_ELEMENT) {
|
||||
if (strict && ! "${rootTag}".equals(parser.getLocalName())) {
|
||||
throw new XMLStreamException("Expected root element '${rootTag}' but found '" + parser.getLocalName() + "'", parser.getLocation(), null);
|
||||
}
|
||||
else if (parsed) {
|
||||
// fallback, already expected a XmlPullParserException due to invalid XML
|
||||
throw new XmlPullParserException("Duplicated tag: '${rootTag}'", parser, null);
|
||||
// fallback, already expected a XMLStreamException due to invalid XML
|
||||
throw new XMLStreamException("Duplicated tag: '${rootTag}'", parser.getLocation(), null);
|
||||
}
|
||||
$rootLcapName = parse${rootUcapName}(parser, strict);
|
||||
parsed = true;
|
||||
|
@ -182,8 +473,8 @@ public class ${className} {
|
|||
if (parsed) {
|
||||
return $rootLcapName;
|
||||
}
|
||||
throw new XmlPullParserException("Expected root element '${rootTag}' but found no element at all: invalid XML document", parser, null);
|
||||
} //-- ${root.name} read(XmlPullParser, boolean)
|
||||
throw new XMLStreamException("Expected root element '${rootTag}' but found no element at all: invalid XML document", parser.getLocation(), null);
|
||||
} //-- ${root.name} read(XMLStreamReader, boolean)
|
||||
|
||||
#foreach ( $class in $model.allClasses )
|
||||
#if ( $class.name != "InputSource" && $class.name != "InputLocation" )
|
||||
|
@ -191,13 +482,13 @@ public class ${className} {
|
|||
#set ( $classLcapName = $Helper.uncapitalise( $class.name ) )
|
||||
#set ( $ancestors = $Helper.ancestors( $class ) )
|
||||
#set ( $allFields = $Helper.xmlFields( $class ) )
|
||||
private ${classUcapName} parse${classUcapName}(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
|
||||
String tagName = parser.getName();
|
||||
private ${classUcapName} parse${classUcapName}(XMLStreamReader parser, boolean strict) throws IOException, XMLStreamException {
|
||||
String tagName = parser.getLocalName();
|
||||
${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder(true);
|
||||
for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
|
||||
String name = parser.getAttributeName(i);
|
||||
String value = parser.getAttributeValue(i);
|
||||
if (name.indexOf(':') >= 0) {
|
||||
String name = parser.getAttributeLocalName(i);
|
||||
String value = parser.getAttributeNamespace(i);
|
||||
if (XSI_NAMESPACE.equals(value)) {
|
||||
// just ignore attributes with non-default namespace (for example: xmlns:xsi)
|
||||
}
|
||||
#if ( $class == $root )
|
||||
|
@ -225,10 +516,10 @@ public class ${className} {
|
|||
}
|
||||
}
|
||||
Set<String> parsed = new HashSet<>();
|
||||
while ((strict ? parser.nextTag() : nextTag(parser)) == XmlPullParser.START_TAG) {
|
||||
String childName = unalias(parser.getName());
|
||||
while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
|
||||
String childName = unalias(parser.getLocalName());
|
||||
if (!parsed.add(childName)) {
|
||||
throw new XmlPullParserException("Duplicated tag: '" + childName + "'", parser, null);
|
||||
throw new XMLStreamException("Duplicated tag: '" + childName + "'", parser.getLocation(), null);
|
||||
}
|
||||
switch (childName) {
|
||||
#set( $ift = "if" )
|
||||
|
@ -241,22 +532,22 @@ public class ${className} {
|
|||
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
|
||||
case "${fieldTagName}": {
|
||||
#if ( $field.type == "String" )
|
||||
${classLcapName}.${field.name}(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
|
||||
${classLcapName}.${field.name}(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"));
|
||||
break;
|
||||
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
|
||||
${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, ${field.defaultValue}));
|
||||
${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"), "${fieldTagName}", parser, ${field.defaultValue}));
|
||||
break;
|
||||
#elseif ( $field.type == "int" )
|
||||
${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, strict, ${field.defaultValue}));
|
||||
${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"), "${fieldTagName}", parser, strict, ${field.defaultValue}));
|
||||
break;
|
||||
#elseif ( $field.type == "DOM" )
|
||||
${classLcapName}.${field.name}(XmlNodeBuilder.build(parser, true));
|
||||
${classLcapName}.${field.name}(XmlNodeBuilder.build(parser));
|
||||
break;
|
||||
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
|
||||
List<String> ${field.name} = new ArrayList<>();
|
||||
while (parser.nextTag() == XmlPullParser.START_TAG) {
|
||||
if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
|
||||
${field.name}.add(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
|
||||
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
|
||||
if ("${Helper.singular($fieldTagName)}".equals(parser.getLocalName())) {
|
||||
${field.name}.add(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"));
|
||||
}
|
||||
else {
|
||||
checkUnknownElement(parser, strict);
|
||||
|
@ -266,9 +557,9 @@ public class ${className} {
|
|||
break;
|
||||
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
|
||||
Map<String, String> ${field.name} = new LinkedHashMap<>();
|
||||
while (parser.nextTag() == XmlPullParser.START_TAG) {
|
||||
String key = parser.getName();
|
||||
String value = parser.nextText().trim();
|
||||
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
|
||||
String key = parser.getLocalName();
|
||||
String value = nextText(parser, strict).trim();
|
||||
${field.name}.put(key, value);
|
||||
}
|
||||
${classLcapName}.${field.name}(${field.name});
|
||||
|
@ -278,8 +569,8 @@ public class ${className} {
|
|||
break;
|
||||
#elseif ( $field.to && $field.multiplicity == "*" )
|
||||
List<$field.to> ${field.name} = new ArrayList<>();
|
||||
while (parser.nextTag() == XmlPullParser.START_TAG) {
|
||||
if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
|
||||
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
|
||||
if ("${Helper.singular($fieldTagName)}".equals(parser.getLocalName())) {
|
||||
${field.name}.add(parse${field.toClass.name}(parser, strict));
|
||||
}
|
||||
else {
|
||||
|
@ -303,7 +594,7 @@ public class ${className} {
|
|||
}
|
||||
}
|
||||
#if ( $class == $root )
|
||||
${classLcapName}.modelEncoding(parser.getInputEncoding());
|
||||
${classLcapName}.modelEncoding(parser.getEncoding());
|
||||
#end
|
||||
return ${classLcapName}.build();
|
||||
}
|
||||
|
@ -337,41 +628,41 @@ public class ${className} {
|
|||
* @param strict a strict object.
|
||||
* @param tagName a tagName object.
|
||||
* @param attribute a attribute object.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @throws IOException IOException if any.
|
||||
*/
|
||||
private void checkUnknownAttribute(XmlPullParser parser, String attribute, String tagName, boolean strict) throws XmlPullParserException, IOException {
|
||||
private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException, IOException {
|
||||
// strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
|
||||
if (strict) {
|
||||
throw new XmlPullParserException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null);
|
||||
throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
|
||||
}
|
||||
} //-- void checkUnknownAttribute(XmlPullParser, String, String, boolean)
|
||||
} //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)
|
||||
|
||||
/**
|
||||
* Method checkUnknownElement.
|
||||
*
|
||||
* @param parser a parser object.
|
||||
* @param strict a strict object.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @throws IOException IOException if any.
|
||||
*/
|
||||
private void checkUnknownElement(XmlPullParser parser, boolean strict) throws XmlPullParserException, IOException {
|
||||
private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException, IOException {
|
||||
if (strict) {
|
||||
throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
|
||||
throw new XMLStreamException("Unrecognised tag: '" + parser.getLocalName() + "'", parser.getLocation(), null);
|
||||
}
|
||||
|
||||
for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XMLStreamReader.START_ELEMENT) {
|
||||
unrecognizedTagCount++;
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
else if (eventType == XMLStreamReader.END_ELEMENT) {
|
||||
unrecognizedTagCount--;
|
||||
}
|
||||
}
|
||||
} //-- void checkUnknownElement(XmlPullParser, boolean)
|
||||
} //-- void checkUnknownElement(XMLStreamReader, boolean)
|
||||
|
||||
/**
|
||||
* Method getTrimmedValue.
|
||||
|
@ -402,20 +693,26 @@ public class ${className} {
|
|||
*
|
||||
* @param parser a parser object.
|
||||
* @throws IOException IOException if any.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return int
|
||||
*/
|
||||
private int nextTag(XmlPullParser parser) throws IOException, XmlPullParserException {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
eventType = parser.next();
|
||||
private int nextTag(XMLStreamReader parser) throws IOException, XMLStreamException {
|
||||
while (true) {
|
||||
int next = parser.next();
|
||||
switch (next) {
|
||||
case XMLStreamReader.SPACE:
|
||||
case XMLStreamReader.COMMENT:
|
||||
case XMLStreamReader.PROCESSING_INSTRUCTION:
|
||||
case XMLStreamReader.CDATA:
|
||||
case XMLStreamReader.CHARACTERS:
|
||||
continue;
|
||||
case XMLStreamReader.START_ELEMENT:
|
||||
case XMLStreamReader.END_ELEMENT:
|
||||
return next;
|
||||
}
|
||||
}
|
||||
if (eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG) {
|
||||
throw new XmlPullParserException("expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null);
|
||||
}
|
||||
return eventType;
|
||||
} //-- int nextTag(XmlPullParser)
|
||||
} //-- int nextTag(XMLStreamReader)
|
||||
|
||||
#foreach ( $class in $model.allClasses )
|
||||
#foreach ( $field in $class.getFields($version) )
|
||||
|
@ -434,16 +731,16 @@ public class ${className} {
|
|||
* @param defaultValue a defaultValue object.
|
||||
* @param parser a parser object.
|
||||
* @param attribute a attribute object.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean getBooleanValue(String s, String attribute, XmlPullParser parser, boolean defaultValue) throws XmlPullParserException {
|
||||
private boolean getBooleanValue(String s, String attribute, XMLStreamReader parser, boolean defaultValue) throws XMLStreamException {
|
||||
if (s != null && s.length() != 0) {
|
||||
return Boolean.valueOf(s).booleanValue();
|
||||
}
|
||||
return defaultValue;
|
||||
} //-- boolean getBooleanValue(String, String, XmlPullParser, String)
|
||||
} //-- boolean getBooleanValue(String, String, XMLStreamReader, String)
|
||||
|
||||
#end
|
||||
#if ( $hasIntegerField )
|
||||
|
@ -454,23 +751,23 @@ public class ${className} {
|
|||
* @param strict a strict object.
|
||||
* @param parser a parser object.
|
||||
* @param attribute a attribute object.
|
||||
* @throws XmlPullParserException XmlPullParserException if
|
||||
* @throws XMLStreamException XMLStreamException if
|
||||
* any.
|
||||
* @return int
|
||||
*/
|
||||
private int getIntegerValue(String s, String attribute, XmlPullParser parser, boolean strict, int defaultValue) throws XmlPullParserException {
|
||||
private int getIntegerValue(String s, String attribute, XMLStreamReader parser, boolean strict, int defaultValue) throws XMLStreamException {
|
||||
if (s != null) {
|
||||
try {
|
||||
return Integer.valueOf(s).intValue();
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
if (strict) {
|
||||
throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be an integer", parser, nfe);
|
||||
throw new XMLStreamException("Unable to parse element '" + attribute + "', must be an integer", parser.getLocation(), nfe);
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
} //-- int getIntegerValue(String, String, XmlPullParser, boolean)
|
||||
} //-- int getIntegerValue(String, String, XMLStreamReader, boolean)
|
||||
|
||||
#end
|
||||
public static interface ContentTransformer {
|
||||
|
@ -483,5 +780,39 @@ public class ${className} {
|
|||
*/
|
||||
String transform(String source, String fieldName);
|
||||
}
|
||||
|
||||
private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
|
||||
int eventType = parser.getEventType();
|
||||
if (eventType != XMLStreamReader.START_ELEMENT) {
|
||||
throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
|
||||
}
|
||||
eventType = parser.next();
|
||||
StringBuilder result = new StringBuilder();
|
||||
while (true) {
|
||||
if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
|
||||
result.append(parser.getText());
|
||||
} else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
|
||||
String val = null;
|
||||
if (strict) {
|
||||
throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
|
||||
} else if (addDefaultEntities) {
|
||||
val = DEFAULT_ENTITIES.get(parser.getLocalName());
|
||||
}
|
||||
if (val != null) {
|
||||
result.append(val);
|
||||
} else {
|
||||
result.append("&").append(parser.getLocalName()).append(";");
|
||||
}
|
||||
} else if (eventType != XMLStreamReader.COMMENT) {
|
||||
break;
|
||||
}
|
||||
eventType = parser.next();
|
||||
}
|
||||
if (eventType != XMLStreamReader.END_ELEMENT) {
|
||||
throw new XMLStreamException(
|
||||
"TEXT must be immediately followed by END_ELEMENT and not " + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -62,7 +62,6 @@ import org.apache.maven.internal.xml.XmlNodeBuilder;
|
|||
import ${packageModelV4}.${class.name};
|
||||
#end
|
||||
#end
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
|
||||
import org.codehaus.plexus.util.xml.pull.MXParser;
|
||||
import org.codehaus.plexus.util.xml.pull.MXSerializer;
|
||||
|
|
|
@ -58,7 +58,6 @@ import org.apache.maven.internal.xml.XmlNodeBuilder;
|
|||
#foreach ( $class in $model.allClasses )
|
||||
import ${packageModelV4}.${class.name};
|
||||
#end
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
|
||||
import org.codehaus.plexus.util.xml.pull.MXParser;
|
||||
import org.codehaus.plexus.util.xml.pull.MXSerializer;
|
||||
|
|
Loading…
Reference in New Issue