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 [4/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/core/src/org/apache/felix/sigil/core/internal/model/eclipse/SigilBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/eclipse/SigilBundle.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/eclipse/SigilBundle.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/eclipse/SigilBundle.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.core.internal.model.eclipse;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -45,14 +46,16 @@
import org.eclipse.core.runtime.SubMonitor;
import org.osgi.framework.Version;
+
/**
* @author dave
*
*/
-public class SigilBundle extends AbstractCompoundModelElement implements ISigilBundle {
-
- private static final long serialVersionUID = 1L;
-
+public class SigilBundle extends AbstractCompoundModelElement implements ISigilBundle
+{
+
+ private static final long serialVersionUID = 1L;
+
private IBundleModelElement bundle;
private IDownloadJar download;
private Set<IPath> sourcePaths;
@@ -63,13 +66,15 @@
private Set<String> dlPackages;
private IPath location;
- private IPath sourcePathLocation;
- private IPath licencePathLocation;
- private IPath sourceRootPath;
- private String bundleHost;
-
- public SigilBundle() {
- super( "Sigil Bundle" );
+ private IPath sourcePathLocation;
+ private IPath licencePathLocation;
+ private IPath sourceRootPath;
+ private String bundleHost;
+
+
+ public SigilBundle()
+ {
+ super( "Sigil Bundle" );
sourcePaths = new HashSet<IPath>();
libraryPaths = new HashSet<IPath>();
composites = new HashSet<ISCAComposite>();
@@ -77,280 +82,410 @@
packages = new HashSet<String>();
dlPackages = new HashSet<String>();
}
-
- public void synchronize(IProgressMonitor monitor) throws IOException {
- SubMonitor progress = SubMonitor.convert(monitor, 100);
- progress.subTask("Synchronizing " + bundle.getSymbolicName() + " binary" );
- sync(location, bundle.getUpdateLocation(), progress.newChild(45));
-
- try {
- progress.subTask("Synchronizing " + bundle.getSymbolicName() + " source" );
- sync(sourcePathLocation, bundle.getSourceLocation(), progress.newChild(45));
- } catch (IOException e) {
- BldCore.error( "Failed to download source for " + bundle.getSymbolicName() + " " + bundle.getVersion(), e.getCause() );
- }
-
- try {
- progress.subTask("Synchronizing " + bundle.getSymbolicName() + " licence" );
- sync(licencePathLocation, bundle.getLicenseURI(), progress.newChild(10));
- } catch (IOException e) {
- BldCore.error( "Failed to download licence for " + bundle.getSymbolicName() + " " + bundle.getVersion(), e.getCause() );
- }
- }
-
- public boolean isSynchronized() {
- return location == null || location.toFile().exists();
- }
-
- private static void sync(IPath local, URI remote, IProgressMonitor monitor) throws IOException {
- try {
- if ( local != null && !local.toFile().exists() ) {
- if ( remote != null ) {
- URL url = remote.toURL();
- URLConnection connection = url.openConnection();
- int contentLength = connection.getContentLength();
-
- monitor.beginTask("Downloading from " + url.getHost(), contentLength);
-
- InputStream in = null;
- OutputStream out = null;
- try {
- URLConnection conn = url.openConnection();
- if ( conn instanceof HttpURLConnection ) {
- HttpURLConnection http = (HttpURLConnection) conn;
- http.setConnectTimeout(10000);
- http.setReadTimeout(5000);
- }
- in = conn.getInputStream();
- File f = local.toFile();
- f.getParentFile().mkdirs();
- out = new FileOutputStream( f );
- stream( in, out, monitor );
- }
- finally {
- if ( in != null ) {
- in.close();
- }
- if ( out != null ) {
- out.close();
- }
- monitor.done();
- }
- }
- }
- }
- catch (IOException e) {
- local.toFile().delete();
- throw e;
- }
- }
-
- private static void stream(InputStream in, OutputStream out, IProgressMonitor monitor) throws IOException {
- byte[] b = new byte[1024];
- for ( ;; ) {
- if ( monitor.isCanceled() ) {
- throw new InterruptedIOException( "User canceled download" );
- }
- int r = in.read( b );
- if ( r == -1 ) break;
- out.write(b, 0, r);
- monitor.worked(r);
- }
-
- out.flush();
- }
-
- public IBundleModelElement getBundleInfo() {
+
+
+ public void synchronize( IProgressMonitor monitor ) throws IOException
+ {
+ SubMonitor progress = SubMonitor.convert( monitor, 100 );
+ progress.subTask( "Synchronizing " + bundle.getSymbolicName() + " binary" );
+ sync( location, bundle.getUpdateLocation(), progress.newChild( 45 ) );
+
+ try
+ {
+ progress.subTask( "Synchronizing " + bundle.getSymbolicName() + " source" );
+ sync( sourcePathLocation, bundle.getSourceLocation(), progress.newChild( 45 ) );
+ }
+ catch ( IOException e )
+ {
+ BldCore.error( "Failed to download source for " + bundle.getSymbolicName() + " " + bundle.getVersion(), e
+ .getCause() );
+ }
+
+ try
+ {
+ progress.subTask( "Synchronizing " + bundle.getSymbolicName() + " licence" );
+ sync( licencePathLocation, bundle.getLicenseURI(), progress.newChild( 10 ) );
+ }
+ catch ( IOException e )
+ {
+ BldCore.error( "Failed to download licence for " + bundle.getSymbolicName() + " " + bundle.getVersion(), e
+ .getCause() );
+ }
+ }
+
+
+ public boolean isSynchronized()
+ {
+ return location == null || location.toFile().exists();
+ }
+
+
+ private static void sync( IPath local, URI remote, IProgressMonitor monitor ) throws IOException
+ {
+ try
+ {
+ if ( local != null && !local.toFile().exists() )
+ {
+ if ( remote != null )
+ {
+ URL url = remote.toURL();
+ URLConnection connection = url.openConnection();
+ int contentLength = connection.getContentLength();
+
+ monitor.beginTask( "Downloading from " + url.getHost(), contentLength );
+
+ InputStream in = null;
+ OutputStream out = null;
+ try
+ {
+ URLConnection conn = url.openConnection();
+ if ( conn instanceof HttpURLConnection )
+ {
+ HttpURLConnection http = ( HttpURLConnection ) conn;
+ http.setConnectTimeout( 10000 );
+ http.setReadTimeout( 5000 );
+ }
+ in = conn.getInputStream();
+ File f = local.toFile();
+ f.getParentFile().mkdirs();
+ out = new FileOutputStream( f );
+ stream( in, out, monitor );
+ }
+ finally
+ {
+ if ( in != null )
+ {
+ in.close();
+ }
+ if ( out != null )
+ {
+ out.close();
+ }
+ monitor.done();
+ }
+ }
+ }
+ }
+ catch ( IOException e )
+ {
+ local.toFile().delete();
+ throw e;
+ }
+ }
+
+
+ private static void stream( InputStream in, OutputStream out, IProgressMonitor monitor ) throws IOException
+ {
+ byte[] b = new byte[1024];
+ for ( ;; )
+ {
+ if ( monitor.isCanceled() )
+ {
+ throw new InterruptedIOException( "User canceled download" );
+ }
+ int r = in.read( b );
+ if ( r == -1 )
+ break;
+ out.write( b, 0, r );
+ monitor.worked( r );
+ }
+
+ out.flush();
+ }
+
+
+ public IBundleModelElement getBundleInfo()
+ {
return bundle;
}
-
- public void setBundleInfo(IBundleModelElement bundle) {
- if ( bundle == null ) {
- if (this.bundle != null) {
- this.bundle.setParent(null);
- }
- }
- else {
- bundle.setParent(this);
- }
+
+
+ public void setBundleInfo( IBundleModelElement bundle )
+ {
+ if ( bundle == null )
+ {
+ if ( this.bundle != null )
+ {
+ this.bundle.setParent( null );
+ }
+ }
+ else
+ {
+ bundle.setParent( this );
+ }
this.bundle = bundle;
}
-
- public IDownloadJar getDownloadJar() {
- return download;
- }
-
- public void setDownloadJar(IDownloadJar download) {
- this.download = download;
+
+
+ public IDownloadJar getDownloadJar()
+ {
+ return download;
+ }
+
+
+ public void setDownloadJar( IDownloadJar download )
+ {
+ this.download = download;
}
-
- public void addLibraryPath( IPath path ) {
+
+
+ public void addLibraryPath( IPath path )
+ {
libraryPaths.add( path );
}
-
- public void removeLibraryPath( IPath path ) {
+
+
+ public void removeLibraryPath( IPath path )
+ {
libraryPaths.remove( path );
}
-
- public Set<IPath> getLibraryPaths() {
+
+
+ public Set<IPath> getLibraryPaths()
+ {
return libraryPaths;
}
-
- public void addSourcePath( IPath path ) {
+
+
+ public void addSourcePath( IPath path )
+ {
sourcePaths.add( path );
}
-
- public void removeSourcePath( IPath path ) {
+
+
+ public void removeSourcePath( IPath path )
+ {
sourcePaths.remove( path );
}
-
- public Set<IPath> getSourcePaths() {
+
+
+ public Set<IPath> getSourcePaths()
+ {
return sourcePaths;
}
- public void clearSourcePaths() {
- sourcePaths.clear();
- }
-
- public void addComposite(ISCAComposite composite) {
+
+ public void clearSourcePaths()
+ {
+ sourcePaths.clear();
+ }
+
+
+ public void addComposite( ISCAComposite composite )
+ {
composites.add( composite );
- composite.setParent(this);
+ composite.setParent( this );
}
- public Set<ISCAComposite> getComposites() {
+
+ public Set<ISCAComposite> getComposites()
+ {
return composites;
}
- public void removeComposite(ISCAComposite composite) {
- if ( composites.remove( composite ) ) {
- composite.setParent(null);
- }
- }
- public void addClasspathEntry(String encodedClasspath) {
- classpath.add( encodedClasspath.trim() );
- }
-
- public Set<String> getClasspathEntrys() {
- return classpath;
- }
-
- public void removeClasspathEntry(String encodedClasspath) {
- classpath.remove(encodedClasspath.trim());
- }
-
- public IPath getLocation() {
- return location;
- }
-
- public void setLocation(IPath location) {
- this.location = location;
- }
-
- public IPath getSourcePathLocation() {
- return sourcePathLocation;
- }
- public IPath getSourceRootPath() {
- return sourceRootPath;
- }
- public void setSourcePathLocation(IPath location) {
- this.sourcePathLocation = location;
- }
- public void setSourceRootPath(IPath location) {
- this.sourceRootPath = location;
- }
-
- @Override
- public String toString() {
- return "SigilBundle[" + (getBundleInfo() == null ? null : (getBundleInfo().getSymbolicName() + ":" + getBundleInfo().getVersion())) + "]";
- }
-
- @Override
- public boolean equals(Object obj) {
- if ( obj == null ) return false;
- if ( obj == this ) return true;
-
- if ( obj instanceof SigilBundle) {
- return obj.toString().equals( toString() );
- }
-
- return false;
- }
- @Override
- public int hashCode() {
- return 31 * toString().hashCode();
- }
-
- public IPath getLicencePathLocation() {
- return licencePathLocation;
- }
-
- public void setLicencePathLocation(IPath licencePathLocation) {
- this.licencePathLocation = licencePathLocation;
- }
-
- public String getFragmentHost() {
- return bundleHost;
- }
-
- public void setFragmentHost(String symbolicName) {
- this.bundleHost = symbolicName;
- }
-
- public String getElementName() {
- return bundle.getSymbolicName();
- }
-
- public Version getVersion() {
- return bundle.getVersion();
- }
-
- public void setVersion(Version version) {
- this.bundle.setVersion(version);
- }
-
- public String getSymbolicName() {
- return bundle.getSymbolicName();
- }
-
- public Set<String> getPackages() {
- return packages;
- }
-
- public void addPackage(String pkg) {
- packages.add(pkg);
- }
-
- public boolean removePackage(String pkg) {
- return packages.remove(pkg);
- }
-
- public Set<String> getDownloadPackages() {
- return dlPackages;
- }
-
- public void addDownloadPackage(String pkg) {
- dlPackages.add(pkg);
- }
-
- public boolean removeDownloadPackage(String pkg) {
- return dlPackages.remove(pkg);
- }
-
- public IPackageExport findExport(String packageName) {
- for ( IPackageExport e : bundle.getExports() ) {
- if ( packageName.equals( e.getPackageName() ) ) {
- return e;
- }
- }
- return null;
- }
-
- public IPackageImport findImport(String packageName) {
- for ( IPackageImport i : bundle.getImports() ) {
- if ( packageName.equals( i.getPackageName() ) ) {
- return i;
- }
- }
- return null;
- }
+
+ public void removeComposite( ISCAComposite composite )
+ {
+ if ( composites.remove( composite ) )
+ {
+ composite.setParent( null );
+ }
+ }
+
+
+ public void addClasspathEntry( String encodedClasspath )
+ {
+ classpath.add( encodedClasspath.trim() );
+ }
+
+
+ public Set<String> getClasspathEntrys()
+ {
+ return classpath;
+ }
+
+
+ public void removeClasspathEntry( String encodedClasspath )
+ {
+ classpath.remove( encodedClasspath.trim() );
+ }
+
+
+ public IPath getLocation()
+ {
+ return location;
+ }
+
+
+ public void setLocation( IPath location )
+ {
+ this.location = location;
+ }
+
+
+ public IPath getSourcePathLocation()
+ {
+ return sourcePathLocation;
+ }
+
+
+ public IPath getSourceRootPath()
+ {
+ return sourceRootPath;
+ }
+
+
+ public void setSourcePathLocation( IPath location )
+ {
+ this.sourcePathLocation = location;
+ }
+
+
+ public void setSourceRootPath( IPath location )
+ {
+ this.sourceRootPath = location;
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return "SigilBundle["
+ + ( getBundleInfo() == null ? null : ( getBundleInfo().getSymbolicName() + ":" + getBundleInfo()
+ .getVersion() ) ) + "]";
+ }
+
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( obj == null )
+ return false;
+ if ( obj == this )
+ return true;
+
+ if ( obj instanceof SigilBundle )
+ {
+ return obj.toString().equals( toString() );
+ }
+
+ return false;
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ return 31 * toString().hashCode();
+ }
+
+
+ public IPath getLicencePathLocation()
+ {
+ return licencePathLocation;
+ }
+
+
+ public void setLicencePathLocation( IPath licencePathLocation )
+ {
+ this.licencePathLocation = licencePathLocation;
+ }
+
+
+ public String getFragmentHost()
+ {
+ return bundleHost;
+ }
+
+
+ public void setFragmentHost( String symbolicName )
+ {
+ this.bundleHost = symbolicName;
+ }
+
+
+ public String getElementName()
+ {
+ return bundle.getSymbolicName();
+ }
+
+
+ public Version getVersion()
+ {
+ return bundle.getVersion();
+ }
+
+
+ public void setVersion( Version version )
+ {
+ this.bundle.setVersion( version );
+ }
+
+
+ public String getSymbolicName()
+ {
+ return bundle.getSymbolicName();
+ }
+
+
+ public Set<String> getPackages()
+ {
+ return packages;
+ }
+
+
+ public void addPackage( String pkg )
+ {
+ packages.add( pkg );
+ }
+
+
+ public boolean removePackage( String pkg )
+ {
+ return packages.remove( pkg );
+ }
+
+
+ public Set<String> getDownloadPackages()
+ {
+ return dlPackages;
+ }
+
+
+ public void addDownloadPackage( String pkg )
+ {
+ dlPackages.add( pkg );
+ }
+
+
+ public boolean removeDownloadPackage( String pkg )
+ {
+ return dlPackages.remove( pkg );
+ }
+
+
+ public IPackageExport findExport( String packageName )
+ {
+ for ( IPackageExport e : bundle.getExports() )
+ {
+ if ( packageName.equals( e.getPackageName() ) )
+ {
+ return e;
+ }
+ }
+ return null;
+ }
+
+
+ public IPackageImport findImport( String packageName )
+ {
+ for ( IPackageImport i : bundle.getImports() )
+ {
+ if ( packageName.equals( i.getPackageName() ) )
+ {
+ return i;
+ }
+ }
+ return null;
+ }
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/BundleModelElement.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/BundleModelElement.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/BundleModelElement.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/BundleModelElement.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.core.internal.model.osgi;
+
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
@@ -34,7 +35,9 @@
import org.apache.felix.sigil.model.osgi.IRequiredBundle;
import org.osgi.framework.Version;
-public class BundleModelElement extends AbstractCompoundModelElement implements IBundleModelElement {
+
+public class BundleModelElement extends AbstractCompoundModelElement implements IBundleModelElement
+{
/**
*
*/
@@ -59,13 +62,15 @@
private String vendor;
private String contactAddress;
private String copyright;
-
+
// internal values
private String activator;
private Set<ILibraryImport> libraries;
- public BundleModelElement() {
- super( "OSGi Bundle" );
+
+ public BundleModelElement()
+ {
+ super( "OSGi Bundle" );
this.imports = new HashSet<IPackageImport>();
this.exports = new HashSet<IPackageExport>();
this.requires = new HashSet<IRequiredBundle>();
@@ -73,223 +78,321 @@
this.libraries = new HashSet<ILibraryImport>();
}
- public String getActivator() {
- return activator;
- }
-
- public void setActivator(String activator) {
- this.activator = activator;
- }
-
- public void addLibraryImport(ILibraryImport library) {
- libraries.add(library);
- }
-
- public Set<ILibraryImport> getLibraryImports() {
- return libraries;
- }
-
- public void removeLibraryImport(ILibraryImport library) {
- libraries.remove(library);
- }
- public String getCategory() {
+ public String getActivator()
+ {
+ return activator;
+ }
+
+
+ public void setActivator( String activator )
+ {
+ this.activator = activator;
+ }
+
+
+ public void addLibraryImport( ILibraryImport library )
+ {
+ libraries.add( library );
+ }
+
+
+ public Set<ILibraryImport> getLibraryImports()
+ {
+ return libraries;
+ }
+
+
+ public void removeLibraryImport( ILibraryImport library )
+ {
+ libraries.remove( library );
+ }
+
+
+ public String getCategory()
+ {
return category;
}
- public void setCategory(String category) {
+
+ public void setCategory( String category )
+ {
this.category = category;
}
- public String getContactAddress() {
+
+ public String getContactAddress()
+ {
return contactAddress;
}
- public void setContactAddress(String contactAddress) {
+
+ public void setContactAddress( String contactAddress )
+ {
this.contactAddress = contactAddress;
}
- public String getCopyright() {
+
+ public String getCopyright()
+ {
return copyright;
}
- public void setCopyright(String copyright) {
+
+ public void setCopyright( String copyright )
+ {
this.copyright = copyright;
}
- public URI getDocURI() {
+
+ public URI getDocURI()
+ {
return docURI;
}
- public void setDocURI(URI docURI) {
+
+ public void setDocURI( URI docURI )
+ {
this.docURI = docURI;
}
- public Set<IPackageExport> getExports() {
+
+ public Set<IPackageExport> getExports()
+ {
return exports;
}
- public void addExport(IPackageExport packageExport) {
- exports.add(packageExport);
- packageExport.setParent(this);
+
+ public void addExport( IPackageExport packageExport )
+ {
+ exports.add( packageExport );
+ packageExport.setParent( this );
}
- public void removeExport(IPackageExport packageExport) {
- if ( exports.remove(packageExport) ) {
- packageExport.setParent(null);
- }
+
+ public void removeExport( IPackageExport packageExport )
+ {
+ if ( exports.remove( packageExport ) )
+ {
+ packageExport.setParent( null );
+ }
}
-
- public Set<IPackageImport> getImports() {
+
+
+ public Set<IPackageImport> getImports()
+ {
return imports;
}
- public void addImport(IPackageImport packageImport) {
- imports.add(packageImport);
- packageImport.setParent(this);
- }
-
- public void removeImport(IPackageImport packageImport) {
- if ( imports.remove( packageImport ) ) {
- packageImport.setParent(null);
- }
+
+ public void addImport( IPackageImport packageImport )
+ {
+ imports.add( packageImport );
+ packageImport.setParent( this );
}
-
- public Set<IRequiredBundle> getRequiredBundles() {
+
+
+ public void removeImport( IPackageImport packageImport )
+ {
+ if ( imports.remove( packageImport ) )
+ {
+ packageImport.setParent( null );
+ }
+ }
+
+
+ public Set<IRequiredBundle> getRequiredBundles()
+ {
return requires;
}
- public void addRequiredBundle(IRequiredBundle bundle) {
+
+ public void addRequiredBundle( IRequiredBundle bundle )
+ {
requires.add( bundle );
- bundle.setParent(this);
+ bundle.setParent( this );
}
- public void removeRequiredBundle(IRequiredBundle bundle) {
- if ( requires.remove(bundle) ) {
- bundle.setParent(null);
- }
+
+ public void removeRequiredBundle( IRequiredBundle bundle )
+ {
+ if ( requires.remove( bundle ) )
+ {
+ bundle.setParent( null );
+ }
}
-
- public URI getLicenseURI() {
+
+
+ public URI getLicenseURI()
+ {
return licenseURI;
}
- public void setLicenseURI(URI licenseURI) {
+
+ public void setLicenseURI( URI licenseURI )
+ {
this.licenseURI = licenseURI;
}
- public URI getSourceLocation() {
+
+ public URI getSourceLocation()
+ {
return sourceLocation;
}
- public void setSourceLocation(URI sourceLocation) {
+
+ public void setSourceLocation( URI sourceLocation )
+ {
this.sourceLocation = sourceLocation;
}
- public String getSymbolicName() {
+
+ public String getSymbolicName()
+ {
return symbolicName;
}
- public void setSymbolicName(String symbolicName) {
+
+ public void setSymbolicName( String symbolicName )
+ {
this.symbolicName = symbolicName == null ? null : symbolicName.intern();
}
- public URI getUpdateLocation() {
+
+ public URI getUpdateLocation()
+ {
return updateLocation;
}
- public void setUpdateLocation(URI updateLocation) {
+
+ public void setUpdateLocation( URI updateLocation )
+ {
this.updateLocation = updateLocation;
}
- public String getVendor() {
- return vendor;
+
+ public String getVendor()
+ {
+ return vendor;
}
- public void setVendor(String vendor) {
+
+ public void setVendor( String vendor )
+ {
this.vendor = vendor;
}
- public Version getVersion() {
- return version;
+
+ public Version getVersion()
+ {
+ return version;
}
- public void setVersion(Version version) {
+
+ public void setVersion( Version version )
+ {
this.version = version == null ? Version.emptyVersion : version;
}
- public void checkValid() throws InvalidModelException {
- if (symbolicName == null)
- throw new InvalidModelException(this, "Bundle symbolic name not set");
+
+ public void checkValid() throws InvalidModelException
+ {
+ if ( symbolicName == null )
+ throw new InvalidModelException( this, "Bundle symbolic name not set" );
}
- public BundleModelElement clone() {
- BundleModelElement bd = (BundleModelElement) super.clone();
+
+ public BundleModelElement clone()
+ {
+ BundleModelElement bd = ( BundleModelElement ) super.clone();
bd.imports = new HashSet<IPackageImport>();
bd.exports = new HashSet<IPackageExport>();
bd.requires = new HashSet<IRequiredBundle>();
-
- for (IPackageImport pi : imports ) {
- bd.imports.add((IPackageImport) pi.clone());
+
+ for ( IPackageImport pi : imports )
+ {
+ bd.imports.add( ( IPackageImport ) pi.clone() );
}
- for (IPackageExport pe : exports ) {
- bd.exports.add((IPackageExport) pe.clone());
+ for ( IPackageExport pe : exports )
+ {
+ bd.exports.add( ( IPackageExport ) pe.clone() );
}
-
- for ( IRequiredBundle rb : requires ) {
- bd.requires.add((IRequiredBundle) rb.clone());
+
+ for ( IRequiredBundle rb : requires )
+ {
+ bd.requires.add( ( IRequiredBundle ) rb.clone() );
}
return bd;
}
- public String toString() {
+
+ public String toString()
+ {
StringBuffer buf = new StringBuffer();
- buf.append("BundleModelElement[");
- buf.append(symbolicName);
- buf.append(", ");
- buf.append(version);
- buf.append("]");
+ buf.append( "BundleModelElement[" );
+ buf.append( symbolicName );
+ buf.append( ", " );
+ buf.append( version );
+ buf.append( "]" );
return buf.toString();
}
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public void addClasspath(String path) {
- classpathElements.add( path );
- }
-
- public Collection<String> getClasspaths() {
- return classpathElements.isEmpty() ? Collections.singleton( "." ) : classpathElements;
- }
-
- public void removeClasspath(String path) {
- classpathElements.remove( path );
- }
-
- public IRequiredBundle getFragmentHost() {
- return fragmentHost;
- }
-
- public void setFragmentHost(IRequiredBundle fragmentHost) {
- this.fragmentHost = fragmentHost;
- }
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+
+ public void addClasspath( String path )
+ {
+ classpathElements.add( path );
+ }
+
+
+ public Collection<String> getClasspaths()
+ {
+ return classpathElements.isEmpty() ? Collections.singleton( "." ) : classpathElements;
+ }
+
+
+ public void removeClasspath( String path )
+ {
+ classpathElements.remove( path );
+ }
+
+
+ public IRequiredBundle getFragmentHost()
+ {
+ return fragmentHost;
+ }
+
+
+ public void setFragmentHost( IRequiredBundle fragmentHost )
+ {
+ this.fragmentHost = fragmentHost;
+ }
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/PackageExport.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/PackageExport.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/PackageExport.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/PackageExport.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.core.internal.model.osgi;
+
import java.util.Collection;
import java.util.HashSet;
@@ -27,97 +28,138 @@
import org.apache.felix.sigil.model.osgi.IPackageExport;
import org.osgi.framework.Version;
-public class PackageExport extends AbstractModelElement implements IPackageExport {
- private static final long serialVersionUID = 1L;
+public class PackageExport extends AbstractModelElement implements IPackageExport
+{
+
+ private static final long serialVersionUID = 1L;
- private String name;
+ private String name;
private Version version;
private HashSet<String> uses = new HashSet<String>();
- public PackageExport() {
- super("OSGi Package Export");
- }
- public String getPackageName() {
+ public PackageExport()
+ {
+ super( "OSGi Package Export" );
+ }
+
+
+ public String getPackageName()
+ {
return name;
}
- public void setPackageName(String packageName) {
+
+ public void setPackageName( String packageName )
+ {
this.name = packageName;
}
- public Version getVersion() {
- Version result;
- if(version != null) {
- result = version;
- } else {
- ISigilBundle owningBundle = getAncestor(ISigilBundle.class);
- if(owningBundle == null) {
- result = Version.emptyVersion;
- } else {
- result = owningBundle.getVersion();
- }
+
+ public Version getVersion()
+ {
+ Version result;
+ if ( version != null )
+ {
+ result = version;
+ }
+ else
+ {
+ ISigilBundle owningBundle = getAncestor( ISigilBundle.class );
+ if ( owningBundle == null )
+ {
+ result = Version.emptyVersion;
+ }
+ else
+ {
+ result = owningBundle.getVersion();
+ }
}
return result;
}
-
- public Version getRawVersion() {
- return version;
+
+
+ public Version getRawVersion()
+ {
+ return version;
}
- public void setVersion(Version version) {
+
+ public void setVersion( Version version )
+ {
this.version = version; // == null ? Version.emptyVersion : version;
}
-
- public void addUse(String use) {
- uses.add(use);
- }
-
- public Collection<String> getUses() {
- return uses;
- }
-
- public void removeUse(String use) {
- uses.remove(use);
- }
-
- @Override
- public String toString() {
- return "PackageExport[" + name + ":" + version + ":uses=" + uses + "]";
- }
-
- public void setUses(Collection<String> uses) {
- this.uses.clear();
- this.uses.addAll(uses);
- }
-
- public int compareTo(IPackageExport o) {
- int i = name.compareTo(o.getPackageName());
-
- if ( i == 0 ) {
- i = compareVersion(o.getVersion());
- }
-
- return i;
- }
-
- private int compareVersion(Version other) {
- if ( version == null ) {
- if ( other == null ) {
- return 0;
- }
- else {
- return 1;
- }
- }
- else {
- if ( other == null ) {
- return -1;
- }
- else {
- return version.compareTo(other);
- }
- }
- }
+
+
+ public void addUse( String use )
+ {
+ uses.add( use );
+ }
+
+
+ public Collection<String> getUses()
+ {
+ return uses;
+ }
+
+
+ public void removeUse( String use )
+ {
+ uses.remove( use );
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return "PackageExport[" + name + ":" + version + ":uses=" + uses + "]";
+ }
+
+
+ public void setUses( Collection<String> uses )
+ {
+ this.uses.clear();
+ this.uses.addAll( uses );
+ }
+
+
+ public int compareTo( IPackageExport o )
+ {
+ int i = name.compareTo( o.getPackageName() );
+
+ if ( i == 0 )
+ {
+ i = compareVersion( o.getVersion() );
+ }
+
+ return i;
+ }
+
+
+ private int compareVersion( Version other )
+ {
+ if ( version == null )
+ {
+ if ( other == null )
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ else
+ {
+ if ( other == null )
+ {
+ return -1;
+ }
+ else
+ {
+ return version.compareTo( other );
+ }
+ }
+ }
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/PackageImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/PackageImport.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/PackageImport.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/PackageImport.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.core.internal.model.osgi;
+
import org.apache.felix.sigil.model.AbstractModelElement;
import org.apache.felix.sigil.model.IModelElement;
import org.apache.felix.sigil.model.InvalidModelException;
@@ -26,138 +27,189 @@
import org.apache.felix.sigil.model.osgi.IPackageExport;
import org.apache.felix.sigil.model.osgi.IPackageImport;
-public class PackageImport extends AbstractModelElement implements IPackageImport {
- private static final long serialVersionUID = 1L;
-
- private String name;
+public class PackageImport extends AbstractModelElement implements IPackageImport
+{
+
+ private static final long serialVersionUID = 1L;
+
+ private String name;
private VersionRange versions = VersionRange.ANY_VERSION;
-
+
// resolution directive
private boolean optional;
- private boolean dependency = true;
- private OSGiImport osgiImport = OSGiImport.AUTO;
+ private boolean dependency = true;
+ private OSGiImport osgiImport = OSGiImport.AUTO;
+
- public PackageImport() {
- super( "OSGi Package Import" );
+ public PackageImport()
+ {
+ super( "OSGi Package Import" );
}
+
@Override
- public void checkValid() throws InvalidModelException {
- if ( name == null ) {
- throw new InvalidModelException( this, "Package name must be set" );
- }
- }
+ public void checkValid() throws InvalidModelException
+ {
+ if ( name == null )
+ {
+ throw new InvalidModelException( this, "Package name must be set" );
+ }
+ }
+
- public boolean isOptional() {
+ public boolean isOptional()
+ {
return optional;
}
- public void setOptional(boolean optional) {
+
+ public void setOptional( boolean optional )
+ {
this.optional = optional;
}
- public boolean isDependency() {
- return dependency;
- }
-
- public void setDependency(boolean dependency) {
- this.dependency = dependency;
- }
-
- public OSGiImport getOSGiImport() {
- return osgiImport;
- }
-
- public void setOSGiImport(OSGiImport osgiHeader) {
- this.osgiImport = osgiHeader;
- }
- public String getPackageName() {
+ public boolean isDependency()
+ {
+ return dependency;
+ }
+
+
+ public void setDependency( boolean dependency )
+ {
+ this.dependency = dependency;
+ }
+
+
+ public OSGiImport getOSGiImport()
+ {
+ return osgiImport;
+ }
+
+
+ public void setOSGiImport( OSGiImport osgiHeader )
+ {
+ this.osgiImport = osgiHeader;
+ }
+
+
+ public String getPackageName()
+ {
return name;
}
- public void setPackageName(String name) {
+
+ public void setPackageName( String name )
+ {
this.name = name;
}
- public VersionRange getVersions() {
+
+ public VersionRange getVersions()
+ {
return versions;
}
- public void setVersions(VersionRange versions) {
+
+ public void setVersions( VersionRange versions )
+ {
this.versions = versions == null ? VersionRange.ANY_VERSION : versions;
}
- @Override
- public String toString() {
- return "Package-Import[" + name + ":" + versions + ":" + (optional ? "optional" : "mandatory") + "]";
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
+
+ @Override
+ public String toString()
+ {
+ return "Package-Import[" + name + ":" + versions + ":" + ( optional ? "optional" : "mandatory" ) + "]";
+ }
+
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
return true;
- if (obj == null)
+ if ( obj == null )
return false;
-
- if ( obj instanceof PackageImport ) {
- PackageImport pi = (PackageImport) obj;
- return name.equals( pi.name ) && versions.equals( pi.versions ) && optional == pi.optional;
- }
- else {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- int hc = name.hashCode() * versions.hashCode();
-
- if ( optional ) {
- hc *= -1;
- }
-
- return hc;
- }
-
- public boolean accepts(IModelElement provider) {
- if ( provider instanceof IPackageExport ) {
- IPackageExport pe = (IPackageExport) provider;
- return pe.getPackageName().equals( name ) && versions.contains( pe.getVersion() );
- }
- else {
- return false;
- }
- }
-
- public int compareTo(IPackageImport o) {
- int i = name.compareTo(o.getPackageName());
-
- if ( i == 0 ) {
- i = compareVersion(o.getVersions());
- }
-
- return i;
- }
-
- private int compareVersion(VersionRange range) {
- if ( versions == null ) {
- if ( range == null ) {
- return 0;
- }
- else {
- return 1;
- }
- }
- else {
- if ( range == null ) {
- return -1;
- }
- else {
- return versions.getCeiling().compareTo(range.getCeiling());
- }
- }
- }
+
+ if ( obj instanceof PackageImport )
+ {
+ PackageImport pi = ( PackageImport ) obj;
+ return name.equals( pi.name ) && versions.equals( pi.versions ) && optional == pi.optional;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ int hc = name.hashCode() * versions.hashCode();
+
+ if ( optional )
+ {
+ hc *= -1;
+ }
+
+ return hc;
+ }
+
+
+ public boolean accepts( IModelElement provider )
+ {
+ if ( provider instanceof IPackageExport )
+ {
+ IPackageExport pe = ( IPackageExport ) provider;
+ return pe.getPackageName().equals( name ) && versions.contains( pe.getVersion() );
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ public int compareTo( IPackageImport o )
+ {
+ int i = name.compareTo( o.getPackageName() );
+
+ if ( i == 0 )
+ {
+ i = compareVersion( o.getVersions() );
+ }
+
+ return i;
+ }
+
+
+ private int compareVersion( VersionRange range )
+ {
+ if ( versions == null )
+ {
+ if ( range == null )
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ else
+ {
+ if ( range == null )
+ {
+ return -1;
+ }
+ else
+ {
+ return versions.getCeiling().compareTo( range.getCeiling() );
+ }
+ }
+ }
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/RequiredBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/RequiredBundle.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/RequiredBundle.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/internal/model/osgi/RequiredBundle.java Tue Jul 21 18:51:33 2009
@@ -19,115 +19,156 @@
package org.apache.felix.sigil.core.internal.model.osgi;
+
import org.apache.felix.sigil.model.AbstractModelElement;
import org.apache.felix.sigil.model.IModelElement;
import org.apache.felix.sigil.model.common.VersionRange;
import org.apache.felix.sigil.model.osgi.IBundleModelElement;
import org.apache.felix.sigil.model.osgi.IRequiredBundle;
-public class RequiredBundle extends AbstractModelElement implements IRequiredBundle {
- private static final long serialVersionUID = 1L;
-
- private String symbolicName;
+
+public class RequiredBundle extends AbstractModelElement implements IRequiredBundle
+{
+ private static final long serialVersionUID = 1L;
+
+ private String symbolicName;
private VersionRange versions = VersionRange.ANY_VERSION;
private boolean optional;
-
- public RequiredBundle() {
- super("OSGi Bundle Requirement");
- }
- public String getSymbolicName() {
+
+ public RequiredBundle()
+ {
+ super( "OSGi Bundle Requirement" );
+ }
+
+
+ public String getSymbolicName()
+ {
return symbolicName;
}
- public void setSymbolicName(String symbolicName) {
+
+ public void setSymbolicName( String symbolicName )
+ {
this.symbolicName = symbolicName == null ? null : symbolicName.intern();
}
- public VersionRange getVersions() {
+
+ public VersionRange getVersions()
+ {
return versions;
}
- public void setVersions(VersionRange versions) {
+
+ public void setVersions( VersionRange versions )
+ {
this.versions = versions == null ? VersionRange.ANY_VERSION : versions;
}
- public boolean isOptional() {
- return optional;
- }
-
- public void setOptional(boolean optional) {
- this.optional = optional;
- }
-
- @Override
- public String toString() {
- return "RequiredBundle[" + symbolicName + ":" + versions + ":" + (optional ? "optional" : "mandatory") + "]";
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
+
+ public boolean isOptional()
+ {
+ return optional;
+ }
+
+
+ public void setOptional( boolean optional )
+ {
+ this.optional = optional;
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return "RequiredBundle[" + symbolicName + ":" + versions + ":" + ( optional ? "optional" : "mandatory" ) + "]";
+ }
+
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
return true;
- if (obj == null)
+ if ( obj == null )
+ return false;
+
+ if ( obj instanceof RequiredBundle )
+ {
+ RequiredBundle rb = ( RequiredBundle ) obj;
+ return symbolicName.equals( rb.symbolicName ) && versions.equals( rb.versions ) && optional == rb.optional;
+ }
+ else
+ {
return false;
-
- if ( obj instanceof RequiredBundle ) {
- RequiredBundle rb = (RequiredBundle) obj;
- return symbolicName.equals( rb.symbolicName ) && versions.equals( rb.versions ) && optional == rb.optional;
- }
- else {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- int hc = symbolicName.hashCode() * versions.hashCode();
-
- if ( optional ) {
- hc *= -1;
- }
-
- return hc;
- }
-
- public boolean accepts(IModelElement provider) {
- if ( provider instanceof IBundleModelElement ) {
- IBundleModelElement bndl = (IBundleModelElement) provider;
- return symbolicName.equals( bndl.getSymbolicName() ) && versions.contains( bndl.getVersion() );
- }
- else {
- return false;
- }
- }
-
- public int compareTo(IRequiredBundle o) {
- int i = symbolicName.compareTo(o.getSymbolicName());
-
- if ( i == 0 ) {
- i = compareVersion(o.getVersions());
- }
-
- return i;
- }
-
- private int compareVersion(VersionRange range) {
- if ( versions == null ) {
- if ( range == null ) {
- return 0;
- }
- else {
- return 1;
- }
- }
- else {
- if ( range == null ) {
- return -1;
- }
- else {
- return versions.getCeiling().compareTo(range.getCeiling());
- }
- }
- }
+ }
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ int hc = symbolicName.hashCode() * versions.hashCode();
+
+ if ( optional )
+ {
+ hc *= -1;
+ }
+
+ return hc;
+ }
+
+
+ public boolean accepts( IModelElement provider )
+ {
+ if ( provider instanceof IBundleModelElement )
+ {
+ IBundleModelElement bndl = ( IBundleModelElement ) provider;
+ return symbolicName.equals( bndl.getSymbolicName() ) && versions.contains( bndl.getVersion() );
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ public int compareTo( IRequiredBundle o )
+ {
+ int i = symbolicName.compareTo( o.getSymbolicName() );
+
+ if ( i == 0 )
+ {
+ i = compareVersion( o.getVersions() );
+ }
+
+ return i;
+ }
+
+
+ private int compareVersion( VersionRange range )
+ {
+ if ( versions == null )
+ {
+ if ( range == null )
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ else
+ {
+ if ( range == null )
+ {
+ return -1;
+ }
+ else
+ {
+ return versions.getCeiling().compareTo( range.getCeiling() );
+ }
+ }
+ }
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/licence/ILicenseManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/licence/ILicenseManager.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/licence/ILicenseManager.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/licence/ILicenseManager.java Tue Jul 21 18:51:33 2009
@@ -19,14 +19,25 @@
package org.apache.felix.sigil.core.licence;
+
import java.util.Set;
import java.util.regex.Pattern;
-public interface ILicenseManager {
- void addLicense(String name, Pattern pattern);
- void removeLicense(String name);
- Set<String> getLicenseNames();
- Pattern getLicensePattern(String name);
- ILicensePolicy getDefaultPolicy();
- //ILicensePolicy getPolicy(ISigilProjectModel project);
+
+public interface ILicenseManager
+{
+ void addLicense( String name, Pattern pattern );
+
+
+ void removeLicense( String name );
+
+
+ Set<String> getLicenseNames();
+
+
+ Pattern getLicensePattern( String name );
+
+
+ ILicensePolicy getDefaultPolicy();
+ //ILicensePolicy getPolicy(ISigilProjectModel project);
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/licence/ILicensePolicy.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/licence/ILicensePolicy.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/licence/ILicensePolicy.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/licence/ILicensePolicy.java Tue Jul 21 18:51:33 2009
@@ -19,12 +19,21 @@
package org.apache.felix.sigil.core.licence;
+
import org.apache.felix.sigil.model.eclipse.ISigilBundle;
import org.eclipse.core.runtime.IProgressMonitor;
-public interface ILicensePolicy {
- void addAllowed(String licenseName);
- void removeAllowed(String licenseName);
- boolean accept(ISigilBundle bundle);
- void save(IProgressMonitor monitor);
+
+public interface ILicensePolicy
+{
+ void addAllowed( String licenseName );
+
+
+ void removeAllowed( String licenseName );
+
+
+ boolean accept( ISigilBundle bundle );
+
+
+ void save( IProgressMonitor monitor );
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/BundleResolver.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/BundleResolver.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/BundleResolver.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/BundleResolver.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.core.repository;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -51,394 +52,529 @@
import org.eclipse.core.runtime.SubMonitor;
import org.osgi.framework.Version;
-public class BundleResolver implements IBundleResolver {
- private class BundleOrderComparator implements Comparator<ISigilBundle> {
- private IModelElement requirement;
-
- public BundleOrderComparator(IModelElement requirement) {
- this.requirement = requirement;
- }
-
- public int compare(ISigilBundle o1, ISigilBundle o2) {
- int c = compareVersions(o1, o2);
-
- if ( c == 0 ) {
- c = compareImports(o1, o2);
- }
-
- return c;
- }
-
- private int compareImports(ISigilBundle o1, ISigilBundle o2) {
- int c1 = o1.getBundleInfo().getImports().size();
- int c2 = o2.getBundleInfo().getImports().size();
-
- if ( c1 < c2 ) {
- return -1;
- }
- else if ( c2 > c1 ) {
- return 1;
- }
- else {
- return 0;
- }
- }
-
- private int compareVersions(ISigilBundle o1, ISigilBundle o2) {
- Version v1 = null;
- Version v2 = null;
- if ( requirement instanceof IPackageImport ) {
- v1 = findExportVersion( (IPackageImport) requirement, o1 );
- v2 = findExportVersion( (IPackageImport) requirement, o2 );
- }
- else if ( requirement instanceof IRequiredBundle ) {
- v1 = o1.getBundleInfo().getVersion();
- v2 = o1.getBundleInfo().getVersion();
- }
-
- if ( v1 == null ) {
- if ( v2 == null ) {
- return 0;
- }
- else {
- return 1;
- }
- }
- else {
- if ( v2 == null ) {
- return -1;
- }
- else {
- return v2.compareTo(v1);
- }
- }
- }
-
- private Version findExportVersion(IPackageImport pi, ISigilBundle o1) {
- for ( IPackageExport pe : o1.getBundleInfo().getExports() ) {
- if ( pi.getPackageName().equals( pi.getPackageName() ) ) {
- return pe.getVersion();
- }
- }
-
- return null;
- }
-
- }
-
- private class ResolutionContext {
- private final IModelElement root;
- private final ResolutionConfig config;
- private final IResolutionMonitor monitor;
-
- private final Resolution resolution = new Resolution();
- private final Set<IModelElement> parsed = new HashSet<IModelElement>();
- private final LinkedList<IModelElement> requirements = new LinkedList<IModelElement>();
-
- public ResolutionContext(IModelElement root, ResolutionConfig config, IResolutionMonitor monitor) {
- this.root = root;
- this.config = config;
- this.monitor = monitor;
- }
-
- public void enterModelElement(IModelElement element) {
- parsed.add(element);
- }
-
- public void exitModelElement(IModelElement element) {
- parsed.remove(element);
- }
-
- public boolean isNewModelElement(IModelElement element) {
- return !parsed.contains(element);
- }
-
- public boolean isValid() {
- return resolution.isSuccess();
- }
-
- public void setValid(boolean valid) {
- resolution.setSuccess(valid);
- }
-
- public ResolutionException newResolutionException() {
- return new ResolutionException(root, requirements.toArray( new IModelElement[requirements.size()]) );
- }
-
- public void startRequirement(IModelElement element) {
- requirements.add(element);
- monitor.startResolution(element);
- }
-
- public void endRequirement(IModelElement element) {
- ISigilBundle provider = resolution.getProvider(element);
-
- setValid( provider != null || isOptional(element) || config.isIgnoreErrors() );
-
- if ( isValid() ) {
- // only clear stack if valid
- // else use it as an aid to trace errors
- requirements.remove(element);
- }
-
- monitor.endResolution( element, provider );
- }
- }
-
- private class Resolution implements IResolution {
- private Map<ISigilBundle, List<IModelElement>> providees = new HashMap<ISigilBundle, List<IModelElement>>();
- private Map<IModelElement, ISigilBundle> providers = new HashMap<IModelElement, ISigilBundle>();
- private boolean success = true; // assume success
-
- boolean addProvider(IModelElement element, ISigilBundle provider) {
- providers.put( element, provider );
-
- List<IModelElement> requirements = providees.get( provider );
-
- boolean isNewProvider = requirements == null;
-
- if ( isNewProvider ) {
- requirements = new ArrayList<IModelElement>();
- providees.put( provider, requirements );
- }
-
- requirements.add( element );
-
- return isNewProvider;
- }
-
- void removeProvider(IModelElement element, ISigilBundle provider) {
- providers.remove(element);
- List<IModelElement> e = providees.get(provider);
- e.remove(element);
- if ( e.isEmpty() ) {
- providees.remove(provider);
- }
- }
-
- void setSuccess(boolean success) {
- this.success = success;
- }
-
- public boolean isSuccess() {
- return success;
- }
-
- public ISigilBundle getProvider(IModelElement requirement) {
- return providers.get(requirement);
- }
-
- public Set<ISigilBundle> getBundles() {
- return providees.keySet();
- }
-
- public List<IModelElement> getMatchedRequirements(ISigilBundle bundle) {
- return providees.get(bundle);
- }
-
- public boolean isSynchronized() {
- for ( ISigilBundle b : getBundles() ) {
- if ( !b.isSynchronized() ) {
- return false;
- }
- }
-
- return true;
- }
-
- public void synchronize(IProgressMonitor monitor) {
- Set<ISigilBundle> bundles = getBundles();
- SubMonitor progress = SubMonitor.convert(monitor, bundles.size());
-
- for ( ISigilBundle b : bundles ) {
- if ( monitor.isCanceled() ) {
- break;
- }
-
- try {
- b.synchronize(progress.newChild(1));
- } catch (IOException e) {
- BldCore.error( "Failed to synchronize " + b, e );
- }
- }
- }
- }
-
- private static final IResolutionMonitor NULL_MONITOR = new IResolutionMonitor() {
- public void endResolution(IModelElement requirement,
- ISigilBundle sigilBundle) {
- }
-
- public boolean isCanceled() {
- return false;
- }
-
- public void startResolution(IModelElement requirement) {
- }
- };
-
- private IRepositoryManager repositoryManager;
-
- public BundleResolver(IRepositoryManager repositoryManager) {
- this.repositoryManager = repositoryManager;
- }
-
- public IResolution resolve(IModelElement element, ResolutionConfig config, IResolutionMonitor monitor) throws ResolutionException {
- if ( monitor == null ) {
- monitor = NULL_MONITOR;
- }
- ResolutionContext ctx = new ResolutionContext(element, config, monitor);
-
- resolveElement(element, ctx);
-
- if ( !ctx.isValid() ) {
- throw ctx.newResolutionException();
- }
-
- return ctx.resolution;
- }
-
- private void resolveElement(IModelElement element, ResolutionContext ctx) throws ResolutionException {
- if ( isRequirement(element) ) {
- resolveRequirement(element, ctx);
- }
-
- if ( ctx.isValid() && element instanceof ICompoundModelElement ) {
- resolveCompound((ICompoundModelElement) element, ctx);
- }
- }
-
- private void resolveCompound(ICompoundModelElement compound, ResolutionContext ctx) throws ResolutionException {
- for ( IModelElement element : compound.children() ) {
- if ( ctx.isNewModelElement(element) ) {
- if ( isRequirement(element) ) {
- resolveRequirement(element, ctx);
- }
- else if ( element instanceof ICompoundModelElement ) {
- if ( !ctx.monitor.isCanceled() ) {
- ctx.enterModelElement( element );
- resolveElement((ICompoundModelElement) element, ctx);
- ctx.exitModelElement(element);
- }
- }
-
- if ( !ctx.isValid() ) {
- break;
- }
- }
- }
- }
-
- private void resolveRequirement(IModelElement requirement, ResolutionContext ctx) throws ResolutionException {
- if ( ctx.config.isOptional() || !isOptional(requirement) ) {
- ctx.startRequirement(requirement );
-
- try {
- int[] priorities = repositoryManager.getPriorityLevels();
-
- outer: for ( int i = 0; i< priorities.length; i++ ) {
- List<ISigilBundle> providers = findProvidersAtPriority(priorities[i], requirement, ctx);
-
- if ( !providers.isEmpty() && !ctx.monitor.isCanceled() ) {
- if ( providers.size() > 1 ) {
- Collections.sort(providers, new BundleOrderComparator(requirement));
- }
-
- for ( ISigilBundle provider : providers ) {
- // reset validity - if there's another provider it can still be solved
- ctx.setValid(true);
- if ( ctx.resolution.addProvider(requirement, provider) ) {
- if ( ctx.config.isDependents() ) {
- resolveElement(provider, ctx);
- }
-
- if ( ctx.isValid() ) {
- break outer;
- }
- else {
- ctx.resolution.removeProvider(requirement, provider);
- }
- }
- else {
- break outer;
- }
- }
- }
- }
- }
- finally {
- ctx.endRequirement(requirement);
- }
- }
- }
-
- private List<ISigilBundle> findProvidersAtPriority(int i, IModelElement requirement, ResolutionContext ctx) throws ResolutionException {
- ArrayList<ISigilBundle> providers = new ArrayList<ISigilBundle>();
-
- for (IBundleRepository rep : repositoryManager.getRepositories(i)) {
- if ( ctx.monitor.isCanceled() ) {
- break;
- }
- providers.addAll( findProviders( requirement, ctx.config, rep ) );
- }
-
- return providers;
- }
-
- private Collection<ISigilBundle> findProviders(IModelElement requirement, ResolutionConfig config, IBundleRepository rep) throws ResolutionException {
- ArrayList<ISigilBundle> found = new ArrayList<ISigilBundle>();
-
- if ( requirement instanceof IPackageImport ) {
- IPackageImport pi = (IPackageImport) requirement;
- found.addAll( rep.findAllProviders( pi, config.getOptions() ) );
- }
- else if ( requirement instanceof IRequiredBundle ) {
- IRequiredBundle rb = (IRequiredBundle) requirement;
- found.addAll( rep.findAllProviders( rb, config.getOptions() ) );
- }
- else if ( requirement instanceof ILibraryImport ) {
- ILibrary lib = repositoryManager.resolveLibrary((ILibraryImport) requirement);
- if (lib != null) {
- found.addAll( rep.findProviders(lib, config.getOptions()) );
- }
- }
- else {
- // shouldn't get here - developer error if do
- // use isRequirement before getting anywhere near this logic...
- throw new IllegalStateException( "Invalid requirement type " + requirement );
- }
-
- return found;
- }
-
-
- private boolean isOptional(IModelElement element) {
- if ( element instanceof IPackageImport ) {
- return ((IPackageImport) element).isOptional();
- }
- else if ( element instanceof IRequiredBundle ) {
- return ((IRequiredBundle) element).isOptional();
- }
- else if ( element instanceof ILibraryImport ) {
- ILibrary lib = repositoryManager.resolveLibrary((ILibraryImport) element);
- for ( IPackageImport pi : lib.getImports() ) {
- if ( !isOptional(pi) ) {
- return false;
- }
- }
- return true;
- }
- else {
- // should never get this due to isRequirement test prior to calling this
- // developer error if found
- throw new IllegalStateException( "Invalid optional element test for " + element);
- }
- }
-
- private boolean isRequirement(IModelElement element) {
- return element instanceof IPackageImport || element instanceof IRequiredBundle || element instanceof ILibraryImport;
- }
-
-
+public class BundleResolver implements IBundleResolver
+{
+
+ private class BundleOrderComparator implements Comparator<ISigilBundle>
+ {
+ private IModelElement requirement;
+
+
+ public BundleOrderComparator( IModelElement requirement )
+ {
+ this.requirement = requirement;
+ }
+
+
+ public int compare( ISigilBundle o1, ISigilBundle o2 )
+ {
+ int c = compareVersions( o1, o2 );
+
+ if ( c == 0 )
+ {
+ c = compareImports( o1, o2 );
+ }
+
+ return c;
+ }
+
+
+ private int compareImports( ISigilBundle o1, ISigilBundle o2 )
+ {
+ int c1 = o1.getBundleInfo().getImports().size();
+ int c2 = o2.getBundleInfo().getImports().size();
+
+ if ( c1 < c2 )
+ {
+ return -1;
+ }
+ else if ( c2 > c1 )
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+
+ private int compareVersions( ISigilBundle o1, ISigilBundle o2 )
+ {
+ Version v1 = null;
+ Version v2 = null;
+ if ( requirement instanceof IPackageImport )
+ {
+ v1 = findExportVersion( ( IPackageImport ) requirement, o1 );
+ v2 = findExportVersion( ( IPackageImport ) requirement, o2 );
+ }
+ else if ( requirement instanceof IRequiredBundle )
+ {
+ v1 = o1.getBundleInfo().getVersion();
+ v2 = o1.getBundleInfo().getVersion();
+ }
+
+ if ( v1 == null )
+ {
+ if ( v2 == null )
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ else
+ {
+ if ( v2 == null )
+ {
+ return -1;
+ }
+ else
+ {
+ return v2.compareTo( v1 );
+ }
+ }
+ }
+
+
+ private Version findExportVersion( IPackageImport pi, ISigilBundle o1 )
+ {
+ for ( IPackageExport pe : o1.getBundleInfo().getExports() )
+ {
+ if ( pi.getPackageName().equals( pi.getPackageName() ) )
+ {
+ return pe.getVersion();
+ }
+ }
+
+ return null;
+ }
+
+ }
+
+ private class ResolutionContext
+ {
+ private final IModelElement root;
+ private final ResolutionConfig config;
+ private final IResolutionMonitor monitor;
+
+ private final Resolution resolution = new Resolution();
+ private final Set<IModelElement> parsed = new HashSet<IModelElement>();
+ private final LinkedList<IModelElement> requirements = new LinkedList<IModelElement>();
+
+
+ public ResolutionContext( IModelElement root, ResolutionConfig config, IResolutionMonitor monitor )
+ {
+ this.root = root;
+ this.config = config;
+ this.monitor = monitor;
+ }
+
+
+ public void enterModelElement( IModelElement element )
+ {
+ parsed.add( element );
+ }
+
+
+ public void exitModelElement( IModelElement element )
+ {
+ parsed.remove( element );
+ }
+
+
+ public boolean isNewModelElement( IModelElement element )
+ {
+ return !parsed.contains( element );
+ }
+
+
+ public boolean isValid()
+ {
+ return resolution.isSuccess();
+ }
+
+
+ public void setValid( boolean valid )
+ {
+ resolution.setSuccess( valid );
+ }
+
+
+ public ResolutionException newResolutionException()
+ {
+ return new ResolutionException( root, requirements.toArray( new IModelElement[requirements.size()] ) );
+ }
+
+
+ public void startRequirement( IModelElement element )
+ {
+ requirements.add( element );
+ monitor.startResolution( element );
+ }
+
+
+ public void endRequirement( IModelElement element )
+ {
+ ISigilBundle provider = resolution.getProvider( element );
+
+ setValid( provider != null || isOptional( element ) || config.isIgnoreErrors() );
+
+ if ( isValid() )
+ {
+ // only clear stack if valid
+ // else use it as an aid to trace errors
+ requirements.remove( element );
+ }
+
+ monitor.endResolution( element, provider );
+ }
+ }
+
+ private class Resolution implements IResolution
+ {
+ private Map<ISigilBundle, List<IModelElement>> providees = new HashMap<ISigilBundle, List<IModelElement>>();
+ private Map<IModelElement, ISigilBundle> providers = new HashMap<IModelElement, ISigilBundle>();
+ private boolean success = true; // assume success
+
+
+ boolean addProvider( IModelElement element, ISigilBundle provider )
+ {
+ providers.put( element, provider );
+
+ List<IModelElement> requirements = providees.get( provider );
+
+ boolean isNewProvider = requirements == null;
+
+ if ( isNewProvider )
+ {
+ requirements = new ArrayList<IModelElement>();
+ providees.put( provider, requirements );
+ }
+
+ requirements.add( element );
+
+ return isNewProvider;
+ }
+
+
+ void removeProvider( IModelElement element, ISigilBundle provider )
+ {
+ providers.remove( element );
+ List<IModelElement> e = providees.get( provider );
+ e.remove( element );
+ if ( e.isEmpty() )
+ {
+ providees.remove( provider );
+ }
+ }
+
+
+ void setSuccess( boolean success )
+ {
+ this.success = success;
+ }
+
+
+ public boolean isSuccess()
+ {
+ return success;
+ }
+
+
+ public ISigilBundle getProvider( IModelElement requirement )
+ {
+ return providers.get( requirement );
+ }
+
+
+ public Set<ISigilBundle> getBundles()
+ {
+ return providees.keySet();
+ }
+
+
+ public List<IModelElement> getMatchedRequirements( ISigilBundle bundle )
+ {
+ return providees.get( bundle );
+ }
+
+
+ public boolean isSynchronized()
+ {
+ for ( ISigilBundle b : getBundles() )
+ {
+ if ( !b.isSynchronized() )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ public void synchronize( IProgressMonitor monitor )
+ {
+ Set<ISigilBundle> bundles = getBundles();
+ SubMonitor progress = SubMonitor.convert( monitor, bundles.size() );
+
+ for ( ISigilBundle b : bundles )
+ {
+ if ( monitor.isCanceled() )
+ {
+ break;
+ }
+
+ try
+ {
+ b.synchronize( progress.newChild( 1 ) );
+ }
+ catch ( IOException e )
+ {
+ BldCore.error( "Failed to synchronize " + b, e );
+ }
+ }
+ }
+ }
+
+ private static final IResolutionMonitor NULL_MONITOR = new IResolutionMonitor()
+ {
+ public void endResolution( IModelElement requirement, ISigilBundle sigilBundle )
+ {
+ }
+
+
+ public boolean isCanceled()
+ {
+ return false;
+ }
+
+
+ public void startResolution( IModelElement requirement )
+ {
+ }
+ };
+
+ private IRepositoryManager repositoryManager;
+
+
+ public BundleResolver( IRepositoryManager repositoryManager )
+ {
+ this.repositoryManager = repositoryManager;
+ }
+
+
+ public IResolution resolve( IModelElement element, ResolutionConfig config, IResolutionMonitor monitor )
+ throws ResolutionException
+ {
+ if ( monitor == null )
+ {
+ monitor = NULL_MONITOR;
+ }
+ ResolutionContext ctx = new ResolutionContext( element, config, monitor );
+
+ resolveElement( element, ctx );
+
+ if ( !ctx.isValid() )
+ {
+ throw ctx.newResolutionException();
+ }
+
+ return ctx.resolution;
+ }
+
+
+ private void resolveElement( IModelElement element, ResolutionContext ctx ) throws ResolutionException
+ {
+ if ( isRequirement( element ) )
+ {
+ resolveRequirement( element, ctx );
+ }
+
+ if ( ctx.isValid() && element instanceof ICompoundModelElement )
+ {
+ resolveCompound( ( ICompoundModelElement ) element, ctx );
+ }
+ }
+
+
+ private void resolveCompound( ICompoundModelElement compound, ResolutionContext ctx ) throws ResolutionException
+ {
+ for ( IModelElement element : compound.children() )
+ {
+ if ( ctx.isNewModelElement( element ) )
+ {
+ if ( isRequirement( element ) )
+ {
+ resolveRequirement( element, ctx );
+ }
+ else if ( element instanceof ICompoundModelElement )
+ {
+ if ( !ctx.monitor.isCanceled() )
+ {
+ ctx.enterModelElement( element );
+ resolveElement( ( ICompoundModelElement ) element, ctx );
+ ctx.exitModelElement( element );
+ }
+ }
+
+ if ( !ctx.isValid() )
+ {
+ break;
+ }
+ }
+ }
+ }
+
+
+ private void resolveRequirement( IModelElement requirement, ResolutionContext ctx ) throws ResolutionException
+ {
+ if ( ctx.config.isOptional() || !isOptional( requirement ) )
+ {
+ ctx.startRequirement( requirement );
+
+ try
+ {
+ int[] priorities = repositoryManager.getPriorityLevels();
+
+ outer: for ( int i = 0; i < priorities.length; i++ )
+ {
+ List<ISigilBundle> providers = findProvidersAtPriority( priorities[i], requirement, ctx );
+
+ if ( !providers.isEmpty() && !ctx.monitor.isCanceled() )
+ {
+ if ( providers.size() > 1 )
+ {
+ Collections.sort( providers, new BundleOrderComparator( requirement ) );
+ }
+
+ for ( ISigilBundle provider : providers )
+ {
+ // reset validity - if there's another provider it can still be solved
+ ctx.setValid( true );
+ if ( ctx.resolution.addProvider( requirement, provider ) )
+ {
+ if ( ctx.config.isDependents() )
+ {
+ resolveElement( provider, ctx );
+ }
+
+ if ( ctx.isValid() )
+ {
+ break outer;
+ }
+ else
+ {
+ ctx.resolution.removeProvider( requirement, provider );
+ }
+ }
+ else
+ {
+ break outer;
+ }
+ }
+ }
+ }
+ }
+ finally
+ {
+ ctx.endRequirement( requirement );
+ }
+ }
+ }
+
+
+ private List<ISigilBundle> findProvidersAtPriority( int i, IModelElement requirement, ResolutionContext ctx )
+ throws ResolutionException
+ {
+ ArrayList<ISigilBundle> providers = new ArrayList<ISigilBundle>();
+
+ for ( IBundleRepository rep : repositoryManager.getRepositories( i ) )
+ {
+ if ( ctx.monitor.isCanceled() )
+ {
+ break;
+ }
+ providers.addAll( findProviders( requirement, ctx.config, rep ) );
+ }
+
+ return providers;
+ }
+
+
+ private Collection<ISigilBundle> findProviders( IModelElement requirement, ResolutionConfig config,
+ IBundleRepository rep ) throws ResolutionException
+ {
+ ArrayList<ISigilBundle> found = new ArrayList<ISigilBundle>();
+
+ if ( requirement instanceof IPackageImport )
+ {
+ IPackageImport pi = ( IPackageImport ) requirement;
+ found.addAll( rep.findAllProviders( pi, config.getOptions() ) );
+ }
+ else if ( requirement instanceof IRequiredBundle )
+ {
+ IRequiredBundle rb = ( IRequiredBundle ) requirement;
+ found.addAll( rep.findAllProviders( rb, config.getOptions() ) );
+ }
+ else if ( requirement instanceof ILibraryImport )
+ {
+ ILibrary lib = repositoryManager.resolveLibrary( ( ILibraryImport ) requirement );
+ if ( lib != null )
+ {
+ found.addAll( rep.findProviders( lib, config.getOptions() ) );
+ }
+ }
+ else
+ {
+ // shouldn't get here - developer error if do
+ // use isRequirement before getting anywhere near this logic...
+ throw new IllegalStateException( "Invalid requirement type " + requirement );
+ }
+
+ return found;
+ }
+
+
+ private boolean isOptional( IModelElement element )
+ {
+ if ( element instanceof IPackageImport )
+ {
+ return ( ( IPackageImport ) element ).isOptional();
+ }
+ else if ( element instanceof IRequiredBundle )
+ {
+ return ( ( IRequiredBundle ) element ).isOptional();
+ }
+ else if ( element instanceof ILibraryImport )
+ {
+ ILibrary lib = repositoryManager.resolveLibrary( ( ILibraryImport ) element );
+ for ( IPackageImport pi : lib.getImports() )
+ {
+ if ( !isOptional( pi ) )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ else
+ {
+ // should never get this due to isRequirement test prior to calling this
+ // developer error if found
+ throw new IllegalStateException( "Invalid optional element test for " + element );
+ }
+ }
+
+
+ private boolean isRequirement( IModelElement element )
+ {
+ return element instanceof IPackageImport || element instanceof IRequiredBundle
+ || element instanceof ILibraryImport;
+ }
+
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/DirectoryHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/DirectoryHelper.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/DirectoryHelper.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/DirectoryHelper.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.core.repository;
+
import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -34,61 +35,85 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-public class DirectoryHelper {
- public static void scanBundles(AbstractBundleRepository repository, List<ISigilBundle> bundles, IPath path, IPath source, boolean recursive) {
- File dir = path.toFile();
-
- if ( dir.exists() ) {
- for ( File f : dir.listFiles() ){
- if ( f.isDirectory() ) {
- if ( recursive ) {
- scanBundles( repository, bundles, new Path( f.getAbsolutePath() ), source, recursive );
- }
- }
- else if ( f.isFile() && f.getName().endsWith( ".jar" )){
- JarFile jar = null;
- try {
- jar = new JarFile(f);
- ISigilBundle bundle = buildBundle(repository, jar.getManifest(), f );
- if ( bundle != null ) {
- bundle.setSourcePathLocation( source );
- bundle.setSourceRootPath( new Path( "src" ) );
- bundles.add( bundle );
- }
- } catch (IOException e) {
- BldCore.error( "Failed to read jar file " + f, e );
- } catch (ModelElementFactoryException e) {
- BldCore.error( "Failed to build bundle " + f , e );
- } catch (RuntimeException e) {
- BldCore.error( "Failed to build bundle " + f , e );
- }
- finally {
- if ( jar != null ) {
- try {
- jar.close();
- } catch (IOException e) {
- BldCore.error( "Failed to close jar file", e );
- }
- }
- }
- }
- }
- }
- }
-
- private static ISigilBundle buildBundle(
- AbstractBundleRepository repository, Manifest manifest, File f) {
- IBundleModelElement info = repository.buildBundleModelElement( manifest );
-
- ISigilBundle bundle = null;
-
- if ( info != null ) {
- bundle = ModelElementFactory.getInstance().newModelElement( ISigilBundle.class );
- bundle.addChild(info);
- bundle.setLocation( new Path( f.getAbsolutePath() ) );
- }
- return bundle;
- }
+public class DirectoryHelper
+{
+ public static void scanBundles( AbstractBundleRepository repository, List<ISigilBundle> bundles, IPath path,
+ IPath source, boolean recursive )
+ {
+ File dir = path.toFile();
+
+ if ( dir.exists() )
+ {
+ for ( File f : dir.listFiles() )
+ {
+ if ( f.isDirectory() )
+ {
+ if ( recursive )
+ {
+ scanBundles( repository, bundles, new Path( f.getAbsolutePath() ), source, recursive );
+ }
+ }
+ else if ( f.isFile() && f.getName().endsWith( ".jar" ) )
+ {
+ JarFile jar = null;
+ try
+ {
+ jar = new JarFile( f );
+ ISigilBundle bundle = buildBundle( repository, jar.getManifest(), f );
+ if ( bundle != null )
+ {
+ bundle.setSourcePathLocation( source );
+ bundle.setSourceRootPath( new Path( "src" ) );
+ bundles.add( bundle );
+ }
+ }
+ catch ( IOException e )
+ {
+ BldCore.error( "Failed to read jar file " + f, e );
+ }
+ catch ( ModelElementFactoryException e )
+ {
+ BldCore.error( "Failed to build bundle " + f, e );
+ }
+ catch ( RuntimeException e )
+ {
+ BldCore.error( "Failed to build bundle " + f, e );
+ }
+ finally
+ {
+ if ( jar != null )
+ {
+ try
+ {
+ jar.close();
+ }
+ catch ( IOException e )
+ {
+ BldCore.error( "Failed to close jar file", e );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ private static ISigilBundle buildBundle( AbstractBundleRepository repository, Manifest manifest, File f )
+ {
+ IBundleModelElement info = repository.buildBundleModelElement( manifest );
+
+ ISigilBundle bundle = null;
+
+ if ( info != null )
+ {
+ bundle = ModelElementFactory.getInstance().newModelElement( ISigilBundle.class );
+ bundle.addChild( info );
+ bundle.setLocation( new Path( f.getAbsolutePath() ) );
+ }
+
+ return bundle;
+ }
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/FileSystemRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/FileSystemRepository.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/FileSystemRepository.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/FileSystemRepository.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.core.repository;
+
import java.util.ArrayList;
import org.apache.felix.sigil.model.eclipse.ISigilBundle;
@@ -26,40 +27,53 @@
import org.apache.felix.sigil.repository.IRepositoryVisitor;
import org.eclipse.core.runtime.IPath;
-public class FileSystemRepository extends AbstractBundleRepository {
- private ArrayList<ISigilBundle> bundles;
- private IPath path;
- private boolean recurse;
-
- public FileSystemRepository(String id, IPath path, boolean recurse) {
- super(id);
- this.path = path;
- this.recurse = recurse;
- }
-
- @Override
- public void accept(IRepositoryVisitor visitor, int options) {
- synchronized( this ) {
- if ( bundles == null ) {
- bundles = new ArrayList<ISigilBundle>();
- DirectoryHelper.scanBundles(this, bundles, path, null, recurse);
- }
- }
-
- for ( ISigilBundle b : bundles ) {
- if ( !visitor.visit(b) ) {
- break;
- }
- }
- }
-
- public void refresh() {
- synchronized( this ) {
- bundles = null;
- }
-
- notifyChange();
- }
+public class FileSystemRepository extends AbstractBundleRepository
+{
+
+ private ArrayList<ISigilBundle> bundles;
+ private IPath path;
+ private boolean recurse;
+
+
+ public FileSystemRepository( String id, IPath path, boolean recurse )
+ {
+ super( id );
+ this.path = path;
+ this.recurse = recurse;
+ }
+
+
+ @Override
+ public void accept( IRepositoryVisitor visitor, int options )
+ {
+ synchronized ( this )
+ {
+ if ( bundles == null )
+ {
+ bundles = new ArrayList<ISigilBundle>();
+ DirectoryHelper.scanBundles( this, bundles, path, null, recurse );
+ }
+ }
+
+ for ( ISigilBundle b : bundles )
+ {
+ if ( !visitor.visit( b ) )
+ {
+ break;
+ }
+ }
+ }
+
+
+ public void refresh()
+ {
+ synchronized ( this )
+ {
+ bundles = null;
+ }
+
+ notifyChange();
+ }
}
Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/FileSystemRepositoryProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/FileSystemRepositoryProvider.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/FileSystemRepositoryProvider.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/core/repository/FileSystemRepositoryProvider.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.core.repository;
+
import java.io.File;
import java.util.Properties;
@@ -27,16 +28,19 @@
import org.apache.felix.sigil.repository.RepositoryException;
import org.eclipse.core.runtime.Path;
-public class FileSystemRepositoryProvider implements IRepositoryProvider {
- public IBundleRepository createRepository(String id, Properties preferences)
- throws RepositoryException {
- String dir = preferences.getProperty("dir");
- if (!new File(dir).isDirectory()) {
- throw new RepositoryException("directory '" + dir +"' does not exist.");
- }
- boolean recurse = Boolean.valueOf(preferences.getProperty("recurse"));
- return new FileSystemRepository(id, new Path(dir), recurse);
- }
+public class FileSystemRepositoryProvider implements IRepositoryProvider
+{
+
+ public IBundleRepository createRepository( String id, Properties preferences ) throws RepositoryException
+ {
+ String dir = preferences.getProperty( "dir" );
+ if ( !new File( dir ).isDirectory() )
+ {
+ throw new RepositoryException( "directory '" + dir + "' does not exist." );
+ }
+ boolean recurse = Boolean.valueOf( preferences.getProperty( "recurse" ) );
+ return new FileSystemRepository( id, new Path( dir ), recurse );
+ }
}