Skip to content

Commit

Permalink
[MASSEMBLY-1017] Don't use deprecated methods in code (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski authored Feb 4, 2024
1 parent aeed884 commit b3b7866
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 88 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ under the License.
</distributionManagement>

<properties>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>

<javaVersion>8</javaVersion>
<mdoVersion>2.2.0</mdoVersion>
<mavenVersion>3.2.5</mavenVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public AssemblyProxyArchiver(
* {@inheritDoc}
*/
@Override
@Deprecated
public void addArchivedFileSet(
final File archiveFile, final String prefix, final String[] includes, final String[] excludes) {
inPublicApi.set(Boolean.TRUE);
Expand Down Expand Up @@ -158,6 +159,7 @@ private void debug(final String message) {
* {@inheritDoc}
*/
@Override
@Deprecated
public void addArchivedFileSet(final File archiveFile, final String prefix) {
inPublicApi.set(Boolean.TRUE);
try {
Expand All @@ -178,6 +180,7 @@ public void addArchivedFileSet(final File archiveFile, final String prefix) {
* {@inheritDoc}
*/
@Override
@Deprecated
public void addArchivedFileSet(final File archiveFile, final String[] includes, final String[] excludes) {
inPublicApi.set(Boolean.TRUE);
try {
Expand All @@ -200,6 +203,7 @@ public void addArchivedFileSet(final File archiveFile, final String[] includes,
* {@inheritDoc}
*/
@Override
@Deprecated
public void addArchivedFileSet(final File archiveFile) {
inPublicApi.set(Boolean.TRUE);
try {
Expand All @@ -220,6 +224,7 @@ public void addArchivedFileSet(final File archiveFile) {
* {@inheritDoc}
*/
@Override
@Deprecated
public void addDirectory(
final File directory, final String prefix, final String[] includes, final String[] excludes) {
inPublicApi.set(Boolean.TRUE);
Expand Down Expand Up @@ -270,6 +275,7 @@ public void addSymlink(String symlinkName, int permissions, String symlinkDestin
* {@inheritDoc}
*/
@Override
@Deprecated
public void addDirectory(final File directory, final String prefix) {
inPublicApi.set(Boolean.TRUE);
try {
Expand All @@ -291,6 +297,7 @@ public void addDirectory(final File directory, final String prefix) {
* {@inheritDoc}
*/
@Override
@Deprecated
public void addDirectory(final File directory, final String[] includes, final String[] excludes) {
inPublicApi.set(Boolean.TRUE);
try {
Expand All @@ -314,6 +321,7 @@ public void addDirectory(final File directory, final String[] includes, final St
* {@inheritDoc}
*/
@Override
@Deprecated
public void addDirectory(final File directory) {
inPublicApi.set(Boolean.TRUE);
try {
Expand Down Expand Up @@ -777,6 +785,7 @@ public int getOverrideFileMode() {
* {@inheritDoc}
*/
@Override
@Deprecated
public boolean isUseJvmChmod() {
return useJvmChmod;
}
Expand All @@ -785,6 +794,7 @@ public boolean isUseJvmChmod() {
* {@inheritDoc}
*/
@Override
@Deprecated
public void setUseJvmChmod(final boolean useJvmChmod) {
this.useJvmChmod = useJvmChmod;
}
Expand Down Expand Up @@ -840,11 +850,13 @@ public boolean isSymbolicLink() {
}

@Override
@Deprecated
public void setLastModifiedDate(Date lastModifiedDate) {
delegate.setLastModifiedDate(lastModifiedDate);
}

@Override
@Deprecated
public Date getLastModifiedDate() {
return delegate.getLastModifiedDate();
}
Expand All @@ -855,6 +867,7 @@ public void setFilenameComparator(Comparator<String> filenameComparator) {
}

@Override
@Deprecated
public void configureReproducible(Date outputTimestamp) {
delegate.configureReproducible(outputTimestamp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ public InputStream transform(PlexusIoResource plexusIoResource, InputStream inpu
configSource,
isPropertyFile,
configSource.getAdditionalProperties());
result = encoding != null
? new ReaderInputStream(filtered, encoding)
: new ReaderInputStream(filtered);
result = ReaderInputStream.builder()
.setReader(filtered)
.setCharset(encoding)
.get();
}
if (transformLineEndings) {
checkifFileTypeIsAppropriateForLineEndingTransformation(plexusIoResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ private Assembly addAssemblyForDescriptorReference(
}
}

try (Reader reader = new XmlStreamReader(resourceAsStream)) {
try (Reader reader =
XmlStreamReader.builder().setInputStream(resourceAsStream).get()) {
final Assembly assembly = readAssembly(reader, ref, null, configSource);
assemblies.add(assembly);
return assembly;
Expand All @@ -201,7 +202,7 @@ private Assembly addAssemblyFromDescriptorFile(
}
}

try (Reader r = new XmlStreamReader(descriptor)) {
try (Reader r = XmlStreamReader.builder().setFile(descriptor).get()) {
final Assembly assembly =
readAssembly(r, descriptor.getAbsolutePath(), descriptor.getParentFile(), configSource);

Expand Down Expand Up @@ -233,7 +234,9 @@ private Assembly addAssemblyFromDescriptor(
}
}

try (Reader r = new XmlStreamReader(location.getInputStream())) {
try (Reader r = XmlStreamReader.builder()
.setInputStream(location.getInputStream())
.get()) {
File dir = null;
if (location.getFile() != null) {
dir = location.getFile().getParentFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ private static FixedStringSearchInterpolator executionPropertiesInterpolator(
session = configSource.getMavenSession();

if (session != null) {
Properties userProperties = session.getExecutionProperties(); // this is added twice....

if (userProperties != null) {
return FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(userProperties));
}
return FixedStringSearchInterpolator.create(
new PropertiesBasedValueSource(session.getUserProperties()),
new PropertiesBasedValueSource(session.getSystemProperties()));
}
}
return FixedStringSearchInterpolator.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public void addFile_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, Archiv
}

@Test
@SuppressWarnings("deprecation")
public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
final Archiver delegate = new JarArchiver();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public void testAddDependencySet_ShouldInterpolateDefaultOutputFileNameMapping()

final MavenSession session = mock(MavenSession.class);
when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
when(session.getExecutionProperties()).thenReturn(new Properties());
when(session.getUserProperties()).thenReturn(new Properties());
when(session.getSystemProperties()).thenReturn(new Properties());

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

verify(session).getProjectBuildingRequest();
verify(session, times(2)).getExecutionProperties();
verify(session, times(2)).getUserProperties();
verify(session, times(2)).getSystemProperties();

verify(projectBuilder).build(any(Artifact.class), any(ProjectBuildingRequest.class));
}
Expand Down Expand Up @@ -211,7 +213,8 @@ public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed()

final MavenSession session = mock(MavenSession.class);
when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
when(session.getExecutionProperties()).thenReturn(new Properties());
when(session.getUserProperties()).thenReturn(new Properties());
when(session.getSystemProperties()).thenReturn(new Properties());

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

verify(session).getProjectBuildingRequest();
verify(session, times(2)).getExecutionProperties();
verify(session, times(2)).getUserProperties();
verify(session, times(2)).getSystemProperties();

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

final MavenSession session = mock(MavenSession.class);
when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
when(session.getExecutionProperties()).thenReturn(new Properties());
when(session.getUserProperties()).thenReturn(new Properties());
when(session.getSystemProperties()).thenReturn(new Properties());

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

verify(session).getProjectBuildingRequest();
verify(session, atLeastOnce()).getExecutionProperties();
verify(session, atLeastOnce()).getUserProperties();
verify(session, atLeastOnce()).getSystemProperties();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.jdom2.Document;
import org.jdom2.Text;
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.xpath.XPath;
import org.jdom2.input.sax.XMLReaders;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -147,17 +150,19 @@ public void testAddToArchive_ShouldWriteComponentWithoutHintToFile() throws Exce

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

final SAXBuilder builder = new SAXBuilder(false);
final SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);

final Document doc = builder.build(fca.getFile());
XPathFactory xPathFactory = XPathFactory.instance();

final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
XPathExpression<Text> role = xPathFactory.compile("//component[position()=1]/role/text()", Filters.text());
XPathExpression<Text> hint = xPathFactory.compile("//component[position()=1]/role-hint/text()", Filters.text());
XPathExpression<Text> implementation =
xPathFactory.compile("//component[position()=1]/implementation/text()", Filters.text());

assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
assertNull(hint.selectSingleNode(doc));
assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
assertEquals("role", role.evaluateFirst(doc).getText());
assertNull(hint.evaluateFirst(doc));
assertEquals("impl", implementation.evaluateFirst(doc).getText());
}

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

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

final SAXBuilder builder = new SAXBuilder(false);
final SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);

final Document doc = builder.build(fca.getFile());
XPathFactory xPathFactory = XPathFactory.instance();

final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
XPathExpression<Text> role = xPathFactory.compile("//component[position()=1]/role/text()", Filters.text());
XPathExpression<Text> hint = xPathFactory.compile("//component[position()=1]/role-hint/text()", Filters.text());
XPathExpression<Text> implementation =
xPathFactory.compile("//component[position()=1]/implementation/text()", Filters.text());

assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
assertEquals("hint", ((Text) hint.selectSingleNode(doc)).getText());
assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
assertEquals("role", role.evaluateFirst(doc).getText());
assertEquals("hint", hint.evaluateFirst(doc).getText());
assertEquals("impl", implementation.evaluateFirst(doc).getText());
}

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

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

final SAXBuilder builder = new SAXBuilder(false);
final SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);

final Document doc = builder.build(fca.getFile());

final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");

assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
assertEquals("hint", ((Text) hint.selectSingleNode(doc)).getText());
assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());

final XPath role2 = XPath.newInstance("//component[position()=2]/role/text()");
final XPath hint2 = XPath.newInstance("//component[position()=2]/role-hint/text()");
final XPath implementation2 = XPath.newInstance("//component[position()=2]/implementation/text()");

assertEquals("role", ((Text) role2.selectSingleNode(doc)).getText());
assertEquals("hint2", ((Text) hint2.selectSingleNode(doc)).getText());
assertEquals("impl", ((Text) implementation2.selectSingleNode(doc)).getText());
XPathFactory xPathFactory = XPathFactory.instance();

XPathExpression<Text> role = xPathFactory.compile("//component[position()=1]/role/text()", Filters.text());
XPathExpression<Text> hint = xPathFactory.compile("//component[position()=1]/role-hint/text()", Filters.text());
XPathExpression<Text> implementation =
xPathFactory.compile("//component[position()=1]/implementation/text()", Filters.text());

assertEquals("role", role.evaluateFirst(doc).getText());
assertEquals("hint", hint.evaluateFirst(doc).getText());
assertEquals("impl", implementation.evaluateFirst(doc).getText());

XPathExpression<Text> role2 = xPathFactory.compile("//component[position()=2]/role/text()", Filters.text());
XPathExpression<Text> hint2 =
xPathFactory.compile("//component[position()=2]/role-hint/text()", Filters.text());
XPathExpression<Text> implementation2 =
xPathFactory.compile("//component[position()=2]/implementation/text()", Filters.text());

assertEquals("role", role2.evaluateFirst(doc).getText());
assertEquals("hint2", hint2.evaluateFirst(doc).getText());
assertEquals("impl", implementation2.evaluateFirst(doc).getText());
}

@Test
Expand Down Expand Up @@ -257,25 +268,29 @@ public void testAddToArchive_ShouldWriteTwoComponentToArchivedFile() throws Exce
Files.copy(zf.getInputStream(ze), descriptorFile.toPath());
}

final SAXBuilder builder = new SAXBuilder(false);
final SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);

final Document doc = builder.build(descriptorFile);

final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");

assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
assertEquals("hint", ((Text) hint.selectSingleNode(doc)).getText());
assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());

final XPath role2 = XPath.newInstance("//component[position()=2]/role/text()");
final XPath hint2 = XPath.newInstance("//component[position()=2]/role-hint/text()");
final XPath implementation2 = XPath.newInstance("//component[position()=2]/implementation/text()");

assertEquals("role", ((Text) role2.selectSingleNode(doc)).getText());
assertEquals("hint2", ((Text) hint2.selectSingleNode(doc)).getText());
assertEquals("impl", ((Text) implementation2.selectSingleNode(doc)).getText());
XPathFactory xPathFactory = XPathFactory.instance();
XPathExpression<Text> role = xPathFactory.compile("//component[position()=1]/role/text()", Filters.text());
XPathExpression<Text> hint = xPathFactory.compile("//component[position()=1]/role-hint/text()", Filters.text());
XPathExpression<Text> implementation =
xPathFactory.compile("//component[position()=1]/implementation/text()", Filters.text());

assertEquals("role", role.evaluateFirst(doc).getText());
assertEquals("hint", hint.evaluateFirst(doc).getText());
assertEquals("impl", implementation.evaluateFirst(doc).getText());

XPathExpression<Text> role2 = xPathFactory.compile("//component[position()=2]/role/text()", Filters.text());
XPathExpression<Text> hint2 =
xPathFactory.compile("//component[position()=2]/role-hint/text()", Filters.text());
XPathExpression<Text> implementation2 =
xPathFactory.compile("//component[position()=2]/implementation/text()", Filters.text());

assertEquals("role", role2.evaluateFirst(doc).getText());
assertEquals("hint2", hint2.evaluateFirst(doc).getText());
assertEquals("impl", implementation2.evaluateFirst(doc).getText());
}

private Xpp3Dom createComponentDom(final ComponentDef def) {
Expand Down
Loading

0 comments on commit b3b7866

Please sign in to comment.