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

Commit

Permalink
@lang: -> follow up changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Jul 24, 2015
1 parent 8fa0da0 commit ff0a6cb
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 96 deletions.
Expand Up @@ -78,12 +78,12 @@ protected BuildManager getBuildManager() {
}

protected BuildTarget testGetBuildTargetFor(ProjectBuildInfo buildInfo, String targetName, String buildConfig,
String buildType) throws CommonException {
String buildType) throws CommonException, CoreException {
return testGetBuildTargetFor(buildInfo, targetName, buildConfig, buildType, buildConfig);
}

protected BuildTarget testGetBuildTargetFor(ProjectBuildInfo buildInfo, String targetName, String goPackageName,
String buildType, String relArtifactPath) throws CommonException {
String buildType, String relArtifactPath) throws CommonException, CoreException {
BuildTarget buildTarget = buildInfo.getBuildTargetFor(targetName);
assertAreEqual(buildTarget.getTargetName(), targetName);

Expand All @@ -92,11 +92,11 @@ protected BuildTarget testGetBuildTargetFor(ProjectBuildInfo buildInfo, String t
assertAreEqual(buildTargetOp.getBuildTypeName(), buildType);

if(relArtifactPath == null) {
verifyThrows(() -> buildTargetOp.getArtifactPath3(), CommonException.class);
verifyThrows(() -> buildTargetOp.getArtifactPath(), CommonException.class);
} else {
Location binLocation = getProjectLocation().resolve("bin");
assertAreEqual(buildTargetOp.getArtifactPath3(),
binLocation.resolve(relArtifactPath + MiscUtil.getExecutableSuffix()).toPath());
assertAreEqual(buildTargetOp.getArtifactPath(),
binLocation.resolve(relArtifactPath + MiscUtil.getExecutableSuffix()).toString());

}

Expand Down
Expand Up @@ -84,9 +84,9 @@ protected Path getValidExecutableFilePath2() throws CoreException, CommonExcepti

String exePathString = settings.getExecutablePath_Attribute();
if(exePathString != null) {
return buildTargetOperation.getValidArtifactPath3(exePathString);
return buildTargetOperation.getValidArtifactPath(exePathString);
}
return buildTargetOperation.getValidArtifactPath3();
return buildTargetOperation.getValidArtifactPath();
}

public Location toAbsolute(Path exePath) throws StatusException, CoreException {
Expand Down
Expand Up @@ -226,11 +226,11 @@ public String getBuildTargetName(String buildConfigName, String buildType) {
return buildConfigName + StringUtil.prefixStr(BUILD_TYPE_NAME_SEPARATOR, buildType);
}

public static String getBuildConfigString(String targetName) {
public String getBuildConfigString(String targetName) {
return StringUtil.substringUntilMatch(targetName, BUILD_TYPE_NAME_SEPARATOR);
}

public static String getBuildTypeString(String targetName) {
public String getBuildTypeString(String targetName) {
return StringUtil.segmentAfterMatch(targetName, BUILD_TYPE_NAME_SEPARATOR);
}

Expand Down
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.Path;

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

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.launch.LaunchMessages;
Expand All @@ -41,6 +42,10 @@ public BuildManager getBuildManager() {
return LangCore.getBuildManager();
}

public IProject getProject() {
return project;
}

public BuildConfiguration getBuildConfiguration() {
return buildConfiguration2;
}
Expand All @@ -57,7 +62,7 @@ public String getBuildTypeName() {
return buildTypeName;
}

public String getEffectiveBuildOptions() throws CommonException {
public String getEffectiveBuildOptions() throws CommonException, CoreException {
String buildOptions = getBuildOptions();
if(buildOptions != null) {
return buildOptions;
Expand Down Expand Up @@ -104,10 +109,11 @@ public String getName() {
}

public abstract String getDefaultBuildOptions(BuildTargetRunner buildTargetRunner)
throws CommonException;
throws CommonException, CoreException;

public String getArtifactPath(BuildTargetRunner buildTargetRunner) {
return buildTargetRunner.getBuildConfiguration().getArtifactPath();
public String getArtifactPath(BuildTargetRunner buildTargetOp)
throws CommonException, CoreException {
return buildTargetOp.getBuildConfiguration().getArtifactPath();
}

}
Expand All @@ -118,21 +124,19 @@ protected BuildType getBuildType() throws CommonException {
return getBuildManager().getBuildType_NonNull(getBuildTypeName());
}

public String getDefaultBuildOptions() throws CommonException {
public String getDefaultBuildOptions() throws CommonException, CoreException {
return getBuildType().getDefaultBuildOptions(this);
}

/* FIXME: rename */
public String getArtifactPath3() throws CommonException {
public String getArtifactPath() throws CommonException, CoreException {
return getBuildType().getArtifactPath(this);
}

public Path getValidArtifactPath3() throws CommonException {
String artifactPathStr = getArtifactPath3();
return getValidArtifactPath3(artifactPathStr);
public Path getValidArtifactPath() throws CommonException, CoreException {
return getValidArtifactPath(getArtifactPath());
}

public Path getValidArtifactPath3(String artifactPathStr) throws CommonException {
public Path getValidArtifactPath(String artifactPathStr) throws CommonException {
if(artifactPathStr == null || artifactPathStr.isEmpty()) {
throw new CommonException(LaunchMessages.BuildTarget_NoArtifactPathSpecified);
}
Expand Down
Expand Up @@ -57,7 +57,7 @@ public String getBuildType() {
return StringUtil.nullAsEmpty(buildTarget.getBuildTypeName());
}

protected String getEffectiveBuildOptions() throws CommonException {
protected String getEffectiveBuildOptions() throws CommonException, CoreException {
return buildTarget.getEffectiveBuildOptions();
}

Expand All @@ -67,27 +67,33 @@ protected String[] getEvaluatedAndParserArguments() throws CoreException, Common

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

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

addMainArguments(commands);

commands.addElements(getEvaluatedAndParserArguments());

ExternalProcessResult processResult = startProcess(pm, commands);
processBuildOutput(processResult);
return getProcessBuilder(commands);
}

protected void addToolCommand(ArrayList2<String> commands) throws CommonException {
protected void addToolCommand(ArrayList2<String> commands)
throws CoreException, CommonException, OperationCancellation {
commands.add(getBuildToolPath().toString());
}

protected abstract void addMainArguments(ArrayList2<String> commands);

// TODO: write some default for this method, refactor associated code.
protected abstract ExternalProcessResult startProcess(IProgressMonitor pm, ArrayList2<String> commands)
throws CommonException, OperationCancellation;
protected abstract void addMainArguments(ArrayList2<String> commands)
throws CoreException, CommonException, OperationCancellation;

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

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

}
Expand Up @@ -17,8 +17,6 @@

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

import com.googlecode.goclipse.core.GoCoreMessages;
import com.googlecode.goclipse.core.GoEnvironmentPrefs;
import com.googlecode.goclipse.core.GoProjectEnvironment;
Expand All @@ -27,7 +25,6 @@
import com.googlecode.goclipse.tooling.env.GoEnvironment;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.launch.LaunchUtils;
import melnorme.lang.ide.core.operations.OperationInfo;
import melnorme.lang.ide.core.operations.ToolMarkersUtil;
import melnorme.lang.ide.core.operations.build.BuildManager;
Expand All @@ -41,6 +38,7 @@
import melnorme.lang.ide.core.project_model.ProjectBuildInfo;
import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.tooling.data.StatusLevel;
import melnorme.lang.utils.ProcessUtils;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.collections.Indexable;
import melnorme.utilbox.concurrency.OperationCancellation;
Expand Down Expand Up @@ -86,6 +84,19 @@ public BuildTarget getBuildTargetFor(ProjectBuildInfo projectBuildInfo, String t
return createBuildTarget(targetName, false, null);
}

@Override
public BuildTargetRunner getBuildTargetOperation(IProject project, BuildTarget buildTarget)
throws CommonException {
String targetName = buildTarget.getTargetName();
String buildConfigName = getBuildConfigString(targetName);
String buildTypeName = getBuildTypeString(targetName);

/* FIXME: adapt this code in parent */
BuildConfiguration buildConfiguration = new BuildConfiguration(buildConfigName, null);

return createBuildTargetOperation(project, buildConfiguration, buildTypeName, buildTarget);
}

@Override
public BuildTargetRunner createBuildTargetOperation(IProject project, BuildConfiguration buildConfig,
String buildTypeName, BuildTarget buildSettings) {
Expand Down Expand Up @@ -113,7 +124,7 @@ protected GoPackageName getValidGoPackageName(String goPackageString) throws Com

@Override
public String getDefaultBuildOptions(BuildTargetRunner buildTargetOp) throws CommonException {
String goPackageSpec = getGoPackageSpec(buildTargetOp.project, buildTargetOp.getBuildConfigName());
String goPackageSpec = getGoPackageSpec(buildTargetOp.getProject(), buildTargetOp.getBuildConfigName());
return getBuildCommand() + " -v -gcflags \"-N -l\" " + goPackageSpec;
}

Expand All @@ -137,8 +148,8 @@ protected String getGoPackageSpec(IProject project, String goPackageSpec) throws
}

@Override
public String getArtifactPath(BuildTargetRunner buildTargetOp) {
Location binFolderLocation = GoProjectEnvironment.getBinFolderLocation(buildTargetOp.project);
public String getArtifactPath(BuildTargetRunner buildTargetOp) throws CommonException {
Location binFolderLocation = GoProjectEnvironment.getBinFolderLocation(buildTargetOp.getProject());

String binFilePath = getBinFilePath(getValidGoPackageName(buildTargetOp.getBuildConfigName()));
return binFolderLocation.resolve(binFilePath + MiscUtil.getExecutableSuffix()).toString();
Expand Down Expand Up @@ -214,8 +225,7 @@ protected void addMainArguments(ArrayList2<String> commands) {
}

@Override
protected ExternalProcessResult startProcess(IProgressMonitor pm, ArrayList2<String> commands)
throws CommonException, OperationCancellation, CoreException {
protected ProcessBuilder getProcessBuilder(ArrayList2<String> commands) throws CoreException, CommonException {
Location projectLocation = ResourceUtils.getProjectLocation(project);

goEnv = getValidGoEnvironment(project);
Expand All @@ -226,10 +236,9 @@ protected ExternalProcessResult startProcess(IProgressMonitor pm, ArrayList2<Str

checkGoFilesInSourceRoot();
}

ProcessBuilder pb = goEnv.createProcessBuilder(commands, sourceRootDir);

return runBuildTool(pm, pb);
ProcessBuilder pb = ProcessUtils.createProcessBuilder(commands, sourceRootDir);
goEnv.setupProcessEnv(pb, true);
return pb;
}

protected void checkGoFilesInSourceRoot() throws CoreException {
Expand All @@ -244,7 +253,8 @@ protected void checkGoFilesInSourceRoot() throws CoreException {
}

@Override
protected void processBuildOutput(ExternalProcessResult buildAllResult) throws CommonException {
protected void processBuildOutput(ExternalProcessResult buildAllResult)
throws CoreException, CommonException, OperationCancellation {
GoBuildOutputProcessor buildOutput = new GoBuildOutputProcessor() {
@Override
protected void handleMessageParseError(CommonException ce) {
Expand Down
Expand Up @@ -34,7 +34,7 @@ protected ProcessBuilder createCleanPB() throws CoreException, CommonException {
ArrayList2<String> goBuildCmdLine = GoBuildManager.getToolCommandLine();
goBuildCmdLine.addElements("clean", "-i", "-x");
GoBuildManager.addSourcePackagesToCmdLine(project, goBuildCmdLine, goEnv);
return goEnv.createProcessBuilder(goBuildCmdLine, getProjectLocation());
return goEnv.createProcessBuilder(goBuildCmdLine, getProjectLocation(), true);
}

}
Expand Up @@ -87,7 +87,7 @@ public MainLaunchTab_ProgramPathField() {
@Override
protected String getDefaultFieldValue() {
try {
return getValidatedBuildTargetRunner().getArtifactPath3();
return getValidatedBuildTargetRunner().getArtifactPath();
} catch(CoreException | CommonException e) {
return null;
}
Expand Down

0 comments on commit ff0a6cb

Please sign in to comment.