Skip to content

Commit

Permalink
Merge pull request os72#79 from adamkennedy/java-shading-fix
Browse files Browse the repository at this point in the history
Fix for broken multi-file shading with protoc 3.11.1
  • Loading branch information
os72 authored Feb 29, 2020
2 parents cfbfad2 + 0a06c25 commit ba8ceea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/main/java/com/github/os72/protocjar/Protoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}
Expand Down
13 changes: 11 additions & 2 deletions src/test/java/com/github/os72/protocjar/ProtocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit ba8ceea

Please sign in to comment.