Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
Massive refactoring of Path usage to Location.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Mar 18, 2015
1 parent af95c78 commit 86c7838
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 131 deletions.
Expand Up @@ -14,9 +14,9 @@
import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

import java.io.File;
import java.nio.file.Path;
import java.util.Collection;

import melnorme.utilbox.misc.Location;
import melnorme.utilbox.tests.TestsWorkingDir;

import org.eclipse.core.resources.IProject;
Expand All @@ -31,7 +31,7 @@

public class GoProjectEnvironmentTest extends CommonGoCoreTest {

public static final Path WORKING_DIR = CommonGoToolingTest.TESTS_WORKDIR;
public static final Location WORKING_DIR = CommonGoToolingTest.TESTS_WORKDIR;
public static final GoRoot SAMPLE_GO_ROOT = CommonGoToolingTest.SAMPLE_GO_ROOT;
public static final GoPath SAMPLE_GO_PATH = CommonGoToolingTest.SAMPLE_GO_PATH;

Expand Down Expand Up @@ -75,18 +75,18 @@ public class GoProjectEnvironmentTest extends CommonGoCoreTest {

GoEnvironmentPrefs.GO_PATH.set(SAMPLE_GO_PATH.asString());

sampleProject.moveToLocation(SAMPLE_GOPATH_Entry.resolve("src/github.com/foo"));
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
checkEnvGoPath(project, list(SAMPLE_GOPATH_Entry.toString()), true);

// Test 1 dir under 'src'
sampleProject.moveToLocation(SAMPLE_GOPATH_Entry.resolve("src/foo"));
sampleProject.moveToLocation(SAMPLE_GOPATH_Entry.resolve_valid("src/foo"));
checkEnvGoPath(project, list(SAMPLE_GOPATH_Entry.toString()), true);

// Test under 'src'
sampleProject.moveToLocation(SAMPLE_GOPATH_Entry.resolve("../temp"));
sampleProject.moveToLocation(SAMPLE_GOPATH_Entry.resolve_valid("../temp"));
TestsWorkingDir.deleteDir(SAMPLE_GOPATH_Entry);
sampleProject.moveToLocation(SAMPLE_GOPATH_Entry.resolve("src"));
sampleProject.moveToLocation(SAMPLE_GOPATH_Entry.resolve_valid("src"));
checkEnvGoPath(project, list(SAMPLE_GOPATH_Entry.toString()), true);
}

Expand Down
Expand Up @@ -16,6 +16,7 @@
import melnorme.lang.ide.core.utils.prefs.StringPreference;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -52,20 +53,19 @@ public static GoPath getEffectiveGoPath(IProject project) {
return rawGoPath;
}

IPath location = project.getLocation();
if(location == null) {
Location projectLoc = ResourceUtils.getResourceLocation(project);
if(projectLoc == null) {
return rawGoPath;
}
java.nio.file.Path projectPath = location.toFile().toPath();

java.nio.file.Path goPathEntry = rawGoPath.findGoPathEntryForSourcePath(projectPath);
Location goPathEntry = rawGoPath.findGoPathEntryForSourcePath(projectLoc);
if(goPathEntry != null) {
// GOPATH already contains project location
return rawGoPath;
}

// Implicitly add project location to GOPATH
ArrayList2<String> newGoPathEntries = new ArrayList2<>(projectPath.toString());
ArrayList2<String> newGoPathEntries = new ArrayList2<>(projectLoc.toPathString());
newGoPathEntries.addElements(rawGoPath.getGoPathEntries());

return new GoPath(newGoPathEntries);
Expand Down Expand Up @@ -132,8 +132,8 @@ public static IPath getPkgFolder(IProject project) {
return project.getLocation().append("pkg");
}

public static IPath getBinFolder(java.nio.file.Path goWorkspaceEntry) {
return Path.fromOSString(goWorkspaceEntry.resolve("bin").toString());
public static IPath getBinFolder(Location goWorkspaceEntry) {
return Path.fromOSString(goWorkspaceEntry.resolve_valid("bin").toString());
}

public static IContainer getSourceFolderRoot(IProject project) throws CoreException {
Expand Down
Expand Up @@ -11,10 +11,13 @@
package com.googlecode.goclipse.core.launch;


import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.ide.launching.AbstractLangLaunchConfigurationDelegate;
import melnorme.lang.utils.ProcessUtils;
import melnorme.utilbox.misc.Location;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunch;
Expand All @@ -36,17 +39,17 @@ protected IPath getProgramFullPath(ILaunchConfiguration configuration) throws Co
}

IProject project = getProject(configuration);
IPath launchResource = project.findMember(path).getLocation();
IResource launchResource = project.findMember(path);

GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(project);

java.nio.file.Path goPackageAbsolutePath = launchResource.toFile().toPath();
java.nio.file.Path goPathEntry = goEnv.getGoPath().findGoPathEntryForSourcePath(goPackageAbsolutePath);
Location goPackageLocation = ResourceUtils.getResourceLocation(launchResource);
Location goPathEntry = goEnv.getGoPath().findGoPathEntryForSourcePath(goPackageLocation);

if (goPathEntry == null) {
throw GoCore.createCoreException("Given Go package not found: " + path, null);
} else {
String cmdName = goPackageAbsolutePath.getFileName().toString(); // get last segment
String cmdName = goPackageLocation.path.getFileName().toString(); // get last segment
String executableName = cmdName + ProcessUtils.getExecutableSuffix();

return GoProjectEnvironment.getBinFolder(goPathEntry).append(executableName);
Expand Down
Expand Up @@ -35,7 +35,7 @@ public void doRun(IProgressMonitor monitor) throws CommonException, CoreExceptio

ArrayList2<String> cmdLine = getCmdLine();

GoToolManager.getDefault().runBuildTool(goEnv, monitor, workingDir.toPath(), cmdLine);
GoToolManager.getDefault().runBuildTool(goEnv, monitor, workingDir, cmdLine);
}

protected Location getFirstGoPathEntry(GoEnvironment goEnv) throws CommonException {
Expand Down
Expand Up @@ -12,7 +12,6 @@

import static melnorme.lang.ide.core.utils.ResourceUtils.getProjectLocation;

import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;

Expand All @@ -24,6 +23,7 @@
import melnorme.lang.tooling.data.StatusException;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -102,13 +102,13 @@ protected IProject[] doBuild(final IProject project, int kind, Map<String, Strin
goBuildCmdLine.addElements("./...");
// addSourcePackagesToCmdLine(project, goBuildCmdLine, goEnv);

Path projectLocation = getProjectLocation(project);
Path sourceRootDir;
Location projectLocation = getProjectLocation(project);

Location sourceRootDir;
if(GoProjectEnvironment.isProjectInsideGoPath(project, goEnv.getGoPath())) {
sourceRootDir = projectLocation;
} else {
sourceRootDir = projectLocation.resolve("src");
sourceRootDir = projectLocation.resolve_valid("src");
}

ExternalProcessResult buildAllResult =
Expand Down
Expand Up @@ -10,12 +10,11 @@
*******************************************************************************/
package com.googlecode.goclipse.core.operations;

import java.io.File;
import java.nio.file.Path;
import java.util.List;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.operations.AbstractToolsManager;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

import org.eclipse.core.runtime.CoreException;
Expand All @@ -34,16 +33,11 @@ public static GoToolManager getDefault() {
}

/* ----------------- ----------------- */

public ExternalProcessResult runBuildTool(GoEnvironment goEnv, IProgressMonitor pm, File workingDir,
List<String> commandLine) throws CoreException {
return runBuildTool(goEnv, pm, workingDir.toPath(), commandLine);
}

public ExternalProcessResult runBuildTool(GoEnvironment goEnv, IProgressMonitor pm, Path workingDir,
public ExternalProcessResult runBuildTool(GoEnvironment goEnv, IProgressMonitor pm, Location workingDir,
List<String> commandLine) throws CoreException {

ProcessBuilder pb = goEnv.createProcessBuilder(commandLine, workingDir);
ProcessBuilder pb = goEnv.createProcessBuilder(commandLine, workingDir.path);
return runTool(null, pm, pb);
}

Expand Down
Expand Up @@ -6,6 +6,7 @@

import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.misc.MiscUtil;

import org.eclipse.core.filesystem.EFS;
Expand Down Expand Up @@ -96,7 +97,7 @@ protected Object[] getProjectChildren(IProject project) {
GoEnvironment goEnvironment = GoProjectEnvironment.getGoEnvironment(project);

GoRoot goRoot = goEnvironment.getGoRoot();
java.nio.file.Path goRootSource;
Location goRootSource;
try {
goRootSource = goRoot.getSourceRootLocation();
} catch (CommonException e) {
Expand Down
Expand Up @@ -51,7 +51,7 @@ protected void performLongRunningComputation_do(IProgressMonitor monitor) throws

try {
GoOracleFindDefinitionOperation op = new GoOracleFindDefinitionOperation(goOraclePath);
ProcessBuilder pb = op.createProcessBuilder(goEnv, inputPath, range.getOffset());
ProcessBuilder pb = op.createProcessBuilder(goEnv, inputLoc, range.getOffset());

ExternalProcessResult result = GoToolManager.getDefault().runEngineTool(pb, null, monitor);

Expand Down
Expand Up @@ -11,7 +11,6 @@
*******************************************************************************/
package com.googlecode.goclipse.ui.launch;

import java.nio.file.Path;
import java.util.Collection;

import melnorme.lang.ide.launching.LaunchConstants;
Expand All @@ -20,6 +19,7 @@
import melnorme.lang.ide.ui.launch.MainLaunchConfigurationTab;
import melnorme.lang.ide.ui.utils.UIOperationExceptionHandler;
import melnorme.utilbox.misc.ArrayUtil;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.misc.StringUtil;

import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -161,9 +161,9 @@ public String getText(Object element) {
if(!GoProjectEnvironment.isProjectInsideGoPath(project, goEnv.getGoPath())) {
packageResourcePath = "src/" + packageResourcePath;
} else {
Path projectLocation = project.getLocation().toFile().toPath();
Location projectLocation = Location.create_fromValid(project.getLocation().toFile().toPath());
GoPackageName projectGoPackage =
goEnv.getGoPath().findGoPackageForSourceFile(projectLocation.resolve("dummy.go"));
goEnv.getGoPath().findGoPackageForSourceFile(projectLocation.resolve_valid("dummy.go"));

// snip project base name.
packageResourcePath = StringUtil.segmentAfterMatch(packageResourcePath,
Expand Down
Expand Up @@ -10,10 +10,10 @@
*******************************************************************************/
package com.googlecode.goclipse.ui.launch;

import java.nio.file.Path;

import melnorme.lang.ide.core.LaunchConstants_Actual;
import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.ide.ui.launch.AbstractLaunchShortcut2;
import melnorme.utilbox.misc.Location;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -51,11 +51,11 @@ protected ResourceLaunchTarget resourceToLaunchTarget(IResource resource) {

@Override
protected ILaunchConfiguration createConfiguration(ILaunchTarget launchable) {
Path packageLocation = launchable.getAssociatedResource().getLocation().toFile().toPath();
Location packageLocation = ResourceUtils.getResourceLocation(launchable.getAssociatedResource());
IProject project = launchable.getProject();

GoPath goPath = GoProjectEnvironment.getEffectiveGoPath(project);
GoPackageName goPackage = goPath.findGoPackageForSourceFile(packageLocation.resolve("dummy.go"));
GoPackageName goPackage = goPath.findGoPackageForSourceFile(packageLocation.resolve_valid("dummy.go"));
String suggestedName = project.getName() + " - " + goPackage.getFullNameAsString();
return super.createConfiguration(launchable, suggestedName);
}
Expand Down
Expand Up @@ -10,11 +10,9 @@
*******************************************************************************/
package com.googlecode.goclipse.tooling;

import static melnorme.lang.tests.LangToolingTestResources.getTestResourcePath;

import java.nio.file.Path;

import static melnorme.lang.tests.LangToolingTestResources.getTestResourceLoc;
import melnorme.lang.tests.CommonToolingTest;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.tests.TestsWorkingDir;

import com.googlecode.goclipse.tooling.env.GoArch;
Expand All @@ -25,11 +23,11 @@

public class CommonGoToolingTest extends CommonToolingTest {

public static final Path TESTS_WORKDIR = TestsWorkingDir.getWorkingDirPath();
public static final Location TESTS_WORKDIR = TestsWorkingDir.getWorkingDir();

public static final GoRoot SAMPLE_GO_ROOT = new GoRoot(TESTS_WORKDIR.resolve("goRoot").toString());
public static final GoRoot SAMPLE_GO_ROOT = new GoRoot(TESTS_WORKDIR.resolve_valid("goRoot").toString());

public static final Path SAMPLE_GOPATH_Entry = TESTS_WORKDIR.resolve("goPathEntry");
public static final Location SAMPLE_GOPATH_Entry = TESTS_WORKDIR.resolve_valid("goPathEntry");
public static final GoPath SAMPLE_GO_PATH = new GoPath(SAMPLE_GOPATH_Entry.toString());

protected static final GoEnvironment SAMPLE_GOEnv_1 = new GoEnvironment(
Expand All @@ -38,6 +36,6 @@ public class CommonGoToolingTest extends CommonToolingTest {
SAMPLE_GO_PATH
);

public static final Path TR_SAMPLE_GOPATH_ENTRY = getTestResourcePath("sampleGoPathEntry");
public static final Location TR_SAMPLE_GOPATH_ENTRY = getTestResourceLoc("sampleGoPathEntry");

}
Expand Up @@ -61,7 +61,7 @@ protected void handleLineParseError(CommonException ce) {
error(path("MyGoLibFoo/libfoo/blah.go"), 7, -1, "undefined: asdfsd"),
error(path("MyGoLibFoo/libfoo/blah.go"), 10, -1, "not enough arguments in call to fmt.Printf"),
error(path("MyGoLibFoo/foo.go"), 3, -1, "undefined: ziggy"),
error(TR_SAMPLE_GOPATH_ENTRY.resolve("src/samplePackage/foo.go"), 5, -1, "undefined: ziggy2")
error(TR_SAMPLE_GOPATH_ENTRY.resolve_valid("src/samplePackage/foo.go").path, 5, -1, "undefined: ziggy2")
);
testParseError(buildProcessor,
readTemplatedFiled(BUILD_OUTPUT_TestResources.resolve("outputA.txt")),
Expand All @@ -78,7 +78,7 @@ protected void handleLineParseError(CommonException ce) {
List<ToolSourceMessage> OUTPUTB_Errors = listFrom(
error(path("libbar/blah.go"), 3, 8, errorMessage1),
error(path("../MyGoLibFoo/libfoo/blah.go"), 3, 8, errorMessage2),
error(TR_SAMPLE_GOPATH_ENTRY.resolve("src/samplePackage/foo.go"), 3, 2, errorMessage3)
error(TR_SAMPLE_GOPATH_ENTRY.resolve_valid("src/samplePackage/foo.go").path, 3, 2, errorMessage3)
);
testParseError(buildProcessor,
OUTPUT_B,
Expand Down

0 comments on commit 86c7838

Please sign in to comment.