use of com.typelead.gradle.utils.CabalHelper.WriteResult in project gradle-eta by typelead.
the class EtaResolveDependencies method resolveDependencies.
@TaskAction
public void resolveDependencies() {
/* Create the destination directory if it doesn't exist. */
File workingDir = getDestinationDirectory();
if (!workingDir.exists() && !workingDir.mkdirs()) {
throw new GradleException("Unable to create destination directory: " + workingDir.getAbsolutePath());
}
/* Remove the cabal.project.freeze file from a previous run, if it exists. */
File existingFreezeFile = getFreezeConfigFile();
if (existingFreezeFile.exists() && !existingFreezeFile.delete()) {
throw new GradleException("Unable to delete existing freeze file: " + existingFreezeFile.getAbsolutePath());
}
/* Generate the .cabal & cabal.project files. */
final WriteResult[] writeResults = new WriteResult[2];
DependencyUtils.foldEtaDependencies(project, dependencies.get(), (directDeps, projectDeps, gitStringDeps, gitDeps) -> {
/* Include the git dependencies in the Etlas
dependency list, but avoid project dependencies because they will be
built separately and will not be found. */
directDeps.addAll(gitStringDeps);
writeResults[0] = CabalHelper.generateCabalFile(getProject().getName(), NamingScheme.fixVersion(getProject().getVersion().toString()), directDeps, workingDir);
writeResults[1] = CabalHelper.generateCabalProjectFile(gitDeps, workingDir);
});
/* Delete existing *.cabal files to avoid errors when changing the project
name. */
final File oldCabalFile = writeResults[0].getFile();
project.delete(project.fileTree(workingDir, fileTree -> {
fileTree.include("*.cabal");
fileTree.exclude(fileTreeElement -> {
try {
return fileTreeElement.getFile().getCanonicalPath().equals(oldCabalFile.getCanonicalPath());
} catch (IOException e) {
return true;
}
});
}));
/* Only run the freeze command if the cabal files have changed or the
Eta version state has changed. */
boolean changed = writeResults[0].isChanged() || writeResults[0].isChanged() || getVersionsChanged();
if (changed) {
/* Fork an etlas process to freeze the dependencies. */
EtlasCommand etlas = new EtlasCommand(getProject());
etlas.getWorkingDirectory().set(workingDir);
etlas.freeze();
}
setDidWork(changed);
}
use of com.typelead.gradle.utils.CabalHelper.WriteResult in project gradle-eta by typelead.
the class EtaInstallDependencies method installDependencies.
@TaskAction
public void installDependencies() {
final EtaOptions etaOptions = getOptions();
etaOptions.validate(etaInfo.get());
final File workingDir = getDestinationDir();
copyFreezeConfigIfChanged(workingDir);
/* Calculate all the modules */
final List<String> modules = getModules();
/* Determine if it's an executable */
String exec = executable.getOrNull();
if (exec != null && exec.length() <= 0) {
exec = null;
}
final String executableSpec = exec;
/* Generate the .cabal & cabal.project files. */
final WriteResult[] writeResults = new WriteResult[2];
final String targetConfigurationName = getTargetConfiguration();
Set<File> packageDBs = ConfigurationUtils.getEtaConfiguration(ConfigurationUtils.getConfiguration(project, targetConfigurationName)).getAllArtifacts(project).stream().map(Provider::get).collect(Collectors.toSet());
packageDBs.addAll(project.files(extraPackageDBs.values()).getFiles());
DependencyUtils.foldEtaDependencies(project, dependencies.get(), (directDeps, projectDeps, gitStringDeps, gitDeps) -> {
/* Include the project dependencies and git dependencies in the Etlas
dependency list. */
directDeps.addAll(projectDeps);
directDeps.addAll(gitStringDeps);
directDeps.addAll(extraPackageDBs.keySet());
writeResults[0] = CabalHelper.generateCabalFile(getPackageName(), getPackageVersion(), executableSpec, getSourceDirs().getFiles().stream().map(File::getAbsolutePath).collect(Collectors.toList()), modules, etaOptions, directDeps, workingDir);
writeResults[1] = CabalHelper.generateCabalProjectFile(gitDeps, packageDBs, workingDir);
});
/* Delete existing *.cabal files to avoid errors when changing the project
name. */
final File oldCabalFile = writeResults[0].getFile();
project.delete(project.fileTree(workingDir, fileTree -> {
fileTree.include("*.cabal");
fileTree.exclude(fileTreeElement -> {
try {
return fileTreeElement.getFile().getCanonicalPath().equals(oldCabalFile.getCanonicalPath());
} catch (IOException e) {
return true;
}
});
}));
/* Fork an etlas process to install the dependencies. */
final EtlasCommand etlas = new EtlasCommand(project);
etlas.getWorkingDirectory().set(workingDir);
boolean isUpToDate = etlas.deps(EtlasCommand.libTarget(getPackageName()), dependencyGraph -> {
/* Inject the dependencies into the respective configurations. */
DependencyHandler dependencies = project.getDependencies();
final EtaConfiguration targetEtaConfiguration = ConfigurationUtils.getEtaConfiguration(project, getTargetConfiguration());
targetEtaConfiguration.resolve(project, dependencies, dependencyGraph);
});
setDidWork(!isUpToDate);
}
Aggregations