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

Commit

Permalink
Add lint target. Fix tests target
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed May 17, 2016
1 parent 98549e3 commit 4fe88e1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected void testBuildOperation() throws CommonException, OperationCancellatio

/* ----------------- setup a project not CONTAINED in a Go-workspace 'src' entry ----------------- */
Location projectParentLoc = getProjectLocation().resolve_fromValid("..");
GoEnvironmentPrefs.GO_PATH.setValue(project, projectParentLoc.toString());
GoEnvironmentPrefs.GO_PATH.setValue(project, projectParentLoc.resolve_fromValid("other").toString());
GoEnvironmentPrefs.APPEND_PROJECT_LOC_TO_GOPATH.setValue(project, false);
// createSourceDir(projectParentLoc);

Expand All @@ -162,7 +162,7 @@ protected void testBuildOperation() throws CommonException, OperationCancellatio
// Test operation working directory
assertEquals(
getBuildOperation(bt2).getToolProcessBuilder().directory().toString(),
ResourceUtils.loc(project2.getLocation()).toString());
TESTS_GO_WORKSPACE.resolve_fromValid("src").toString());
}

protected void createSourceDir(Location projectLoc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static GoPath getEffectiveGoPath(IProject project) {
return rawGoPath;
}

GoWorkspaceLocation goPathEntry = rawGoPath.findGoPathEntryForSourcePath(projectLoc);
GoWorkspaceLocation goPathEntry = rawGoPath.findGoPathEntryForSourceLocation(projectLoc);
if(goPathEntry != null) {
// GOPATH already contains project location
return rawGoPath;
Expand All @@ -73,7 +73,7 @@ public static boolean isProjectInsideGoPathSourceFolder(IProject project) throws
}

public static boolean isProjectInsideGoPathSourceFolder(IProject project, GoPath goPath) throws CommonException {
return goPath.findGoPathEntryForSourcePath(ResourceUtils.getProjectLocation2(project)) != null;
return goPath.findGoPathEntryForSourceLocation(ResourceUtils.getProjectLocation2(project)) != null;
}

protected static String getEffectiveValueFromEnv(IProjectPreference<String> pref, IProject project,
Expand Down Expand Up @@ -106,19 +106,6 @@ public static GoEnvironment getValidatedGoEnvironment(final IProject project) th
return goEnv;
}

public static Location getAssociatedSourceFolder(GoPath goPath, Location projectLoc) throws CommonException {

if(goPath.findExactGoPathEntry(projectLoc) != null) {
return projectLoc.resolve_valid("src");
}

if(goPath.findGoPathEntryForSourcePath(projectLoc) != null) {
return projectLoc;
}

throw new CommonException(GoCoreMessages.ERROR_GOPATH_DoesNotContainProject());
}

public static ArrayList2<GoPackageName> findSourcePackages(IProject project, GoEnvironment goEnvironment)
throws CoreException {
return goEnvironment.getGoPath().findGoSourcePackages(ResourceUtils.getProjectLocation(project));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
package com.googlecode.goclipse.core.operations;

import static melnorme.lang.ide.core.utils.ResourceUtils.loc;
import static melnorme.utilbox.core.CoreUtil.array;
import static melnorme.utilbox.misc.PathUtil.createResolvedPath;

import static melnorme.utilbox.core.CoreUtil.list;
import java.nio.file.Path;

import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -64,8 +62,8 @@ public GoBuildManager(LangBundleModel bundleModel, ToolManager toolManager) {
}

public static final String BUILD_TYPE_Build = "build";
public static final String BUILD_TYPE_BuildCheck = "check";
public static final String BUILD_TYPE_BuildTests = "build-tests";
public static final String BUILD_TYPE_Lint = "lint";
public static final String BUILD_TYPE_RunTests = "[run-tests]";

public static final Indexable<BuildType> BUILD_TYPES = createDefaultBuildTypes();
Expand All @@ -76,7 +74,7 @@ public static ArrayList2<BuildType> createDefaultBuildTypes() {
return ArrayList2.create(
new GoDefaultBuildType(BUILD_TYPE_Build),
new GoTestBuildType(),
new GoCheckBuildType(),
new GoLintBuildType(),
new GoRunTestsBuildType()
);
}
Expand All @@ -94,9 +92,9 @@ public BuildTargetNameParser getBuildTargetNameParser() {
@Override
protected void addDefaultBuildTarget(ArrayList2<BuildTarget> buildTargets, IProject project, BundleInfo bundleInfo,
BuildConfiguration buildConfig, BuildType buildType, BuildTargetData btd) {
if(buildType.getName().equals(BUILD_TYPE_BuildCheck)) {
btd.autoBuildEnabled = true;
}
// if(buildType.getName().equals(BUILD_TYPE_BuildCheck)) {
// btd.autoBuildEnabled = true;
// }
super.addDefaultBuildTarget(buildTargets, project, bundleInfo, buildConfig, buildType, btd);
}

Expand All @@ -120,24 +118,27 @@ protected GoPackageName getValidGoPackageName(String goPackageString) throws Com

@Override
public String getDefaultCommandArguments(BuildTarget bt) throws CommonException {
ArrayList2<String> buildArgs = getPackageSpecCommand(bt, getBuildCommand());
ArrayList2<String> buildArgs = getDefaultCommandArguments_list(bt);
return DebugPlugin.renderArguments(buildArgs.toArray(String.class), null);
}

protected ArrayList2<String> getPackageSpecCommand(BuildTarget bt, String... buildCommands)
protected ArrayList2<String> getDefaultCommandArguments_list(BuildTarget bt) throws CommonException {
Indexable<String> baseCommand = getBuildCommand2();
ArrayList2<String> commandLine = baseCommand.toArrayList().addElements("-v", "-gcflags", "-N -l");
addPackageSpecCommand(bt, commandLine);
return commandLine;
}

protected void addPackageSpecCommand(BuildTarget bt, ArrayList2<String> buildCommand)
throws CommonException {
ArrayList2<String> buildArgs = new ArrayList2<>();
buildArgs.addElements(buildCommands);

String goPackageSpec = getGoPackageSpec(
bt.getProject(),
bt.getBuildConfigName()
);
buildArgs.addElements("-v", "-gcflags", "-N -l", goPackageSpec);
return buildArgs;
buildCommand.addElements(goPackageSpec);
}

protected abstract String[] getBuildCommand();
protected abstract Indexable<String> getBuildCommand2();

protected String getGoPackageSpec(IProject project, String goPackageSpec) throws CommonException {

Expand Down Expand Up @@ -194,8 +195,8 @@ public GoDefaultBuildType(String name) {
}

@Override
protected String[] getBuildCommand() {
return array("build");
protected Indexable<String> getBuildCommand2() {
return list("install");
}

@Override
Expand All @@ -205,14 +206,21 @@ public BuildTargetOperation getBuildOperation(BuildOperationParameters buildOpPa

}

public static class GoCheckBuildType extends GoDefaultBuildType {
public GoCheckBuildType() {
super(BUILD_TYPE_BuildCheck);
public static class GoLintBuildType extends GoDefaultBuildType {
public GoLintBuildType() {
super(BUILD_TYPE_Lint);
}

@Override
protected String[] getBuildCommand() {
return array("install");
public String getDefaultCommandLine(BuildTarget bt) throws CommonException {
return getDefaultCommandArguments(bt);
}

@Override
protected ArrayList2<String> getDefaultCommandArguments_list(BuildTarget bt) throws CommonException {
ArrayList2<String> commandLine = new ArrayList2<>("gometalinter");
addPackageSpecCommand(bt, commandLine);
return commandLine;
}
}

Expand All @@ -228,10 +236,13 @@ public GoBuildTargetOperation(BuildOperationParameters buildOpParams) throws Com
Location projectLoc = getProjectLocation();

goEnv = GoProjectEnvironment.getValidatedGoEnvironment(project);
sourceBaseDir = GoProjectEnvironment.getAssociatedSourceFolder(goEnv.getGoPath(), projectLoc);
sourceBaseDir = goEnv.getGoPath().getSourceRootforLocation(projectLoc);
if(sourceBaseDir == null) {
throw new CommonException(GoCoreMessages.ERROR_GOPATH_DoesNotContainProject());
}

if(sourceBaseDir.getParent().equals(projectLoc)) {
checkGoFilesInSourceRoot();
checkForGoFilesInSourceRoot(sourceBaseDir);
}

workingDirectory = sourceBaseDir;
Expand All @@ -247,7 +258,7 @@ public ProcessBuilder getToolProcessBuilder() throws CommonException, OperationC
return pb;
}

protected void checkGoFilesInSourceRoot() throws CommonException {
protected void checkForGoFilesInSourceRoot(Location sourceBaseDir) throws CommonException {
CheckSrcFolderRootFilesWithNoPackage srcCheck = new CheckSrcFolderRootFilesWithNoPackage();

if(!sourceBaseDir.toFile().exists()) {
Expand Down Expand Up @@ -285,8 +296,8 @@ public GoTestBuildType() {
}

@Override
protected String[] getBuildCommand() {
return array("test", "-c");
protected Indexable<String> getBuildCommand2() {
return list("test", "-c");
}

@Override
Expand Down Expand Up @@ -335,10 +346,10 @@ public void execute(IOperationMonitor om) throws CommonException, OperationCance
String goPackageToBuild = StringUtil.trimEnd(argumentsTemplate.get(lastArgIx), "...");

GoWorkspaceLocation goWorkspace = goEnv.getGoPath().findGoPathEntry(getProjectLocation());
GoPackageName baseGoPackage = goEnv.getGoPath().findGoPackageForLocation(getProjectLocation());
if(baseGoPackage != null) {
goPackageToBuild = createResolvedPath(baseGoPackage.toString(), goPackageToBuild).toString();
}
// GoPackageName baseGoPackage = goEnv.getGoPath().findGoPackageForLocation(getProjectLocation());
// if(baseGoPackage != null) {
// goPackageToBuild = createResolvedPath(baseGoPackage.toString(), goPackageToBuild).toString();
// }
Collection2<GoPackageName> sourcePackages = goWorkspace.findSubPackages(goPackageToBuild);

for (GoPackageName goPackage : sourcePackages) {
Expand All @@ -363,8 +374,8 @@ public GoRunTestsBuildType() {
}

@Override
protected String[] getBuildCommand() {
return array("test");
protected Indexable<String> getBuildCommand2() {
return list("test");
}

@Override
Expand Down
14 changes: 12 additions & 2 deletions plugin_tooling/src/com/googlecode/goclipse/tooling/env/GoPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String getGoPathWorkspaceString() {
return StringUtil.collToString(goPathElements, File.pathSeparator);
}

public GoWorkspaceLocation findExactGoPathEntry(Location location) {
public GoWorkspaceLocation findGoPathEntryAt(Location location) {
assertNotNull(location);

for (String pathElement : goPathElements) {
Expand Down Expand Up @@ -100,7 +100,7 @@ public GoWorkspaceLocation findGoPathEntry(Location goPathSubLocation) {

/** @return the GOPATH entry that contains the given sourcePath, if it's in the "src" folder of that entry.
* Return null otherwise. */
public GoWorkspaceLocation findGoPathEntryForSourcePath(Location sourcePath) {
public GoWorkspaceLocation findGoPathEntryForSourceLocation(Location sourcePath) {
GoWorkspaceLocation goWorkspace = findGoPathEntry(sourcePath);

if(goWorkspace != null && sourcePath.startsWith(goWorkspace.getSrcLocation())) {
Expand Down Expand Up @@ -142,4 +142,14 @@ public ArrayList2<GoPackageName> findGoSourcePackages(Location subLocation) {
return workspaceEntry.findSourcePackages(subLocation);
}

public Location getSourceRootforLocation(Location location) {

GoWorkspaceLocation goPathEntryForLoc = findGoPathEntry(location);
if(goPathEntryForLoc != null) {
return goPathEntryForLoc.location.resolve_valid("src");
}

return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package com.googlecode.goclipse.tooling.env;

import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import static melnorme.utilbox.core.CoreUtil.areEqual;

import java.io.IOException;
Expand All @@ -29,7 +30,7 @@ public class GoWorkspaceLocation {
protected final Location location;

public GoWorkspaceLocation(Location location) {
this.location = location;
this.location = assertNotNull(location);
}

@Override
Expand Down

0 comments on commit 4fe88e1

Please sign in to comment.