diff --git a/src/main/java/com/github/os72/protocjar/Protoc.java b/src/main/java/com/github/os72/protocjar/Protoc.java index 754a674..a2b55f9 100644 --- a/src/main/java/com/github/os72/protocjar/Protoc.java +++ b/src/main/java/com/github/os72/protocjar/Protoc.java @@ -149,8 +149,7 @@ else if (file.getName().endsWith(".java")) { FileInputStream is = null; FileOutputStream os = null; try { - if (version.length() <= 5) version = version.replace(".", ""); // "1.2.3" -> "123" - else version = "_" + version.replace(".", "_"); // "3.11.1" -> "_3_11_1" + version = javaShadingVersion(version); tmpFile = File.createTempFile(file.getName(), null); pw = new PrintWriter(tmpFile); br = new BufferedReader(new FileReader(file)); @@ -177,6 +176,16 @@ else if (file.getName().endsWith(".java")) { } } + static String javaShadingVersion(String version) { + if (!version.contains(".")) { + return version; + } else if (version.length() <= 5) { + return version.replace(".", ""); // "1.2.3" -> "123" + } else { + return "_" + version.replace(".", "_"); + } + } + public static File extractProtoc(ProtocVersion protocVersion, boolean includeStdTypes) throws IOException { return extractProtoc(protocVersion, includeStdTypes, null); } diff --git a/src/test/java/com/github/os72/protocjar/ProtocTest.java b/src/test/java/com/github/os72/protocjar/ProtocTest.java index 77feb12..b17eddd 100644 --- a/src/test/java/com/github/os72/protocjar/ProtocTest.java +++ b/src/test/java/com/github/os72/protocjar/ProtocTest.java @@ -15,10 +15,10 @@ */ package com.github.os72.protocjar; -import java.io.File; - import org.junit.Test; +import java.io.File; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -100,6 +100,15 @@ public void testRunProtocCompile() throws Exception { } } + @Test + public void testJavaShadingVersion() { + log("testJavaShadingVersion"); + assertEquals("123", Protoc.javaShadingVersion("1.2.3")); + assertEquals("123", Protoc.javaShadingVersion("123")); + assertEquals("_3_11_1", Protoc.javaShadingVersion("3.11.1")); + assertEquals("_3_11_1", Protoc.javaShadingVersion("_3_11_1")); + } + @Test public void testRunProtocCompileShade() throws Exception { log("testRunProtocCompileShade");