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 [11/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/...
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/install/OSGiInstallManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/install/OSGiInstallManager.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/install/OSGiInstallManager.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/install/OSGiInstallManager.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.eclipse.internal.install;
+
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -48,220 +49,296 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
-public class OSGiInstallManager implements IOSGiInstallManager, IPropertyChangeListener {
- private static final int NORMAL_PRIORITY = 0;
-
- private LinkedList<IOSGiInstallBuilder> builders = new LinkedList<IOSGiInstallBuilder>();
-
- private HashMap<IPath, IOSGiInstall> pathToinstall = new HashMap<IPath, IOSGiInstall>();
- private HashMap<String, IOSGiInstall> idToInstall = new HashMap<String, IOSGiInstall>();
-
- private String defaultId;
-
- private boolean initialised;
-
- public IOSGiInstall findInstall(String id) {
- init();
- return idToInstall.get(id);
- }
-
- public String[] getInstallIDs() {
- init();
- return idToInstall.keySet().toArray( new String[idToInstall.size()] );
- }
-
- public IOSGiInstall[] getInstalls() {
- init();
- return idToInstall.values().toArray( new IOSGiInstall[idToInstall.size()] );
- }
-
- public IOSGiInstall getDefaultInstall() {
- init();
- return findInstall(defaultId);
- }
-
- public IOSGiInstallType findInstallType(String location) {
- IOSGiInstallType type = null;
-
- try {
- IOSGiInstall install = buildInstall("tmp", new Path( location ) );
- type = install == null ? null : install.getType();
- } catch (CoreException e) {
- SigilCore.error( "Failed to build install", e);
- }
-
- return type;
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- synchronized( this ) {
- if ( event.getProperty().equals(SigilCore.OSGI_INSTALLS) ) {
- clearInstalls();
- String val = (String) event.getNewValue();
- addInstalls(val);
- }
- else if ( event.getProperty().equals( SigilCore.OSGI_DEFAULT_INSTALL_ID ) ) {
- defaultId = (String) event.getNewValue();
- }
- }
- }
-
- private void init() {
- boolean show = false;
-
- IPreferenceStore prefs = getPreferenceStore();
-
- synchronized( this ) {
- if ( !initialised ) {
- initialised = true;
-
- prefs.addPropertyChangeListener(this);
-
- String val = prefs.getString(SigilCore.OSGI_INSTALLS);
-
- boolean noAsk = prefs.getBoolean(SigilCore.PREFERENCES_NOASK_OSGI_INSTALL);
- if(val == null || val.trim().length() == 0) {
- show = !noAsk;
- }
- else {
- addInstalls(val);
- defaultId = prefs.getString(SigilCore.OSGI_DEFAULT_INSTALL_ID);
- }
- }
- }
-
- if ( show ) {
- showInstallPrefs(prefs);
- }
- }
-
- private void addInstalls(String prop) {
- if ( prop != null && prop.trim().length() > 0 ) {
- IPreferenceStore prefs = getPreferenceStore();
-
- for (String id : prop.split(",")) {
- String path = prefs.getString( SigilCore.OSGI_INSTALL_PREFIX + id );
- addInstall(id, new Path( path ) );
- }
- }
- }
-
- private IPreferenceStore getPreferenceStore() {
- return SigilCore.getDefault().getPreferenceStore();
- }
-
- private void showInstallPrefs(final IPreferenceStore prefs) {
- Runnable r = new Runnable() {
- public void run() {
- MessageDialogWithToggle questionDialog = MessageDialogWithToggle.openYesNoQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Sigil Configuration", "Missing OSGi installation. Open preferences to configure it now?", "Do not show this message again", false, null, null);
- prefs.setValue(SigilCore.PREFERENCES_NOASK_OSGI_INSTALL, questionDialog.getToggleState());
- if(questionDialog.getReturnCode() == IDialogConstants.YES_ID) {
- PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, SigilCore.OSGI_INSTALLS_PREFERENCES_ID, null, null);
- dialog.open();
- }
- }
- };
- Display d = Display.getCurrent();
- if ( d == null ) {
- d = Display.getDefault();
- d.asyncExec(r);
- }
- else {
- d.syncExec(r);
- }
- }
-
- private IOSGiInstall addInstall(String id, IPath path) {
- IOSGiInstall install = pathToinstall.get(path);
-
- if ( install == null ) {
- try {
- install = buildInstall(id, path);
- if ( install != null ) {
- pathToinstall.put( path, install );
- idToInstall.put( install.getId(), install );
- }
- }
- catch (CoreException e) {
- SigilCore.error( "Failed to build install for " + path, e);
- }
- }
-
- return install;
- }
-
- private IOSGiInstall buildInstall(String id, IPath path) throws CoreException {
- initBuilders();
- IOSGiInstall install = null;
-
- for ( IOSGiInstallBuilder b : builders ) {
- install = b.build(id, path);
-
- if ( install != null ) {
- break;
- }
- }
-
- return install;
- }
-
- private void clearInstalls() {
- idToInstall.clear();
- pathToinstall.clear();
- }
-
- private void initBuilders() {
- synchronized( builders ) {
- if ( builders.isEmpty() ) {
- final HashMap<IOSGiInstallBuilder, Integer> tmp = new HashMap<IOSGiInstallBuilder, Integer>();
-
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint p = registry.getExtensionPoint(SigilCore.INSTALL_BUILDER_EXTENSION_POINT_ID);
- for ( IExtension e : p.getExtensions() ) {
- for ( IConfigurationElement c : e.getConfigurationElements() ) {
- createBuilderFromElement(c, tmp);
- }
- }
-
- builders = new LinkedList<IOSGiInstallBuilder>(tmp.keySet());
- Collections.sort(builders, new Comparator<IOSGiInstallBuilder>() {
- public int compare(IOSGiInstallBuilder o1, IOSGiInstallBuilder o2) {
- int p1 = tmp.get(o1);
- int p2 = tmp.get(o2);
-
- if ( p1 == p2 ) {
- return 0;
- }
- else if ( p1 > p2 ) {
- return -1;
- }
- else {
- return 1;
- }
- }
- });
- }
- }
- }
-
- private void createBuilderFromElement(IConfigurationElement c, Map<IOSGiInstallBuilder, Integer> builder) {
- try {
- IOSGiInstallBuilder b = (IOSGiInstallBuilder) c.createExecutableExtension("class");
- int priority = parsePriority( c );
- builder.put(b, priority);
- } catch (CoreException e) {
- SigilCore.error("Failed to create builder", e);
- }
- }
-
- private int parsePriority(IConfigurationElement c) {
- String str = c.getAttribute("priority");
-
- if ( str == null ) {
- return NORMAL_PRIORITY;
- }
- else {
- return Integer.parseInt(str);
- }
- }
+
+public class OSGiInstallManager implements IOSGiInstallManager, IPropertyChangeListener
+{
+ private static final int NORMAL_PRIORITY = 0;
+
+ private LinkedList<IOSGiInstallBuilder> builders = new LinkedList<IOSGiInstallBuilder>();
+
+ private HashMap<IPath, IOSGiInstall> pathToinstall = new HashMap<IPath, IOSGiInstall>();
+ private HashMap<String, IOSGiInstall> idToInstall = new HashMap<String, IOSGiInstall>();
+
+ private String defaultId;
+
+ private boolean initialised;
+
+
+ public IOSGiInstall findInstall( String id )
+ {
+ init();
+ return idToInstall.get( id );
+ }
+
+
+ public String[] getInstallIDs()
+ {
+ init();
+ return idToInstall.keySet().toArray( new String[idToInstall.size()] );
+ }
+
+
+ public IOSGiInstall[] getInstalls()
+ {
+ init();
+ return idToInstall.values().toArray( new IOSGiInstall[idToInstall.size()] );
+ }
+
+
+ public IOSGiInstall getDefaultInstall()
+ {
+ init();
+ return findInstall( defaultId );
+ }
+
+
+ public IOSGiInstallType findInstallType( String location )
+ {
+ IOSGiInstallType type = null;
+
+ try
+ {
+ IOSGiInstall install = buildInstall( "tmp", new Path( location ) );
+ type = install == null ? null : install.getType();
+ }
+ catch ( CoreException e )
+ {
+ SigilCore.error( "Failed to build install", e );
+ }
+
+ return type;
+ }
+
+
+ public void propertyChange( PropertyChangeEvent event )
+ {
+ synchronized ( this )
+ {
+ if ( event.getProperty().equals( SigilCore.OSGI_INSTALLS ) )
+ {
+ clearInstalls();
+ String val = ( String ) event.getNewValue();
+ addInstalls( val );
+ }
+ else if ( event.getProperty().equals( SigilCore.OSGI_DEFAULT_INSTALL_ID ) )
+ {
+ defaultId = ( String ) event.getNewValue();
+ }
+ }
+ }
+
+
+ private void init()
+ {
+ boolean show = false;
+
+ IPreferenceStore prefs = getPreferenceStore();
+
+ synchronized ( this )
+ {
+ if ( !initialised )
+ {
+ initialised = true;
+
+ prefs.addPropertyChangeListener( this );
+
+ String val = prefs.getString( SigilCore.OSGI_INSTALLS );
+
+ boolean noAsk = prefs.getBoolean( SigilCore.PREFERENCES_NOASK_OSGI_INSTALL );
+ if ( val == null || val.trim().length() == 0 )
+ {
+ show = !noAsk;
+ }
+ else
+ {
+ addInstalls( val );
+ defaultId = prefs.getString( SigilCore.OSGI_DEFAULT_INSTALL_ID );
+ }
+ }
+ }
+
+ if ( show )
+ {
+ showInstallPrefs( prefs );
+ }
+ }
+
+
+ private void addInstalls( String prop )
+ {
+ if ( prop != null && prop.trim().length() > 0 )
+ {
+ IPreferenceStore prefs = getPreferenceStore();
+
+ for ( String id : prop.split( "," ) )
+ {
+ String path = prefs.getString( SigilCore.OSGI_INSTALL_PREFIX + id );
+ addInstall( id, new Path( path ) );
+ }
+ }
+ }
+
+
+ private IPreferenceStore getPreferenceStore()
+ {
+ return SigilCore.getDefault().getPreferenceStore();
+ }
+
+
+ private void showInstallPrefs( final IPreferenceStore prefs )
+ {
+ Runnable r = new Runnable()
+ {
+ public void run()
+ {
+ MessageDialogWithToggle questionDialog = MessageDialogWithToggle.openYesNoQuestion( PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow().getShell(), "Sigil Configuration",
+ "Missing OSGi installation. Open preferences to configure it now?",
+ "Do not show this message again", false, null, null );
+ prefs.setValue( SigilCore.PREFERENCES_NOASK_OSGI_INSTALL, questionDialog.getToggleState() );
+ if ( questionDialog.getReturnCode() == IDialogConstants.YES_ID )
+ {
+ PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn( null,
+ SigilCore.OSGI_INSTALLS_PREFERENCES_ID, null, null );
+ dialog.open();
+ }
+ }
+ };
+ Display d = Display.getCurrent();
+ if ( d == null )
+ {
+ d = Display.getDefault();
+ d.asyncExec( r );
+ }
+ else
+ {
+ d.syncExec( r );
+ }
+ }
+
+
+ private IOSGiInstall addInstall( String id, IPath path )
+ {
+ IOSGiInstall install = pathToinstall.get( path );
+
+ if ( install == null )
+ {
+ try
+ {
+ install = buildInstall( id, path );
+ if ( install != null )
+ {
+ pathToinstall.put( path, install );
+ idToInstall.put( install.getId(), install );
+ }
+ }
+ catch ( CoreException e )
+ {
+ SigilCore.error( "Failed to build install for " + path, e );
+ }
+ }
+
+ return install;
+ }
+
+
+ private IOSGiInstall buildInstall( String id, IPath path ) throws CoreException
+ {
+ initBuilders();
+ IOSGiInstall install = null;
+
+ for ( IOSGiInstallBuilder b : builders )
+ {
+ install = b.build( id, path );
+
+ if ( install != null )
+ {
+ break;
+ }
+ }
+
+ return install;
+ }
+
+
+ private void clearInstalls()
+ {
+ idToInstall.clear();
+ pathToinstall.clear();
+ }
+
+
+ private void initBuilders()
+ {
+ synchronized ( builders )
+ {
+ if ( builders.isEmpty() )
+ {
+ final HashMap<IOSGiInstallBuilder, Integer> tmp = new HashMap<IOSGiInstallBuilder, Integer>();
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint p = registry.getExtensionPoint( SigilCore.INSTALL_BUILDER_EXTENSION_POINT_ID );
+ for ( IExtension e : p.getExtensions() )
+ {
+ for ( IConfigurationElement c : e.getConfigurationElements() )
+ {
+ createBuilderFromElement( c, tmp );
+ }
+ }
+
+ builders = new LinkedList<IOSGiInstallBuilder>( tmp.keySet() );
+ Collections.sort( builders, new Comparator<IOSGiInstallBuilder>()
+ {
+ public int compare( IOSGiInstallBuilder o1, IOSGiInstallBuilder o2 )
+ {
+ int p1 = tmp.get( o1 );
+ int p2 = tmp.get( o2 );
+
+ if ( p1 == p2 )
+ {
+ return 0;
+ }
+ else if ( p1 > p2 )
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ } );
+ }
+ }
+ }
+
+
+ private void createBuilderFromElement( IConfigurationElement c, Map<IOSGiInstallBuilder, Integer> builder )
+ {
+ try
+ {
+ IOSGiInstallBuilder b = ( IOSGiInstallBuilder ) c.createExecutableExtension( "class" );
+ int priority = parsePriority( c );
+ builder.put( b, priority );
+ }
+ catch ( CoreException e )
+ {
+ SigilCore.error( "Failed to create builder", e );
+ }
+ }
+
+
+ private int parsePriority( IConfigurationElement c )
+ {
+ String str = c.getAttribute( "priority" );
+
+ if ( str == null )
+ {
+ return NORMAL_PRIORITY;
+ }
+ else
+ {
+ return Integer.parseInt( str );
+ }
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilModelRoot.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilModelRoot.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilModelRoot.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilModelRoot.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.eclipse.internal.model.project;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -44,83 +45,109 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-public class SigilModelRoot implements ISigilModelRoot {
- public List<ISigilProjectModel> getProjects() {
- IProject[] all = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- ArrayList<ISigilProjectModel> projects = new ArrayList<ISigilProjectModel>(all.length);
- for (IProject p : all) {
- try {
- if (p.isOpen() && p.hasNature(SigilCore.NATURE_ID)) {
- ISigilProjectModel n = SigilCore.create(p);
- projects.add(n);
- }
- } catch (CoreException e) {
- SigilCore.error("Failed to build model element", e);
- }
- }
-
- return projects;
- }
-
- public Collection<ISigilProjectModel> resolveDependentProjects(
- ISigilProjectModel sigil, IProgressMonitor monitor) {
- HashSet<ISigilProjectModel> dependents = new HashSet<ISigilProjectModel>();
-
- for (ISigilProjectModel n : getProjects()) {
- if (!sigil.equals(n)) {
- for (IPackageExport pe : sigil.getBundle().getBundleInfo().getExports()) {
- for (IPackageImport i : n.getBundle().getBundleInfo()
- .getImports()) {
- if (pe.getPackageName().equals(i.getPackageName())
- && i.getVersions().contains(pe.getVersion())) {
- dependents.add(n);
- }
- }
-
- for (ILibraryImport l : n.getBundle().getBundleInfo().getLibraryImports()) {
- ILibrary lib = SigilCore.getRepositoryManager(sigil).resolveLibrary(l);
-
- if (lib != null) {
- for (IPackageImport i : lib.getImports()) {
- if (pe.getPackageName().equals(
- i.getPackageName())
- && i.getVersions().contains(
- pe.getVersion())) {
- dependents.add(n);
- }
- }
- } else {
- SigilCore.error("No library found for " + l);
- }
- }
- }
-
- for (IRequiredBundle r : n.getBundle().getBundleInfo().getRequiredBundles()) {
- if (sigil.getSymbolicName().equals(r.getSymbolicName())
- && r.getVersions().contains(sigil.getVersion())) {
- dependents.add(n);
- }
- }
- }
- }
-
- return dependents;
- }
-
- public Collection<ISigilBundle> resolveBundles(ISigilProjectModel sigil, IModelElement element, boolean includeOptional, IProgressMonitor monitor) throws CoreException {
- int options = ResolutionConfig.INCLUDE_DEPENDENTS;
- if ( includeOptional ) {
- options |= ResolutionConfig.INCLUDE_OPTIONAL;
- }
-
- ResolutionConfig config = new ResolutionConfig(options);
- try {
- IBundleResolver resolver = SigilCore.getRepositoryManager(sigil).getBundleResolver();
- IResolution resolution = resolver.resolve(element, config, new ResolutionMonitorAdapter(monitor));
- resolution.synchronize(monitor);
- return resolution.getBundles();
- } catch (ResolutionException e) {
- throw SigilCore.newCoreException(e.getMessage(), e);
- }
- }
+
+public class SigilModelRoot implements ISigilModelRoot
+{
+ public List<ISigilProjectModel> getProjects()
+ {
+ IProject[] all = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ ArrayList<ISigilProjectModel> projects = new ArrayList<ISigilProjectModel>( all.length );
+ for ( IProject p : all )
+ {
+ try
+ {
+ if ( p.isOpen() && p.hasNature( SigilCore.NATURE_ID ) )
+ {
+ ISigilProjectModel n = SigilCore.create( p );
+ projects.add( n );
+ }
+ }
+ catch ( CoreException e )
+ {
+ SigilCore.error( "Failed to build model element", e );
+ }
+ }
+
+ return projects;
+ }
+
+
+ public Collection<ISigilProjectModel> resolveDependentProjects( ISigilProjectModel sigil, IProgressMonitor monitor )
+ {
+ HashSet<ISigilProjectModel> dependents = new HashSet<ISigilProjectModel>();
+
+ for ( ISigilProjectModel n : getProjects() )
+ {
+ if ( !sigil.equals( n ) )
+ {
+ for ( IPackageExport pe : sigil.getBundle().getBundleInfo().getExports() )
+ {
+ for ( IPackageImport i : n.getBundle().getBundleInfo().getImports() )
+ {
+ if ( pe.getPackageName().equals( i.getPackageName() )
+ && i.getVersions().contains( pe.getVersion() ) )
+ {
+ dependents.add( n );
+ }
+ }
+
+ for ( ILibraryImport l : n.getBundle().getBundleInfo().getLibraryImports() )
+ {
+ ILibrary lib = SigilCore.getRepositoryManager( sigil ).resolveLibrary( l );
+
+ if ( lib != null )
+ {
+ for ( IPackageImport i : lib.getImports() )
+ {
+ if ( pe.getPackageName().equals( i.getPackageName() )
+ && i.getVersions().contains( pe.getVersion() ) )
+ {
+ dependents.add( n );
+ }
+ }
+ }
+ else
+ {
+ SigilCore.error( "No library found for " + l );
+ }
+ }
+ }
+
+ for ( IRequiredBundle r : n.getBundle().getBundleInfo().getRequiredBundles() )
+ {
+ if ( sigil.getSymbolicName().equals( r.getSymbolicName() )
+ && r.getVersions().contains( sigil.getVersion() ) )
+ {
+ dependents.add( n );
+ }
+ }
+ }
+ }
+
+ return dependents;
+ }
+
+
+ public Collection<ISigilBundle> resolveBundles( ISigilProjectModel sigil, IModelElement element,
+ boolean includeOptional, IProgressMonitor monitor ) throws CoreException
+ {
+ int options = ResolutionConfig.INCLUDE_DEPENDENTS;
+ if ( includeOptional )
+ {
+ options |= ResolutionConfig.INCLUDE_OPTIONAL;
+ }
+
+ ResolutionConfig config = new ResolutionConfig( options );
+ try
+ {
+ IBundleResolver resolver = SigilCore.getRepositoryManager( sigil ).getBundleResolver();
+ IResolution resolution = resolver.resolve( element, config, new ResolutionMonitorAdapter( monitor ) );
+ resolution.synchronize( monitor );
+ return resolution.getBundles();
+ }
+ catch ( ResolutionException e )
+ {
+ throw SigilCore.newCoreException( e.getMessage(), e );
+ }
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.eclipse.internal.model.project;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -71,390 +72,519 @@
import org.osgi.framework.Version;
import org.osgi.service.prefs.Preferences;
+
/**
* @author dave
*
*/
-public class SigilProject extends AbstractCompoundModelElement implements ISigilProjectModel {
+public class SigilProject extends AbstractCompoundModelElement implements ISigilProjectModel
+{
- private static final long serialVersionUID = 1L;
-
- private IFile bldProjectFile;
+ private static final long serialVersionUID = 1L;
+
+ private IFile bldProjectFile;
private IProject project;
private IBldProject bldProject;
-
+
private ISigilBundle bundle;
- private IEclipsePreferences preferences;
+ private IEclipsePreferences preferences;
- public SigilProject() {
- super( "Sigil Project" );
+
+ public SigilProject()
+ {
+ super( "Sigil Project" );
}
-
- public SigilProject(IProject project) throws CoreException {
- this();
+
+
+ public SigilProject( IProject project ) throws CoreException
+ {
+ this();
this.project = project;
- bldProjectFile = project.getFile( new Path( SigilCore.SIGIL_PROJECT_FILE) );
+ bldProjectFile = project.getFile( new Path( SigilCore.SIGIL_PROJECT_FILE ) );
}
-
+
+
// to aid testing conversion between project file formats
- public InputStream saveBundle(ISigilBundle b) throws CoreException {
- setBundle(b);
- // FIXME causes NPE in JavaHelper
- // calculateUses();
- return buildContents();
- }
-
- public void save(IProgressMonitor monitor) throws CoreException {
- SubMonitor progress = SubMonitor.convert(monitor, 100);
-
- calculateUses();
-
- bldProjectFile.setContents( buildContents(), IFile.KEEP_HISTORY, progress.newChild(10));
-
- IRepositoryManager manager = SigilCore.getRepositoryManager(this);
- ResolutionConfig config = new ResolutionConfig(ResolutionConfig.INCLUDE_OPTIONAL);
-
- try {
- IResolution res = manager.getBundleResolver().resolve(this, config, new ResolutionMonitorAdapter(progress.newChild(10)));
- if ( !res.isSynchronized() ) {
- res.synchronize(progress.newChild(60));
- }
- } catch (ResolutionException e) {
- throw SigilCore.newCoreException("Failed to synchronize dependencies", e);
- }
-
-
- progress.setWorkRemaining(40);
-
- SigilCore.rebuildBundleDependencies( this, progress.newChild(20) );
- }
-
- /**
- * Returns the project custom preference pool.
- * Project preferences may include custom encoding.
- * @return IEclipsePreferences or <code>null</code> if the project
- * does not have a java nature.
- */
- public Preferences getPreferences(){
- synchronized(this) {
- if ( preferences == null ) {
- preferences = loadPreferences();
- }
-
- return preferences;
- }
- }
-
-
- /**
- * @return
- */
- private synchronized IEclipsePreferences loadPreferences() {
- IScopeContext context = new ProjectScope(getProject());
- final IEclipsePreferences eclipsePreferences = context.getNode(SigilCore.PLUGIN_ID);
-
- // Listen to node removal from parent in order to reset cache
- INodeChangeListener nodeListener = new IEclipsePreferences.INodeChangeListener() {
- public void added(IEclipsePreferences.NodeChangeEvent event) {
- // do nothing
- }
-
- public void removed(IEclipsePreferences.NodeChangeEvent event) {
- if (event.getChild() == eclipsePreferences) {
- synchronized( SigilProject.this ) {
- preferences = null;
- }
- ((IEclipsePreferences) eclipsePreferences.parent()).removeNodeChangeListener(this);
- }
- }
- };
-
- ((IEclipsePreferences) eclipsePreferences.parent()).addNodeChangeListener(nodeListener);
-
- return eclipsePreferences;
- }
-
- public Collection<IClasspathEntry> findExternalClasspath(IProgressMonitor monitor) throws CoreException {
- return JavaHelper.resolveClasspathEntrys(this, monitor);
- }
-
- private void calculateUses() {
- visit( new IModelWalker() {
- public boolean visit(IModelElement element) {
- if ( element instanceof IPackageExport ) {
- IPackageExport pe = (IPackageExport) element;
- try {
- pe.setUses( Arrays.asList( JavaHelper.findUses(pe.getPackageName(), SigilProject.this ) ) );
- } catch (CoreException e) {
- SigilCore.error( "Failed to build uses list for " + pe, e );
- }
- }
- return true;
- }
- } );
- }
-
- public Collection<ISigilProjectModel> findDependentProjects(IProgressMonitor monitor) {
- return SigilCore.getRoot().resolveDependentProjects(this, monitor);
- }
-
- public Version getVersion() {
- ISigilBundle bundle = getBundle();
- return bundle == null ? null : bundle.getBundleInfo() == null ? null : bundle.getBundleInfo().getVersion();
- }
-
- public String getSymbolicName() {
- ISigilBundle bundle = getBundle();
- return bundle == null ? null : bundle.getBundleInfo() == null ? null : bundle.getBundleInfo().getSymbolicName();
- }
+ public InputStream saveBundle( ISigilBundle b ) throws CoreException
+ {
+ setBundle( b );
+ // FIXME causes NPE in JavaHelper
+ // calculateUses();
+ return buildContents();
+ }
+
+
+ public void save( IProgressMonitor monitor ) throws CoreException
+ {
+ SubMonitor progress = SubMonitor.convert( monitor, 100 );
+
+ calculateUses();
+
+ bldProjectFile.setContents( buildContents(), IFile.KEEP_HISTORY, progress.newChild( 10 ) );
+
+ IRepositoryManager manager = SigilCore.getRepositoryManager( this );
+ ResolutionConfig config = new ResolutionConfig( ResolutionConfig.INCLUDE_OPTIONAL );
+
+ try
+ {
+ IResolution res = manager.getBundleResolver().resolve( this, config,
+ new ResolutionMonitorAdapter( progress.newChild( 10 ) ) );
+ if ( !res.isSynchronized() )
+ {
+ res.synchronize( progress.newChild( 60 ) );
+ }
+ }
+ catch ( ResolutionException e )
+ {
+ throw SigilCore.newCoreException( "Failed to synchronize dependencies", e );
+ }
+
+ progress.setWorkRemaining( 40 );
+
+ SigilCore.rebuildBundleDependencies( this, progress.newChild( 20 ) );
+ }
+
+
+ /**
+ * Returns the project custom preference pool.
+ * Project preferences may include custom encoding.
+ * @return IEclipsePreferences or <code>null</code> if the project
+ * does not have a java nature.
+ */
+ public Preferences getPreferences()
+ {
+ synchronized ( this )
+ {
+ if ( preferences == null )
+ {
+ preferences = loadPreferences();
+ }
+
+ return preferences;
+ }
+ }
+
+
+ /**
+ * @return
+ */
+ private synchronized IEclipsePreferences loadPreferences()
+ {
+ IScopeContext context = new ProjectScope( getProject() );
+ final IEclipsePreferences eclipsePreferences = context.getNode( SigilCore.PLUGIN_ID );
+
+ // Listen to node removal from parent in order to reset cache
+ INodeChangeListener nodeListener = new IEclipsePreferences.INodeChangeListener()
+ {
+ public void added( IEclipsePreferences.NodeChangeEvent event )
+ {
+ // do nothing
+ }
+
+
+ public void removed( IEclipsePreferences.NodeChangeEvent event )
+ {
+ if ( event.getChild() == eclipsePreferences )
+ {
+ synchronized ( SigilProject.this )
+ {
+ preferences = null;
+ }
+ ( ( IEclipsePreferences ) eclipsePreferences.parent() ).removeNodeChangeListener( this );
+ }
+ }
+ };
+
+ ( ( IEclipsePreferences ) eclipsePreferences.parent() ).addNodeChangeListener( nodeListener );
+
+ return eclipsePreferences;
+ }
+
+
+ public Collection<IClasspathEntry> findExternalClasspath( IProgressMonitor monitor ) throws CoreException
+ {
+ return JavaHelper.resolveClasspathEntrys( this, monitor );
+ }
+
+
+ private void calculateUses()
+ {
+ visit( new IModelWalker()
+ {
+ public boolean visit( IModelElement element )
+ {
+ if ( element instanceof IPackageExport )
+ {
+ IPackageExport pe = ( IPackageExport ) element;
+ try
+ {
+ pe.setUses( Arrays.asList( JavaHelper.findUses( pe.getPackageName(), SigilProject.this ) ) );
+ }
+ catch ( CoreException e )
+ {
+ SigilCore.error( "Failed to build uses list for " + pe, e );
+ }
+ }
+ return true;
+ }
+ } );
+ }
+
+
+ public Collection<ISigilProjectModel> findDependentProjects( IProgressMonitor monitor )
+ {
+ return SigilCore.getRoot().resolveDependentProjects( this, monitor );
+ }
+
+
+ public Version getVersion()
+ {
+ ISigilBundle bundle = getBundle();
+ return bundle == null ? null : bundle.getBundleInfo() == null ? null : bundle.getBundleInfo().getVersion();
+ }
+
+
+ public String getSymbolicName()
+ {
+ ISigilBundle bundle = getBundle();
+ return bundle == null ? null : bundle.getBundleInfo() == null ? null : bundle.getBundleInfo().getSymbolicName();
+ }
- public IProject getProject() {
+
+ public IProject getProject()
+ {
return project;
}
- public ISigilBundle getBundle() {
- if ( bundle == null && bldProjectFile != null ) {
- synchronized( bldProjectFile ) {
- try {
- if ( bldProjectFile.getLocation().toFile().exists() ) {
- bundle = parseContents(bldProjectFile);
- }
- else {
- bundle = setupDefaults();
- NullProgressMonitor npm = new NullProgressMonitor();
- bldProjectFile.create( buildContents(), true /* force */, npm);
- project.refreshLocal( IResource.DEPTH_INFINITE, npm );
- }
- } catch (CoreException e) {
- SigilCore.error( "Failed to build bundle", e);
- }
- }
- }
- return bundle;
- }
-
- public void setBundle(ISigilBundle bundle) {
- this.bundle = bundle;
- }
-
- public IJavaProject getJavaModel() {
- return JavaCore.create( project );
- }
-
- @Override
- public boolean equals(Object obj) {
- if ( obj == null ) return false;
-
- if ( obj == this ) return true;
-
- try {
- SigilProject p = (SigilProject) obj;
- return getSymbolicName().equals( p.getSymbolicName() ) && (getVersion() == null ? p.getVersion() == null : getVersion().equals( p.getVersion() ));
- }
- catch (ClassCastException e) {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- // TODO Auto-generated method stub
- return super.hashCode();
- }
-
- @Override
- public String toString() {
- return "SigilProject[" + getSymbolicName() + ":" + getVersion() + "]";
- }
-
- public void resetClasspath(IProgressMonitor monitor) throws CoreException {
- Path containerPath = new Path( SigilCore.CLASSPATH_CONTAINER_PATH );
- IJavaProject java = getJavaModel();
- ClasspathContainerInitializer init = JavaCore.getClasspathContainerInitializer(SigilCore.CLASSPATH_CONTAINER_PATH);
- ThreadProgressMonitor.setProgressMonitor(monitor);
- try {
- init.requestClasspathContainerUpdate(containerPath, java, null);
- }
- finally {
- ThreadProgressMonitor.setProgressMonitor(null);
- }
- }
-
- public IPath findBundleLocation() throws CoreException {
- IPath p = getBundle().getLocation();
- if ( p == null ) {
- p = SigilCore.getDefault().findDefaultBundleLocation(this);
- }
- return p;
- }
-
- public IModelElement findImport(final String packageName, final IProgressMonitor monitor) {
- final IModelElement[] found = new IModelElement[1];
-
- visit( new IModelWalker() {
- public boolean visit(IModelElement element) {
- if ( element instanceof IPackageImport ) {
- IPackageImport pi = (IPackageImport) element;
- if ( pi.getPackageName().equals( packageName ) ) {
- found[0] = pi;
- return false;
- }
- }
- else if ( element instanceof IRequiredBundle ) {
- IRequiredBundle rb = (IRequiredBundle) element;
- try {
- IRepositoryManager manager = SigilCore.getRepositoryManager(SigilProject.this);
- ResolutionConfig config = new ResolutionConfig(ResolutionConfig.IGNORE_ERRORS);
- IResolution res = manager.getBundleResolver().resolve(rb, config, new ResolutionMonitorAdapter(monitor));
- ISigilBundle b = res.getProvider(rb);
- for ( IPackageExport pe : b.getBundleInfo().getExports() ) {
- if ( pe.getPackageName().equals( packageName ) ) {
- found[0] = rb;
- return false;
- }
- }
- } catch (ResolutionException e) {
- SigilCore.error( "Failed to resolve " + rb, e );
- }
- }
- return true;
- }
-
- });
-
- return found[0];
- }
-
- public boolean isInClasspath(String packageName, IProgressMonitor monitor) throws CoreException {
- if ( findImport(packageName, monitor) != null ) {
- return true;
- }
-
- for ( String path : getBundle().getClasspathEntrys() ) {
- IClasspathEntry cp = getJavaModel().decodeClasspathEntry(path);
- for ( IPackageFragmentRoot root : getJavaModel().findPackageFragmentRoots(cp) ) {
- if ( findPackage( packageName, root ) ) {
- return true;
- }
- }
- }
- return false;
- }
-
- public boolean isInClasspath(ISigilBundle bundle) {
- for ( String path : getBundle().getClasspathEntrys() ) {
- IClasspathEntry cp = getJavaModel().decodeClasspathEntry(path);
- switch ( cp.getEntryKind() ) {
- case IClasspathEntry.CPE_PROJECT:
- ISigilProjectModel p = bundle.getAncestor(ISigilProjectModel.class);
- return p != null && cp.getPath().equals(p.getProject().getFullPath());
- case IClasspathEntry.CPE_LIBRARY:
- return cp.getPath().equals(bundle.getLocation());
- }
- }
-
- return false;
- }
-
- private boolean findPackage(String packageName, IParent parent) throws JavaModelException {
- for ( IJavaElement e : parent.getChildren() ) {
- if ( e.getElementType() == IJavaElement.PACKAGE_FRAGMENT ) {
- return e.getElementName().equals( packageName );
- }
-
- if ( e instanceof IParent ) {
- if ( findPackage(packageName, (IParent) e) ) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- private ISigilBundle setupDefaults() {
- ISigilBundle bundle = ModelElementFactory.getInstance().newModelElement(ISigilBundle.class);
- IBundleModelElement info = ModelElementFactory.getInstance().newModelElement( IBundleModelElement.class );
- info.setSymbolicName(project.getName());
- bundle.setBundleInfo(info);
- bundle.setParent(this);
- return bundle;
- }
-
-
- private ISigilBundle parseContents(IFile projectFile) throws CoreException {
- /*if ( !projectFile.isSynchronized(IResource.DEPTH_ONE) ) {
- projectFile.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
- }*/
-
- if ( projectFile.getName().equals( SigilCore.SIGIL_PROJECT_FILE) ) {
- return parseBldContents(projectFile.getLocationURI());
- }
- else {
- throw SigilCore.newCoreException("Unexpected project file: " + projectFile.getName(), null );
- }
- }
-
- private ISigilBundle parseBldContents(URI uri) throws CoreException {
- try {
- bldProject = BldFactory.getProject(uri, true);
- ISigilBundle bundle = bldProject.getDefaultBundle();
- bundle.setParent(this);
- return bundle;
- } catch (IOException e) {
- throw SigilCore.newCoreException( "Failed to parse " + uri, e);
- }
- }
-
- private InputStream buildContents() throws CoreException {
- ByteArrayOutputStream buf = new ByteArrayOutputStream();
- try {
- if (bldProject == null) {
- bldProject = BldFactory.newProject(bldProjectFile.getLocationURI(), null);
- }
- bldProject.setDefaultBundle(getBundle());
- bldProject.saveTo(buf);
- } catch (IOException e) {
- throw SigilCore.newCoreException("Failed to save project file", e);
- }
- return new ByteArrayInputStream(buf.toByteArray());
- }
-
-// private InputStream buildXMLContents() throws CoreException {
-// Serializer serializer = SigilCore.getDefault().getDescriptorSerializer();
-//
-// ByteArrayOutputStream buf = new ByteArrayOutputStream();
-//
-// try {
-// serializer.serialize(getBundle(), buf);
-// } catch (SerializingException e) {
-// throw SigilCore.newCoreException("Failed to serialize " + this, e);
-// }
-//
-// return new ByteArrayInputStream(buf.toByteArray());
-// }
-
- public String getName() {
- return getProject().getName();
- }
-
- public IPath findOutputLocation() throws CoreException {
- return getProject().getLocation().append(
- getJavaModel().getOutputLocation()
- .removeFirstSegments(1));
- }
-
- public IBldProject getBldProject() throws CoreException {
- try {
- return BldFactory.getProject(project.getFile(IBldProject.PROJECT_FILE).getLocationURI());
- } catch (IOException e) {
- throw SigilCore.newCoreException("Failed to get project file: ",e);
- }
- }
-
- public boolean isInBundleClasspath(IPackageFragmentRoot root) throws JavaModelException {
- String enc = getJavaModel().encodeClasspathEntry(root.getRawClasspathEntry());
- return getBundle().getClasspathEntrys().contains( enc.trim() );
- }
+
+ public ISigilBundle getBundle()
+ {
+ if ( bundle == null && bldProjectFile != null )
+ {
+ synchronized ( bldProjectFile )
+ {
+ try
+ {
+ if ( bldProjectFile.getLocation().toFile().exists() )
+ {
+ bundle = parseContents( bldProjectFile );
+ }
+ else
+ {
+ bundle = setupDefaults();
+ NullProgressMonitor npm = new NullProgressMonitor();
+ bldProjectFile.create( buildContents(), true /* force */, npm );
+ project.refreshLocal( IResource.DEPTH_INFINITE, npm );
+ }
+ }
+ catch ( CoreException e )
+ {
+ SigilCore.error( "Failed to build bundle", e );
+ }
+ }
+ }
+ return bundle;
+ }
+
+
+ public void setBundle( ISigilBundle bundle )
+ {
+ this.bundle = bundle;
+ }
+
+
+ public IJavaProject getJavaModel()
+ {
+ return JavaCore.create( project );
+ }
+
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( obj == null )
+ return false;
+
+ if ( obj == this )
+ return true;
+
+ try
+ {
+ SigilProject p = ( SigilProject ) obj;
+ return getSymbolicName().equals( p.getSymbolicName() )
+ && ( getVersion() == null ? p.getVersion() == null : getVersion().equals( p.getVersion() ) );
+ }
+ catch ( ClassCastException e )
+ {
+ return false;
+ }
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ // TODO Auto-generated method stub
+ return super.hashCode();
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return "SigilProject[" + getSymbolicName() + ":" + getVersion() + "]";
+ }
+
+
+ public void resetClasspath( IProgressMonitor monitor ) throws CoreException
+ {
+ Path containerPath = new Path( SigilCore.CLASSPATH_CONTAINER_PATH );
+ IJavaProject java = getJavaModel();
+ ClasspathContainerInitializer init = JavaCore
+ .getClasspathContainerInitializer( SigilCore.CLASSPATH_CONTAINER_PATH );
+ ThreadProgressMonitor.setProgressMonitor( monitor );
+ try
+ {
+ init.requestClasspathContainerUpdate( containerPath, java, null );
+ }
+ finally
+ {
+ ThreadProgressMonitor.setProgressMonitor( null );
+ }
+ }
+
+
+ public IPath findBundleLocation() throws CoreException
+ {
+ IPath p = getBundle().getLocation();
+ if ( p == null )
+ {
+ p = SigilCore.getDefault().findDefaultBundleLocation( this );
+ }
+ return p;
+ }
+
+
+ public IModelElement findImport( final String packageName, final IProgressMonitor monitor )
+ {
+ final IModelElement[] found = new IModelElement[1];
+
+ visit( new IModelWalker()
+ {
+ public boolean visit( IModelElement element )
+ {
+ if ( element instanceof IPackageImport )
+ {
+ IPackageImport pi = ( IPackageImport ) element;
+ if ( pi.getPackageName().equals( packageName ) )
+ {
+ found[0] = pi;
+ return false;
+ }
+ }
+ else if ( element instanceof IRequiredBundle )
+ {
+ IRequiredBundle rb = ( IRequiredBundle ) element;
+ try
+ {
+ IRepositoryManager manager = SigilCore.getRepositoryManager( SigilProject.this );
+ ResolutionConfig config = new ResolutionConfig( ResolutionConfig.IGNORE_ERRORS );
+ IResolution res = manager.getBundleResolver().resolve( rb, config,
+ new ResolutionMonitorAdapter( monitor ) );
+ ISigilBundle b = res.getProvider( rb );
+ for ( IPackageExport pe : b.getBundleInfo().getExports() )
+ {
+ if ( pe.getPackageName().equals( packageName ) )
+ {
+ found[0] = rb;
+ return false;
+ }
+ }
+ }
+ catch ( ResolutionException e )
+ {
+ SigilCore.error( "Failed to resolve " + rb, e );
+ }
+ }
+ return true;
+ }
+
+ } );
+
+ return found[0];
+ }
+
+
+ public boolean isInClasspath( String packageName, IProgressMonitor monitor ) throws CoreException
+ {
+ if ( findImport( packageName, monitor ) != null )
+ {
+ return true;
+ }
+
+ for ( String path : getBundle().getClasspathEntrys() )
+ {
+ IClasspathEntry cp = getJavaModel().decodeClasspathEntry( path );
+ for ( IPackageFragmentRoot root : getJavaModel().findPackageFragmentRoots( cp ) )
+ {
+ if ( findPackage( packageName, root ) )
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+ public boolean isInClasspath( ISigilBundle bundle )
+ {
+ for ( String path : getBundle().getClasspathEntrys() )
+ {
+ IClasspathEntry cp = getJavaModel().decodeClasspathEntry( path );
+ switch ( cp.getEntryKind() )
+ {
+ case IClasspathEntry.CPE_PROJECT:
+ ISigilProjectModel p = bundle.getAncestor( ISigilProjectModel.class );
+ return p != null && cp.getPath().equals( p.getProject().getFullPath() );
+ case IClasspathEntry.CPE_LIBRARY:
+ return cp.getPath().equals( bundle.getLocation() );
+ }
+ }
+
+ return false;
+ }
+
+
+ private boolean findPackage( String packageName, IParent parent ) throws JavaModelException
+ {
+ for ( IJavaElement e : parent.getChildren() )
+ {
+ if ( e.getElementType() == IJavaElement.PACKAGE_FRAGMENT )
+ {
+ return e.getElementName().equals( packageName );
+ }
+
+ if ( e instanceof IParent )
+ {
+ if ( findPackage( packageName, ( IParent ) e ) )
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+ private ISigilBundle setupDefaults()
+ {
+ ISigilBundle bundle = ModelElementFactory.getInstance().newModelElement( ISigilBundle.class );
+ IBundleModelElement info = ModelElementFactory.getInstance().newModelElement( IBundleModelElement.class );
+ info.setSymbolicName( project.getName() );
+ bundle.setBundleInfo( info );
+ bundle.setParent( this );
+ return bundle;
+ }
+
+
+ private ISigilBundle parseContents( IFile projectFile ) throws CoreException
+ {
+ /*if ( !projectFile.isSynchronized(IResource.DEPTH_ONE) ) {
+ projectFile.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
+ }*/
+
+ if ( projectFile.getName().equals( SigilCore.SIGIL_PROJECT_FILE ) )
+ {
+ return parseBldContents( projectFile.getLocationURI() );
+ }
+ else
+ {
+ throw SigilCore.newCoreException( "Unexpected project file: " + projectFile.getName(), null );
+ }
+ }
+
+
+ private ISigilBundle parseBldContents( URI uri ) throws CoreException
+ {
+ try
+ {
+ bldProject = BldFactory.getProject( uri, true );
+ ISigilBundle bundle = bldProject.getDefaultBundle();
+ bundle.setParent( this );
+ return bundle;
+ }
+ catch ( IOException e )
+ {
+ throw SigilCore.newCoreException( "Failed to parse " + uri, e );
+ }
+ }
+
+
+ private InputStream buildContents() throws CoreException
+ {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ try
+ {
+ if ( bldProject == null )
+ {
+ bldProject = BldFactory.newProject( bldProjectFile.getLocationURI(), null );
+ }
+ bldProject.setDefaultBundle( getBundle() );
+ bldProject.saveTo( buf );
+ }
+ catch ( IOException e )
+ {
+ throw SigilCore.newCoreException( "Failed to save project file", e );
+ }
+ return new ByteArrayInputStream( buf.toByteArray() );
+ }
+
+
+ // private InputStream buildXMLContents() throws CoreException {
+ // Serializer serializer = SigilCore.getDefault().getDescriptorSerializer();
+ //
+ // ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ //
+ // try {
+ // serializer.serialize(getBundle(), buf);
+ // } catch (SerializingException e) {
+ // throw SigilCore.newCoreException("Failed to serialize " + this, e);
+ // }
+ //
+ // return new ByteArrayInputStream(buf.toByteArray());
+ // }
+
+ public String getName()
+ {
+ return getProject().getName();
+ }
+
+
+ public IPath findOutputLocation() throws CoreException
+ {
+ return getProject().getLocation().append( getJavaModel().getOutputLocation().removeFirstSegments( 1 ) );
+ }
+
+
+ public IBldProject getBldProject() throws CoreException
+ {
+ try
+ {
+ return BldFactory.getProject( project.getFile( IBldProject.PROJECT_FILE ).getLocationURI() );
+ }
+ catch ( IOException e )
+ {
+ throw SigilCore.newCoreException( "Failed to get project file: ", e );
+ }
+ }
+
+
+ public boolean isInBundleClasspath( IPackageFragmentRoot root ) throws JavaModelException
+ {
+ String enc = getJavaModel().encodeClasspathEntry( root.getRawClasspathEntry() );
+ return getBundle().getClasspathEntrys().contains( enc.trim() );
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryConfiguration.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryConfiguration.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryConfiguration.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryConfiguration.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.eclipse.internal.model.repository;
+
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -49,335 +50,430 @@
import org.eclipse.swt.graphics.Image;
import org.osgi.framework.Bundle;
-public class RepositoryConfiguration implements IRepositoryConfiguration {
-
- private static final String REPOSITORY = "repository.";
- private static final String REPOSITORY_SET = REPOSITORY + "set.";
- private static final String REPOSITORY_SETS = REPOSITORY + "sets";
- private static final String REPOSITORY_TIMESTAMP = REPOSITORY + "timestamp";
- private static final String INSTANCES = ".instances";
- private static final String NAME = ".name";
- private static final String LOC = ".loc";
- private static final String TIMESTAMP = ".timestamp";
-
- public static final String REPOSITORY_DEFAULT_SET = REPOSITORY + "default.set";
-
- public List<IRepositoryModel> loadRepositories() {
- IPreferenceStore prefs = SigilCore.getDefault().getPreferenceStore();
-
- ArrayList<IRepositoryModel> repositories = new ArrayList<IRepositoryModel>();
-
- for ( RepositoryType type : loadRepositoryTypes() ) {
- String typeID = type.getId();
-
- if ( type.isDynamic() ) {
- String instances = prefs.getString( REPOSITORY + typeID + INSTANCES );
- if ( instances.trim().length() > 0 ) {
- for( String instance : instances.split(",") ) {
- String key = REPOSITORY + typeID + "." + instance;
- repositories.add( loadRepository(instance, key, type, prefs) );
- }
- }
- }
- else {
- String key = REPOSITORY + typeID;
- repositories.add( loadRepository(typeID, key, type, prefs) );
- }
-
- }
-
- return repositories;
- }
-
- public IRepositoryModel findRepository(String id) {
- for (IRepositoryModel model : loadRepositories()) {
- if ( model.getId().equals( id ) ) {
- return model;
- }
- }
- return null;
- }
-
- public void saveRepositories(List<IRepositoryModel> repositories) throws CoreException {
- IPreferenceStore prefs = getPreferences();
-
- HashMap<IRepositoryType, List<IRepositoryModel>> mapped = new HashMap<IRepositoryType, List<IRepositoryModel>>(repositories.size());
-
- saveRepositoryPreferences(repositories, mapped);
- createNewEntries(mapped, prefs);
- deleteOldEntries(repositories,prefs);
- // time stamp is used as a signal to the manager
- // to update its view of the stored repositories
- timeStamp(prefs);
- }
-
- public List<RepositoryType> loadRepositoryTypes() {
- List<RepositoryType> repositories = new ArrayList<RepositoryType>();
-
- IExtensionRegistry registry = Platform.getExtensionRegistry();
-
- IExtensionPoint p = registry.getExtensionPoint(SigilCore.REPOSITORY_PROVIDER_EXTENSION_POINT_ID);
-
- for ( IExtension e : p.getExtensions() ) {
- for ( IConfigurationElement c : e.getConfigurationElements() ) {
- String id = c.getAttribute("id");
- String type = c.getAttribute("type");
- boolean dynamic = Boolean.valueOf( c.getAttribute("dynamic") );
- String icon = c.getAttribute("icon");
- Image image = (icon == null || icon.trim().length() == 0) ? null : loadImage(e, icon);
- repositories.add( new RepositoryType(id, type, dynamic, image ) );
- }
- }
-
- return repositories;
- }
-
- public IRepositoryModel newRepositoryElement(IRepositoryType type) {
- String id = UUID.randomUUID().toString();
- PreferenceStore prefs = new PreferenceStore();
- RepositoryModel element = new RepositoryModel(id, "", type, prefs);
- prefs.setFilename(makeFileName(element));
- prefs.setValue("id", id);
- return element;
- }
-
- public IRepositorySet getDefaultRepositorySet() {
- //int level = findLevel( key + LEVEL, type, prefs );
- ArrayList<IRepositoryModel> reps = new ArrayList<IRepositoryModel>();
- for ( String s : PrefsUtils.stringToArray(getPreferences().getString( REPOSITORY_DEFAULT_SET)) ) {
- reps.add( findRepository(s) );
- }
- return new RepositorySet( reps );
- }
-
- public IRepositorySet getRepositorySet(String name) {
- String key = REPOSITORY_SET + name;
- if ( getPreferences().contains(key) ) {
- ArrayList<IRepositoryModel> reps = new ArrayList<IRepositoryModel>();
- for ( String s : PrefsUtils.stringToArray(getPreferences().getString( key )) ) {
- reps.add( findRepository(s) );
- }
- return new RepositorySet( reps );
- }
- else {
- return null;
- }
- }
-
- public Map<String, IRepositorySet> loadRepositorySets() {
- IPreferenceStore store = getPreferences();
-
- HashMap<String, IRepositorySet> sets = new HashMap<String, IRepositorySet>();
-
- for ( String name : PrefsUtils.stringToArray(store.getString(REPOSITORY_SETS))) {
- String key = REPOSITORY_SET + name;
- ArrayList<IRepositoryModel> reps = new ArrayList<IRepositoryModel>();
- for ( String s : PrefsUtils.stringToArray(getPreferences().getString( key )) ) {
- reps.add( findRepository(s) );
- }
- sets.put( name, new RepositorySet( reps ) );
- }
-
- return sets;
- }
-
- public void saveRepositorySets(Map<String, IRepositorySet> sets) {
- IPreferenceStore store = getPreferences();
-
- ArrayList<String> names = new ArrayList<String>();
-
- for ( Map.Entry<String, IRepositorySet> set : sets.entrySet() ) {
- String name = set.getKey();
- String key = REPOSITORY_SET + name;
- ArrayList<String> ids = new ArrayList<String>();
- for ( IRepositoryModel m : set.getValue().getRepositories() ) {
- ids.add( m.getId() );
- }
- store.setValue(key, PrefsUtils.listToString(ids) );
- names.add( name );
- }
-
- for ( String name : PrefsUtils.stringToArray(store.getString(REPOSITORY_SETS))) {
- if ( !names.contains(name) ) {
- String key = REPOSITORY_SET + name;
- store.setToDefault(key);
- }
- }
-
- store.setValue(REPOSITORY_SETS, PrefsUtils.listToString(names) );
- timeStamp(store);
- }
-
- public void setDefaultRepositorySet(IRepositorySet defaultSet) {
- ArrayList<String> ids = new ArrayList<String>();
- for ( IRepositoryModel m : defaultSet.getRepositories() ) {
- ids.add( m.getId() );
- }
- IPreferenceStore prefs = getPreferences();
- prefs.setValue( REPOSITORY_DEFAULT_SET, PrefsUtils.listToString( ids ) );
- timeStamp(prefs);
- }
-
- private void timeStamp(IPreferenceStore prefs) {
- prefs.setValue( REPOSITORY_TIMESTAMP, System.currentTimeMillis() );
- }
-
- private IPreferenceStore getPreferences() {
- return SigilCore.getDefault().getPreferenceStore();
- }
-
- private void deleteOldEntries(List<IRepositoryModel> repositories, IPreferenceStore prefs) {
- for ( IRepositoryModel e : loadRepositories() ) {
- if ( !repositories.contains(e) ) {
- new File( makeFileName(e) ).delete();
- String key = makeKey(e);
- prefs.setToDefault( key + LOC );
- prefs.setToDefault( key + NAME );
- }
- }
-
- for ( IRepositoryType type : loadRepositoryTypes() ) {
- boolean found = false;
- for ( IRepositoryModel e : repositories ) {
- if ( e.getType().equals( type ) ) {
- found = true;
- break;
- }
- }
-
- if ( !found ) {
- prefs.setToDefault( REPOSITORY + type.getId() + INSTANCES );
- }
- }
- }
-
- private static void createNewEntries(HashMap<IRepositoryType, List<IRepositoryModel>> mapped, IPreferenceStore prefs) {
- for ( Map.Entry<IRepositoryType, List<IRepositoryModel>> entry : mapped.entrySet() ) {
- IRepositoryType type = entry.getKey();
- if ( type.isDynamic() ) {
- StringBuffer buf = new StringBuffer();
-
- for ( IRepositoryModel element : entry.getValue() ) {
- if ( buf.length() > 0 ) {
- buf.append( "," );
- }
- buf.append( element.getId() );
- saveRepository(element, prefs);
- }
-
- prefs.setValue( REPOSITORY + type.getId() + INSTANCES, buf.toString() );
- }
- else {
- IRepositoryModel element = entry.getValue().get(0);
- saveRepository(element, prefs);
- }
- }
- }
-
- private static void saveRepositoryPreferences(List<IRepositoryModel> repositories,
- HashMap<IRepositoryType, List<IRepositoryModel>> mapped) throws CoreException {
- for( IRepositoryModel rep : repositories ) {
- try {
- createDir( makeFileName(rep));
- rep.getPreferences().save();
- List<IRepositoryModel> list = mapped.get( rep.getType() );
- if ( list == null ) {
- list = new ArrayList<IRepositoryModel>(1);
- mapped.put( rep.getType(), list );
- }
- list.add( rep );
- } catch (IOException e) {
- throw SigilCore.newCoreException("Failed to save repository preferences", e);
- }
- }
- }
-
- private static void createDir(String fileName) {
- File file = new File( fileName );
- file.getParentFile().mkdirs();
- }
-
- private static void saveRepository(IRepositoryModel element, IPreferenceStore prefs) {
- String key = makeKey(element);
- prefs.setValue( key + LOC, makeFileName(element) );
- if ( element.getType().isDynamic() ) {
- prefs.setValue( key + NAME, element.getName() );
- }
- prefs.setValue( key + TIMESTAMP, now() );
- }
-
- private static long now() {
- return System.currentTimeMillis();
- }
-
- private static String makeKey(IRepositoryModel element) {
- IRepositoryType type = element.getType();
-
- String key = REPOSITORY + type.getId();
- if ( type.isDynamic() )
- key = key + "." + element.getId();
-
- return key;
- }
-
- private static String makeFileName(IRepositoryModel element) {
- IPath path = SigilCore.getDefault().getStateLocation();
- path = path.append( "repository" );
- path = path.append( element.getType().getId() );
- path = path.append( element.getId() );
- return path.toOSString();
- }
-
- private static RepositoryModel loadRepository(String id, String key, RepositoryType type, IPreferenceStore prefs) {
- String name = type.isDynamic() ? prefs.getString( key + NAME ) : type.getType();
-
- PreferenceStore repPrefs = new PreferenceStore();
- RepositoryModel element = new RepositoryModel( id, name, type, repPrefs );
-
- String loc = prefs.getString( key + LOC );
-
- if ( loc == null || loc.trim().length() == 0 ) {
- loc = makeFileName(element);
- }
-
- repPrefs.setFilename(loc);
-
- if ( new File( loc ).exists() ) {
- try {
- repPrefs.load();
- } catch (IOException e) {
- SigilCore.error("Failed to load properties for repository " + key, e );
- }
- }
-
- repPrefs.setValue( "id", id );
-
- return element;
- }
-
- @SuppressWarnings("unchecked")
- private static Image loadImage(IExtension ext, String icon) {
- int i = icon.lastIndexOf( "/" );
- String path = i == -1 ? "/" : icon.substring(0, i);
- String name = i == -1 ? icon : icon.substring(i+1);
-
- Bundle b = Platform.getBundle(ext.getContributor().getName());
-
- Enumeration<URL> en = b.findEntries(path, name, false);
- Image image = null;
-
- if ( en.hasMoreElements() ) {
- try {
- image = SigilCore.loadImage(en.nextElement());
- } catch (IOException e) {
- SigilCore.error( "Failed to load image", e );
- }
- }
- else {
- SigilCore.error("No such image " + icon + " in bundle " + b.getSymbolicName() );
- }
-
- return image;
- }
+
+public class RepositoryConfiguration implements IRepositoryConfiguration
+{
+
+ private static final String REPOSITORY = "repository.";
+ private static final String REPOSITORY_SET = REPOSITORY + "set.";
+ private static final String REPOSITORY_SETS = REPOSITORY + "sets";
+ private static final String REPOSITORY_TIMESTAMP = REPOSITORY + "timestamp";
+ private static final String INSTANCES = ".instances";
+ private static final String NAME = ".name";
+ private static final String LOC = ".loc";
+ private static final String TIMESTAMP = ".timestamp";
+
+ public static final String REPOSITORY_DEFAULT_SET = REPOSITORY + "default.set";
+
+
+ public List<IRepositoryModel> loadRepositories()
+ {
+ IPreferenceStore prefs = SigilCore.getDefault().getPreferenceStore();
+
+ ArrayList<IRepositoryModel> repositories = new ArrayList<IRepositoryModel>();
+
+ for ( RepositoryType type : loadRepositoryTypes() )
+ {
+ String typeID = type.getId();
+
+ if ( type.isDynamic() )
+ {
+ String instances = prefs.getString( REPOSITORY + typeID + INSTANCES );
+ if ( instances.trim().length() > 0 )
+ {
+ for ( String instance : instances.split( "," ) )
+ {
+ String key = REPOSITORY + typeID + "." + instance;
+ repositories.add( loadRepository( instance, key, type, prefs ) );
+ }
+ }
+ }
+ else
+ {
+ String key = REPOSITORY + typeID;
+ repositories.add( loadRepository( typeID, key, type, prefs ) );
+ }
+
+ }
+
+ return repositories;
+ }
+
+
+ public IRepositoryModel findRepository( String id )
+ {
+ for ( IRepositoryModel model : loadRepositories() )
+ {
+ if ( model.getId().equals( id ) )
+ {
+ return model;
+ }
+ }
+ return null;
+ }
+
+
+ public void saveRepositories( List<IRepositoryModel> repositories ) throws CoreException
+ {
+ IPreferenceStore prefs = getPreferences();
+
+ HashMap<IRepositoryType, List<IRepositoryModel>> mapped = new HashMap<IRepositoryType, List<IRepositoryModel>>(
+ repositories.size() );
+
+ saveRepositoryPreferences( repositories, mapped );
+ createNewEntries( mapped, prefs );
+ deleteOldEntries( repositories, prefs );
+ // time stamp is used as a signal to the manager
+ // to update its view of the stored repositories
+ timeStamp( prefs );
+ }
+
+
+ public List<RepositoryType> loadRepositoryTypes()
+ {
+ List<RepositoryType> repositories = new ArrayList<RepositoryType>();
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+
+ IExtensionPoint p = registry.getExtensionPoint( SigilCore.REPOSITORY_PROVIDER_EXTENSION_POINT_ID );
+
+ for ( IExtension e : p.getExtensions() )
+ {
+ for ( IConfigurationElement c : e.getConfigurationElements() )
+ {
+ String id = c.getAttribute( "id" );
+ String type = c.getAttribute( "type" );
+ boolean dynamic = Boolean.valueOf( c.getAttribute( "dynamic" ) );
+ String icon = c.getAttribute( "icon" );
+ Image image = ( icon == null || icon.trim().length() == 0 ) ? null : loadImage( e, icon );
+ repositories.add( new RepositoryType( id, type, dynamic, image ) );
+ }
+ }
+
+ return repositories;
+ }
+
+
+ public IRepositoryModel newRepositoryElement( IRepositoryType type )
+ {
+ String id = UUID.randomUUID().toString();
+ PreferenceStore prefs = new PreferenceStore();
+ RepositoryModel element = new RepositoryModel( id, "", type, prefs );
+ prefs.setFilename( makeFileName( element ) );
+ prefs.setValue( "id", id );
+ return element;
+ }
+
+
+ public IRepositorySet getDefaultRepositorySet()
+ {
+ //int level = findLevel( key + LEVEL, type, prefs );
+ ArrayList<IRepositoryModel> reps = new ArrayList<IRepositoryModel>();
+ for ( String s : PrefsUtils.stringToArray( getPreferences().getString( REPOSITORY_DEFAULT_SET ) ) )
+ {
+ reps.add( findRepository( s ) );
+ }
+ return new RepositorySet( reps );
+ }
+
+
+ public IRepositorySet getRepositorySet( String name )
+ {
+ String key = REPOSITORY_SET + name;
+ if ( getPreferences().contains( key ) )
+ {
+ ArrayList<IRepositoryModel> reps = new ArrayList<IRepositoryModel>();
+ for ( String s : PrefsUtils.stringToArray( getPreferences().getString( key ) ) )
+ {
+ reps.add( findRepository( s ) );
+ }
+ return new RepositorySet( reps );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ public Map<String, IRepositorySet> loadRepositorySets()
+ {
+ IPreferenceStore store = getPreferences();
+
+ HashMap<String, IRepositorySet> sets = new HashMap<String, IRepositorySet>();
+
+ for ( String name : PrefsUtils.stringToArray( store.getString( REPOSITORY_SETS ) ) )
+ {
+ String key = REPOSITORY_SET + name;
+ ArrayList<IRepositoryModel> reps = new ArrayList<IRepositoryModel>();
+ for ( String s : PrefsUtils.stringToArray( getPreferences().getString( key ) ) )
+ {
+ reps.add( findRepository( s ) );
+ }
+ sets.put( name, new RepositorySet( reps ) );
+ }
+
+ return sets;
+ }
+
+
+ public void saveRepositorySets( Map<String, IRepositorySet> sets )
+ {
+ IPreferenceStore store = getPreferences();
+
+ ArrayList<String> names = new ArrayList<String>();
+
+ for ( Map.Entry<String, IRepositorySet> set : sets.entrySet() )
+ {
+ String name = set.getKey();
+ String key = REPOSITORY_SET + name;
+ ArrayList<String> ids = new ArrayList<String>();
+ for ( IRepositoryModel m : set.getValue().getRepositories() )
+ {
+ ids.add( m.getId() );
+ }
+ store.setValue( key, PrefsUtils.listToString( ids ) );
+ names.add( name );
+ }
+
+ for ( String name : PrefsUtils.stringToArray( store.getString( REPOSITORY_SETS ) ) )
+ {
+ if ( !names.contains( name ) )
+ {
+ String key = REPOSITORY_SET + name;
+ store.setToDefault( key );
+ }
+ }
+
+ store.setValue( REPOSITORY_SETS, PrefsUtils.listToString( names ) );
+ timeStamp( store );
+ }
+
+
+ public void setDefaultRepositorySet( IRepositorySet defaultSet )
+ {
+ ArrayList<String> ids = new ArrayList<String>();
+ for ( IRepositoryModel m : defaultSet.getRepositories() )
+ {
+ ids.add( m.getId() );
+ }
+ IPreferenceStore prefs = getPreferences();
+ prefs.setValue( REPOSITORY_DEFAULT_SET, PrefsUtils.listToString( ids ) );
+ timeStamp( prefs );
+ }
+
+
+ private void timeStamp( IPreferenceStore prefs )
+ {
+ prefs.setValue( REPOSITORY_TIMESTAMP, System.currentTimeMillis() );
+ }
+
+
+ private IPreferenceStore getPreferences()
+ {
+ return SigilCore.getDefault().getPreferenceStore();
+ }
+
+
+ private void deleteOldEntries( List<IRepositoryModel> repositories, IPreferenceStore prefs )
+ {
+ for ( IRepositoryModel e : loadRepositories() )
+ {
+ if ( !repositories.contains( e ) )
+ {
+ new File( makeFileName( e ) ).delete();
+ String key = makeKey( e );
+ prefs.setToDefault( key + LOC );
+ prefs.setToDefault( key + NAME );
+ }
+ }
+
+ for ( IRepositoryType type : loadRepositoryTypes() )
+ {
+ boolean found = false;
+ for ( IRepositoryModel e : repositories )
+ {
+ if ( e.getType().equals( type ) )
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if ( !found )
+ {
+ prefs.setToDefault( REPOSITORY + type.getId() + INSTANCES );
+ }
+ }
+ }
+
+
+ private static void createNewEntries( HashMap<IRepositoryType, List<IRepositoryModel>> mapped,
+ IPreferenceStore prefs )
+ {
+ for ( Map.Entry<IRepositoryType, List<IRepositoryModel>> entry : mapped.entrySet() )
+ {
+ IRepositoryType type = entry.getKey();
+ if ( type.isDynamic() )
+ {
+ StringBuffer buf = new StringBuffer();
+
+ for ( IRepositoryModel element : entry.getValue() )
+ {
+ if ( buf.length() > 0 )
+ {
+ buf.append( "," );
+ }
+ buf.append( element.getId() );
+ saveRepository( element, prefs );
+ }
+
+ prefs.setValue( REPOSITORY + type.getId() + INSTANCES, buf.toString() );
+ }
+ else
+ {
+ IRepositoryModel element = entry.getValue().get( 0 );
+ saveRepository( element, prefs );
+ }
+ }
+ }
+
+
+ private static void saveRepositoryPreferences( List<IRepositoryModel> repositories,
+ HashMap<IRepositoryType, List<IRepositoryModel>> mapped ) throws CoreException
+ {
+ for ( IRepositoryModel rep : repositories )
+ {
+ try
+ {
+ createDir( makeFileName( rep ) );
+ rep.getPreferences().save();
+ List<IRepositoryModel> list = mapped.get( rep.getType() );
+ if ( list == null )
+ {
+ list = new ArrayList<IRepositoryModel>( 1 );
+ mapped.put( rep.getType(), list );
+ }
+ list.add( rep );
+ }
+ catch ( IOException e )
+ {
+ throw SigilCore.newCoreException( "Failed to save repository preferences", e );
+ }
+ }
+ }
+
+
+ private static void createDir( String fileName )
+ {
+ File file = new File( fileName );
+ file.getParentFile().mkdirs();
+ }
+
+
+ private static void saveRepository( IRepositoryModel element, IPreferenceStore prefs )
+ {
+ String key = makeKey( element );
+ prefs.setValue( key + LOC, makeFileName( element ) );
+ if ( element.getType().isDynamic() )
+ {
+ prefs.setValue( key + NAME, element.getName() );
+ }
+ prefs.setValue( key + TIMESTAMP, now() );
+ }
+
+
+ private static long now()
+ {
+ return System.currentTimeMillis();
+ }
+
+
+ private static String makeKey( IRepositoryModel element )
+ {
+ IRepositoryType type = element.getType();
+
+ String key = REPOSITORY + type.getId();
+ if ( type.isDynamic() )
+ key = key + "." + element.getId();
+
+ return key;
+ }
+
+
+ private static String makeFileName( IRepositoryModel element )
+ {
+ IPath path = SigilCore.getDefault().getStateLocation();
+ path = path.append( "repository" );
+ path = path.append( element.getType().getId() );
+ path = path.append( element.getId() );
+ return path.toOSString();
+ }
+
+
+ private static RepositoryModel loadRepository( String id, String key, RepositoryType type, IPreferenceStore prefs )
+ {
+ String name = type.isDynamic() ? prefs.getString( key + NAME ) : type.getType();
+
+ PreferenceStore repPrefs = new PreferenceStore();
+ RepositoryModel element = new RepositoryModel( id, name, type, repPrefs );
+
+ String loc = prefs.getString( key + LOC );
+
+ if ( loc == null || loc.trim().length() == 0 )
+ {
+ loc = makeFileName( element );
+ }
+
+ repPrefs.setFilename( loc );
+
+ if ( new File( loc ).exists() )
+ {
+ try
+ {
+ repPrefs.load();
+ }
+ catch ( IOException e )
+ {
+ SigilCore.error( "Failed to load properties for repository " + key, e );
+ }
+ }
+
+ repPrefs.setValue( "id", id );
+
+ return element;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private static Image loadImage( IExtension ext, String icon )
+ {
+ int i = icon.lastIndexOf( "/" );
+ String path = i == -1 ? "/" : icon.substring( 0, i );
+ String name = i == -1 ? icon : icon.substring( i + 1 );
+
+ Bundle b = Platform.getBundle( ext.getContributor().getName() );
+
+ Enumeration<URL> en = b.findEntries( path, name, false );
+ Image image = null;
+
+ if ( en.hasMoreElements() )
+ {
+ try
+ {
+ image = SigilCore.loadImage( en.nextElement() );
+ }
+ catch ( IOException e )
+ {
+ SigilCore.error( "Failed to load image", e );
+ }
+ }
+ else
+ {
+ SigilCore.error( "No such image " + icon + " in bundle " + b.getSymbolicName() );
+ }
+
+ return image;
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryModel.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryModel.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryModel.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryModel.java Tue Jul 21 18:51:33 2009
@@ -19,63 +19,86 @@
package org.apache.felix.sigil.eclipse.internal.model.repository;
+
import org.apache.felix.sigil.eclipse.model.repository.IRepositoryModel;
import org.apache.felix.sigil.eclipse.model.repository.IRepositoryType;
import org.eclipse.jface.preference.PreferenceStore;
-public class RepositoryModel implements IRepositoryModel {
- private String id;
-
- private String name;
-
- private IRepositoryType type;
-
- private PreferenceStore preferences;
-
- public RepositoryModel(String id, String name, IRepositoryType type, PreferenceStore preferences) {
- this.id = id;
- this.name = name;
- this.type = type;
- this.preferences = preferences;
- }
-
- public PreferenceStore getPreferences() {
- return preferences;
- }
-
- public IRepositoryType getType() {
- return type;
- }
-
- public String getId() {
- return id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public boolean equals(Object obj) {
- try {
- RepositoryModel e = (RepositoryModel) obj;
- return id.equals(e.id);
- }
- catch (ClassCastException e) {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
-
- public String toString() {
- return type.getId() + ":" + id + ":" + name;
- }
+
+public class RepositoryModel implements IRepositoryModel
+{
+ private String id;
+
+ private String name;
+
+ private IRepositoryType type;
+
+ private PreferenceStore preferences;
+
+
+ public RepositoryModel( String id, String name, IRepositoryType type, PreferenceStore preferences )
+ {
+ this.id = id;
+ this.name = name;
+ this.type = type;
+ this.preferences = preferences;
+ }
+
+
+ public PreferenceStore getPreferences()
+ {
+ return preferences;
+ }
+
+
+ public IRepositoryType getType()
+ {
+ return type;
+ }
+
+
+ public String getId()
+ {
+ return id;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ try
+ {
+ RepositoryModel e = ( RepositoryModel ) obj;
+ return id.equals( e.id );
+ }
+ catch ( ClassCastException e )
+ {
+ return false;
+ }
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ return id.hashCode();
+ }
+
+
+ public String toString()
+ {
+ return type.getId() + ":" + id + ":" + name;
+ }
}
\ No newline at end of file
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryType.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryType.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryType.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/repository/RepositoryType.java Tue Jul 21 18:51:33 2009
@@ -19,57 +19,77 @@
package org.apache.felix.sigil.eclipse.internal.model.repository;
+
import org.apache.felix.sigil.eclipse.model.repository.IRepositoryType;
import org.eclipse.swt.graphics.Image;
-public class RepositoryType implements IRepositoryType {
- private String type;
- private String id;
- private Image icon;
- private boolean dynamic;
-
- public RepositoryType(String id, String type, boolean dynamic,
- Image icon) {
- this.id = id;
- this.type = type;
- this.dynamic = dynamic;
- this.icon = icon;
- }
-
- public String getType() {
- return type;
- }
-
- public String getId() {
- return id;
- }
-
- public Image getIcon() {
- return icon;
- }
-
- public boolean isDynamic() {
- return dynamic;
- }
-
- @Override
- public boolean equals(Object obj) {
- try {
- RepositoryType t = (RepositoryType) obj;
- return t.id.equals( id );
- }
- catch (ClassCastException e) {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
-
- @Override
- public String toString() {
- return type;
- }
+
+public class RepositoryType implements IRepositoryType
+{
+ private String type;
+ private String id;
+ private Image icon;
+ private boolean dynamic;
+
+
+ public RepositoryType( String id, String type, boolean dynamic, Image icon )
+ {
+ this.id = id;
+ this.type = type;
+ this.dynamic = dynamic;
+ this.icon = icon;
+ }
+
+
+ public String getType()
+ {
+ return type;
+ }
+
+
+ public String getId()
+ {
+ return id;
+ }
+
+
+ public Image getIcon()
+ {
+ return icon;
+ }
+
+
+ public boolean isDynamic()
+ {
+ return dynamic;
+ }
+
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ try
+ {
+ RepositoryType t = ( RepositoryType ) obj;
+ return t.id.equals( id );
+ }
+ catch ( ClassCastException e )
+ {
+ return false;
+ }
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ return id.hashCode();
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return type;
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/repository/eclipse/GlobalRepositoryManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/repository/eclipse/GlobalRepositoryManager.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/repository/eclipse/GlobalRepositoryManager.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/repository/eclipse/GlobalRepositoryManager.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.eclipse.internal.repository.eclipse;
+
import java.util.List;
import org.apache.felix.sigil.eclipse.SigilCore;
@@ -26,17 +27,21 @@
import org.apache.felix.sigil.eclipse.model.repository.IRepositoryModel;
import org.apache.felix.sigil.repository.IRepositoryManager;
-public class GlobalRepositoryManager extends SigilRepositoryManager implements
- IRepositoryManager {
- public GlobalRepositoryManager() {
- super(null);
- }
-
- @Override
- protected IRepositoryModel[] findRepositories() {
- List<IRepositoryModel> repos = SigilCore.getRepositoryConfiguration().loadRepositories();
- return repos.toArray( new IRepositoryModel[repos.size()]);
- }
+public class GlobalRepositoryManager extends SigilRepositoryManager implements IRepositoryManager
+{
+
+ public GlobalRepositoryManager()
+ {
+ super( null );
+ }
+
+
+ @Override
+ protected IRepositoryModel[] findRepositories()
+ {
+ List<IRepositoryModel> repos = SigilCore.getRepositoryConfiguration().loadRepositories();
+ return repos.toArray( new IRepositoryModel[repos.size()] );
+ }
}