Skip to content

Upgrade to Java 7 #5

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

Closed

Conversation

plamentotev
Copy link
Member

Hi,

As discussed on codehaus-plexus/plexus-archiver#55, Plexus Archiver is going to require Java 7.
I'm using the occasion to purpose an update for Plexus IO as well.

The proposed changes are:

  • Update the required Java version to 7
  • Use the new language features introduced in Java 7 ( diamond operators (<>) and try with resources)
  • And most importantly - Plexus IO uses the ls command to get the file attributes when running on Java versions prior to 7. Remove all legacy code and use only the Java 7 implementation.

Unfortunately the proposed changes are not backward compatible. Instead of having FileAttributes, Java7FileAttributes and Java7AttributeUtils, now we have FileAttributes and AttributeUtils. Java7Reflector, AttributeParserclasses and the public PlexusIoResourceAttributeUtils#getFileAttributesByPath( File dir, boolean recursive, boolean includeNumericUserId ) method are deleted. What do you think? We could remove the legacy code without changing the public interfaces and classes, but I think it's better to just remove the legacy code and interfaces - it will make the maintenance easier in long run.

p.s. If we make backward incompatible changes I guess we need to bump the project version.

@michael-o michael-o self-assigned this Apr 30, 2017
@michael-o
Copy link
Member

I just created milestone 3.0. I think it is best to bump version to 3.0.0 and get rid of all stuff no matter what. This is fine for a major release.

@michael-o michael-o added this to the 3.0 milestone Apr 30, 2017
@@ -114,8 +114,7 @@ private void createZipFile( File dest, File dir ) throws IOException
private void compare( InputStream in, File file )
throws IOException
{
InputStream fIn = new FileInputStream( file );
try
try(InputStream fIn = new FileInputStream( file ))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing whitespace.

sb.append("\nuid: ");
sb.append(hasUserId() ? Integer.toString(userId) : "");
sb.append("\ngid: ");
sb.append(hasGroupId() ? Integer.toString(groupId) : "");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use System.lineSeparator() instead of \n.

verifyLsModeSet( "-r--------", new boolean[]{ true, false, false, false, false, false, false, false, false } );
verifyLsModeSet( "--w-------", new boolean[]{ false, true, false, false, false, false, false, false, false } );
}
if ( Os.isFamily( Os.FAMILY_WINDOWS ) || Os.isFamily( Os.FAMILY_WIN9X ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can safely drop WIN9X.

@@ -94,7 +67,7 @@ public void testGetAttributesForThisTestClass()
assertEquals( System.getProperty( "user.name" ), fileAttrs.getUserName() );
}

public void testFolderJava7()
public void testFolder()
throws IOException, CommandLineException {

if (Os.isFamily( Os.FAMILY_WINDOWS ) || Os.isFamily( Os.FAMILY_WIN9X )){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here probably throughout.

@@ -200,119 +130,18 @@ public void testSrcResource()

assertTrue(pr.getOctalMode() > 0);
}
public void testPermissionDenied()
public void testNonExistingFolder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unix does not know folders, but only directories.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not quite sure I follow you. Do you mean that in Unix there are 'directories' not 'folders' and that's why the method name should be'testNonExistingDirectory? I choose this name because it's consistent with the rest of the existing test names (such as testFolderJava7).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, update accordingly since you already doing update.

@michael-o
Copy link
Member

Completed the review. Looks good to me. Please review the codestyle. In most cases whitespace is missing before and after parens.

@@ -183,141 +174,11 @@ public static PlexusIoResourceAttributes getFileAttributes( File file )
return o;
}

public static Map<String, PlexusIoResourceAttributes> getFileAttributesByPath( File dir )
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I've deleted this one by mistake - it does make sense and it's used by Plexus Archiver. I'll restore it.

README.md Outdated
It is therefore recommended to run mvn -Djava.language.downgrade=true clean install before relasing, to assess
that features still work with older jdk versions.


Version 2.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is incomplete anyway, drop it altogether.

@michael-o
Copy link
Member

Waiting for your updated PR. Tell me when you are done.

Now the changelog is kept in the Plexus Archiver project
and the Java version bit is also going to to outdated
after the update to Java 7.
@plamentotev plamentotev force-pushed the upgrade-to-java-7 branch from fc7cd6c to eb7996f Compare May 3, 2017 18:53
@plamentotev
Copy link
Member Author

I have updated the PR.

About the code style - there seems to be quite a lot violations. Maybe I should fix them in separate commit. Have to figure out how to do it though. The InteliJ Idea and Eclipse auto-formatting is long way from perfect.

@michael-o
Copy link
Member

Agreed. A separate commit makes sense. Let me review the new changes....

/*
* Copyright 2016 Plexus developers.
* Copyright 2011 The Codehaus Foundation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copyright change is weird...

Copy link
Member Author

@plamentotev plamentotev May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually FileAttributesTest is not modified at all. It's deleted and Java7FileAttributesTest is renamed to FileAttributesTest (the same goes for FileAttributes and Java7FileAttributes). Git shows those as diffs but they are actually delete + rename. Maybe I should state that explicitly in the commit message as it's not obvious from looking at the diffs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Please go ahead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I've modified the commit message.

The classes related to file attributes are depending on
features introduced in Java 7. To support Java version prior to 7,
plexus IO uses reflection check to choose between two
different implementations. The legacy one that parses the output
from the `ls` command and the Java 7 one that is pure Java.

Because now Java 7 is the minimum required version, remove all the
reflection Java version checks and remove any legacy code that
executes only for Java versions below 7.

There were two version of `FileAttributes` - `FileAttributes` and
`Java7FileAttributes`. Remove the legacy `FileAttributes` and rename
`Java7FileAttributes` to `FileAttributes`.
Rename `Java7AttributeUtils` to `AttributeUtils` as there is
no longer Java version specific implementations for
attributes related classes.

NOTE: The commit diff shows `FileAttributes` as changed
      but it's actually deleted and `Java7FileAttributes`
      is renamed to `FileAttributes`.
      The same goes for `FileAttributesTest` and `Java7FileAttributesTest`

Also remove `PlexusIoResourceAttributeUtils#getFileAttributesByPath( File dir, boolean recursive, boolean includeNumericUserId )`.
`includeNumericUserId` is related to the `ls` command and is no longer needed.

Update the tests. Delete no longer needed resources and tests.
All tests and resources related to the `ls` output parsing
are no longer needed. Also replace
`PlexusIoResourceAttributeUtilsTest#testPermissionDenied`
with `testNonExistingFolder` - when folder is missing
we no longer get `cannot access` response from
the `ls` command and the new test method name is more suitable.
We could quite safely assume that the tests are not going to be
executed on Windows 9x.
Unix uses the term 'Directory' and the test runs only
on Unix-like OSes. Change the test name accordingly.
@plamentotev plamentotev force-pushed the upgrade-to-java-7 branch from eb7996f to 9ccf45d Compare May 4, 2017 20:02
@plamentotev plamentotev force-pushed the upgrade-to-java-7 branch from 9ccf45d to 55773f5 Compare May 4, 2017 20:10
@plamentotev
Copy link
Member Author

I've fixed the code style. Or at least I've tried 😄 .

@michael-o
Copy link
Member

You did very well...
I will go on and create a branch for it

@michael-o
Copy link
Member

@michael-o michael-o closed this in b07738a May 9, 2017
@plamentotev plamentotev deleted the upgrade-to-java-7 branch May 9, 2017 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants