diff --git a/.ci.settings.xml b/.ci.settings.xml new file mode 100644 index 000000000..67264bf28 --- /dev/null +++ b/.ci.settings.xml @@ -0,0 +1,11 @@ + + + + + ossrh + ${env.SONATYPE_USERNAME} + ${env.SONATYPE_PASSWORD} + + + + diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml new file mode 100644 index 000000000..3534e0140 --- /dev/null +++ b/.github/workflows/ci-build.yml @@ -0,0 +1,36 @@ +name: 'CI Build' + +on: + workflow_dispatch: + push: + branches: + - master + pull_request: + types: [ opened, reopened, edited ] + branches: + - master + +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: false + +jobs: + compile-and-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Java and Maven + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '8' + cache: 'maven' + cache-dependency-path: 'pom.xml' + + - name: Compile + run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V + + - name: Run tests + run: mvn test -B diff --git a/.github/workflows/ci-publish.yml b/.github/workflows/ci-publish.yml new file mode 100644 index 000000000..19e58fa0e --- /dev/null +++ b/.github/workflows/ci-publish.yml @@ -0,0 +1,44 @@ +name: 'CI Publish to Maven Central' + +on: + workflow_dispatch: + push: + tags: + - 'release/*' + +concurrency: + group: '${{ github.workflow }} @ ${{ github.head_ref || github.ref }}' + cancel-in-progress: false + +jobs: + compile-test-and-publish-to-maven-central: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Java and Maven + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '8' + cache: 'maven' + cache-dependency-path: 'pom.xml' + + - name: Compile + run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V + + - name: Run tests + run: mvn test -B + + - name: Copy publishing-config settings.xml into place + run: cp .ci.settings.xml $HOME/.m2/settings.xml + + - name: Publish to Maven Central + run: ./publish.sh + env: + SONATYPE_GPGKEY_FILE_ENCRYPTION_KEY: ${{ secrets.SONATYPE_GPGKEY_FILE_ENCRYPTION_KEY }} + SONATYPE_GPGKEY_FILE_ENCRYPTION_IV: ${{ secrets.SONATYPE_GPGKEY_FILE_ENCRYPTION_IV }} + SONATYPE_GPGKEY_PASSPHRASE: ${{ secrets.SONATYPE_GPGKEY_PASSPHRASE }} + SONATYPE_USERNAME: ${{ vars.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index fdb69aaab..000000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,36 +0,0 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - java: ['7', '8', '11', '17', '18'] - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 7 - if: ${{ matrix.java == '7'}} - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.java }} - - name: Set up JDK - if: ${{ matrix.java != '7'}} - uses: actions/setup-java@v3 - with: - java-version: ${{ matrix.java }} - distribution: temurin - cache: maven - - name: Build with Maven - run: mvn -B package -Dgpg.skip=true --file pom.xml diff --git a/.gitignore b/.gitignore index 6e30df54e..cf3a5c865 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ build .DS_Store .gradle +/metadata-extractor.iml diff --git a/Source/com/drew/imaging/ImageMetadataReader.java b/Source/com/drew/imaging/ImageMetadataReader.java index 474300950..7bdcd1098 100644 --- a/Source/com/drew/imaging/ImageMetadataReader.java +++ b/Source/com/drew/imaging/ImageMetadataReader.java @@ -115,17 +115,19 @@ public static Metadata readMetadata(@NotNull final InputStream inputStream) thro @NotNull public static Metadata readMetadata(@NotNull final InputStream inputStream, final long streamLength) throws ImageProcessingException, IOException { - BufferedInputStream bufferedInputStream = inputStream instanceof BufferedInputStream - ? (BufferedInputStream)inputStream - : new BufferedInputStream(inputStream); + try (BufferedInputStream bufferedInputStream = inputStream instanceof BufferedInputStream + ? (BufferedInputStream)inputStream : new BufferedInputStream(inputStream)) { - FileType fileType = FileTypeDetector.detectFileType(bufferedInputStream); + FileType fileType = FileTypeDetector.detectFileType(bufferedInputStream); - Metadata metadata = readMetadata(bufferedInputStream, streamLength, fileType); + Metadata metadata = readMetadata(bufferedInputStream, streamLength, fileType); - metadata.addDirectory(new FileTypeDirectory(fileType)); + metadata.addDirectory(new FileTypeDirectory(fileType)); + + return metadata; + + } - return metadata; } /** diff --git a/Source/com/drew/imaging/png/PngMetadataReader.java b/Source/com/drew/imaging/png/PngMetadataReader.java index c2dd8b9e9..e283ec90a 100644 --- a/Source/com/drew/imaging/png/PngMetadataReader.java +++ b/Source/com/drew/imaging/png/PngMetadataReader.java @@ -177,10 +177,9 @@ private static void processChunk(@NotNull Metadata metadata, @NotNull PngChunk c int bytesLeft = bytes.length - (profileNameBytes.length + 1 + 1); byte[] compressedProfile = reader.getBytes(bytesLeft); - try { - InflaterInputStream inflateStream = new InflaterInputStream(new ByteArrayInputStream(compressedProfile)); + try (ByteArrayInputStream bais = new ByteArrayInputStream(compressedProfile); + InflaterInputStream inflateStream = new InflaterInputStream(bais)) { new IccReader().extract(new RandomAccessStreamReader(inflateStream), metadata, directory); - inflateStream.close(); } catch(java.util.zip.ZipException zex) { directory.addError(String.format("Exception decompressing PNG iCCP chunk : %s", zex.getMessage())); metadata.addDirectory(directory); @@ -222,8 +221,9 @@ private static void processChunk(@NotNull Metadata metadata, @NotNull PngChunk c int bytesLeft = bytes.length - (keywordsv.getBytes().length + 1 + 1); byte[] textBytes = null; if (compressionMethod == 0) { - try { - textBytes = StreamUtil.readAllBytes(new InflaterInputStream(new ByteArrayInputStream(bytes, bytes.length - bytesLeft, bytesLeft))); + try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes, bytes.length - bytesLeft, bytesLeft); + InflaterInputStream inflateStream = new InflaterInputStream(bais)) { + textBytes = StreamUtil.readAllBytes(inflateStream); } catch(java.util.zip.ZipException zex) { PngDirectory directory = new PngDirectory(PngChunkType.zTXt); directory.addError(String.format("Exception decompressing PNG zTXt chunk with keyword \"%s\": %s", keyword, zex.getMessage())); @@ -266,8 +266,9 @@ private static void processChunk(@NotNull Metadata metadata, @NotNull PngChunk c textBytes = reader.getNullTerminatedBytes(bytesLeft, false); } else if (compressionFlag == 1) { if (compressionMethod == 0) { - try { - textBytes = StreamUtil.readAllBytes(new InflaterInputStream(new ByteArrayInputStream(bytes, bytes.length - bytesLeft, bytesLeft))); + try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes, bytes.length - bytesLeft, bytesLeft); + InflaterInputStream inflateStream = new InflaterInputStream(bais)) { + textBytes = StreamUtil.readAllBytes(inflateStream); } catch(java.util.zip.ZipException zex) { PngDirectory directory = new PngDirectory(PngChunkType.iTXt); directory.addError(String.format("Exception decompressing PNG iTXt chunk with keyword \"%s\": %s", keyword, zex.getMessage())); diff --git a/Source/com/drew/lang/StreamUtil.java b/Source/com/drew/lang/StreamUtil.java index 341b54b6e..38b7c875d 100644 --- a/Source/com/drew/lang/StreamUtil.java +++ b/Source/com/drew/lang/StreamUtil.java @@ -31,16 +31,17 @@ public final class StreamUtil { public static byte[] readAllBytes(InputStream stream) throws IOException { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + byte[] buffer = new byte[1024]; + while (true) { + int bytesRead = stream.read(buffer); + if (bytesRead == -1) + break; + outputStream.write(buffer, 0, bytesRead); + } - byte[] buffer = new byte[1024]; - while (true) { - int bytesRead = stream.read(buffer); - if (bytesRead == -1) - break; - outputStream.write(buffer, 0, bytesRead); + return outputStream.toByteArray(); } - return outputStream.toByteArray(); } } diff --git a/Source/com/drew/lang/StringUtil.java b/Source/com/drew/lang/StringUtil.java index 586d9ce86..be04906ec 100644 --- a/Source/com/drew/lang/StringUtil.java +++ b/Source/com/drew/lang/StringUtil.java @@ -81,15 +81,18 @@ public static String join(@NotNull T[] strings, @NotNul @NotNull public static String fromStream(@NotNull InputStream stream) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - sb.append(line); + try (InputStreamReader inputStreamReader = new InputStreamReader(stream); + BufferedReader reader = new BufferedReader(inputStreamReader)) { + StringBuilder sb = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + return sb.toString(); } - return sb.toString(); } + public static int compare(@Nullable String s1, @Nullable String s2) { boolean null1 = s1 == null; diff --git a/Source/com/drew/metadata/eps/EpsReader.java b/Source/com/drew/metadata/eps/EpsReader.java index 24d8233c5..1e616b7a5 100644 --- a/Source/com/drew/metadata/eps/EpsReader.java +++ b/Source/com/drew/metadata/eps/EpsReader.java @@ -264,21 +264,22 @@ private static void extractXmpData(@NotNull final Metadata metadata, @NotNull Se */ private static byte[] readUntil(@NotNull SequentialReader reader, @NotNull byte[] sentinel) throws IOException { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - - final int length = sentinel.length; - int depth = 0; - - while (depth != length) { - byte b = reader.getByte(); - if (b == sentinel[depth]) - depth++; - else - depth = 0; - bytes.write(b); + try (ByteArrayOutputStream bytes = new ByteArrayOutputStream()) { + final int length = sentinel.length; + int depth = 0; + + while (depth != length) { + byte b = reader.getByte(); + if (b == sentinel[depth]) + depth++; + else + depth = 0; + bytes.write(b); + } + + return bytes.toByteArray(); } - return bytes.toByteArray(); } /** @@ -303,48 +304,48 @@ private static byte[] readUntil(@NotNull SequentialReader reader, @NotNull byte[ @Nullable private static byte[] decodeHexCommentBlock(@NotNull SequentialReader reader) throws IOException { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + try (ByteArrayOutputStream bytes = new ByteArrayOutputStream()) { - // Use a state machine to efficiently parse data in a single traversal + // Use a state machine to efficiently parse data in a single traversal - final int AwaitingPercent = 0; - final int AwaitingSpace = 1; - final int AwaitingHex1 = 2; - final int AwaitingHex2 = 3; + final int AwaitingPercent = 0; + final int AwaitingSpace = 1; + final int AwaitingHex1 = 2; + final int AwaitingHex2 = 3; - int state = AwaitingPercent; + int state = AwaitingPercent; - int carry = 0; - boolean done = false; + int carry = 0; + boolean done = false; - byte b = 0; - while (!done) { - b = reader.getByte(); + byte b = 0; + while (!done) { + b = reader.getByte(); - switch (state) { + switch (state) { case AwaitingPercent: { switch (b) { - case '\r': - case '\n': - case ' ': - // skip newline chars and spaces - break; - case '%': - state = AwaitingSpace; - break; - default: - return null; + case '\r': + case '\n': + case ' ': + // skip newline chars and spaces + break; + case '%': + state = AwaitingSpace; + break; + default: + return null; } break; } case AwaitingSpace: { switch (b) { - case ' ': - state = AwaitingHex1; - break; - default: - done = true; - break; + case ' ': + state = AwaitingHex1; + break; + default: + done = true; + break; } break; } @@ -368,14 +369,17 @@ private static byte[] decodeHexCommentBlock(@NotNull SequentialReader reader) th state = AwaitingHex1; break; } + } } - } - // skip through the remainder of the last line - while (b != '\n') - b = reader.getByte(); + // skip through the remainder of the last line + while (b != '\n') + b = reader.getByte(); + + return bytes.toByteArray(); + + } - return bytes.toByteArray(); } /** diff --git a/Source/com/drew/metadata/exif/ExifTiffHandler.java b/Source/com/drew/metadata/exif/ExifTiffHandler.java index 6189588f6..5bfc1e3e0 100644 --- a/Source/com/drew/metadata/exif/ExifTiffHandler.java +++ b/Source/com/drew/metadata/exif/ExifTiffHandler.java @@ -320,14 +320,15 @@ public boolean customProcessTag(final int tagOffset, byte[] jpegrawbytes = reader.getBytes(tagOffset, byteCount); // Extract information from embedded image since it is metadata-rich - ByteArrayInputStream jpegmem = new ByteArrayInputStream(jpegrawbytes); - try { + try (ByteArrayInputStream jpegmem = new ByteArrayInputStream(jpegrawbytes)) { + Metadata jpegDirectory = JpegMetadataReader.readMetadata(jpegmem); for (Directory directory : jpegDirectory.getDirectories()) { directory.setParent(_currentDirectory); _metadata.addDirectory(directory); } return true; + } catch (JpegProcessingException e) { _currentDirectory.addError("Error processing JpgFromRaw: " + e.getMessage()); } catch (IOException e) { diff --git a/Source/com/drew/metadata/gif/GifReader.java b/Source/com/drew/metadata/gif/GifReader.java index 32a1e8e74..1a6112e2a 100644 --- a/Source/com/drew/metadata/gif/GifReader.java +++ b/Source/com/drew/metadata/gif/GifReader.java @@ -356,37 +356,39 @@ private static GifImageDirectory readImageBlock(SequentialReader reader) throws private static byte[] gatherBytes(SequentialReader reader) throws IOException { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - byte[] buffer = new byte[257]; + try (ByteArrayOutputStream bytes = new ByteArrayOutputStream()) { + byte[] buffer = new byte[257]; - while (true) - { - byte b = reader.getByte(); - if (b == 0) - return bytes.toByteArray(); + while (true) + { + byte b = reader.getByte(); + if (b == 0) + return bytes.toByteArray(); - int bInt = b & 0xFF; + int bInt = b & 0xFF; - buffer[0] = b; - reader.getBytes(buffer, 1, bInt); - bytes.write(buffer, 0, bInt + 1); + buffer[0] = b; + reader.getBytes(buffer, 1, bInt); + bytes.write(buffer, 0, bInt + 1); + } } } private static byte[] gatherBytes(SequentialReader reader, int firstLength) throws IOException { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) { + int length = firstLength; - int length = firstLength; + while (length > 0) + { + buffer.write(reader.getBytes(length), 0, length); - while (length > 0) - { - buffer.write(reader.getBytes(length), 0, length); + length = reader.getByte() & 0xff; + } - length = reader.getByte() & 0xff; + return buffer.toByteArray(); } - return buffer.toByteArray(); } private static void skipBlocks(SequentialReader reader) throws IOException diff --git a/Source/com/drew/metadata/heif/HeifPictureHandler.java b/Source/com/drew/metadata/heif/HeifPictureHandler.java index 088a9d636..5f9ff8650 100644 --- a/Source/com/drew/metadata/heif/HeifPictureHandler.java +++ b/Source/com/drew/metadata/heif/HeifPictureHandler.java @@ -150,8 +150,9 @@ private void handleItem(@NotNull ItemInfoBox.ItemInfoEntry entry, return; } payloadReader.skip(tiffHeaderOffset); - ByteArrayInputStream tiffStream = new ByteArrayInputStream(payloadReader.getBytes(payloadReader.available())); - new ExifReader().extract(new RandomAccessStreamReader(tiffStream), metadata); + try (ByteArrayInputStream tiffStream = new ByteArrayInputStream(payloadReader.getBytes(payloadReader.available()))) { + new ExifReader().extract(new RandomAccessStreamReader(tiffStream), metadata); + } } } diff --git a/Source/com/drew/tools/ProcessAllImagesInFolderUtility.java b/Source/com/drew/tools/ProcessAllImagesInFolderUtility.java index b9327b82b..49e44aba1 100644 --- a/Source/com/drew/tools/ProcessAllImagesInFolderUtility.java +++ b/Source/com/drew/tools/ProcessAllImagesInFolderUtility.java @@ -42,6 +42,7 @@ import com.drew.metadata.xmp.XmpDirectory; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; /** @@ -75,7 +76,11 @@ public static void main(String[] args) throws IOException printUsage(); System.exit(1); } - log = new PrintStream(new FileOutputStream(args[++i], false), true); + + try (FileOutputStream fos = new FileOutputStream(args[++i], false)) { + log = new PrintStream(fos , true); + } + } else { // Treat this argument as a directory directories.add(arg); @@ -492,26 +497,19 @@ private static PrintWriter openWriter(@NotNull File file) throws IOException javaDir.mkdir(); String outputPath = String.format("%s/metadata/java/%s.txt", file.getParent(), file.getName()); - Writer writer = new OutputStreamWriter( - new FileOutputStream(outputPath), - "UTF-8" - ); - writer.write("FILE: " + file.getName() + NEW_LINE); - - // Detect file type - BufferedInputStream stream = null; - try { - stream = new BufferedInputStream(new FileInputStream(file)); + try (FileOutputStream fos = new FileOutputStream(outputPath); + Writer writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8); + FileInputStream fis =new FileInputStream(file); + BufferedInputStream stream = new BufferedInputStream(fis)) { + writer.write("FILE: " + file.getName() + NEW_LINE); + FileType fileType = FileTypeDetector.detectFileType(stream); writer.write(String.format("TYPE: %s" + NEW_LINE, fileType.toString().toUpperCase())); writer.write(NEW_LINE); - } finally { - if (stream != null) { - stream.close(); - } + + return new PrintWriter(writer); } - return new PrintWriter(writer); } private static void closeWriter(@Nullable Writer writer) throws IOException @@ -638,46 +636,49 @@ public void onScanCompleted(@NotNull PrintStream log) private void writeOutput(@NotNull PrintStream stream) throws IOException { - Writer writer = new OutputStreamWriter(stream); - writer.write("# Image Database Summary\n\n"); + try (Writer writer = new OutputStreamWriter(stream)) { - for (Map.Entry> entry : _rowListByExtension.entrySet()) { - String extension = entry.getKey(); - writer.write("## " + extension.toUpperCase() + " Files\n\n"); + writer.write("# Image Database Summary\n\n"); - writer.write("File|Manufacturer|Model|Dir Count|Exif?|Makernote|Thumbnail|All Data\n"); - writer.write("----|------------|-----|---------|-----|---------|---------|--------\n"); + for (Map.Entry> entry : _rowListByExtension.entrySet()) { + String extension = entry.getKey(); + writer.write("## " + extension.toUpperCase() + " Files\n\n"); - List rows = entry.getValue(); + writer.write("File|Manufacturer|Model|Dir Count|Exif?|Makernote|Thumbnail|All Data\n"); + writer.write("----|------------|-----|---------|-----|---------|---------|--------\n"); - // Order by manufacturer, then model - Collections.sort(rows, new Comparator() { - public int compare(Row o1, Row o2) - { - int c1 = StringUtil.compare(o1.manufacturer, o2.manufacturer); - return c1 != 0 ? c1 : StringUtil.compare(o1.model, o2.model); + List rows = entry.getValue(); + + // Order by manufacturer, then model + Collections.sort(rows, new Comparator() { + public int compare(Row o1, Row o2) + { + int c1 = StringUtil.compare(o1.manufacturer, o2.manufacturer); + return c1 != 0 ? c1 : StringUtil.compare(o1.model, o2.model); + } + }); + + for (Row row : rows) { + writer.write(String.format("[%s](https://raw.githubusercontent.com/drewnoakes/metadata-extractor-images/master/%s/%s)|%s|%s|%d|%s|%s|%s|[metadata](https://raw.githubusercontent.com/drewnoakes/metadata-extractor-images/master/%s/metadata/%s.txt)\n", + row.file.getName(), + row.relativePath, + StringUtil.urlEncode(row.file.getName()), + row.manufacturer == null ? "" : row.manufacturer, + row.model == null ? "" : row.model, + row.metadata.getDirectoryCount(), + row.exifVersion == null ? "" : row.exifVersion, + row.makernote == null ? "" : row.makernote, + row.thumbnail == null ? "" : row.thumbnail, + row.relativePath, + StringUtil.urlEncode(row.file.getName()).toLowerCase() + )); } - }); - for (Row row : rows) { - writer.write(String.format("[%s](https://raw.githubusercontent.com/drewnoakes/metadata-extractor-images/master/%s/%s)|%s|%s|%d|%s|%s|%s|[metadata](https://raw.githubusercontent.com/drewnoakes/metadata-extractor-images/master/%s/metadata/%s.txt)\n", - row.file.getName(), - row.relativePath, - StringUtil.urlEncode(row.file.getName()), - row.manufacturer == null ? "" : row.manufacturer, - row.model == null ? "" : row.model, - row.metadata.getDirectoryCount(), - row.exifVersion == null ? "" : row.exifVersion, - row.makernote == null ? "" : row.makernote, - row.thumbnail == null ? "" : row.thumbnail, - row.relativePath, - StringUtil.urlEncode(row.file.getName()).toLowerCase() - )); + writer.write('\n'); } + writer.flush(); - writer.write('\n'); } - writer.flush(); } } diff --git a/Tests/com/drew/lang/CompoundExceptionTest.java b/Tests/com/drew/lang/CompoundExceptionTest.java index f836d1767..3590178c9 100644 --- a/Tests/com/drew/lang/CompoundExceptionTest.java +++ b/Tests/com/drew/lang/CompoundExceptionTest.java @@ -68,10 +68,11 @@ public void testNoInnerException() throws Exception try { throw new CompoundException("message", null); } catch (CompoundException e) { - try { - PrintStream nullStream = new PrintStream(new NullOutputStream()); + try (NullOutputStream nullOutputStream = new NullOutputStream(); + PrintStream nullStream = new PrintStream(nullOutputStream); + PrintWriter printWriter = new PrintWriter(nullStream)) { e.printStackTrace(nullStream); - e.printStackTrace(new PrintWriter(nullStream)); + e.printStackTrace(printWriter); } catch (Exception e1) { fail("Exception during printStackTrace for CompoundException with no inner exception"); } diff --git a/metadata-extractor.iml b/metadata-extractor.iml deleted file mode 100644 index 64d8d9cca..000000000 --- a/metadata-extractor.iml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index d1d171aed..0d744a51c 100644 --- a/pom.xml +++ b/pom.xml @@ -12,9 +12,9 @@ 7 - com.drewnoakes + com.github.dalet-oss metadata-extractor - 2.19.0 + ${revision} jar ${project.groupId}:${project.artifactId} @@ -47,9 +47,9 @@ - scm:git:git://github.com/drewnoakes/metadata-extractor.git - scm:git:git@github.com:drewnoakes/metadata-extractor.git - https://github.com/drewnoakes/metadata-extractor + scm:git:git://github.com/dalet-oss/metadata-extractor.git + scm:git:git@github.com:dalet-oss/metadata-extractor.git + https://github.com/dalet-oss/metadata-extractor @@ -61,6 +61,12 @@ + 1.8 + 1.8 + + false + + DEV UTF-8 @@ -88,6 +94,83 @@ -Xdoclint:none + + release + + + + org.codehaus.mojo + flatten-maven-plugin + 1.5.0 + + true + resolveCiFriendliesOnly + + + + flatten.clean + clean + + clean + + + + flatten + process-resources + + flatten + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.6.3 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.1.0 + + + sign-artifacts + verify + + sign + + + true + + --pinentry-mode + loopback + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + + @@ -178,40 +261,14 @@ - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - - false - - - + ossrh - https://oss.sonatype.org/content/repositories/snapshots - + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + diff --git a/publish.sh b/publish.sh new file mode 100755 index 000000000..f459f3cf5 --- /dev/null +++ b/publish.sh @@ -0,0 +1,50 @@ +echo 'Determining version number for publication' +echo 'Looking for an existing release tag against this commit' + +VERSION=$(git describe --tags --match release/* --exact-match 2>&1) +if [ $? -ne 0 ] +then + LAST=$(git describe --tags --match release/* 2>&1) + if [ $? -ne 0 ] + then + echo 'No release tags found at all; bail out' + exit 1 + fi + + echo "No matching tag found. Push a tag like release/1.0.1 against HEAD in order to release. Most recent tag is: ${LAST}" + exit 0 +fi + +VERSION=$(echo $VERSION | sed 's#release/##g') +echo "Publishing version: ${VERSION}" + +status=$(curl -s --head -w %{http_code} -o /dev/null https://repo1.maven.org/maven2/com/github/dalet-oss/arangobee/${VERSION}/) +if [ $status -eq 200 ] +then + echo 'Version already available on Maven Central. This must be a rebuild; nothing to do here.' +else + echo 'Version not already available on Maven Central' + + # Decrypt the gpg key used for signing + echo 'Decrypting the GPG key used for signing' + openssl aes-256-cbc -K ${SONATYPE_GPGKEY_FILE_ENCRYPTION_KEY} -iv ${SONATYPE_GPGKEY_FILE_ENCRYPTION_IV} -in secret.gpg.enc -out secret.gpg -d + export GPG_TTY=$(tty) + if [ ! -f secret.gpg ] + then + echo 'Decryption failed; bail out' + exit 1 + fi + echo 'Decryption successful' + + # Work around some nonsense on the specific version of GPG that comes with Ubuntu - see https://www.fluidkeys.com/tweak-gpg-2.1.11/ + echo 'allow-loopback-pinentry' >> ~/.gnupg/gpg-agent.conf + gpgconf --reload gpg-agent + + # Add the key into gpg; then sign something random to get the key into the gpg-agent + echo ${SONATYPE_GPGKEY_PASSPHRASE} | gpg2 --passphrase-fd 0 --batch --yes --import secret.gpg + touch /tmp/foo.txt + gpg2 --pinentry-mode=loopback --passphrase ${SONATYPE_GPGKEY_PASSPHRASE} --sign /tmp/foo.txt + + # Build, sign and publish the artifacts + mvn -Prelease deploy -DskipTests -Drevision=${VERSION} -Dgpg.executable=gpg2 -Dgpgkey.passphrase=${SONATYPE_GPGKEY_PASSPHRASE} +fi diff --git a/secret.gpg.enc b/secret.gpg.enc new file mode 100644 index 000000000..fd1c131a3 Binary files /dev/null and b/secret.gpg.enc differ