Remove version control from Eclipose RCP project - eclipse-plugin

I have an Eclipse RCP application that uses EGit and JGit to implement the version control of projects.
In some cases, I want to make it so that a project is no longer under version control. This implies both deleting the project's .git directory on the file system, and making my application aware that the project is not under version control.
I tried looking through the JGit API for solutions to this, but could not find anything useful. Simply deleting the .git directory using a file manipulation API is not sufficient, as some files in it seem to be locked (very likely by JGit).

Sorry, I'm not 100% sure because your scenario is not clear enough to me, however you said that your application is based also on EGit, so I assume that you are using the standard eclipse APIs to manage the projects. If this is the case, what you are looking for is: org.eclipse.team.core.RepositoryProvider
This is an example:
public class UntrackProject extends AbstractHandler implements IHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IProject project = getProject(); // get the project, for example using the selection service
try {
RepositoryProvider.unmap(project);
//TODO Refresh your viewer to show changes
} catch (TeamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
For reference, you can check the handler of the context menu "Disconnect", that does exactly what you are looking for: org.eclipse.egit.ui.internal.actions.DisconnectActionHandler
https://git.eclipse.org/c/egit/egit.git/tree/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DisconnectActionHandler.java
It uses a lot of internal classes of egit, but in the end it uses the RepositoryProvider's API.
Note that the method RepositoryProvider.unmap(project) does NOT delete the repository, it just disconnects the project.
I hope this helps!

Related

IntelliJ autocompletion plugin development for Gherkin steps

I've recently started working on IntelliJ plugin development and got stuck a bit with autocompletion implementation.
Don't want to go deep into the details of plugins idea, but I would like to pass some strings through autocompletion into the Gherkin steps.
If Gherkin plugin in IntelliJ is disabled (file is expressed as plain text), there are no problems for passing 'Message' value to step through autocompletion. If plugin is enabled, it does not work.
Example of scenario:
Scenario: Successful message appearance
When user access home page
When user sees message "Message"
Example of completion contributor:
public SimpleCompletionContributor() {
extend(CompletionType.BASIC, PlatformPatterns.psiElement(),
new CompletionProvider<>() {
public void addCompletions(#NotNull CompletionParameters parameters,
#NotNull ProcessingContext context,
#NotNull CompletionResultSet resultSet) {
resultSet.addElement(LookupElementBuilder.create("Message"));
}
});
}
Structure of entire document observed via PsiPlugin:
As I understand, Gherkin plugin changes interpretation of file, and currently I can do nothing about it. What I am missing?
Thanks!

Dynamically include precompiled (Razor) views in .NET Core 2.1

Idea
I'm trying to build a modular .NET Core MVC application, were I can add 'modules' (extensions) just by copying the required libraries to a predefined folder. The application defines a set of dependencies (DI), error handling and basic layout; the modules provide the actual application or page logic.
We've build a proof of concept, using ExtCore - the concept works great, Controllers are added automatically and the 'plain' Views are recognized easily (the ones set as 'Embedded Resource').
Challenge
However, I don't like the fact that Views are set to 'Embedded Resource', as it will be a small performance hit as the Razor page is now build at runtime.
What we've tried
As .NET Core 2.1 now has the ability to create Reusable Razor UI, I've created a project with a reference to <Project Sdk="Microsoft.NET.Sdk.Razor"> and compiled it to a Razor library (*.Views.dll).
When I link the Razor View library as project dependency in (main) application, everything works fine. However, the goal still is to make the application fully plug-and-play and allow libraries to be included just by deploying them to a folder.
I've tried to achieve this extending the Razor View Engine using a PhysicalFileProvider, but it won't recognize the views in the library.
services.Configure<RazorViewEngineOptions>(opt =>
{
opt.FileProviders.Add(new PhysicalFileProvider("path/to/extension"));
});
The result always is an exception telling me that /Views/[controller]/[action].cshtml is not found.
Searching other answers I came across this project, which creates a ViewLocationExpander. I tried implementing various versions of this idea without luck - most likely because this is an older concept based on .NET Core 1.x which still uses a project dependency; although the Razor View engine now searches the namespace of the assembly.
services.Configure<RazorViewEngineOptions>(opt =>
{
opt.FileProviders.Add(new PhysicalFileProvider("path/to/extension");
opt.ViewLocationExpanders.Add(new DynamicLocationExpander());
});
Where DynamicLocationExpander looks like:
public class DynamicLocationExpander: IViewLocationExpander
{
public DynamicLocationExpander()
{
}
public void PopulateValues(ViewLocationExpanderContext context)
{
}
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
string assembly = ((ControllerActionDescriptor)context.ActionContext.ActionDescriptor)
.ControllerTypeInfo.AsType().Assembly.GetName().Name;
foreach (var viewLocation in viewLocations)
yield return $"{assembly}/{viewLocation}";
}
}
Question
How can we dynamically link a Razor View library, containing precompiled views, to the Razor Engine in a (parent) application?

How do I get the correct value for sketchPath in IntelliJ IDEA?

I want to setup IntelliJ IDEA to compile Processing sketches. So far I've been following the instructions found here:
http://www.slideshare.net/eskimoblood/processing-in-intellij
These instructions work fine for code completion and basic "drawing". But I run into problems once I want to access files – i.e. an image - inside the data folder which is created on slide 19. First the code of my Processing class:
import processing.core.PApplet;
import processing.core.PImage;
public class IntellijTest extends PApplet
{
private PImage image;
#Override
public void setup() {
size(400, 400);
println(sketchPath);
// load image
image = loadImage("test.png");
}
#Override
public void draw() {
background(0);
noStroke();
fill(200);
rect(100, 100, 200, 200);
// draw image
image(image, 110, 100);
}
}
This leads to the following error:
/Applications/IntelliJ IDEA 12.app/bin
The file "test.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:3572)
at processing.core.PApplet.image(PApplet.java:12604)
at IntellijTest.draw(IntellijTest.java:28)
at processing.core.PApplet.handleDraw(PApplet.java:2306)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2177)
at java.lang.Thread.run(Thread.java:744)
As you can see the sketchPath is set to "/Applications/IntelliJ IDEA 12.app/bin". So the running sketch (Applet) does not find the image. IntelliJ does even warn me about it, but I still haven't figured out how to add the image to the sketch or better how to set the correct sketchPath value so that the sketch finds all files inside the data folder at runtime.
I'ld really appreciate any hints or insights on how to accomplish this.
I just had the same problem. I solved it by marking the data directory as Source Root
You can include files into your target directory without having to include it in your source folder. To accomplish you need to "mark it" the auxiliary folder as a source folder.
I keep my source files in /src/main/java and my resources in /src/main/resources where resources contains all my configuration properties and other things that don't belong in the source code. You can right click on the folder in the project explorer and "Mark it" as source. It should appear at the root of your target/project/.
Also keep in mind if you're running a Java Application (not Applet), Java will uses the system environment classpath to resolve relative paths. So as you start calling files in your program, Java will look in the folders listed in the classpath to resolve file locations as well as look in the root of your target project.

