Skip to content

Get rid of usage deprecated Reader/WriterFactory #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.io.File;
import java.util.Properties;

import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.XmlStreamReader;

/**
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
Expand All @@ -43,7 +43,7 @@ public static void main(String[] args) throws Exception {

parseArgumentsFromCommandLine(args);

modello.generate(ReaderFactory.newXmlReader(modelFile), outputType, parameters);
modello.generate(new XmlStreamReader(modelFile), outputType, parameters);
}

public static void parseArgumentsFromCommandLine(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.codehaus.modello.model.ModelInterface;
import org.codehaus.modello.model.ModelValidationException;
import org.codehaus.modello.plugin.ModelloGenerator;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;

/**
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
Expand All @@ -74,7 +74,7 @@ public MetadataPluginManager getMetadataPluginManager() {
}

public Model loadModel(File file) throws IOException, ModelloException, ModelValidationException {
try (Reader reader = ReaderFactory.newXmlReader(file)) {
try (Reader reader = new XmlStreamReader(file)) {
return loadModel(reader);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.hamcrest.core.StringStartsWith;

Expand All @@ -28,7 +28,7 @@ public void testXpp3ParsingWithModelWithWrongRootTag()

MavenXpp3Reader reader = new MavenXpp3Reader();

reader.read( ReaderFactory.newXmlReader( model ), true );
reader.read( new XmlStreamReader( model ), true );
}

@Test
Expand All @@ -41,7 +41,7 @@ public void testXpp3ParsingWithModelWithMissingElements()

MavenXpp3Reader reader = new MavenXpp3Reader();

reader.read( ReaderFactory.newXmlReader( model ), true );
reader.read( new XmlStreamReader( model ), true );
}

@Test
Expand All @@ -55,7 +55,7 @@ public void testXpp3ParsingWithModelWithPostTags()

MavenXpp3Reader reader = new MavenXpp3Reader();

reader.read( ReaderFactory.newXmlReader( model ), true );
reader.read( new XmlStreamReader( model ), true );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.codehaus.modello.plugin.java.javasource.JType;
import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata;
import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata;
import org.codehaus.plexus.util.IOUtil;

/**
* Generate a basic conversion class between two versions of a model.
Expand Down Expand Up @@ -310,18 +309,10 @@ private void generateConverters(Version toVersion) throws ModelloException, IOEx
sc.add("return value;");
}

JSourceWriter interfaceWriter = null;
JSourceWriter classWriter = null;

try {
interfaceWriter = newJSourceWriter(packageName, conversionInterface.getName(true));
classWriter = newJSourceWriter(packageName, basicConverterClass.getName(true));

try (JSourceWriter interfaceWriter = newJSourceWriter(packageName, conversionInterface.getName(true));
JSourceWriter classWriter = newJSourceWriter(packageName, basicConverterClass.getName(true))) {
conversionInterface.print(interfaceWriter);
basicConverterClass.print(classWriter);
} finally {
IOUtil.close(classWriter);
IOUtil.close(interfaceWriter);
}
}

Expand Down Expand Up @@ -351,12 +342,8 @@ private void generateConverterTool(List<Version> allVersions) throws ModelloExce
}
writeConvertMethod(converterClass, objectModel, basePackage, allVersions, null, rootClass);

JSourceWriter classWriter = null;
try {
classWriter = newJSourceWriter(packageName, converterClass.getName(true));
try (JSourceWriter classWriter = newJSourceWriter(packageName, converterClass.getName(true))) {
converterClass.print(new JSourceWriter(classWriter));
} finally {
IOUtil.close(classWriter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.codehaus.modello.test.model.io.dom4j.MavenDom4jWriter;
import org.codehaus.modello.verifier.Verifier;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.dom4j.DocumentException;

Expand Down Expand Up @@ -80,7 +80,7 @@ public void verifyEncodedRead()
{
String path = "src/test/verifiers/dom4j/expected-encoding.xml";

Reader reader = ReaderFactory.newXmlReader( new File( path ) );
Reader reader = new XmlStreamReader( new File( path ) );
MavenDom4jReader modelReader = new MavenDom4jReader();

Model model = modelReader.read( reader );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.codehaus.modello.verifier.VerifierException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;

Expand Down Expand Up @@ -1465,12 +1466,11 @@ private void createAssociation(JClass jClass, ModelAssociation modelAssociation,
}
}

if (StringUtils.equals(
javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.FIELD_INIT)) {
if (Objects.equals(javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.FIELD_INIT)) {
jField.setInitString(defaultValue);
}

if (StringUtils.equals(
if (Objects.equals(
javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.CONSTRUCTOR_INIT)) {
jConstructorSource.add("this." + jField.getName() + " = " + defaultValue + ";");
}
Expand All @@ -1484,7 +1484,7 @@ private void createAssociation(JClass jClass, ModelAssociation modelAssociation,

JSourceCode sc = getter.getSourceCode();

if (StringUtils.equals(
if (Objects.equals(
javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.LAZY_INIT)) {
sc.add("if ( this." + jField.getName() + " == null )");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@
*/

