diff --git a/custom-log4j-appender/build-jar.gradle b/custom-log4j-appender/build-jar.gradle new file mode 100644 index 0000000..106c280 --- /dev/null +++ b/custom-log4j-appender/build-jar.gradle @@ -0,0 +1,94 @@ +plugins { + id 'java' + id 'maven-publish' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'com.squareup.okhttp3:okhttp:4.9.3' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.1' + implementation 'org.apache.logging.log4j:log4j-core:2.14.1' + implementation 'org.apache.logging.log4j:log4j-api:2.14.1' +} + +jar { + manifest { + attributes( + 'Implementation-Title': 'Custom Log4j Appender', + 'Implementation-Vendor': 'New Relic Labs', + 'Implementation-Vendor-Id': 'com.newrelic.labs', + 'Implementation-Version': '1.0.2' + ) + } +} + + + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +task javadocJar(type: Jar) { + archiveClassifier.set('javadoc') + from javadoc +} + +task sourcesJar(type: Jar) { + archiveClassifier.set('sources') + from sourceSets.main.allSource +} + + + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java // Include standard JAR + + artifact javadocJar + artifact sourcesJar + + groupId = 'io.github.newrelic-experimental' + artifactId = 'custom-log4j-appender' + version = '1.0.2' + + pom { + name = 'Custom Log4j Appender' + description = 'A custom Log4j appender for New Relic.' + url = 'https://github.com/newrelic-experimental/newrelic-java-log4j-appender' + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'newrelic' + name = 'New Relic' + email = 'gsidhwani@newrelic.com' + } + } + scm { + connection = 'scm:git:git://github.com/newrelic-experimental/newrelic-java-log4j-appender.git' + developerConnection = 'scm:git:ssh://github.com/newrelic-experimental/newrelic-java-log4j-appender.git' + url = 'https://github.com/newrelic-experimental/newrelic-java-log4j-appender' + } + } + } + } + + repositories { + maven { + name = 'sonatype' + url = uri('https://oss.sonatype.org/service/local/staging/deploy/maven2/') + credentials { + username = project.findProperty("ossrhUsername") ?: "" + password = project.findProperty("ossrhPassword") ?: "" + } + } + } +} \ No newline at end of file diff --git a/custom-log4j-appender/build-shadowJar.gradle b/custom-log4j-appender/build-shadowJar.gradle new file mode 100644 index 0000000..7b40c3c --- /dev/null +++ b/custom-log4j-appender/build-shadowJar.gradle @@ -0,0 +1,91 @@ +plugins { + id 'java' + id 'com.github.johnrengelman.shadow' version '6.1.0' + id 'maven-publish' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'com.squareup.okhttp3:okhttp:4.9.3' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.1' + implementation 'org.apache.logging.log4j:log4j-core:2.14.1' + implementation 'org.apache.logging.log4j:log4j-api:2.14.1' +} + +jar { + enabled = false // Disable the standard JAR task +} + +shadowJar { + archiveClassifier.set('') // Remove the 'all' classifier + mergeServiceFiles() + manifest { + attributes 'Main-Class': 'com.newrelic.labs.logforwarder.MAIN' + } +} + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +task javadocJar(type: Jar) { + archiveClassifier.set('javadoc') + from javadoc +} + +task sourcesJar(type: Jar) { + archiveClassifier.set('sources') + from sourceSets.main.allSource +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifact shadowJar // Only include Shadow JAR + artifact javadocJar + artifact sourcesJar + + groupId = 'io.github.newrelic-experimental' + artifactId = 'custom-log4j-appender' + version = '1.0.0' + + pom { + name = 'Custom Log4j Appender' + description = 'A custom Log4j appender for New Relic Labs.' + url = 'https://github.com/newrelic-experimental/newrelic-java-log4j-appender' + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'newrelic' + name = 'New Relic' + email = 'info@newrelic.com' + } + } + scm { + connection = 'scm:git:git://github.com/newrelic-experimental/newrelic-java-log4j-appender.git' + developerConnection = 'scm:git:ssh://github.com/newrelic-experimental/newrelic-java-log4j-appender.git' + url = 'https://github.com/newrelic-experimental/newrelic-java-log4j-appender' + } + } + } + } + + repositories { + maven { + name = 'sonatype' + url = uri('https://oss.sonatype.org/service/local/staging/deploy/maven2/') + credentials { + username = project.findProperty("ossrhUsername") ?: "" + password = project.findProperty("ossrhPassword") ?: "" + } + } + } +} \ No newline at end of file diff --git a/custom-log4j-appender/build.gradle b/custom-log4j-appender/build.gradle index 707501f..106c280 100644 --- a/custom-log4j-appender/build.gradle +++ b/custom-log4j-appender/build.gradle @@ -25,6 +25,8 @@ jar { } } + + tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } diff --git a/custom-log4j-appender/publish-jar.sh b/custom-log4j-appender/publish-jar.sh index b414afd..ad57775 100755 --- a/custom-log4j-appender/publish-jar.sh +++ b/custom-log4j-appender/publish-jar.sh @@ -1,5 +1,9 @@ #!/bin/bash +# clean existing stuff +rm -rf build io +# copy correct build.gradle +cp build-jar.gradle build.gradle # Set variables GROUP_ID="io.github.newrelic-experimental" ARTIFACT_ID="custom-log4j-appender" diff --git a/custom-log4j-appender/publish_shadowJar.sh b/custom-log4j-appender/publish_shadowJar.sh deleted file mode 100755 index 51cbf32..0000000 --- a/custom-log4j-appender/publish_shadowJar.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash - -# Set variables -GROUP_ID="io.github.newrelic-experimental" -ARTIFACT_ID="custom-log4j-appender" -VERSION="1.0.0" -KEY_ID="0ED9FD74E81E6D83FAE25F235640EA0B1C631C6F" # Replace with your actual key ID - -# Get the current directory (assuming the script is run from the custom-log4j-appender directory) -CURRENT_DIR=$(pwd) -PROJECT_ROOT=$(dirname "$CURRENT_DIR") - -echo "Current Directory: $CURRENT_DIR" -echo "Project Root: $PROJECT_ROOT" - -# Clean and build the project -cd "$PROJECT_ROOT" -./gradlew clean build shadowJar javadocJar sourcesJar generatePomFileForMavenJavaPublication - -# Navigate to the directory containing the artifacts -cd "$CURRENT_DIR/build/libs" - -# List the contents of the build/libs directory for debugging -echo "Contents of build/libs:" -ls -la - -# Find the files without version numbers -JAR_FILE="custom-log4j-appender.jar" -JAVADOC_FILE="custom-log4j-appender-javadoc.jar" -SOURCES_FILE="custom-log4j-appender-sources.jar" -POM_FILE="custom-log4j-appender-$VERSION.pom" - -echo "JAR File: $JAR_FILE" -echo "Javadoc File: $JAVADOC_FILE" -echo "Sources File: $SOURCES_FILE" -echo "POM File: $POM_FILE" - -# Check if the files exist before proceeding -if [ ! -f "$JAR_FILE" ] || [ ! -f "$JAVADOC_FILE" ] || [ ! -f "$SOURCES_FILE" ]; then - echo "One or more expected files are missing in build/libs" - ls -la - exit 1 -fi - -# Prepare the directory structure -TARGET_DIR="$CURRENT_DIR/io/github/newrelic-experimental/custom-log4j-appender/$VERSION" -mkdir -p $TARGET_DIR - -# Copy the built artifacts to the appropriate directory with version numbers -echo "Copying artifacts to $TARGET_DIR" -cp $JAR_FILE $TARGET_DIR/custom-log4j-appender-$VERSION.jar -cp $JAVADOC_FILE $TARGET_DIR/custom-log4j-appender-$VERSION-javadoc.jar -cp $SOURCES_FILE $TARGET_DIR/custom-log4j-appender-$VERSION-sources.jar - -# Navigate to the target directory -cd $TARGET_DIR - -# Generate checksums for the copied files -for file in custom-log4j-appender-$VERSION.jar custom-log4j-appender-$VERSION-javadoc.jar custom-log4j-appender-$VERSION-sources.jar; do - echo "Generating checksums for $file" - md5sum $file | awk '{ print $1 }' > $file.md5 - sha1sum $file | awk '{ print $1 }' > $file.sha1 -done - -# Generate GPG signatures using the specific key ID -for file in custom-log4j-appender-$VERSION.jar custom-log4j-appender-$VERSION-javadoc.jar custom-log4j-appender-$VERSION-sources.jar; do - echo "Generating GPG signature for $file" - gpg --local-user $KEY_ID --armor --detach-sign $file -done - -# Generate and copy the POM file -cd "$PROJECT_ROOT" -./gradlew generatePomFileForMavenJavaPublication -cp custom-log4j-appender/build/publications/mavenJava/pom-default.xml $TARGET_DIR/$POM_FILE - -# Navigate back to the target directory -cd $TARGET_DIR - -# Generate checksums and signatures for the POM file -echo "Generating checksums and GPG signature for $POM_FILE" -md5sum $POM_FILE | awk '{ print $1 }' > $POM_FILE.md5 -sha1sum $POM_FILE | awk '{ print $1 }' > $POM_FILE.sha1 -gpg --local-user $KEY_ID --armor --detach-sign $POM_FILE - -# Verify checksums -echo "Verifying checksums" -for file in custom-log4j-appender-$VERSION.jar custom-log4j-appender-$VERSION-javadoc.jar custom-log4j-appender-$VERSION-sources.jar $POM_FILE; do - if [ -f "$file" ]; then - echo "Verifying checksum for $file" - md5sum -c <(echo "$(cat $file.md5) $file") - sha1sum -c <(echo "$(cat $file.sha1) $file") - else - echo "File $file does not exist in the target directory $TARGET_DIR." - ls -la $TARGET_DIR - fi -done - -# Navigate back to the custom-log4j-appender directory -cd "$CURRENT_DIR" - -# Create a ZIP file containing the entire directory structure -echo "Creating ZIP file custom-log4j-appender-$VERSION.zip" -zip -r custom-log4j-appender-$VERSION.zip io - -echo "Artifacts prepared and zipped successfully. You can now upload custom-log4j-appender-$VERSION.zip to Sonatype OSSRH."