Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #561 - cleanup task input/output issues #567

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build_script/integTest.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sourceSets {
}

dependencies {
integTestImplementation gradleTestKit()
integTestImplementation externalDependency.spock
}

Expand Down
1 change: 1 addition & 0 deletions gradle-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tasks.pluginUnderTestMetadata {
}

integTest {
classpath += files(pluginUnderTestMetadata.outputDirectory)
dependsOn configurations.dataTemplateForTesting, configurations.pegasusPluginForTesting
systemProperty 'integTest.dataTemplateCompileDependencies', "'${configurations.dataTemplateForTesting.join("', '")}'"
systemProperty 'integTest.pegasusPluginDependencies', "'${configurations.pegasusPluginForTesting.join("', '")}'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.gradle.plugins.ide.idea.IdeaPlugin;
import org.gradle.plugins.ide.idea.model.IdeaModule;
import org.gradle.util.GradleVersion;


/**
Expand Down Expand Up @@ -633,6 +634,11 @@ public void setJavadocJarTask(Task javadocJarTask)
@Override
public void apply(Project project)
{
if (!isAtLeastGradle54())
{
throw new GradleException("The pegasus plugin requires Gradle 5.4 or higher; please upgrade.");
}

project.getPlugins().apply(JavaPlugin.class);
project.getPlugins().apply(IdeaPlugin.class);
project.getPlugins().apply(EclipsePlugin.class);
Expand Down Expand Up @@ -1407,6 +1413,7 @@ protected void configureRestModelGeneration(Project project, SourceSet sourceSet
changedFileReportTask.setIdlFiles(SharedFileUtils.getSuffixedFiles(project, apiIdlDir, IDL_FILE_SUFFIX));
changedFileReportTask.setSnapshotFiles(SharedFileUtils.getSuffixedFiles(project, apiSnapshotDir,
SNAPSHOT_FILE_SUFFIX));
changedFileReportTask.getOutputFile().set(project.getLayout().getBuildDirectory().file("changedFilesReport.txt"));
changedFileReportTask.mustRunAfter(publishRestliSnapshotTask, publishRestliIdlTask);
changedFileReportTask.doLast(new CacheableAction<>(t ->
{
Expand Down Expand Up @@ -2224,4 +2231,8 @@ private Task publishPegasusSchemaSnapshot(Project project, SourceSet sourceSet,
task.onlyIf(t -> !SharedFileUtils.getSuffixedFiles(project, inputDir, PDL_FILE_SUFFIX).isEmpty());
});
}
protected static boolean isAtLeastGradle54() {
return GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("5.4")) >= 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

import com.linkedin.pegasus.gradle.IOUtil;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.FileCollection;
import org.gradle.api.specs.Specs;
import org.gradle.api.file.FileType;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.incremental.IncrementalTaskInputs;
import org.gradle.work.InputChanges;


public class ChangedFileReportTask extends DefaultTask
Expand All @@ -21,15 +25,10 @@ public class ChangedFileReportTask extends DefaultTask

private FileCollection _idlFiles = getProject().files();
private FileCollection _snapshotFiles = getProject().files();

public ChangedFileReportTask()
{
//with Gradle 6.0, Declaring an incremental task without outputs is not allowed.
getOutputs().upToDateWhen(Specs.satisfyNone());
}
private RegularFileProperty _outputFile = getProject().getObjects().fileProperty();

@TaskAction
public void checkFilesForChanges(IncrementalTaskInputs inputs)
public void checkFilesForChanges(InputChanges inputs)
{
getLogger().lifecycle("Checking idl and snapshot files for changes...");
getLogger().info("idlFiles: " + _idlFiles.getAsPath());
Expand All @@ -41,46 +40,59 @@ public void checkFilesForChanges(IncrementalTaskInputs inputs)

if (inputs.isIncremental())
{
inputs.outOfDate(inputFileDetails -> {
if (inputFileDetails.isAdded())
inputs.getFileChanges(getSnapshotFiles()).forEach(change -> {
if (change.getFileType() != FileType.DIRECTORY)
{
filesAdded.add(inputFileDetails.getFile().getAbsolutePath());
}

if (inputFileDetails.isRemoved())
{
filesRemoved.add(inputFileDetails.getFile().getAbsolutePath());
}

if (inputFileDetails.isModified())
{
filesChanged.add(inputFileDetails.getFile().getAbsolutePath());
String path = change.getFile().getAbsolutePath();
switch (change.getChangeType())
{
case ADDED:
filesAdded.add(path);
break;
case REMOVED:
filesRemoved.add(path);
break;
case MODIFIED:
filesChanged.add(path);
break;
}
}
});

inputs.removed(inputFileDetails -> filesRemoved.add(inputFileDetails.getFile().getAbsolutePath()));
StringBuilder sb = new StringBuilder();

if (!filesRemoved.isEmpty())
{
String files = joinByComma(filesRemoved);
_needCheckinFiles.add(files);
getLogger().lifecycle(
"The following files have been removed, be sure to remove them from source control: {}", files);
String removedFilesMsg = String.format("The following files have been removed, " +
"be sure to remove them from source control: %s\n", files);
sb.append(removedFilesMsg);
}

if (!filesAdded.isEmpty())
{
String files = joinByComma(filesAdded);
_needCheckinFiles.add(files);
getLogger().lifecycle("The following files have been added, be sure to add them to source control: {}", files);
String addedFilesMsg = String.format("The following files have been added, " +
"be sure to add them to source control: %s\n", files);
sb.append(addedFilesMsg);
}

if (!filesChanged.isEmpty())
{
String files = joinByComma(filesChanged);
_needCheckinFiles.add(files);
getLogger().lifecycle(
"The following files have been changed, be sure to commit the changes to source control: {}", files);
String modifiedFilesMsg = String.format("The following files have been changed, " +
"be sure to commit the changes to source control: %s\n", files);
sb.append(modifiedFilesMsg);
}

String output = sb.toString();
if (!output.isEmpty())
{
getLogger().lifecycle(output);
IOUtil.writeText(getOutputFile().get().getAsFile(), output);
}
}
}
Expand Down Expand Up @@ -119,4 +131,9 @@ public Collection<String> getNeedCheckinFiles()
{
return _needCheckinFiles;
}

@OutputFile
public RegularFileProperty getOutputFile() {
return _outputFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ReplacedBy;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -175,6 +176,7 @@ public void setSummaryTarget(File summaryTarget)
* @deprecated use {@link #isModelCompatible()} instead
*/
@Deprecated
@ReplacedBy("modelCompatible")
public boolean getIsModelCompatible()
{
return isModelCompatible();
Expand All @@ -189,6 +191,7 @@ public boolean getIsModelCompatible()
* @deprecated use {@link #isModelCompatible()} instead
*/
@Deprecated
@ReplacedBy("modelCompatible")
public boolean isIsModelCompatible()
{
return isModelCompatible();
Expand All @@ -209,6 +212,7 @@ public boolean isModelCompatible()
* @deprecated use {@link #isRestSpecCompatible()} instead
*/
@Deprecated
@ReplacedBy("restSpecCompatible")
public boolean getIsRestSpecCompatible()
{
return isRestSpecCompatible();
Expand All @@ -223,6 +227,7 @@ public boolean getIsRestSpecCompatible()
* @deprecated use {@link #isRestSpecCompatible()} instead
*/
@Deprecated
@ReplacedBy("restSpecCompatible")
public boolean isIsRestSpecCompatible()
{
return isRestSpecCompatible();
Expand All @@ -243,6 +248,7 @@ public boolean isRestSpecCompatible()
* @deprecated use {@link #isEquivalent()} instead
*/
@Deprecated
@ReplacedBy("equivalent")
public boolean getIsEquivalent()
{
return _equivalent;
Expand All @@ -257,6 +263,7 @@ public boolean getIsEquivalent()
* @deprecated use {@link #isEquivalent()} instead
*/
@Deprecated
@ReplacedBy("equivalent")
public boolean isIsEquivalent()
{
return _equivalent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ReplacedBy;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -210,6 +211,7 @@ public void setSummaryTarget(File summaryTarget)
* @deprecated use {@link #isModelCompatible()} instead
*/
@Deprecated
@ReplacedBy("modelCompatible")
public boolean getIsModelCompatible()
{
return isModelCompatible();
Expand All @@ -224,6 +226,7 @@ public boolean getIsModelCompatible()
* @deprecated use {@link #isModelCompatible()} instead
*/
@Deprecated
@ReplacedBy("modelCompatible")
public boolean isIsModelCompatible()
{
return isModelCompatible();
Expand All @@ -244,6 +247,7 @@ public boolean isModelCompatible()
* @deprecated use {@link #isRestSpecCompatible()} instead
*/
@Deprecated
@ReplacedBy("restSpecCompatible")
public boolean getIsRestSpecCompatible()
{
return isRestSpecCompatible();
Expand All @@ -258,6 +262,7 @@ public boolean getIsRestSpecCompatible()
* @deprecated use {@link #isRestSpecCompatible()} instead
*/
@Deprecated
@ReplacedBy("restSpecCompatible")
public boolean isIsRestSpecCompatible()
{
return isRestSpecCompatible();
Expand All @@ -278,6 +283,7 @@ public boolean isRestSpecCompatible()
* @deprecated use {@link #isEquivalent()} instead
*/
@Deprecated
@ReplacedBy("equivalent")
public boolean getIsEquivalent()
{
return isEquivalent();
Expand All @@ -292,6 +298,7 @@ public boolean getIsEquivalent()
* @deprecated use {@link #isEquivalent()} instead
*/
@Deprecated
@ReplacedBy("equivalent")
public boolean isIsEquivalent()
{
return isEquivalent();
Expand All @@ -312,6 +319,7 @@ public boolean isEquivalent()
* @deprecated use {@link #isRestSpecEquivalent()} instead
*/
@Deprecated
@ReplacedBy("restSpecEquivalent")
public boolean getIsRestSpecEquivalent()
{
return isRestSpecEquivalent();
Expand All @@ -326,6 +334,7 @@ public boolean getIsRestSpecEquivalent()
* @deprecated use {@link #isRestSpecEquivalent()} instead
*/
@Deprecated
@ReplacedBy("restSpecEquivalent")
public boolean isIsRestSpecEquivalent()
{
return isRestSpecEquivalent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ReplacedBy;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -105,6 +106,7 @@ public void setCurrentSnapshotFiles(FileCollection currentSnapshotFiles)
}

@InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
public File getPreviousSnapshotDirectory()
{
return _previousSnapshotDirectory;
Expand Down Expand Up @@ -157,6 +159,7 @@ public void setSummaryTarget(File summaryTarget)
* @deprecated use {@link #isModelCompatible()} instead
*/
@Deprecated
@ReplacedBy("modelCompatible")
public boolean getIsModelCompatible()
{
return isModelCompatible();
Expand All @@ -171,6 +174,7 @@ public boolean getIsModelCompatible()
* @deprecated use {@link #isModelCompatible()} instead
*/
@Deprecated
@ReplacedBy("modelCompatible")
public boolean isIsModelCompatible()
{
return isModelCompatible();
Expand All @@ -191,6 +195,7 @@ public boolean isModelCompatible()
* @deprecated use {@link #isRestSpecCompatible()} instead
*/
@Deprecated
@ReplacedBy("restSpecCompatible")
public boolean getIsRestSpecCompatible()
{
return isRestSpecCompatible();
Expand All @@ -205,6 +210,7 @@ public boolean getIsRestSpecCompatible()
* @deprecated use {@link #isRestSpecCompatible()} instead
*/
@Deprecated
@ReplacedBy("restSpecCompatible")
public boolean isIsRestSpecCompatible()
{
return isRestSpecCompatible();
Expand All @@ -225,6 +231,7 @@ public boolean isRestSpecCompatible()
* @deprecated use {@link #isEquivalent()} instead
*/
@Deprecated
@ReplacedBy("equivalent")
public boolean getIsEquivalent()
{
return isEquivalent();
Expand All @@ -239,6 +246,7 @@ public boolean getIsEquivalent()
* @deprecated use {@link #isEquivalent()} instead
*/
@Deprecated
@ReplacedBy("equivalent")
public boolean isIsEquivalent()
{
return isEquivalent();
Expand All @@ -259,6 +267,7 @@ public boolean isEquivalent()
* @deprecated use {@link #isRestSpecEquivalent()} instead
*/
@Deprecated
@ReplacedBy("restSpecEquivalent")
public boolean getIsRestSpecEquivalent()
{
return isRestSpecEquivalent();
Expand All @@ -273,6 +282,7 @@ public boolean getIsRestSpecEquivalent()
* @deprecated use {@link #isRestSpecEquivalent()} instead
*/
@Deprecated
@ReplacedBy("restSpecEquivalent")
public boolean isIsRestSpecEquivalent()
{
return isRestSpecEquivalent();
Expand Down
Loading