Skip to content

Commit d2ddc56

Browse files
Get rid of usage deprecated Reader/WriterFactory
Fix #369
1 parent 43a88e4 commit d2ddc56

File tree

28 files changed

+76
-89
lines changed

28 files changed

+76
-89
lines changed

modello-core/src/main/java/org/codehaus/modello/ModelloCli.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import java.io.File;
2626
import java.util.Properties;
2727

28-
import org.codehaus.plexus.util.ReaderFactory;
2928
import org.codehaus.plexus.util.StringUtils;
29+
import org.codehaus.plexus.util.xml.XmlStreamReader;
3030

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

4444
parseArgumentsFromCommandLine(args);
4545

46-
modello.generate(ReaderFactory.newXmlReader(modelFile), outputType, parameters);
46+
modello.generate(new XmlStreamReader(modelFile), outputType, parameters);
4747
}
4848

4949
public static void parseArgumentsFromCommandLine(String[] args) throws Exception {

modello-core/src/main/java/org/codehaus/modello/core/DefaultModelloCore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import org.codehaus.modello.model.ModelInterface;
5454
import org.codehaus.modello.model.ModelValidationException;
5555
import org.codehaus.modello.plugin.ModelloGenerator;
56-
import org.codehaus.plexus.util.ReaderFactory;
56+
import org.codehaus.plexus.util.xml.XmlStreamReader;
5757

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

7676
public Model loadModel(File file) throws IOException, ModelloException, ModelValidationException {
77-
try (Reader reader = ReaderFactory.newXmlReader(file)) {
77+
try (Reader reader = new XmlStreamReader(file)) {
7878
return loadModel(reader);
7979
}
8080
}

modello-maven-plugin/src/it/maven-model/src/test/java/org/codehaus/modello/xpp3/Xpp3ParsingTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.Test;
77
import org.junit.rules.ExpectedException;
88
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
9-
import org.codehaus.plexus.util.ReaderFactory;
9+
import org.codehaus.plexus.util.xml.XmlStreamReader;
1010
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
1111
import org.hamcrest.core.StringStartsWith;
1212

@@ -28,7 +28,7 @@ public void testXpp3ParsingWithModelWithWrongRootTag()
2828

2929
MavenXpp3Reader reader = new MavenXpp3Reader();
3030

31-
reader.read( ReaderFactory.newXmlReader( model ), true );
31+
reader.read( new XmlStreamReader( model ), true );
3232
}
3333

3434
@Test
@@ -41,7 +41,7 @@ public void testXpp3ParsingWithModelWithMissingElements()
4141

4242
MavenXpp3Reader reader = new MavenXpp3Reader();
4343

44-
reader.read( ReaderFactory.newXmlReader( model ), true );
44+
reader.read( new XmlStreamReader( model ), true );
4545
}
4646

4747
@Test
@@ -55,7 +55,7 @@ public void testXpp3ParsingWithModelWithPostTags()
5555

5656
MavenXpp3Reader reader = new MavenXpp3Reader();
5757

58-
reader.read( ReaderFactory.newXmlReader( model ), true );
58+
reader.read( new XmlStreamReader( model ), true );
5959
}
6060

6161
}

modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/converters/ConverterGenerator.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.codehaus.modello.plugin.java.javasource.JType;
5353
import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata;
5454
import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata;
55-
import org.codehaus.plexus.util.IOUtil;
5655

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

313-
JSourceWriter interfaceWriter = null;
314-
JSourceWriter classWriter = null;
315-
316-
try {
317-
interfaceWriter = newJSourceWriter(packageName, conversionInterface.getName(true));
318-
classWriter = newJSourceWriter(packageName, basicConverterClass.getName(true));
319-
312+
try (JSourceWriter interfaceWriter = newJSourceWriter(packageName, conversionInterface.getName(true));
313+
JSourceWriter classWriter = newJSourceWriter(packageName, basicConverterClass.getName(true))) {
320314
conversionInterface.print(interfaceWriter);
321315
basicConverterClass.print(classWriter);
322-
} finally {
323-
IOUtil.close(classWriter);
324-
IOUtil.close(interfaceWriter);
325316
}
326317
}
327318

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

354-
JSourceWriter classWriter = null;
355-
try {
356-
classWriter = newJSourceWriter(packageName, converterClass.getName(true));
345+
try (JSourceWriter classWriter = newJSourceWriter(packageName, converterClass.getName(true))) {
357346
converterClass.print(new JSourceWriter(classWriter));
358-
} finally {
359-
IOUtil.close(classWriter);
360347
}
361348
}
362349

modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/Dom4jVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.codehaus.modello.test.model.io.dom4j.MavenDom4jWriter;
3636
import org.codehaus.modello.verifier.Verifier;
3737
import org.codehaus.plexus.util.FileUtils;
38-
import org.codehaus.plexus.util.ReaderFactory;
38+
import org.codehaus.plexus.util.xml.XmlStreamReader;
3939
import org.codehaus.plexus.util.xml.Xpp3Dom;
4040
import org.dom4j.DocumentException;
4141

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

83-
Reader reader = ReaderFactory.newXmlReader( new File( path ) );
83+
Reader reader = new XmlStreamReader( new File( path ) );
8484
MavenDom4jReader modelReader = new MavenDom4jReader();
8585

8686
Model model = modelReader.read( reader );

modello-plugins/modello-plugin-jackson/src/test/verifiers/jackson/JacksonVerifier.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.codehaus.modello.verifier.VerifierException;
4343
import org.codehaus.plexus.util.FileUtils;
4444
import org.codehaus.plexus.util.IOUtil;
45-
import org.codehaus.plexus.util.ReaderFactory;
4645

4746
import com.fasterxml.jackson.databind.JsonNode;
4847
import com.fasterxml.jackson.databind.ObjectMapper;

modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.HashSet;
3333
import java.util.Iterator;
3434
import java.util.List;
35+
import java.util.Objects;
3536
import java.util.Properties;
3637
import java.util.Set;
3738

@@ -1465,12 +1466,11 @@ private void createAssociation(JClass jClass, ModelAssociation modelAssociation,
14651466
}
14661467
}
14671468

1468-
if (StringUtils.equals(
1469-
javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.FIELD_INIT)) {
1469+
if (Objects.equals(javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.FIELD_INIT)) {
14701470
jField.setInitString(defaultValue);
14711471
}
14721472

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

14851485
JSourceCode sc = getter.getSourceCode();
14861486

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

modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JCompUnit.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@
7575
*/
7676

7777
import java.io.File;
78+
import java.nio.file.Files;
7879
import java.util.ArrayList;
7980
import java.util.Enumeration;
8081
import java.util.List;
8182
import java.util.SortedSet;
8283
import java.util.TreeSet;
8384

84-
import org.codehaus.plexus.util.WriterFactory;
85-
8685
/**
8786
* A representation of the Java Source code for a Java compilation
8887
* unit. This is
@@ -337,7 +336,7 @@ public void print(String destDir, String lineSeparator) {
337336
File file = new File(filename);
338337
JSourceWriter jsw = null;
339338
try {
340-
jsw = new JSourceWriter(WriterFactory.newPlatformWriter(file));
339+
jsw = new JSourceWriter(Files.newBufferedWriter(file.toPath()));
341340
} catch (java.io.IOException ioe) {
342341
System.out.println("unable to create compilation unit file: " + filename);
343342
return;

modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethodSignature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public final class JMethodSignature {
125125
**/
126126
public JMethodSignature(String name, JType returnType) {
127127

128-
if ((name == null) || (name.length() == 0)) {
128+
if ((name == null) || (name.isEmpty())) {
129129
String err = "The method name must not be null or zero-length";
130130
throw new IllegalArgumentException(err);
131131
}

modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JStructure.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@
6767
*/
6868

6969
import java.io.File;
70+
import java.nio.file.Files;
7071
import java.util.ArrayList;
7172
import java.util.Collections;
7273
import java.util.Enumeration;
7374
import java.util.List;
7475

75-
import org.codehaus.plexus.util.WriterFactory;
76-
7776
/**
7877
* This class represents the basic Java "structure" for a Java
7978
* source file. This is the base class for JClass and JInterface.
@@ -555,7 +554,7 @@ public void print(String destDir, String lineSeparator) {
555554
File file = new File(filename);
556555
JSourceWriter jsw = null;
557556
try {
558-
jsw = new JSourceWriter(WriterFactory.newPlatformWriter(file));
557+
jsw = new JSourceWriter(Files.newBufferedWriter(file.toPath()));
559558
} catch (java.io.IOException ioe) {
560559
System.out.println("unable to create class file: " + filename);
561560
return;

0 commit comments

Comments
 (0)