diff --git a/agent-api/metadata/notice.properties b/agent-api/metadata/notice.properties deleted file mode 100644 index 7a0c7091b..000000000 --- a/agent-api/metadata/notice.properties +++ /dev/null @@ -1 +0,0 @@ -dependencies.hash=4DB938898328F0FD02FE0AAC17B76840 \ No newline at end of file diff --git a/agent-common/metadata/notice.properties b/agent-common/metadata/notice.properties deleted file mode 100644 index c66ff4265..000000000 --- a/agent-common/metadata/notice.properties +++ /dev/null @@ -1 +0,0 @@ -dependencies.hash=58A77DBA5639AE986B7AE3449B37C966 \ No newline at end of file diff --git a/agent-plugin/metadata/notice.properties b/agent-plugin/metadata/notice.properties deleted file mode 100644 index 306a78c2a..000000000 --- a/agent-plugin/metadata/notice.properties +++ /dev/null @@ -1 +0,0 @@ -dependencies.hash=264A56624029B76A38CABB520CC327B8 \ No newline at end of file diff --git a/agent-sdk/metadata/notice.properties b/agent-sdk/metadata/notice.properties deleted file mode 100644 index dc4a9df5c..000000000 --- a/agent-sdk/metadata/notice.properties +++ /dev/null @@ -1 +0,0 @@ -dependencies.hash=2D0D1CC58FF70B8B5149B947BE697B84 \ No newline at end of file diff --git a/build-tools/README.md b/build-tools/README.md index e262475ff..e2b7b8b05 100644 --- a/build-tools/README.md +++ b/build-tools/README.md @@ -76,14 +76,6 @@ licensesConfig { } ``` -## Verifying NOTICE files - -NOTICE files need to be kept updated on dependencies changes, for this purpose each will get a new -gradle task named `verifyNoticeFile` which ideally should be run in a CI pipeline in order to -confirm that the existing NOTICE files are valid in regards to their project's dependencies. If -there's an issue, then the `createNoticeFile` task will have to be run so that the new NOTICE files -can be tracked and pushed into the repo. - ## Adding source headers This work is triggered when building this project so there's nothing manual to be done about it. The diff --git a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/metadata/NoticeMetadataHandler.java b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/metadata/NoticeMetadataHandler.java deleted file mode 100644 index eb7b6f108..000000000 --- a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/metadata/NoticeMetadataHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -package co.elastic.otel.android.compilation.tools.metadata; - -import org.gradle.api.Project; -import org.gradle.api.file.RegularFile; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -public class NoticeMetadataHandler { - private static final String METADATA_FILE_NAME = "notice.properties"; - private static final String PROPERTY_DEPENDENCIES_HASH = "dependencies.hash"; - private final Properties properties; - - public static RegularFile getMetadataFile(Project project) { - return project.getLayout().getProjectDirectory().file("metadata/" + METADATA_FILE_NAME); - } - - public static NoticeMetadataHandler create() { - return new NoticeMetadataHandler(new Properties()); - } - - public static NoticeMetadataHandler read(File noticePropertiesFile) { - Properties properties = new Properties(); - try (InputStream in = new FileInputStream(noticePropertiesFile)) { - properties.load(in); - return new NoticeMetadataHandler(properties); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private NoticeMetadataHandler(Properties properties) { - this.properties = properties; - } - - public String getDependenciesHash() { - return properties.getProperty(PROPERTY_DEPENDENCIES_HASH); - } - - public void setDependenciesHash(String dependenciesHash) { - properties.setProperty(PROPERTY_DEPENDENCIES_HASH, dependenciesHash); - } - - public void save(File output) { - try (FileWriter writer = new FileWriter(output, false)) { - writer.write(PROPERTY_DEPENDENCIES_HASH + "=" + getDependenciesHash()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/BaseNoticePlugin.java b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/BaseNoticePlugin.java index ae890aadd..696ce5a68 100644 --- a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/BaseNoticePlugin.java +++ b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/BaseNoticePlugin.java @@ -10,5 +10,4 @@ public abstract class BaseNoticePlugin implements Plugin { protected static final String LIBRARY_ELEMENT_LICENSED_DEPENDENCIES = "licensed-dependencies"; protected static final String CONFIGURATION_NOTICES_COLLECTOR = "noticeFiles"; protected static final String LIBRARY_ELEMENT_NOTICE_FILES = "notice-files"; - protected static final String TASK_VERIFY_NOTICE_FILE_NAME = "verifyNoticeFile"; } diff --git a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/subprojects/AarNoticeProviderPlugin.java b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/subprojects/AarNoticeProviderPlugin.java index 4fd624ebe..534850168 100644 --- a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/subprojects/AarNoticeProviderPlugin.java +++ b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/subprojects/AarNoticeProviderPlugin.java @@ -17,8 +17,6 @@ import co.elastic.otel.android.compilation.tools.tasks.CreateDependenciesListTask; import co.elastic.otel.android.compilation.tools.tasks.CreateNoticeTask; import co.elastic.otel.android.compilation.tools.tasks.NoticeMergerTask; -import co.elastic.otel.android.compilation.tools.tasks.dependencies.DependenciesHasherTask; -import co.elastic.otel.android.compilation.tools.tasks.dependencies.DependenciesVerifierTask; import co.elastic.otel.android.compilation.tools.tasks.subprojects.CopySingleFileTask; import co.elastic.otel.android.compilation.tools.tasks.subprojects.NoticeFilesCollectorTask; import co.elastic.otel.android.compilation.tools.tasks.subprojects.PomLicensesCollectorTask; @@ -38,10 +36,6 @@ public void apply(Project project) { Configuration runtimeClasspath = component.getVariantDependencies().getRuntimeClasspath(); Configuration apmToolsClasspath = wrapConfiguration(project, variant, runtimeClasspath); List runtimeConfigs = getRuntimeConfigurations(project, apmToolsClasspath); - TaskProvider dependenciesHasher = project.getTasks().register(variant.getName() + "DependenciesHasher", DependenciesHasherTask.class, task -> { - task.getRuntimeDependencies().set(runtimeConfigs); - task.getOutputFile().set(project.getLayout().getBuildDirectory().file(task.getName() + "/" + "dependencies_hash.txt")); - }); TaskProvider pomLicensesFinder = project.getTasks().register(variant.getName() + "DependenciesLicencesFinder", PomLicensesCollectorTask.class, task -> { task.getRuntimeDependencies().set(runtimeConfigs); task.getLicensesFound().set(project.getLayout().getBuildDirectory().file(task.getName() + "/licenses.txt")); @@ -63,7 +57,6 @@ public void apply(Project project) { task.getMergedNoticeFiles().from(noticeFilesMerger.flatMap(NoticeMergerTask::getOutputFile)); task.getLicensedDependencies().set(licensesDependencies.flatMap(CreateDependenciesListTask::getOutputFile)); task.getFoundLicensesIds().set(pomLicensesFinder.flatMap(PomLicensesCollectorTask::getLicensesFound)); - task.getDependenciesHashFile().set(dependenciesHasher.flatMap(DependenciesHasherTask::getOutputFile)); task.getOutputDir().set(project.getLayout().getBuildDirectory().dir(task.getName())); }); if (apmExtension.variantName.get().equals(variant.getName())) { @@ -72,9 +65,6 @@ public void apply(Project project) { task.getInputFile().set(createNotice.get().getOutputDir().file("META-INF/NOTICE")); task.getOutputFile().set(project.getLayout().getProjectDirectory().file("src/main/resources/META-INF/NOTICE")); }); - project.getTasks().register(TASK_VERIFY_NOTICE_FILE_NAME, DependenciesVerifierTask.class, task -> { - task.getDependenciesHashFile().set(dependenciesHasher.flatMap(DependenciesHasherTask::getOutputFile)); - }); setUpLicensedDependencies(project, pomLicensesFinder); setUpNoticeFilesProvider(project, noticeCollector); } diff --git a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/subprojects/JarNoticeProviderPlugin.java b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/subprojects/JarNoticeProviderPlugin.java index be7ffc270..d78215269 100644 --- a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/subprojects/JarNoticeProviderPlugin.java +++ b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/plugins/subprojects/JarNoticeProviderPlugin.java @@ -9,8 +9,6 @@ import co.elastic.otel.android.compilation.tools.tasks.CreateDependenciesListTask; import co.elastic.otel.android.compilation.tools.tasks.CreateNoticeTask; import co.elastic.otel.android.compilation.tools.tasks.NoticeMergerTask; -import co.elastic.otel.android.compilation.tools.tasks.dependencies.DependenciesHasherTask; -import co.elastic.otel.android.compilation.tools.tasks.dependencies.DependenciesVerifierTask; import co.elastic.otel.android.compilation.tools.tasks.subprojects.NoticeFilesCollectorTask; import co.elastic.otel.android.compilation.tools.tasks.subprojects.PomLicensesCollectorTask; @@ -20,10 +18,6 @@ public class JarNoticeProviderPlugin extends BaseSubprojectPlugin { public void apply(Project project) { super.apply(project); List runtimeClasspath = getRuntimeConfigurations(project, project.getConfigurations().getByName("runtimeClasspath")); - TaskProvider dependenciesHasher = project.getTasks().register("dependenciesHasher", DependenciesHasherTask.class, task -> { - task.getRuntimeDependencies().set(runtimeClasspath); - task.getOutputFile().set(project.getLayout().getBuildDirectory().file(task.getName() + "/" + "dependencies_hash.txt")); - }); TaskProvider pomLicensesFinder = project.getTasks().register("dependenciesLicencesFinder", PomLicensesCollectorTask.class, task -> { task.getRuntimeDependencies().set(runtimeClasspath); task.getLicensesFound().set(project.getLayout().getBuildDirectory().file(task.getName() + "/licenses.txt")); @@ -48,15 +42,10 @@ public void apply(Project project) { task.getMergedNoticeFiles().from(noticeFilesMerger.flatMap(NoticeMergerTask::getOutputFile)); task.getLicensedDependencies().set(licensesDependencies.flatMap(CreateDependenciesListTask::getOutputFile)); task.getFoundLicensesIds().set(pomLicensesFinder.flatMap(PomLicensesCollectorTask::getLicensesFound)); - task.getDependenciesHashFile().set(dependenciesHasher.flatMap(DependenciesHasherTask::getOutputFile)); task.getOutputDir().set(project.getLayout().getProjectDirectory().dir("src/main/resources")); }); project.getTasks().named("processResources").configure(task -> task.mustRunAfter(createNoticeFileTask)); - project.getTasks().register(TASK_VERIFY_NOTICE_FILE_NAME, DependenciesVerifierTask.class, task -> { - task.getDependenciesHashFile().set(dependenciesHasher.flatMap(DependenciesHasherTask::getOutputFile)); - }); - setUpLicensedDependencies(project, pomLicensesFinder); setUpNoticeFilesProvider(project, noticeCollector); } diff --git a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/CreateNoticeTask.java b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/CreateNoticeTask.java index ce77068e3..f6c256d5a 100644 --- a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/CreateNoticeTask.java +++ b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/CreateNoticeTask.java @@ -1,15 +1,11 @@ package co.elastic.otel.android.compilation.tools.tasks; -import org.apache.commons.io.FileUtils; -import org.gradle.api.Project; import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.InputFiles; -import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.OutputDirectory; -import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import java.io.BufferedReader; @@ -31,7 +27,6 @@ import java.util.Set; import co.elastic.otel.android.compilation.tools.data.ArtifactLicense; -import co.elastic.otel.android.compilation.tools.metadata.NoticeMetadataHandler; import co.elastic.otel.android.compilation.tools.utils.TextUtils; public abstract class CreateNoticeTask extends BaseTask { @@ -45,20 +40,9 @@ public abstract class CreateNoticeTask extends BaseTask { @InputFile public abstract RegularFileProperty getFoundLicensesIds(); - @InputFile - @Optional - public abstract RegularFileProperty getDependenciesHashFile(); - @OutputDirectory public abstract DirectoryProperty getOutputDir(); - @OutputFile - public abstract RegularFileProperty getMetadataOutputFile(); - - public CreateNoticeTask() { - getMetadataOutputFile().set(NoticeMetadataHandler.getMetadataFile(getProject())); - } - @TaskAction public void action() { File licensesFile = getLicensedDependencies().get().getAsFile(); @@ -89,25 +73,6 @@ public void action() { addLicenses(outputStream, licenseIds); } outputStream.close(); - saveMetadata(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private void saveMetadata() { - if (!getDependenciesHashFile().isPresent()) { - Project project = getProject(); - project.getLogger().lifecycle("Skipping metadata saving for project: " + project.getName()); - return; - } - File dependenciesHashFile = getDependenciesHashFile().get().getAsFile(); - File metadataFile = getMetadataOutputFile().get().getAsFile(); - try { - String dependenciesHash = FileUtils.readFileToString(dependenciesHashFile, StandardCharsets.UTF_8); - NoticeMetadataHandler noticeMetadataHandler = NoticeMetadataHandler.create(); - noticeMetadataHandler.setDependenciesHash(dependenciesHash); - noticeMetadataHandler.save(metadataFile); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/dependencies/DependenciesHasherTask.java b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/dependencies/DependenciesHasherTask.java deleted file mode 100644 index 73442ed62..000000000 --- a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/dependencies/DependenciesHasherTask.java +++ /dev/null @@ -1,54 +0,0 @@ -package co.elastic.otel.android.compilation.tools.tasks.dependencies; - -import org.gradle.api.artifacts.Configuration; -import org.gradle.api.artifacts.component.ComponentIdentifier; -import org.gradle.api.artifacts.result.ResolvedArtifactResult; -import org.gradle.api.file.RegularFileProperty; -import org.gradle.api.provider.ListProperty; -import org.gradle.api.tasks.InputFiles; -import org.gradle.api.tasks.OutputFile; -import org.gradle.api.tasks.TaskAction; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; - -import co.elastic.otel.android.compilation.tools.tasks.subprojects.BasePomTask; -import co.elastic.otel.android.compilation.tools.utils.TextUtils; - -/** - * Creates a hash out of the set of direct dependencies IDs for the host project, as an identifier - * for telling when there has been a change in the dependencies. - */ -public abstract class DependenciesHasherTask extends BasePomTask { - - @InputFiles - public abstract ListProperty getRuntimeDependencies(); - - @OutputFile - public abstract RegularFileProperty getOutputFile(); - - @TaskAction - public void execute() { - List componentIdentifiers = getComponentIdentifiers(getRuntimeDependencies().get()); - List artifacts = getPomArtifacts(componentIdentifiers); - List dependenciesUris = extractUrisAlphabeticallyOrdered(artifacts); - - TextUtils.writeText(getOutputFile().get().getAsFile(), createMd5Hash(dependenciesUris)); - } - - private String createMd5Hash(List dependenciesUris) { - String commaSeparatedDependenciesUris = String.join(",", dependenciesUris); - return TextUtils.hashMd5(commaSeparatedDependenciesUris); - } - - private List extractUrisAlphabeticallyOrdered(List artifacts) { - List uris = new ArrayList<>(); - for (ResolvedArtifactResult artifact : artifacts) { - uris.add(artifact.getId().getComponentIdentifier().getDisplayName().toLowerCase(Locale.US)); - } - Collections.sort(uris); - return uris; - } -} diff --git a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/dependencies/DependenciesVerifierTask.java b/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/dependencies/DependenciesVerifierTask.java deleted file mode 100644 index dfcdec12b..000000000 --- a/build-tools/src/main/java/co/elastic/otel/android/compilation/tools/tasks/dependencies/DependenciesVerifierTask.java +++ /dev/null @@ -1,51 +0,0 @@ -package co.elastic.otel.android.compilation.tools.tasks.dependencies; - -import static co.elastic.otel.android.compilation.tools.plugins.BaseNoticePlugin.TASK_CREATE_NOTICE_FILE_NAME; - -import org.apache.commons.io.FileUtils; -import org.gradle.api.DefaultTask; -import org.gradle.api.GradleException; -import org.gradle.api.file.RegularFileProperty; -import org.gradle.api.tasks.InputFile; -import org.gradle.api.tasks.TaskAction; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Objects; - -import co.elastic.otel.android.compilation.tools.metadata.NoticeMetadataHandler; - -/** - * Compares the last notice metadata's dependencies hash with the current hash and fails if they - * are different. - */ -public abstract class DependenciesVerifierTask extends DefaultTask { - - @InputFile - public abstract RegularFileProperty getDependenciesHashFile(); - - @TaskAction - public void execute() { - File dependencyHashFile = getDependenciesHashFile().get().getAsFile(); - File noticePropertiesFile = NoticeMetadataHandler.getMetadataFile(getProject()).getAsFile(); - if (!noticePropertiesFile.exists()) { - throw new GradleException("No NOTICE file has been created for this project, run the `" + TASK_CREATE_NOTICE_FILE_NAME + "` task to generate it."); - } - NoticeMetadataHandler noticeMetadataHandler = NoticeMetadataHandler.read(noticePropertiesFile); - String currentDependenciesHash = readDependenciesHash(dependencyHashFile); - String lastStoredDependenciesHash = noticeMetadataHandler.getDependenciesHash(); - - if (!Objects.equals(currentDependenciesHash, lastStoredDependenciesHash)) { - throw new GradleException("The NOTICE file is outdated, run the `" + TASK_CREATE_NOTICE_FILE_NAME + "` task to re-generate it."); - } - } - - private String readDependenciesHash(File dependencyHashFile) { - try { - return FileUtils.readFileToString(dependencyHashFile, StandardCharsets.UTF_8); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/instrumentation/api/metadata/notice.properties b/instrumentation/api/metadata/notice.properties deleted file mode 100644 index a54d4432e..000000000 --- a/instrumentation/api/metadata/notice.properties +++ /dev/null @@ -1 +0,0 @@ -dependencies.hash=ECBEC25CBD2F92D05A55D4F5C4B08BBA \ No newline at end of file diff --git a/instrumentation/okhttp/bytebuddy/metadata/notice.properties b/instrumentation/okhttp/bytebuddy/metadata/notice.properties deleted file mode 100644 index f42ada5fe..000000000 --- a/instrumentation/okhttp/bytebuddy/metadata/notice.properties +++ /dev/null @@ -1 +0,0 @@ -dependencies.hash=9B4D279E72F0A4ED0538FF46B4E1756B \ No newline at end of file diff --git a/instrumentation/okhttp/library/metadata/notice.properties b/instrumentation/okhttp/library/metadata/notice.properties deleted file mode 100644 index f73e06c7d..000000000 --- a/instrumentation/okhttp/library/metadata/notice.properties +++ /dev/null @@ -1 +0,0 @@ -dependencies.hash=805D2BFABA05EC84314836CD1E826A2C \ No newline at end of file diff --git a/instrumentation/okhttp/plugin/metadata/notice.properties b/instrumentation/okhttp/plugin/metadata/notice.properties deleted file mode 100644 index a54d4432e..000000000 --- a/instrumentation/okhttp/plugin/metadata/notice.properties +++ /dev/null @@ -1 +0,0 @@ -dependencies.hash=ECBEC25CBD2F92D05A55D4F5C4B08BBA \ No newline at end of file