diff --git a/org.jacoco.agent.rt.test/src/org/jacoco/agent/rt/internal/CoverageTransformerTest.java b/org.jacoco.agent.rt.test/src/org/jacoco/agent/rt/internal/CoverageTransformerTest.java index f615cfb184..a16e70dbac 100644 --- a/org.jacoco.agent.rt.test/src/org/jacoco/agent/rt/internal/CoverageTransformerTest.java +++ b/org.jacoco.agent.rt.test/src/org/jacoco/agent/rt/internal/CoverageTransformerTest.java @@ -215,11 +215,15 @@ public void testTransformFailure() { protectionDomain, null); fail("IllegalClassFormatException expected."); } catch (IllegalClassFormatException e) { - assertEquals("Error while instrumenting org.jacoco.Sample.", + assertEquals(String.format( + "Error while instrumenting %s with JaCoCo %s/%s.", + "org.jacoco.Sample", JaCoCo.VERSION, JaCoCo.COMMITID_SHORT), e.getMessage()); } recorder.assertException(IllegalClassFormatException.class, - "Error while instrumenting org.jacoco.Sample.", + String.format("Error while instrumenting %s with JaCoCo %s/%s.", + "org.jacoco.Sample", JaCoCo.VERSION, + JaCoCo.COMMITID_SHORT), IOException.class); recorder.clear(); } diff --git a/org.jacoco.core.test/src/org/jacoco/core/JaCoCoTest.java b/org.jacoco.core.test/src/org/jacoco/core/JaCoCoTest.java index 824788a79b..5aa1cd1d26 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/JaCoCoTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/JaCoCoTest.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.jacoco.core; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; @@ -26,6 +27,16 @@ public void testVERSION() { assertNotNull(JaCoCo.VERSION); } + @Test + public void testCOMMITID() { + assertNotNull(JaCoCo.COMMITID); + } + + @Test + public void testCOMMITID_SHORT() { + assertEquals(7, JaCoCo.COMMITID_SHORT.length()); + } + @Test public void testHOMEURL() { assertNotNull(JaCoCo.HOMEURL); diff --git a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java index 9b5c58eeed..c617cdc49e 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java @@ -36,6 +36,7 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; +import org.jacoco.core.JaCoCo; import org.jacoco.core.data.ExecutionDataStore; import org.jacoco.core.internal.Pack200Streams; import org.jacoco.core.internal.data.CRC64; @@ -136,8 +137,7 @@ public void analyzeClass_should_throw_exception_for_unsupported_class_file_versi analyzer.analyzeClass(bytes, "UnsupportedVersion"); fail("exception expected"); } catch (IOException e) { - assertEquals("Error while analyzing UnsupportedVersion.", - e.getMessage()); + assertExceptionMessage("UnsupportedVersion", e); assertEquals("Unsupported class file major version 64", e.getCause().getMessage()); } @@ -164,7 +164,7 @@ public void testAnalyzeClassIdMatch() throws IOException { final byte[] bytes = TargetLoader .getClassDataAsBytes(AnalyzerTest.class); executionData.get(Long.valueOf(CRC64.classId(bytes)), - "org/jacoco/core/analysis/AnalyzerTest", 200); + "org/jacoco/core/analysis/AnalyzerTest", 400); analyzer.analyzeClass(bytes, "Test"); assertFalse(classes.get("org/jacoco/core/analysis/AnalyzerTest") .isNoMatch()); @@ -173,7 +173,7 @@ public void testAnalyzeClassIdMatch() throws IOException { @Test public void testAnalyzeClassNoIdMatch() throws IOException { executionData.get(Long.valueOf(0), - "org/jacoco/core/analysis/AnalyzerTest", 200); + "org/jacoco/core/analysis/AnalyzerTest", 400); analyzer.analyzeClass( TargetLoader.getClassDataAsBytes(AnalyzerTest.class), "Test"); assertTrue(classes.get("org/jacoco/core/analysis/AnalyzerTest") @@ -189,7 +189,7 @@ public void testAnalyzeClass_Broken() throws IOException { analyzer.analyzeClass(brokenclass, "Broken.class"); fail("expected exception"); } catch (IOException e) { - assertEquals("Error while analyzing Broken.class.", e.getMessage()); + assertExceptionMessage("Broken.class", e); } } @@ -209,7 +209,7 @@ public void testAnalyzeClass_BrokenStream() throws IOException { analyzer.analyzeClass(new BrokenInputStream(), "BrokenStream"); fail("exception expected"); } catch (IOException e) { - assertEquals("Error while analyzing BrokenStream.", e.getMessage()); + assertExceptionMessage("BrokenStream", e); } } @@ -224,8 +224,7 @@ public void analyzeAll_should_throw_exception_for_unsupported_class_file_version "UnsupportedVersion"); fail("exception expected"); } catch (IOException e) { - assertEquals("Error while analyzing UnsupportedVersion.", - e.getMessage()); + assertExceptionMessage("UnsupportedVersion", e); assertEquals("Unsupported class file major version 64", e.getCause().getMessage()); } @@ -274,7 +273,7 @@ public void testAnalyzeAll_Broken() throws IOException { analyzer.analyzeAll(new BrokenInputStream(), "Test"); fail("expected exception"); } catch (IOException e) { - assertEquals("Error while analyzing Test.", e.getMessage()); + assertExceptionMessage("Test", e); } } @@ -289,7 +288,7 @@ public void testAnalyzeAll_BrokenGZ() { analyzer.analyzeAll(new ByteArrayInputStream(buffer), "Test.gz"); fail("expected exception"); } catch (IOException e) { - assertEquals("Error while analyzing Test.gz.", e.getMessage()); + assertExceptionMessage("Test.gz", e); } } @@ -333,7 +332,7 @@ public void testAnalyzeAll_BrokenPack200() { "Test.pack200"); fail("expected exception"); } catch (IOException e) { - assertEquals("Error while analyzing Test.pack200.", e.getMessage()); + assertExceptionMessage("Test.pack200", e); } } @@ -380,7 +379,7 @@ public void testAnalyzeAll_BrokenZip() { analyzer.analyzeAll(new ByteArrayInputStream(buffer), "Test.zip"); fail("expected exception"); } catch (IOException e) { - assertEquals("Error while analyzing Test.zip.", e.getMessage()); + assertExceptionMessage("Test.zip", e); } } @@ -431,9 +430,8 @@ public void testAnalyzeAll_BrokenClassFileInZip() throws IOException { "test.zip"); fail("expected exception"); } catch (IOException e) { - assertEquals( - "Error while analyzing test.zip@org/jacoco/core/analysis/AnalyzerTest.class.", - e.getMessage()); + assertExceptionMessage( + "test.zip@org/jacoco/core/analysis/AnalyzerTest.class", e); } } @@ -452,4 +450,10 @@ private void assertClasses(String... classNames) { classes.keySet()); } + private void assertExceptionMessage(String name, Exception ex) { + String expected = "Error while analyzing " + name + " with JaCoCo " + + JaCoCo.VERSION + "/" + JaCoCo.COMMITID_SHORT + "."; + assertEquals(expected, ex.getMessage()); + } + } diff --git a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java index c755b2d921..2ddb1477c6 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java @@ -33,6 +33,7 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; +import org.jacoco.core.JaCoCo; import org.jacoco.core.analysis.AnalyzerTest; import org.jacoco.core.internal.Pack200Streams; import org.jacoco.core.internal.data.CRC64; @@ -127,8 +128,7 @@ public void instrument_should_throw_exception_for_unsupported_class_file_version instrumenter.instrument(bytes, "UnsupportedVersion"); fail("exception expected"); } catch (final IOException e) { - assertEquals("Error while instrumenting UnsupportedVersion.", - e.getMessage()); + assertExceptionMessage("UnsupportedVersion", e); assertEquals("Unsupported class file major version 64", e.getCause().getMessage()); } @@ -156,8 +156,7 @@ public void testInstrumentBrokenClass1() throws IOException { instrumenter.instrument(brokenclass, "Broken.class"); fail(); } catch (IOException e) { - assertEquals("Error while instrumenting Broken.class.", - e.getMessage()); + assertExceptionMessage("Broken.class", e); } } @@ -178,8 +177,7 @@ public void testInstrumentBrokenStream() { instrumenter.instrument(new BrokenInputStream(), "BrokenStream"); fail("exception expected"); } catch (IOException e) { - assertEquals("Error while instrumenting BrokenStream.", - e.getMessage()); + assertExceptionMessage("BrokenStream", e); } } @@ -194,8 +192,7 @@ public void testInstrumentBrokenStream2() { new ByteArrayOutputStream(), "BrokenStream"); fail("exception expected"); } catch (IOException e) { - assertEquals("Error while instrumenting BrokenStream.", - e.getMessage()); + assertExceptionMessage("BrokenStream", e); } } @@ -230,8 +227,7 @@ public void instrumentAll_should_throw_exception_for_unsupported_class_file_vers new ByteArrayOutputStream(), "UnsupportedVersion"); fail("exception expected"); } catch (final IOException e) { - assertEquals("Error while instrumenting UnsupportedVersion.", - e.getMessage()); + assertExceptionMessage("UnsupportedVersion", e); assertEquals("Unsupported class file major version 64", e.getCause().getMessage()); } @@ -297,7 +293,7 @@ public void testInstrumentAll_Broken() { new ByteArrayOutputStream(), "Broken"); fail("exception expected"); } catch (IOException e) { - assertEquals("Error while instrumenting Broken.", e.getMessage()); + assertExceptionMessage("Broken", e); } } @@ -324,7 +320,7 @@ public int read() throws IOException { instrumenter.instrumentAll(inputStream, new ByteArrayOutputStream(), "Broken"); } catch (IOException e) { - assertEquals("Error while instrumenting Broken.", e.getMessage()); + assertExceptionMessage("Broken", e); } } @@ -346,7 +342,7 @@ public void testInstrumentAll_BrokenZip() { new ByteArrayOutputStream(), "Test.zip"); fail("exception expected"); } catch (IOException e) { - assertEquals("Error while instrumenting Test.zip.", e.getMessage()); + assertExceptionMessage("Test.zip", e); } } @@ -371,9 +367,7 @@ public void testInstrumentAll_BrokenZipEntry() throws IOException { new ByteArrayOutputStream(), "broken.zip"); fail("exception expected"); } catch (IOException e) { - assertEquals( - "Error while instrumenting broken.zip@brokenentry.txt.", - e.getMessage()); + assertExceptionMessage("broken.zip@brokenentry.txt", e); } } @@ -394,8 +388,7 @@ public void testInstrumentAll_BrokenClassFileInZip() throws IOException { "test.zip"); fail(); } catch (IOException e) { - assertEquals("Error while instrumenting test.zip@Test.class.", - e.getMessage()); + assertExceptionMessage("test.zip@Test.class", e); } } @@ -412,7 +405,7 @@ public void testInstrumentAll_BrokenGZ() { new ByteArrayOutputStream(), "Test.gz"); fail("exception expected"); } catch (IOException e) { - assertEquals("Error while instrumenting Test.gz.", e.getMessage()); + assertExceptionMessage("Test.gz", e); } } @@ -462,8 +455,7 @@ public void testInstrumentAll_BrokenPack200() { instrumenter.instrumentAll(new ByteArrayInputStream(buffer), new ByteArrayOutputStream(), "Test.pack200"); } catch (IOException e) { - assertEquals("Error while instrumenting Test.pack200.", - e.getMessage()); + assertExceptionMessage("Test.pack200", e); } } @@ -516,4 +508,10 @@ public void testInstrumentAll_KeepSignatures() throws IOException { assertNull(zipin.getNextEntry()); } + private void assertExceptionMessage(String name, Exception ex) { + String expected = "Error while instrumenting " + name + " with JaCoCo " + + JaCoCo.VERSION + "/" + JaCoCo.COMMITID_SHORT + "."; + assertEquals(expected, ex.getMessage()); + } + } diff --git a/org.jacoco.core/src/org/jacoco/core/JaCoCo.java b/org.jacoco.core/src/org/jacoco/core/JaCoCo.java index 9116bb91ec..6a07341c7f 100644 --- a/org.jacoco.core/src/org/jacoco/core/JaCoCo.java +++ b/org.jacoco.core/src/org/jacoco/core/JaCoCo.java @@ -19,9 +19,17 @@ */ public final class JaCoCo { - /** Qualified build version of the JaCoCo core library. */ + /** Qualified version of JaCoCo core. */ public static final String VERSION; + /** Commit ID of the source tree of JaCoCo core. */ + public static final String COMMITID; + + /** + * Shortened (7 digit) commit ID of the source tree of JaCoCo core. + */ + public static final String COMMITID_SHORT; + /** Absolute URL of the current JaCoCo home page */ public static final String HOMEURL; @@ -32,6 +40,8 @@ public final class JaCoCo { final ResourceBundle bundle = ResourceBundle .getBundle("org.jacoco.core.jacoco"); VERSION = bundle.getString("VERSION"); + COMMITID = bundle.getString("COMMITID"); + COMMITID_SHORT = COMMITID.substring(0, 7); HOMEURL = bundle.getString("HOMEURL"); RUNTIMEPACKAGE = bundle.getString("RUNTIMEPACKAGE"); } diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java index 7052ba522a..53afe22f44 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java @@ -21,6 +21,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import org.jacoco.core.JaCoCo; import org.jacoco.core.data.ExecutionData; import org.jacoco.core.data.ExecutionDataStore; import org.jacoco.core.internal.ContentTypeDetector; @@ -160,7 +161,8 @@ public void analyzeClass(final InputStream input, final String location) private IOException analyzerError(final String location, final Exception cause) { final IOException ex = new IOException( - String.format("Error while analyzing %s.", location)); + String.format("Error while analyzing %s with JaCoCo %s/%s.", + location, JaCoCo.VERSION, JaCoCo.COMMITID_SHORT)); ex.initCause(cause); return ex; } diff --git a/org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java b/org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java index b14e7102c1..3bd85b9c0b 100644 --- a/org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java +++ b/org.jacoco.core/src/org/jacoco/core/instr/Instrumenter.java @@ -23,6 +23,7 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; +import org.jacoco.core.JaCoCo; import org.jacoco.core.internal.ContentTypeDetector; import org.jacoco.core.internal.InputStreams; import org.jacoco.core.internal.Pack200Streams; @@ -158,7 +159,8 @@ public void instrument(final InputStream input, final OutputStream output, private IOException instrumentError(final String name, final Exception cause) { final IOException ex = new IOException( - String.format("Error while instrumenting %s.", name)); + String.format("Error while instrumenting %s with JaCoCo %s/%s.", + name, JaCoCo.VERSION, JaCoCo.COMMITID_SHORT)); ex.initCause(cause); return ex; } diff --git a/org.jacoco.core/src/org/jacoco/core/jacoco.properties b/org.jacoco.core/src/org/jacoco/core/jacoco.properties index 03430a84dd..035ed90d56 100644 --- a/org.jacoco.core/src/org/jacoco/core/jacoco.properties +++ b/org.jacoco.core/src/org/jacoco/core/jacoco.properties @@ -1,3 +1,4 @@ VERSION=${qualified.bundle.version} +COMMITID=${buildNumber} HOMEURL=${jacoco.home.url} RUNTIMEPACKAGE=${jacoco.runtime.package.name} diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html index 88011c3036..baece73bb2 100644 --- a/org.jacoco.doc/docroot/doc/changes.html +++ b/org.jacoco.doc/docroot/doc/changes.html @@ -46,6 +46,9 @@

Non-functional Changes

Release 0.8.7 (2021/05/04)