Skip to content
Merged
2 changes: 2 additions & 0 deletions src/dotnet/APIView/APIView/Model/CodeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public string VersionString

public string Language { get; set; }

public string Variant { get; set; }

public string PackageName { get; set; }

public string ServiceName { get; set; }
Expand Down
5 changes: 3 additions & 2 deletions src/dotnet/APIView/APIViewWeb/Models/ReviewCodeFileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class ReviewCodeFileModel
// This is field is more of a display name. It is set to name value returned by parser which has package name and version in following format
// Package name ( Version )
public string Name { get; set; }

public string Language
{
get => _language ?? (Name.EndsWith(".json", StringComparison.OrdinalIgnoreCase) ? "Json" : "C#");
Expand All @@ -23,6 +22,8 @@ public string Language

public string VersionString { get; set; }

public string Variant { get; set; }

public bool HasOriginal { get; set; }

public DateTime CreationDate { get; set; } = DateTime.Now;
Expand All @@ -36,4 +37,4 @@ public string Language
// This field stores original file name uploaded to create review
public string FileName { get; set; }
}
}
}
3 changes: 3 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Models/ReviewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public string DisplayName
[JsonIgnore]
public string Language => Revisions.LastOrDefault()?.Files.LastOrDefault()?.Language;

[JsonIgnore]
public string Variant => Revisions.LastOrDefault()?.Files.LastOrDefault()?.Variant;

[JsonIgnore]
public string PackageName {
get
Expand Down
19 changes: 18 additions & 1 deletion src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,24 @@
<span><img class="mx-1" src="~/icons/go-original.svg" width="40" alt="@Model.Review.Language"></span>
break;
case "java":
<span><img class="mx-1" src="~/icons/java-original.svg" width="40" alt="@Model.Review.Language"></span>
if(@Model.Review.Variant != null)
{
switch(@Model.Review.Variant.ToLower())
{
case "spring":
<span><img class="mx-1" src="~/icons/java-spring-original.svg" width="40" alt="@Model.Review.Language @Model.Review.Variant"></span>
break;
case "android":
<span><img class="mx-1" src="~/icons/java-android-original.svg" width="40" alt="@Model.Review.Language @Model.Review.Variant"></span>
break;
default:
<span><img class="mx-1" src="~/icons/java-original.svg" width="40" alt="@Model.Review.Language"></span>
break;

@JonathanGiles Jonathan Giles (JonathanGiles) Aug 1, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Eventually I would like to see this change to instead be a single line that uses code along the following lines:

if (variant != null && !variant.isEmpty()) {
    // set the img class property to be 'language-variant' (e.g. 'java-android')
} else {
    // set the img class property to be 'language' (e.g. 'java')
}

Then move all of the image file references out to CSS, e.g.

img.java {

}
img.java-android {

}

}
} else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

{
<span><img class="mx-1" src="~/icons/java-original.svg" width="40" alt="@Model.Review.Language"></span>
}
break;
case "swift":
<span><img class="mx-1" src="~/icons/swift-original.svg" width="40" alt="@Model.Review.Language"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,24 @@
<img class="mx-1" src="~/icons/go-original.svg" alt="@review.Language">
break;
case "java":
<img class="mx-1" src="~/icons/java-original.svg" alt="@review.Language">
if(@review.Variant != null)
{
switch(@review.Variant.ToLower())
{
case "spring":
<img class="mx-1" src="~/icons/java-spring-original.svg" alt="@review.Language @review.Variant">
break;
case "android":
<img class="mx-1" src="~/icons/java-android-original.svg" alt="@review.Language @review.Variant">
break;
default:
<img class="mx-1" src="~/icons/java-original.svg" alt="@review.Language">
break;
}
} else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As much as it pains me (as a Java engineer), the C# expectation here is to put the closing brace and the else on separate lines.

{
<img class="mx-1" src="~/icons/java-original.svg" alt="@review.Language">
}
break;
case "swift":
<img class="mx-1" src="~/icons/swift-original.svg" alt="@review.Language">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ public async Task ToggleIsClosedAsync(ClaimsPrincipal user, string id)
private void InitializeFromCodeFile(ReviewCodeFileModel file, CodeFile codeFile)
{
file.Language = codeFile.Language;
file.Variant = codeFile.Variant;
file.VersionString = codeFile.VersionString;
file.Name = codeFile.Name;
file.PackageName = codeFile.PackageName;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.tools.apiview.processor.model.APIListing;
import com.azure.tools.apiview.processor.model.Diagnostic;
import com.azure.tools.apiview.processor.model.DiagnosticKind;
import com.azure.tools.apiview.processor.model.LanguageVariant;
import com.azure.tools.apiview.processor.model.Token;
import com.azure.tools.apiview.processor.model.maven.Pom;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down Expand Up @@ -157,6 +158,15 @@ private static void processJavaSourcesJar(File inputFile, APIListing apiListing)
apiListing.setLanguage("Java");
apiListing.setMavenPom(reviewProperties.getMavenPom());

if(packageName.contains("spring")) {

@srnagar Srikanta (srnagar) Aug 1, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: let's use groupId.contains("spring") instead of packageName(which is groupId:artifactId) to ensure artifact names that happen to contain spring (not very likely) aren't classified as Spring libraries. As Jonathan Giles (@JonathanGiles) suggested below, we may want a different way to identify this but until then, we can go by the group name.

Just to add a bit more context here, we use groupId to differentiate between Spring, Android and Java Azure libraries.

com.azure - Java libraries
com.azure.android - Android libraries
com.azure.spring - Spring libraries.

Artifact Ids can be any of the hundreds of Azure service names and there's a chance that they may contain terms like "spring" and are not related to the Spring framework.

apiListing.setVariant(LanguageVariant.SPRING);
} else if(packageName.contains("android")) {
apiListing.setVariant(LanguageVariant.ANDROID);
} else {
apiListing.setVariant(LanguageVariant.DEFAULT);
}
System.out.println(" Using '" + apiListing.getVariant() + "' for the language variant");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Eventually we will want a smarter way of discerning this, but it should do for now


final Analyser analyser = new JavaASTAnalyser(inputFile, apiListing);

// Read all files within the jar file so that we can create a list of files to analyse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class APIListing {
@JsonProperty("Language")
private String language;

@JsonProperty("Variant")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Let's name the property LanguageVariant to match the type and is more specific than just variant. You might want to consider doing that in other places too.

private LanguageVariant variant;

@JsonProperty("PackageName")
private String packageName;

Expand Down Expand Up @@ -91,6 +94,14 @@ public void setLanguage(final String language) {
this.language = language;
}

public LanguageVariant getVariant() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: getLanguageVariant()

return variant;
}

public void setVariant(final LanguageVariant variant) {
this.variant = variant;
}

public String getPackageName() {
return packageName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.azure.tools.apiview.processor.model;

import com.fasterxml.jackson.annotation.JsonValue;

public enum LanguageVariant {
DEFAULT("Default"),
SPRING("Spring"),
ANDROID("Android");

private final String variantName;

LanguageVariant(String name) {
this.variantName = name;
}

@Override
@JsonValue
public String toString() {
return this.variantName;
}
}