diff --git a/plugin_ide.core.tests/src/com/googlecode/goclipse/core/GoProjectEnvironmentTest.java b/plugin_ide.core.tests/src/com/googlecode/goclipse/core/GoProjectEnvironmentTest.java index 58ffe6e09..401b9b2c9 100644 --- a/plugin_ide.core.tests/src/com/googlecode/goclipse/core/GoProjectEnvironmentTest.java +++ b/plugin_ide.core.tests/src/com/googlecode/goclipse/core/GoProjectEnvironmentTest.java @@ -39,10 +39,10 @@ public class GoProjectEnvironmentTest extends CommonGoCoreTest { public void test() throws Exception { test$(); } public void test$() throws Exception { - GoEnvironmentPrefs.GO_ROOT.setInstanceScopeValue(SAMPLE_GO_ROOT.asString()); - GoEnvironmentPrefs.GO_ARCH.setInstanceScopeValue("386"); - GoEnvironmentPrefs.GO_OS.setInstanceScopeValue("windows"); - GoEnvironmentPrefs.GO_PATH.setInstanceScopeValue(SAMPLE_GOPATH_Entry.toString()); + GoEnvironmentPrefs.GO_ROOT.getGlobalPreference().setInstanceScopeValue(SAMPLE_GO_ROOT.asString()); + GoEnvironmentPrefs.GO_ARCH.getGlobalPreference().setInstanceScopeValue("386"); + GoEnvironmentPrefs.GO_OS.getGlobalPreference().setInstanceScopeValue("windows"); + GoEnvironmentPrefs.GO_PATH.getGlobalPreference().setInstanceScopeValue(SAMPLE_GOPATH_Entry.toString()); TestsWorkingDir.deleteDir(SAMPLE_GOPATH_Entry); { @@ -64,7 +64,7 @@ public class GoProjectEnvironmentTest extends CommonGoCoreTest { String goPathEntryOther = location.append("other").toOSString(); String gopath = location.toOSString() + File.pathSeparator + goPathEntryOther; - GoEnvironmentPrefs.GO_PATH.setInstanceScopeValue(gopath); + GoEnvironmentPrefs.GO_PATH.getGlobalPreference().setInstanceScopeValue(gopath); // Test GOPATH which already has project location. Also nested GOPATH entry. checkEnvGoPath(project, list(location.toOSString(), goPathEntryOther), false); @@ -73,7 +73,7 @@ public class GoProjectEnvironmentTest extends CommonGoCoreTest { try (SampleGoProject sampleProject = new SampleGoProject(getClass().getSimpleName())){ IProject project = sampleProject.getProject(); - GoEnvironmentPrefs.GO_PATH.setInstanceScopeValue(SAMPLE_GO_PATH.asString()); + GoEnvironmentPrefs.GO_PATH.getGlobalPreference().setInstanceScopeValue(SAMPLE_GO_PATH.asString()); sampleProject.moveToLocation(SAMPLE_GOPATH_Entry.resolve_valid("src/github.com/foo")); // Test that project location is not added, because project is in a Go source package diff --git a/plugin_ide.core/src/com/googlecode/goclipse/core/GoEnvironmentPrefs.java b/plugin_ide.core/src/com/googlecode/goclipse/core/GoEnvironmentPrefs.java index e381a7fa3..774ed2ece 100644 --- a/plugin_ide.core/src/com/googlecode/goclipse/core/GoEnvironmentPrefs.java +++ b/plugin_ide.core/src/com/googlecode/goclipse/core/GoEnvironmentPrefs.java @@ -10,25 +10,32 @@ *******************************************************************************/ package com.googlecode.goclipse.core; +import static melnorme.lang.ide.core.operations.ToolchainPreferences.USE_PROJECT_SETTINGS; + import melnorme.lang.ide.core.LangCore; import melnorme.lang.ide.core.operations.ToolchainPreferences; +import melnorme.lang.ide.core.utils.prefs.IProjectPreference; import melnorme.lang.ide.core.utils.prefs.OptionalStringPreference; import melnorme.lang.ide.core.utils.prefs.StringPreference; public interface GoEnvironmentPrefs { - static StringPreference GO_ROOT = new StringPreference(LangCore.PLUGIN_ID, - "com.googlecode.goclipse.goroot", "", ToolchainPreferences.USE_PROJECT_SETTINGS); - static OptionalStringPreference GO_PATH = new OptionalStringPreference(LangCore.PLUGIN_ID, - "com.googlecode.goclipse.gopath", ToolchainPreferences.USE_PROJECT_SETTINGS); - static StringPreference GO_OS = new StringPreference(LangCore.PLUGIN_ID, - "com.googlecode.goclipse.goos", "", ToolchainPreferences.USE_PROJECT_SETTINGS); - static StringPreference GO_ARCH = new StringPreference(LangCore.PLUGIN_ID, - "com.googlecode.goclipse.goarch", "", ToolchainPreferences.USE_PROJECT_SETTINGS); + IProjectPreference GO_ROOT = new StringPreference(LangCore.PLUGIN_ID, + "com.googlecode.goclipse.goroot", "", USE_PROJECT_SETTINGS).getProjectPreference(); + IProjectPreference GO_OS = new StringPreference(LangCore.PLUGIN_ID, + "com.googlecode.goclipse.goos", "", USE_PROJECT_SETTINGS).getProjectPreference(); + IProjectPreference GO_ARCH = new StringPreference(LangCore.PLUGIN_ID, + "com.googlecode.goclipse.goarch", "", USE_PROJECT_SETTINGS).getProjectPreference(); + IProjectPreference FORMATTER_PATH = new StringPreference(LangCore.PLUGIN_ID, + "com.googlecode.goclipse.formatter.path", "", USE_PROJECT_SETTINGS).getProjectPreference(); + IProjectPreference DOCUMENTOR_PATH = new StringPreference(LangCore.PLUGIN_ID, + "com.googlecode.goclipse.documentor.path", "", USE_PROJECT_SETTINGS).getProjectPreference(); + + + IProjectPreference GO_PATH = new OptionalStringPreference(LangCore.PLUGIN_ID, + "com.googlecode.goclipse.gopath", ToolchainPreferences.USE_PROJECT_SETTINGS).getProjectPreference(); - static StringPreference FORMATTER_PATH = new StringPreference(LangCore.PLUGIN_ID, - "com.googlecode.goclipse.formatter.path", "", ToolchainPreferences.USE_PROJECT_SETTINGS); - static StringPreference DOCUMENTOR_PATH = new StringPreference(LangCore.PLUGIN_ID, - "com.googlecode.goclipse.documentor.path", "", ToolchainPreferences.USE_PROJECT_SETTINGS); +// IProjectPreference APPEND_PROJECT_LOC_TO_GOPATH = new BooleanPreference(LangCore.PLUGIN_ID, +// "append_projloc_gopath", true, ToolchainPreferences.USE_PROJECT_SETTINGS).getProjectPreference(); } \ No newline at end of file diff --git a/plugin_ide.core/src/com/googlecode/goclipse/core/GoProjectEnvironment.java b/plugin_ide.core/src/com/googlecode/goclipse/core/GoProjectEnvironment.java index 86be15d29..d336199e3 100644 --- a/plugin_ide.core/src/com/googlecode/goclipse/core/GoProjectEnvironment.java +++ b/plugin_ide.core/src/com/googlecode/goclipse/core/GoProjectEnvironment.java @@ -27,7 +27,7 @@ import com.googlecode.goclipse.tooling.env.GoWorkspaceLocation; import melnorme.lang.ide.core.utils.ResourceUtils; -import melnorme.lang.ide.core.utils.prefs.StringPreference; +import melnorme.lang.ide.core.utils.prefs.IProjectPreference; import melnorme.utilbox.collections.ArrayList2; import melnorme.utilbox.core.CommonException; import melnorme.utilbox.misc.Location; @@ -35,17 +35,17 @@ public class GoProjectEnvironment implements GoEnvironmentConstants { public static GoRoot getEffectiveGoRoot(IProject project) { - String prefValue = GoEnvironmentPrefs.GO_ROOT.getProjectPreference().getEffectiveValue(project); + String prefValue = GoEnvironmentPrefs.GO_ROOT.getEffectiveValue(project); return new GoRoot(nullAsEmpty(prefValue)); } public static GoArch getEffectiveGoArch(IProject project) { - String strValue = emptyAsNull(GoEnvironmentPrefs.GO_ARCH.getProjectPreference().getEffectiveValue(project)); + String strValue = emptyAsNull(GoEnvironmentPrefs.GO_ARCH.getEffectiveValue(project)); return strValue == null ? null : new GoArch(strValue); } public static GoOs getEffectiveGoOs(IProject project) { - String strValue = emptyAsNull(GoEnvironmentPrefs.GO_OS.getProjectPreference().getEffectiveValue(project)); + String strValue = emptyAsNull(GoEnvironmentPrefs.GO_OS.getEffectiveValue(project)); return strValue == null ? null : new GoOs(strValue); } @@ -82,8 +82,9 @@ public static boolean isProjectInsideGoPathSourceFolder(IProject project, GoPath return goPath.findGoPathEntryForSourcePath(ResourceUtils.getProjectLocation2(project)) != null; } - protected static String getEffectiveValueFromEnv(StringPreference pref, IProject project, String envAlternative) { - String prefValue = pref.getProjectPreference().getEffectiveValue(project); + protected static String getEffectiveValueFromEnv(IProjectPreference pref, IProject project, + String envAlternative) { + String prefValue = pref.getEffectiveValue(project); if(prefValue == null) { return nullAsEmpty(System.getenv(envAlternative)); } diff --git a/plugin_ide.core/src/com/googlecode/goclipse/core/operations/GoToolManager.java b/plugin_ide.core/src/com/googlecode/goclipse/core/operations/GoToolManager.java index acd0dc0f7..02724c1fd 100644 --- a/plugin_ide.core/src/com/googlecode/goclipse/core/operations/GoToolManager.java +++ b/plugin_ide.core/src/com/googlecode/goclipse/core/operations/GoToolManager.java @@ -49,7 +49,7 @@ protected IValidatedField getSDKToolPathField(IProject project) { return new ValidatedSDKToolPath(project, getSDKToolPathValidator()) { @Override protected String getRawFieldValue2() { - return GoEnvironmentPrefs.GO_ROOT.getProjectPreference().getEffectiveValue(project); + return GoEnvironmentPrefs.GO_ROOT.getEffectiveValue(project); } }; } diff --git a/plugin_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/AbstractEditorGoToolOperation.java b/plugin_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/AbstractEditorGoToolOperation.java index 0ff57f785..9427963e1 100644 --- a/plugin_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/AbstractEditorGoToolOperation.java +++ b/plugin_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/AbstractEditorGoToolOperation.java @@ -1,103 +1,106 @@ -/******************************************************************************* - * Copyright (c) 2014 Bruno Medeiros and other Contributors. - * 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: - * Bruno Medeiros - initial API and implementation - *******************************************************************************/ -package com.googlecode.goclipse.ui.editor.actions; - - -import static melnorme.lang.ide.ui.editor.EditorUtils.getEditorDocument; -import static melnorme.utilbox.core.CoreUtil.areEqual; - -import java.nio.file.Path; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.texteditor.ITextEditor; - -import com.googlecode.goclipse.core.GoProjectEnvironment; -import com.googlecode.goclipse.core.operations.GoToolManager; -import com.googlecode.goclipse.tooling.env.GoEnvironment; -import com.googlecode.goclipse.ui.editor.GoEditor; - -import melnorme.lang.ide.core.LangCore; -import melnorme.lang.ide.ui.editor.EditorUtils; -import melnorme.lang.ide.ui.utils.operations.AbstractEditorOperation2; -import melnorme.utilbox.concurrency.OperationCancellation; -import melnorme.utilbox.core.CommonException; -import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult; - -public abstract class AbstractEditorGoToolOperation extends AbstractEditorOperation2 { - - protected GoEditor goEditor; - protected String editorText; - protected ProcessBuilder pb; - - public AbstractEditorGoToolOperation(String operationName, ITextEditor editor) { - super(operationName, editor); - } - - @Override - protected void prepareOperation() throws CoreException { - if(!(editor instanceof GoEditor)) { - throw LangCore.createCoreException("Editor is not a GoEditor.", null); - } - goEditor = (GoEditor) editor; - editorText = getEditorDocument(editor).get(); - - IProject project = EditorUtils.getAssociatedProject(editorInput); - - GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(project); - - try { - Path goSDKPath = GoToolManager.getDefault().getSDKToolPath(project); - pb = prepareProcessBuilder(goSDKPath, goEnv); - } catch (CommonException ce) { - throw LangCore.createCoreException(ce); - } - } - - protected abstract ProcessBuilder prepareProcessBuilder(Path goSDKPath, GoEnvironment goEnv) - throws CoreException, CommonException; - - @Override - protected String doBackgroundValueComputation(IProgressMonitor monitor) - throws CoreException, CommonException, OperationCancellation { - ExternalProcessResult processResult = - GoToolManager.getDefault().newRunToolOperation2(pb, monitor).runProcess(editorText, true); - - return processResult.getStdOutBytes().toString(); - } - - @Override - protected void handleComputationResult() throws CoreException { - if(!areEqual(result, editorText)) { - replaceText(goEditor.getSourceViewer_(), result); - } - } - - - public static void replaceText(ISourceViewer sourceViewer, String newText) { - ISelection sel = sourceViewer.getSelectionProvider().getSelection(); - int topIndex = sourceViewer.getTopIndex(); - - sourceViewer.getDocument().set(newText); - - if (sel != null) { - sourceViewer.getSelectionProvider().setSelection(sel); - } - - if (topIndex != -1) { - sourceViewer.setTopIndex(topIndex); - } - } - +/******************************************************************************* + * Copyright (c) 2014 Bruno Medeiros and other Contributors. + * 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: + * Bruno Medeiros - initial API and implementation + *******************************************************************************/ +package com.googlecode.goclipse.ui.editor.actions; + + +import static melnorme.lang.ide.ui.editor.EditorUtils.getEditorDocument; +import static melnorme.utilbox.core.CoreUtil.areEqual; + +import java.nio.file.Path; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.texteditor.ITextEditor; + +import com.googlecode.goclipse.core.GoProjectEnvironment; +import com.googlecode.goclipse.core.operations.GoToolManager; +import com.googlecode.goclipse.tooling.env.GoEnvironment; +import com.googlecode.goclipse.ui.editor.GoEditor; + +import melnorme.lang.ide.core.LangCore; +import melnorme.lang.ide.ui.editor.EditorUtils; +import melnorme.lang.ide.ui.utils.operations.AbstractEditorOperation2; +import melnorme.utilbox.concurrency.OperationCancellation; +import melnorme.utilbox.core.CommonException; +import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult; + +public abstract class AbstractEditorGoToolOperation extends AbstractEditorOperation2 { + + protected GoEditor goEditor; + protected IProject project; // Can be null + + protected ProcessBuilder pb; + + protected String editorText; + + public AbstractEditorGoToolOperation(String operationName, ITextEditor editor) { + super(operationName, editor); + } + + @Override + protected void prepareOperation() throws CoreException { + if(!(editor instanceof GoEditor)) { + throw LangCore.createCoreException("Editor is not a GoEditor.", null); + } + goEditor = (GoEditor) editor; + editorText = getEditorDocument(editor).get(); + + project = EditorUtils.getAssociatedProject(editorInput); + + GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(project); + + try { + Path goSDKPath = GoToolManager.getDefault().getSDKToolPath(project); + pb = prepareProcessBuilder(goSDKPath, goEnv); + } catch (CommonException ce) { + throw LangCore.createCoreException(ce); + } + } + + protected abstract ProcessBuilder prepareProcessBuilder(Path goSDKPath, GoEnvironment goEnv) + throws CoreException, CommonException; + + @Override + protected String doBackgroundValueComputation(IProgressMonitor monitor) + throws CoreException, CommonException, OperationCancellation { + ExternalProcessResult processResult = + GoToolManager.getDefault().newRunToolOperation2(pb, monitor).runProcess(editorText, true); + + return processResult.getStdOutBytes().toString(); + } + + @Override + protected void handleComputationResult() throws CoreException { + if(!areEqual(result, editorText)) { + replaceText(goEditor.getSourceViewer_(), result); + } + } + + + public static void replaceText(ISourceViewer sourceViewer, String newText) { + ISelection sel = sourceViewer.getSelectionProvider().getSelection(); + int topIndex = sourceViewer.getTopIndex(); + + sourceViewer.getDocument().set(newText); + + if (sel != null) { + sourceViewer.getSelectionProvider().setSelection(sel); + } + + if (topIndex != -1) { + sourceViewer.setTopIndex(topIndex); + } + } + } \ No newline at end of file diff --git a/plugin_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/RunGoFmtOperation.java b/plugin_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/RunGoFmtOperation.java index 8f40750ac..cb5b75a40 100644 --- a/plugin_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/RunGoFmtOperation.java +++ b/plugin_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/RunGoFmtOperation.java @@ -1,53 +1,53 @@ -/******************************************************************************* - * Copyright (c) 2014 Bruno Medeiros and other Contributors. - * 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: - * Bruno Medeiros - initial API and implementation - *******************************************************************************/ -package com.googlecode.goclipse.ui.editor.actions; - -import static melnorme.utilbox.core.CoreUtil.listFrom; - -import java.nio.file.Path; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.texteditor.ITextEditor; - -import com.googlecode.goclipse.core.GoEnvironmentPrefs; -import com.googlecode.goclipse.tooling.env.GoEnvironment; - -import melnorme.lang.ide.ui.editor.actions.AbstractEditorHandler; -import melnorme.lang.ide.ui.utils.operations.BasicUIOperation; -import melnorme.utilbox.core.CommonException; - -public class RunGoFmtOperation extends AbstractEditorGoToolOperation { - - protected static final String RUN_GOFMT_OpName = "Run 'gofmt'"; - - public static AbstractEditorHandler getHandler(IWorkbenchPage page) { - return new AbstractEditorHandler(page) { - @Override - protected BasicUIOperation createOperation(ITextEditor editor) { - return new RunGoFmtOperation(editor); - } - }; - } - - public RunGoFmtOperation(ITextEditor editor) { - super(RUN_GOFMT_OpName, editor); - } - - @Override - protected ProcessBuilder prepareProcessBuilder(Path goSDKPath, GoEnvironment goEnv) - throws CoreException, CommonException { - List cmd = listFrom(GoEnvironmentPrefs.FORMATTER_PATH.get()); - return goEnv.createProcessBuilder(cmd, null, true); - } - +/******************************************************************************* + * Copyright (c) 2014 Bruno Medeiros and other Contributors. + * 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: + * Bruno Medeiros - initial API and implementation + *******************************************************************************/ +package com.googlecode.goclipse.ui.editor.actions; + +import static melnorme.utilbox.core.CoreUtil.listFrom; + +import java.nio.file.Path; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.texteditor.ITextEditor; + +import com.googlecode.goclipse.core.GoEnvironmentPrefs; +import com.googlecode.goclipse.tooling.env.GoEnvironment; + +import melnorme.lang.ide.ui.editor.actions.AbstractEditorHandler; +import melnorme.lang.ide.ui.utils.operations.BasicUIOperation; +import melnorme.utilbox.core.CommonException; + +public class RunGoFmtOperation extends AbstractEditorGoToolOperation { + + protected static final String RUN_GOFMT_OpName = "Run 'gofmt'"; + + public static AbstractEditorHandler getHandler(IWorkbenchPage page) { + return new AbstractEditorHandler(page) { + @Override + protected BasicUIOperation createOperation(ITextEditor editor) { + return new RunGoFmtOperation(editor); + } + }; + } + + public RunGoFmtOperation(ITextEditor editor) { + super(RUN_GOFMT_OpName, editor); + } + + @Override + protected ProcessBuilder prepareProcessBuilder(Path goSDKPath, GoEnvironment goEnv) + throws CoreException, CommonException { + List cmd = listFrom(GoEnvironmentPrefs.FORMATTER_PATH.getEffectiveValue(project)); + return goEnv.createProcessBuilder(cmd, null, true); + } + } \ No newline at end of file diff --git a/plugin_ide.ui/src/com/googlecode/goclipse/ui/wizards/GoProjectWizard.java b/plugin_ide.ui/src/com/googlecode/goclipse/ui/wizards/GoProjectWizard.java index dcf2839bd..c6e84f3f0 100644 --- a/plugin_ide.ui/src/com/googlecode/goclipse/ui/wizards/GoProjectWizard.java +++ b/plugin_ide.ui/src/com/googlecode/goclipse/ui/wizards/GoProjectWizard.java @@ -73,7 +73,7 @@ public GoProjectWizardFirstPage() { @Override protected void validatePreferences() throws ValidationException { - new GoSDKLocationValidator().getValidatedField(GoEnvironmentPrefs.GO_ROOT.get()); + new GoSDKLocationValidator().getValidatedField(GoEnvironmentPrefs.GO_ROOT.getGlobalPreference().get()); } } \ No newline at end of file