Skip to content

Commit

Permalink
6.2 release branch setup with windup working
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Jun 16, 2023
1 parent 4937c63 commit d9dc3fb
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 103 deletions.
2 changes: 2 additions & 0 deletions client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@
"select": "Select",
"settingsAllowApps": "Allow reviewing applications without running an assessment first",
"source": "Source",
"settingsCSVReports": "Enable downloads for CSV reports",
"settingsHTMLReports": "Enable downloads for HTML reports",
"sourceBranch": "Branch",
"sourceCode": "Source code",
"sourceRepo": "Source Repository",
Expand Down
2 changes: 2 additions & 0 deletions client/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
"scheduled": "Programado",
"select": "Seleccione",
"settingsAllowApps": "Permitir la revisión de aplicaciones sin ejecutar una evaluación primero",
"settingsCSVReports": "Habilitar descargas para informes CSV",
"settingsHTMLReports": "Habilitar descargas para informes HTML",
"sourceBranch": "Rama",
"sourceCode": "Código fuente.",
"sourceRepo": "Repositorio",
Expand Down
8 changes: 4 additions & 4 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ export interface ApplicationImportPage {
}

export type SettingTypes = {
"download.csv.enabled": boolean;
"download.html.enabled": boolean;
"git.insecure.enabled": boolean;
"mvn.dependencies.update.forced": boolean;
"mvn.insecure.enabled": boolean;
Expand Down Expand Up @@ -385,6 +387,7 @@ export interface TaskData {
tagger: {
enabled: boolean;
};
output: string;
mode: {
binary: boolean;
withDeps: boolean;
Expand All @@ -409,10 +412,7 @@ export interface TaskData {
rulesets: Ref[];
repository?: Repository;
identity?: Ref;
labels: {
included: string[];
excluded: string[];
};
labels: string[];
};
}

Expand Down
90 changes: 31 additions & 59 deletions client/src/app/common/CustomRules/rules-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IReadFile, ParsedRule, Rule, Ruleset } from "@app/api/models";
import yaml from "js-yaml";
import { IReadFile, ParsedRule, Ruleset } from "@app/api/models";

type RuleFileType = "YAML" | "XML" | null;

Expand All @@ -14,69 +13,43 @@ export const checkRuleFileType = (filename: string): RuleFileType => {

export const parseRules = (file: IReadFile): ParsedRule => {
if (file.data) {
if (checkRuleFileType(file.fileName) === "YAML") {
const yamlDoc = yaml.load(file.data) as any[];
const yamlLabels = yamlDoc?.reduce((acc, parsedLine) => {
const newLabels = parsedLine?.labels ? parsedLine?.labels : [];
return [...acc, ...newLabels];
}, []);
const allLabels = getLabels(yamlLabels);
return {
source: allLabels?.sourceLabel,
target: allLabels?.targetLabel,
otherLabels: allLabels?.otherLabels,
allLabels: allLabels?.allLabels,
total: 0,
...(file.responseID && {
fileID: file.responseID,
}),
};
} else if (checkRuleFileType(file.fileName) === "XML") {
let source: string | null = null;
let target: string | null = null;
let rulesCount = 0;
let source: string | null = null;
let target: string | null = null;
let rulesCount = 0;

const parser = new DOMParser();
const xml = parser.parseFromString(file.data, "text/xml");
const parser = new DOMParser();
const xml = parser.parseFromString(file.data, "text/xml");

const ruleSets = xml.getElementsByTagName("ruleset");
const ruleSets = xml.getElementsByTagName("ruleset");

if (ruleSets && ruleSets.length > 0) {
const metadata = ruleSets[0].getElementsByTagName("metadata");
if (ruleSets && ruleSets.length > 0) {
const metadata = ruleSets[0].getElementsByTagName("metadata");

if (metadata && metadata.length > 0) {
const sources = metadata[0].getElementsByTagName("sourceTechnology");
if (sources && sources.length > 0) source = sources[0].id;
if (metadata && metadata.length > 0) {
const sources = metadata[0].getElementsByTagName("sourceTechnology");
if (sources && sources.length > 0) source = sources[0].id;

const targets = metadata[0].getElementsByTagName("targetTechnology");
if (targets && targets.length > 0) target = targets[0].id;
}

const rulesGroup = ruleSets[0].getElementsByTagName("rules");
if (rulesGroup && rulesGroup.length > 0)
rulesCount = rulesGroup[0].getElementsByTagName("rule").length;
const targets = metadata[0].getElementsByTagName("targetTechnology");
if (targets && targets.length > 0) target = targets[0].id;
}
const allLabels = [
...(source ? [`konveyor.io/source=${source}`] : []),
...(target ? [`konveyor.io/target=${target}`] : []),
];
return {
source: source,
target: target,
otherLabels: allLabels,
allLabels: allLabels,
total: rulesCount,
...(file.responseID && {
fileID: file.responseID,
}),
};
} else {
return {
source: null,
target: null,
total: 0,
};

const rulesGroup = ruleSets[0].getElementsByTagName("rules");
if (rulesGroup && rulesGroup.length > 0)
rulesCount = rulesGroup[0].getElementsByTagName("rule").length;
}
const allLabels = [
...(source ? [`konveyor.io/source=${source}`] : []),
...(target ? [`konveyor.io/target=${target}`] : []),
];
return {
source,
target,
total: rulesCount,
allLabels,
...(file.responseID && {
fileID: file.responseID,
}),
};
} else {
return {
source: null,
Expand All @@ -85,7 +58,6 @@ export const parseRules = (file: IReadFile): ParsedRule => {
};
}
};

interface ILabelMap {
sourceLabel: string;
targetLabel: string;
Expand Down
31 changes: 14 additions & 17 deletions client/src/app/common/CustomRules/useRuleFiles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useContext, useState } from "react";
import XSDSchema from "./windup-jboss-ruleset.xsd";
import { XMLValidator } from "fast-xml-parser";
import { FileLoadError, IReadFile } from "@app/api/models";
import { NotificationsContext } from "@app/shared/notifications-context";
import { AxiosError } from "axios";
Expand All @@ -7,9 +9,6 @@ import { getAxiosErrorMessage } from "@app/utils/utils";
import { useCreateFileMutation } from "@app/queries/rulesets";
import { CustomTargetFormValues } from "@app/pages/migration-targets/custom-target-form";
import { UseFormReturn } from "react-hook-form";
import { XMLValidator } from "fast-xml-parser";
import XSDSchema from "./windup-jboss-ruleset.xsd";
import { checkRuleFileType } from "./rules-utils";
const xmllint = require("xmllint");

export default function useRuleFiles(
Expand Down Expand Up @@ -199,22 +198,15 @@ export default function useRuleFiles(
handleReadFail(error, 100, file);
} else {
if (data) {
if (checkRuleFileType(file.name) === "XML") {
const validatedXMLResult = validateXMLFile(data);
if (validatedXMLResult.state === "valid") {
handleReadSuccess(data, file);
} else {
const error = new Error(
`File "${file.name}" is not a valid XML: ${validatedXMLResult.message}`
);
handleReadFail(error, 100, file);
}
} else {
const validatedXMLResult = validateXMLFile(data);
if (validatedXMLResult.state === "valid")
handleReadSuccess(data, file);
else {
const error = new Error(
`File "${file.name}" is not a valid XML: ${validatedXMLResult.message}`
);
handleReadFail(error, 100, file);
}
} else {
const error = new Error("error");
handleReadFail(error, 100, file);
}
}
}
Expand Down Expand Up @@ -314,6 +306,11 @@ export default function useRuleFiles(
};
};

interface IParsedXMLFileStatus {
state: "valid" | "error";
message?: string;
}

return {
handleFileDrop,
removeFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface IAnalysisWizard {
}

const defaultTaskData: TaskData = {
output: "/windup/report",
tagger: {
enabled: true,
},
Expand All @@ -56,8 +57,6 @@ const defaultTaskData: TaskData = {
artifact: "",
diva: false,
},
targets: [],
sources: [],
scope: {
withKnown: false,
packages: {
Expand All @@ -68,8 +67,8 @@ const defaultTaskData: TaskData = {
};

const defaultTaskgroup: Taskgroup = {
name: `taskgroup.analyzer`,
addon: "analyzer",
name: `taskgroup.windup`,
addon: "windup",
data: {
...defaultTaskData,
},
Expand Down Expand Up @@ -194,7 +193,6 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({

const { handleSubmit, watch, reset } = methods;
const values = watch();
console.log("values", values);

enum StepId {
AnalysisMode = 1,
Expand Down Expand Up @@ -256,13 +254,10 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
},
},
rules: {
labels: {
included: [
...fieldValues.formTargets,
...fieldValues.selectedFormSources,
],
excluded: [],
},
labels: [
...fieldValues.formTargets,
...fieldValues.selectedFormSources,
],
path: fieldValues.customRulesFiles.length > 0 ? "/rules" : "",
tags: {
excluded: fieldValues.excludedRulesTags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,14 @@ export const CustomRules: React.FC<CustomRulesProps> = (props) => {
<MultipleFileUpload
onFileDrop={handleFileDrop}
dropzoneProps={{
accept: ".yml, .yaml, .xml",
accept: ".xml",
}}
>
<MultipleFileUploadMain
titleIcon={<UploadIcon />}
titleText="Drag and drop files here"
titleTextSeparator="or"
infoText="Accepted file types: .yml, .yaml, .xml "
infoText="Accepted file types: .xml "
/>
{showStatus && (
<MultipleFileUploadStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const ApplicationsTableAnalyze: React.FC = () => {
activeAppInDetailDrawer,
} = useApplicationsFilterValues(ApplicationTableType.Analysis, applications);

const { tasks } = useFetchTasks({ addon: "analyzer" });
const { tasks } = useFetchTasks({ addon: "windup" });

const queryClient = useQueryClient();
const allTasksComplete = tasks.every((task) => task.state !== "Running");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const ApplicationsTable: React.FC = () => {
refetch: fetchApplications,
} = useFetchApplications();

const { tasks } = useFetchTasks({ addon: "analyzer" });
const { tasks } = useFetchTasks({ addon: "windup" });

const getTask = (application: Application) =>
tasks.find((task: Task) => task.application?.id === application.id);
Expand Down
Loading

0 comments on commit d9dc3fb

Please sign in to comment.