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 2010/08/02 19:08:20 UTC
svn commit: r981604 [9/22] - in /felix/trunk/sigil:
common/core.tests/src/org/apache/felix/sigil/common/core/
common/core.tests/src/org/apache/felix/sigil/common/core/internal/model/osgi/
common/core/src/org/apache/felix/sigil/common/bnd/ common/core/s...
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=981604&r1=981603&r2=981604&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 Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.eclipse.internal.builders;
-
import java.io.File;
import java.util.Collection;
import java.util.LinkedList;
@@ -56,26 +55,25 @@ import org.eclipse.ui.console.IConsole;
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
+ protected IProject[] build(int kind, @SuppressWarnings("unchecked") Map args,
+ IProgressMonitor monitor) throws CoreException
{
IProject project = getProject();
- if ( checkOk( project ) )
+ if (checkOk(project))
{
- switch ( kind )
+ switch (kind)
{
case CLEAN_BUILD:
case FULL_BUILD:
- fullBuild( project, monitor );
+ fullBuild(project, monitor);
break;
case AUTO_BUILD:
case INCREMENTAL_BUILD:
- autoBuild( project, monitor );
+ autoBuild(project, monitor);
break;
}
}
@@ -83,66 +81,66 @@ public class SigilIncrementalProjectBuil
return null;
}
-
/**
* @param install
* @param project
* @param monitor
* @throws CoreException
*/
- private void autoBuild( IProject project, IProgressMonitor monitor ) throws CoreException
+ private void autoBuild(IProject project, IProgressMonitor monitor)
+ throws CoreException
{
- IResourceDelta delta = getDelta( project );
+ IResourceDelta delta = getDelta(project);
final boolean[] changed = new boolean[1];
- ISigilProjectModel sigil = SigilCore.create( project );
- final IPath bldRoot = sigil.findBundleLocation().removeLastSegments( 1 );
+ ISigilProjectModel sigil = SigilCore.create(project);
+ final IPath bldRoot = sigil.findBundleLocation().removeLastSegments(1);
- delta.accept( new IResourceDeltaVisitor()
+ delta.accept(new IResourceDeltaVisitor()
{
- public boolean visit( IResourceDelta delta ) throws CoreException
+ public boolean visit(IResourceDelta delta) throws CoreException
{
- if ( !changed[0] )
+ if (!changed[0])
{
IResource res = delta.getResource();
- if ( res.getType() == IResource.FILE )
+ if (res.getType() == IResource.FILE)
{
- changed[0] = !bldRoot.isPrefixOf( res.getLocation() );
+ changed[0] = !bldRoot.isPrefixOf(res.getLocation());
}
}
return !changed[0];
}
- } );
+ });
- if ( changed[0] )
+ if (changed[0])
{
- doBuild( project, monitor );
+ doBuild(project, monitor);
}
}
-
/**
* @param install
* @param project
* @param monitor
* @throws CoreException
*/
- private void fullBuild( IProject project, IProgressMonitor monitor ) throws CoreException
+ private void fullBuild(IProject project, IProgressMonitor monitor)
+ throws CoreException
{
- doBuild( project, monitor );
+ doBuild(project, monitor);
}
-
- private boolean checkOk( IProject project ) throws CoreException
+ private boolean checkOk(IProject project) throws CoreException
{
- IMarker[] markers = project.findMarkers( IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
- IResource.DEPTH_INFINITE );
+ IMarker[] markers = project.findMarkers(
+ IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
- for ( IMarker m : markers )
+ for (IMarker m : markers)
{
- Integer s = ( Integer ) m.getAttribute( IMarker.SEVERITY );
- if ( s != null && s.equals( IMarker.SEVERITY_ERROR ) )
+ 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" );
+ SigilCore.log("Skipping " + project.getName()
+ + " build due to unresolved errors");
return false;
}
}
@@ -150,58 +148,56 @@ public class SigilIncrementalProjectBuil
return true;
}
-
- private void doBuild( IProject project, IProgressMonitor monitor ) throws CoreException
+ private void doBuild(IProject project, IProgressMonitor monitor) throws CoreException
{
- ISigilProjectModel sigil = SigilCore.create( project );
+ ISigilProjectModel sigil = SigilCore.create(project);
IBldProject bld = sigil.getBldProject();
- File[] classpath = buildClasspath( sigil, monitor );
+ File[] classpath = buildClasspath(sigil, monitor);
- String destPattern = buildDestPattern( sigil );
+ String destPattern = buildDestPattern(sigil);
Properties env = new Properties();
- BundleBuilder bb = new BundleBuilder( bld, classpath, destPattern, env );
+ BundleBuilder bb = new BundleBuilder(bld, classpath, destPattern, env);
- for ( IBldProject.IBldBundle bundle : bld.getBundles() )
+ for (IBldProject.IBldBundle bundle : bld.getBundles())
{
String id = bundle.getId();
- loginfo( "creating bundle: " + id );
+ loginfo("creating bundle: " + id);
int nWarn = 0;
int nErr = 0;
String msg = "";
try
{
- boolean modified = bb.createBundle( bundle, false, new BundleBuilder.Log()
+ boolean modified = bb.createBundle(bundle, false, new BundleBuilder.Log()
{
- public void warn( String msg )
+ public void warn(String msg)
{
- logwarn( msg );
+ logwarn(msg);
}
-
- public void verbose( String msg )
+ public void verbose(String msg)
{
- loginfo( msg );
+ loginfo(msg);
}
- } );
+ });
nWarn = bb.warnings().size();
- if ( !modified )
+ if (!modified)
{
msg = " (not modified)";
}
}
- catch ( Exception e )
+ catch (Exception e)
{
List<String> errors = bb.errors();
- if ( errors != null )
+ if (errors != null)
{
nErr = errors.size();
- for ( String err : errors )
+ for (String err : errors)
{
- logerror( err );
+ logerror(err);
}
}
// FELIX-1690 - error is already logged no need to throw error as this
@@ -210,124 +206,122 @@ public class SigilIncrementalProjectBuil
}
finally
{
- loginfo( id + ": " + count( nErr, "error" ) + ", " + count( nWarn, "warning" ) + msg );
+ loginfo(id + ": " + count(nErr, "error") + ", " + count(nWarn, "warning")
+ + msg);
}
}
}
-
- private static void loginfo( String message )
+ private static void loginfo(String message)
{
log("INFO: " + message);
}
- private static void logwarn( String message )
+ private static void logwarn(String message)
{
- log( "WARN: " + message );
+ log("WARN: " + message);
}
-
- private static void logerror( String message )
+ private static void logerror(String message)
{
- log( "ERROR: " + message );
+ log("ERROR: " + message);
}
private static void log(final String message)
{
// do this in background to avoid deadlock with ui
- Job job = new Job("log") {
+ Job job = new Job("log")
+ {
@Override
protected IStatus run(IProgressMonitor arg0)
{
BuildConsole console = findConsole();
MessageConsoleStream stream = console.getMessageStream();
- stream.println( message );
+ stream.println(message);
return Status.OK_STATUS;
}
};
job.schedule();
}
-
private static BuildConsole findConsole()
{
BuildConsole console = null;
IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
- for ( IConsole c : manager.getConsoles() )
+ for (IConsole c : manager.getConsoles())
{
- if ( c instanceof BuildConsole )
+ if (c instanceof BuildConsole)
{
- console = ( BuildConsole ) c;
+ console = (BuildConsole) c;
break;
}
}
- if ( console == null )
+ if (console == null)
{
console = new BuildConsole();
- manager.addConsoles( new IConsole[]
- { console } );
+ manager.addConsoles(new IConsole[] { console });
}
return console;
}
-
- private String buildDestPattern( ISigilProjectModel sigil ) throws CoreException
+ private String buildDestPattern(ISigilProjectModel sigil) throws CoreException
{
- IPath loc = sigil.findBundleLocation().removeLastSegments( 1 );
+ 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
+ private File[] buildClasspath(ISigilProjectModel sigil, IProgressMonitor monitor)
+ throws CoreException
{
LinkedList<File> files = new LinkedList<File>();
- if ( sigil.getBundle().getClasspathEntrys().isEmpty() ) {
+ if (sigil.getBundle().getClasspathEntrys().isEmpty())
+ {
IClasspathEntry[] entries = sigil.getJavaModel().getResolvedClasspath(true);
- for ( IClasspathEntry cp : entries )
+ for (IClasspathEntry cp : entries)
{
- convert( cp, sigil, files );
+ convert(cp, sigil, files);
}
}
- else {
- buildLocalClasspath( sigil, files );
- buildExternalClasspath( sigil, files, monitor );
+ else
+ {
+ buildLocalClasspath(sigil, files);
+ buildExternalClasspath(sigil, files, monitor);
}
- return files.toArray( new File[files.size()] );
+ return files.toArray(new File[files.size()]);
}
-
- private void buildExternalClasspath( ISigilProjectModel sigil, List<File> files, IProgressMonitor monitor )
- throws CoreException
+ private void buildExternalClasspath(ISigilProjectModel sigil, List<File> files,
+ IProgressMonitor monitor) throws CoreException
{
- Collection<IClasspathEntry> entries = sigil.findExternalClasspath( monitor );
+ Collection<IClasspathEntry> entries = sigil.findExternalClasspath(monitor);
- for ( IClasspathEntry cp : entries )
+ for (IClasspathEntry cp : entries)
{
- convert( cp, sigil, files );
+ convert(cp, sigil, files);
}
}
-
- private void buildLocalClasspath( ISigilProjectModel sigil, List<File> files ) throws CoreException
+ private void buildLocalClasspath(ISigilProjectModel sigil, List<File> files)
+ throws CoreException
{
- Collection<IClasspathEntry> entries = JavaHelper.findClasspathEntries( sigil.getBundle() );
- for ( IClasspathEntry cp : entries )
+ Collection<IClasspathEntry> entries = JavaHelper.findClasspathEntries(sigil.getBundle());
+ for (IClasspathEntry cp : entries)
{
- convert( cp, sigil, files );
+ convert(cp, sigil, files);
}
}
-
- private void convert( IClasspathEntry cp, ISigilProjectModel sigil, List<File> files ) throws CoreException
+ private void convert(IClasspathEntry cp, ISigilProjectModel sigil, List<File> files)
+ throws CoreException
{
- switch ( cp.getEntryKind() )
+ switch (cp.getEntryKind())
{
case IClasspathEntry.CPE_PROJECT:
{
@@ -350,84 +344,85 @@ public class SigilIncrementalProjectBuil
}
}
-
private void convertVariable(IClasspathEntry cp, List<File> files)
{
- cp = JavaCore.getResolvedClasspathEntry( cp );
- if ( cp != null )
+ cp = JavaCore.getResolvedClasspathEntry(cp);
+ if (cp != null)
{
IPath p = cp.getPath();
- files.add( p.toFile() );
+ files.add(p.toFile());
}
}
-
- private void convertLibrary(ISigilProjectModel sigil, IClasspathEntry cp, List<File> files)
+ private void convertLibrary(ISigilProjectModel sigil, IClasspathEntry cp,
+ List<File> files)
{
IPath p = cp.getPath();
- IProject project = sigil.getProject().getWorkspace().getRoot().getProject( p.segment( 0 ) );
- if ( project.exists() )
+ IProject project = sigil.getProject().getWorkspace().getRoot().getProject(
+ p.segment(0));
+ if (project.exists())
{
- p = project.getLocation().append( p.removeFirstSegments( 1 ) );
+ p = project.getLocation().append(p.removeFirstSegments(1));
}
- files.add( p.toFile() );
+ files.add(p.toFile());
}
-
- private void convertSource(ISigilProjectModel sigil, IClasspathEntry cp, List<File> files) throws JavaModelException
+ private void convertSource(ISigilProjectModel sigil, IClasspathEntry cp,
+ List<File> files) throws JavaModelException
{
- IPath path = cp.getOutputLocation() == null ? sigil.getJavaModel().getOutputLocation() : cp
- .getOutputLocation();
- IFolder buildFolder = sigil.getProject().getFolder( path.removeFirstSegments( 1 ) );
- if ( buildFolder.exists() )
+ 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() );
+ files.add(buildFolder.getLocation().toFile());
}
}
-
- private void convertProject(IClasspathEntry cp, List<File> files) throws CoreException
+ private void convertProject(IClasspathEntry cp, List<File> files)
+ throws CoreException
{
- IProject p = findProject( cp.getPath() );
- ISigilProjectModel project = SigilCore.create( p );
- if ( project.getBundle().getClasspathEntrys().isEmpty() ) {
+ IProject p = findProject(cp.getPath());
+ ISigilProjectModel project = SigilCore.create(p);
+ if (project.getBundle().getClasspathEntrys().isEmpty())
+ {
// ew this is pretty messy - if a dependent bundle specifies it's dependencies
// via package statements vs source directories then we need to add
// the classpath path of that bundle
- for ( IClasspathEntry rp : project.getJavaModel().getResolvedClasspath(true) ) {
- convert( rp, project, files );
+ for (IClasspathEntry rp : project.getJavaModel().getResolvedClasspath(true))
+ {
+ convert(rp, project, files);
}
}
- else {
- for ( String scp : project.getBundle().getClasspathEntrys() )
+ else
+ {
+ for (String scp : project.getBundle().getClasspathEntrys())
{
- IClasspathEntry jcp = project.getJavaModel().decodeClasspathEntry( scp );
- convert( jcp, project, files );
+ IClasspathEntry jcp = project.getJavaModel().decodeClasspathEntry(scp);
+ convert(jcp, project, files);
}
}
}
-
- private IProject findProject( IPath path ) throws CoreException
+ private IProject findProject(IPath path) throws CoreException
{
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- for ( IProject p : root.getProjects() )
+ for (IProject p : root.getProjects())
{
IPath projectPath = p.getFullPath();
- if ( projectPath.equals( path ) )
+ if (projectPath.equals(path))
{
return p;
}
}
- throw SigilCore.newCoreException( "No such project " + path, null );
+ throw SigilCore.newCoreException("No such project " + path, null);
}
-
- private String count( int count, String msg )
+ private String count(int count, String msg)
{
- return count + " " + msg + ( count == 1 ? "" : "s" );
+ return count + " " + msg + (count == 1 ? "" : "s");
}
}
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=981604&r1=981603&r2=981604&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 Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.eclipse.internal.install;
-
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -49,7 +48,6 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
-
public class OSGiInstallManager implements IOSGiInstallManager, IPropertyChangeListener
{
private static final int NORMAL_PRIORITY = 0;
@@ -63,195 +61,185 @@ public class OSGiInstallManager implemen
private boolean initialised;
-
- public IOSGiInstall findInstall( String id )
+ public IOSGiInstall findInstall(String id)
{
init();
- return idToInstall.get( id );
+ return idToInstall.get(id);
}
-
public String[] getInstallIDs()
{
init();
- return idToInstall.keySet().toArray( new String[idToInstall.size()] );
+ return idToInstall.keySet().toArray(new String[idToInstall.size()]);
}
-
public IOSGiInstall[] getInstalls()
{
init();
- return idToInstall.values().toArray( new IOSGiInstall[idToInstall.size()] );
+ return idToInstall.values().toArray(new IOSGiInstall[idToInstall.size()]);
}
-
public IOSGiInstall getDefaultInstall()
{
init();
- return findInstall( defaultId );
+ return findInstall(defaultId);
}
-
- public IOSGiInstallType findInstallType( String location )
+ public IOSGiInstallType findInstallType(String location)
{
IOSGiInstallType type = null;
try
{
- IOSGiInstall install = buildInstall( "tmp", new Path( location ) );
+ IOSGiInstall install = buildInstall("tmp", new Path(location));
type = install == null ? null : install.getType();
}
- catch ( CoreException e )
+ catch (CoreException e)
{
- SigilCore.error( "Failed to build install", e );
+ SigilCore.error("Failed to build install", e);
}
return type;
}
-
- public void propertyChange( PropertyChangeEvent event )
+ public void propertyChange(PropertyChangeEvent event)
{
- synchronized ( this )
+ synchronized (this)
{
- if ( event.getProperty().equals( SigilCore.OSGI_INSTALLS ) )
+ if (event.getProperty().equals(SigilCore.OSGI_INSTALLS))
{
clearInstalls();
- String val = ( String ) event.getNewValue();
- addInstalls( val );
+ String val = (String) event.getNewValue();
+ addInstalls(val);
}
- else if ( event.getProperty().equals( SigilCore.OSGI_DEFAULT_INSTALL_ID ) )
+ else if (event.getProperty().equals(SigilCore.OSGI_DEFAULT_INSTALL_ID))
{
- defaultId = ( String ) event.getNewValue();
+ defaultId = (String) event.getNewValue();
}
}
}
-
private void init()
{
boolean show = false;
IPreferenceStore prefs = getPreferenceStore();
- synchronized ( this )
+ synchronized (this)
{
- if ( !initialised )
+ if (!initialised)
{
initialised = true;
- prefs.addPropertyChangeListener( this );
+ prefs.addPropertyChangeListener(this);
- String val = prefs.getString( SigilCore.OSGI_INSTALLS );
+ String val = prefs.getString(SigilCore.OSGI_INSTALLS);
- boolean noAsk = prefs.getBoolean( SigilCore.PREFERENCES_NOASK_OSGI_INSTALL );
- if ( val == null || val.trim().length() == 0 )
+ 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 );
+ addInstalls(val);
+ defaultId = prefs.getString(SigilCore.OSGI_DEFAULT_INSTALL_ID);
}
}
}
- if ( show )
+ if (show)
{
- showInstallPrefs( prefs );
+ showInstallPrefs(prefs);
}
}
-
- private void addInstalls( String prop )
+ private void addInstalls(String prop)
{
- if ( prop != null && prop.trim().length() > 0 )
+ if (prop != null && prop.trim().length() > 0)
{
IPreferenceStore prefs = getPreferenceStore();
- for ( String id : prop.split( "," ) )
+ for (String id : prop.split(","))
{
- String path = prefs.getString( SigilCore.OSGI_INSTALL_PREFIX + id );
- addInstall( id, new Path( path ) );
+ 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 )
+ private void showInstallPrefs(final IPreferenceStore prefs)
{
Runnable r = new Runnable()
{
public void run()
{
- MessageDialogWithToggle questionDialog = MessageDialogWithToggle.openYesNoQuestion( PlatformUI
- .getWorkbench().getActiveWorkbenchWindow().getShell(), "Sigil Configuration",
+ 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 )
+ "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 );
+ PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(
+ null, SigilCore.OSGI_INSTALLS_PREFERENCES_ID, null, null);
dialog.open();
}
}
};
Display d = Display.getCurrent();
- if ( d == null )
+ if (d == null)
{
d = Display.getDefault();
- d.asyncExec( r );
+ d.asyncExec(r);
}
else
{
- d.syncExec( r );
+ d.syncExec(r);
}
}
-
- private IOSGiInstall addInstall( String id, IPath path )
+ private IOSGiInstall addInstall(String id, IPath path)
{
- IOSGiInstall install = pathToinstall.get( path );
+ IOSGiInstall install = pathToinstall.get(path);
- if ( install == null )
+ if (install == null)
{
try
{
- install = buildInstall( id, path );
- if ( install != null )
+ install = buildInstall(id, path);
+ if (install != null)
{
- pathToinstall.put( path, install );
- idToInstall.put( install.getId(), install );
+ pathToinstall.put(path, install);
+ idToInstall.put(install.getId(), install);
}
}
- catch ( CoreException e )
+ catch (CoreException e)
{
- SigilCore.error( "Failed to build install for " + path, e );
+ SigilCore.error("Failed to build install for " + path, e);
}
}
return install;
}
-
- private IOSGiInstall buildInstall( String id, IPath path ) throws CoreException
+ private IOSGiInstall buildInstall(String id, IPath path) throws CoreException
{
initBuilders();
IOSGiInstall install = null;
- for ( IOSGiInstallBuilder b : builders )
+ for (IOSGiInstallBuilder b : builders)
{
- install = b.build( id, path );
+ install = b.build(id, path);
- if ( install != null )
+ if (install != null)
{
break;
}
@@ -260,45 +248,43 @@ public class OSGiInstallManager implemen
return install;
}
-
private void clearInstalls()
{
idToInstall.clear();
pathToinstall.clear();
}
-
private void initBuilders()
{
- synchronized ( builders )
+ synchronized (builders)
{
- if ( builders.isEmpty() )
+ 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() )
+ IExtensionPoint p = registry.getExtensionPoint(SigilCore.INSTALL_BUILDER_EXTENSION_POINT_ID);
+ for (IExtension e : p.getExtensions())
{
- for ( IConfigurationElement c : e.getConfigurationElements() )
+ for (IConfigurationElement c : e.getConfigurationElements())
{
- createBuilderFromElement( c, tmp );
+ createBuilderFromElement(c, tmp);
}
}
- builders = new LinkedList<IOSGiInstallBuilder>( tmp.keySet() );
- Collections.sort( builders, new Comparator<IOSGiInstallBuilder>()
+ builders = new LinkedList<IOSGiInstallBuilder>(tmp.keySet());
+ Collections.sort(builders, new Comparator<IOSGiInstallBuilder>()
{
- public int compare( IOSGiInstallBuilder o1, IOSGiInstallBuilder o2 )
+ public int compare(IOSGiInstallBuilder o1, IOSGiInstallBuilder o2)
{
- int p1 = tmp.get( o1 );
- int p2 = tmp.get( o2 );
+ int p1 = tmp.get(o1);
+ int p2 = tmp.get(o2);
- if ( p1 == p2 )
+ if (p1 == p2)
{
return 0;
}
- else if ( p1 > p2 )
+ else if (p1 > p2)
{
return -1;
}
@@ -307,38 +293,37 @@ public class OSGiInstallManager implemen
return 1;
}
}
- } );
+ });
}
}
}
-
- private void createBuilderFromElement( IConfigurationElement c, Map<IOSGiInstallBuilder, Integer> builder )
+ private void createBuilderFromElement(IConfigurationElement c,
+ Map<IOSGiInstallBuilder, Integer> builder)
{
try
{
- IOSGiInstallBuilder b = ( IOSGiInstallBuilder ) c.createExecutableExtension( "class" );
- int priority = parsePriority( c );
- builder.put( b, priority );
+ IOSGiInstallBuilder b = (IOSGiInstallBuilder) c.createExecutableExtension("class");
+ int priority = parsePriority(c);
+ builder.put(b, priority);
}
- catch ( CoreException e )
+ catch (CoreException e)
{
- SigilCore.error( "Failed to create builder", e );
+ SigilCore.error("Failed to create builder", e);
}
}
-
- private int parsePriority( IConfigurationElement c )
+ private int parsePriority(IConfigurationElement c)
{
- String str = c.getAttribute( "priority" );
+ String str = c.getAttribute("priority");
- if ( str == null )
+ if (str == null)
{
return NORMAL_PRIORITY;
}
else
{
- return Integer.parseInt( str );
+ 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=981604&r1=981603&r2=981604&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 Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.eclipse.internal.model.project;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -47,146 +46,152 @@ import org.eclipse.core.resources.Resour
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 )
+ ArrayList<ISigilProjectModel> projects = new ArrayList<ISigilProjectModel>(
+ all.length);
+ for (IProject p : all)
{
try
{
- if ( p.isOpen() && p.hasNature( SigilCore.NATURE_ID ) )
+ if (p.isOpen() && p.hasNature(SigilCore.NATURE_ID))
{
- ISigilProjectModel n = SigilCore.create( p );
- projects.add( n );
+ ISigilProjectModel n = SigilCore.create(p);
+ projects.add(n);
}
}
- catch ( CoreException e )
+ catch (CoreException e)
{
- SigilCore.error( "Failed to build model element", e );
+ SigilCore.error("Failed to build model element", e);
}
}
return projects;
}
-
- public Set<ISigilProjectModel> resolveDependentProjects( Collection<ICapabilityModelElement> caps, IProgressMonitor monitor )
+ public Set<ISigilProjectModel> resolveDependentProjects(
+ Collection<ICapabilityModelElement> caps, IProgressMonitor monitor)
{
final HashSet<ISigilProjectModel> dependents = new HashSet<ISigilProjectModel>();
- for ( final ISigilProjectModel n : getProjects() )
+ for (final ISigilProjectModel n : getProjects())
{
- for (final ICapabilityModelElement cap : caps ) {
+ for (final ICapabilityModelElement cap : caps)
+ {
final ISigilProjectModel sigil = cap.getAncestor(ISigilProjectModel.class);
-
+
n.visit(new IModelWalker()
{
public boolean visit(IModelElement element)
{
- if ( element instanceof IRequirementModelElement ) {
+ if (element instanceof IRequirementModelElement)
+ {
IRequirementModelElement req = (IRequirementModelElement) element;
- if ( req.accepts(cap) ) {
+ if (req.accepts(cap))
+ {
dependents.add(n);
return false;
}
}
- else if ( element instanceof ILibraryImport ) {
+ else if (element instanceof ILibraryImport)
+ {
ILibraryImport l = (ILibraryImport) element;
- ILibrary lib = SigilCore.getRepositoryManager( sigil ).resolveLibrary( l );
+ ILibrary lib = SigilCore.getRepositoryManager(sigil).resolveLibrary(
+ l);
- if ( lib != null )
+ if (lib != null)
{
- for ( IPackageImport i : lib.getImports() )
+ for (IPackageImport i : lib.getImports())
{
- if ( i.accepts(cap))
+ if (i.accepts(cap))
{
- dependents.add( n );
+ dependents.add(n);
}
}
}
else
{
- SigilCore.error( "No library found for " + l );
+ SigilCore.error("No library found for " + l);
}
}
return true;
}
});
}
-// 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 );
-// }
-// }
-// }
+ // 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
+ public Collection<ISigilBundle> resolveBundles(ISigilProjectModel sigil,
+ IModelElement element, boolean includeOptional, IProgressMonitor monitor)
+ throws CoreException
{
int options = ResolutionConfig.INCLUDE_DEPENDENTS;
- if ( includeOptional )
+ if (includeOptional)
{
options |= ResolutionConfig.INCLUDE_OPTIONAL;
}
- ResolutionConfig config = new ResolutionConfig( options );
+ ResolutionConfig config = new ResolutionConfig(options);
try
{
- IBundleResolver resolver = SigilCore.getRepositoryManager( sigil ).getBundleResolver();
- IResolution resolution = resolver.resolve( element, config, new ResolutionMonitorAdapter( monitor ) );
- resolution.synchronize( monitor );
+ IBundleResolver resolver = SigilCore.getRepositoryManager(sigil).getBundleResolver();
+ IResolution resolution = resolver.resolve(element, config,
+ new ResolutionMonitorAdapter(monitor));
+ resolution.synchronize(monitor);
return resolution.getBundles();
}
- catch ( ResolutionException e )
+ catch (ResolutionException e)
{
- throw SigilCore.newCoreException( e.getMessage(), 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=981604&r1=981603&r2=981604&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 Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.eclipse.internal.model.project;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -83,7 +82,6 @@ import org.eclipse.jdt.core.JavaModelExc
import org.osgi.framework.Version;
import org.osgi.service.prefs.Preferences;
-
/**
* @author dave
*
@@ -106,94 +104,104 @@ public class SigilProject extends Abstra
public SigilProject()
{
- super( "Sigil Project" );
+ super("Sigil Project");
}
-
- public SigilProject( IProject project ) throws CoreException
+ 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));
}
-
- public void save( IProgressMonitor monitor ) throws CoreException
+ public void save(IProgressMonitor monitor) throws CoreException
{
save(monitor, true);
}
-
- public void save( IProgressMonitor monitor, boolean rebuildDependencies ) throws CoreException
+
+ public void save(IProgressMonitor monitor, boolean rebuildDependencies)
+ throws CoreException
{
- SubMonitor progress = SubMonitor.convert( monitor, 1000 );
+ SubMonitor progress = SubMonitor.convert(monitor, 1000);
+
+ bldProjectFile.setContents(buildContents(), IFile.KEEP_HISTORY,
+ progress.newChild(10));
- bldProjectFile.setContents( buildContents(), IFile.KEEP_HISTORY, progress.newChild( 10 ) );
-
- if ( rebuildDependencies ) {
+ if (rebuildDependencies)
+ {
rebuildDependencies(progress.newChild(900));
}
}
- public void rebuildDependencies(IProgressMonitor monitor) throws CoreException {
- SubMonitor progress = SubMonitor.convert( monitor, 1000 );
+ public void rebuildDependencies(IProgressMonitor monitor) throws CoreException
+ {
+ SubMonitor progress = SubMonitor.convert(monitor, 1000);
+
+ HashSet<ICapabilityModelElement> changes = new HashSet<ICapabilityModelElement>(
+ lastCaps);
- HashSet<ICapabilityModelElement> changes = new HashSet<ICapabilityModelElement>(lastCaps);
-
LinkedList<IRequirementModelElement> reqs = new LinkedList<IRequirementModelElement>();
LinkedList<ICapabilityModelElement> caps = new LinkedList<ICapabilityModelElement>();
-
+
checkChanges(progress.newChild(100), reqs, caps);
-
+
boolean reqsChanged;
boolean capsChanged;
-
- synchronized(this) {
+
+ synchronized (this)
+ {
reqsChanged = isRequirementsChanged(reqs);
capsChanged = isCapabilitiesChanged(caps);
}
-
- if ( reqsChanged ) {
+
+ if (reqsChanged)
+ {
processRequirementsChanges(progress.newChild(600));
SigilCore.rebuild(this, progress.newChild(50));
}
-
- progress.setWorkRemaining( 250 );
- if ( capsChanged ) {
+ progress.setWorkRemaining(250);
+
+ if (capsChanged)
+ {
changes.addAll(caps);
- SigilCore.rebuildBundleDependencies( this, changes, progress.newChild( 250 ) );
- }
+ SigilCore.rebuildBundleDependencies(this, changes, progress.newChild(250));
+ }
}
-
- public void flushDependencyState() {
- synchronized(this) {
+
+ public void flushDependencyState()
+ {
+ synchronized (this)
+ {
lastReqs.clear();
}
}
-
- private void processRequirementsChanges(IProgressMonitor monitor) throws CoreException
+
+ private void processRequirementsChanges(IProgressMonitor monitor)
+ throws CoreException
{
- SubMonitor progress = SubMonitor.convert( monitor, 100 );
-
- IRepositoryManager manager = SigilCore.getRepositoryManager( this );
- ResolutionConfig config = new ResolutionConfig( ResolutionConfig.INCLUDE_OPTIONAL | ResolutionConfig.IGNORE_ERRORS );
+ SubMonitor progress = SubMonitor.convert(monitor, 100);
+
+ IRepositoryManager manager = SigilCore.getRepositoryManager(this);
+ ResolutionConfig config = new ResolutionConfig(ResolutionConfig.INCLUDE_OPTIONAL
+ | ResolutionConfig.IGNORE_ERRORS);
try
{
- IResolution resolution = manager.getBundleResolver().resolve( this, config,
- new ResolutionMonitorAdapter( progress.newChild( 20 ) ) );
-
+ IResolution resolution = manager.getBundleResolver().resolve(this, config,
+ new ResolutionMonitorAdapter(progress.newChild(20)));
+
markProblems(resolution);
-
+
// pull remote bundles from repositories to be added to classpath
- if ( !resolution.isSynchronized() )
+ if (!resolution.isSynchronized())
{
- resolution.synchronize( progress.newChild( 80 ) );
+ resolution.synchronize(progress.newChild(80));
}
}
- catch ( ResolutionException e )
+ catch (ResolutionException e)
{
- throw SigilCore.newCoreException( "Failed to resolve dependencies", e );
+ throw SigilCore.newCoreException("Failed to resolve dependencies", e);
}
}
@@ -201,27 +209,26 @@ public class SigilProject extends Abstra
{
try
{
- getProject().deleteMarkers( SigilCore.MARKER_UNRESOLVED_DEPENDENCY, true,
- IResource.DEPTH_ONE );
+ getProject().deleteMarkers(SigilCore.MARKER_UNRESOLVED_DEPENDENCY, true,
+ IResource.DEPTH_ONE);
// Find missing imports
Collection<IPackageImport> imports = getBundle().getBundleInfo().getImports();
- for ( IPackageImport pkgImport : imports )
+ for (IPackageImport pkgImport : imports)
{
- if ( resolution.getProvider( pkgImport ) == null )
+ if (resolution.getProvider(pkgImport) == null)
{
- markMissingImport( pkgImport, getProject() );
+ markMissingImport(pkgImport, getProject());
}
}
// Find missing required bundles
- Collection<IRequiredBundle> requiredBundles = getBundle().getBundleInfo()
- .getRequiredBundles();
- for ( IRequiredBundle requiredBundle : requiredBundles )
+ Collection<IRequiredBundle> requiredBundles = getBundle().getBundleInfo().getRequiredBundles();
+ for (IRequiredBundle requiredBundle : requiredBundles)
{
- if ( resolution.getProvider( requiredBundle ) == null )
+ if (resolution.getProvider(requiredBundle) == null)
{
- markMissingRequiredBundle( requiredBundle, getProject() );
+ markMissingRequiredBundle(requiredBundle, getProject());
}
}
}
@@ -231,30 +238,35 @@ public class SigilProject extends Abstra
}
}
- private void checkChanges(IProgressMonitor monitor, final List<IRequirementModelElement> reqs, final List<ICapabilityModelElement> caps)
+ private void checkChanges(IProgressMonitor monitor,
+ final List<IRequirementModelElement> reqs,
+ final List<ICapabilityModelElement> caps)
{
visit(new IModelWalker()
- {
+ {
public boolean visit(IModelElement element)
{
- if ( element instanceof IRequirementModelElement ) {
+ if (element instanceof IRequirementModelElement)
+ {
reqs.add((IRequirementModelElement) element);
}
- else if ( element instanceof ICapabilityModelElement ) {
+ else if (element instanceof ICapabilityModelElement)
+ {
// also calculate uses during this pass to save multi pass on model
- if ( element instanceof IPackageExport )
+ if (element instanceof IPackageExport)
{
- IPackageExport pe = ( IPackageExport ) element;
+ IPackageExport pe = (IPackageExport) element;
try
{
- pe.setUses( Arrays.asList( JavaHelper.findUses( pe.getPackageName(), SigilProject.this ) ) );
+ pe.setUses(Arrays.asList(JavaHelper.findUses(
+ pe.getPackageName(), SigilProject.this)));
}
- catch ( CoreException e )
+ catch (CoreException e)
{
- SigilCore.error( "Failed to build uses list for " + pe, e );
+ SigilCore.error("Failed to build uses list for " + pe, e);
}
}
-
+
caps.add((ICapabilityModelElement) element);
}
return true;
@@ -262,13 +274,14 @@ public class SigilProject extends Abstra
});
}
-
private boolean isRequirementsChanged(List<IRequirementModelElement> dependencies)
{
- if ( lastReqs.equals(dependencies) ) {
+ if (lastReqs.equals(dependencies))
+ {
return false;
}
- else {
+ else
+ {
lastReqs = dependencies;
return true;
}
@@ -276,39 +289,46 @@ public class SigilProject extends Abstra
private boolean isCapabilitiesChanged(List<ICapabilityModelElement> capabilites)
{
- if ( lastCaps.equals(capabilites) ) {
+ if (lastCaps.equals(capabilites))
+ {
return false;
}
- else {
+ else
+ {
lastCaps = capabilites;
return true;
}
}
- private static void markMissingImport( IPackageImport pkgImport, IProject project ) throws CoreException
+ private static void markMissingImport(IPackageImport pkgImport, IProject project)
+ throws CoreException
{
- IMarker marker = project.getProject().createMarker( SigilCore.MARKER_UNRESOLVED_IMPORT_PACKAGE );
- marker.setAttribute( "element", pkgImport.getPackageName() );
- marker.setAttribute( "versionRange", pkgImport.getVersions().toString() );
- marker.setAttribute( IMarker.MESSAGE, "Cannot resolve imported package \"" + pkgImport.getPackageName()
- + "\" with version range " + pkgImport.getVersions() );
- marker.setAttribute( IMarker.SEVERITY, pkgImport.isOptional() ? IMarker.SEVERITY_WARNING
- : IMarker.SEVERITY_ERROR );
- marker.setAttribute( IMarker.PRIORITY, IMarker.PRIORITY_HIGH );
+ IMarker marker = project.getProject().createMarker(
+ SigilCore.MARKER_UNRESOLVED_IMPORT_PACKAGE);
+ marker.setAttribute("element", pkgImport.getPackageName());
+ marker.setAttribute("versionRange", pkgImport.getVersions().toString());
+ marker.setAttribute(IMarker.MESSAGE, "Cannot resolve imported package \""
+ + pkgImport.getPackageName() + "\" with version range "
+ + pkgImport.getVersions());
+ marker.setAttribute(IMarker.SEVERITY,
+ pkgImport.isOptional() ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR);
+ marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
+ }
+
+ private static void markMissingRequiredBundle(IRequiredBundle req, IProject project)
+ throws CoreException
+ {
+ IMarker marker = project.getProject().createMarker(
+ SigilCore.MARKER_UNRESOLVED_REQUIRE_BUNDLE);
+ marker.setAttribute("element", req.getSymbolicName());
+ marker.setAttribute("versionRange", req.getVersions().toString());
+ marker.setAttribute(IMarker.MESSAGE, "Cannot resolve required bundle \""
+ + req.getSymbolicName() + "\" with version range " + req.getVersions());
+ marker.setAttribute(IMarker.SEVERITY, req.isOptional() ? IMarker.SEVERITY_WARNING
+ : IMarker.SEVERITY_ERROR);
+ marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
}
-
- private static void markMissingRequiredBundle( IRequiredBundle req, IProject project ) throws CoreException
- {
- IMarker marker = project.getProject().createMarker( SigilCore.MARKER_UNRESOLVED_REQUIRE_BUNDLE );
- marker.setAttribute( "element", req.getSymbolicName() );
- marker.setAttribute( "versionRange", req.getVersions().toString() );
- marker.setAttribute( IMarker.MESSAGE, "Cannot resolve required bundle \"" + req.getSymbolicName()
- + "\" with version range " + req.getVersions() );
- marker.setAttribute( IMarker.SEVERITY, req.isOptional() ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR );
- marker.setAttribute( IMarker.PRIORITY, IMarker.PRIORITY_HIGH );
- }
-
/**
* Returns the project custom preference pool.
* Project preferences may include custom encoding.
@@ -317,9 +337,9 @@ public class SigilProject extends Abstra
*/
public Preferences getPreferences()
{
- synchronized ( this )
+ synchronized (this)
{
- if ( preferences == null )
+ if (preferences == null)
{
preferences = loadPreferences();
}
@@ -328,83 +348,80 @@ public class SigilProject extends Abstra
}
}
-
/**
* @return
*/
private synchronized IEclipsePreferences loadPreferences()
{
- IScopeContext context = new ProjectScope( getProject() );
- final IEclipsePreferences eclipsePreferences = context.getNode( SigilCore.PLUGIN_ID );
+ 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 )
+ public void added(IEclipsePreferences.NodeChangeEvent event)
{
// do nothing
}
-
- public void removed( IEclipsePreferences.NodeChangeEvent event )
+ public void removed(IEclipsePreferences.NodeChangeEvent event)
{
- if ( event.getChild() == eclipsePreferences )
+ if (event.getChild() == eclipsePreferences)
{
- synchronized ( SigilProject.this )
+ synchronized (SigilProject.this)
{
preferences = null;
}
- ( ( IEclipsePreferences ) eclipsePreferences.parent() ).removeNodeChangeListener( this );
+ ((IEclipsePreferences) eclipsePreferences.parent()).removeNodeChangeListener(this);
}
}
};
- ( ( IEclipsePreferences ) eclipsePreferences.parent() ).addNodeChangeListener( nodeListener );
+ ((IEclipsePreferences) eclipsePreferences.parent()).addNodeChangeListener(nodeListener);
return eclipsePreferences;
}
-
- public Collection<IClasspathEntry> findExternalClasspath( IProgressMonitor monitor ) throws CoreException
+ public Collection<IClasspathEntry> findExternalClasspath(IProgressMonitor monitor)
+ throws CoreException
{
- return JavaHelper.resolveClasspathEntrys( this, monitor );
+ return JavaHelper.resolveClasspathEntrys(this, monitor);
}
public Version getVersion()
{
ISigilBundle bundle = getBundle();
- return bundle == null ? null : bundle.getBundleInfo() == null ? null : bundle.getBundleInfo().getVersion();
+ 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();
+ return bundle == null ? null : bundle.getBundleInfo() == null ? null
+ : bundle.getBundleInfo().getSymbolicName();
}
-
public IProject getProject()
{
return project;
}
-
public ISigilBundle getBundle()
{
ISigilBundle b = null;
-
+
try
{
boolean newProject = false;
-
- synchronized ( bldProjectFile )
+
+ synchronized (bldProjectFile)
{
- if ( bundle == null )
+ if (bundle == null)
{
- if ( bldProjectFile.getLocation().toFile().exists() )
+ if (bldProjectFile.getLocation().toFile().exists())
{
- bundle = parseContents( bldProjectFile );
+ bundle = parseContents(bldProjectFile);
}
else
{
@@ -416,168 +433,165 @@ public class SigilProject extends Abstra
b = bundle;
}
- if ( newProject ) {
+ if (newProject)
+ {
NullProgressMonitor npm = new NullProgressMonitor();
- bldProjectFile.create( buildContents(), true /* force */, npm );
- project.refreshLocal( IResource.DEPTH_ONE, npm );
+ bldProjectFile.create(buildContents(), true /* force */, npm);
+ project.refreshLocal(IResource.DEPTH_ONE, npm);
}
}
- catch ( CoreException e )
+ catch (CoreException e)
{
- SigilCore.error( "Failed to build bundle", e );
+ SigilCore.error("Failed to build bundle", e);
}
-
+
return b;
}
-
- public void setBundle( ISigilBundle bundle )
+ public void setBundle(ISigilBundle bundle)
{
- synchronized( bldProjectFile ) {
+ synchronized (bldProjectFile)
+ {
this.bundle = bundle;
}
}
-
public IJavaProject getJavaModel()
{
- return JavaCore.create( project );
+ return JavaCore.create(project);
}
-
@Override
- public boolean equals( Object obj )
+ public boolean equals(Object obj)
{
- if ( obj == null )
+ if (obj == null)
return false;
- if ( obj == this )
+ if (obj == this)
return true;
try
{
- SigilProject p = ( SigilProject ) obj;
- return getSymbolicName().equals( p.getSymbolicName() )
- && ( getVersion() == null ? p.getVersion() == null : getVersion().equals( p.getVersion() ) );
+ SigilProject p = (SigilProject) obj;
+ return getSymbolicName().equals(p.getSymbolicName())
+ && (getVersion() == null ? p.getVersion() == null : getVersion().equals(
+ p.getVersion()));
}
- catch ( ClassCastException e )
+ catch (ClassCastException e)
{
return false;
}
}
-
@Override
public int hashCode()
{
int hc = getSymbolicName().hashCode();
- if ( getVersion() != null ) {
+ if (getVersion() != null)
+ {
hc *= getVersion().hashCode();
}
hc *= 7;
return hc;
}
-
@Override
public String toString()
{
return "SigilProject[" + getSymbolicName() + ":" + getVersion() + "]";
}
-
- public void resetClasspath( IProgressMonitor monitor ) throws CoreException
+ public void resetClasspath(IProgressMonitor monitor) throws CoreException
{
- Path containerPath = new Path( SigilCore.CLASSPATH_CONTAINER_PATH );
+ Path containerPath = new Path(SigilCore.CLASSPATH_CONTAINER_PATH);
IJavaProject java = getJavaModel();
- ClasspathContainerInitializer init = JavaCore
- .getClasspathContainerInitializer( SigilCore.CLASSPATH_CONTAINER_PATH );
- ThreadProgressMonitor.setProgressMonitor( monitor );
+ ClasspathContainerInitializer init = JavaCore.getClasspathContainerInitializer(SigilCore.CLASSPATH_CONTAINER_PATH);
+ ThreadProgressMonitor.setProgressMonitor(monitor);
try
{
- init.requestClasspathContainerUpdate( containerPath, java, null );
+ init.requestClasspathContainerUpdate(containerPath, java, null);
}
finally
{
- ThreadProgressMonitor.setProgressMonitor( null );
+ ThreadProgressMonitor.setProgressMonitor(null);
}
}
-
public IPath findBundleLocation() throws CoreException
{
IPath p = PathUtil.newPathIfExists(getBundle().getLocation());
- if ( p == null )
+ if (p == null)
{
- p = SigilCore.getDefault().findDefaultBundleLocation( this );
+ p = SigilCore.getDefault().findDefaultBundleLocation(this);
}
return p;
}
-
- public IModelElement findImport( final String packageName, final IProgressMonitor monitor )
+ public IModelElement findImport(final String packageName,
+ final IProgressMonitor monitor)
{
final IModelElement[] found = new IModelElement[1];
- visit( new IModelWalker()
+ visit(new IModelWalker()
{
- public boolean visit( IModelElement element )
+ public boolean visit(IModelElement element)
{
- if ( element instanceof IPackageImport )
+ if (element instanceof IPackageImport)
{
- IPackageImport pi = ( IPackageImport ) element;
- if ( pi.getPackageName().equals( packageName ) )
+ IPackageImport pi = (IPackageImport) element;
+ if (pi.getPackageName().equals(packageName))
{
found[0] = pi;
return false;
}
}
- else if ( element instanceof IRequiredBundle )
+ else if (element instanceof IRequiredBundle)
{
- IRequiredBundle rb = ( IRequiredBundle ) element;
+ 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() )
+ 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 ) )
+ if (pe.getPackageName().equals(packageName))
{
found[0] = rb;
return false;
}
}
}
- catch ( ResolutionException e )
+ catch (ResolutionException e)
{
- SigilCore.error( "Failed to resolve " + rb, e );
+ SigilCore.error("Failed to resolve " + rb, e);
}
}
return true;
}
- } );
+ });
return found[0];
}
-
- public boolean isInClasspath( String packageName, IProgressMonitor monitor ) throws CoreException
+ public boolean isInClasspath(String packageName, IProgressMonitor monitor)
+ throws CoreException
{
- if ( findImport( packageName, monitor ) != null )
+ if (findImport(packageName, monitor) != null)
{
return true;
}
- for ( String path : getBundle().getClasspathEntrys() )
+ for (String path : getBundle().getClasspathEntrys())
{
- IClasspathEntry cp = getJavaModel().decodeClasspathEntry( path );
- for ( IPackageFragmentRoot root : getJavaModel().findPackageFragmentRoots( cp ) )
+ IClasspathEntry cp = getJavaModel().decodeClasspathEntry(path);
+ for (IPackageFragmentRoot root : getJavaModel().findPackageFragmentRoots(cp))
{
- if ( findPackage( packageName, root ) )
+ if (findPackage(packageName, root))
{
return true;
}
@@ -586,38 +600,37 @@ public class SigilProject extends Abstra
return false;
}
-
- public boolean isInClasspath( ISigilBundle bundle )
+ public boolean isInClasspath(ISigilBundle bundle)
{
- for ( String path : getBundle().getClasspathEntrys() )
+ for (String path : getBundle().getClasspathEntrys())
{
- IClasspathEntry cp = getJavaModel().decodeClasspathEntry( path );
- switch ( cp.getEntryKind() )
+ 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() );
+ 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 cp.getPath().equals(bundle.getLocation());
}
}
return false;
}
-
- private boolean findPackage( String packageName, IParent parent ) throws JavaModelException
+ private boolean findPackage(String packageName, IParent parent)
+ throws JavaModelException
{
- for ( IJavaElement e : parent.getChildren() )
+ for (IJavaElement e : parent.getChildren())
{
- if ( e.getElementType() == IJavaElement.PACKAGE_FRAGMENT )
+ if (e.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
{
- return e.getElementName().equals( packageName );
+ return e.getElementName().equals(packageName);
}
- if ( e instanceof IParent )
+ if (e instanceof IParent)
{
- if ( findPackage( packageName, ( IParent ) e ) )
+ if (findPackage(packageName, (IParent) e))
{
return true;
}
@@ -627,113 +640,115 @@ public class SigilProject extends Abstra
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 );
+ 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
+ private ISigilBundle parseContents(IFile projectFile) throws CoreException
{
- if ( projectFile.getName().equals( SigilCore.SIGIL_PROJECT_FILE ) )
+ if (projectFile.getName().equals(SigilCore.SIGIL_PROJECT_FILE))
{
- return parseBldContents( projectFile.getLocationURI() );
+ return parseBldContents(projectFile.getLocationURI());
}
else
{
- throw SigilCore.newCoreException( "Unexpected project file: " + projectFile.getName(), null );
+ throw SigilCore.newCoreException("Unexpected project file: "
+ + projectFile.getName(), null);
}
}
-
- private ISigilBundle parseBldContents( URI uri ) throws CoreException
+ private ISigilBundle parseBldContents(URI uri) throws CoreException
{
try
{
- bldProject = BldFactory.getProject( uri, true );
+ bldProject = BldFactory.getProject(uri, true);
ISigilBundle bundle = bldProject.getDefaultBundle();
-
- if ( bundle == null ) {
+
+ if (bundle == null)
+ {
throw SigilCore.newCoreException("No default bundle", null);
}
-
- bundle.setParent( this );
+
+ bundle.setParent(this);
return bundle;
}
- catch ( IOException e )
+ catch (IOException e)
{
- throw SigilCore.newCoreException( "Failed to parse " + uri, e );
+ throw SigilCore.newCoreException("Failed to parse " + uri, e);
}
}
-
private InputStream buildContents() throws CoreException
{
ByteArrayOutputStream buf = new ByteArrayOutputStream();
try
{
- if ( bldProject == null )
+ if (bldProject == null)
{
- bldProject = BldFactory.newProject( bldProjectFile.getLocationURI(), null );
+ bldProject = BldFactory.newProject(bldProjectFile.getLocationURI(), null);
}
- bldProject.setDefaultBundle( getBundle() );
- bldProject.saveTo( buf );
+ bldProject.setDefaultBundle(getBundle());
+ bldProject.saveTo(buf);
}
- catch ( IOException e )
+ catch (IOException e)
{
- throw SigilCore.newCoreException( "Failed to save project file", e );
+ throw SigilCore.newCoreException("Failed to save project file", e);
}
- return new ByteArrayInputStream( buf.toByteArray() );
+ return new ByteArrayInputStream(buf.toByteArray());
}
-
public String getName()
{
return getProject().getName();
}
-
public IPath findOutputLocation() throws CoreException
{
- return getProject().getLocation().append( getJavaModel().getOutputLocation().removeFirstSegments( 1 ) );
+ return getProject().getLocation().append(
+ getJavaModel().getOutputLocation().removeFirstSegments(1));
}
-
public IBldProject getBldProject() throws CoreException
{
try
{
- return BldFactory.getProject( project.getFile( IBldProject.PROJECT_FILE ).getLocationURI() );
+ return BldFactory.getProject(project.getFile(IBldProject.PROJECT_FILE).getLocationURI());
}
- catch ( IOException e )
+ catch (IOException e)
{
- throw SigilCore.newCoreException( "Failed to get project file: ", e );
+ throw SigilCore.newCoreException("Failed to get project file: ", e);
}
}
-
- public boolean isInBundleClasspath( IPackageFragment root ) throws JavaModelException
+ public boolean isInBundleClasspath(IPackageFragment root) throws JavaModelException
{
- if ( getBundle().getClasspathEntrys().isEmpty() ) {
- for ( String p : getBundle().getPackages() ) {
- SigilCore.log("Checking " + p + "->" + root.getElementName() );
+ if (getBundle().getClasspathEntrys().isEmpty())
+ {
+ for (String p : getBundle().getPackages())
+ {
+ SigilCore.log("Checking " + p + "->" + root.getElementName());
Matcher m = GlobCompiler.compile(p).matcher(root.getElementName());
- if ( m.matches() ) {
+ if (m.matches())
+ {
return true;
}
}
return false;
}
- else {
+ else
+ {
IPackageFragmentRoot parent = (IPackageFragmentRoot) root.getParent();
- String enc = getJavaModel().encodeClasspathEntry( parent.getRawClasspathEntry() );
- return getBundle().getClasspathEntrys().contains( enc.trim() );
+ String enc = getJavaModel().encodeClasspathEntry(
+ parent.getRawClasspathEntry());
+ return getBundle().getClasspathEntrys().contains(enc.trim());
}
}
}