-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #99 Preference page for dotnet path and future developments
Will stop users from using features requiring dotnet if the path is not found and point them towards the preference page Signed-off-by: Lucas Bullen <lbullen@redhat.com>
- Loading branch information
1 parent
2c8a663
commit ff46e87
Showing
11 changed files
with
261 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
org.eclipse.acute/src/org/eclipse/acute/AcutePreferenceInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Lucas Bullen (Red Hat Inc.) - Initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.acute; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import org.eclipse.core.runtime.Platform; | ||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; | ||
import org.eclipse.jface.preference.IPreferenceStore; | ||
|
||
public class AcutePreferenceInitializer extends AbstractPreferenceInitializer { | ||
|
||
public static String explicitDotnetPathPreference = "dotnet.explicitPath"; | ||
|
||
@Override | ||
public void initializeDefaultPreferences() { | ||
IPreferenceStore store = AcutePlugin.getDefault().getPreferenceStore(); | ||
|
||
store.setDefault(explicitDotnetPathPreference, getBestDotnetPathGuess()); | ||
} | ||
|
||
private String getBestDotnetPathGuess() { | ||
try { | ||
String[] command = new String[] { "/bin/bash", "-c", "which dotnet" }; | ||
if (Platform.getOS().equals(Platform.OS_WIN32)) { | ||
command = new String[] { "cmd", "/c", "which dotnet" }; | ||
} | ||
ProcessBuilder builder = new ProcessBuilder(command); | ||
Process process = builder.start(); | ||
|
||
if (process.waitFor() == 0) { | ||
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) { | ||
return in.readLine(); | ||
} | ||
} | ||
} catch (IOException | InterruptedException e) { | ||
// Error will be caught with empty response | ||
} | ||
return ""; | ||
} | ||
|
||
} |
118 changes: 118 additions & 0 deletions
118
org.eclipse.acute/src/org/eclipse/acute/AcutePreferencePage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Lucas Bullen (Red Hat Inc.) - Initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.acute; | ||
|
||
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; | ||
|
||
import java.io.File; | ||
|
||
import org.eclipse.jface.preference.IPreferenceStore; | ||
import org.eclipse.jface.preference.PreferencePage; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Button; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Control; | ||
import org.eclipse.swt.widgets.FileDialog; | ||
import org.eclipse.swt.widgets.Label; | ||
import org.eclipse.swt.widgets.Text; | ||
import org.eclipse.ui.IWorkbench; | ||
import org.eclipse.ui.IWorkbenchPreferencePage; | ||
|
||
public class AcutePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { | ||
public static String PAGE_ID = "org.eclipse.acute.preferencePage"; | ||
private IPreferenceStore store; | ||
|
||
private Text explicitDotnetPathText; | ||
|
||
@Override | ||
public void init(IWorkbench workbench) { | ||
store = doGetPreferenceStore(); | ||
} | ||
|
||
@Override | ||
protected Control createContents(Composite parent) { | ||
Composite container = new Composite(parent, SWT.NULL); | ||
container.setLayout(new GridLayout(2, false)); | ||
|
||
createDotnetPathPart(container); | ||
|
||
initializeContent(); | ||
return container; | ||
} | ||
|
||
private void initializeContent() { | ||
explicitDotnetPathText.setText(store.getString(AcutePreferenceInitializer.explicitDotnetPathPreference)); | ||
} | ||
|
||
@Override | ||
protected IPreferenceStore doGetPreferenceStore() { | ||
return AcutePlugin.getDefault().getPreferenceStore(); | ||
} | ||
|
||
private boolean isPageValid() { | ||
if (explicitDotnetPathText.getText().isEmpty()) { | ||
setErrorMessage("Path cannot be empty"); | ||
return false; | ||
} | ||
File dotnetCommand = new File(explicitDotnetPathText.getText()); | ||
if (!dotnetCommand.exists() || !dotnetCommand.isFile()) { | ||
setErrorMessage("Input a valid path to `dotnet` command"); | ||
return false; | ||
} else if (!dotnetCommand.canExecute()) { | ||
setErrorMessage("Inputted command is not executable"); | ||
return false; | ||
} | ||
setErrorMessage(null); | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void performDefaults() { | ||
explicitDotnetPathText.setText(store.getDefaultString(AcutePreferenceInitializer.explicitDotnetPathPreference)); | ||
super.performDefaults(); | ||
} | ||
|
||
@Override | ||
public boolean performOk() { | ||
store.setValue(AcutePreferenceInitializer.explicitDotnetPathPreference, explicitDotnetPathText.getText()); | ||
return super.performOk(); | ||
} | ||
|
||
private void createDotnetPathPart(Composite container) { | ||
Label infoLabel = new Label(container, SWT.WRAP); | ||
infoLabel.setText( | ||
"Direct path to the `dotnet` command for .NET Core features:"); | ||
infoLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); | ||
|
||
GridData textIndent = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); | ||
textIndent.horizontalIndent = 25; | ||
|
||
explicitDotnetPathText = new Text(container, SWT.BORDER); | ||
explicitDotnetPathText.setLayoutData(textIndent); | ||
explicitDotnetPathText.addModifyListener(e -> { | ||
setValid(isPageValid()); | ||
}); | ||
|
||
Button browseButton = new Button(container, SWT.NONE); | ||
browseButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); | ||
browseButton.setText("Browse..."); | ||
browseButton.addSelectionListener(widgetSelectedAdapter(e -> { | ||
FileDialog dialog = new FileDialog(browseButton.getShell()); | ||
String path = dialog.open(); | ||
if (path != null) { | ||
explicitDotnetPathText.setText(path); | ||
} | ||
})); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.