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

C# codegen support Context generation #140

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fbf96f2
Add .net platform C# solution generation
hamzajg Apr 13, 2022
61b8a3a
Add platform settings based generation
hamzajg Apr 13, 2022
1d9d515
Replace test template setting java sdk version
hamzajg Apr 13, 2022
e4d3a36
Fix default code formatter component registration
hamzajg Apr 13, 2022
486edee
Refactoring to codegen
hamzajg Apr 14, 2022
08c220f
Refactoring.
hamzajg Apr 14, 2022
b966cca
Add Readme file generation to application settings generation..
hamzajg Apr 14, 2022
3ae3774
Add shouldProcess based on dialect
hamzajg Apr 14, 2022
df08ad2
Add shouldProcess based on dialect
hamzajg Apr 14, 2022
8ac8f0e
Add shouldProcess based on dialect
hamzajg Apr 14, 2022
93a8eb0
Move designer model generation to codegen
hamzajg Apr 14, 2022
1385b07
Add C# code formatter
hamzajg Apr 14, 2022
f13b74a
Update platform UI..
hamzajg Apr 14, 2022
fb13293
Fix query unit test generation
hamzajg Apr 14, 2022
e3a7bc1
Fix code generation mapper
hamzajg Apr 15, 2022
133f3cb
Update platform UI..
hamzajg Apr 15, 2022
5dc98c4
Merge branch 'features/csharp_codegen_support' into features/csharp_c…
hamzajg Apr 15, 2022
b455a79
Formatting
hamzajg Apr 15, 2022
fbe0de6
Update UI..
hamzajg Apr 15, 2022
210a452
Update UI
hamzajg Apr 16, 2022
b7401c6
Add Context validation for .Net Platform
hamzajg Apr 20, 2022
5bcc982
Fix platformSettings check
hamzajg Apr 20, 2022
a68c0e7
Fix resolve imports
hamzajg Apr 20, 2022
b2aad3c
Use xoomVersion
hamzajg Apr 21, 2022
b4c30af
Fix shouldProcess
hamzajg Apr 21, 2022
9f7e7aa
Fix shouldProcess
hamzajg Apr 21, 2022
b979af8
Add C# context validator
hamzajg Apr 21, 2022
dc652ab
Update designer model formatter
hamzajg Apr 21, 2022
90f209d
Fix generation validation
hamzajg Apr 21, 2022
b82c19c
Fix generation target directory
hamzajg Apr 21, 2022
42e53a7
Refactoring..
hamzajg Apr 21, 2022
1d81852
Fix browser launcher platform
hamzajg Apr 21, 2022
398a67a
Fix solution generation data
hamzajg Apr 21, 2022
680f541
Fix shouldProcess queries test generation
hamzajg Apr 21, 2022
7b2a9e0
Add Unit Test project generation and .NET solution structure file system
hamzajg May 10, 2022
87b5e63
Merge remote-tracking branch 'origin/master' into features/csharp_cod…
hamzajg Jul 18, 2022
319026f
Merge remote-tracking branch 'origin/master' into features/csharp_cod…
hamzajg Jul 27, 2022
9fbaf03
Merge remote-tracking branch 'origin/master' into features/csharp_cod…
hamzajg Jan 5, 2023
87e6711
Merge remote-tracking branch 'origin/master' into features/csharp_cod…
hamzajg Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 15 additions & 42 deletions src/main/frontend/src/routes/context.svelte
Original file line number Diff line number Diff line change
@@ -1,59 +1,32 @@
<script>
import { TextField, Checkbox, Select } from "svelte-materialify/src";
import CardForm from "../components/CardForm.svelte";
import { artifactRule, packageRule, requireRule, versionRule, projectNameRule, frameworkRule } from '../validators';
import { artifactRule, packageRule, requireRule, versionRule, projectNameRule, namespaceRule } from '../validators';
import Validation from '../util/Validation';
import { settings, isValid } from '../stores';

// let groupId = $settings.context ? $settings.context.groupId : "";
// let artifactId = $settings.context ? $settings.context.artifactId : "";
// let artifactVersion = $settings.context ? $settings.context.artifactVersion : "";
// let packageName = $settings.context ? $settings.context.packageName : "";

// let projectName = $settings.context ? $settings.context.projectName : "";
// let outputDirectory = $settings.context ? $settings.context.outputDirectory : "";
// let solutionFile = $settings.context ? $settings.context.solutionFile : "";
// let projectPath = $settings.context ? $settings.context.projectPath : "";
// let isSameDirectoryActive = $settings.context ? $settings.context.isSameDirectoryActive : false;
// let framework = $settings.context ? $settings.context.framework : false;
// let sdk = $settings.context ? $settings.context.sdk : '';

