use of com.typelead.gradle.utils.EtlasCommand 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.EtlasCommand in project gradle-eta by typelead.
the class EtaSetupEnvironment method setupEnvironment.
@TaskAction
public void setupEnvironment() {
EtlasCommand etlas = new EtlasCommand(getProject());
ResolvedExecutable etlasExec = resolveEtlas();
/* This is a bootstrap step since we need to populate
this property in order for the following etlas
invocation to work. */
resolvedEtlas.set(etlasExec);
ensureTelemetryPreferencesAndUpdate(etlas);
if (etlasExec.getVersion() == null) {
etlasExec.setVersion(etlas.numericVersion());
}
ResolvedExecutable etaExec = resolveEta(etlas);
resolvedEta.set(etaExec);
if (etaExec.isFresh()) {
getProject().getLogger().lifecycle("Installing Eta v" + friendlyVersion(etaExec.getVersion()));
etlas.installEta();
}
boolean changed = SnapshotUtils.takeSnapshotAndCompare(getVersionsSnapshot(), etaExec, etlasExec, getEtaSpec(), getEtlasSpec());
resolvedEtaInfo.set(fetchEtaInfo(etlas, etaExec, changed));
versionsChanged.set(Boolean.valueOf(changed));
setDidWork(changed);
}
use of com.typelead.gradle.utils.EtlasCommand 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);
}
use of com.typelead.gradle.utils.EtlasCommand in project gradle-eta by typelead.
the class EtaCompile method compile.
@TaskAction
public void compile() {
final Project project = getProject();
final File workingDir = getDestinationDir();
/* Create cabal.project.local file that will contain configuration options:
- Configure the `-cp` flag
*/
Set<File> classpathFiles = new LinkedHashSet<File>(getClasspath().getFiles());
classpathFiles.addAll(getExtraClasspath());
CabalHelper.generateCabalProjectLocalFile(getPackageName(), classpathFiles, workingDir);
/* Fork an etlas process to fetch the dependencies. */
final EtlasCommand etlas = new EtlasCommand(project);
etlas.getWorkingDirectory().set(workingDir);
boolean isUpToDate = etlas.build();
setDidWork(!isUpToDate);
Directory classesDir = this.classesDir.getOrNull();
File outputJarFile = getOutputJarFile();
if (classesDir != null && !isUpToDate && outputJarFile.exists()) {
/* Extract the Jar file into the classes directory so the rest of the
Gradle Java pipeline can work as intended.
TODO: Add an option for the Eta compiler to generate classfiles directly.
*/
project.copy(copySpec -> {
copySpec.from(project.zipTree(outputJarFile));
copySpec.into(classesDir);
});
}
}
use of com.typelead.gradle.utils.EtlasCommand in project gradle-eta by typelead.
the class EtaInstallAllDependencies method installAllDependencies.
@TaskAction
public void installAllDependencies() {
final File workingDir = getDestinationDir();
/* Fork an etlas process to install the dependencies. */
final EtlasCommand etlas = new EtlasCommand(project);
etlas.getWorkingDirectory().set(workingDir);
boolean isUpToDate = etlas.deps(EtlasCommand.libTarget(getProject().getName()), dependencyGraph -> {
for (Project p : project.getAllprojects()) {
if (p.getConvention().findPlugin(EtaPluginConvention.class) != null) {
DependencyHandler dependencies = p.getDependencies();
for (Configuration c : p.getConfigurations()) {
final EtaConfiguration etaConfiguration = ExtensionHelper.getExtension(c, EtaConfiguration.class);
if (etaConfiguration != null) {
etaConfiguration.resolve(project, dependencies, dependencyGraph);
}
}
}
}
for (Project p : project.getAllprojects()) {
if (p.getPlugins().findPlugin(EtaPlugin.class) == null && p.getConvention().findPlugin(JavaPluginConvention.class) != null) {
p.getTasks().withType(EtaInjectDependencies.class).all(EtaInjectDependencies::injectDependencies);
}
}
});
setDidWork(!isUpToDate);
}
Aggregations