Skip to content

Commit

Permalink
Merge pull request #1 from LuukBerkel/Development
Browse files Browse the repository at this point in the history
Added: 'package' to the regex
  • Loading branch information
LarsHoendervangers authored Oct 30, 2021
2 parents 6d2ef31 + 80771b2 commit dda22ce
Show file tree
Hide file tree
Showing 70 changed files with 4,928 additions and 0 deletions.
57 changes: 57 additions & 0 deletions JSharp-IDE/JSharp-IDE.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31624.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JSharp-IDE", "JSharp-IDE\JSharp-IDE.csproj", "{95D619F8-0C28-42BC-B0E7-CE25ECABF956}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JSharp-Server", "JSharp-Server\JSharp-Server.csproj", "{94B61A45-2FD3-4363-AC69-DD5FE55E1572}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "JSharp-Shared", "JSharp-Shared\JSharp-Shared.shproj", "{02587232-53BE-471C-A8E3-D39AAF6EE745}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestShared", "UnitTestShared\UnitTestShared.csproj", "{AD3A1D42-D48F-401D-9811-51722D6783D6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestIDE", "UnitTestIDE\UnitTestIDE.csproj", "{B6AFCB05-65BB-4051-8BEB-B2BBF82CD5C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestServer", "UnitTestServer\UnitTestServer.csproj", "{B218790C-DC52-4576-9124-1D26F2AD2F38}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
JSharp-Shared\JSharp-Shared.projitems*{02587232-53be-471c-a8e3-d39aaf6ee745}*SharedItemsImports = 13
JSharp-Shared\JSharp-Shared.projitems*{94b61a45-2fd3-4363-ac69-dd5fe55e1572}*SharedItemsImports = 5
JSharp-Shared\JSharp-Shared.projitems*{95d619f8-0c28-42bc-b0e7-ce25ecabf956}*SharedItemsImports = 5
JSharp-Shared\JSharp-Shared.projitems*{ad3a1d42-d48f-401d-9811-51722d6783d6}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95D619F8-0C28-42BC-B0E7-CE25ECABF956}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95D619F8-0C28-42BC-B0E7-CE25ECABF956}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95D619F8-0C28-42BC-B0E7-CE25ECABF956}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95D619F8-0C28-42BC-B0E7-CE25ECABF956}.Release|Any CPU.Build.0 = Release|Any CPU
{94B61A45-2FD3-4363-AC69-DD5FE55E1572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94B61A45-2FD3-4363-AC69-DD5FE55E1572}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94B61A45-2FD3-4363-AC69-DD5FE55E1572}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94B61A45-2FD3-4363-AC69-DD5FE55E1572}.Release|Any CPU.Build.0 = Release|Any CPU
{AD3A1D42-D48F-401D-9811-51722D6783D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD3A1D42-D48F-401D-9811-51722D6783D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD3A1D42-D48F-401D-9811-51722D6783D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD3A1D42-D48F-401D-9811-51722D6783D6}.Release|Any CPU.Build.0 = Release|Any CPU
{B6AFCB05-65BB-4051-8BEB-B2BBF82CD5C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6AFCB05-65BB-4051-8BEB-B2BBF82CD5C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6AFCB05-65BB-4051-8BEB-B2BBF82CD5C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6AFCB05-65BB-4051-8BEB-B2BBF82CD5C4}.Release|Any CPU.Build.0 = Release|Any CPU
{B218790C-DC52-4576-9124-1D26F2AD2F38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B218790C-DC52-4576-9124-1D26F2AD2F38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B218790C-DC52-4576-9124-1D26F2AD2F38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B218790C-DC52-4576-9124-1D26F2AD2F38}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D01184E5-6A8C-4B49-AF9E-3225FF336C8D}
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions JSharp-IDE/JSharp-IDE/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Application x:Class="JSharp_IDE.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:JSharp_IDE"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ToastNotifications.Messages;component/Themes/Default.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions JSharp-IDE/JSharp-IDE/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace JSharp_IDE
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions JSharp-IDE/JSharp-IDE/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
248 changes: 248 additions & 0 deletions JSharp-IDE/JSharp-IDE/Compiler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
using JSharp_IDE.ViewModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace JSharp_IDE
{
class Compiler
{
public string CompilerPath { get; set; }
public MainWindowViewModel mwvm;

public Compiler(string compilerPath, MainWindowViewModel mwvm)
{
if (!Directory.Exists(compilerPath)) throw new Exception("Invalid java systemvariable path");
this.CompilerPath = compilerPath;
this.mwvm = mwvm;
}

/// <summary>
/// Compiles the java code into a java project.
/// </summary>
/// <param name="pathOut">Output directory</param>
/// <param name="pathSrc">Source directory</param>
/// <param name="pathLib">Library directory</param>
/// <param name="pathRes">Resources directory</param>
public void Compile(string pathOut, string pathSrc, string pathLib, string pathRes)
{

using (var compileTask = new Process())
{
//Checks
if ((!Directory.Exists(pathSrc)) &&
(!Directory.Exists(pathOut)) &&
(!Directory.Exists(pathLib)) &&
(!Directory.Exists(pathRes)))
throw new Exception("Invalid file path");

//libraries
string[] libraries = Directory.GetFiles(pathLib);
string libCommand = "";
foreach (string lib in libraries)
{
libCommand = libCommand + lib + ";";
}

//Resources
string resCommand = pathRes + ";";

//Files
string fileFinderCompiler(string pathFiles)
{
//If there is something in the directory
if (Directory.GetDirectories(pathFiles).Length > 0
|| Directory.GetFiles(pathFiles).Length > 0)
{
//Variables
string result = "";

//Search for files
string[] files = Directory.GetFiles(pathFiles);
foreach (string file in files)
{
if (file.Contains(".java"))
result += file + " ";
}

//Search for direcories
string[] directory = Directory.GetDirectories(pathFiles);
if (directory.Length > 0)
{
foreach (string dir in directory)
{
result += fileFinderCompiler(dir);
}
}

//Returning list..
return result;
}

//Throw exceptoin when now files are found..
throw new Exception("No files found");
}


//Arguments
string compileCommand = @"javac -cp " + libCommand + resCommand + @" ^ " + fileFinderCompiler(pathSrc) + " -d " + pathOut;


//Process
compileTask.StartInfo.FileName = @"cmd.exe";
compileTask.StartInfo.WorkingDirectory = pathOut;
compileTask.StartInfo.EnvironmentVariables["Path"] = this.CompilerPath;
compileTask.StartInfo.RedirectStandardInput = true;
compileTask.StartInfo.RedirectStandardOutput = true;
compileTask.StartInfo.RedirectStandardError = true;
compileTask.StartInfo.CreateNoWindow = true;
compileTask.Start();

//Execution
compileTask.StandardInput.WriteLine(compileCommand);
compileTask.StandardInput.Flush();
compileTask.StandardInput.Close();

//Checking
string error = compileTask.StandardError.ReadToEnd();
if (error.Length > 0 && error.Contains("error")) throw new Exception(error);

//Closing
compileTask.WaitForExit();
compileTask.Close();
}

}

/// <summary>
/// Runs the compiled java code.
/// </summary>
/// <param name="pathOut">Output directory</param>
/// <param name="pathLib">Library directory</param>
/// <param name="pathRes">Resources directory</param>
/// <param name="main">Main class directory</param>
public void Execute(string pathOut, string pathLib, string pathRes, string main)
{
new Thread(() =>
{
using (var executeTask = new Process())
{
//Checks
if ((!Directory.Exists(pathOut)) &&
(!Directory.Exists(pathLib)) &&
(!Directory.Exists(pathRes)))
throw new Exception("Invalid file path");

//libraries
string[] libraries = Directory.GetFiles(pathLib);
string libCommand = "";
foreach (string lib in libraries)
{
libCommand = libCommand + lib + ";";
}

//Resources
string resCommand = pathRes + "; ";

//Arguments
string executeCommand = @"java -classpath " + libCommand + resCommand + main;

//Process
executeTask.StartInfo.FileName = @"cmd.exe";
executeTask.StartInfo.WorkingDirectory = pathOut;
executeTask.StartInfo.RedirectStandardInput = true;
executeTask.StartInfo.RedirectStandardOutput = true;
executeTask.StartInfo.CreateNoWindow = true;
executeTask.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{

if (!String.IsNullOrEmpty(e.Data))
{
Debug.WriteLine(e.Data);
this.mwvm.DebugWindow += "\n" + e.Data;

}
});

executeTask.Start();

//Execution
executeTask.StandardInput.WriteLine(executeCommand);
executeTask.StandardInput.Flush();
executeTask.StandardInput.Close();
executeTask.BeginOutputReadLine();


executeTask.WaitForExit();
executeTask.Close();
}
}).Start();
}

/// <summary>
/// Searches the main method in all classes.
/// </summary>
/// <param name="pathSrc">Source directory</param>
/// <returns>The path to the main method.</returns>
public string MainSearcher(string pathSrc)
{
return MainFinder(pathSrc);
}

/// <summary>
/// Searches the main method in all classes.
/// This method is recursive.
/// </summary>
/// <param name="pathFiles">Source directory</param>
/// <returns>The path to the main method.</returns>
private string MainFinder(string pathFiles)
{
//If there is something in the directory
if (Directory.GetDirectories(pathFiles).Length > 0
|| Directory.GetFiles(pathFiles).Length > 0)
{
//Search for files
string[] files = Directory.GetFiles(pathFiles);
foreach (string file in files)
{
if (file.Contains(".java"))
{
string data = File.ReadAllText(file);

//Rip people that write it in mulptiple rules...
if (data.Contains("public static void main(String[] args)"))
{
FileInfo fileInfo = new FileInfo(file);
string filename = fileInfo.Name;
filename = filename.Remove(filename.IndexOf(fileInfo.Extension));
return filename;
}
}
}

//Search for direcories
string[] directory = Directory.GetDirectories(pathFiles);
if (directory.Length > 0)
{
foreach (string dir in directory)
{
string data = MainFinder(dir);
if (data != "")
{
string target = new DirectoryInfo(dir).Name;
return target + "." + data;
}
}
}
}
return "";
}
}
}



38 changes: 38 additions & 0 deletions JSharp-IDE/JSharp-IDE/JSharp-IDE.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<RootNamespace>JSharp_IDE</RootNamespace>
<UseWPF>true</UseWPF>
</PropertyGroup>

<Import Project="..\JSharp-Shared\JSharp-Shared.projitems" Label="Shared" />

<ItemGroup>
<None Remove="icons8-ok-50 %281%29.png" />
<None Remove="Resources\errror_icon.png" />
<None Remove="Resources\Hammer_30x.png" />
<None Remove="Resources\oke_icon.png" />
<None Remove="Resources\Run_16x.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="4.0.0" />
<PackageReference Include="ToastNotifications.Messages" Version="2.5.1" />
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\oke_icon.png" />
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\errror_icon.png" />
<Resource Include="Resources\Hammer_30x.png" />
<Resource Include="Resources\Run_16x.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>

</Project>
Loading

0 comments on commit dda22ce

Please sign in to comment.