Skip to content

Commit

Permalink
feat: add gradle snapshots module
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyi222666 committed May 26, 2022
1 parent 6f99abc commit 8dbeb6f
Show file tree
Hide file tree
Showing 94 changed files with 6,922 additions and 2 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ android {

debug {
isMinifyEnabled = false

}
}
kotlinOptions {
jvmTarget = "11"
}
packagingOptions {
resources.excludes.addAll(listOf("META-INF/**","xsd/*","license/*"))
resources.excludes.addAll(listOf("META-INF/**", "xsd/*", "license/*"))
resources.pickFirsts.add("kotlin/**")
}
compileOptions {
Expand All @@ -72,6 +75,7 @@ dependencies {

implementation(project(":core-api"))
implementation(project(":functional"))
implementation(project(":snapshots"))
implementation(project(":file-temp"))

/*
Expand Down
1 change: 1 addition & 0 deletions subprojects/snapshots/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions subprojects/snapshots/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id("java-library")
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
api(project(":files"))
api(project(":hashing"))

implementation(project(":base-annotations"))


implementation("com.google.guava:guava:30.1.1-jre")
implementation("com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava")
implementation("com.google.code.findbugs:jsr305:3.0.2")


implementation("org.slf4j:slf4j-api:1.7.36")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.internal;

import java.util.Collection;

public interface RelativePathSupplier {
boolean isRoot();

Collection<String> getSegments();

String toRelativePath();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.internal.fingerprint;

import org.gradle.internal.hash.HashCode;
import org.gradle.internal.snapshot.FileSystemSnapshot;

/**
* A file collection fingerprint taken during this build.
*/
public interface CurrentFileCollectionFingerprint extends FileCollectionFingerprint {
/**
* Returns the combined hash of the contents of this {@link CurrentFileCollectionFingerprint}.
*/
HashCode getHash();

String getStrategyIdentifier();

/**
* Returns the snapshot used to capture these fingerprints.
*/
FileSystemSnapshot getSnapshot();

boolean isEmpty();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.internal.fingerprint;

import org.gradle.internal.file.FileType;
import org.gradle.internal.snapshot.FileSystemLocationSnapshot;

import java.util.function.Predicate;

/**
* Specifies how a fingerprinter should handle directories that are found in a filecollection.
*/
public enum DirectorySensitivity {
/**
* Whatever the default behavior is for the given fingerprinter. For some fingerprinters, the
* default behavior is to fingerprint directories, for others, they ignore directories by default.
*/
DEFAULT(snapshot -> true),
/**
* Ignore directories
*/
IGNORE_DIRECTORIES(snapshot -> snapshot.getType() != FileType.Directory);

private final Predicate<FileSystemLocationSnapshot> fingerprintCheck;

DirectorySensitivity(Predicate<FileSystemLocationSnapshot> fingerprintCheck) {
this.fingerprintCheck = fingerprintCheck;
}

public boolean shouldFingerprint(FileSystemLocationSnapshot snapshot) {
return fingerprintCheck.test(snapshot);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.internal.fingerprint;

import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import org.gradle.internal.hash.HashCode;
import org.gradle.internal.hash.Hashing;

import java.util.Map;

/**
* An immutable snapshot of some aspects of the contents and meta-data of a collection of files or directories.
*/
public interface FileCollectionFingerprint {

/**
* The underlying fingerprints.
*/
Map<String, FileSystemLocationFingerprint> getFingerprints();

/**
* The Merkle hashes of the roots which make up this file collection fingerprint.
*/
ImmutableMultimap<String, HashCode> getRootHashes();

/**
* The absolute paths for the roots of this file collection fingerprint.
*/
default ImmutableSet<String> getRootPaths() {
return getRootHashes().keySet();
}

FileCollectionFingerprint EMPTY = new FileCollectionFingerprint() {
private final HashCode strategyConfigurationHash = Hashing.signature(getClass());

@Override
public Map<String, FileSystemLocationFingerprint> getFingerprints() {
return ImmutableSortedMap.of();
}

@Override
public ImmutableMultimap<String, HashCode> getRootHashes() {
return ImmutableMultimap.of();
}

@Override
public ImmutableSet<String> getRootPaths() {
return ImmutableSet.of();
}

@Override
public HashCode getStrategyConfigurationHash() {
return strategyConfigurationHash;
}

@Override
public String toString() {
return "EMPTY";
}
};

HashCode getStrategyConfigurationHash();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.internal.fingerprint;

import org.gradle.internal.file.FileType;
import org.gradle.internal.hash.HashCode;
import org.gradle.internal.hash.Hashable;
import org.gradle.internal.hash.Hashing;

/**
* An immutable fingerprint of some aspects of a file's metadata and content.
*
* Should implement {@link #equals(Object)} and {@link #hashCode()} to compare these aspects.
* Comparisons are very frequent, so these methods need to be fast.
*
* File fingerprints are cached between builds, so their memory footprint should be kept to a minimum.
*/
public interface FileSystemLocationFingerprint extends Comparable<FileSystemLocationFingerprint>, Hashable {
HashCode DIR_SIGNATURE = Hashing.signature("DIR");
HashCode MISSING_FILE_SIGNATURE = Hashing.signature("MISSING");

String getNormalizedPath();
HashCode getNormalizedContentHash();
FileType getType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.internal.fingerprint;

import com.google.common.collect.ImmutableList;
import org.gradle.internal.hash.Hasher;

import java.util.Collection;

/**
* Strategy for appending a collection of fingerprints to a hasher.
*/
public enum FingerprintHashingStrategy {
SORT {
@Override
public void appendToHasher(Hasher hasher, Collection<FileSystemLocationFingerprint> fingerprints) {
ImmutableList<FileSystemLocationFingerprint> sortedFingerprints = ImmutableList.sortedCopyOf(fingerprints);
appendCollectionToHasherKeepingOrder(hasher, sortedFingerprints);
}
},
KEEP_ORDER {
@Override
public void appendToHasher(Hasher hasher, Collection<FileSystemLocationFingerprint> fingerprints) {
appendCollectionToHasherKeepingOrder(hasher, fingerprints);
}
};

public abstract void appendToHasher(Hasher hasher, Collection<FileSystemLocationFingerprint> fingerprints);

protected void appendCollectionToHasherKeepingOrder(Hasher hasher, Collection<FileSystemLocationFingerprint> fingerprints) {
for (FileSystemLocationFingerprint fingerprint : fingerprints) {
fingerprint.appendToHasher(hasher);
}
}
}
Loading

0 comments on commit 8dbeb6f

Please sign in to comment.