36
Jakarta Commons don’t re-invent the wheel Torsten Curdt

Jakarta Commons - Don't re-invent the wheel

  • Upload
    tcurdt

  • View
    1.514

  • Download
    2

Embed Size (px)

DESCRIPTION

Many projects use at least some of them - the Jakarta Commons libraries. Small reusable libraries simplifying the day-to-day work of thousands of java programmers. But over time the jakarta commons project has grown and the number of components makes it harder and harder to keep track. This session will try to give an overview of the components available and how the Jakarta Commons community is organized.

Citation preview

Page 1: Jakarta Commons - Don't re-invent the wheel

Jakarta Commons

don’t re-invent the wheel

Torsten Curdt

Page 2: Jakarta Commons - Don't re-invent the wheel

Increase Productivity

Page 3: Jakarta Commons - Don't re-invent the wheel

Re-use to Excel

Page 4: Jakarta Commons - Don't re-invent the wheel

•Faster

•Better designed

•Less time

•Smaller team

Page 5: Jakarta Commons - Don't re-invent the wheel

How did we do it?

Page 6: Jakarta Commons - Don't re-invent the wheel

Know your libraries!

Page 7: Jakarta Commons - Don't re-invent the wheel

Sharing QA

Page 8: Jakarta Commons - Don't re-invent the wheel

Heritage

Page 9: Jakarta Commons - Don't re-invent the wheel

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”

Page 10: Jakarta Commons - Don't re-invent the wheel

Growth

Sandbox

Proper Dormant

Page 11: Jakarta Commons - Don't re-invent the wheel

Project Stats

0

11

23

34

45

Active Inactive

3834

10

SandboxProperDormant

Page 12: Jakarta Commons - Don't re-invent the wheel

Proper

Page 13: Jakarta Commons - Don't re-invent the wheel

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 14: Jakarta Commons - Don't re-invent the wheel

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 15: Jakarta Commons - Don't re-invent the wheel

Email

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 16: Jakarta Commons - Don't re-invent the wheel

IO

InputStream in;OutputStream out;

IOUtils.copy(in, out);

...

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

Page 17: Jakarta Commons - Don't re-invent the wheel

JXPath

XPathContext context = JXPathContext.newContext(dom);

String value = (String) context.getValue("/my/xpath/to/value");

Page 18: Jakarta Commons - Don't re-invent the wheel

Lang

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

String n = “0”;StringUtils.leftPad(s, 4, ‘0’); // “0000”

Page 19: Jakarta Commons - Don't re-invent the wheel

Logging

public class C { private Log log = LogFactory.getLog(C.class); ... if (log.isDebugEnabled()) { log.debug("log message"); }

Page 20: Jakarta Commons - Don't re-invent the wheel

Net

NNTPClient client = new NNTPClient();client.connect("news.server.net");

NewsgroupInfo[] = client.listNewsgroups();

client.disconnect();

Page 21: Jakarta Commons - Don't re-invent the wheel

Primitives

ArrayByteList list = new ArrayByteList();

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

byte[] bytes = list.toArray();

Page 22: Jakarta Commons - Don't re-invent the wheel

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 23: Jakarta Commons - Don't re-invent the wheel

Overviewattributes, beanutils, betwixt, chain, cli, codec, collections, configuration, daemon, dbcp, dbutils, digester, discovery, el, email, fileupload, httpclient, io, jelly, jexl, jxpath, lang, launcher, logging, math, modeler, net, pool, primitives, scxml, transaction, validator, vfs

Page 24: Jakarta Commons - Don't re-invent the wheel

Sandbox

Page 25: Jakarta Commons - Don't re-invent the wheel

CSV

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

CSVParser parser = new CSVParser(reader,’;’);String[][] data = parser.getAllValues();

Page 26: Jakarta Commons - Don't re-invent the wheel

Exec

OutputStream out;OutputStream error;

CommandLine cl = new CommandLineImpl();cl.setExecutable("path/to/exe");cl.addArgument("arg");exec.execute(cl, out, error);

Page 27: Jakarta Commons - Don't re-invent the wheel

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 28: Jakarta Commons - Don't re-invent the wheel

JCI

JavaCompiler compiler = new EclipseJavaCompiler();ResourceStore store = new MemoryResourceStore();

CompilationResult result = compiler.compile( new String[] { "org/MyClass.java" }, new FileResourceReader(directory), store );

Page 29: Jakarta Commons - Don't re-invent the wheel

OpenPGP

keyRing = new BouncyCastleKeyRing( secret, public, password);signer = new BouncyCastleOpenPgpSigner();signer.detachedSign( fileInputStream signatureOutputStream, keyId, keyRing, true );

Page 30: Jakarta Commons - Don't re-invent the wheel

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 31: Jakarta Commons - Don't re-invent the wheel

Overview

compress, csv, exec, i18n, id, javaflow, jci, openpgp , pipel ine, proxy

Page 32: Jakarta Commons - Don't re-invent the wheel

Dormant

Page 33: Jakarta Commons - Don't re-invent the wheel

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 34: Jakarta Commons - Don't re-invent the wheel

Not invented here

Page 35: Jakarta Commons - Don't re-invent the wheel

We need you!

Page 36: Jakarta Commons - Don't re-invent the wheel

Thanks!