Apache Commons - Don\'t re-invent the wheel
-
Upload
tcurdt -
Category
Technology
-
view
2.373 -
download
0
description
Transcript of Apache Commons - Don\'t re-invent the wheel
![Page 1: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/1.jpg)
Apache Commons
don’t re-invent the wheel
Torsten Curdt
![Page 2: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/2.jpg)
Why are you aDeveloper?
![Page 3: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/3.jpg)
Creating & Building
![Page 4: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/4.jpg)
That is a problem!
![Page 5: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/5.jpg)
The journeyis the goal.
![Page 6: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/6.jpg)
Use vs Build
![Page 7: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/7.jpg)
A Story of Re-use
![Page 8: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/8.jpg)
•Faster
•Better designed
•Less time
•Smaller team
![Page 9: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/9.jpg)
Original
Re-Impl
0 5,000 10,000 15,000 20,000 25,000
hours
![Page 10: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/10.jpg)
20,000 hours
![Page 11: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/11.jpg)
7x
![Page 12: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/12.jpg)
5x
![Page 13: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/13.jpg)
How did we do it?
![Page 14: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/14.jpg)
Re-use to Excel
![Page 15: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/15.jpg)
Know your libraries!
![Page 16: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/16.jpg)
Heritage
![Page 17: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/17.jpg)
Charter
“ C r e a t i o n o f s m a l l r e - u s eab l e components that can be used across projects. They are supposed to have as few dependencies as possible, meant to be well tested and compatible with the current de-facto standard version of the JDK”
![Page 18: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/18.jpg)
Growth
Sandbox
Proper Dormant
![Page 19: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/19.jpg)
Project Stats
0
15
30
45
60
Active Inactive
37
37
18
SandboxProperDormant
![Page 20: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/20.jpg)
Proper
![Page 21: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/21.jpg)
Collections
Map map = new CaseInsensitiveMap();map.put("One", "One");map.get("ONE");
Map colorMap = MapUtils.toMap(new String[][] {{ {"red", "#FF0000"}, {"green", "#00FF00"}, {"blue", "#0000FF"}});
![Page 22: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/22.jpg)
Primitives
ArrayByteList list = new ArrayByteList();
list.add(byte);list.removeElementAt(index);
byte[] bytes = list.toArray();
![Page 23: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/23.jpg)
IO
InputStream in;OutputStream out;
IOUtils.copy(in, out);
...
byte[] data = IOUtils.toByteArray(in);
![Page 24: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/24.jpg)
Lang
String s = “Apache Jakarta Commons”;StringUtils.right(s, 7); // “Commons”
String n = “0”;StringUtils.leftPad(s, 4, ‘0’); // “0000”
![Page 25: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/25.jpg)
Logging
public class C { private Log log = LogFactory.getLog(C.class); ... if (log.isDebugEnabled()) { log.debug("log message"); }
![Page 26: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/26.jpg)
CLI
Options options = new Options();options.addOption("h", false, "display usage");
CommandLine line = parser.parse(options, args);
if(line.hasOption("h")) { HelpFormatter f = new HelpFormatter(); f.printHelp("myprogram", options); ...
![Page 27: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/27.jpg)
SimpleEmail email = new SimpleEmail();email.setHostName("mail.myserver.com");email.addTo("[email protected]", "John Doe");email.setFrom("[email protected]", "Me");email.setSubject("Test message");email.setMsg("A simple test of commons-email");email.send();
![Page 28: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/28.jpg)
Net
NNTPClient client = new NNTPClient();client.connect("news.server.net");
NewsgroupInfo[] = client.listNewsgroups();
client.disconnect();
![Page 29: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/29.jpg)
JXPath
XPathContext context = JXPathContext.newContext(dom);
String value = (String) context.getValue("/my/xpath/to/value");
![Page 30: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/30.jpg)
VFS
FileSystemManager fs = VFS.getManager();FileObject jar = fs.resolveFile( "jar:lib/aJarFile.jar" );
FileObject[] childs = jar.getChildren();for (int i=0; i < childs.length; i++ ) { ...
![Page 31: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/31.jpg)
JCI
JavaCompiler compiler = new EclipseJavaCompiler();ResourceStore store = new MemoryResourceStore();
CompilationResult result = compiler.compile( new String[] { "org/MyClass.java" }, new FileResourceReader(directory), store );
![Page 32: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/32.jpg)
Exec
OutputStream out;OutputStream error;
CommandLine cl = new CommandLineImpl();cl.setExecutable("path/to/exe");cl.addArgument("arg");exec.execute(cl, out, error);
![Page 33: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/33.jpg)
Proxy
o = (MyObject) new CglibProxyFactory() .createInterceptorProxy( new MyObjectImpl(), new LoggingInterceptor(log), new Class[]{ MyObject.class });o.test(”test”);
[DEBUG] - BEGIN test(test)[DEBUG] - END test()
![Page 34: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/34.jpg)
Overviewattributes, beanutils, betwixt, chain, cli, codec, collections, configuration, daemon, dbcp, dbutils, digester, discovery, el, email, fileupload, httpclient, io, jci, jelly, jexl, jxpath, lang, launcher, logging, math, modeler, net, pool, primitives, proxy, scxml, transaction, validator, vfs
![Page 35: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/35.jpg)
Sandbox
![Page 36: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/36.jpg)
CSV
String[][] data = CSVParser.parse(string);
CSVParser parser = new CSVParser(reader,’;’);String[][] data = parser.getAllValues();
![Page 37: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/37.jpg)
Javaflow
class MyRunnable implements Runnable { public void run() { for(int i=0; i<10; i++ ) Continuation.suspend(); }}Continuation c = Continuation.startWith( new MyRunnable());Continuation d = Continuation.continueWith(c);...
![Page 38: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/38.jpg)
OpenPGP
keyRing = new BouncyCastleKeyRing( secret, public, password);signer = new BouncyCastleOpenPgpSigner();signer.detachedSign( fileInputStream signatureOutputStream, keyId, keyRing, true );
![Page 39: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/39.jpg)
Overview
compress, csv, expression, finder, flatfile, functor, i18n, id, javaflow, jnet, js2j, me, monitoring, nabla, openpgp, p e r f o r m a n c e , p i p e l i n e , validator2
![Page 40: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/40.jpg)
Dormant
![Page 41: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/41.jpg)
Overviewbenchmark, cache, clazz, codec-mulipart, combo, contract, events, feedparser, filters, functor, grant, graph2, http, jex, jjar, jpath, jrcs, jux, latka, mapper, messenger, pattern, periodicity, reflect, resources, rupert, s c a f f o l d , s e r v i c e s , s e r v l e t , simplestore, tbm, test, threading, threadpool, workflow, xmlio, xmlunit, xo
![Page 42: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/42.jpg)
80%
20%
direct dependencyno dependency
![Page 44: Apache Commons - Don\'t re-invent the wheel](https://reader033.fdocuments.us/reader033/viewer/2022052523/55540a92b4c90577468b51a5/html5/thumbnails/44.jpg)
Thanks!
http://vafer.org/bloghttp://twitter.com/tcurdt