semantic versioning a large existing codebase · the project started with no versioning, and with...

39
Case Study Semantic Versioning A Large Existing Codebase EclipseCon 2014 Raymond Augé <[email protected] (mailto:[email protected]) > @rotty3000 | #eclipsecon #semver

Upload: others

Post on 17-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Case Study

Semantic Versioning A LargeExisting Codebase

EclipseCon 2014

Raymond Augé <[email protected](mailto:[email protected])>

@rotty3000 | #eclipsecon #semver

Page 2: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Outline

The Goal The Project

The Problem The solution

Semantic Versioning Tools

BND Our Enhancements

The conclusion

Page 3: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The Goal

Improve Code Quality

Increase Developer Joy

Page 4: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The Project

Liferay Portal project is a large open source application

A large community of users and contributors

Page 5: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The problem

Product versioning scheme

Minor Releases (6.1.0 6.2.0)Binary patch security hot­fixesCollective Fix­PacksNo incremental feature updates

API Breaking changes (hopefully not!)

Page 6: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The problem

Product versioning scheme

Major Releases (6.2.0 7.0.0)More than 1 year between releasesMonolithic upgrades

API Breaking changes (guaranteed! Best effort to know which!)Tight coupling rampant across features

Page 7: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The solution

To a large degree resolving these issues begins with APIManagement.

Page 8: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The solution

Controlled evolution demonstrates API Reliability

Ability to resolve implementation issues while maintainingcompatibility demonstrates API Stability

Though there are no measures of API Productivity, it’s clear thatgood APIs improve developer productivity

Page 9: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The solution

Reliability, Stability, Productivity make happy Developers /Users / Customers!

Page 10: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Semantic Versioning

Achieve programmatic detection of API changes

Provide developers with tools to ease the learning curve

Artifact granularity is not sufficient when size exceed someinordinate number of APIs.

Page 11: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Semantic Versioning

Using the OSGi Alliance Semantic Versioning white paperdefinition

http://www.osgi.org/wiki/uploads/Links/SemanticVersioning.pdf(http://www.osgi.org/wiki/uploads/Links/SemanticVersioning.pdf)

The unit of granularity is package.

However, implementing Semantic Versioning at the scale of thisproject is a significant amount of work!

Page 12: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Tools

The key to Semantic Versioning is tooling.

Humans are biased, error prone

Semantic Versioning is boring and tedious

Let machines do the work

There aren’t many well known tools.

Fortunately, the most well known one is FANTASTIC (and canprovide even more useful information than it currently lets on.)

Page 13: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Tools

With proper tooling it’s simple to adopt Semantic Versioningincrementally!

Page 14: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND

"bnd is the Swiss army knife of OSGi, it is used for creating andworking with OSGi bundles. Its primary goal is take the pain out ofdeveloping bundles."

http://www.aqute.biz/Bnd— Peter Kriens

http://www.aqute.biz/Bnd/Bnd (http://www.aqute.biz/Bnd/Bnd) (thelibrary) http://bndtools.org/ (http://bndtools.org/) (a complete OSGi Suitefor Eclipse)

Page 15: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Baseline

"Baselining compares the public API of a bundle with the publicAPI of another bundle."

http://www.aqute.biz/Bnd/Versioning— Peter Kriens

Page 16: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Baseline

Invocation

Output

java ­jar biz.aQute.bnd­latest.jar baseline ­d ./biz.aQute.bnd­latest.jar

/other/bnd.jar

Page 17: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Easily recognize degree of version change

Detects all types of change

===============================================================

biz.aQute.bnd 2.3.0.20140315­151701­2.2.0.20131017­210830

===============================================================

Package Delta New Old

Suggest If Prov.

aQute.bnd.build MINOR 2.3.0 2.2.0

ok ­

aQute.bnd.header MINOR 1.3.0 1.2.0

ok ­

aQute.bnd.osgi MINOR 2.2.0 2.1.3

ok ­

aQute.bnd.service.classparser ADDED 1.0.0 ­

ok ­

aQute.bnd.service.extension ADDED 1.0.0 ­

ok ­

aQute.bnd.service.phases ADDED 1.0.0 ­

ok ­

aQute.bnd.service.repository MINOR 1.3.0 1.1.0