How to Debug NinjectWebCommon.cs?

We are trying to debug through ninjectwebcommon.cs to find the binding for a respository.
In VS 2012, I am putting a Debugpoint on the kernel.bind but it doesnot hit anytime. Can someone sugggest me how to debug this?
I have NInject Version v4.0.30319
The not-so-simple and (obviously) temporary solution for me was to create a background thread in NinjectWebCommon.RegisterServices with the configuration I was debugging:
var thread = new System.Threading.Thread(() =>
{
while (!System.Diagnostics.Debugger.IsAttached)
{
System.Threading.Thread.Sleep(100);
}
// custom code, including kernel.Bind<>() calls here
});
thread.IsBackground = true;
thread.Start();
The idea here is to keep the thread you've created from executing the debuggable code until the debugger is actually attached. Setting the IsBackground property is important, because this allows the rest of the RegisterServices method to complete, which in turn allows the application to start and allows the debugger to attach.
Ninject is open source. You can download the entire project from their Github page at https://github.com/ninject. From there you can point Visual Studio to those projects instead of using the compiled assemblies.
Another option would be to use http://symbolsource.org as a Symbol Server. But it looks like they only have Ninject 3.

MEF + SL4 question

I'm working on an app in the Silverlight 4 RC and i'm taking the oppertunity to learn MEF for handling plugin controls. I've got it working in a pretty basic manor, but it's not exactly tidy and I know there is a better way of importing multiple xap's.
Essentially, in the App.xaml of my host app, I've got the following telling MEF to load my xap's:
AggregateCatalog catalog = new AggregateCatalog();
DeploymentCatalog c1 = new DeploymentCatalog(new Uri("TestPlugInA.xap", UriKind.Relative));
DeploymentCatalog c2 = new DeploymentCatalog(new Uri("TestPlugInB.xap", UriKind.Relative));
catalog.Catalogs.Add(c1);
catalog.Catalogs.Add(c2);
CompositionHost.Initialize(catalog);
c1.DownloadAsync();
c2.DownloadAsync();
I'm sure I'm not using the AggregateCatalog fully here and I need to be able to load any xap's that might be in the directory, not just hardcoding Uri's obviously....
Also, in the MainPage.xaml.cs in the host I have the following collection which MEF puts the plugin's into:
[ImportMany(AllowRecomposition = true)]
public ObservableCollection<IPlugInApp> PlugIns { get; set; }
Again, this works, but I'm pretty sure I'm using ImportMany incorrectly....
Finally, the MainPage.xaml.cs file implements IPartImportsSatisfiedNotification and I have the following for handling the plugin's once loaded:
public void OnImportsSatisfied()
{
sp.Children.Clear();
foreach (IPlugInApp plugIn in PlugIns)
{
if (plugIn != null)
sp.Children.Add(plugIn.GetUserControl());
}
}
This works, but it seems filthy that it runs n times (n being the number of xap's to load). I'm having to call sp.Children.Clear() as if I don't, when loading the 2 plugin's, my stack panel is populated as follows:
TestPlugIn A
TestPlugIn A
TestPlugIn B
I'm clearly missing something here. Can anyone point out what I should be doing?
Thanks!
I think most of what you are doing is fine. Although ObservableCollections do support notifications of individual elements being added and removed, MEF doesn't take advantage of this. In your case it will simply clear the collection and then add all the plugins. Since you are using OnImportsSatisfied for the change notification, you don't even need an ObservableCollection. You could just use an IEnumerable for your import.
To add flexibility in downloading different xaps, I would expose a service in your container that can be imported and that provides the functionality to download a xap given a url. Then any component in your container can trigger a download, and the url to download can come from whatever source you deem appropriate.