You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ds...@apache.org on 2009/07/21 20:51:41 UTC
svn commit: r796467 [9/25] - in /felix/trunk/sigil:
common/core.tests/src/org/apache/felix/sigil/core/
common/core/src/org/apache/felix/sigil/bnd/
common/core/src/org/apache/felix/sigil/config/
common/core/src/org/apache/felix/sigil/core/ common/core/s...
Modified: felix/trunk/sigil/common/junit/src/org/apache/felix/sigil/junit/server/impl/JUnitServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/junit/src/org/apache/felix/sigil/junit/server/impl/JUnitServiceImpl.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/junit/src/org/apache/felix/sigil/junit/server/impl/JUnitServiceImpl.java (original)
+++ felix/trunk/sigil/common/junit/src/org/apache/felix/sigil/junit/server/impl/JUnitServiceImpl.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.junit.server.impl;
+
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
@@ -34,119 +35,162 @@
import org.apache.felix.sigil.junit.server.JUnitService;
import org.osgi.framework.BundleContext;
-public class JUnitServiceImpl implements JUnitService {
-
- private static final Logger log = Logger.getLogger(JUnitServiceImpl.class.getName());
-
- private static final Class<?>[] BUNDLE_CONTEXT_PARAMS = new Class[] { BundleContext.class };
-
- private final JUnitServiceFactory junitServiceFactory;
- private final BundleContext bundleContext;
-
- public JUnitServiceImpl(JUnitServiceFactory junitServiceFactory, BundleContext bundleContext) {
- this.junitServiceFactory = junitServiceFactory;
- this.bundleContext = bundleContext;
- }
-
- public Set<String> getTests() {
- return junitServiceFactory.getTests();
- }
-
- public TestSuite createTest(String test) {
- return createTest(test, null);
- }
-
- public TestSuite createTest(String test, BundleContext ctx) {
- try {
- TestSuite ts = junitServiceFactory.getTest(test);
-
- if ( ts == null ) return null;
-
- TestSuite ret = new TestSuite(ts.getName());
-
- Enumeration<Test> e = ts.tests();
-
- while ( e.hasMoreElements() ) {
- Test t = e.nextElement();
- setContext(t, ctx);
- ret.addTest(t);
- }
-
- return ret;
- }
- catch (final NoClassDefFoundError e) {
- TestSuite s = new TestSuite(test);
- s.addTest( new Test() {
- public int countTestCases() {
- return 1;
- }
-
- public void run(TestResult result) {
- result.addError(this, e);
- }
- });
- return s;
- }
- catch (final RuntimeException e) {
- TestSuite s = new TestSuite(test);
- s.addTest( new Test() {
- public int countTestCases() {
- return 1;
- }
-
- public void run(TestResult result) {
- result.addError(this, e);
- }
-
- });
- return s;
- }
- }
-
- private void setContext(Test t, BundleContext ctx) {
- try {
- Method m = findMethod( t.getClass(), "setBundleContext", BUNDLE_CONTEXT_PARAMS );
- if ( m != null )
- m.invoke(t, ctx == null ? bundleContext : ctx );
- } catch (SecurityException e) {
- log.log( Level.WARNING, "Failed to set bundle context on " + t, e);
- } catch (IllegalArgumentException e) {
- log.log( Level.WARNING, "Failed to set bundle context on " + t, e);
- } catch (IllegalAccessException e) {
- log.log( Level.WARNING, "Failed to set bundle context on " + t, e);
- } catch (InvocationTargetException e) {
- log.log( Level.WARNING, "Failed to set bundle context on " + t, e);
- }
- }
-
- private Method findMethod(Class<?> clazz, String name,
- Class<?>[] params) {
- Method found = null;
-
- for ( Method m : clazz.getDeclaredMethods() ) {
- if ( m.getName().equals(name) && Arrays.deepEquals(m.getParameterTypes(), params) ) {
- found = m;
- break;
- }
- }
-
- if ( found == null ) {
- Class<?> c = clazz.getSuperclass();
-
- if ( c != null && c != Object.class ) {
- found = findMethod(c, name, params);
- }
- }
-
- if ( found == null ) {
- for ( Class<?> c : clazz.getInterfaces() ) {
- found = findMethod(c, name, params);
- if ( found != null ) {
- break;
- }
- }
- }
-
- return found;
- }
+
+public class JUnitServiceImpl implements JUnitService
+{
+
+ private static final Logger log = Logger.getLogger( JUnitServiceImpl.class.getName() );
+
+ private static final Class<?>[] BUNDLE_CONTEXT_PARAMS = new Class[]
+ { BundleContext.class };
+
+ private final JUnitServiceFactory junitServiceFactory;
+ private final BundleContext bundleContext;
+
+
+ public JUnitServiceImpl( JUnitServiceFactory junitServiceFactory, BundleContext bundleContext )
+ {
+ this.junitServiceFactory = junitServiceFactory;
+ this.bundleContext = bundleContext;
+ }
+
+
+ public Set<String> getTests()
+ {
+ return junitServiceFactory.getTests();
+ }
+
+
+ public TestSuite createTest( String test )
+ {
+ return createTest( test, null );
+ }
+
+
+ public TestSuite createTest( String test, BundleContext ctx )
+ {
+ try
+ {
+ TestSuite ts = junitServiceFactory.getTest( test );
+
+ if ( ts == null )
+ return null;
+
+ TestSuite ret = new TestSuite( ts.getName() );
+
+ Enumeration<Test> e = ts.tests();
+
+ while ( e.hasMoreElements() )
+ {
+ Test t = e.nextElement();
+ setContext( t, ctx );
+ ret.addTest( t );
+ }
+
+ return ret;
+ }
+ catch ( final NoClassDefFoundError e )
+ {
+ TestSuite s = new TestSuite( test );
+ s.addTest( new Test()
+ {
+ public int countTestCases()
+ {
+ return 1;
+ }
+
+
+ public void run( TestResult result )
+ {
+ result.addError( this, e );
+ }
+ } );
+ return s;
+ }
+ catch ( final RuntimeException e )
+ {
+ TestSuite s = new TestSuite( test );
+ s.addTest( new Test()
+ {
+ public int countTestCases()
+ {
+ return 1;
+ }
+
+
+ public void run( TestResult result )
+ {
+ result.addError( this, e );
+ }
+
+ } );
+ return s;
+ }
+ }
+
+
+ private void setContext( Test t, BundleContext ctx )
+ {
+ try
+ {
+ Method m = findMethod( t.getClass(), "setBundleContext", BUNDLE_CONTEXT_PARAMS );
+ if ( m != null )
+ m.invoke( t, ctx == null ? bundleContext : ctx );
+ }
+ catch ( SecurityException e )
+ {
+ log.log( Level.WARNING, "Failed to set bundle context on " + t, e );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ log.log( Level.WARNING, "Failed to set bundle context on " + t, e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ log.log( Level.WARNING, "Failed to set bundle context on " + t, e );
+ }
+ catch ( InvocationTargetException e )
+ {
+ log.log( Level.WARNING, "Failed to set bundle context on " + t, e );
+ }
+ }
+
+
+ private Method findMethod( Class<?> clazz, String name, Class<?>[] params )
+ {
+ Method found = null;
+
+ for ( Method m : clazz.getDeclaredMethods() )
+ {
+ if ( m.getName().equals( name ) && Arrays.deepEquals( m.getParameterTypes(), params ) )
+ {
+ found = m;
+ break;
+ }
+ }
+
+ if ( found == null )
+ {
+ Class<?> c = clazz.getSuperclass();
+
+ if ( c != null && c != Object.class )
+ {
+ found = findMethod( c, name, params );
+ }
+ }
+
+ if ( found == null )
+ {
+ for ( Class<?> c : clazz.getInterfaces() )
+ {
+ found = findMethod( c, name, params );
+ if ( found != null )
+ {
+ break;
+ }
+ }
+ }
+
+ return found;
+ }
}
Modified: felix/trunk/sigil/common/junit/src/org/apache/felix/sigil/junit/server/impl/TestClassListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/junit/src/org/apache/felix/sigil/junit/server/impl/TestClassListener.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/junit/src/org/apache/felix/sigil/junit/server/impl/TestClassListener.java (original)
+++ felix/trunk/sigil/common/junit/src/org/apache/felix/sigil/junit/server/impl/TestClassListener.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.junit.server.impl;
+
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.Enumeration;
@@ -34,101 +35,136 @@
import org.osgi.framework.BundleEvent;
import org.osgi.framework.SynchronousBundleListener;
-public class TestClassListener implements SynchronousBundleListener {
- private static final Logger log = Logger.getLogger(TestClassListener.class.getName());
-
- private final JUnitServiceFactory service;
-
- private HashMap<Long, Class<TestCase>[]> registrations = new HashMap<Long, Class<TestCase>[]>();
-
- public TestClassListener(JUnitServiceFactory service) {
- this.service = service;
- }
-
- public void bundleChanged(BundleEvent event) {
- switch( event.getType() ) {
- case BundleEvent.RESOLVED:
- index( event.getBundle() );
- break;
- case BundleEvent.UNRESOLVED:
- unindex( event.getBundle() );
- break;
- }
- }
-
- void index(Bundle bundle) {
- if ( isTestBundle( bundle ) ) {
- List<String> tests = findTests( bundle );
-
- if ( !tests.isEmpty() ) {
- LinkedList<Class<? extends TestCase>> regs = new LinkedList<Class<? extends TestCase>>();
-
- for ( String jc : tests ) {
- try {
- Class<?> clazz = bundle.loadClass(jc);
- if ( isTestCase(clazz) ) {
- Class<? extends TestCase> tc = clazz.asSubclass(TestCase.class);
- regs.add( tc );
- service.registerTest(tc);
- }
- } catch (ClassNotFoundException e) {
- log.log( Level.WARNING, "Failed to load class " + jc, e );
- } catch (NoClassDefFoundError e) {
- log.log( Level.WARNING, "Failed to load class " + jc, e );
- }
- }
-
- registrations.put( bundle.getBundleId(), toArray(regs) );
- }
- }
- }
-
- private boolean isTestBundle(Bundle bundle) {
- try {
- bundle.loadClass(TestCase.class.getName());
- return true;
- } catch (ClassNotFoundException e) {
- return false;
- }
- }
-
- @SuppressWarnings("unchecked")
- private Class<TestCase>[] toArray(LinkedList<Class<? extends TestCase>> regs) {
- return regs.toArray( new Class[regs.size()] );
- }
-
- private boolean isTestCase(Class<?> clazz) {
- return
- TestCase.class.isAssignableFrom(clazz) &&
- !Modifier.isAbstract(clazz.getModifiers()) &&
- !clazz.getPackage().getName().startsWith( "junit" );
- }
-
- void unindex(Bundle bundle) {
- Class<TestCase>[] classes = registrations.remove(bundle.getBundleId());
- if ( classes != null ) {
- for ( Class<TestCase> tc : classes ) {
- service.unregister(tc);
- }
- }
- }
-
- private List<String> findTests(Bundle bundle) {
- @SuppressWarnings("unchecked") Enumeration<URL> urls = bundle.findEntries("", "*.class", true);
-
- LinkedList<String> tests = new LinkedList<String>();
- while( urls.hasMoreElements() ) {
- URL url = urls.nextElement();
- tests.add( toClassName( url ) );
- }
-
- return tests;
- }
-
- private String toClassName(URL url) {
- String f = url.getFile();
- String cn = f.substring(1, f.length() - 6 );
- return cn.replace('/', '.');
- }
+
+public class TestClassListener implements SynchronousBundleListener
+{
+ private static final Logger log = Logger.getLogger( TestClassListener.class.getName() );
+
+ private final JUnitServiceFactory service;
+
+ private HashMap<Long, Class<TestCase>[]> registrations = new HashMap<Long, Class<TestCase>[]>();
+
+
+ public TestClassListener( JUnitServiceFactory service )
+ {
+ this.service = service;
+ }
+
+
+ public void bundleChanged( BundleEvent event )
+ {
+ switch ( event.getType() )
+ {
+ case BundleEvent.RESOLVED:
+ index( event.getBundle() );
+ break;
+ case BundleEvent.UNRESOLVED:
+ unindex( event.getBundle() );
+ break;
+ }
+ }
+
+
+ void index( Bundle bundle )
+ {
+ if ( isTestBundle( bundle ) )
+ {
+ List<String> tests = findTests( bundle );
+
+ if ( !tests.isEmpty() )
+ {
+ LinkedList<Class<? extends TestCase>> regs = new LinkedList<Class<? extends TestCase>>();
+
+ for ( String jc : tests )
+ {
+ try
+ {
+ Class<?> clazz = bundle.loadClass( jc );
+ if ( isTestCase( clazz ) )
+ {
+ Class<? extends TestCase> tc = clazz.asSubclass( TestCase.class );
+ regs.add( tc );
+ service.registerTest( tc );
+ }
+ }
+ catch ( ClassNotFoundException e )
+ {
+ log.log( Level.WARNING, "Failed to load class " + jc, e );
+ }
+ catch ( NoClassDefFoundError e )
+ {
+ log.log( Level.WARNING, "Failed to load class " + jc, e );
+ }
+ }
+
+ registrations.put( bundle.getBundleId(), toArray( regs ) );
+ }
+ }
+ }
+
+
+ private boolean isTestBundle( Bundle bundle )
+ {
+ try
+ {
+ bundle.loadClass( TestCase.class.getName() );
+ return true;
+ }
+ catch ( ClassNotFoundException e )
+ {
+ return false;
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private Class<TestCase>[] toArray( LinkedList<Class<? extends TestCase>> regs )
+ {
+ return regs.toArray( new Class[regs.size()] );
+ }
+
+
+ private boolean isTestCase( Class<?> clazz )
+ {
+ return TestCase.class.isAssignableFrom( clazz ) && !Modifier.isAbstract( clazz.getModifiers() )
+ && !clazz.getPackage().getName().startsWith( "junit" );
+ }
+
+
+ void unindex( Bundle bundle )
+ {
+ Class<TestCase>[] classes = registrations.remove( bundle.getBundleId() );
+ if ( classes != null )
+ {
+ for ( Class<TestCase> tc : classes )
+ {
+ service.unregister( tc );
+ }
+ }
+ }
+
+
+ private List<String> findTests( Bundle bundle )
+ {
+ @SuppressWarnings("unchecked")
+ Enumeration<URL> urls = bundle.findEntries( "", "*.class", true );
+
+ LinkedList<String> tests = new LinkedList<String>();
+ while ( urls.hasMoreElements() )
+ {
+ URL url = urls.nextElement();
+ tests.add( toClassName( url ) );
+ }
+
+ return tests;
+ }
+
+
+ private String toClassName( URL url )
+ {
+ String f = url.getFile();
+ String cn = f.substring( 1, f.length() - 6 );
+ return cn.replace( '/', '.' );
+ }
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/AbstractOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/AbstractOBRBundleRepository.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/AbstractOBRBundleRepository.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/AbstractOBRBundleRepository.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.obr;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -32,113 +33,153 @@
import org.apache.felix.sigil.repository.AbstractBundleRepository;
-public abstract class AbstractOBRBundleRepository extends AbstractBundleRepository {
- private static SAXParserFactory factory = SAXParserFactory.newInstance();
-
- private URL obrURL;
- private File obrlCache;
- private File bundleCache;
- private long updatePeriod;
-
- public AbstractOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod) {
- super(id);
- this.obrURL = repositoryURL;
- this.obrlCache = obrCache;
- this.bundleCache = bundleCache;
- this.updatePeriod = updatePeriod;
- }
-
- public void refresh() {
- obrlCache.delete();
- }
-
- protected void readBundles(OBRListener listener) throws Exception {
- syncOBRIndex();
- OBRHandler handler = new OBRHandler(getObrURL(), getBundleCache(), listener);
- SAXParser parser = factory.newSAXParser();
- parser.parse(getObrlCache(), handler );
- }
-
- private void syncOBRIndex() {
- if ( isUpdated() ) {
- InputStream in = null;
- OutputStream out = null;
-
- try {
- URLConnection c = getObrURL().openConnection();
- c.connect();
- in = c.getInputStream();
- File file = getObrlCache();
- if ( !file.getParentFile().mkdirs() ) {
- throw new IOException( "Failed to create obr cache" );
- }
- out = new FileOutputStream(file);
- stream(in, out);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- getObrlCache().setLastModified(0);
- }
- finally {
- close(in, out);
- }
- }
- }
-
- private void close(InputStream in, OutputStream out) {
- if ( in != null ) {
- try {
- in.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if ( out != null ) {
- try {
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- private void stream(InputStream in, OutputStream out) throws IOException {
- byte[] buf = new byte[1024];
- for(;;) {
- int r = in.read(buf);
- if ( r == -1 ) {
- break;
- }
- out.write(buf, 0, r);
- }
- out.flush();
- }
-
- private boolean isUpdated() {
- if ( !getObrlCache().exists() ) {
- return true;
- }
-
- return getObrlCache().lastModified() + getUpdatePeriod() < System.currentTimeMillis();
- }
-
- public URL getObrURL() {
- return obrURL;
- }
-
- public File getObrlCache() {
- return obrlCache;
- }
-
- public File getBundleCache() {
- return bundleCache;
- }
-
- public long getUpdatePeriod() {
- return updatePeriod;
- }
+public abstract class AbstractOBRBundleRepository extends AbstractBundleRepository
+{
+ private static SAXParserFactory factory = SAXParserFactory.newInstance();
+
+ private URL obrURL;
+ private File obrlCache;
+ private File bundleCache;
+ private long updatePeriod;
+
+
+ public AbstractOBRBundleRepository( String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod )
+ {
+ super( id );
+ this.obrURL = repositoryURL;
+ this.obrlCache = obrCache;
+ this.bundleCache = bundleCache;
+ this.updatePeriod = updatePeriod;
+ }
+
+
+ public void refresh()
+ {
+ obrlCache.delete();
+ }
+
+
+ protected void readBundles( OBRListener listener ) throws Exception
+ {
+ syncOBRIndex();
+ OBRHandler handler = new OBRHandler( getObrURL(), getBundleCache(), listener );
+ SAXParser parser = factory.newSAXParser();
+ parser.parse( getObrlCache(), handler );
+ }
+
+
+ private void syncOBRIndex()
+ {
+ if ( isUpdated() )
+ {
+ InputStream in = null;
+ OutputStream out = null;
+
+ try
+ {
+ URLConnection c = getObrURL().openConnection();
+ c.connect();
+ in = c.getInputStream();
+ File file = getObrlCache();
+ if ( !file.getParentFile().mkdirs() )
+ {
+ throw new IOException( "Failed to create obr cache" );
+ }
+ out = new FileOutputStream( file );
+ stream( in, out );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ getObrlCache().setLastModified( 0 );
+ }
+ finally
+ {
+ close( in, out );
+ }
+ }
+ }
+
+
+ private void close( InputStream in, OutputStream out )
+ {
+ if ( in != null )
+ {
+ try
+ {
+ in.close();
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if ( out != null )
+ {
+ try
+ {
+ out.close();
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ private void stream( InputStream in, OutputStream out ) throws IOException
+ {
+ byte[] buf = new byte[1024];
+ for ( ;; )
+ {
+ int r = in.read( buf );
+ if ( r == -1 )
+ {
+ break;
+ }
+ out.write( buf, 0, r );
+ }
+ out.flush();
+ }
+
+
+ private boolean isUpdated()
+ {
+ if ( !getObrlCache().exists() )
+ {
+ return true;
+ }
+
+ return getObrlCache().lastModified() + getUpdatePeriod() < System.currentTimeMillis();
+ }
+
+
+ public URL getObrURL()
+ {
+ return obrURL;
+ }
+
+
+ public File getObrlCache()
+ {
+ return obrlCache;
+ }
+
+
+ public File getBundleCache()
+ {
+ return bundleCache;
+ }
+
+
+ public long getUpdatePeriod()
+ {
+ return updatePeriod;
+ }
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/CachingOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/CachingOBRBundleRepository.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/CachingOBRBundleRepository.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/CachingOBRBundleRepository.java Tue Jul 21 18:51:33 2009
@@ -19,59 +19,78 @@
package org.apache.felix.sigil.obr;
+
import java.io.File;
import java.lang.ref.SoftReference;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
-
import org.apache.felix.sigil.model.eclipse.ISigilBundle;
import org.apache.felix.sigil.repository.IRepositoryVisitor;
-public class CachingOBRBundleRepository extends AbstractOBRBundleRepository {
- private SoftReference<List<ISigilBundle>> bundles;
-
- public CachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod) {
- super(id, repositoryURL, obrCache, bundleCache, updatePeriod);
- }
-
- @Override
- public void accept(IRepositoryVisitor visitor, int options) {
- for ( ISigilBundle b : loadFromCache(options) ) {
- if ( !visitor.visit(b) ) {
- break;
- }
- }
- }
-
- public synchronized void refresh() {
- super.refresh();
- if ( bundles != null ) {
- bundles.clear();
- notifyChange();
- }
- }
-
- private synchronized List<ISigilBundle> loadFromCache(int options) {
- List<ISigilBundle> cached = bundles == null ? null : bundles.get();
- if ( cached == null ) {
- try {
- final LinkedList<ISigilBundle> read = new LinkedList<ISigilBundle>();
- readBundles(new OBRListener() {
- public void handleBundle(ISigilBundle bundle) {
- read.add(bundle);
- }
- });
- cached = read;
- bundles = new SoftReference<List<ISigilBundle>>(cached);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return cached;
- }
+public class CachingOBRBundleRepository extends AbstractOBRBundleRepository
+{
+
+ private SoftReference<List<ISigilBundle>> bundles;
+
+
+ public CachingOBRBundleRepository( String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod )
+ {
+ super( id, repositoryURL, obrCache, bundleCache, updatePeriod );
+ }
+
+
+ @Override
+ public void accept( IRepositoryVisitor visitor, int options )
+ {
+ for ( ISigilBundle b : loadFromCache( options ) )
+ {
+ if ( !visitor.visit( b ) )
+ {
+ break;
+ }
+ }
+ }
+
+
+ public synchronized void refresh()
+ {
+ super.refresh();
+ if ( bundles != null )
+ {
+ bundles.clear();
+ notifyChange();
+ }
+ }
+
+
+ private synchronized List<ISigilBundle> loadFromCache( int options )
+ {
+ List<ISigilBundle> cached = bundles == null ? null : bundles.get();
+ if ( cached == null )
+ {
+ try
+ {
+ final LinkedList<ISigilBundle> read = new LinkedList<ISigilBundle>();
+ readBundles( new OBRListener()
+ {
+ public void handleBundle( ISigilBundle bundle )
+ {
+ read.add( bundle );
+ }
+ } );
+ cached = read;
+ bundles = new SoftReference<List<ISigilBundle>>( cached );
+ }
+ catch ( Exception e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ return cached;
+ }
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/NonCachingOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/NonCachingOBRBundleRepository.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/NonCachingOBRBundleRepository.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/NonCachingOBRBundleRepository.java Tue Jul 21 18:51:33 2009
@@ -19,49 +19,63 @@
package org.apache.felix.sigil.obr;
+
import java.io.File;
import java.net.URL;
import org.apache.felix.sigil.model.eclipse.ISigilBundle;
import org.apache.felix.sigil.repository.IRepositoryVisitor;
-public class NonCachingOBRBundleRepository extends AbstractOBRBundleRepository {
- /*public static void main(String[] args) throws Exception {
- String url = args[0];
- String obr = args[1];
- String cache = args[2];
- String update = args[3];
- BldCore.init();
- NonCachingOBRBundleRepository rep = new NonCachingOBRBundleRepository( "main", new URL(url), new File(obr), new File(cache), Long.parseLong(update));
- rep.accept(new IRepositoryVisitor() {
- public boolean visit(ISigilBundle bundle) {
- System.out.println( "Found " + bundle );
- return true;
- }
- });
- } */
-
- public NonCachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod) {
- super(id, repositoryURL, obrCache, bundleCache, updatePeriod);
- }
-
- @Override
- public void accept(final IRepositoryVisitor visitor, int options) {
- try {
- readBundles(new OBRListener() {
- boolean visit = true;
- public void handleBundle(ISigilBundle bundle) {
- if ( visit ) {
- visit = visitor.visit(bundle);
- }
- }
- });
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+public class NonCachingOBRBundleRepository extends AbstractOBRBundleRepository
+{
+ /*public static void main(String[] args) throws Exception {
+ String url = args[0];
+ String obr = args[1];
+ String cache = args[2];
+ String update = args[3];
+ BldCore.init();
+ NonCachingOBRBundleRepository rep = new NonCachingOBRBundleRepository( "main", new URL(url), new File(obr), new File(cache), Long.parseLong(update));
+ rep.accept(new IRepositoryVisitor() {
+ public boolean visit(ISigilBundle bundle) {
+ System.out.println( "Found " + bundle );
+ return true;
+ }
+ });
+ } */
+
+ public NonCachingOBRBundleRepository( String id, URL repositoryURL, File obrCache, File bundleCache,
+ long updatePeriod )
+ {
+ super( id, repositoryURL, obrCache, bundleCache, updatePeriod );
+ }
+
+
+ @Override
+ public void accept( final IRepositoryVisitor visitor, int options )
+ {
+ try
+ {
+ readBundles( new OBRListener()
+ {
+ boolean visit = true;
+
+
+ public void handleBundle( ISigilBundle bundle )
+ {
+ if ( visit )
+ {
+ visit = visitor.visit( bundle );
+ }
+ }
+ } );
+ }
+ catch ( Exception e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRHandler.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRHandler.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRHandler.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.obr;
+
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
@@ -49,241 +50,320 @@
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
-final class OBRHandler extends DefaultHandler {
- private static final String PACKAGE = "package";
- private static final String URI = "uri";
- private static final String PRESENTATION_NAME = "presentationname";
- private static final String VERSION = "version";
- private static final String SYMBOLIC_NAME = "symbolicname";
- private final File cacheDir;
- private final URL obrURL;
- private final OBRListener listener;
-
- private HashSet<String> sanity = new HashSet<String>();
- private Locator locator;
- private ISigilBundle bundle;
- private IPackageExport export;
-
- public OBRHandler(URL obrURL, File bundleCache, OBRListener listener) {
- this.obrURL = obrURL;
- this.cacheDir = bundleCache;
- this.listener = listener;
- }
-
- public void setDocumentLocator (Locator locator) {
- this.locator = locator;
- }
-
- public void startElement (String uri, String localName,
- String qName, Attributes attributes) throws SAXException {
- if ( "resource".equals( qName ) ) {
- startResource(attributes);
- }
- else if ( "capability".equals( qName ) ) {
- startCapability(attributes);
- }
- else if( "require".equals( qName ) ) {
- startRequire(attributes);
- }
- else if ( "p".equals( qName ) ) {
- startProperty(attributes);
- }
- }
-
- public void endElement (String uri, String localName, String qName)
- throws SAXException {
- if ( "resource".equals( qName ) ) {
- endResource();
- }
- else if ( "capability".equals( qName ) ) {
- endCapability();
- }
- else if( "require".equals( qName ) ) {
- endRequire();
- }
- else if ( "p".equals( qName ) ) {
- endProperty();
- }
- }
-
- private void startResource(Attributes attributes) throws SAXException {
- try {
- String uri = attributes.getValue("", URI);
- if ( uri.endsWith( ".jar" ) ) {
- if ( !sanity.add(uri) ) {
- throw new RuntimeException(uri);
- }
- ISigilBundle b = ModelElementFactory.getInstance().newModelElement(ISigilBundle.class);
- IBundleModelElement info = ModelElementFactory.getInstance().newModelElement(IBundleModelElement.class);
- info.setSymbolicName(attributes.getValue("", SYMBOLIC_NAME));
- info.setVersion(new Version(attributes.getValue("", VERSION)));
- info.setName(attributes.getValue("", PRESENTATION_NAME));
- URI l = makeAbsolute(uri);
- info.setUpdateLocation(l);
- b.setLocation(cachePath(info));
- b.setBundleInfo(info);
- bundle = b;
- }
- }
- catch (Exception e) {
- throw new SAXParseException("Failed to build bundle info", locator, e);
- }
- }
-
- private URI makeAbsolute(String uri) throws URISyntaxException {
- URI l = new URI(uri);
- if ( !l.isAbsolute() ) {
- String base = obrURL.toExternalForm();
- int i = base.lastIndexOf("/");
- if ( i != -1 ) {
- base = base.substring(0, i);
- l = new URI( base + (uri.startsWith("/") ? "" : "/") + uri );
- }
- }
- return l;
- }
-
- private IPath cachePath(IBundleModelElement info) {
- return new Path(cacheDir.getAbsolutePath()).append( info.getSymbolicName() + "_" + info.getVersion() + ".jar" );
- }
-
- private void startCapability(Attributes attributes) {
- if ( bundle != null ) {
- if ( PACKAGE.equals( attributes.getValue("", "name") ) ) {
- export = ModelElementFactory.getInstance().newModelElement(IPackageExport.class);
- }
- }
- }
-
- private void startRequire(Attributes attributes) throws SAXParseException {
- if ( bundle != null ) {
- String name = attributes.getValue("name");
- if ( PACKAGE.equals( name ) ) {
- IPackageImport pi = ModelElementFactory.getInstance().newModelElement(IPackageImport.class);
- try {
- LDAPExpr expr = LDAPParser.parseExpression(attributes.getValue("filter") );
- pi.setPackageName(decodePackage(expr, locator));
- pi.setVersions(decodeVersions(expr, locator));
- pi.setOptional(Boolean.valueOf(attributes.getValue("optional")));
- bundle.getBundleInfo().addImport(pi);
- } catch (LDAPParseException e) {
- throw new SAXParseException("Failed to parse filter", locator, e);
- }
- }
- else if ( "bundle".equals( name ) ) {
- IRequiredBundle b = ModelElementFactory.getInstance().newModelElement(IRequiredBundle.class);
- try {
- LDAPExpr expr = LDAPParser.parseExpression(attributes.getValue("filter") );
- b.setSymbolicName(decodeSymbolicName(expr, locator));
- b.setVersions(decodeVersions(expr, locator));
- b.setOptional(Boolean.valueOf(attributes.getValue("optional")));
- bundle.getBundleInfo().addRequiredBundle(b);
- } catch (Exception e) {
- System.err.println( "Failed to parse filter in bundle " + bundle.getBundleInfo().getSymbolicName() );
- throw new SAXParseException("Failed to parse filter in bundle " + bundle.getBundleInfo().getSymbolicName(), locator, e);
- }
- }
- //else if ( "ee".equals( name ) ) {
- // TODO ignore for now...
- //}
- //else if ( "service".equals( name ) ) {
- // TODO ignore for now...
- //}
- //else {
- // for ( int i = 0; i < attributes.getLength(); i++ ) {
- // System.out.println( "Found requirement " + attributes.getValue(i) );
- // }
- //}
- }
- }
-
- private static VersionRange decodeVersions(LDAPExpr expr, Locator locator) throws SAXParseException {
- try {
- return VersionRangeHelper.decodeVersions(expr);
- }
- catch (NumberFormatException e) {
- throw new SAXParseException(e.getMessage(), locator);
- }
- }
-
- private void startProperty(Attributes attributes) {
- if ( export != null ) {
- String name = attributes.getValue("", "n");
- String value = attributes.getValue("", "v");
- if ( PACKAGE.equals( name ) ) {
- export.setPackageName(value);
- }
- else if ( "uses".equals( name ) ) {
- String[] split = value.split(",");
- export.setUses( Arrays.asList(split) );
- }
- else if ( "version".equals( name ) ) {
- export.setVersion( new Version(value) );
- }
- }
- }
-
- private void endResource() {
- if ( bundle != null ) {
- listener.handleBundle(bundle);
- bundle = null;
- }
- }
-
- private void endCapability() {
- if ( bundle != null ) {
- if ( export != null ) {
- bundle.getBundleInfo().addExport(export);
- export = null;
- }
- }
- }
-
- private void endRequire() {
- // TODO Auto-generated method stub
-
- }
-
- private void endProperty() {
- // TODO Auto-generated method stub
-
- }
-
- private static String decodePackage(LDAPExpr expr, Locator locator) throws SAXParseException {
- ArrayList<SimpleTerm> terms = new ArrayList<SimpleTerm>(1);
-
- findTerms("package", expr, terms);
-
- if ( terms.isEmpty() ) {
- throw new SAXParseException("Missing name filter in " + expr, locator);
- }
-
- return terms.get(0).getRval();
- }
-
- private static String decodeSymbolicName(LDAPExpr expr, Locator locator) throws SAXParseException {
- ArrayList<SimpleTerm> terms = new ArrayList<SimpleTerm>(1);
-
- findTerms("symbolicname", expr, terms);
-
- if ( terms.isEmpty() ) {
- throw new SAXParseException("Missing name filter in " + expr, locator);
- }
-
- return terms.get(0).getRval();
- }
-
- private static void findTerms(String string, LDAPExpr expr, List<SimpleTerm> terms) throws SAXParseException {
- if ( expr instanceof SimpleTerm ) {
- SimpleTerm term = (SimpleTerm) expr;
- if ( term.getName().equals(string) ) {
- terms.add(term);
- }
- }
- else {
- for ( LDAPExpr c : expr.getChildren() ) {
- findTerms(string, c, terms);
- }
- }
- }
+
+final class OBRHandler extends DefaultHandler
+{
+ private static final String PACKAGE = "package";
+ private static final String URI = "uri";
+ private static final String PRESENTATION_NAME = "presentationname";
+ private static final String VERSION = "version";
+ private static final String SYMBOLIC_NAME = "symbolicname";
+ private final File cacheDir;
+ private final URL obrURL;
+ private final OBRListener listener;
+
+ private HashSet<String> sanity = new HashSet<String>();
+ private Locator locator;
+ private ISigilBundle bundle;
+ private IPackageExport export;
+
+
+ public OBRHandler( URL obrURL, File bundleCache, OBRListener listener )
+ {
+ this.obrURL = obrURL;
+ this.cacheDir = bundleCache;
+ this.listener = listener;
+ }
+
+
+ public void setDocumentLocator( Locator locator )
+ {
+ this.locator = locator;
+ }
+
+
+ public void startElement( String uri, String localName, String qName, Attributes attributes ) throws SAXException
+ {
+ if ( "resource".equals( qName ) )
+ {
+ startResource( attributes );
+ }
+ else if ( "capability".equals( qName ) )
+ {
+ startCapability( attributes );
+ }
+ else if ( "require".equals( qName ) )
+ {
+ startRequire( attributes );
+ }
+ else if ( "p".equals( qName ) )
+ {
+ startProperty( attributes );
+ }
+ }
+
+
+ public void endElement( String uri, String localName, String qName ) throws SAXException
+ {
+ if ( "resource".equals( qName ) )
+ {
+ endResource();
+ }
+ else if ( "capability".equals( qName ) )
+ {
+ endCapability();
+ }
+ else if ( "require".equals( qName ) )
+ {
+ endRequire();
+ }
+ else if ( "p".equals( qName ) )
+ {
+ endProperty();
+ }
+ }
+
+
+ private void startResource( Attributes attributes ) throws SAXException
+ {
+ try
+ {
+ String uri = attributes.getValue( "", URI );
+ if ( uri.endsWith( ".jar" ) )
+ {
+ if ( !sanity.add( uri ) )
+ {
+ throw new RuntimeException( uri );
+ }
+ ISigilBundle b = ModelElementFactory.getInstance().newModelElement( ISigilBundle.class );
+ IBundleModelElement info = ModelElementFactory.getInstance()
+ .newModelElement( IBundleModelElement.class );
+ info.setSymbolicName( attributes.getValue( "", SYMBOLIC_NAME ) );
+ info.setVersion( new Version( attributes.getValue( "", VERSION ) ) );
+ info.setName( attributes.getValue( "", PRESENTATION_NAME ) );
+ URI l = makeAbsolute( uri );
+ info.setUpdateLocation( l );
+ b.setLocation( cachePath( info ) );
+ b.setBundleInfo( info );
+ bundle = b;
+ }
+ }
+ catch ( Exception e )
+ {
+ throw new SAXParseException( "Failed to build bundle info", locator, e );
+ }
+ }
+
+
+ private URI makeAbsolute( String uri ) throws URISyntaxException
+ {
+ URI l = new URI( uri );
+ if ( !l.isAbsolute() )
+ {
+ String base = obrURL.toExternalForm();
+ int i = base.lastIndexOf( "/" );
+ if ( i != -1 )
+ {
+ base = base.substring( 0, i );
+ l = new URI( base + ( uri.startsWith( "/" ) ? "" : "/" ) + uri );
+ }
+ }
+ return l;
+ }
+
+
+ private IPath cachePath( IBundleModelElement info )
+ {
+ return new Path( cacheDir.getAbsolutePath() )
+ .append( info.getSymbolicName() + "_" + info.getVersion() + ".jar" );
+ }
+
+
+ private void startCapability( Attributes attributes )
+ {
+ if ( bundle != null )
+ {
+ if ( PACKAGE.equals( attributes.getValue( "", "name" ) ) )
+ {
+ export = ModelElementFactory.getInstance().newModelElement( IPackageExport.class );
+ }
+ }
+ }
+
+
+ private void startRequire( Attributes attributes ) throws SAXParseException
+ {
+ if ( bundle != null )
+ {
+ String name = attributes.getValue( "name" );
+ if ( PACKAGE.equals( name ) )
+ {
+ IPackageImport pi = ModelElementFactory.getInstance().newModelElement( IPackageImport.class );
+ try
+ {
+ LDAPExpr expr = LDAPParser.parseExpression( attributes.getValue( "filter" ) );
+ pi.setPackageName( decodePackage( expr, locator ) );
+ pi.setVersions( decodeVersions( expr, locator ) );
+ pi.setOptional( Boolean.valueOf( attributes.getValue( "optional" ) ) );
+ bundle.getBundleInfo().addImport( pi );
+ }
+ catch ( LDAPParseException e )
+ {
+ throw new SAXParseException( "Failed to parse filter", locator, e );
+ }
+ }
+ else if ( "bundle".equals( name ) )
+ {
+ IRequiredBundle b = ModelElementFactory.getInstance().newModelElement( IRequiredBundle.class );
+ try
+ {
+ LDAPExpr expr = LDAPParser.parseExpression( attributes.getValue( "filter" ) );
+ b.setSymbolicName( decodeSymbolicName( expr, locator ) );
+ b.setVersions( decodeVersions( expr, locator ) );
+ b.setOptional( Boolean.valueOf( attributes.getValue( "optional" ) ) );
+ bundle.getBundleInfo().addRequiredBundle( b );
+ }
+ catch ( Exception e )
+ {
+ System.err.println( "Failed to parse filter in bundle " + bundle.getBundleInfo().getSymbolicName() );
+ throw new SAXParseException( "Failed to parse filter in bundle "
+ + bundle.getBundleInfo().getSymbolicName(), locator, e );
+ }
+ }
+ //else if ( "ee".equals( name ) ) {
+ // TODO ignore for now...
+ //}
+ //else if ( "service".equals( name ) ) {
+ // TODO ignore for now...
+ //}
+ //else {
+ // for ( int i = 0; i < attributes.getLength(); i++ ) {
+ // System.out.println( "Found requirement " + attributes.getValue(i) );
+ // }
+ //}
+ }
+ }
+
+
+ private static VersionRange decodeVersions( LDAPExpr expr, Locator locator ) throws SAXParseException
+ {
+ try
+ {
+ return VersionRangeHelper.decodeVersions( expr );
+ }
+ catch ( NumberFormatException e )
+ {
+ throw new SAXParseException( e.getMessage(), locator );
+ }
+ }
+
+
+ private void startProperty( Attributes attributes )
+ {
+ if ( export != null )
+ {
+ String name = attributes.getValue( "", "n" );
+ String value = attributes.getValue( "", "v" );
+ if ( PACKAGE.equals( name ) )
+ {
+ export.setPackageName( value );
+ }
+ else if ( "uses".equals( name ) )
+ {
+ String[] split = value.split( "," );
+ export.setUses( Arrays.asList( split ) );
+ }
+ else if ( "version".equals( name ) )
+ {
+ export.setVersion( new Version( value ) );
+ }
+ }
+ }
+
+
+ private void endResource()
+ {
+ if ( bundle != null )
+ {
+ listener.handleBundle( bundle );
+ bundle = null;
+ }
+ }
+
+
+ private void endCapability()
+ {
+ if ( bundle != null )
+ {
+ if ( export != null )
+ {
+ bundle.getBundleInfo().addExport( export );
+ export = null;
+ }
+ }
+ }
+
+
+ private void endRequire()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ private void endProperty()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ private static String decodePackage( LDAPExpr expr, Locator locator ) throws SAXParseException
+ {
+ ArrayList<SimpleTerm> terms = new ArrayList<SimpleTerm>( 1 );
+
+ findTerms( "package", expr, terms );
+
+ if ( terms.isEmpty() )
+ {
+ throw new SAXParseException( "Missing name filter in " + expr, locator );
+ }
+
+ return terms.get( 0 ).getRval();
+ }
+
+
+ private static String decodeSymbolicName( LDAPExpr expr, Locator locator ) throws SAXParseException
+ {
+ ArrayList<SimpleTerm> terms = new ArrayList<SimpleTerm>( 1 );
+
+ findTerms( "symbolicname", expr, terms );
+
+ if ( terms.isEmpty() )
+ {
+ throw new SAXParseException( "Missing name filter in " + expr, locator );
+ }
+
+ return terms.get( 0 ).getRval();
+ }
+
+
+ private static void findTerms( String string, LDAPExpr expr, List<SimpleTerm> terms ) throws SAXParseException
+ {
+ if ( expr instanceof SimpleTerm )
+ {
+ SimpleTerm term = ( SimpleTerm ) expr;
+ if ( term.getName().equals( string ) )
+ {
+ terms.add( term );
+ }
+ }
+ else
+ {
+ for ( LDAPExpr c : expr.getChildren() )
+ {
+ findTerms( string, c, terms );
+ }
+ }
+ }
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRListener.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRListener.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRListener.java Tue Jul 21 18:51:33 2009
@@ -19,8 +19,11 @@
package org.apache.felix.sigil.obr;
+
import org.apache.felix.sigil.model.eclipse.ISigilBundle;
-public interface OBRListener {
- void handleBundle(ISigilBundle bundle);
+
+public interface OBRListener
+{
+ void handleBundle( ISigilBundle bundle );
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRRepositoryProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRRepositoryProvider.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRRepositoryProvider.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/OBRRepositoryProvider.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.obr;
+
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
@@ -29,23 +30,30 @@
import org.apache.felix.sigil.repository.IRepositoryProvider;
import org.apache.felix.sigil.repository.RepositoryException;
-public class OBRRepositoryProvider implements IRepositoryProvider {
- public IBundleRepository createRepository(String id, Properties preferences) throws RepositoryException {
- try {
- URL repositoryURL = new URL( preferences.getProperty("url") );
- File indexCache = new File( preferences.getProperty("index") );
- File localCache = new File( preferences.getProperty("cache") );
- // TODO create user configurable updatePeriod
- long updatePeriod = TimeUnit.MILLISECONDS.convert(60*60*24*7, TimeUnit.SECONDS);
- if ( preferences.getProperty("inmemory") == null ) {
- return new NonCachingOBRBundleRepository(id, repositoryURL, indexCache, localCache, updatePeriod);
- }
- else {
- return new CachingOBRBundleRepository(id, repositoryURL, indexCache, localCache, updatePeriod);
- }
- }
- catch (MalformedURLException e) {
- throw new RepositoryException("Invalid repository url", e);
- }
- }
+
+public class OBRRepositoryProvider implements IRepositoryProvider
+{
+ public IBundleRepository createRepository( String id, Properties preferences ) throws RepositoryException
+ {
+ try
+ {
+ URL repositoryURL = new URL( preferences.getProperty( "url" ) );
+ File indexCache = new File( preferences.getProperty( "index" ) );
+ File localCache = new File( preferences.getProperty( "cache" ) );
+ // TODO create user configurable updatePeriod
+ long updatePeriod = TimeUnit.MILLISECONDS.convert( 60 * 60 * 24 * 7, TimeUnit.SECONDS );
+ if ( preferences.getProperty( "inmemory" ) == null )
+ {
+ return new NonCachingOBRBundleRepository( id, repositoryURL, indexCache, localCache, updatePeriod );
+ }
+ else
+ {
+ return new CachingOBRBundleRepository( id, repositoryURL, indexCache, localCache, updatePeriod );
+ }
+ }
+ catch ( MalformedURLException e )
+ {
+ throw new RepositoryException( "Invalid repository url", e );
+ }
+ }
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/VersionRangeHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/VersionRangeHelper.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/VersionRangeHelper.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/VersionRangeHelper.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.obr;
+
import java.util.ArrayList;
import java.util.List;
@@ -31,162 +32,208 @@
import org.apache.felix.sigil.model.common.VersionRange;
import org.osgi.framework.Version;
-class VersionRangeHelper {
-
- // e.g. (&(version>=1.0.0)(version<=2.0.0)) (&(version>1.0.0)(version<2.0.0)) (&(!(version<1.0.0))(!(version>2.0.0))) (&(!(version<=1.0.0))(!(version>=2.0.0))) (version=1.0.0) (version>=1.0.0) (version<=2.0.0) (version>1.0.0) (version<2.0.0) (!(version>2.0.0)) (!(version<1.0.0)) (!(version>=2.0.0)) (!(version<=1.0.0))
- public static void main(String[] args) throws LDAPParseException {
- for ( String arg : args ) {
- LDAPExpr expr = LDAPParser.parseExpression(arg.trim());
- System.out.println( expr + " -> " + decodeVersions(expr) );
- }
- }
-
- static VersionRange decodeVersions(LDAPExpr expr) throws NumberFormatException {
- ArrayList<LDAPExpr> terms = new ArrayList<LDAPExpr>(1);
-
- findExpr("version", expr, terms);
-
- if ( terms.isEmpty() ) {
- // woo hoo!
- return VersionRange.ANY_VERSION;
- }
- else {
- switch ( terms.size() ) {
- case 1: {
- return parseSimpleVersionRange(terms.get(0));
- }
- case 2: {
- return parseCompoundVersionRange(terms.get(0), terms.get(1));
- }
- default: {
- // (&(version>=min)(!(version=min))(version<=max)(!(version=max))) - (min,max) - not dealt with!!
- // (&(|(version>min)(version=min))(|(version<max)(version=max))) - [min,max] - not dealt with!!
- throw new NumberFormatException("Failed to parse complicated version expression " + expr);
- }
- }
- }
- }
-
- // (&(version>=min)(version<=max)) - [min,max]
- // (&(version>min)(version<max)) - (min,max)
- //
- // (&(!(version<min))(!(version>max))) - [min,max]
- // (&(!(version<=min))(!(version>=max)) - (min,max)
- private static VersionRange parseCompoundVersionRange(LDAPExpr left, LDAPExpr right) throws NumberFormatException {
- VersionRange one = parseSimpleVersionRange(left);
- VersionRange two = parseSimpleVersionRange(right);
-
- // sanity check
- if ( one.isPointVersion() || two.isPointVersion() ) {
- throw new NumberFormatException("Unexpected point version in compound expression " + left);
- }
-
- VersionRange max = one.getFloor().equals( Version.emptyVersion ) ? one : two;
- VersionRange min = max == one ? two : one;
-
- return new VersionRange( min.isOpenFloor(), min.getFloor(), max.getCeiling(), max.isOpenCeiling() );
- }
-
- // possible variations
- // (version=v) - [v,v]
- //
- // (version>=min) - [min,*)
- // (version<=max) - [0,max]
- //
- // (version>min) - (min,*)
- // (version<max) - [0,max)
- //
- // (!(version>max)) - [0,max]
- // (!(version<min)) - [min,*)
- // (!(version>=max)) - [0,max)
- // (!(version<=min)) - (0,*)
- private static VersionRange parseSimpleVersionRange(LDAPExpr expr) throws NumberFormatException {
- Version min = Version.emptyVersion;
- Version max = VersionRange.INFINITE_VERSION;
- boolean openFloor = false;
- boolean openCeiling = false;
- if ( expr instanceof Not ) {
- Not n = (Not) expr;
- SimpleTerm t = (SimpleTerm) n.getEx();
- if ( t.getOp() == Ops.EQ ) {
- throw new NumberFormatException("Unexpected point version in negated expression " + expr);
- }
- if ( !isMax(t.getOp()) ) {
- max = toVersion(t);
- openCeiling = !openFloor(t);
- }
- else if ( !isMin(t.getOp()) ) {
- min = toVersion(t);
- openFloor = !openCeiling(t);
- }
- else {
- throw new IllegalStateException("Unexpected operator " + t.getOp());
- }
- }
- else {
- SimpleTerm t = (SimpleTerm) expr;
- if ( t.getOp().equals( Ops.EQ ) ) {
- max = toVersion(t);
- min = max;
- openFloor = false;
- openCeiling = false;
- }
- else if ( isMax(t.getOp()) ) {
- max = toVersion(t);
- openCeiling = openCeiling(t);
- }
- else if ( isMin(t.getOp()) ) {
- min = toVersion(t);
- openFloor = openFloor(t);
- }
- else {
- throw new IllegalStateException("Unexpected operator " + t.getOp());
- }
- }
-
- return new VersionRange( openFloor, min, max, openCeiling );
- }
-
- private static Version toVersion(SimpleTerm t) {
- return new Version(t.getRval());
- }
-
- private static boolean isMax(Ops op) {
- return op == Ops.LE || op == Ops.LT;
- }
-
- private static boolean isMin(Ops op) {
- return op == Ops.GE || op == Ops.GT;
- }
-
- private static boolean openFloor(SimpleTerm t) {
- return t.getOp() == Ops.GT;
- }
-
- private static boolean openCeiling(SimpleTerm t) {
- return t.getOp() == Ops.LT;
- }
-
- private static void findExpr(String string, LDAPExpr expr, List<LDAPExpr> terms) {
- if ( expr instanceof SimpleTerm ) {
- SimpleTerm term = (SimpleTerm) expr;
- if ( term.getName().equals(string) ) {
- terms.add(term);
- }
- }
- else if ( expr instanceof Not ) {
- Not not = (Not) expr;
- if ( not.getEx() instanceof SimpleTerm ) {
- SimpleTerm term = (SimpleTerm) not.getEx();
- if ( term.getName().equals(string) ) {
- terms.add(not);
- }
- }
- }
- else {
- for ( LDAPExpr c : expr.getChildren() ) {
- findExpr(string, c, terms);
- }
- }
- }
+
+class VersionRangeHelper
+{
+
+ // e.g. (&(version>=1.0.0)(version<=2.0.0)) (&(version>1.0.0)(version<2.0.0)) (&(!(version<1.0.0))(!(version>2.0.0))) (&(!(version<=1.0.0))(!(version>=2.0.0))) (version=1.0.0) (version>=1.0.0) (version<=2.0.0) (version>1.0.0) (version<2.0.0) (!(version>2.0.0)) (!(version<1.0.0)) (!(version>=2.0.0)) (!(version<=1.0.0))
+ public static void main( String[] args ) throws LDAPParseException
+ {
+ for ( String arg : args )
+ {
+ LDAPExpr expr = LDAPParser.parseExpression( arg.trim() );
+ System.out.println( expr + " -> " + decodeVersions( expr ) );
+ }
+ }
+
+
+ static VersionRange decodeVersions( LDAPExpr expr ) throws NumberFormatException
+ {
+ ArrayList<LDAPExpr> terms = new ArrayList<LDAPExpr>( 1 );
+
+ findExpr( "version", expr, terms );
+
+ if ( terms.isEmpty() )
+ {
+ // woo hoo!
+ return VersionRange.ANY_VERSION;
+ }
+ else
+ {
+ switch ( terms.size() )
+ {
+ case 1:
+ {
+ return parseSimpleVersionRange( terms.get( 0 ) );
+ }
+ case 2:
+ {
+ return parseCompoundVersionRange( terms.get( 0 ), terms.get( 1 ) );
+ }
+ default:
+ {
+ // (&(version>=min)(!(version=min))(version<=max)(!(version=max))) - (min,max) - not dealt with!!
+ // (&(|(version>min)(version=min))(|(version<max)(version=max))) - [min,max] - not dealt with!!
+ throw new NumberFormatException( "Failed to parse complicated version expression " + expr );
+ }
+ }
+ }
+ }
+
+
+ // (&(version>=min)(version<=max)) - [min,max]
+ // (&(version>min)(version<max)) - (min,max)
+ //
+ // (&(!(version<min))(!(version>max))) - [min,max]
+ // (&(!(version<=min))(!(version>=max)) - (min,max)
+ private static VersionRange parseCompoundVersionRange( LDAPExpr left, LDAPExpr right ) throws NumberFormatException
+ {
+ VersionRange one = parseSimpleVersionRange( left );
+ VersionRange two = parseSimpleVersionRange( right );
+
+ // sanity check
+ if ( one.isPointVersion() || two.isPointVersion() )
+ {
+ throw new NumberFormatException( "Unexpected point version in compound expression " + left );
+ }
+
+ VersionRange max = one.getFloor().equals( Version.emptyVersion ) ? one : two;
+ VersionRange min = max == one ? two : one;
+
+ return new VersionRange( min.isOpenFloor(), min.getFloor(), max.getCeiling(), max.isOpenCeiling() );
+ }
+
+
+ // possible variations
+ // (version=v) - [v,v]
+ //
+ // (version>=min) - [min,*)
+ // (version<=max) - [0,max]
+ //
+ // (version>min) - (min,*)
+ // (version<max) - [0,max)
+ //
+ // (!(version>max)) - [0,max]
+ // (!(version<min)) - [min,*)
+ // (!(version>=max)) - [0,max)
+ // (!(version<=min)) - (0,*)
+ private static VersionRange parseSimpleVersionRange( LDAPExpr expr ) throws NumberFormatException
+ {
+ Version min = Version.emptyVersion;
+ Version max = VersionRange.INFINITE_VERSION;
+ boolean openFloor = false;
+ boolean openCeiling = false;
+ if ( expr instanceof Not )
+ {
+ Not n = ( Not ) expr;
+ SimpleTerm t = ( SimpleTerm ) n.getEx();
+ if ( t.getOp() == Ops.EQ )
+ {
+ throw new NumberFormatException( "Unexpected point version in negated expression " + expr );
+ }
+ if ( !isMax( t.getOp() ) )
+ {
+ max = toVersion( t );
+ openCeiling = !openFloor( t );
+ }
+ else if ( !isMin( t.getOp() ) )
+ {
+ min = toVersion( t );
+ openFloor = !openCeiling( t );
+ }
+ else
+ {
+ throw new IllegalStateException( "Unexpected operator " + t.getOp() );
+ }
+ }
+ else
+ {
+ SimpleTerm t = ( SimpleTerm ) expr;
+ if ( t.getOp().equals( Ops.EQ ) )
+ {
+ max = toVersion( t );
+ min = max;
+ openFloor = false;
+ openCeiling = false;
+ }
+ else if ( isMax( t.getOp() ) )
+ {
+ max = toVersion( t );
+ openCeiling = openCeiling( t );
+ }
+ else if ( isMin( t.getOp() ) )
+ {
+ min = toVersion( t );
+ openFloor = openFloor( t );
+ }
+ else
+ {
+ throw new IllegalStateException( "Unexpected operator " + t.getOp() );
+ }
+ }
+
+ return new VersionRange( openFloor, min, max, openCeiling );
+ }
+
+
+ private static Version toVersion( SimpleTerm t )
+ {
+ return new Version( t.getRval() );
+ }
+
+
+ private static boolean isMax( Ops op )
+ {
+ return op == Ops.LE || op == Ops.LT;
+ }
+
+
+ private static boolean isMin( Ops op )
+ {
+ return op == Ops.GE || op == Ops.GT;
+ }
+
+
+ private static boolean openFloor( SimpleTerm t )
+ {
+ return t.getOp() == Ops.GT;
+ }
+
+
+ private static boolean openCeiling( SimpleTerm t )
+ {
+ return t.getOp() == Ops.LT;
+ }
+
+
+ private static void findExpr( String string, LDAPExpr expr, List<LDAPExpr> terms )
+ {
+ if ( expr instanceof SimpleTerm )
+ {
+ SimpleTerm term = ( SimpleTerm ) expr;
+ if ( term.getName().equals( string ) )
+ {
+ terms.add( term );
+ }
+ }
+ else if ( expr instanceof Not )
+ {
+ Not not = ( Not ) expr;
+ if ( not.getEx() instanceof SimpleTerm )
+ {
+ SimpleTerm term = ( SimpleTerm ) not.getEx();
+ if ( term.getName().equals( string ) )
+ {
+ terms.add( not );
+ }
+ }
+ }
+ else
+ {
+ for ( LDAPExpr c : expr.getChildren() )
+ {
+ findExpr( string, c, terms );
+ }
+ }
+ }
}