You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/07/13 15:26:06 UTC

svn commit: r793581 [8/23] - in /felix/trunk/sigil: ./ bld-ivy/ bld-ivy/example/ bld-ivy/example/dependence/ bld-ivy/example/dependence/dependee/ bld-ivy/example/dependence/dependee/src/ bld-ivy/example/dependence/dependee/src/standalone/ bld-ivy/examp...

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/Library.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/Library.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/Library.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/Library.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.internal.model.eclipse;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.cauldron.sigil.model.AbstractCompoundModelElement;
+import org.cauldron.sigil.model.eclipse.ILibrary;
+import org.cauldron.sigil.model.osgi.IPackageImport;
+import org.cauldron.sigil.model.osgi.IRequiredBundle;
+import org.osgi.framework.Version;
+
+public class Library extends AbstractCompoundModelElement implements ILibrary {
+
+	private static final long serialVersionUID = 1L;
+	
+	private String name;
+	private Version version;
+	private Set<IRequiredBundle> bundles;
+	private Set<IPackageImport> imports;
+	
+	public Library() {
+		super("Library");
+		bundles = new HashSet<IRequiredBundle>();
+		imports = new HashSet<IPackageImport>();
+	}
+	
+	public void addBundle(IRequiredBundle bundle) {
+		bundles.add(bundle);
+	}
+
+	public void addImport(IPackageImport pi) {
+		imports.add(pi);
+	}
+
+	public Collection<IRequiredBundle> getBundles() {
+		return bundles;
+	}
+
+	public Collection<IPackageImport> getImports() {
+		return imports;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public Version getVersion() {
+		return version;
+	}
+
+	public void removeBundle(IRequiredBundle bundle) {
+		bundles.remove(bundle);
+	}
+
+	public void removeImport(IPackageImport pi) {
+		imports.remove(pi);
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public void setVersion(Version version) {
+		this.version = version;
+	}
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/LibraryImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/LibraryImport.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/LibraryImport.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/LibraryImport.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.internal.model.eclipse;
+
+import org.cauldron.sigil.model.AbstractModelElement;
+import org.cauldron.sigil.model.common.VersionRange;
+import org.cauldron.sigil.model.eclipse.ILibraryImport;
+
+public class LibraryImport extends AbstractModelElement implements ILibraryImport {
+
+	private static final long serialVersionUID = 1L;
+
+	public LibraryImport() {
+		super("Library Import");
+	}
+
+	private String libraryName;
+	private VersionRange range = VersionRange.ANY_VERSION;
+	
+	public String getLibraryName() {
+		return libraryName;
+	}
+
+	public VersionRange getVersions() {
+		return range;
+	}
+
+	public void setLibraryName(String name) {
+		this.libraryName = name;
+	}
+
+	public void setVersions(VersionRange range) {
+		this.range = range;
+	}
+
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/SigilBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/SigilBundle.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/SigilBundle.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/eclipse/SigilBundle.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.internal.model.eclipse;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.cauldron.bld.core.BldCore;
+import org.cauldron.sigil.model.AbstractCompoundModelElement;
+import org.cauldron.sigil.model.eclipse.IDownloadJar;
+import org.cauldron.sigil.model.eclipse.ISCAComposite;
+import org.cauldron.sigil.model.eclipse.ISigilBundle;
+import org.cauldron.sigil.model.osgi.IBundleModelElement;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.model.osgi.IPackageImport;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+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;
+	
+    private IBundleModelElement bundle;
+    private IDownloadJar download;
+    private Set<IPath> sourcePaths;
+    private Set<IPath> libraryPaths;
+    private Set<ISCAComposite> composites;
+    private Set<String> classpath;
+    private Set<String> packages;
+    private Set<String> dlPackages;
+    private IPath location;
+
+	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>();
+        classpath = new HashSet<String>();
+        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() {
+        return bundle;
+    }
+    
+    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 void addLibraryPath( IPath path ) {
+        libraryPaths.add( path );
+    }
+    
+    public void removeLibraryPath( IPath path ) {
+        libraryPaths.remove( path );
+    }
+    
+    public Set<IPath> getLibraryPaths() {
+        return libraryPaths;
+    }
+    
+    public void addSourcePath( IPath path ) {
+        sourcePaths.add( path );
+    }
+    
+    public void removeSourcePath( IPath path ) {
+        sourcePaths.remove( path );
+    }
+    
+    public Set<IPath> getSourcePaths() {
+        return sourcePaths;
+    }
+
+    public void clearSourcePaths() {
+    	sourcePaths.clear();
+	}
+    
+	public void addComposite(ISCAComposite composite) {
+        composites.add( composite );
+        composite.setParent(this);
+    }
+
+    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;
+	}
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/BundleModelElement.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/BundleModelElement.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/BundleModelElement.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/BundleModelElement.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,382 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.internal.model.osgi;
+
+import java.net.URI;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.cauldron.sigil.model.AbstractCompoundModelElement;
+import org.cauldron.sigil.model.InvalidModelException;
+import org.cauldron.sigil.model.eclipse.ILibraryImport;
+import org.cauldron.sigil.model.osgi.IBundleModelElement;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.model.osgi.IPackageImport;
+import org.cauldron.sigil.model.osgi.IRequiredBundle;
+import org.osgi.framework.Version;
+
+public class BundleModelElement extends AbstractCompoundModelElement implements IBundleModelElement {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+    // required obr values
+    private URI updateLocation;
+    private String symbolicName;
+    private Version version = Version.emptyVersion;
+    private Set<IPackageImport> imports;
+    private Set<IPackageExport> exports;
+    private Set<IRequiredBundle> requires;
+    private URI sourceLocation;
+    private Set<String> classpathElements;
+    private IRequiredBundle fragmentHost;
+
+    // human readable values
+    private String name;
+    private String description;
+    private String category;
+    private URI licenseURI;
+    private URI docURI;
+    private String vendor;
+    private String contactAddress;
+    private String copyright;
+    
+    // internal values
+    private String activator;
+    private Set<ILibraryImport> libraries;
+
+    public BundleModelElement() {
+    	super( "OSGi Bundle" );
+        this.imports = new HashSet<IPackageImport>();
+        this.exports = new HashSet<IPackageExport>();
+        this.requires = new HashSet<IRequiredBundle>();
+        this.classpathElements = new HashSet<String>();
+        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);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getCategory()
+	 */
+    public String getCategory() {
+        return category;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setCategory(java.lang.String)
+	 */
+    public void setCategory(String category) {
+        this.category = category;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getContactAddress()
+	 */
+    public String getContactAddress() {
+        return contactAddress;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setContactAddress(java.lang.String)
+	 */
+    public void setContactAddress(String contactAddress) {
+        this.contactAddress = contactAddress;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getCopyright()
+	 */
+    public String getCopyright() {
+        return copyright;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setCopyright(java.lang.String)
+	 */
+    public void setCopyright(String copyright) {
+        this.copyright = copyright;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getDocURI()
+	 */
+    public URI getDocURI() {
+        return docURI;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setDocURI(java.net.URI)
+	 */
+    public void setDocURI(URI docURI) {
+        this.docURI = docURI;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getExports()
+	 */
+    public Set<IPackageExport> getExports() {
+        return exports;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#addExport(org.cauldron.sigil.model.osgi.PackageExport)
+	 */
+    public void addExport(IPackageExport packageExport) {
+        exports.add(packageExport);
+        packageExport.setParent(this);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#removeExport(org.cauldron.sigil.model.osgi.PackageExport)
+	 */
+    public void removeExport(IPackageExport packageExport) {
+    	if ( exports.remove(packageExport) ) {
+    		packageExport.setParent(null);
+    	}
+    }
+    
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getImports()
+	 */
+    public Set<IPackageImport> getImports() {
+        return imports;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#addImport(org.cauldron.sigil.model.osgi.PackageImport)
+	 */
+    public void addImport(IPackageImport packageImport) {
+        imports.add(packageImport);
+        packageImport.setParent(this);
+    }
+    
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#removeImport(org.cauldron.sigil.model.osgi.PackageImport)
+	 */
+    public void removeImport(IPackageImport packageImport) {
+    	if ( imports.remove( packageImport ) ) {
+    		packageImport.setParent(null);
+    	}
+    }
+    
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getRequiredBundles()
+	 */
+    public Set<IRequiredBundle> getRequiredBundles() {
+        return requires;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#addRequiredBundle(org.cauldron.sigil.model.osgi.RequiresBundle)
+	 */
+    public void addRequiredBundle(IRequiredBundle bundle) {
+        requires.add( bundle );
+        bundle.setParent(this);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#removeRequiredBundle(org.cauldron.sigil.model.osgi.RequiresBundle)
+	 */
+    public void removeRequiredBundle(IRequiredBundle bundle) {
+    	if ( requires.remove(bundle) ) {
+    		bundle.setParent(null);
+    	}
+    }
+    
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getLicenseURI()
+	 */
+    public URI getLicenseURI() {
+        return licenseURI;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setLicenseURI(java.net.URI)
+	 */
+    public void setLicenseURI(URI licenseURI) {
+        this.licenseURI = licenseURI;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getSourceLocation()
+	 */
+    public URI getSourceLocation() {
+        return sourceLocation;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setSourceLocation(java.net.URI)
+	 */
+    public void setSourceLocation(URI sourceLocation) {
+        this.sourceLocation = sourceLocation;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getSymbolicName()
+	 */
+    public String getSymbolicName() {
+        return symbolicName;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setSymbolicName(java.lang.String)
+	 */
+    public void setSymbolicName(String symbolicName) {
+        this.symbolicName = symbolicName == null ? null : symbolicName.intern();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getUpdateLocation()
+	 */
+    public URI getUpdateLocation() {
+        return updateLocation;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setUpdateLocation(java.net.URI)
+	 */
+    public void setUpdateLocation(URI updateLocation) {
+        this.updateLocation = updateLocation;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getVendor()
+	 */
+    public String getVendor() {
+    		return vendor;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setVendor(java.lang.String)
+	 */
+    public void setVendor(String vendor) {
+        this.vendor = vendor;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#getVersion()
+	 */
+    public Version getVersion() {
+    	return version;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.model.osgi.IBundleModelElement#setVersion(java.lang.String)
+	 */
+    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 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 (IPackageExport pe : exports ) {
+            bd.exports.add((IPackageExport) pe.clone());
+        }
+        
+        for ( IRequiredBundle rb : requires ) {
+            bd.requires.add((IRequiredBundle) rb.clone());
+        }
+
+        return bd;
+    }
+
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+
+        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;
+	}
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/PackageExport.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/PackageExport.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/PackageExport.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/PackageExport.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.internal.model.osgi;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.cauldron.sigil.model.AbstractModelElement;
+import org.cauldron.sigil.model.eclipse.ISigilBundle;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.osgi.framework.Version;
+
+public class PackageExport extends AbstractModelElement implements IPackageExport {
+
+	private static final long serialVersionUID = 1L;
+
+	private String name;
+    private Version version;
+    private HashSet<String> uses = new HashSet<String>();
+
+	public PackageExport() {
+		super("OSGi Package Export");
+	}
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageExport#getPackageName()
+	 */
+    public String getPackageName() {
+        return name;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageExport#setPackageName(java.lang.String)
+	 */
+    public void setPackageName(String packageName) {
+        this.name = packageName;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageExport#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;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageExport#setVersion(java.lang.String)
+	 */
+    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);
+			}
+		}
+	}
+	
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/PackageImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/PackageImport.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/PackageImport.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/PackageImport.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.internal.model.osgi;
+
+import org.cauldron.sigil.model.AbstractModelElement;
+import org.cauldron.sigil.model.IModelElement;
+import org.cauldron.sigil.model.InvalidModelException;
+import org.cauldron.sigil.model.common.VersionRange;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.model.osgi.IPackageImport;
+
+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;
+
+    public PackageImport() {
+    	super( "OSGi Package Import" );
+    }
+
+    @Override
+	public void checkValid() throws InvalidModelException {
+    	if ( name == null ) {
+    		throw new InvalidModelException( this, "Package name must be set" );
+    	}
+	}
+
+	/* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageImport#isOptional()
+	 */
+    public boolean isOptional() {
+        return optional;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageImport#setOptional(boolean)
+	 */
+    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() {
+        return name;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageImport#setName(java.lang.String)
+	 */
+    public void setPackageName(String name) {
+        this.name = name;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageImport#getVersion()
+	 */
+    public VersionRange getVersions() {
+        return versions;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IPackageImport#setVersion(java.lang.String)
+	 */
+    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)
+            return true;
+        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());
+			}
+		}
+	}
+
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/RequiredBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/RequiredBundle.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/RequiredBundle.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/internal/model/osgi/RequiredBundle.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.internal.model.osgi;
+
+import org.cauldron.sigil.model.AbstractModelElement;
+import org.cauldron.sigil.model.IModelElement;
+import org.cauldron.sigil.model.common.VersionRange;
+import org.cauldron.sigil.model.osgi.IBundleModelElement;
+import org.cauldron.sigil.model.osgi.IRequiredBundle;
+
+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");
+	}
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IRequiresBundle#getSymbolicName()
+	 */
+    public String getSymbolicName() {
+        return symbolicName;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IRequiresBundle#setSymbolicName(java.lang.String)
+	 */
+    public void setSymbolicName(String symbolicName) {
+        this.symbolicName = symbolicName == null ? null : symbolicName.intern();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IRequiresBundle#getVersion()
+	 */
+    public VersionRange getVersions() {
+        return versions;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.cauldron.sigil.internal.model.osgi.IRequiresBundle#setVersion(java.lang.String)
+	 */
+    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)
+            return true;
+        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;
+		}
+	}
+
+	@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());
+			}
+		}
+	}
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/licence/ILicenseManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/licence/ILicenseManager.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/licence/ILicenseManager.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/licence/ILicenseManager.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.licence;
+
+import java.util.Set;
+import java.util.regex.Pattern;
+
+//import org.cauldron.sigil.model.project.ISigilProjectModel;
+
+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);
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/licence/ILicensePolicy.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/licence/ILicensePolicy.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/licence/ILicensePolicy.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/licence/ILicensePolicy.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.licence;
+
+import org.cauldron.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);
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/BundleResolver.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/BundleResolver.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/BundleResolver.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/BundleResolver.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,444 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.repository;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.cauldron.bld.core.BldCore;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.cauldron.sigil.model.ICompoundModelElement;
+import org.cauldron.sigil.model.IModelElement;
+import org.cauldron.sigil.model.eclipse.ILibrary;
+import org.cauldron.sigil.model.eclipse.ILibraryImport;
+import org.cauldron.sigil.model.eclipse.ISigilBundle;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.model.osgi.IPackageImport;
+import org.cauldron.sigil.model.osgi.IRequiredBundle;
+import org.cauldron.sigil.repository.IBundleRepository;
+import org.cauldron.sigil.repository.IBundleResolver;
+import org.cauldron.sigil.repository.IRepositoryManager;
+import org.cauldron.sigil.repository.IResolution;
+import org.cauldron.sigil.repository.IResolutionMonitor;
+import org.cauldron.sigil.repository.ResolutionConfig;
+import org.cauldron.sigil.repository.ResolutionException;
+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;
+	}
+	
+	
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/DirectoryHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/DirectoryHelper.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/DirectoryHelper.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/DirectoryHelper.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.repository;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.cauldron.bld.core.BldCore;
+import org.cauldron.sigil.model.ModelElementFactory;
+import org.cauldron.sigil.model.ModelElementFactoryException;
+import org.cauldron.sigil.model.eclipse.ISigilBundle;
+import org.cauldron.sigil.model.osgi.IBundleModelElement;
+import org.cauldron.sigil.repository.AbstractBundleRepository;
+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;
+	}
+
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/FileSystemRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/FileSystemRepository.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/FileSystemRepository.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/FileSystemRepository.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.repository;
+
+import java.util.ArrayList;
+
+import org.cauldron.sigil.model.eclipse.ISigilBundle;
+import org.cauldron.sigil.repository.AbstractBundleRepository;
+import org.cauldron.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();
+	}
+
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/FileSystemRepositoryProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/FileSystemRepositoryProvider.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/FileSystemRepositoryProvider.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/FileSystemRepositoryProvider.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.repository;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.cauldron.sigil.repository.IBundleRepository;
+import org.cauldron.sigil.repository.IRepositoryProvider;
+import org.cauldron.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);		
+	}
+
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/ProgressWrapper.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/ProgressWrapper.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/ProgressWrapper.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/ProgressWrapper.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.repository;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.cauldron.sigil.repository.IResolutionMonitor;
+
+public class ProgressWrapper implements IProgressMonitor {
+
+	private IResolutionMonitor monitor;
+	
+	public ProgressWrapper(IResolutionMonitor monitor) {
+		this.monitor = monitor;
+	}
+
+	public boolean isCanceled() {
+		return monitor.isCanceled();
+	}
+
+	public void beginTask(String name, int totalWork) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void done() {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void internalWorked(double work) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void setCanceled(boolean value) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void setTaskName(String name) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void subTask(String name) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void worked(int work) {
+		// TODO Auto-generated method stub
+
+	}
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/SystemRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/SystemRepository.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/SystemRepository.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/SystemRepository.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.repository;
+
+import java.io.IOException;
+import java.util.jar.JarFile;
+
+import org.cauldron.bld.core.BldCore;
+import org.cauldron.sigil.model.ModelElementFactory;
+import org.cauldron.sigil.model.ModelElementFactoryException;
+import org.cauldron.sigil.model.eclipse.ISigilBundle;
+import org.cauldron.sigil.model.osgi.IBundleModelElement;
+import org.cauldron.sigil.model.osgi.IPackageExport;
+import org.cauldron.sigil.repository.AbstractBundleRepository;
+import org.cauldron.sigil.repository.IRepositoryVisitor;
+import org.eclipse.core.runtime.IPath;
+
+public class SystemRepository extends AbstractBundleRepository {
+
+	private final String packages;
+	private final IPath frameworkPath;
+
+	public SystemRepository(String id, IPath frameworkPath, String packages) {
+		super(id);
+		this.frameworkPath = frameworkPath;
+		this.packages = packages;
+	}
+
+	private static ISigilBundle systemBundle;
+	
+	@Override
+	public void accept(IRepositoryVisitor visitor, int options) {
+		ISigilBundle bundle = loadSystemBundle();
+		
+		if ( bundle != null ) {
+			visitor.visit(bundle);
+		}
+	}
+
+	private synchronized ISigilBundle loadSystemBundle() {
+		if (systemBundle == null) {
+			systemBundle = ModelElementFactory.getInstance().newModelElement(ISigilBundle.class);
+			
+			JarFile jar = null;
+			
+			try {
+    			final IBundleModelElement info;
+				if (frameworkPath != null) {
+        			systemBundle.setLocation(frameworkPath);
+    				jar = new JarFile(frameworkPath.toFile());
+    				info = buildBundleModelElement(jar.getManifest());
+				} else {
+				    info = ModelElementFactory.getInstance().newModelElement(IBundleModelElement.class);
+				}
+				
+    			applyProfile(info);
+    			systemBundle.addChild(info);
+			} catch (IOException e) {
+				BldCore.error( "Failed to read jar file " + frameworkPath, e );
+			} catch (ModelElementFactoryException e) {
+				BldCore.error( "Failed to build bundle " + frameworkPath , e );
+			} catch (RuntimeException e) {
+				BldCore.error( "Failed to build bundle " + frameworkPath , e );
+			}
+			finally {
+				if (jar != null) {
+					try {
+						jar.close();
+					} catch (IOException e) {
+						BldCore.error( "Failed to close jar file", e );
+					}
+				}
+			}
+		}
+		
+		return systemBundle;
+	}
+
+	private void applyProfile(IBundleModelElement info) {
+		if (packages != null) {
+			for (String name : packages.split(",\\s*")) {
+				IPackageExport pe = ModelElementFactory.getInstance().newModelElement(IPackageExport.class);
+				pe.setPackageName(name);
+				info.addExport(pe);
+			}
+		}
+	}
+
+	public synchronized void refresh() {
+		systemBundle = null;
+		notifyChange();
+	}
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/SystemRepositoryProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/SystemRepositoryProvider.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/SystemRepositoryProvider.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/repository/SystemRepositoryProvider.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.repository;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.cauldron.sigil.repository.IBundleRepository;
+import org.cauldron.sigil.repository.IRepositoryProvider;
+import org.cauldron.sigil.repository.RepositoryException;
+import org.eclipse.core.runtime.Path;
+
+public class SystemRepositoryProvider implements IRepositoryProvider {
+
+	public IBundleRepository createRepository(String id, Properties properties)
+			throws RepositoryException {
+		String fw = properties.getProperty("framework");
+		Path frameworkPath = fw == null ? null : new Path(fw);
+		String extraPkgs = properties.getProperty("packages");
+		String profile = properties.getProperty("profile");
+		
+		try {
+			Properties p = readProfile(profile);
+    		String pkgs = p.getProperty("org.osgi.framework.system.packages") + "," + extraPkgs;
+			return new SystemRepository(id, frameworkPath, pkgs);
+		} catch (IOException e) {
+			throw new RepositoryException("Failed to load profile", e);
+		}
+	}
+	
+	public static Properties readProfile(String name) throws IOException {
+		if (name == null) {
+			String version = System.getProperty("java.specification.version");
+			String[] split = version.split("\\.");
+			String prefix = ("6".compareTo(split[1]) <= 0) ? "JavaSE-" : "J2SE-";
+			name = prefix + version;
+		}
+		
+		String profilePath = "profiles/" + name + ".profile";
+		InputStream in = SystemRepositoryProvider.class.getClassLoader().getResourceAsStream(profilePath);
+		
+		if (in == null)
+			throw new IOException("No such profile: " + profilePath);
+		
+		Properties p = new Properties();
+		p.load(in);
+		
+		return p;
+	}
+	
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/util/QuoteUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/util/QuoteUtil.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/util/QuoteUtil.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/bld/core/util/QuoteUtil.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.bld.core.util;
+
+import java.util.ArrayList;
+
+public class QuoteUtil {
+	public static String[] split(String str) {
+		ArrayList<String> split = new ArrayList<String>();
+		boolean quote = false;
+		StringBuffer buf = new StringBuffer(str.length());
+		
+		for ( int i = 0; i < str.length(); i++ ) {
+			char c = str.charAt(i);
+			switch ( c ) {
+			case '"':
+				quote = !quote;
+				break;
+			case ',':
+				if ( !quote ) {
+					split.add( buf.toString().trim() );
+					buf.setLength(0);
+					break;
+				}
+				// else fall through on purpose
+			default:
+				buf.append( c );
+			}
+		}
+		
+		if ( buf.length() > 0 ) {
+			split.add( buf.toString().trim() );
+		}
+		return split.toArray( new String[split.size()] );
+	}	
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/sigil/model/AbstractCompoundModelElement.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/sigil/model/AbstractCompoundModelElement.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/sigil/model/AbstractCompoundModelElement.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/sigil/model/AbstractCompoundModelElement.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.sigil.model;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+public abstract class AbstractCompoundModelElement extends AbstractModelElement implements ICompoundModelElement {
+
+	private static final long serialVersionUID = 1L;
+	
+	public AbstractCompoundModelElement(String description) {
+		super(description);
+	}
+
+	public boolean addChild(IModelElement child) throws InvalidModelException {
+		return support.addChild(child);
+	}
+
+	public boolean removeChild(IModelElement child) {
+		return support.removeChild(child);
+	}
+
+	public IModelElement[] children() {
+		return support.children();
+	}
+	
+	private static final ThreadLocal<Map<IModelWalker,Set<IModelElement>>> walkedLocal = new ThreadLocal<Map<IModelWalker,Set<IModelElement>>>();
+	
+	public void visit(IModelWalker walker) {
+		if ( walker.visit( this ) ) {
+			Map<IModelWalker,Set<IModelElement>> walked = walkedLocal.get();
+			boolean delete = false;
+			
+			if ( walked == null ) {
+				walked = new HashMap<IModelWalker, Set<IModelElement>>();
+				walkedLocal.set(walked);
+			}
+
+			Set<IModelElement> check = walked.get(walker);
+			
+			if ( check == null ) {
+				delete = true;
+				check = new HashSet<IModelElement>(); 
+			}
+			
+			check.add( this );
+			
+			try {
+				for ( IModelElement e : children() ) {
+					if ( !check.contains( e ) && walker.visit( e ) ) {
+						check.add( e );
+						if ( e instanceof ICompoundModelElement ) {
+							ICompoundModelElement c = (ICompoundModelElement) e;
+							c.visit(walker);
+						}
+					}
+				}
+			}
+			finally {
+				if ( delete ) {
+					walked.remove(walker);
+					
+					if ( walked.isEmpty() ) {
+						walkedLocal.set( null );
+					}
+				}
+			}
+		}
+	}
+
+	public Set<Class<? extends IModelElement>> getOptionalChildren() {
+		return support.getChildrenTypes(false);
+	}
+
+	public Set<Class<? extends IModelElement>> getRequiredChildren() {
+		return support.getChildrenTypes(true);
+	}
+
+	public <T extends IModelElement> T[] childrenOfType(Class<T> type) {
+		return support.childrenOfType( type );
+	}
+
+
+	@Override
+	public void checkValid() throws InvalidModelException {
+		super.checkValid();
+		
+		for ( IModelElement e : support.children() ) {
+			e.checkValid();
+		}
+	}	
+}

Added: felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/sigil/model/AbstractModelElement.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/sigil/model/AbstractModelElement.java?rev=793581&view=auto
==============================================================================
--- felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/sigil/model/AbstractModelElement.java (added)
+++ felix/trunk/sigil/org.cauldron.bld.core/src/org/cauldron/sigil/model/AbstractModelElement.java Mon Jul 13 13:25:46 2009
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.cauldron.sigil.model;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+
+public abstract class AbstractModelElement implements IModelElement {
+	
+	private static final long serialVersionUID = 1L;
+
+	private IModelElement parent;
+	
+    private String description;
+    private transient Map<Object, Object> meta;
+    private Map<Serializable, Serializable> serializedMeta;
+    private OverrideOptions override;
+    
+    protected final ModelElementSupport support;
+
+    public AbstractModelElement(String description) {
+    	support = new ModelElementSupport(this);
+    	this.description = description.intern();
+        this.meta = new HashMap<Object, Object>();
+        this.serializedMeta = new HashMap<Serializable, Serializable>();
+    }
+
+    public String getElementDescription() {
+        return description;
+    }
+
+    public Map<Object, Object> getMeta() {
+        return meta;
+    }
+
+    public void setMeta(Map<Object, Object> meta) {
+        this.meta = meta;
+    }
+
+    @Override
+    public AbstractModelElement clone() {
+		try {
+	        AbstractModelElement clone = (AbstractModelElement) super.clone();
+	   
+	        clone.meta = new HashMap<Object, Object>(meta);
+
+	        return clone;
+		} catch (CloneNotSupportedException e) {
+			// can't happen but make compiler happy
+			throw new IllegalStateException(e);
+		}
+    }
+
+    @SuppressWarnings("unchecked")
+	public <T extends IModelElement> T getAncestor(Class<T> type) {
+    	IModelElement parent = this.parent;
+    	
+    	while ( parent != null ) {
+    		if ( type.isInstance( parent ) ) {
+    			return (T) parent;
+    		}
+    		parent = parent.getParent();
+    	}
+    	
+		return null;
+	}
+
+	public IModelElement getParent() {
+		return parent;
+	}
+	
+	public void setParent( IModelElement parent ) {
+		if ( parent != null ) {
+			if ( this.parent != null && this.parent != parent ) {
+				throw new IllegalStateException( "Parent already installed");
+			}
+		}
+		
+		this.parent = parent;
+	}
+	
+    public void checkValid() throws InvalidModelException {
+    	for ( String req : getRequiredProperties() ) {
+    		try {
+				if ( getProperty( req ) == null ) {
+					throw new InvalidModelException(this, "Missing property " + req );
+				}
+			} catch (NoSuchMethodException e) {
+				throw new InvalidModelException( this, "No such property " + req );
+			}
+    	}
+	}
+
+	public Object getProperty(String name) throws NoSuchMethodException {
+		return support.getProperty(name);
+	}
+
+	public void setProperty(String name, Object value)
+			throws NoSuchMethodException {
+		support.setProperty(name, value);
+	}
+
+	public void addProperty(String name, Object value)
+			throws NoSuchMethodException {
+		support.addProperty(name, value);
+	}
+
+	public void removeProperty(String name, Object value)
+			throws NoSuchMethodException {
+		support.removeProperty(name, value);
+	}
+
+	public Object getDefaultPropertyValue(String name) {
+		return support.getDefaultPropertyValue( name );
+	}
+
+	public Set<String> getPropertyNames() {
+		return support.getPropertyNames();
+	}
+
+	public Set<String> getRequiredProperties() {
+		return Collections.emptySet();
+	}
+
+	protected Object writeReplace() {
+        AbstractModelElement clone = clone();
+
+        for (Map.Entry<Object, Object> e : clone.meta.entrySet()) {
+            if (e.getKey() instanceof Serializable && e.getValue() instanceof Serializable) {
+                serializedMeta.put((Serializable) e.getKey(), (Serializable) e.getValue());
+            }
+        }
+
+        clone.meta.clear();
+
+        return clone;
+    }
+
+    public Class<?> getPropertyType(String name) throws NoSuchMethodException {
+		return support.getPropertyType(name);
+	}
+
+	protected Object readResolve() {
+        this.meta = new HashMap<Object, Object>(serializedMeta);
+        serializedMeta.clear();
+        return this;
+    }
+
+	public OverrideOptions getOverride() {
+		return override;
+	}
+
+	public void setOverride(OverrideOptions override) {
+		this.override = override;
+	}
+}