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

Feature/3465 support for java variants #3797

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
14 changes: 14 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@
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)
JonathanGiles marked this conversation as resolved.
Show resolved Hide resolved
{
@switch(@Model.Review.Variant.ToLower())
{
case "spring":
<span><img class="mx-1" src="~/icons/java-spring-original.svg" width="40" alt="@Model.Review.Variant"></span>
break;
case "android":
<span><img class="mx-1" src="~/icons/java-android-original.svg" width="40" alt="@Model.Review.Variant"></span>
break;
default:
break;
}
}
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 @@ -47,6 +47,20 @@
break;
case "java":
<img class="mx-1" src="~/icons/java-original.svg" alt="@review.Language">
@if(@review.Variant != null)
JonathanGiles marked this conversation as resolved.
Show resolved Hide resolved
{
@switch(@review.Variant.ToLower())
{
case "spring":
<img class="mx-1" src="~/icons/java-spring-original.svg" alt="@review.Variant">
break;
case "android":
<img class="mx-1" src="~/icons/java-android-original.svg" alt="@review.Variant">
break;
default:
break;
}
}
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.indexOf("spring") > -1) {
apiListing.setVariant(LanguageVariant.Spring);
} else if(packageName.indexOf("android") > -1) {
apiListing.setVariant(LanguageVariant.Android);
} else {
apiListing.setVariant(LanguageVariant.Default);
}
System.out.println(" Using '" + apiListing.getVariant() + "' for the language variant");
Copy link
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
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
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,7 @@
package com.azure.tools.apiview.processor.model;

public enum LanguageVariant {
Default,
Spring,
Android,
JonathanGiles marked this conversation as resolved.
Show resolved Hide resolved
}