Skip to content

Commit b3b7866

Browse files
[MASSEMBLY-1017] Don't use deprecated methods in code (#182)
1 parent aeed884 commit b3b7866

File tree

10 files changed

+126
-88
lines changed

10 files changed

+126
-88
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ under the License.
6969
</distributionManagement>
7070

7171
<properties>
72+
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
73+
7274
<javaVersion>8</javaVersion>
7375
<mdoVersion>2.2.0</mdoVersion>
7476
<mavenVersion>3.2.5</mavenVersion>

src/main/java/org/apache/maven/plugins/assembly/archive/archiver/AssemblyProxyArchiver.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public AssemblyProxyArchiver(
129129
* {@inheritDoc}
130130
*/
131131
@Override
132+
@Deprecated
132133
public void addArchivedFileSet(
133134
final File archiveFile, final String prefix, final String[] includes, final String[] excludes) {
134135
inPublicApi.set(Boolean.TRUE);
@@ -158,6 +159,7 @@ private void debug(final String message) {
158159
* {@inheritDoc}
159160
*/
160161
@Override
162+
@Deprecated
161163
public void addArchivedFileSet(final File archiveFile, final String prefix) {
162164
inPublicApi.set(Boolean.TRUE);
163165
try {
@@ -178,6 +180,7 @@ public void addArchivedFileSet(final File archiveFile, final String prefix) {
178180
* {@inheritDoc}
179181
*/
180182
@Override
183+
@Deprecated
181184
public void addArchivedFileSet(final File archiveFile, final String[] includes, final String[] excludes) {
182185
inPublicApi.set(Boolean.TRUE);
183186
try {
@@ -200,6 +203,7 @@ public void addArchivedFileSet(final File archiveFile, final String[] includes,
200203
* {@inheritDoc}
201204
*/
202205
@Override
206+
@Deprecated
203207
public void addArchivedFileSet(final File archiveFile) {
204208
inPublicApi.set(Boolean.TRUE);
205209
try {
@@ -220,6 +224,7 @@ public void addArchivedFileSet(final File archiveFile) {
220224
* {@inheritDoc}
221225
*/
222226
@Override
227+
@Deprecated
223228
public void addDirectory(
224229
final File directory, final String prefix, final String[] includes, final String[] excludes) {
225230
inPublicApi.set(Boolean.TRUE);
@@ -270,6 +275,7 @@ public void addSymlink(String symlinkName, int permissions, String symlinkDestin
270275
* {@inheritDoc}
271276
*/
272277
@Override
278+
@Deprecated
273279
public void addDirectory(final File directory, final String prefix) {
274280
inPublicApi.set(Boolean.TRUE);
275281
try {
@@ -291,6 +297,7 @@ public void addDirectory(final File directory, final String prefix) {
291297
* {@inheritDoc}
292298
*/
293299
@Override
300+
@Deprecated
294301
public void addDirectory(final File directory, final String[] includes, final String[] excludes) {
295302
inPublicApi.set(Boolean.TRUE);
296303
try {
@@ -314,6 +321,7 @@ public void addDirectory(final File directory, final String[] includes, final St
314321
* {@inheritDoc}
315322
*/
316323
@Override
324+
@Deprecated
317325
public void addDirectory(final File directory) {
318326
inPublicApi.set(Boolean.TRUE);
319327
try {
@@ -777,6 +785,7 @@ public int getOverrideFileMode() {
777785
* {@inheritDoc}
778786
*/
779787
@Override
788+
@Deprecated
780789
public boolean isUseJvmChmod() {
781790
return useJvmChmod;
782791
}
@@ -785,6 +794,7 @@ public boolean isUseJvmChmod() {
785794
* {@inheritDoc}
786795
*/
787796
@Override
797+
@Deprecated
788798
public void setUseJvmChmod(final boolean useJvmChmod) {
789799
this.useJvmChmod = useJvmChmod;
790800
}
@@ -840,11 +850,13 @@ public boolean isSymbolicLink() {
840850
}
841851

842852
@Override
853+
@Deprecated
843854
public void setLastModifiedDate(Date lastModifiedDate) {
844855
delegate.setLastModifiedDate(lastModifiedDate);
845856
}
846857

847858
@Override
859+
@Deprecated
848860
public Date getLastModifiedDate() {
849861
return delegate.getLastModifiedDate();
850862
}
@@ -855,6 +867,7 @@ public void setFilenameComparator(Comparator<String> filenameComparator) {
855867
}
856868

857869
@Override
870+
@Deprecated
858871
public void configureReproducible(Date outputTimestamp) {
859872
delegate.configureReproducible(outputTimestamp);
860873
}

src/main/java/org/apache/maven/plugins/assembly/format/ReaderFormatter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ public InputStream transform(PlexusIoResource plexusIoResource, InputStream inpu
140140
configSource,
141141
isPropertyFile,
142142
configSource.getAdditionalProperties());
143-
result = encoding != null
144-
? new ReaderInputStream(filtered, encoding)
145-
: new ReaderInputStream(filtered);
143+
result = ReaderInputStream.builder()
144+
.setReader(filtered)
145+
.setCharset(encoding)
146+
.get();
146147
}
147148
if (transformLineEndings) {
148149
checkifFileTypeIsAppropriateForLineEndingTransformation(plexusIoResource);

src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ private Assembly addAssemblyForDescriptorReference(
180180
}
181181
}
182182

183-
try (Reader reader = new XmlStreamReader(resourceAsStream)) {
183+
try (Reader reader =
184+
XmlStreamReader.builder().setInputStream(resourceAsStream).get()) {
184185
final Assembly assembly = readAssembly(reader, ref, null, configSource);
185186
assemblies.add(assembly);
186187
return assembly;
@@ -201,7 +202,7 @@ private Assembly addAssemblyFromDescriptorFile(
201202
}
202203
}
203204

204-
try (Reader r = new XmlStreamReader(descriptor)) {
205+
try (Reader r = XmlStreamReader.builder().setFile(descriptor).get()) {
205206
final Assembly assembly =
206207
readAssembly(r, descriptor.getAbsolutePath(), descriptor.getParentFile(), configSource);
207208

@@ -233,7 +234,9 @@ private Assembly addAssemblyFromDescriptor(
233234
}
234235
}
235236

236-
try (Reader r = new XmlStreamReader(location.getInputStream())) {
237+
try (Reader r = XmlStreamReader.builder()
238+
.setInputStream(location.getInputStream())
239+
.get()) {
237240
File dir = null;
238241
if (location.getFile() != null) {
239242
dir = location.getFile().getParentFile();

src/main/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtils.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,9 @@ private static FixedStringSearchInterpolator executionPropertiesInterpolator(
197197
session = configSource.getMavenSession();
198198

199199
if (session != null) {
200-
Properties userProperties = session.getExecutionProperties(); // this is added twice....
201-
202-
if (userProperties != null) {
203-
return FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(userProperties));
204-
}
200+
return FixedStringSearchInterpolator.create(
201+
new PropertiesBasedValueSource(session.getUserProperties()),
202+
new PropertiesBasedValueSource(session.getSystemProperties()));
205203
}
206204
}
207205
return FixedStringSearchInterpolator.empty();

src/test/java/org/apache/maven/plugins/assembly/archive/archiver/AssemblyProxyArchiverTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public void addFile_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, Archiv
130130
}
131131

132132
@Test
133+
@SuppressWarnings("deprecation")
133134
public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
134135
final Archiver delegate = new JarArchiver();
135136

src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public void testAddDependencySet_ShouldInterpolateDefaultOutputFileNameMapping()
124124

125125
final MavenSession session = mock(MavenSession.class);
126126
when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
127-
when(session.getExecutionProperties()).thenReturn(new Properties());
127+
when(session.getUserProperties()).thenReturn(new Properties());
128+
when(session.getSystemProperties()).thenReturn(new Properties());
128129

129130
final AssemblerConfigurationSource configSource = mock(AssemblerConfigurationSource.class);
130131
when(configSource.getFinalName()).thenReturn(mainAid + "-" + mainVer);
@@ -158,7 +159,8 @@ public void testAddDependencySet_ShouldInterpolateDefaultOutputFileNameMapping()
158159
verify(archiver).setFileMode(146);
159160

160161
verify(session).getProjectBuildingRequest();
161-
verify(session, times(2)).getExecutionProperties();
162+
verify(session, times(2)).getUserProperties();
163+
verify(session, times(2)).getSystemProperties();
162164

163165
verify(projectBuilder).build(any(Artifact.class), any(ProjectBuildingRequest.class));
164166
}
@@ -211,7 +213,8 @@ public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed()
211213

212214
final MavenSession session = mock(MavenSession.class);
213215
when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
214-
when(session.getExecutionProperties()).thenReturn(new Properties());
216+
when(session.getUserProperties()).thenReturn(new Properties());
217+
when(session.getSystemProperties()).thenReturn(new Properties());
215218

216219
final AssemblerConfigurationSource configSource = mock(AssemblerConfigurationSource.class);
217220
when(configSource.getFinalName()).thenReturn("final-name");
@@ -238,7 +241,8 @@ public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed()
238241
verify(archiver).getOverrideFileMode();
239242

240243
verify(session).getProjectBuildingRequest();
241-
verify(session, times(2)).getExecutionProperties();
244+
verify(session, times(2)).getUserProperties();
245+
verify(session, times(2)).getSystemProperties();
242246

243247
verify(projectBuilder).build(any(Artifact.class), any(ProjectBuildingRequest.class));
244248
}
@@ -269,7 +273,8 @@ private void verifyOneDependencyAdded(final String outputLocation, final boolean
269273

270274
final MavenSession session = mock(MavenSession.class);
271275
when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
272-
when(session.getExecutionProperties()).thenReturn(new Properties());
276+
when(session.getUserProperties()).thenReturn(new Properties());
277+
when(session.getSystemProperties()).thenReturn(new Properties());
273278

274279
final AssemblerConfigurationSource configSource = mock(AssemblerConfigurationSource.class);
275280
when(configSource.getMavenSession()).thenReturn(session);
@@ -318,7 +323,8 @@ private void verifyOneDependencyAdded(final String outputLocation, final boolean
318323
verify(archiver).setDirectoryMode(146);
319324

320325
verify(session).getProjectBuildingRequest();
321-
verify(session, atLeastOnce()).getExecutionProperties();
326+
verify(session, atLeastOnce()).getUserProperties();
327+
verify(session, atLeastOnce()).getSystemProperties();
322328

323329
verify(projectBuilder).build(any(Artifact.class), any(ProjectBuildingRequest.class));
324330

src/test/java/org/apache/maven/plugins/assembly/filter/ComponentsXmlArchiverFileFilterTest.java

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@
4747
import org.codehaus.plexus.util.xml.Xpp3Dom;
4848
import org.jdom2.Document;
4949
import org.jdom2.Text;
50+
import org.jdom2.filter.Filters;
5051
import org.jdom2.input.SAXBuilder;
51-
import org.jdom2.xpath.XPath;
52+
import org.jdom2.input.sax.XMLReaders;
53+
import org.jdom2.xpath.XPathExpression;
54+
import org.jdom2.xpath.XPathFactory;
5255
import org.junit.Before;
5356
import org.junit.Rule;
5457
import org.junit.Test;
@@ -147,17 +150,19 @@ public void testAddToArchive_ShouldWriteComponentWithoutHintToFile() throws Exce
147150

148151
assertEquals(ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH, fca.getDestFileName());
149152

150-
final SAXBuilder builder = new SAXBuilder(false);
153+
final SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
151154

152155
final Document doc = builder.build(fca.getFile());
156+
XPathFactory xPathFactory = XPathFactory.instance();
153157

154-
final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
155-
final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
156-
final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
158+
XPathExpression<Text> role = xPathFactory.compile("//component[position()=1]/role/text()", Filters.text());
159+
XPathExpression<Text> hint = xPathFactory.compile("//component[position()=1]/role-hint/text()", Filters.text());
160+
XPathExpression<Text> implementation =
161+
xPathFactory.compile("//component[position()=1]/implementation/text()", Filters.text());
157162

158-
assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
159-
assertNull(hint.selectSingleNode(doc));
160-
assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
163+
assertEquals("role", role.evaluateFirst(doc).getText());
164+
assertNull(hint.evaluateFirst(doc));
165+
assertEquals("impl", implementation.evaluateFirst(doc).getText());
161166
}
162167

163168
@Test
@@ -173,17 +178,19 @@ public void testAddToArchive_ShouldWriteComponentWithHintToFile() throws Excepti
173178

174179
assertEquals(ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH, fca.getDestFileName());
175180

176-
final SAXBuilder builder = new SAXBuilder(false);
181+
final SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
177182

178183
final Document doc = builder.build(fca.getFile());
184+
XPathFactory xPathFactory = XPathFactory.instance();
179185

180-
final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
181-
final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
182-
final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
186+
XPathExpression<Text> role = xPathFactory.compile("//component[position()=1]/role/text()", Filters.text());
187+
XPathExpression<Text> hint = xPathFactory.compile("//component[position()=1]/role-hint/text()", Filters.text());
188+
XPathExpression<Text> implementation =
189+
xPathFactory.compile("//component[position()=1]/implementation/text()", Filters.text());
183190

184-
assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
185-
assertEquals("hint", ((Text) hint.selectSingleNode(doc)).getText());
186-
assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
191+
assertEquals("role", role.evaluateFirst(doc).getText());
192+
assertEquals("hint", hint.evaluateFirst(doc).getText());
193+
assertEquals("impl", implementation.evaluateFirst(doc).getText());
187194
}
188195

189196
@Test
@@ -204,25 +211,29 @@ public void testAddToArchive_ShouldWriteTwoComponentToFile() throws Exception {
204211

205212
assertEquals(ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH, fca.getDestFileName());
206213

207-
final SAXBuilder builder = new SAXBuilder(false);
214+
final SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
208215

209216
final Document doc = builder.build(fca.getFile());
210-
211-
final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
212-
final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
213-
final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
214-
215-
assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
216-
assertEquals("hint", ((Text) hint.selectSingleNode(doc)).getText());
217-
assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
218-
219-
final XPath role2 = XPath.newInstance("//component[position()=2]/role/text()");
220-
final XPath hint2 = XPath.newInstance("//component[position()=2]/role-hint/text()");
221-
final XPath implementation2 = XPath.newInstance("//component[position()=2]/implementation/text()");
222-
223-
assertEquals("role", ((Text) role2.selectSingleNode(doc)).getText());
224-
assertEquals("hint2", ((Text) hint2.selectSingleNode(doc)).getText());
225-
assertEquals("impl", ((Text) implementation2.selectSingleNode(doc)).getText());
217+
XPathFactory xPathFactory = XPathFactory.instance();
218+
219+
XPathExpression<Text> role = xPathFactory.compile("//component[position()=1]/role/text()", Filters.text());
220+
XPathExpression<Text> hint = xPathFactory.compile("//component[position()=1]/role-hint/text()", Filters.text());
221+
XPathExpression<Text> implementation =
222+
xPathFactory.compile("//component[position()=1]/implementation/text()", Filters.text());
223+
224+
assertEquals("role", role.evaluateFirst(doc).getText());
225+
assertEquals("hint", hint.evaluateFirst(doc).getText());
226+
assertEquals("impl", implementation.evaluateFirst(doc).getText());
227+
228+
XPathExpression<Text> role2 = xPathFactory.compile("//component[position()=2]/role/text()", Filters.text());
229+
XPathExpression<Text> hint2 =
230+
xPathFactory.compile("//component[position()=2]/role-hint/text()", Filters.text());
231+
XPathExpression<Text> implementation2 =
232+
xPathFactory.compile("//component[position()=2]/implementation/text()", Filters.text());
233+
234+
assertEquals("role", role2.evaluateFirst(doc).getText());
235+
assertEquals("hint2", hint2.evaluateFirst(doc).getText());
236+
assertEquals("impl", implementation2.evaluateFirst(doc).getText());
226237
}
227238

228239
@Test
@@ -257,25 +268,29 @@ public void testAddToArchive_ShouldWriteTwoComponentToArchivedFile() throws Exce
257268
Files.copy(zf.getInputStream(ze), descriptorFile.toPath());
258269
}
259270

260-
final SAXBuilder builder = new SAXBuilder(false);
271+
final SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
261272

262273
final Document doc = builder.build(descriptorFile);
263274

264-
final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
265-
final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
266-
final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
267-
268-
assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
269-
assertEquals("hint", ((Text) hint.selectSingleNode(doc)).getText());
270-
assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
271-
272-
final XPath role2 = XPath.newInstance("//component[position()=2]/role/text()");
273-
final XPath hint2 = XPath.newInstance("//component[position()=2]/role-hint/text()");
274-
final XPath implementation2 = XPath.newInstance("//component[position()=2]/implementation/text()");
275-
276-
assertEquals("role", ((Text) role2.selectSingleNode(doc)).getText());
277-
assertEquals("hint2", ((Text) hint2.selectSingleNode(doc)).getText());
278-
assertEquals("impl", ((Text) implementation2.selectSingleNode(doc)).getText());
275+
XPathFactory xPathFactory = XPathFactory.instance();
276+
XPathExpression<Text> role = xPathFactory.compile("//component[position()=1]/role/text()", Filters.text());
277+
XPathExpression<Text> hint = xPathFactory.compile("//component[position()=1]/role-hint/text()", Filters.text());
278+
XPathExpression<Text> implementation =
279+
xPathFactory.compile("//component[position()=1]/implementation/text()", Filters.text());
280+
281+
assertEquals("role", role.evaluateFirst(doc).getText());
282+
assertEquals("hint", hint.evaluateFirst(doc).getText());
283+
assertEquals("impl", implementation.evaluateFirst(doc).getText());
284+
285+
XPathExpression<Text> role2 = xPathFactory.compile("//component[position()=2]/role/text()", Filters.text());
286+
XPathExpression<Text> hint2 =
287+
xPathFactory.compile("//component[position()=2]/role-hint/text()", Filters.text());
288+
XPathExpression<Text> implementation2 =
289+
xPathFactory.compile("//component[position()=2]/implementation/text()", Filters.text());
290+
291+
assertEquals("role", role2.evaluateFirst(doc).getText());
292+
assertEquals("hint2", hint2.evaluateFirst(doc).getText());
293+
assertEquals("impl", implementation2.evaluateFirst(doc).getText());
279294
}
280295

281296
private Xpp3Dom createComponentDom(final ComponentDef def) {

0 commit comments

Comments
 (0)