import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import org.codehaus.plexus.util.WriterFactory;

/**
* A representation of the Java Source code for a Java compilation
* unit. This is
Expand Down Expand Up @@ -337,7 +336,7 @@ public void print(String destDir, String lineSeparator) {
File file = new File(filename);
JSourceWriter jsw = null;
try {
jsw = new JSourceWriter(WriterFactory.newPlatformWriter(file));
jsw = new JSourceWriter(Files.newBufferedWriter(file.toPath()));
} catch (java.io.IOException ioe) {
System.out.println("unable to create compilation unit file: " + filename);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public final class JMethodSignature {
**/
public JMethodSignature(String name, JType returnType) {

if ((name == null) || (name.length() == 0)) {
if ((name == null) || (name.isEmpty())) {
String err = "The method name must not be null or zero-length";
throw new IllegalArgumentException(err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@
*/

import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

import org.codehaus.plexus.util.WriterFactory;

/**
* This class represents the basic Java "structure" for a Java
* source file. This is the base class for JClass and JInterface.
Expand Down Expand Up @@ -555,7 +554,7 @@ public void print(String destDir, String lineSeparator) {
File file = new File(filename);
JSourceWriter jsw = null;
try {
jsw = new JSourceWriter(WriterFactory.newPlatformWriter(file));
jsw = new JSourceWriter(Files.newBufferedWriter(file.toPath()));
} catch (java.io.IOException ioe) {
System.out.println("unable to create class file: " + filename);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.codehaus.modello.verifier.VerifierException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.xmlunit.builder.DiffBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private void generateStaxReaderDelegate(List<String> versions) throws ModelloExc
jClass.addImport("javax.xml.stream.*");

jClass.addImport("org.codehaus.plexus.util.IOUtil");
jClass.addImport("org.codehaus.plexus.util.ReaderFactory");
jClass.addImport("org.codehaus.plexus.util.xml.XmlStreamReader");

JMethod method = new JMethod("read", new JClass("Object"), null);

Expand All @@ -404,7 +404,7 @@ private void generateStaxReaderDelegate(List<String> versions) throws ModelloExc
JSourceCode sc = method.getSourceCode();

sc.add("String modelVersion;");
sc.add("Reader reader = ReaderFactory.newXmlReader( f );");
sc.add("Reader reader = new XmlStreamReader( f );");

sc.add("try");
sc.add("{");
Expand All @@ -415,7 +415,7 @@ private void generateStaxReaderDelegate(List<String> versions) throws ModelloExc
sc.addIndented("IOUtil.close( reader );");
sc.add("}");

sc.add("reader = ReaderFactory.newXmlReader( f );");
sc.add("reader = new XmlStreamReader( f );");
sc.add("try");
sc.add("{");
sc.indent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.codehaus.modello.test.model.parts.io.stax.PartsStaxWriter;
import org.codehaus.modello.verifier.Verifier;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;

import java.io.File;
import java.io.IOException;
Expand All @@ -50,7 +50,7 @@ public void verify()
{
File file = new File( "src/test/verifiers/stax-parts/parts.xml" );

Reader reader = ReaderFactory.newXmlReader( file );
Reader reader = new XmlStreamReader( file );
PartsStaxReader modelReader = new PartsStaxReader();

Model model = modelReader.read( reader );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.codehaus.modello.test.model.vif.Model;
import org.codehaus.modello.test.model.vif.io.stax.VersionInFieldStaxReader;
import org.codehaus.modello.verifier.Verifier;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;

import java.io.File;
import java.io.IOException;
Expand All @@ -46,12 +46,12 @@ public void verify()
{
File file = new File( "src/test/verifiers/stax-version-in-field/version-in-field.xml" );

Reader reader = ReaderFactory.newXmlReader( file );
Reader reader = new XmlStreamReader( file );
VersionInFieldStaxReader modelReader = new VersionInFieldStaxReader();

Assert.assertEquals( "4.0.0", modelReader.determineVersion( reader ) );

reader = ReaderFactory.newXmlReader( file );
reader = new XmlStreamReader( file );
Model model = modelReader.read( reader );

Assert.assertEquals( "4.0.0", model.getModelVersion() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.codehaus.modello.test.model.vin.Model;
import org.codehaus.modello.test.model.vin.io.stax.VersionInNamespaceStaxReader;
import org.codehaus.modello.verifier.Verifier;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;

import java.io.File;
import java.io.IOException;
Expand All @@ -43,12 +43,12 @@ public void verify()
{
File file = new File( "src/test/verifiers/stax-version-in-namespace/version-in-namespace.xml" );

Reader reader = ReaderFactory.newXmlReader( file );
Reader reader = new XmlStreamReader( file );
VersionInNamespaceStaxReader modelReader = new VersionInNamespaceStaxReader();

Assert.assertEquals( "4.0.0", modelReader.determineVersion( reader ) );

reader = ReaderFactory.newXmlReader( file );
reader = new XmlStreamReader( file );
Model model = modelReader.read( reader );

Assert.assertEquals( "Maven", model.getName() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.codehaus.modello.test.model.vin.Model;
import org.codehaus.modello.test.model.vin.io.stax.VersionInNamespaceStaxReader;
import org.codehaus.modello.verifier.Verifier;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;

import java.io.File;
import java.io.IOException;
Expand All @@ -43,12 +43,12 @@ public void verify()
{
File file = new File( "src/test/verifiers/stax-wrong-version-in-namespace/wrong-version-in-namespace.xml" );

Reader reader = ReaderFactory.newXmlReader( file );
Reader reader = new XmlStreamReader( file );
VersionInNamespaceStaxReader modelReader = new VersionInNamespaceStaxReader();

Assert.assertEquals( "3.2.1", modelReader.determineVersion( reader ) );

reader = ReaderFactory.newXmlReader( file );
reader = new XmlStreamReader( file );
try
{
modelReader.read( reader );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.codehaus.modello.test.model.vif.Model;
import org.codehaus.modello.test.model.vif.io.stax.VersionInFieldStaxReader;
import org.codehaus.modello.verifier.Verifier;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;

import java.io.File;
import java.io.IOException;
Expand All @@ -43,12 +43,12 @@ public void verify()
{
File file = new File( "src/test/verifiers/stax-wrong-version/wrong-version.xml" );

Reader reader = ReaderFactory.newXmlReader( file );
Reader reader = new XmlStreamReader( file );
VersionInFieldStaxReader modelReader = new VersionInFieldStaxReader();

Assert.assertEquals( "1.2.3", modelReader.determineVersion( reader ) );

reader = ReaderFactory.newXmlReader( file );
reader = new XmlStreamReader( file );
try
{
modelReader.read( reader );
Expand Down
Loading