ok ­

aQute.bnd.service.url MINOR 1.2.0 1.1.0

ok ­

aQute.bnd.version MINOR 1.1.0 1.0.0

ok ­

1

2

1

2

Page 18: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND

The project started with no versioning, and with developersignorant about Semantic Versioning.

BND’s existing information does not provide enough detail for lessexperienced developers to understand how things get broken.

Page 19: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND

Internally BND performs exceptionally detailed API analytics, notexposed in it’s default output

The project needed that information

None of our code is OSGi aware. BND is designed to operate withOSGi bundles.

Page 20: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND

Can BND still be used when the code isn’t OSGi ready

Yes! Even the most basic BND configuration is useful

Bundle­SymbolicName: $bundle.name

Bundle­Version: $bundle.version

Export­Package: *

Import­Package: *

Page 21: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Creating Jars

Consider this simple directory structure

/bnd.bnd

/bnd.jar

/src/main/java/com/test/Fee.java

/src/main/java/com/test/IFoo.java

Fee.java

­­­­

package com.test;

public class Fee

public void doFee()

public void doFee2(IFoo foo)

­­­­

IFoo.java

­­­­

package com.test;

public interface IFoo

public void doFoo();

­­­­

Page 22: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

bnd.bnd

­­­­

Bundle­SymbolicName: a

Bundle­Version: 1.0.0

Export­Package: *

Import­Package: *

Include­Resource: build/classes

­output: build/libs/$Bundle­SymbolicName.jar

­­­­

Page 23: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Creating Jars

Compile

Jar with BND

mkdir ­p build/classes

javac ­d build/classes $(find . ­name "*.java")

