Skip to content
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

Fixed #96: reserved template manifest properties are preserved #97

Merged
merged 4 commits into from
Aug 8, 2018

Conversation

duncanp-lseg
Copy link

No description provided.

@ghost ghost assigned duncanp-lseg Aug 7, 2018
@ghost ghost added the Status: Needs Review label Aug 7, 2018
{
/// <summary>
/// Reads a valid v1.0 Jar Manifest.
/// See http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest
Copy link
Author

Choose a reason for hiding this comment

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

Simple reader to extract key-value pairs from an existing manifest file.
Required so we can copy single- and multi-line properties from the manifest in the template jar.

private const string RelativeConfigurationResourcePath = "org\\sonar\\plugins\\roslynsdk\\configuration.xml";
private const string RelativeRulesXmlResourcePath = "org\\sonar\\plugins\\roslynsdk\\rules.xml";
private const string RelativeConfigurationResourcePath = "org/sonar/plugins/roslynsdk/configuration.xml";
private const string RelativeRulesXmlResourcePath = "org/sonar/plugins/roslynsdk/rules.xml";
Copy link
Author

Choose a reason for hiding this comment

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

The relative path is used for both file paths and in the archive entry names. It has to be / for the archive entries, but can be either for the file paths so it's simpler just to to use /.

Choose a reason for hiding this comment

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

Maybe that's worth having this feedback directly in the code so we don't change it on the future (forgetting why this was done). Besides, maybe having a test on this (changing from private to internal) might help.

Copy link
Author

Choose a reason for hiding this comment

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

I'll add a comment but I don't think it's worth adding further tests. The only one where it really matters is for the ManifestResource path, and there are about a dozen tests that already fail if that is wrong. The other strings are passed to the ArchiveUpdater.AddFile method, which is defensive and replaces the backslashes with forward slashes anyway.

{
// This property must appear first in the manifest.
// See http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest
jarManifestBuilder.SetProperty("Sonar-Version", "4.5.2");
Copy link
Author

Choose a reason for hiding this comment

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

This was the bug - the SDK was hard-coding values that should have been copied from the template jar.

reader.FindValue("Sonar-Version").Should().Be("6.7");
reader.FindValue("Plugin-Class").Should().Be("org.sonar.plugins.roslynsdk.RoslynSdkGeneratedPlugin");
reader.FindValue("SonarLint-Supported").Should().Be("false");
reader.FindValue("Plugin-Dependencies").Should().Be("META-INF/lib/jsr305-1.3.9.jar META-INF/lib/commons-io-2.6.jar META-INF/lib/stax2-api-3.1.4.jar META-INF/lib/staxmate-2.0.1.jar META-INF/lib/stax-api-1.0.1.jar");
Copy link
Author

Choose a reason for hiding this comment

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

Regression test for the bug

* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/


Choose a reason for hiding this comment

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

[cosmetic] un-needed blank line.

throw new ArgumentNullException(nameof(manifestText));
}

kvps = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

Choose a reason for hiding this comment

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

[minor] This could be done inline with the declaration.

Copy link
Author

Choose a reason for hiding this comment

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

It could, but if there is a constructor I prefer to initialize it there - less jumping around when debugging.

var lines = joinedText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

// Every line should now be a key-value pair
foreach(var line in lines)

Choose a reason for hiding this comment

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

[cosmetic] Missing space after foreach

// The simplest way to rejoin the lines is just to replace all (EOL + space) with EOL

var joinedText = manifestText.Replace("\r\n ", string.Empty);
var lines = joinedText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

Choose a reason for hiding this comment

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

I am not sure to understand the logic here. You have replaced all \r\n by string.Empty and then want to split on \r\n so you are not going to split anything.

Copy link
Author

Choose a reason for hiding this comment

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

See the comment in line 48. It's replacing \r\n + space first i.e. any continuation lines will have been joined to a single line.

";
// Act
var jarReader = new JarManifestReader(text);

Choose a reason for hiding this comment

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

[cosmetic] un-needed blank line.

// multiple lines, with the continuation line starting with a single space.
// The simplest way to rejoin the lines is just to replace all (EOL + space) with EOL
var joinedText = manifestText.Replace("\r\n ", string.Empty);
var lines = joinedText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

Choose a reason for hiding this comment

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

Don't know why my previous comment was lost so I am redoing it:
This seems weird as you replace windows EOL by empty string and then on the replaced string you try to split on windows EOL.

Copy link
Author

Choose a reason for hiding this comment

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

I deleted a line, which might by why your comment and my reply were lost.

See the comment in line 44: it's removing EOL + space to re-join all of the continuation lines together. Any EOL that are not followed by a space will still be there.

Choose a reason for hiding this comment

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

OOOOOOOOH I didn't see the space after the \r\n... sorry for that.

private const string RelativeConfigurationResourcePath = "org\\sonar\\plugins\\roslynsdk\\configuration.xml";
private const string RelativeRulesXmlResourcePath = "org\\sonar\\plugins\\roslynsdk\\rules.xml";
private const string RelativeConfigurationResourcePath = "org/sonar/plugins/roslynsdk/configuration.xml";
private const string RelativeRulesXmlResourcePath = "org/sonar/plugins/roslynsdk/rules.xml";

Choose a reason for hiding this comment

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

Maybe that's worth having this feedback directly in the code so we don't change it on the future (forgetting why this was done). Besides, maybe having a test on this (changing from private to internal) might help.

@duncanp-lseg duncanp-lseg merged commit 10a1c69 into master Aug 8, 2018
@ghost ghost removed the Status: Needs Review label Aug 8, 2018
@duncanp-lseg duncanp-lseg deleted the duncanp/manifest96 branch August 8, 2018 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants