Apache
                Commons

Torsten Curdt

                don’t re-invent the wheel
Why are you a
 Developer?
Creating & Building
That is a problem!
The journey
is the goal.
Use vs Build
A Story of Re-use
•Faster
•Better designed
•Less time
•Smaller team
Original




Re-Impl




           0   5,000   10,000   15,000   20,000   25,000
                            hours
20,000 hours
7x
5x
How did we do it?
Re-use to Excel
Know your libraries!
Heritage
Charter
“Creation of small re-useable
components that can be used across
projects. They are supposed to have as
few depend...
Growth

Sandbox




Proper    Dormant
Project Stats
60
                         Dormant
                         Proper
      37                 Sandbox
45




...
Proper
Collections
Map map = new CaseInsensitiveMap();
map.put(quot;Onequot;, quot;Onequot;);
map.get(quot;ONEquot;);

Map colorM...
Primitives

ArrayByteList list = new ArrayByteList();

list.add(byte);
list.removeElementAt(index);

byte[] bytes = list.t...
IO

InputStream in;
OutputStream out;

IOUtils.copy(in, out);

...

byte[] data = IOUtils.toByteArray(in);
Lang

String s = “Apache Jakarta Commons”;
StringUtils.right(s, 7); // “Commons”

String n = “0”;
StringUtils.leftPad(s, 4...
Logging

public class C {
  private Log log = LogFactory.getLog(C.class);
  ...
      if (log.isDebugEnabled()) {
        ...
CLI
Options options = new Options();
options.addOption(quot;hquot;, false, quot;display usagequot;);

CommandLine line = p...
Email

SimpleEmail email = new SimpleEmail();
email.setHostName(quot;mail.myserver.comquot;);
email.addTo(quot;jdoe@somewh...
Net

NNTPClient client = new NNTPClient();
client.connect(quot;news.server.netquot;);

NewsgroupInfo[] = client.listNewsgr...
JXPath

XPathContext context =
  JXPathContext.newContext(dom);

String value = (String)
  context.getValue(quot;/my/xpath...
VFS

FileSystemManager fs = VFS.getManager();
FileObject jar = fs.resolveFile(
  quot;jar:lib/aJarFile.jarquot; );

FileOb...
JCI
JavaCompiler compiler =
  new EclipseJavaCompiler();
ResourceStore store =
  new MemoryResourceStore();

CompilationRe...
Exec

OutputStream out;
OutputStream error;

CommandLine cl = new CommandLineImpl();
cl.setExecutable(quot;path/to/exequot...
Proxy
o = (MyObject) new CglibProxyFactory()
    .createInterceptorProxy(
       new MyObjectImpl(),
       new LoggingInt...
Overview
attributes, beanutils, betwixt, chain,
cli, codec, collections, configuration,
daemon, dbcp, dbutils, digester,
d...
Sandbox
CSV

String[][] data = CSVParser.parse(string);

CSVParser parser = new CSVParser(reader,’;’);
String[][] data = parser.ge...
Javaflow
class MyRunnable implements Runnable {
  public void run() {
    for(int i=0; i<10; i++ )
      Continuation.susp...
OpenPGP
keyRing = new BouncyCastleKeyRing(
                 secret, public, password);
signer = new BouncyCastleOpenPgpSig...
Overview
compress, csv, expression,
finder, flatfile, functor, i18n,
id, javaflow, jnet, js2j, me,
monitoring, nabla, open...
Dormant
Overview
benchmark, cache, clazz, codec-
mulipart, combo, contract, events,
feedparser, filters, functor, grant,
graph2, h...
direct dependency
            no dependency




      20%




80%
We need you!


dev@commons.apache.org
Thanks!
  http://vafer.org/blog
http://twitter.com/tcurdt
Upcoming SlideShare
Loading in …5
×

Apache Commons - Don\'t re-invent the wheel

4,659 views

Published on

Introduction to Apache Commons presented at ApacheCon US 2008

Published in: Technology
  • Be the first to comment

Apache Commons - Don\'t re-invent the wheel

  1. Apache Commons Torsten Curdt don’t re-invent the wheel
  2. Why are you a Developer?
  3. Creating & Building
  4. That is a problem!
  5. The journey is the goal.
  6. Use vs Build
  7. A Story of Re-use
  8. •Faster •Better designed •Less time •Smaller team
  9. Original Re-Impl 0 5,000 10,000 15,000 20,000 25,000 hours
  10. 20,000 hours
  11. 7x
  12. 5x
  13. How did we do it?
  14. Re-use to Excel
  15. Know your libraries!
  16. Heritage
  17. Charter “Creation of small re-useable 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”
  18. Growth Sandbox Proper Dormant
  19. Project Stats 60 Dormant Proper 37 Sandbox 45 30 37 15 18 0 Active Inactive
  20. Proper
  21. Collections Map map = new CaseInsensitiveMap(); map.put(quot;Onequot;, quot;Onequot;); map.get(quot;ONEquot;); Map colorMap = MapUtils.toMap(new String[][] {{ {quot;redquot;, quot;#FF0000quot;}, {quot;greenquot;, quot;#00FF00quot;}, {quot;bluequot;, quot;#0000FFquot;} });
  22. Primitives ArrayByteList list = new ArrayByteList(); list.add(byte); list.removeElementAt(index); byte[] bytes = list.toArray();
  23. IO InputStream in; OutputStream out; IOUtils.copy(in, out); ... byte[] data = IOUtils.toByteArray(in);
  24. Lang String s = “Apache Jakarta Commons”; StringUtils.right(s, 7); // “Commons” String n = “0”; StringUtils.leftPad(s, 4, ‘0’); // “0000”
  25. Logging public class C { private Log log = LogFactory.getLog(C.class); ... if (log.isDebugEnabled()) { log.debug(quot;log messagequot;); }
  26. CLI Options options = new Options(); options.addOption(quot;hquot;, false, quot;display usagequot;); CommandLine line = parser.parse(options, args); if(line.hasOption(quot;hquot;)) { HelpFormatter f = new HelpFormatter(); f.printHelp(quot;myprogramquot;, options); ...
  27. Email SimpleEmail email = new SimpleEmail(); email.setHostName(quot;mail.myserver.comquot;); email.addTo(quot;jdoe@somewhere.orgquot;, quot;John Doequot;); email.setFrom(quot;me@apache.orgquot;, quot;Mequot;); email.setSubject(quot;Test messagequot;); email.setMsg(quot;A simple test of commons-emailquot;); email.send();
  28. Net NNTPClient client = new NNTPClient(); client.connect(quot;news.server.netquot;); NewsgroupInfo[] = client.listNewsgroups(); client.disconnect();
  29. JXPath XPathContext context = JXPathContext.newContext(dom); String value = (String) context.getValue(quot;/my/xpath/to/valuequot;);
  30. VFS FileSystemManager fs = VFS.getManager(); FileObject jar = fs.resolveFile( quot;jar:lib/aJarFile.jarquot; ); FileObject[] childs = jar.getChildren(); for (int i=0; i < childs.length; i++ ) { ...
  31. JCI JavaCompiler compiler = new EclipseJavaCompiler(); ResourceStore store = new MemoryResourceStore(); CompilationResult result = compiler.compile( new String[] { quot;org/MyClass.javaquot; }, new FileResourceReader(directory), store );
  32. Exec OutputStream out; OutputStream error; CommandLine cl = new CommandLineImpl(); cl.setExecutable(quot;path/to/exequot;); cl.addArgument(quot;argquot;); exec.execute(cl, out, error);
  33. 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()
  34. Overview attributes, 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
  35. Sandbox
  36. CSV String[][] data = CSVParser.parse(string); CSVParser parser = new CSVParser(reader,’;’); String[][] data = parser.getAllValues();
  37. 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); ...
  38. OpenPGP keyRing = new BouncyCastleKeyRing( secret, public, password); signer = new BouncyCastleOpenPgpSigner(); signer.detachedSign( fileInputStream signatureOutputStream, keyId, keyRing, true );
  39. Overview compress, csv, expression, finder, flatfile, functor, i18n, id, javaflow, jnet, js2j, me, monitoring, nabla, openpgp, performance, pipeline, validator2
  40. Dormant
  41. Overview benchmark, 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, scaffold, services, servlet, simplestore, tbm, test, threading, threadpool, workflow, xmlio, xmlunit, xo
  42. direct dependency no dependency 20% 80%
  43. We need you! dev@commons.apache.org
  44. Thanks! http://vafer.org/blog http://twitter.com/tcurdt

×