// const availableSDKs = [
// { name: '3.1.402', value: '3.1.402' },
// { name: '2.1.300', value: '2.1.300' },
// ];
$: $isValid.context = Validation.validateContext($settings);
// $: $isValid.contextWithPlatform = Validation.validateContextWithPlatform($settings, $settings.platformSettings.platform === 'JVM' ? { groupId, artifactId, artifactVersion, packageName } : { projectName, outputDirectory, solutionFile, projectPath, isSameDirectoryActive, framework, sdk })
// $: $isValid.contextWithPlatform, () => $settings.context = $settings.platformSettings.platform === 'JVM' ? { groupId, artifactId, artifactVersion, packageName } : { projectName, outputDirectory, solutionFile, projectPath, isSameDirectoryActive, framework, sdk }
$: isJvmPlatform = !$settings.platformSettings || $settings.platformSettings.platform === 'JVM';
$: isDotNetPlatform = $settings.platformSettings && $settings.platformSettings.platform === '.NET';
$: $isValid.jvmContext = Validation.validateContext($settings);
$: $isValid.dotNetContext = Validation.validatePlatformWithContext($settings, $settings.context);
</script>

<svelte:head>
<title>Context</title>
</svelte:head>

<!-- add newbie tooltips -->
<!-- <CardForm title="Context" previous="platform" next="aggregates" bind:valid={$isValid.contextWithPlatform}>
{#if $settings.platformSettings && $settings.platformSettings.platform === '.NET'}
<TextField class="mb-4 pb-4" bind:value={solutionFile} rules={[requireRule, projectNameRule]}>Solution Name</TextField>
<TextField class="mb-4 pb-4" placeholder="MyCompany.MyTechnology.FirstFeature" bind:value={projectName} rules={[requireRule, projectNameRule]}>Project Name</TextField>
<TextField class="mb-4 pb-4" bind:value={outputDirectory} rules={[requireRule]}>Solution Directory</TextField>
<TextField class="mb-4 pb-4" bind:value={projectPath} rules={[requireRule]}>Project Path</TextField>
<Select class="mb-4 pb-4" items={availableSDKs} bind:value={sdk}>SDK</Select>
<TextField class="mb-4 pb-4" bind:value={framework} rules={[requireRule, frameworkRule]}>Framework</TextField>
<Checkbox bind:checked={isSameDirectoryActive}>Put solution and project in the same directory</Checkbox>
{:else if $settings.platformSettings && $settings.platformSettings.platform === 'JVM'}
<CardForm title="Context" next="aggregates" bind:valid={$isValid.context}>
<TextField class="mb-4 pb-4" placeholder="com.example" bind:value={$settings.context.groupId} rules={[requireRule, packageRule]} validateOnBlur={!$settings.context.groupId}>Group Id</TextField>
<TextField class="mb-4 pb-4" placeholder="demo" bind:value={$settings.context.artifactId} rules={[requireRule, artifactRule]} validateOnBlur={!$settings.context.artifactId}>Artifact Id</TextField>
<TextField class="mb-4 pb-4" placeholder="1.0.0" bind:value={$settings.context.artifactVersion} rules={[requireRule, versionRule]} validateOnBlur={!$settings.context.artifactVersion}>Artifact Version</TextField>
<TextField class="mb-4 pb-4" placeholder="com.example.demo" bind:value={$settings.context.packageName} rules={[requireRule, packageRule]} validateOnBlur={!$settings.context.packageName}>Base Package Name</TextField>
</CardForm>
{/if}
</CardForm> -->

<CardForm title="Context" next="aggregates" bind:valid={$isValid.context}>
{#if isJvmPlatform}
<CardForm title="Context" next="aggregates" bind:valid={$isValid.jvmContext}>
<TextField class="mb-4 pb-4" placeholder="com.example" bind:value={$settings.context.groupId} rules={[requireRule, packageRule]} validateOnBlur={!$settings.context.groupId}>Group Id</TextField>
<TextField class="mb-4 pb-4" placeholder="demo" bind:value={$settings.context.artifactId} rules={[requireRule, artifactRule]} validateOnBlur={!$settings.context.artifactId}>Artifact Id</TextField>
<TextField class="mb-4 pb-4" placeholder="1.0.0" bind:value={$settings.context.artifactVersion} rules={[requireRule, versionRule]} validateOnBlur={!$settings.context.artifactVersion}>Artifact Version</TextField>
<TextField class="mb-4 pb-4" placeholder="com.example.demo" bind:value={$settings.context.packageName} rules={[requireRule, packageRule]} validateOnBlur={!$settings.context.packageName}>Base Package Name</TextField>
</CardForm>
{:else if isDotNetPlatform}
<CardForm title="Context" next="aggregates" bind:valid={$isValid.dotNetContext}>
<TextField class="mb-4 pb-4" placeholder="Example" bind:value={$settings.context.solutionName} rules={[requireRule, projectNameRule]} validateOnBlur={!$settings.context.solutionName}>Solution Name</TextField>
<TextField class="mb-4 pb-4" placeholder="Demo" bind:value={$settings.context.projectName} rules={[requireRule, projectNameRule]} validateOnBlur={!$settings.context.projectName}>Project Name</TextField>
<TextField class="mb-4 pb-4" placeholder="1.0.0" bind:value={$settings.context.projectVersion} rules={[requireRule, versionRule]} validateOnBlur={!$settings.context.projectVersion}>Project Version</TextField>
<TextField class="mb-4 pb-4" placeholder="Io.Example.Demo " bind:value={$settings.context.namespace} rules={[requireRule, namespaceRule]} validateOnBlur={!$settings.context.namespace}>Base Namespace</TextField>
</CardForm>
{/if}
5 changes: 4 additions & 1 deletion src/main/frontend/src/routes/generation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@
function buildProjectDirectory() {
let context = $settings.context;
if(context) {
return `${$settingsInfo.userHomePath}${$settingsInfo.pathSeparator}VLINGO-XOOM${$settingsInfo.pathSeparator}${context.groupId}${$settingsInfo.pathSeparator}${context.artifactId}${Number($projectGenerationIndex)}`;
if(!$settings.platformSettings || $settings.platformSettings.platform === 'JVM')
return `${$settingsInfo.userHomePath}${$settingsInfo.pathSeparator}VLINGO-XOOM${$settingsInfo.pathSeparator}${context.groupId}${$settingsInfo.pathSeparator}${context.artifactId}${Number($projectGenerationIndex)}`;
else
return `${$settingsInfo.userHomePath}${$settingsInfo.pathSeparator}VLINGO-XOOM${$settingsInfo.pathSeparator}${context.solutionName}${$settingsInfo.pathSeparator}${context.projectName}${Number($projectGenerationIndex)}`;
}
return `${$settingsInfo.userHomePath}${$settingsInfo.pathSeparator}VLINGO-XOOM${$settingsInfo.pathSeparator}`;
}
Expand Down
185 changes: 123 additions & 62 deletions src/main/frontend/src/routes/platform.svelte
Original file line number Diff line number Diff line change
@@ -1,81 +1,142 @@
<script>
import { Switch, Radio } from "svelte-materialify/src";
import CardForm from "../components/CardForm.svelte";
import { settings } from "../stores";
import { Switch, Radio } from "svelte-materialify/src";
import CardForm from "../components/CardForm.svelte";
import { settings } from "../stores";

const platforms = [
{
name: 'JVM',
options: [
{
name: 'Java',
disabled: false,
},
{
name: 'Kotlin',
disabled: true
}
],
default: 'Java',
},
{
name: '.NET',
options: [
{
name: 'C#',
disabled: false
},
{
name: 'F#',
disabled: true
}
],
default: 'C#'
}
]

let value = $settings.platformSettings && $settings.platformSettings.platform === ".NET";
let lang = $settings.platformSettings && $settings.platformSettings.lang;
let options = platforms.reduce((acc, cur) => {
if ($settings.platformSettings && $settings.platformSettings.platform === cur.name) acc = [...cur.options]
return acc;
}, []);
const platforms = [
{
name: "JVM",
options: [
{
name: "Java",
value: "Java",
disabled: false,
sdkVersions: [],
xoomVersions: [],
},
{
name: "Kotlin",
value: "Kotlin",
disabled: true,
sdkVersions: [],
xoomVersions: [],
},
],
default: "Java",
},
{
name: ".NET",
options: [
{
name: "C#",
value: "C_SHARP",
disabled: false,
sdkVersions: [
{
name: "Net 6.0",
value: "net6.0",
},
],
xoomVersions: [
{
name: "1.9.3 (Stable)",
value: "1.9.3",
},
],
},
{
name: "F#",
value: "F_SHARP",
disabled: true,
sdkVersions: [],
xoomVersions: [],
},
],
default: "C#",
},
];

$: $settings.platformSettings = {
platform: value ? '.NET' : 'JVM',
lang
};
let value = $settings.platformSettings && $settings.platformSettings.platform === ".NET";
let platform = !$settings.platformSettings ? "JVM" : $settings.platformSettings.platform;
let lang = !$settings.platformSettings ? "Java" : $settings.platformSettings.lang;
let sdkVersion = !$settings.platformSettings ? "" : $settings.platformSettings.sdkVersion;
let xoomVersion = !$settings.platformSettings ? "" : $settings.platformSettings.xoomVersion;
let options = platforms.reduce((acc, cur) => {
if ( $settings.platformSettings && $settings.platformSettings.platform === cur.name)
acc = [...cur.options];
return acc;
}, []);

function updateOptions() {
const v = value ? '.NET' : 'JVM';
const platform = platforms.find(p => p.name === v)
if (platform) {
options = platform.options
lang = platform.options.some(o => o.name === lang) ? lang : platform.default
}
}
function updateOptions() {
const v = value ? ".NET" : "JVM";
const selectedPlatform = platforms.find((p) => p.name === v);
if (selectedPlatform) {
options = selectedPlatform.options;
lang = selectedPlatform.options.some((o) => o.value === lang) ? lang : selectedPlatform.default;
platform = selectedPlatform.name;
}
$settings.platformSettings = {
platform,
lang,
sdkVersion,
xoomVersion,
};
}

$: value, updateOptions()
$: value || (lang || sdkVersion || xoomVersion), updateOptions();
</script>

<svelte:head>
<title>Context</title>
<title>Platform</title>
</svelte:head>

<!-- add newbie tooltips -->
<CardForm title="Platform" next="context">
<div class="vl-switch d-flex justify-center mb-8 mt-8">
<b>JVM</b>
<!-- <Switch class="mr-4 ml-8" bind:checked={value} inset></Switch>
<b>.NET</b> -->
<Switch class="mr-4 ml-8" bind:checked={value} inset />
<b>.NET</b>
</div>

<div class="d-flex justify-center mb-8">
{#each options as option (option)}
<div class="ml-6 mr-6">
<Radio bind:group={lang} disabled={option.disabled} value={option.name}>{option.name}</Radio>
</div>
{/each}
<fieldset style="width: 50%;padding: 15px; border: none">
<legend>Language: </legend>
<div class="d-flex justify-center">
{#each options as option (option)}
<div class="ml-6 mr-6">
<Radio bind:group={lang} disabled={option.disabled} value={option.value}>{option.name}</Radio>
</div>
{/each}
</div>
{#each options as option (option)}
{#if !option.disabled}
{#if option.sdkVersions.length > 0}
<fieldset style="border: none">
<legend>SDK Version: </legend>
<div class="d-flex">
{#each option.sdkVersions as sdk (sdk)}
<div class="ml-6 mr-6">
<Radio bind:group={sdkVersion} value={sdk.value}>{sdk.name}</Radio>
</div>
{/each}
</div>
</fieldset>
{/if}
{#if option.xoomVersions.length > 0}
<fieldset style="border: none">
<legend>VLINGO Version: </legend>
<div class="d-flex">
{#each option.xoomVersions as vlingo (vlingo)}
<div class="ml-6 mr-6">
<Radio bind:group={xoomVersion} value={vlingo.value}>{vlingo.name}</Radio>
</div>
{/each}
</div>
</fieldset>
{/if}
{/if}
{/each}
</fieldset>
</div>
</CardForm>

Expand All @@ -88,4 +149,4 @@
transform: translate(72px);
}
}
</style>
</style>
3 changes: 2 additions & 1 deletion src/main/frontend/src/stores/context.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const defaultContext = {groupId: "", artifactId: "", artifactVersion: "", packageName: ""};
export const defaultContext = {groupId: "", artifactId: "", artifactVersion: "", packageName: ""};
export const dotNetContext = {solutionName: "", projectName: "", projectVersion: "", namespace: ""};
24 changes: 19 additions & 5 deletions src/main/frontend/src/stores/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {writable} from 'svelte/store';
import {defaultContext} from './context';
import {defaultContext, dotNetContext} from './context';
import {createLocalStore, isMobileStore} from './utils';
import {defaultPersistenceSettings} from './persistence';
import {defaultGenerationSettings, defaultSettings} from './generation';
Expand Down Expand Up @@ -91,10 +91,15 @@ function updateSettings(newSettings) {
}

function updateContext(currentSettings, updatedSettings) {
let updatedContext = updatedSettings.context ? updatedSettings.context : defaultContext;
let updatedContext = updatedSettings.context ? updatedSettings.context : resolveContext(currentSettings);
currentSettings.context = { ...currentSettings.context, ...updatedContext };
}

const resolveContext = (settings) => {
return settings.paltformSettings && settings.paltformSettings === '.NET' ? dotNetContext : defaultContext;
}


function updateAggregates(currentSettings, updatedSettings) {
if(!updatedSettings.model ||
!updatedSettings.model.aggregateSettings ||
Expand Down Expand Up @@ -146,10 +151,19 @@ function updateGeneration(currentSettings, updatedSettings) {
currentSettings.projectDirectory = updatedSettings.projectDirectory;
}

export function isSettingsComplete(currentSettings) {
return currentSettings.context && currentSettings.context.groupId && currentSettings.context.artifactId &&
const isContextSettingsComplete = (currentSettings) => {
if(!currentSettings.platformSettings || currentSettings.platformSettings.platform === 'JVM')
return currentSettings.context.groupId && currentSettings.context.artifactId &&
currentSettings.context.packageName && currentSettings.context.artifactVersion &&
Validation.validateContext(currentSettings) && currentSettings.model &&
Validation.validateContext(currentSettings);
else
return currentSettings.context.solutionName && currentSettings.context.projectName &&
currentSettings.context.projectVersion && currentSettings.context.namespace &&
Validation.validatePlatformWithContext(currentSettings, currentSettings.context);
}

export function isSettingsComplete(currentSettings) {
return currentSettings.context && isContextSettingsComplete(currentSettings) && currentSettings.model &&
currentSettings.model.aggregateSettings && currentSettings.model.aggregateSettings.length > 0 &&
currentSettings.model.persistenceSettings && Validation.validateDeployment(currentSettings)
&& currentSettings.projectDirectory;
Expand Down
5 changes: 3 additions & 2 deletions src/main/frontend/src/util/Validation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { artifactRule, packageRule, requireRule, versionRule } from '../validators';
import {artifactRule, namespaceRule, packageRule, projectNameRule, versionRule} from '../validators';

export default {
validateContext(settings) {
Expand All @@ -15,6 +15,7 @@ export default {
return aggregates && aggregates.length > 0;
},
validatePlatformWithContext(settings, context) {
return !!settings.platformSettings && ((settings.platformSettings.platform === 'JVM' && !packageRule(context.groupId) && !artifactRule(context.artifactId) && !versionRule(context.artifactVersion) && !packageRule(context.packageName)) || (settings.platformSettings.platform === '.NET' && context.projectName && !!context.outputDirectory && !!context.solutionFile && !!context.projectPath && !!context.framework && !!context.sdk && !projectNameRule(context.solutionFile) && !projectNameRule(context.projectName) && !frameworkRule(context.framework)))
return settings && settings.context && !projectNameRule(context.solutionName) && !projectNameRule(context.projectName)
&& !versionRule(settings.context.projectVersion) && !namespaceRule(settings.context.namespace);
}
}
6 changes: 4 additions & 2 deletions src/main/frontend/src/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const errors = Object.freeze({
EMPTY: "may not be empty",
VERSION: "Must be a semantic version number (major.minor.patch, e.g. 1.6.12)",
CLASSNAME: "must be initial cap (e.g. SomethingDefined)",
NAMESPACE: "Must be namespace syntax (e.g. com.example.demo)",
PACKAGE: "Must be package syntax (e.g. com.example.demo)",
NAMESPACE: "Must be namespace syntax (e.g. Com.Example.Demo)",
ARTIFACT: "Must consist of lowercase letters and hyphens",
FIELDNAME: "must follow java identifier pattern",
ROUTEPATH: "Must follow route path pattern",
Expand Down Expand Up @@ -55,7 +56,8 @@ const frameworks = [
export const requireRule = (value) => !!value ? undefined : errors.EMPTY;

export const versionRule = (value) => /^\d+\.\d+\.\d+$/.test(value) ? undefined : errors.VERSION;
export const packageRule = (value) => /^[a-z]+(\.[a-zA-Z_]([a-zA-Z_$#\d])*)+$/.test(value) ? undefined : errors.NAMESPACE;
export const packageRule = (value) => /^[a-z]+(\.[a-zA-Z_]([a-zA-Z_$#\d])*)+$/.test(value) ? undefined : errors.PACKAGE;
export const namespaceRule = (value) => /^[A-Za-z]+(\.[a-zA-Z_]([a-zA-Z_$#\d])*)+$/.test(value) ? undefined : errors.NAMESPACE;
export const artifactRule = (value) => /^[a-z-]+$/.test(value) ? undefined : errors.ARTIFACT;
export const classNameRule = (value) => /^[A-Z]+[A-Za-z]*$/.test(value) ? undefined : errors.CLASSNAME;
export const identifierRule = (value) => /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(value) ? undefined : errors.FIELDNAME;
Expand Down