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

Commit

Permalink
LANG: Minor BuildTargetOperation cleanup, and related
Browse files Browse the repository at this point in the history
Properly implemented GoTestBuildType build op.
GoPath/GoPackages code cleanup.
  • Loading branch information
bruno-medeiros committed Jul 29, 2015
1 parent 0233ad7 commit e9e24e0
Show file tree
Hide file tree
Showing 26 changed files with 437 additions and 245 deletions.
Expand Up @@ -94,7 +94,7 @@ public class GoProjectEnvironmentTest extends CommonGoCoreTest {


protected void checkEnvGoPath(IProject project, Collection<String> list, boolean insideGoPath) protected void checkEnvGoPath(IProject project, Collection<String> list, boolean insideGoPath)
throws CoreException { throws CoreException {
assertTrue(GoProjectEnvironment.isProjectInsideGoPath(project) == insideGoPath); assertTrue(GoProjectEnvironment.isProjectInsideGoPathSourceFolder(project) == insideGoPath);
GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(project); GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(project);
assertEquals(goEnv.getGoPathEntries(), list); assertEquals(goEnv.getGoPathEntries(), list);
} }
Expand Down
Expand Up @@ -69,7 +69,7 @@ protected BuildManager getBuildManager() {
assertTrue(pbi != null); assertTrue(pbi != null);
assertTrue(pbi.getBuildTargets().size() == GoBuildManager.BUILD_TYPES.size()); assertTrue(pbi.getBuildTargets().size() == GoBuildManager.BUILD_TYPES.size());


testGetBuildTargetFor(pbi, "go_package", "go_package", null); testGetBuildTargetFor(pbi, "go_package", "go_package", "build");
testGetBuildTargetFor(pbi, "go_package#build", "go_package", "build"); testGetBuildTargetFor(pbi, "go_package#build", "go_package", "build");
testGetBuildTargetFor(pbi, "foo/go_package#build", "foo/go_package", "build", "go_package"); testGetBuildTargetFor(pbi, "foo/go_package#build", "foo/go_package", "build", "go_package");


Expand Down
Expand Up @@ -75,7 +75,9 @@ public String getDefaultArtifactPath() throws CommonException, CoreException {
} }


public Location getValidExecutableLocation() throws CoreException, CommonException { public Location getValidExecutableLocation() throws CoreException, CommonException {
String effectiveArtifactPath = artifactPathOverride != null ? artifactPathOverride : getDefaultArtifactPath(); // Note we want to validate the default artifact path, even if it's not used because of the override.
String defaultArtifactPath = getDefaultArtifactPath();
String effectiveArtifactPath = artifactPathOverride != null ? artifactPathOverride : defaultArtifactPath;
return getValidExecutableLocation(effectiveArtifactPath); return getValidExecutableLocation(effectiveArtifactPath);
} }


Expand Down
Expand Up @@ -11,12 +11,15 @@
package melnorme.lang.ide.core.operations; package melnorme.lang.ide.core.operations;


import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;


import melnorme.lang.ide.core.LangCore; import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.operations.build.IToolOperation; import melnorme.lang.ide.core.operations.build.IToolOperation;
import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.utilbox.concurrency.OperationCancellation; import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException; import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult; import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;


public abstract class AbstractToolManagerOperation implements IToolOperation { public abstract class AbstractToolManagerOperation implements IToolOperation {
Expand All @@ -31,6 +34,10 @@ public IProject getProject() {
return project; return project;
} }


protected Location getProjectLocation() throws CoreException {
return ResourceUtils.getProjectLocation(project);
}

protected AbstractToolManager getToolManager() { protected AbstractToolManager getToolManager() {
return LangCore.getToolManager(); return LangCore.getToolManager();
} }
Expand Down
Expand Up @@ -367,6 +367,9 @@ public BuildTargetValidator createBuildTargetValidator(IProject project, String
throws CommonException { throws CommonException {
String buildConfigName = getBuildConfigString(targetName); String buildConfigName = getBuildConfigString(targetName);
String buildTypeName = getBuildTypeString(targetName); String buildTypeName = getBuildTypeString(targetName);
if(buildTypeName == null) {
buildTypeName = getBuildTypes().get(0).getName();
}
return createBuildTargetValidator(project, buildConfigName, buildTypeName, buildOptions); return createBuildTargetValidator(project, buildConfigName, buildTypeName, buildOptions);
} }


Expand Down
Expand Up @@ -76,24 +76,22 @@ protected String getEffectiveBuildOptions() throws CommonException, CoreExceptio
return effectiveBuildOptions; return effectiveBuildOptions;
} }


protected String[] getEvaluatedAndParserArguments() throws CoreException, CommonException {
return LaunchUtils.getEvaluatedAndParsedArguments(getEffectiveBuildOptions());
}

@Override @Override
public void execute(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation { public void execute(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation {
ProcessBuilder pb = getToolProcessBuilder(); ProcessBuilder pb = getToolProcessBuilder();
ExternalProcessResult processResult = runBuildTool(opInfo, pb, pm); runBuildToolAndProcessOutput(pb, pm);
processBuildOutput(processResult);
} }


protected ProcessBuilder getToolProcessBuilder() throws CoreException, CommonException, OperationCancellation { protected ProcessBuilder getToolProcessBuilder() throws CoreException, CommonException, OperationCancellation {
return getToolProcessBuilder(getMainArguments(), getEvaluatedAndParsedArguments());
}

protected ProcessBuilder getToolProcessBuilder(String[] mainArguments, String[] extraArguments)
throws CoreException, CommonException, OperationCancellation {
ArrayList2<String> commands = new ArrayList2<String>(); ArrayList2<String> commands = new ArrayList2<String>();
addToolCommand(commands); addToolCommand(commands);

commands.addElements(mainArguments);
addMainArguments(commands); commands.addElements(extraArguments);

commands.addElements(getEvaluatedAndParserArguments());
return getProcessBuilder(commands); return getProcessBuilder(commands);
} }


Expand All @@ -102,12 +100,21 @@ protected void addToolCommand(ArrayList2<String> commands)
commands.add(getBuildToolPath().toString()); commands.add(getBuildToolPath().toString());
} }


protected abstract void addMainArguments(ArrayList2<String> commands) protected abstract String[] getMainArguments()
throws CoreException, CommonException, OperationCancellation; throws CoreException, CommonException, OperationCancellation;


protected String[] getEvaluatedAndParsedArguments() throws CoreException, CommonException {
return LaunchUtils.getEvaluatedAndParsedArguments(getEffectiveBuildOptions());
}

protected abstract ProcessBuilder getProcessBuilder(ArrayList2<String> commands) protected abstract ProcessBuilder getProcessBuilder(ArrayList2<String> commands)
throws CommonException, OperationCancellation, CoreException; throws CommonException, OperationCancellation, CoreException;


public void runBuildToolAndProcessOutput(ProcessBuilder pb, IProgressMonitor pm)
throws CoreException, CommonException, OperationCancellation {
processBuildOutput(runBuildTool(opInfo, pb, pm));
}

protected abstract void processBuildOutput(ExternalProcessResult processResult) protected abstract void processBuildOutput(ExternalProcessResult processResult)
throws CoreException, CommonException, OperationCancellation; throws CoreException, CommonException, OperationCancellation;


Expand Down
Expand Up @@ -12,8 +12,6 @@


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


import java.util.Collection;

import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;


Expand All @@ -24,6 +22,7 @@
import com.googlecode.goclipse.tooling.env.GoOs; import com.googlecode.goclipse.tooling.env.GoOs;
import com.googlecode.goclipse.tooling.env.GoPath; import com.googlecode.goclipse.tooling.env.GoPath;
import com.googlecode.goclipse.tooling.env.GoRoot; import com.googlecode.goclipse.tooling.env.GoRoot;
import com.googlecode.goclipse.tooling.env.GoWorkspaceLocation;


import melnorme.lang.ide.core.utils.ResourceUtils; import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.ide.core.utils.prefs.StringPreference; import melnorme.lang.ide.core.utils.prefs.StringPreference;
Expand Down Expand Up @@ -57,7 +56,7 @@ public static GoPath getEffectiveGoPath(IProject project) {
return rawGoPath; return rawGoPath;
} }


