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 [10/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/SigilCore.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/SigilCore.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/SigilCore.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/SigilCore.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.eclipse;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -80,491 +81,618 @@
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
+
/**
* The activator class controls the plug-in life cycle
*/
-public class SigilCore extends AbstractUIPlugin {
+public class SigilCore extends AbstractUIPlugin
+{
- private static final String BASE = "org.apache.felix.sigil";
- // The plug-in ID
- public static final String PLUGIN_ID = BASE + ".eclipse.core";
+ private static final String BASE = "org.apache.felix.sigil";
+ // The plug-in ID
+ public static final String PLUGIN_ID = BASE + ".eclipse.core";
public static final String NATURE_ID = BASE + ".sigilnature";
public static final String PREFERENCES_ID = BASE + ".ui.preferences.SigilPreferencePage";
public static final String OSGI_INSTALLS_PREFERENCES_ID = BASE + ".ui.preferences.osgiInstalls";
public static final String EXCLUDED_RESOURCES_PREFERENCES_ID = BASE + ".ui.preferences.excludedResources";
- public static final String REPOSITORIES_PREFERENCES_ID = BASE + ".ui.preferences.repositoriesPreferencePage";
+ public static final String REPOSITORIES_PREFERENCES_ID = BASE + ".ui.preferences.repositoriesPreferencePage";
public static final String SIGIL_PROJECT_FILE = IBldProject.PROJECT_FILE;
- public static final String BUILDER_ID = PLUGIN_ID + ".sigilBuilder";
- public static final String CLASSPATH_CONTAINER_PATH = BASE + ".classpathContainer";
+ public static final String BUILDER_ID = PLUGIN_ID + ".sigilBuilder";
+ public static final String CLASSPATH_CONTAINER_PATH = BASE + ".classpathContainer";
public static final String OSGI_INSTALLS = BASE + ".osgi.installs";
- public static final String OSGI_DEFAULT_INSTALL_ID = BASE + ".osgi.default.install.id";
- public static final String OSGI_INSTALL_PREFIX = BASE + ".osgi.install.";
- public static final String OSGI_SOURCE_LOCATION = BASE + ".osgi.source.location";
- public static final String OSGI_INSTALL_CHECK_PREFERENCE = BASE + ".osgi.install.check";
- public static final String LIBRARY_KEYS_PREF = BASE + ".library.keys";
- public static final String PREFERENCES_REBUILD_PROJECTS = BASE + ".rebuild.projects";
- public static final String QUALIFY_VERSIONS = BASE + ".qualify.versions";
-
- public static final String DEFAULT_VERSION_LOWER_BOUND = BASE + ".versionLowerBound";
- public static final String DEFAULT_VERSION_UPPER_BOUND = BASE + ".versionUpperBound";
-
- public static final String DEFAULT_EXCLUDED_RESOURCES = BASE + ".excludedResources";
- public static final String PREFERENCES_NOASK_OSGI_INSTALL = BASE + ".noAskOSGIHome";
- public static final String PREFERENCES_ADD_IMPORT_FOR_EXPORT = BASE + ".addImportForExport";
- public static final String INCLUDE_OPTIONAL_DEPENDENCIES = BASE + ".includeOptionalDependencies";
-
- public static final String INSTALL_BUILDER_EXTENSION_POINT_ID = BASE + ".installbuilder";
- public static final String REPOSITORY_PROVIDER_EXTENSION_POINT_ID = BASE + ".repositoryprovider";
-
- public static final String MARKER_UNRESOLVED_DEPENDENCY = BASE + ".unresolvedDependencyMarker";
- public static final String MARKER_UNRESOLVED_IMPORT_PACKAGE = BASE + ".unresolvedDependencyMarker.importPackage";
- public static final String MARKER_UNRESOLVED_REQUIRE_BUNDLE = BASE + ".unresolvedDependencyMarker.requireBundle";
- public static final String REPOSITORY_SET = PLUGIN_ID + ".repository.set";
- public static final String PREFERENCES_INCLUDE_OPTIONAL = PLUGIN_ID + ".include.optional";
-
- private static final Object NULL = new Object();
-
- // The shared instance
- private static SigilCore plugin;
-
- private ServiceTracker descriptorTracker;
- private ServiceTracker registryTracker;
- private ServiceTracker serializerTracker;
-
- private static IRepositoryConfiguration repositoryConfig;
- private static OSGiInstallManager installs;
- private static ISigilModelRoot modelRoot;
- private static HashMap<Object, SigilRepositoryManager> repositoryManagers = new HashMap<Object, SigilRepositoryManager>();
- private static GlobalRepositoryManager globalRepositoryManager;
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static SigilCore getDefault() {
- return plugin;
- }
-
- public static CoreException newCoreException(String msg, Throwable t) {
- return new CoreException(makeStatus(msg, t, IStatus.ERROR));
- }
-
- public static void log(String msg) {
- DebugPlugin.log(makeStatus(msg, null, IStatus.INFO));
- }
-
- public static void error(String msg) {
- DebugPlugin.log(makeStatus(msg, null, IStatus.ERROR));
- }
-
- public static void error(String msg, Throwable t) {
- DebugPlugin.log(makeStatus(msg, t, IStatus.ERROR));
- }
-
- public static void warn(String msg) {
- DebugPlugin.log(makeStatus(msg, null, IStatus.WARNING));
- }
-
- public static void warn(String msg, Throwable t) {
- DebugPlugin.log(makeStatus(msg, t, IStatus.WARNING));
- }
-
- private static IStatus makeStatus(String msg, Throwable t, int status) {
- if (t instanceof CoreException) {
- CoreException c = (CoreException) t;
- return c.getStatus();
- } else {
- return new Status(status, SigilCore.PLUGIN_ID, status, msg, t);
- }
- }
-
- public static boolean isSigilProject(IProject resource) {
- if ( resource == null ) return false;
-
- if ( resource.isAccessible() && resource instanceof IProject ) {
- IProject project = (IProject) resource;
- try {
- return project.hasNature(NATURE_ID);
- } catch (CoreException e) {
- error( e.getMessage(), e );
- return false;
- }
- }
- else {
- return false;
- }
- }
-
- public static boolean hasProjectNature(IProject project)
- throws CoreException {
- return project.getNature(NATURE_ID) != null;
- }
-
- public static ResourceBundle getResourceBundle() {
- return ResourceBundle.getBundle("resources."
- + SigilCore.class.getName(), Locale.getDefault(),
- SigilCore.class.getClassLoader());
- }
-
- public static ISigilProjectModel create(IProject project)
- throws CoreException {
- if (project.hasNature(NATURE_ID)) {
- return new SigilProject(project);
- } else {
- throw newCoreException("Project " + project.getName()
- + " is not a sigil project", null);
- }
- }
-
- /**
- * The constructor
- */
- public SigilCore() {
- plugin = this;
- }
-
- public void earlyStartup() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
- * )
- */
- public void start(final BundleContext context) throws Exception {
- super.start(context);
-
- modelRoot = new SigilModelRoot();
-
- repositoryConfig = new RepositoryConfiguration();
-
- installs = new OSGiInstallManager();
-
- globalRepositoryManager = new GlobalRepositoryManager();
-
- registerModelElements(context);
- registerResourceListeners();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
- * )
- */
- public void stop(BundleContext context) throws Exception {
- if (descriptorTracker != null) {
- descriptorTracker.close();
- descriptorTracker = null;
- }
-
- if (registryTracker != null) {
- registryTracker.close();
- registryTracker = null;
- }
-
- if (serializerTracker != null) {
- serializerTracker.close();
- serializerTracker = null;
- }
-
- for ( SigilRepositoryManager m : repositoryManagers.values() ) {
- m.destroy();
- }
-
- repositoryManagers.clear();
-
- globalRepositoryManager.destroy();
- globalRepositoryManager = null;
-
- plugin = null;
-
- super.stop(context);
- }
-
-
- public static boolean isBundledPath(String bp) throws CoreException {
- boolean bundle = JavaHelper.isCachedBundle(bp);
-
- if (!bundle) {
- bundle = isProjectPath(bp);
-
- if (!bundle) {
- for (IBundleRepository r : getGlobalRepositoryManager().getRepositories()) {
- bundle = isBundlePath(bp, r);
- if (bundle)
- break;
- }
- }
- }
-
- return bundle;
- }
-
- private static boolean isBundlePath(final String bp, IBundleRepository r) {
- final AtomicBoolean flag = new AtomicBoolean();
-
- IRepositoryVisitor visitor = new IRepositoryVisitor() {
- public boolean visit(ISigilBundle b) {
- IPath path = b.getLocation();
- if (path != null && path.toOSString().equals(bp)) {
- flag.set(true);
- return false;
- } else {
- return true;
- }
- }
-
- };
-
- r.accept(visitor, ResolutionConfig.INDEXED_ONLY
- | ResolutionConfig.LOCAL_ONLY);
-
- return flag.get();
- }
-
- private static boolean isProjectPath(String bp) throws CoreException {
- for (ISigilProjectModel p : SigilCore.getRoot().getProjects()) {
- IPath path = p.findOutputLocation();
-
- if (path.toOSString().equals(bp)) {
- return true;
- }
- }
-
- return false;
- }
-
- private void registerResourceListeners() {
- final IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- IResourceDelta delta = event.getDelta();
- if ( delta != null ) {
- try {
- delta.accept(new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta) throws CoreException {
- IResource resource = delta.getResource();
- if(resource instanceof IProject) {
- IProject project = (IProject) resource;
- if ( SigilCore.isSigilProject(project) ) {
- switch (delta.getKind()) {
- case IResourceDelta.REMOVED:
- case IResourceDelta.ADDED:
- rebuildAllBundleDependencies(Job.getJobManager().createProgressGroup());
- break;
- }
- }
- // Recurse no more
- return false;
- }
- return true;
- }
- });
- } catch (CoreException e) {
- error("Failed to update after change", e);
- }
- }
- }
- };
-
- Job job = new Job("Initialising sigil resource listeners") {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.POST_CHANGE);
- return Status.OK_STATUS;
- }
- };
- job.setSystem(true);
- job.schedule();
- }
-
- private void registerModelElements(BundleContext context) {
- // trick to get eclipse to lazy load BldCore for model elements
- BldCore.getLicenseManager();
- String uri = "http://sigil.codecauldron.org/xml/sigil-namespace";
- ModelElementFactory.getInstance().register(ISigilProjectModel.class,
- SigilProject.class, "project", "sigil", uri);
- }
-
- public static IOSGiInstallManager getInstallManager() {
- return installs;
- }
-
- public static ISigilModelRoot getRoot() {
- return modelRoot;
- }
-
- public static IRepositoryManager getGlobalRepositoryManager() {
- return globalRepositoryManager;
- }
-
- public static IRepositoryManager getRepositoryManager(String set) {
- SigilRepositoryManager manager = null;
-
- if ( set == null ) {
- manager = repositoryManagers.get( NULL );
- if ( manager == null ) {
- manager = new SigilRepositoryManager(null);
- manager.initialise();
- repositoryManagers.put( NULL, manager );
- }
- }
- else {
- manager = repositoryManagers.get(set);
-
- if ( manager == null ) {
- manager = new SigilRepositoryManager(set);
- manager.initialise();
- repositoryManagers.put( set, manager );
- }
- }
-
- return manager;
- }
- public static IRepositoryManager getRepositoryManager(ISigilProjectModel model) {
- return getRepositoryManager(loadProjectRepositorySet(model));
- }
-
- private static String loadProjectRepositorySet(ISigilProjectModel model) {
- if ( model == null ) {
- return null;
- }
-
- return model.getPreferences().get(REPOSITORY_SET, null );
- }
-
-
- public static IRepositoryConfiguration getRepositoryConfiguration() {
- return repositoryConfig;
- }
-
- public static void rebuildAllBundleDependencies(IProgressMonitor monitor) {
- Collection<ISigilProjectModel> projects = getRoot().getProjects();
- if ( !projects.isEmpty() ) {
- SubMonitor progress = SubMonitor.convert(monitor, projects.size()*20);
- for ( ISigilProjectModel p : projects ) {
- rebuild(p, progress);
- }
- }
-
- monitor.done();
- }
-
- public static void rebuildBundleDependencies(ISigilProjectModel project, IProgressMonitor monitor) {
- HashSet<ISigilProjectModel> affected = new HashSet<ISigilProjectModel>(project.findDependentProjects(monitor));
- affected.add(project);
-
- SubMonitor progress = SubMonitor.convert(monitor, affected.size()*20);
- for (ISigilProjectModel dependent : affected) {
- rebuild(dependent, progress);
- }
- }
-
-
- private static void rebuild(ISigilProjectModel dependent, SubMonitor progress) {
- try {
- dependent.resetClasspath(progress.newChild(10));
- dependent.getProject().build(IncrementalProjectBuilder.FULL_BUILD, progress.newChild(10));
- } catch (CoreException e) {
- SigilCore.error("Failed to rebuild " + dependent, e);
- }
- }
-
- public IPath findDefaultBundleLocation(ISigilProjectModel m)
- throws CoreException {
- IPath loc = m.getProject().getLocation();
- loc = loc.append(m.getJavaModel().getOutputLocation().removeFirstSegments(1));
- loc = loc.removeLastSegments(1).append( "lib" );
- return loc.append(m.getSymbolicName() + ".jar");
- }
-
- public static void makeSigilProject(IProject project,
- IProgressMonitor monitor) throws CoreException {
- IProjectDescription description = project.getDescription();
-
- String[] natures = description.getNatureIds();
- String[] newNatures = new String[natures.length + 1];
- System.arraycopy(natures, 0, newNatures, 0, natures.length);
- newNatures[natures.length] = SigilCore.NATURE_ID;
- description.setNatureIds(newNatures);
-
- ICommand sigilBuild = description.newCommand();
- sigilBuild.setBuilderName(SigilCore.BUILDER_ID);
-
- ICommand javaBuild = description.newCommand();
- javaBuild.setBuilderName(JavaCore.BUILDER_ID);
-
- description.setBuildSpec(new ICommand[] { javaBuild, sigilBuild });
-
- project.setDescription(description, new SubProgressMonitor(monitor, 2));
-
- IJavaProject java = JavaCore.create(project);
- if (java.exists()) {
- IClasspathEntry[] cp = java.getRawClasspath();
- // XXX fix for http://jira.codecauldron.org/browse/SIGIL-304
- if ( !isSigilOnClasspath(cp) ) {
- ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(
- Arrays.asList(cp));
- entries.add(JavaCore.newContainerEntry(new Path(
- SigilCore.CLASSPATH_CONTAINER_PATH)));
- java.setRawClasspath(entries.toArray(new IClasspathEntry[entries
- .size()]), monitor);
- }
- }
- }
-
- /**
- * @param cp
- * @return
- */
- private static boolean isSigilOnClasspath(IClasspathEntry[] cp) {
- for ( IClasspathEntry e : cp ) {
- if ( e.getEntryKind() == IClasspathEntry.CPE_CONTAINER && e.getPath().segment(0).equals(SigilCore.CLASSPATH_CONTAINER_PATH) ) {
- return true;
- }
- }
- return false;
- }
-
- public static Image loadImage(URL url) throws IOException {
- ImageRegistry registry = getDefault().getImageRegistry();
-
- String key = url.toExternalForm();
- Image img = registry.get( key );
-
- if ( img == null ) {
- img = openImage(url);
- registry.put( key, img );
- }
-
- return img;
- }
-
- private static Image openImage(URL url) throws IOException {
- Display display = Display.getCurrent();
- if ( display == null ) {
- display = Display.getDefault();
- }
-
- InputStream in = null;
- try {
- in = url.openStream();
- return new Image(display, in);
- }
- finally {
- if ( in != null ) {
- try {
- in.close();
- } catch (IOException e) {
- error( "Failed to close stream", e );
- }
- }
- }
- }
+ public static final String OSGI_DEFAULT_INSTALL_ID = BASE + ".osgi.default.install.id";
+ public static final String OSGI_INSTALL_PREFIX = BASE + ".osgi.install.";
+ public static final String OSGI_SOURCE_LOCATION = BASE + ".osgi.source.location";
+ public static final String OSGI_INSTALL_CHECK_PREFERENCE = BASE + ".osgi.install.check";
+ public static final String LIBRARY_KEYS_PREF = BASE + ".library.keys";
+ public static final String PREFERENCES_REBUILD_PROJECTS = BASE + ".rebuild.projects";
+ public static final String QUALIFY_VERSIONS = BASE + ".qualify.versions";
+
+ public static final String DEFAULT_VERSION_LOWER_BOUND = BASE + ".versionLowerBound";
+ public static final String DEFAULT_VERSION_UPPER_BOUND = BASE + ".versionUpperBound";
+
+ public static final String DEFAULT_EXCLUDED_RESOURCES = BASE + ".excludedResources";
+ public static final String PREFERENCES_NOASK_OSGI_INSTALL = BASE + ".noAskOSGIHome";
+ public static final String PREFERENCES_ADD_IMPORT_FOR_EXPORT = BASE + ".addImportForExport";
+ public static final String INCLUDE_OPTIONAL_DEPENDENCIES = BASE + ".includeOptionalDependencies";
+
+ public static final String INSTALL_BUILDER_EXTENSION_POINT_ID = BASE + ".installbuilder";
+ public static final String REPOSITORY_PROVIDER_EXTENSION_POINT_ID = BASE + ".repositoryprovider";
+
+ public static final String MARKER_UNRESOLVED_DEPENDENCY = BASE + ".unresolvedDependencyMarker";
+ public static final String MARKER_UNRESOLVED_IMPORT_PACKAGE = BASE + ".unresolvedDependencyMarker.importPackage";
+ public static final String MARKER_UNRESOLVED_REQUIRE_BUNDLE = BASE + ".unresolvedDependencyMarker.requireBundle";
+ public static final String REPOSITORY_SET = PLUGIN_ID + ".repository.set";
+ public static final String PREFERENCES_INCLUDE_OPTIONAL = PLUGIN_ID + ".include.optional";
+
+ private static final Object NULL = new Object();
+
+ // The shared instance
+ private static SigilCore plugin;
+
+ private ServiceTracker descriptorTracker;
+ private ServiceTracker registryTracker;
+ private ServiceTracker serializerTracker;
+
+ private static IRepositoryConfiguration repositoryConfig;
+ private static OSGiInstallManager installs;
+ private static ISigilModelRoot modelRoot;
+ private static HashMap<Object, SigilRepositoryManager> repositoryManagers = new HashMap<Object, SigilRepositoryManager>();
+ private static GlobalRepositoryManager globalRepositoryManager;
+
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static SigilCore getDefault()
+ {
+ return plugin;
+ }
+
+
+ public static CoreException newCoreException( String msg, Throwable t )
+ {
+ return new CoreException( makeStatus( msg, t, IStatus.ERROR ) );
+ }
+
+
+ public static void log( String msg )
+ {
+ DebugPlugin.log( makeStatus( msg, null, IStatus.INFO ) );
+ }
+
+
+ public static void error( String msg )
+ {
+ DebugPlugin.log( makeStatus( msg, null, IStatus.ERROR ) );
+ }
+
+
+ public static void error( String msg, Throwable t )
+ {
+ DebugPlugin.log( makeStatus( msg, t, IStatus.ERROR ) );
+ }
+
+
+ public static void warn( String msg )
+ {
+ DebugPlugin.log( makeStatus( msg, null, IStatus.WARNING ) );
+ }
+
+
+ public static void warn( String msg, Throwable t )
+ {
+ DebugPlugin.log( makeStatus( msg, t, IStatus.WARNING ) );
+ }
+
+
+ private static IStatus makeStatus( String msg, Throwable t, int status )
+ {
+ if ( t instanceof CoreException )
+ {
+ CoreException c = ( CoreException ) t;
+ return c.getStatus();
+ }
+ else
+ {
+ return new Status( status, SigilCore.PLUGIN_ID, status, msg, t );
+ }
+ }
+
+
+ public static boolean isSigilProject( IProject resource )
+ {
+ if ( resource == null )
+ return false;
+
+ if ( resource.isAccessible() && resource instanceof IProject )
+ {
+ IProject project = ( IProject ) resource;
+ try
+ {
+ return project.hasNature( NATURE_ID );
+ }
+ catch ( CoreException e )
+ {
+ error( e.getMessage(), e );
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ public static boolean hasProjectNature( IProject project ) throws CoreException
+ {
+ return project.getNature( NATURE_ID ) != null;
+ }
+
+
+ public static ResourceBundle getResourceBundle()
+ {
+ return ResourceBundle.getBundle( "resources." + SigilCore.class.getName(), Locale.getDefault(), SigilCore.class
+ .getClassLoader() );
+ }
+
+
+ public static ISigilProjectModel create( IProject project ) throws CoreException
+ {
+ if ( project.hasNature( NATURE_ID ) )
+ {
+ return new SigilProject( project );
+ }
+ else
+ {
+ throw newCoreException( "Project " + project.getName() + " is not a sigil project", null );
+ }
+ }
+
+
+ /**
+ * The constructor
+ */
+ public SigilCore()
+ {
+ plugin = this;
+ }
+
+
+ public void earlyStartup()
+ {
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start( final BundleContext context ) throws Exception
+ {
+ super.start( context );
+
+ modelRoot = new SigilModelRoot();
+
+ repositoryConfig = new RepositoryConfiguration();
+
+ installs = new OSGiInstallManager();
+
+ globalRepositoryManager = new GlobalRepositoryManager();
+
+ registerModelElements( context );
+ registerResourceListeners();
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ public void stop( BundleContext context ) throws Exception
+ {
+ if ( descriptorTracker != null )
+ {
+ descriptorTracker.close();
+ descriptorTracker = null;
+ }
+
+ if ( registryTracker != null )
+ {
+ registryTracker.close();
+ registryTracker = null;
+ }
+
+ if ( serializerTracker != null )
+ {
+ serializerTracker.close();
+ serializerTracker = null;
+ }
+
+ for ( SigilRepositoryManager m : repositoryManagers.values() )
+ {
+ m.destroy();
+ }
+
+ repositoryManagers.clear();
+
+ globalRepositoryManager.destroy();
+ globalRepositoryManager = null;
+
+ plugin = null;
+
+ super.stop( context );
+ }
+
+
+ public static boolean isBundledPath( String bp ) throws CoreException
+ {
+ boolean bundle = JavaHelper.isCachedBundle( bp );
+
+ if ( !bundle )
+ {
+ bundle = isProjectPath( bp );
+
+ if ( !bundle )
+ {
+ for ( IBundleRepository r : getGlobalRepositoryManager().getRepositories() )
+ {
+ bundle = isBundlePath( bp, r );
+ if ( bundle )
+ break;
+ }
+ }
+ }
+
+ return bundle;
+ }
+
+
+ private static boolean isBundlePath( final String bp, IBundleRepository r )
+ {
+ final AtomicBoolean flag = new AtomicBoolean();
+
+ IRepositoryVisitor visitor = new IRepositoryVisitor()
+ {
+ public boolean visit( ISigilBundle b )
+ {
+ IPath path = b.getLocation();
+ if ( path != null && path.toOSString().equals( bp ) )
+ {
+ flag.set( true );
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ };
+
+ r.accept( visitor, ResolutionConfig.INDEXED_ONLY | ResolutionConfig.LOCAL_ONLY );
+
+ return flag.get();
+ }
+
+
+ private static boolean isProjectPath( String bp ) throws CoreException
+ {
+ for ( ISigilProjectModel p : SigilCore.getRoot().getProjects() )
+ {
+ IPath path = p.findOutputLocation();
+
+ if ( path.toOSString().equals( bp ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ private void registerResourceListeners()
+ {
+ final IResourceChangeListener listener = new IResourceChangeListener()
+ {
+ public void resourceChanged( IResourceChangeEvent event )
+ {
+ IResourceDelta delta = event.getDelta();
+ if ( delta != null )
+ {
+ try
+ {
+ delta.accept( new IResourceDeltaVisitor()
+ {
+ public boolean visit( IResourceDelta delta ) throws CoreException
+ {
+ IResource resource = delta.getResource();
+ if ( resource instanceof IProject )
+ {
+ IProject project = ( IProject ) resource;
+ if ( SigilCore.isSigilProject( project ) )
+ {
+ switch ( delta.getKind() )
+ {
+ case IResourceDelta.REMOVED:
+ case IResourceDelta.ADDED:
+ rebuildAllBundleDependencies( Job.getJobManager().createProgressGroup() );
+ break;
+ }
+ }
+ // Recurse no more
+ return false;
+ }
+ return true;
+ }
+ } );
+ }
+ catch ( CoreException e )
+ {
+ error( "Failed to update after change", e );
+ }
+ }
+ }
+ };
+
+ Job job = new Job( "Initialising sigil resource listeners" )
+ {
+ @Override
+ protected IStatus run( IProgressMonitor monitor )
+ {
+ ResourcesPlugin.getWorkspace().addResourceChangeListener( listener,
+ IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.POST_CHANGE );
+ return Status.OK_STATUS;
+ }
+ };
+ job.setSystem( true );
+ job.schedule();
+ }
+
+
+ private void registerModelElements( BundleContext context )
+ {
+ // trick to get eclipse to lazy load BldCore for model elements
+ BldCore.getLicenseManager();
+ String uri = "http://sigil.codecauldron.org/xml/sigil-namespace";
+ ModelElementFactory.getInstance().register( ISigilProjectModel.class, SigilProject.class, "project", "sigil",
+ uri );
+ }
+
+
+ public static IOSGiInstallManager getInstallManager()
+ {
+ return installs;
+ }
+
+
+ public static ISigilModelRoot getRoot()
+ {
+ return modelRoot;
+ }
+
+
+ public static IRepositoryManager getGlobalRepositoryManager()
+ {
+ return globalRepositoryManager;
+ }
+
+
+ public static IRepositoryManager getRepositoryManager( String set )
+ {
+ SigilRepositoryManager manager = null;
+
+ if ( set == null )
+ {
+ manager = repositoryManagers.get( NULL );
+ if ( manager == null )
+ {
+ manager = new SigilRepositoryManager( null );
+ manager.initialise();
+ repositoryManagers.put( NULL, manager );
+ }
+ }
+ else
+ {
+ manager = repositoryManagers.get( set );
+
+ if ( manager == null )
+ {
+ manager = new SigilRepositoryManager( set );
+ manager.initialise();
+ repositoryManagers.put( set, manager );
+ }
+ }
+
+ return manager;
+ }
+
+
+ public static IRepositoryManager getRepositoryManager( ISigilProjectModel model )
+ {
+ return getRepositoryManager( loadProjectRepositorySet( model ) );
+ }
+
+
+ private static String loadProjectRepositorySet( ISigilProjectModel model )
+ {
+ if ( model == null )
+ {
+ return null;
+ }
+
+ return model.getPreferences().get( REPOSITORY_SET, null );
+ }
+
+
+ public static IRepositoryConfiguration getRepositoryConfiguration()
+ {
+ return repositoryConfig;
+ }
+
+
+ public static void rebuildAllBundleDependencies( IProgressMonitor monitor )
+ {
+ Collection<ISigilProjectModel> projects = getRoot().getProjects();
+ if ( !projects.isEmpty() )
+ {
+ SubMonitor progress = SubMonitor.convert( monitor, projects.size() * 20 );
+ for ( ISigilProjectModel p : projects )
+ {
+ rebuild( p, progress );
+ }
+ }
+
+ monitor.done();
+ }
+
+
+ public static void rebuildBundleDependencies( ISigilProjectModel project, IProgressMonitor monitor )
+ {
+ HashSet<ISigilProjectModel> affected = new HashSet<ISigilProjectModel>( project.findDependentProjects( monitor ) );
+ affected.add( project );
+
+ SubMonitor progress = SubMonitor.convert( monitor, affected.size() * 20 );
+ for ( ISigilProjectModel dependent : affected )
+ {
+ rebuild( dependent, progress );
+ }
+ }
+
+
+ private static void rebuild( ISigilProjectModel dependent, SubMonitor progress )
+ {
+ try
+ {
+ dependent.resetClasspath( progress.newChild( 10 ) );
+ dependent.getProject().build( IncrementalProjectBuilder.FULL_BUILD, progress.newChild( 10 ) );
+ }
+ catch ( CoreException e )
+ {
+ SigilCore.error( "Failed to rebuild " + dependent, e );
+ }
+ }
+
+
+ public IPath findDefaultBundleLocation( ISigilProjectModel m ) throws CoreException
+ {
+ IPath loc = m.getProject().getLocation();
+ loc = loc.append( m.getJavaModel().getOutputLocation().removeFirstSegments( 1 ) );
+ loc = loc.removeLastSegments( 1 ).append( "lib" );
+ return loc.append( m.getSymbolicName() + ".jar" );
+ }
+
+
+ public static void makeSigilProject( IProject project, IProgressMonitor monitor ) throws CoreException
+ {
+ IProjectDescription description = project.getDescription();
+
+ String[] natures = description.getNatureIds();
+ String[] newNatures = new String[natures.length + 1];
+ System.arraycopy( natures, 0, newNatures, 0, natures.length );
+ newNatures[natures.length] = SigilCore.NATURE_ID;
+ description.setNatureIds( newNatures );
+
+ ICommand sigilBuild = description.newCommand();
+ sigilBuild.setBuilderName( SigilCore.BUILDER_ID );
+
+ ICommand javaBuild = description.newCommand();
+ javaBuild.setBuilderName( JavaCore.BUILDER_ID );
+
+ description.setBuildSpec( new ICommand[]
+ { javaBuild, sigilBuild } );
+
+ project.setDescription( description, new SubProgressMonitor( monitor, 2 ) );
+
+ IJavaProject java = JavaCore.create( project );
+ if ( java.exists() )
+ {
+ IClasspathEntry[] cp = java.getRawClasspath();
+ // XXX fix for http://jira.codecauldron.org/browse/SIGIL-304
+ if ( !isSigilOnClasspath( cp ) )
+ {
+ ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>( Arrays.asList( cp ) );
+ entries.add( JavaCore.newContainerEntry( new Path( SigilCore.CLASSPATH_CONTAINER_PATH ) ) );
+ java.setRawClasspath( entries.toArray( new IClasspathEntry[entries.size()] ), monitor );
+ }
+ }
+ }
+
+
+ /**
+ * @param cp
+ * @return
+ */
+ private static boolean isSigilOnClasspath( IClasspathEntry[] cp )
+ {
+ for ( IClasspathEntry e : cp )
+ {
+ if ( e.getEntryKind() == IClasspathEntry.CPE_CONTAINER
+ && e.getPath().segment( 0 ).equals( SigilCore.CLASSPATH_CONTAINER_PATH ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public static Image loadImage( URL url ) throws IOException
+ {
+ ImageRegistry registry = getDefault().getImageRegistry();
+
+ String key = url.toExternalForm();
+ Image img = registry.get( key );
+
+ if ( img == null )
+ {
+ img = openImage( url );
+ registry.put( key, img );
+ }
+
+ return img;
+ }
+
+
+ private static Image openImage( URL url ) throws IOException
+ {
+ Display display = Display.getCurrent();
+ if ( display == null )
+ {
+ display = Display.getDefault();
+ }
+
+ InputStream in = null;
+ try
+ {
+ in = url.openStream();
+ return new Image( display, in );
+ }
+ finally
+ {
+ if ( in != null )
+ {
+ try
+ {
+ in.close();
+ }
+ catch ( IOException e )
+ {
+ error( "Failed to close stream", e );
+ }
+ }
+ }
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstall.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstall.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstall.java Tue Jul 21 18:51:33 2009
@@ -19,47 +19,55 @@
package org.apache.felix.sigil.eclipse.install;
+
import java.util.Map;
import org.eclipse.core.runtime.IPath;
+
/**
* Encapsulates all information about a particular OSGi install.
*
* @author dave
*
*/
-public interface IOSGiInstall {
-
- /**
- * A unique id which can be used to refer to this install within the eclipse runtime.
- * @return
- */
- String getId();
-
- /**
- * Where this install is located
- * @return
- */
- IPath getInstallLocation();
-
- /**
- * @return
- */
- Map<String, String> getProperties();
-
- /**
- * @return
- */
- String[] getLaunchArguments();
-
- /**
- * @return
- */
- IPath getVarDirectory();
-
- /**
- * @return
- */
- IOSGiInstallType getType();
+public interface IOSGiInstall
+{
+
+ /**
+ * A unique id which can be used to refer to this install within the eclipse runtime.
+ * @return
+ */
+ String getId();
+
+
+ /**
+ * Where this install is located
+ * @return
+ */
+ IPath getInstallLocation();
+
+
+ /**
+ * @return
+ */
+ Map<String, String> getProperties();
+
+
+ /**
+ * @return
+ */
+ String[] getLaunchArguments();
+
+
+ /**
+ * @return
+ */
+ IPath getVarDirectory();
+
+
+ /**
+ * @return
+ */
+ IOSGiInstallType getType();
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallBuilder.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallBuilder.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallBuilder.java Tue Jul 21 18:51:33 2009
@@ -19,9 +19,12 @@
package org.apache.felix.sigil.eclipse.install;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-public interface IOSGiInstallBuilder {
- IOSGiInstall build(String id, IPath path) throws CoreException;
+
+public interface IOSGiInstallBuilder
+{
+ IOSGiInstall build( String id, IPath path ) throws CoreException;
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallManager.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallManager.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallManager.java Tue Jul 21 18:51:33 2009
@@ -19,10 +19,20 @@
package org.apache.felix.sigil.eclipse.install;
-public interface IOSGiInstallManager {
- IOSGiInstall findInstall(String id);
- String[] getInstallIDs();
- IOSGiInstall[] getInstalls();
- IOSGiInstall getDefaultInstall();
- IOSGiInstallType findInstallType(String location);
+
+public interface IOSGiInstallManager
+{
+ IOSGiInstall findInstall( String id );
+
+
+ String[] getInstallIDs();
+
+
+ IOSGiInstall[] getInstalls();
+
+
+ IOSGiInstall getDefaultInstall();
+
+
+ IOSGiInstallType findInstallType( String location );
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallType.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallType.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallType.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/IOSGiInstallType.java Tue Jul 21 18:51:33 2009
@@ -19,50 +19,61 @@
package org.apache.felix.sigil.eclipse.install;
+
import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.graphics.Image;
+
//import org.eclipse.swt.graphics.Image;
-public interface IOSGiInstallType {
- /**
- * @return
- */
- String getName();
-
- /**
- *
- * @return
- */
- String getVersion();
-
- /**
- * @return
- */
- String getMainClass();
-
- /**
- * @return
- */
- String[] getClassPath();
-
- /**
- * @return
- */
- IPath getSourceLocation();
-
- /**
- * @return
- */
- IPath getJavaDocLocation();
-
- /**
- * Return the paths of any bundles that are started by default in this OSGi instance.
- * @return
- */
- IPath[] getDefaultBundleLocations();
+public interface IOSGiInstallType
+{
+ /**
+ * @return
+ */
+ String getName();
+
+
+ /**
+ *
+ * @return
+ */
+ String getVersion();
+
+
+ /**
+ * @return
+ */
+ String getMainClass();
+
+
+ /**
+ * @return
+ */
+ String[] getClassPath();
+
+
+ /**
+ * @return
+ */
+ IPath getSourceLocation();
+
+
+ /**
+ * @return
+ */
+ IPath getJavaDocLocation();
+
+
+ /**
+ * Return the paths of any bundles that are started by default in this OSGi instance.
+ * @return
+ */
+ IPath[] getDefaultBundleLocations();
+
+
+ String getId();
- String getId();
- Image getIcon();
+ Image getIcon();
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/OSGiInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/OSGiInstall.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/OSGiInstall.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/OSGiInstall.java Tue Jul 21 18:51:33 2009
@@ -19,75 +19,99 @@
package org.apache.felix.sigil.eclipse.install;
+
import java.util.Arrays;
import java.util.Map;
import org.eclipse.core.runtime.IPath;
-public class OSGiInstall implements IOSGiInstall {
- private String id;
- private IPath installLocation;
- private String[] launchArgs;
- private Map<String, String> properties;
- private IPath varDirectory;
- private IOSGiInstallType type;
-
- public IPath getVarDirectory() {
- return varDirectory;
- }
-
- public void setVarDirectory(IPath varDirectory) {
- this.varDirectory = varDirectory;
- }
-
- public OSGiInstall(String id) {
- this.id = id;
- }
-
- public String getId() {
- return id;
- }
-
- public IPath getInstallLocation() {
- return installLocation;
- }
-
- public void setInstallLocation(IPath installLocation) {
- this.installLocation = installLocation;
- }
-
- public String[] getLaunchArguments() {
- return launchArgs;
- }
-
- public void setLaunchArguments(String[] launchArgs) {
- this.launchArgs = launchArgs;
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String,String> properties) {
- this.properties = properties;
- }
-
- public String toString() {
- return "OSGiInstall[\n" +
- "id=" + id + "\n" +
- "type=" + type + "\n" +
- "installLocation=" + installLocation + "\n" +
- "launchArgs=" + Arrays.asList(launchArgs) + "\n" +
- "properties=" + properties + "\n" +
- "]";
- }
-
- public IOSGiInstallType getType() {
- return type;
- }
-
- public void setType(IOSGiInstallType type) {
- this.type = type;
- }
+public class OSGiInstall implements IOSGiInstall
+{
+
+ private String id;
+ private IPath installLocation;
+ private String[] launchArgs;
+ private Map<String, String> properties;
+ private IPath varDirectory;
+ private IOSGiInstallType type;
+
+
+ public IPath getVarDirectory()
+ {
+ return varDirectory;
+ }
+
+
+ public void setVarDirectory( IPath varDirectory )
+ {
+ this.varDirectory = varDirectory;
+ }
+
+
+ public OSGiInstall( String id )
+ {
+ this.id = id;
+ }
+
+
+ public String getId()
+ {
+ return id;
+ }
+
+
+ public IPath getInstallLocation()
+ {
+ return installLocation;
+ }
+
+
+ public void setInstallLocation( IPath installLocation )
+ {
+ this.installLocation = installLocation;
+ }
+
+
+ public String[] getLaunchArguments()
+ {
+ return launchArgs;
+ }
+
+
+ public void setLaunchArguments( String[] launchArgs )
+ {
+ this.launchArgs = launchArgs;
+ }
+
+
+ public Map<String, String> getProperties()
+ {
+ return properties;
+ }
+
+
+ public void setProperties( Map<String, String> properties )
+ {
+ this.properties = properties;
+ }
+
+
+ public String toString()
+ {
+ return "OSGiInstall[\n" + "id=" + id + "\n" + "type=" + type + "\n" + "installLocation=" + installLocation
+ + "\n" + "launchArgs=" + Arrays.asList( launchArgs ) + "\n" + "properties=" + properties + "\n" + "]";
+ }
+
+
+ public IOSGiInstallType getType()
+ {
+ return type;
+ }
+
+
+ public void setType( IOSGiInstallType type )
+ {
+ this.type = type;
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/OSGiInstallType.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/OSGiInstallType.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/OSGiInstallType.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/install/OSGiInstallType.java Tue Jul 21 18:51:33 2009
@@ -19,104 +19,140 @@
package org.apache.felix.sigil.eclipse.install;
+
import java.util.Arrays;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.graphics.Image;
-public class OSGiInstallType implements IOSGiInstallType {
- private String id;
- private String name;
- private String version;
- private String mainClass;
- private String[] classPath;
- private IPath javaDocLocation;
- private IPath sourceLocation;
- private IPath[] defaultBundleLocations;
- private Image icon;
-
- public Image getIcon() {
- return icon;
- }
-
- public void setIcon(Image icon) {
- this.icon = icon;
- }
-
- public String getId() {
- return id;
- }
-
- public String[] getClassPath() {
- return classPath;
- }
-
- public IPath[] getDefaultBundleLocations() {
- return defaultBundleLocations;
- }
-
- public IPath getJavaDocLocation() {
- return javaDocLocation;
- }
-
- public String getMainClass() {
- return mainClass;
- }
-
- public String getName() {
- return name;
- }
-
- public IPath getSourceLocation() {
- return sourceLocation;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public void setMainClass(String mainClass) {
- this.mainClass = mainClass;
- }
-
- public void setClassPath(String[] classPath) {
- this.classPath = classPath;
- }
-
- public void setJavaDocLocation(IPath javaDocLocation) {
- this.javaDocLocation = javaDocLocation;
- }
-
- public void setSourceLocation(IPath sourceLocation) {
- this.sourceLocation = sourceLocation;
- }
-
- public void setDefaultBundleLocations(IPath[] defaultBundleLocations) {
- this.defaultBundleLocations = defaultBundleLocations;
- }
-
- public String toString() {
- return "OSGiInstallType[\n" +
- "name=" + name + "\n" +
- "version=" + version + "\n" +
- "mainClass=" + mainClass + "\n" +
- "classPath=" + Arrays.asList(classPath) + "\n" +
- "javaDocLocation=" + javaDocLocation + "\n" +
- "sourceLocation=" + sourceLocation + "\n" +
- "defaultBundleLocations=" + Arrays.asList(defaultBundleLocations) + "\n" +
- "]";
- }
+public class OSGiInstallType implements IOSGiInstallType
+{
+
+ private String id;
+ private String name;
+ private String version;
+ private String mainClass;
+ private String[] classPath;
+ private IPath javaDocLocation;
+ private IPath sourceLocation;
+ private IPath[] defaultBundleLocations;
+ private Image icon;
+
+
+ public Image getIcon()
+ {
+ return icon;
+ }
+
+
+ public void setIcon( Image icon )
+ {
+ this.icon = icon;
+ }
+
+
+ public String getId()
+ {
+ return id;
+ }
+
+
+ public String[] getClassPath()
+ {
+ return classPath;
+ }
+
+
+ public IPath[] getDefaultBundleLocations()
+ {
+ return defaultBundleLocations;
+ }
+
+
+ public IPath getJavaDocLocation()
+ {
+ return javaDocLocation;
+ }
+
+
+ public String getMainClass()
+ {
+ return mainClass;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public IPath getSourceLocation()
+ {
+ return sourceLocation;
+ }
+
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+
+ public void setId( String id )
+ {
+ this.id = id;
+ }
+
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+
+ public void setMainClass( String mainClass )
+ {
+ this.mainClass = mainClass;
+ }
+
+
+ public void setClassPath( String[] classPath )
+ {
+ this.classPath = classPath;
+ }
+
+
+ public void setJavaDocLocation( IPath javaDocLocation )
+ {
+ this.javaDocLocation = javaDocLocation;
+ }
+
+
+ public void setSourceLocation( IPath sourceLocation )
+ {
+ this.sourceLocation = sourceLocation;
+ }
+
+
+ public void setDefaultBundleLocations( IPath[] defaultBundleLocations )
+ {
+ this.defaultBundleLocations = defaultBundleLocations;
+ }
+
+
+ public String toString()
+ {
+ return "OSGiInstallType[\n" + "name=" + name + "\n" + "version=" + version + "\n" + "mainClass=" + mainClass
+ + "\n" + "classPath=" + Arrays.asList( classPath ) + "\n" + "javaDocLocation=" + javaDocLocation + "\n"
+ + "sourceLocation=" + sourceLocation + "\n" + "defaultBundleLocations="
+ + Arrays.asList( defaultBundleLocations ) + "\n" + "]";
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/adapter/FileAdaptorFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/adapter/FileAdaptorFactory.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/adapter/FileAdaptorFactory.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/adapter/FileAdaptorFactory.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.eclipse.internal.adapter;
+
import org.apache.felix.sigil.eclipse.SigilCore;
import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
import org.apache.felix.sigil.model.ModelElementFactory;
@@ -29,58 +30,75 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterFactory;
+
/**
* @author savage
*
*/
-public class FileAdaptorFactory implements IAdapterFactory {
+public class FileAdaptorFactory implements IAdapterFactory
+{
+
+ public FileAdaptorFactory()
+ {
+
+ }
- public FileAdaptorFactory() {
-
- }
- private Class<?>[] types = new Class<?>[] { ISigilBundle.class };
-
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
- */
- @SuppressWarnings("unchecked")
- public Object getAdapter( Object adaptableObject, Class adapterType ) {
+ private Class<?>[] types = new Class<?>[]
+ { ISigilBundle.class };
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ public Object getAdapter( Object adaptableObject, Class adapterType )
+ {
Object adapted = null;
-
- IFile file = (IFile) adaptableObject;
-
- if ( ISigilBundle.class.equals( adapterType ) ) {
- adapted = adaptBundle(file);
+
+ IFile file = ( IFile ) adaptableObject;
+
+ if ( ISigilBundle.class.equals( adapterType ) )
+ {
+ adapted = adaptBundle( file );
}
-
- return adapted;
- }
-
- private Object adaptBundle(IFile file) {
+
+ return adapted;
+ }
+
+
+ private Object adaptBundle( IFile file )
+ {
Object adapted = null;
IProject project = file.getProject();
- try {
- if ( SigilCore.hasProjectNature( project ) ) {
+ try
+ {
+ if ( SigilCore.hasProjectNature( project ) )
+ {
ISigilProjectModel sigil = SigilCore.create( project );
ISigilBundle bundle = ModelElementFactory.getInstance().newModelElement( ISigilBundle.class );
bundle.setParent( sigil );
adapted = bundle;
}
}
- catch ( CoreException e ) {
- SigilCore.error( "Failed to construct bundle", e );
- } catch (ModelElementFactoryException e) {
- SigilCore.error( "Failed to construct bundle", e );
- }
-
+ catch ( CoreException e )
+ {
+ SigilCore.error( "Failed to construct bundle", e );
+ }
+ catch ( ModelElementFactoryException e )
+ {
+ SigilCore.error( "Failed to construct bundle", e );
+ }
+
return adapted;
- }
+ }
+
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
- */
- @SuppressWarnings("unchecked")
- public Class[] getAdapterList() {
- return types;
- }
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ @SuppressWarnings("unchecked")
+ public Class[] getAdapterList()
+ {
+ return types;
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/adapter/ProjectAdaptorFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/adapter/ProjectAdaptorFactory.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/adapter/ProjectAdaptorFactory.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/adapter/ProjectAdaptorFactory.java Tue Jul 21 18:51:33 2009
@@ -19,53 +19,68 @@
package org.apache.felix.sigil.eclipse.internal.adapter;
+
import org.apache.felix.sigil.eclipse.SigilCore;
import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterFactory;
+
/**
* @author savage
*
*/
-public class ProjectAdaptorFactory implements IAdapterFactory {
+public class ProjectAdaptorFactory implements IAdapterFactory
+{
+
+ private Class<?>[] types = new Class<?>[]
+ { ISigilProjectModel.class };
- private Class<?>[] types = new Class<?>[] { ISigilProjectModel.class };
-
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
- */
- @SuppressWarnings("unchecked")
- public Object getAdapter( Object adaptableObject, Class adapterType ) {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ public Object getAdapter( Object adaptableObject, Class adapterType )
+ {
Object adapted = null;
-
- IProject project = (IProject) adaptableObject;
-
- if ( ISigilProjectModel.class.equals( adapterType ) ) {
- adapted = adaptProject(project);
- }
-
- return adapted;
- }
-
- private Object adaptProject(IProject project) {
- try {
- if ( SigilCore.isSigilProject(project) ) {
- return SigilCore.create(project);
- }
- } catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
- */
- @SuppressWarnings("unchecked")
- public Class[] getAdapterList() {
- return types;
- }
+
+ IProject project = ( IProject ) adaptableObject;
+
+ if ( ISigilProjectModel.class.equals( adapterType ) )
+ {
+ adapted = adaptProject( project );
+ }
+
+ return adapted;
+ }
+
+
+ private Object adaptProject( IProject project )
+ {
+ try
+ {
+ if ( SigilCore.isSigilProject( project ) )
+ {
+ return SigilCore.create( project );
+ }
+ }
+ catch ( CoreException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ @SuppressWarnings("unchecked")
+ public Class[] getAdapterList()
+ {
+ return types;
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/builders/BuildConsole.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/builders/BuildConsole.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/builders/BuildConsole.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/builders/BuildConsole.java Tue Jul 21 18:51:33 2009
@@ -19,24 +19,32 @@
package org.apache.felix.sigil.eclipse.internal.builders;
+
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
-public class BuildConsole extends MessageConsole {
- private static final ImageDescriptor imageDescriptor = null;
- private MessageConsoleStream stream;
+public class BuildConsole extends MessageConsole
+{
+
+ private static final ImageDescriptor imageDescriptor = null;
+ private MessageConsoleStream stream;
+
- public BuildConsole() {
- super("Sigil Build", imageDescriptor, true);
- }
-
- public synchronized MessageConsoleStream getMessageStream() {
- if ( stream == null ) {
- stream = newMessageStream();
- }
- return stream;
- }
+ public BuildConsole()
+ {
+ super( "Sigil Build", imageDescriptor, true );
+ }
+
+
+ public synchronized MessageConsoleStream getMessageStream()
+ {
+ if ( stream == null )
+ {
+ stream = newMessageStream();
+ }
+ return stream;
+ }
}
Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/builders/SigilIncrementalProjectBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/builders/SigilIncrementalProjectBuilder.java?rev=796467&r1=796466&r2=796467&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/builders/SigilIncrementalProjectBuilder.java (original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/builders/SigilIncrementalProjectBuilder.java Tue Jul 21 18:51:33 2009
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.eclipse.internal.builders;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
@@ -51,261 +52,334 @@
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsoleStream;
-public class SigilIncrementalProjectBuilder extends IncrementalProjectBuilder {
- @Override
- protected IProject[] build(int kind, @SuppressWarnings("unchecked")Map args, IProgressMonitor monitor)
- throws CoreException {
- IProject project = getProject();
-
- if ( checkOk( project ) ) {
- switch ( kind ) {
- case CLEAN_BUILD:
- case FULL_BUILD:
- fullBuild( project, monitor );
- break;
- case AUTO_BUILD:
- case INCREMENTAL_BUILD:
- autoBuild( project, monitor );
- break;
- }
- }
-
- return null;
- }
+public class SigilIncrementalProjectBuilder extends IncrementalProjectBuilder
+{
+
+ @Override
+ protected IProject[] build( int kind, @SuppressWarnings("unchecked") Map args, IProgressMonitor monitor )
+ throws CoreException
+ {
+ IProject project = getProject();
+
+ if ( checkOk( project ) )
+ {
+ switch ( kind )
+ {
+ case CLEAN_BUILD:
+ case FULL_BUILD:
+ fullBuild( project, monitor );
+ break;
+ case AUTO_BUILD:
+ case INCREMENTAL_BUILD:
+ autoBuild( project, monitor );
+ break;
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * @param install
+ * @param project
+ * @param monitor
+ * @throws CoreException
+ */
+ private void autoBuild( IProject project, IProgressMonitor monitor ) throws CoreException
+ {
+ IResourceDelta delta = getDelta( project );
+ final boolean[] changed = new boolean[1];
+ ISigilProjectModel sigil = SigilCore.create( project );
+ final IPath bldRoot = sigil.findBundleLocation().removeLastSegments( 1 );
+
+ delta.accept( new IResourceDeltaVisitor()
+ {
+ public boolean visit( IResourceDelta delta ) throws CoreException
+ {
+ if ( !changed[0] )
+ {
+ IResource res = delta.getResource();
+ if ( res.getType() == IResource.FILE )
+ {
+ changed[0] = !bldRoot.isPrefixOf( res.getLocation() );
+ }
+ }
+ return !changed[0];
+ }
+ } );
+
+ if ( changed[0] )
+ {
+ doBuild( project, monitor );
+ }
+ }
+
/**
- * @param install
- * @param project
- * @param monitor
+ * @param install
+ * @param project
+ * @param monitor
* @throws CoreException
- */
- private void autoBuild(IProject project,
- IProgressMonitor monitor) throws CoreException {
- IResourceDelta delta = getDelta(project);
- final boolean[] changed = new boolean[1];
- ISigilProjectModel sigil = SigilCore.create(project);
- final IPath bldRoot = sigil.findBundleLocation().removeLastSegments(1);
-
- delta.accept(new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta) throws CoreException {
- if ( !changed[0] ) {
- IResource res = delta.getResource();
- if ( res.getType() == IResource.FILE ) {
- changed[0] = !bldRoot.isPrefixOf(res.getLocation());
- }
- }
- return !changed[0];
- }
- });
-
- if ( changed[0] ) {
- doBuild(project, monitor);
- }
- }
-
- /**
- * @param install
- * @param project
- * @param monitor
- * @throws CoreException
- */
- private void fullBuild(IProject project,
- IProgressMonitor monitor) throws CoreException {
- doBuild(project, monitor);
- }
-
- private boolean checkOk(IProject project) throws CoreException {
- IMarker[] markers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
-
- for ( IMarker m : markers ) {
- Integer s = (Integer) m.getAttribute(IMarker.SEVERITY);
- if ( s != null && s.equals( IMarker.SEVERITY_ERROR ) ) {
- SigilCore.log( "Skipping " + project.getName() + " build due to unresolved errors" );
- return false;
- }
- }
-
- return true;
- }
-
- private void doBuild(IProject project, IProgressMonitor monitor ) throws CoreException {
- ISigilProjectModel sigil = SigilCore.create(project);
- IBldProject bld = sigil.getBldProject();
-
- File[] classpath = buildClasspath(sigil, monitor);
-
- String destPattern = buildDestPattern(sigil);
-
- Properties env = new Properties();
-
- BundleBuilder bb = new BundleBuilder(bld, classpath, destPattern, env);
-
- for (IBldProject.IBldBundle bundle : bld.getBundles()) {
- String id = bundle.getId();
- loginfo("creating bundle: " + id);
- int nWarn = 0;
- int nErr = 0;
- String msg = "";
-
- try {
- boolean modified = bb.createBundle(bundle, false, new BundleBuilder.Log() {
- public void warn(String msg) {
- logwarn(msg);
- }
- public void verbose(String msg) {
- loginfo(msg);
- }
- });
- nWarn = bb.warnings().size();
- if (!modified) {
- msg = " (not modified)";
- }
- } catch (Exception e) {
- List<String> errors = bb.errors();
- if (errors != null) {
- nErr = errors.size();
- for (String err : errors) {
- logerror(err);
- }
- }
- throw SigilCore.newCoreException("Failed to create: " + id + ": " + e, e);
- } finally {
- loginfo(id + ": " + count(nErr, "error") + ", " + count(nWarn, "warning") + msg);
- }
- }
- }
-
- private static void loginfo(String message) {
- BuildConsole console = findConsole();
- MessageConsoleStream stream = console.getMessageStream();
- stream.println("INFO: " + message);
- }
-
- private static void logwarn(String message) {
- BuildConsole console = findConsole();
- MessageConsoleStream stream = console.getMessageStream();
- stream.println("WARN: " + message);
- }
-
- private static void logerror(String message) {
- BuildConsole console = findConsole();
- MessageConsoleStream stream = console.getMessageStream();
- stream.println("ERROR: " + message);
- }
-
- private static BuildConsole findConsole() {
- BuildConsole console = null;
-
+ */
+ private void fullBuild( IProject project, IProgressMonitor monitor ) throws CoreException
+ {
+ doBuild( project, monitor );
+ }
+
+
+ private boolean checkOk( IProject project ) throws CoreException
+ {
+ IMarker[] markers = project.findMarkers( IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
+ IResource.DEPTH_INFINITE );
+
+ for ( IMarker m : markers )
+ {
+ Integer s = ( Integer ) m.getAttribute( IMarker.SEVERITY );
+ if ( s != null && s.equals( IMarker.SEVERITY_ERROR ) )
+ {
+ SigilCore.log( "Skipping " + project.getName() + " build due to unresolved errors" );
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ private void doBuild( IProject project, IProgressMonitor monitor ) throws CoreException
+ {
+ ISigilProjectModel sigil = SigilCore.create( project );
+ IBldProject bld = sigil.getBldProject();
+
+ File[] classpath = buildClasspath( sigil, monitor );
+
+ String destPattern = buildDestPattern( sigil );
+
+ Properties env = new Properties();
+
+ BundleBuilder bb = new BundleBuilder( bld, classpath, destPattern, env );
+
+ for ( IBldProject.IBldBundle bundle : bld.getBundles() )
+ {
+ String id = bundle.getId();
+ loginfo( "creating bundle: " + id );
+ int nWarn = 0;
+ int nErr = 0;
+ String msg = "";
+
+ try
+ {
+ boolean modified = bb.createBundle( bundle, false, new BundleBuilder.Log()
+ {
+ public void warn( String msg )
+ {
+ logwarn( msg );
+ }
+
+
+ public void verbose( String msg )
+ {
+ loginfo( msg );
+ }
+ } );
+ nWarn = bb.warnings().size();
+ if ( !modified )
+ {
+ msg = " (not modified)";
+ }
+ }
+ catch ( Exception e )
+ {
+ List<String> errors = bb.errors();
+ if ( errors != null )
+ {
+ nErr = errors.size();
+ for ( String err : errors )
+ {
+ logerror( err );
+ }
+ }
+ throw SigilCore.newCoreException( "Failed to create: " + id + ": " + e, e );
+ }
+ finally
+ {
+ loginfo( id + ": " + count( nErr, "error" ) + ", " + count( nWarn, "warning" ) + msg );
+ }
+ }
+ }
+
+
+ private static void loginfo( String message )
+ {
+ BuildConsole console = findConsole();
+ MessageConsoleStream stream = console.getMessageStream();
+ stream.println( "INFO: " + message );
+ }
+
+
+ private static void logwarn( String message )
+ {
+ BuildConsole console = findConsole();
+ MessageConsoleStream stream = console.getMessageStream();
+ stream.println( "WARN: " + message );
+ }
+
+
+ private static void logerror( String message )
+ {
+ BuildConsole console = findConsole();
+ MessageConsoleStream stream = console.getMessageStream();
+ stream.println( "ERROR: " + message );
+ }
+
+
+ private static BuildConsole findConsole()
+ {
+ BuildConsole console = null;
+
IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
-
- for ( IConsole c : manager.getConsoles() ) {
- if ( c instanceof BuildConsole ) {
- console = (BuildConsole) c;
- break;
- }
- }
-
- if ( console == null ) {
- console = new BuildConsole();
- manager.addConsoles( new IConsole[] { console } );
+
+ for ( IConsole c : manager.getConsoles() )
+ {
+ if ( c instanceof BuildConsole )
+ {
+ console = ( BuildConsole ) c;
+ break;
+ }
+ }
+
+ if ( console == null )
+ {
+ console = new BuildConsole();
+ manager.addConsoles( new IConsole[]
+ { console } );
}
-
+
return console;
- }
+ }
+
+
+ private String buildDestPattern( ISigilProjectModel sigil ) throws CoreException
+ {
+ IPath loc = sigil.findBundleLocation().removeLastSegments( 1 );
+
+ loc.toFile().mkdirs();
+
+ return loc.toOSString() + File.separator + "[name].jar";
+ }
+
+
+ private File[] buildClasspath( ISigilProjectModel sigil, IProgressMonitor monitor ) throws CoreException
+ {
+ ArrayList<File> files = new ArrayList<File>();
+
+ buildLocalClasspath( sigil, files );
+ buildExternalClasspath( sigil, files, monitor );
+
+ return files.toArray( new File[files.size()] );
+ }
+
+
+ private void buildExternalClasspath( ISigilProjectModel sigil, ArrayList<File> files, IProgressMonitor monitor )
+ throws CoreException
+ {
+ Collection<IClasspathEntry> entries = sigil.findExternalClasspath( monitor );
+ files.ensureCapacity( files.size() + entries.size() );
+
+ for ( IClasspathEntry cp : entries )
+ {
+ convert( cp, sigil, files );
+ }
+ }
+
+
+ private void buildLocalClasspath( ISigilProjectModel sigil, ArrayList<File> files ) throws CoreException
+ {
+ Collection<IClasspathEntry> entries = JavaHelper.findClasspathEntries( sigil.getBundle() );
+ files.ensureCapacity( files.size() + entries.size() );
+ for ( IClasspathEntry cp : entries )
+ {
+ convert( cp, sigil, files );
+ }
+
+ if ( !sigil.getBundle().getComposites().isEmpty() )
+ {
+ throw new IllegalStateException( "XXX-FIXME-XXX" );
+ }
+ }
+
+
+ private void convert( IClasspathEntry cp, ISigilProjectModel sigil, ArrayList<File> files ) throws CoreException
+ {
+ switch ( cp.getEntryKind() )
+ {
+ case IClasspathEntry.CPE_PROJECT:
+ {
+ IProject p = findProject( cp.getPath() );
+ ISigilProjectModel project = SigilCore.create( p );
+ for ( String scp : project.getBundle().getClasspathEntrys() )
+ {
+ IClasspathEntry jcp = project.getJavaModel().decodeClasspathEntry( scp );
+ convert( jcp, project, files );
+ }
+ break;
+ }
+ case IClasspathEntry.CPE_SOURCE:
+ {
+ IPath path = cp.getOutputLocation() == null ? sigil.getJavaModel().getOutputLocation() : cp
+ .getOutputLocation();
+ IFolder buildFolder = sigil.getProject().getFolder( path.removeFirstSegments( 1 ) );
+ if ( buildFolder.exists() )
+ {
+ files.add( buildFolder.getLocation().toFile() );
+ }
+ break;
+ }
+ case IClasspathEntry.CPE_LIBRARY:
+ {
+ IPath p = cp.getPath();
+
+ IProject project = sigil.getProject().getWorkspace().getRoot().getProject( p.segment( 0 ) );
+ if ( project.exists() )
+ {
+ p = project.getLocation().append( p.removeFirstSegments( 1 ) );
+ }
+
+ files.add( p.toFile() );
+ break;
+ }
+ case IClasspathEntry.CPE_VARIABLE:
+ cp = JavaCore.getResolvedClasspathEntry( cp );
+ if ( cp != null )
+ {
+ IPath p = cp.getPath();
+ files.add( p.toFile() );
+ }
+ break;
+ }
+ }
+
+
+ private IProject findProject( IPath path ) throws CoreException
+ {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ for ( IProject p : root.getProjects() )
+ {
+ IPath projectPath = p.getFullPath();
+ if ( projectPath.equals( path ) )
+ {
+ return p;
+ }
+ }
+
+ throw SigilCore.newCoreException( "No such project " + path, null );
+ }
+
- private String buildDestPattern(ISigilProjectModel sigil) throws CoreException {
- IPath loc = sigil.findBundleLocation().removeLastSegments(1);
-
- loc.toFile().mkdirs();
-
- return loc.toOSString() + File.separator + "[name].jar";
- }
-
- private File[] buildClasspath(ISigilProjectModel sigil, IProgressMonitor monitor) throws CoreException {
- ArrayList<File> files = new ArrayList<File>();
-
- buildLocalClasspath(sigil, files);
- buildExternalClasspath(sigil, files, monitor);
-
- return files.toArray( new File[files.size()] );
- }
-
- private void buildExternalClasspath(ISigilProjectModel sigil,
- ArrayList<File> files, IProgressMonitor monitor) throws CoreException {
- Collection<IClasspathEntry> entries = sigil.findExternalClasspath(monitor);
- files.ensureCapacity(files.size() + entries.size());
-
- for ( IClasspathEntry cp : entries ) {
- convert(cp, sigil, files);
- }
- }
-
- private void buildLocalClasspath(ISigilProjectModel sigil, ArrayList<File> files) throws CoreException {
- Collection<IClasspathEntry> entries = JavaHelper.findClasspathEntries(sigil.getBundle());
- files.ensureCapacity(files.size() + entries.size());
- for ( IClasspathEntry cp : entries ) {
- convert(cp, sigil, files);
- }
-
- if ( !sigil.getBundle().getComposites().isEmpty() ) {
- throw new IllegalStateException("XXX-FIXME-XXX");
- }
- }
-
- private void convert(IClasspathEntry cp, ISigilProjectModel sigil, ArrayList<File> files) throws CoreException {
- switch( cp.getEntryKind() ) {
- case IClasspathEntry.CPE_PROJECT: {
- IProject p = findProject(cp.getPath());
- ISigilProjectModel project = SigilCore.create(p);
- for ( String scp : project.getBundle().getClasspathEntrys() ) {
- IClasspathEntry jcp = project.getJavaModel().decodeClasspathEntry(scp);
- convert( jcp, project, files );
- }
- break;
- }
- case IClasspathEntry.CPE_SOURCE : {
- IPath path = cp.getOutputLocation() == null ? sigil.getJavaModel().getOutputLocation() : cp.getOutputLocation();
- IFolder buildFolder = sigil.getProject().getFolder(path.removeFirstSegments(1));
- if ( buildFolder.exists() ) {
- files.add(buildFolder.getLocation().toFile());
- }
- break;
- }
- case IClasspathEntry.CPE_LIBRARY: {
- IPath p = cp.getPath();
-
- IProject project = sigil.getProject().getWorkspace().getRoot().getProject(p.segment(0));
- if ( project.exists() ) {
- p = project.getLocation().append( p.removeFirstSegments(1) );
- }
-
- files.add( p.toFile() );
- break;
- }
- case IClasspathEntry.CPE_VARIABLE:
- cp = JavaCore.getResolvedClasspathEntry(cp);
- if ( cp != null ) {
- IPath p = cp.getPath();
- files.add( p.toFile() );
- }
- break;
- }
- }
-
- private IProject findProject(IPath path) throws CoreException {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- for ( IProject p : root.getProjects() ) {
- IPath projectPath = p.getFullPath();
- if ( projectPath.equals( path ) ) {
- return p;
- }
- }
-
- throw SigilCore.newCoreException("No such project " + path, null);
- }
-
- private String count(int count, String msg) {
- return count + " " + msg + (count == 1 ? "" : "s");
- }
+ private String count( int count, String msg )
+ {
+ return count + " " + msg + ( count == 1 ? "" : "s" );
+ }
}