rsync ­aq ­­exclude '*.java' src/main/java/* build/classes/

mkdir ­p build/libs

java ­jar bnd.jar bnd ­p bnd.bnd

Page 24: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Creating Jars

Result

build/libs/a.jar!MANIFEST.MF

­­­­

Manifest­Version: 1.0

Bnd­LastModified: 1395117308444

Bundle­ManifestVersion: 2

Bundle­Name: a

Bundle­SymbolicName: a

Bundle­Version: 1.0.0

Created­By: 1.7.0_51 (Oracle Corporation)

Export­Package: com.test;version="1.0.0"

Include­Resource: build/classes

Require­Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))"

Tool: Bnd­2.3.0.20140315­151701

­­­­

Page 25: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Baseline

Baseline is the operation of comparing one jar to a previousversion of the same jar in order to analyze for API changes.

The base case

java ­jar bnd.jar baseline build/libs/a.jar repo/a­latest.jar

===============================================================

a 1.0.0­1.0.0

===============================================================

Page 26: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Baseline

Added a new method

Produces

IFoo.java

­­­­

package com.test;

public interface IFoo

public void doFoo();

public void doFoo2();

­­­­

1

1

Page 27: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Adding a method to an interface is a MAJOR change

java ­jar bnd.jar baseline ­d build/libs/a.jar repo/a­latest.jar

===============================================================

* a 1.0.0­1.0.0 suggests 2.0.0

===============================================================

Package Delta New Old

Suggest If Prov.

* com.test MAJOR 1.0.0 1.0.0

2.0.0 1.0.01

1

Page 28: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Baseline

Added the @ProviderType annotation

Produces

IFoo.java

­­­­

package com.test;

@aQute.bnd.annotation.ProviderType

public interface IFoo

public void doFoo();

public void doFoo2();

­­­­

1

1

Page 29: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The change is now MINOR and suggested version reflects this

java ­jar bnd.jar baseline ­d build/libs/a.jar repo/a­latest.jar

===============================================================

* a 1.0.0­1.0.0 suggests 1.1.0

===============================================================

Package Delta New Old

Suggest If Prov.

* com.test MINOR 1.0.0 1.0.0

1.1.0 ­ 1

1

Page 30: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

BND - Baseline

Baseline indicates that the package’s version still needs to beproperly assigned.

To assign a proper version create a text file called packageinfoin the package directory.

Rebuild and baseline

packageinfo

­­­­

version 1.1.0

­­­­

Page 31: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Note the package state is no longer dirty.

Baseline now suggests that the library version be increased to 1.1.0 but refrain from doing so until the lib isready to release.

java ­jar bnd.jar baseline ­d build/libs/a.jar repo/a­latest.jar

===============================================================

* a 1.0.0­1.0.0 suggests 1.1.0

===============================================================

Package Delta New Old

Suggest If Prov.

com.test MINOR 1.1.0 1.0.0

ok ­

2

1

1

2

Page 32: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Our Enhancements

Our team wrapped BND operations for use in ant and gradle.

This allowed us deeper access to the extensive information BNDhas available.

Different reporting levels allow developers to choose what mostsuits their needs.

Baseline reporting is automatically enabled for all builds and usesa remote repository for zero configuration setup.

Optionally, persisted reports can be reviewed later or used bythings like CI to fail builds, etc.

Page 33: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Our Enhancements

Case #1

Interface removed

Method signature changed from public to protected

Static method added

PACKAGE_NAME DELTA CUR_VER BASE_VER

REC_VER WARNINGS

= ================================================== ========== ========== ==========

========== ==========

* com.liferay.portal.kernel.monitoring.statistics MAJOR 6.2.0 6.2.0

7.0.0 VERSION INCREASE REQUIRED

> class com.liferay.portal.kernel.monitoring.statistics.DataSampleThreadLocal

­ implements java.lang.Cloneable

> method clone()

+ access protected

+ method initialize()

+ access static

1

2

3

1

2

3

Page 34: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Our Enhancements

Case #2

Abstract class

Annotated as @ProviderType

Deletion of a method is always MAJOR

PACKAGE_NAME DELTA CUR_VER BASE_VER

REC_VER WARNINGS

= ================================================== ========== ========== ==========

========== ==========

* com.liferay.portal.kernel.template MAJOR 6.3.0 6.2.0

7.0.0 VERSION INCREASE REQUIRED

< class com.liferay.portal.kernel.template.BaseTemplateHandler

+ method getTemplatesHelpContent(java.lang.String)

+ return java.lang.String

+ annotated aQute.bnd.annotation.ProviderType

> class com.liferay.portal.kernel.template.TemplateHandlerRegistryUtil

­ method <init>()

[snip]

1

2

3

1

2

3

Page 35: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Our Enhancements

Case #2 (cont’)

Interface is modified

Method is added

PACKAGE_NAME DELTA CUR_VER BASE_VER

REC_VER WARNINGS

= ================================================== ========== ========== ==========

========== ==========

* com.liferay.portal.kernel.template MAJOR 6.3.0 6.2.0

7.0.0 VERSION INCREASE REQUIRED

[snip]

< interface com.liferay.portal.kernel.template.TemplateHandler

+ method getTemplatesHelpContent(java.lang.String)

+ access abstract

+ return java.lang.String

+ annotated aQute.bnd.annotation.ProviderType

­ interface com.liferay.portal.kernel.template.TemplateHandlerRegistry

[snip]

­ version 6.2.0

+ version 6.3.0

1

2

3

4

1

2

Page 36: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Because it’s @ProviderType change is MINOR

Version had previously been increased, but now it’s MAJOR

The conclusion

Did we achieve our goals?

Improve Code Quality

More quickly identify problem areas

Catch all packages suffer too much change (too many classesaffected): how should classes be slit up logically

Over embellished bug fixes: never mix bug fixes and API changes

Bad design decisions are more obvious

3

4

Page 37: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The conclusion

Did we achieve our goals?

Improve Code Quality

Packages which don’t change over time are either very stable orunused

stable: Isolate and congratulate the maintainer

unused: Delete without prejudice

Packages which do change frequently are possible problem areas,or need to be isolated into individual modules

Page 38: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

The conclusion

Did we achieve our goals?

Increase Developer Joy

Developers are more accountable (oddly this makes otherdevelopers happy)

Ability to produce 100% accurate reports of API change acrossthe entire product: means they have a reliable source ofinformation

Just like automated tests, automated API change detection makesdevelopers feel more confident

Increased enthusiasm evident among our developers

Page 39: Semantic Versioning A Large Existing Codebase · The project started with no versioning, and with developers ignorant about Semantic Versioning. BND’s existing information does

Thank You!