Location goPathEntry = rawGoPath.findGoPathEntryForSourcePath(projectLoc); GoWorkspaceLocation goPathEntry = rawGoPath.findGoPathEntryForSourcePath(projectLoc);
if(goPathEntry != null) { if(goPathEntry != null) {
// GOPATH already contains project location // GOPATH already contains project location
return rawGoPath; return rawGoPath;
Expand All @@ -66,16 +65,15 @@ public static GoPath getEffectiveGoPath(IProject project) {
// Implicitly add project location to GOPATH // Implicitly add project location to GOPATH
ArrayList2<String> newGoPathEntries = new ArrayList2<>(projectLoc.toPathString()); ArrayList2<String> newGoPathEntries = new ArrayList2<>(projectLoc.toPathString());
newGoPathEntries.addAll(rawGoPath.getGoPathEntries()); newGoPathEntries.addAll(rawGoPath.getGoPathEntries());

return new GoPath(newGoPathEntries); return new GoPath(newGoPathEntries);
} }


public static boolean isProjectInsideGoPath(IProject project) throws CoreException { public static boolean isProjectInsideGoPathSourceFolder(IProject project) throws CoreException {
GoPath goPath = getEffectiveGoPath(project); GoPath goPath = getEffectiveGoPath(project);
return isProjectInsideGoPath(project, goPath); return isProjectInsideGoPathSourceFolder(project, goPath);
} }


public static boolean isProjectInsideGoPath(IProject project, GoPath goPath) throws CoreException { public static boolean isProjectInsideGoPathSourceFolder(IProject project, GoPath goPath) throws CoreException {
return goPath.findGoPathEntryForSourcePath(ResourceUtils.getProjectLocation(project)) != null; return goPath.findGoPathEntryForSourcePath(ResourceUtils.getProjectLocation(project)) != null;
} }


Expand Down Expand Up @@ -116,9 +114,9 @@ public static GoEnvironment getValidatedGoEnvironment(final IProject project) th
return goEnv; return goEnv;
} }


public static Collection<GoPackageName> getSourcePackages(IProject project, GoEnvironment goEnvironment) public static ArrayList2<GoPackageName> findSourcePackages(IProject project, GoEnvironment goEnvironment)
throws CoreException { throws CoreException {
return goEnvironment.getGoPath().findSourcePackages(ResourceUtils.getProjectLocation(project)); return goEnvironment.getGoPath().findGoSourcePackages(ResourceUtils.getProjectLocation(project));
} }


public static Location getBinFolderLocation(IProject project) throws CommonException { public static Location getBinFolderLocation(IProject project) throws CommonException {
Expand Down

0 comments on commit e9e24e0

Please sign in to comment.