From b8f4bb3092efa42a727a6d4a724c8413d64ea557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20SVENSSON?= Date: Sun, 1 Oct 2023 23:04:02 +0200 Subject: [PATCH] Format java files in o.e.equinox.app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was achieved by running: eclipse -consolelog -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \ -config .settings/org.eclipse.jdt.core.prefs . -data `mktemp -d` Signed-off-by: Torbjörn SVENSSON --- .../ApplicationAdminPermission.java | 295 +++++++------ .../application/ApplicationDescriptor.java | 398 +++++++++--------- .../application/ApplicationException.java | 79 ++-- .../application/ApplicationHandle.java | 140 +++--- .../application/ScheduledApplication.java | 110 +++-- .../org/eclipse/equinox/app/IApplication.java | 56 +-- .../equinox/app/IApplicationContext.java | 131 +++--- .../equinox/internal/app/Activator.java | 18 +- .../internal/app/AnyThreadAppLauncher.java | 3 +- .../equinox/internal/app/AppCommands.java | 94 +++-- .../equinox/internal/app/AppPersistence.java | 55 ++- .../equinox/internal/app/CommandLineArgs.java | 14 +- .../app/DefaultApplicationListener.java | 31 +- .../internal/app/EclipseAppContainer.java | 220 ++++++---- .../internal/app/EclipseAppDescriptor.java | 20 +- .../internal/app/EclipseAppHandle.java | 70 +-- .../app/EclipseScheduledApplication.java | 10 +- .../equinox/internal/app/IBranding.java | 2 +- .../internal/app/MainApplicationLauncher.java | 3 +- .../app/ProviderExtensionBranding.java | 3 +- 20 files changed, 944 insertions(+), 808 deletions(-) diff --git a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationAdminPermission.java b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationAdminPermission.java index 5fe9fdd7f70..f16f7f84e4e 100644 --- a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationAdminPermission.java +++ b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationAdminPermission.java @@ -33,25 +33,23 @@ * specified filter. *

* ApplicationAdminPermission may be granted for different actions: - * {@code lifecycle}, {@code schedule} and {@code lock}. The - * permission {@code schedule} implies the permission - * {@code lifecycle}. + * {@code lifecycle}, {@code schedule} and {@code lock}. The permission + * {@code schedule} implies the permission {@code lifecycle}. * * @version $Id$ */ public class ApplicationAdminPermission extends Permission { private static final long serialVersionUID = 1L; - + /** * Allows the lifecycle management of the target applications. */ public static final String LIFECYCLE_ACTION = "lifecycle"; /** - * Allows scheduling of the target applications. The permission to - * schedule an application implies that the scheduler can also - * manage the lifecycle of that application i.e. {@code schedule} - * implies {@code lifecycle} + * Allows scheduling of the target applications. The permission to schedule an + * application implies that the scheduler can also manage the lifecycle of that + * application i.e. {@code schedule} implies {@code lifecycle} */ public static final String SCHEDULE_ACTION = "schedule"; @@ -60,219 +58,217 @@ public class ApplicationAdminPermission extends Permission { */ public static final String LOCK_ACTION = "lock"; - private ApplicationDescriptor applicationDescriptor; + private ApplicationDescriptor applicationDescriptor; /** - * Constructs an ApplicationAdminPermission. The {@code filter} - * specifies the target application. The {@code filter} is an - * LDAP-style filter, the recognized properties are {@code signer} - * and {@code pid}. The pattern specified in the {@code signer} - * is matched with the Distinguished Name chain used to sign the application. - * Wildcards in a DN are not matched according to the filter string rules, - * but according to the rules defined for a DN chain. The attribute - * {@code pid} is matched with the PID of the application according to - * the filter string rules. + * Constructs an ApplicationAdminPermission. The {@code filter} specifies the + * target application. The {@code filter} is an LDAP-style filter, the + * recognized properties are {@code signer} and {@code pid}. The pattern + * specified in the {@code signer} is matched with the Distinguished Name chain + * used to sign the application. Wildcards in a DN are not matched according to + * the filter string rules, but according to the rules defined for a DN chain. + * The attribute {@code pid} is matched with the PID of the application + * according to the filter string rules. *

- * If the {@code filter} is {@code null} then it matches - * {@code "*"}. If - * {@code actions} is {@code "*"} then it identifies all the - * possible actions. + * If the {@code filter} is {@code null} then it matches {@code "*"}. If + * {@code actions} is {@code "*"} then it identifies all the possible actions. * - * @param filter - * filter to identify application. The value {@code null} - * is equivalent to {@code "*"} and it indicates "all application". - * @param actions - * comma-separated list of the desired actions granted on the - * applications or "*" means all the actions. It must not be - * {@code null}. The order of the actions in the list is - * not significant. - * @throws InvalidSyntaxException - * is thrown if the specified {@code filter} is not syntactically - * correct. + * @param filter filter to identify application. The value {@code null} is + * equivalent to {@code "*"} and it indicates "all application". + * @param actions comma-separated list of the desired actions granted on the + * applications or "*" means all the actions. It must not be + * {@code null}. The order of the actions in the list is not + * significant. + * @throws InvalidSyntaxException is thrown if the specified {@code filter} is + * not syntactically correct. * - * @exception NullPointerException - * is thrown if the actions parameter is {@code null} + * @exception NullPointerException is thrown if the actions parameter is + * {@code null} * * @see ApplicationDescriptor * @see org.osgi.framework.AdminPermission */ public ApplicationAdminPermission(String filter, String actions) throws InvalidSyntaxException { super(filter == null ? "*" : filter); - - if( filter == null ) + + if (filter == null) filter = "*"; - - if( actions == null ) - throw new NullPointerException( "Action string cannot be null!" ); - + + if (actions == null) + throw new NullPointerException("Action string cannot be null!"); + this.applicationDescriptor = null; this.filter = (filter == null ? "*" : filter); this.actions = actions; - if( !filter.equals( "*" ) && !filter.equals( "<>" ) ) - FrameworkUtil.createFilter( this.filter ); // check if the filter is valid + if (!filter.equals("*") && !filter.equals("<>")) + FrameworkUtil.createFilter(this.filter); // check if the filter is valid init(); } - + /** - * This contructor should be used when creating {@code ApplicationAdminPermission} - * instance for {@code checkPermission} call. + * This contructor should be used when creating + * {@code ApplicationAdminPermission} instance for {@code checkPermission} call. + * * @param application the tareget of the operation, it must not be {@code null} - * @param actions the required operation. it must not be {@code null} - * @throws NullPointerException if any of the arguments is null. + * @param actions the required operation. it must not be {@code null} + * @throws NullPointerException if any of the arguments is null. */ public ApplicationAdminPermission(ApplicationDescriptor application, String actions) { super(application.getApplicationId()); - - if( application == null || actions == null ) - throw new NullPointerException( "ApplicationDescriptor and action string cannot be null!" ); - + + if (application == null || actions == null) + throw new NullPointerException("ApplicationDescriptor and action string cannot be null!"); + this.filter = application.getApplicationId(); this.applicationDescriptor = application; this.actions = actions; - + init(); } - + /** * This method can be used in the {@link java.security.ProtectionDomain} - * implementation in the {@code implies} method to insert the - * application ID of the current application into the permission being - * checked. This enables the evaluation of the - * {@code <<SELF>>} pseudo targets. + * implementation in the {@code implies} method to insert the application ID of + * the current application into the permission being checked. This enables the + * evaluation of the {@code <<SELF>>} pseudo targets. + * * @param applicationId the ID of the current application. * @return the permission updated with the ID of the current application */ public ApplicationAdminPermission setCurrentApplicationId(String applicationId) { ApplicationAdminPermission newPerm = null; - - if( this.applicationDescriptor == null ) { + + if (this.applicationDescriptor == null) { try { - newPerm = new ApplicationAdminPermission( this.filter, this.actions ); - }catch( InvalidSyntaxException e ) { + newPerm = new ApplicationAdminPermission(this.filter, this.actions); + } catch (InvalidSyntaxException e) { throw new RuntimeException(e); /* this can never happen */ } - } - else - newPerm = new ApplicationAdminPermission( this.applicationDescriptor, this.actions ); - + } else + newPerm = new ApplicationAdminPermission(this.applicationDescriptor, this.actions); + newPerm.applicationID = applicationId; - + return newPerm; } /** - * Checks if the specified {@code permission} is implied by this permission. - * The method returns true under the following conditions: + * Checks if the specified {@code permission} is implied by this permission. The + * method returns true under the following conditions: *

+ *
  • This permission was created by specifying a filter (see + * {@link #ApplicationAdminPermission(String, String)}) + *
  • The implied {@code otherPermission} was created for a particular + * {@link ApplicationDescriptor} (see + * {@link #ApplicationAdminPermission(ApplicationDescriptor, String)}) + *
  • The {@code filter} of this permission mathes the + * {@code ApplicationDescriptor} specified in the {@code otherPermission}. If + * the filter in this permission is the {@code <<SELF>>} pseudo + * target, then the currentApplicationId set in the {@code otherPermission} is + * compared to the application Id of the target {@code ApplicationDescriptor}. + *
  • The list of permitted actions in this permission contains all actions + * required in the {@code otherPermission} + * * Otherwise the method returns false. + * * @param otherPermission the implied permission - * @return true if this permission implies the {@code otherPermission}, false otherwise. + * @return true if this permission implies the {@code otherPermission}, false + * otherwise. */ @Override public boolean implies(Permission otherPermission) { - if( otherPermission == null ) + if (otherPermission == null) return false; - - if(!(otherPermission instanceof ApplicationAdminPermission)) + + if (!(otherPermission instanceof ApplicationAdminPermission)) return false; ApplicationAdminPermission other = (ApplicationAdminPermission) otherPermission; - if( !filter.equals("*") ) { - if( other.applicationDescriptor == null ) + if (!filter.equals("*")) { + if (other.applicationDescriptor == null) return false; - - if( filter.equals( "<>") ) { - if( other.applicationID == null ) + + if (filter.equals("<>")) { + if (other.applicationID == null) return false; /* it cannot be, this might be a bug */ - - if( !other.applicationID.equals( other.applicationDescriptor.getApplicationId() ) ) + + if (!other.applicationID.equals(other.applicationDescriptor.getApplicationId())) return false; - } - else { + } else { Hashtable props = new Hashtable(); - props.put( "pid", other.applicationDescriptor.getApplicationId() ); - props.put( "signer", new SignerWrapper( other.applicationDescriptor ) ); - + props.put("pid", other.applicationDescriptor.getApplicationId()); + props.put("signer", new SignerWrapper(other.applicationDescriptor)); + Filter flt = getFilter(); - if( flt == null ) + if (flt == null) return false; - - if( !flt.match( props ) ) + + if (!flt.match(props)) return false; } } - - if( !actionsVector.containsAll( other.actionsVector ) ) + + if (!actionsVector.containsAll(other.actionsVector)) return false; - + return true; } @Override public boolean equals(Object with) { - if( with == null || !(with instanceof ApplicationAdminPermission) ) + if (with == null || !(with instanceof ApplicationAdminPermission)) return false; - - ApplicationAdminPermission other = (ApplicationAdminPermission)with; - + + ApplicationAdminPermission other = (ApplicationAdminPermission) with; + // Compare actions: - if( other.actionsVector.size() != actionsVector.size() ) + if (other.actionsVector.size() != actionsVector.size()) return false; - - for( int i=0; i != actionsVector.size(); i++ ) - if( !other.actionsVector.contains( actionsVector.get( i ) ) ) + + for (int i = 0; i != actionsVector.size(); i++) + if (!other.actionsVector.contains(actionsVector.get(i))) return false; - - - return equal(this.filter, other.filter ) && equal(this.applicationDescriptor, other.applicationDescriptor) + + return equal(this.filter, other.filter) && equal(this.applicationDescriptor, other.applicationDescriptor) && equal(this.applicationID, other.applicationID); } - + /** - * Compares parameters for equality. If both object are null, they are considered - * equal. - * @param a object to compare - * @param b other object to compare - * @return true if both objects are equal or both are null - */ + * Compares parameters for equality. If both object are null, they are + * considered equal. + * + * @param a object to compare + * @param b other object to compare + * @return true if both objects are equal or both are null + */ private static boolean equal(Object a, Object b) { // This equation is true if both references are null or both point // to the same object. In both cases they are considered as equal. - if( a == b ) { + if (a == b) { return true; } - + return a.equals(b); } @Override public int hashCode() { int hc = 0; - for( int i=0; i != actionsVector.size(); i++ ) - hc ^= ((String)actionsVector.get( i )).hashCode(); - hc ^= (null == this.filter )? 0 : this.filter.hashCode(); + for (int i = 0; i != actionsVector.size(); i++) + hc ^= ((String) actionsVector.get(i)).hashCode(); + hc ^= (null == this.filter) ? 0 : this.filter.hashCode(); hc ^= (null == this.applicationDescriptor) ? 0 : this.applicationDescriptor.hashCode(); hc ^= (null == this.applicationID) ? 0 : this.applicationID.hashCode(); return hc; } /** - * Returns the actions of this permission. - * @return the actions specified when this permission was created - */ + * Returns the actions of this permission. + * + * @return the actions specified when this permission was created + */ @Override public String getActions() { return actions; @@ -281,11 +277,11 @@ public String getActions() { private String applicationID; private static final Vector ACTIONS = new Vector(); - private Vector actionsVector; - private final String filter; - private final String actions; - private Filter appliedFilter = null; - + private Vector actionsVector; + private final String filter; + private final String actions; + private Filter appliedFilter = null; + static { ACTIONS.add(LIFECYCLE_ACTION); ACTIONS.add(SCHEDULE_ACTION); @@ -299,29 +295,28 @@ private static Vector actionsVector(String actions) { String action = t.nextToken().trim(); v.add(action.toLowerCase()); } - - if( v.contains( SCHEDULE_ACTION ) && !v.contains( LIFECYCLE_ACTION ) ) - v.add( LIFECYCLE_ACTION ); - + + if (v.contains(SCHEDULE_ACTION) && !v.contains(LIFECYCLE_ACTION)) + v.add(LIFECYCLE_ACTION); + return v; } - private static class SignerWrapper extends Object { private String pattern; private ApplicationDescriptor appDesc; - + /** * @param pattern */ public SignerWrapper(String pattern) { - this.pattern = pattern; + this.pattern = pattern; } - + SignerWrapper(ApplicationDescriptor appDesc) { this.appDesc = appDesc; } - + @Override public boolean equals(Object o) { if (!(o instanceof SignerWrapper)) @@ -332,26 +327,26 @@ public boolean equals(Object o) { return matchAppDesc.matchDNChain(matchPattern); } } - + private void init() { - actionsVector = actionsVector( actions ); + actionsVector = actionsVector(actions); - if ( actions.equals("*") ) - actionsVector = actionsVector( LIFECYCLE_ACTION + "," + SCHEDULE_ACTION + "," + LOCK_ACTION ); + if (actions.equals("*")) + actionsVector = actionsVector(LIFECYCLE_ACTION + "," + SCHEDULE_ACTION + "," + LOCK_ACTION); else if (!ACTIONS.containsAll(actionsVector)) throw new IllegalArgumentException("Illegal action!"); - + applicationID = null; } - + private Filter getFilter() { if (appliedFilter == null) { try { appliedFilter = FrameworkUtil.createFilter(filter); } catch (InvalidSyntaxException e) { - //we will return null + // we will return null } - } + } return appliedFilter; } } diff --git a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationDescriptor.java b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationDescriptor.java index 219ec9e84e8..3e39abe5148 100644 --- a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationDescriptor.java +++ b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationDescriptor.java @@ -33,10 +33,10 @@ public abstract class ApplicationDescriptor { /* - * NOTE: An implementor may also choose to replace this class in - * their distribution with a class that directly interfaces with the - * org.osgi.service.application implementation. This replacement class MUST NOT alter the - * public/protected signature of this class. + * NOTE: An implementor may also choose to replace this class in their + * distribution with a class that directly interfaces with the + * org.osgi.service.application implementation. This replacement class MUST NOT + * alter the public/protected signature of this class. */ /** @@ -111,16 +111,15 @@ public abstract class ApplicationDescriptor { private final String pid; - private final boolean[] locked = {false}; + private final boolean[] locked = { false }; /** * Constructs the {@code ApplicationDescriptor}. * - * @param applicationId - * The identifier of the application. Its value is also available - * as the {@code service.pid} service property of this - * {@code ApplicationDescriptor} service. This parameter must not - * be {@code null}. + * @param applicationId The identifier of the application. Its value is also + * available as the {@code service.pid} service property of + * this {@code ApplicationDescriptor} service. This + * parameter must not be {@code null}. * @throws NullPointerException if the specified {@code applicationId} is null. */ protected ApplicationDescriptor(String applicationId) { @@ -142,56 +141,54 @@ public final String getApplicationId() { } /** - * This method verifies whether the specified {@code pattern} - * matches the Distinguished Names of any of the certificate chains - * used to authenticate this application. + * This method verifies whether the specified {@code pattern} matches the + * Distinguished Names of any of the certificate chains used to authenticate + * this application. *

    - * The {@code pattern} must adhere to the - * syntax defined in {@link org.osgi.service.application.ApplicationAdminPermission} - * for signer attributes. + * The {@code pattern} must adhere to the syntax defined in + * {@link org.osgi.service.application.ApplicationAdminPermission} for signer + * attributes. *

    - * This method is used by {@link ApplicationAdminPermission#implies(java.security.Permission)} method - * to match target {@code ApplicationDescriptor} and filter. + * This method is used by + * {@link ApplicationAdminPermission#implies(java.security.Permission)} method + * to match target {@code ApplicationDescriptor} and filter. * - * @param pattern a pattern for a chain of Distinguished Names. It must not be null. - * @return {@code true} if the specified pattern matches at least - * one of the certificate chains used to authenticate this application - * @throws NullPointerException if the specified {@code pattern} is null. - * @throws IllegalStateException if the application descriptor was - * unregistered + * @param pattern a pattern for a chain of Distinguished Names. It must not be + * null. + * @return {@code true} if the specified pattern matches at least one of the + * certificate chains used to authenticate this application + * @throws NullPointerException if the specified {@code pattern} is null. + * @throws IllegalStateException if the application descriptor was unregistered */ public abstract boolean matchDNChain(String pattern); /** - * Returns the properties of the application descriptor as key-value pairs. - * The return value contains the locale aware and unaware properties as - * well. The returned {@code Map} will include the service - * properties of this {@code ApplicationDescriptor} as well. + * Returns the properties of the application descriptor as key-value pairs. The + * return value contains the locale aware and unaware properties as well. The + * returned {@code Map} will include the service properties of this + * {@code ApplicationDescriptor} as well. *

    - * This method will call the {@code getPropertiesSpecific} method - * to enable the container implementation to insert application model and/or - * container implementation specific properties. + * This method will call the {@code getPropertiesSpecific} method to enable the + * container implementation to insert application model and/or container + * implementation specific properties. *

    - * The returned {@link java.util.Map} will contain the standard OSGi service - * properties as well - * (e.g. service.id, service.vendor etc.) and specialized application - * descriptors may offer further service properties. The returned Map contains - * a snapshot of the properties. It will not reflect further changes in the - * property values nor will the update of the Map change the corresponding - * service property. - * - * @param locale - * the locale string, it may be null, the value null means the - * default locale. If the provided locale is the empty String - * ({@code ""})then raw (non-localized) values are returned. + * The returned {@link java.util.Map} will contain the standard OSGi service + * properties as well (e.g. service.id, service.vendor etc.) and specialized + * application descriptors may offer further service properties. The returned + * Map contains a snapshot of the properties. It will not reflect further + * changes in the property values nor will the update of the Map change the + * corresponding service property. * - * @return copy of the service properties of this application descriptor service, - * according to the specified locale. If locale is null then the - * default locale's properties will be returned. (Since service + * @param locale the locale string, it may be null, the value null means the + * default locale. If the provided locale is the empty String + * ({@code ""})then raw (non-localized) values are returned. + * + * @return copy of the service properties of this application descriptor + * service, according to the specified locale. If locale is null then + * the default locale's properties will be returned. (Since service * properties are always exist it cannot return null.) * - * @throws IllegalStateException - * if the application descriptor is unregistered + * @throws IllegalStateException if the application descriptor is unregistered */ public final Map getProperties(String locale) { Map props = getPropertiesSpecific(locale); @@ -204,47 +201,46 @@ public final Map getProperties(String locale) { unlockSpecific(); } } - /* replace the container's lock with the application model's lock, that's the correct */ + /* + * replace the container's lock with the application model's lock, that's the + * correct + */ props.put(APPLICATION_LOCKED, Boolean.valueOf(locked[0])); return props; } /** - * Container implementations can provide application model specific - * and/or container implementation specific properties via this - * method. + * Container implementations can provide application model specific and/or + * container implementation specific properties via this method. * * Localizable properties must be returned localized if the provided - * {@code locale} argument is not the empty String. The value - * {@code null} indicates to use the default locale, for other - * values the specified locale should be used. - * - * The returned {@link java.util.Map} must contain the standard OSGi service - * properties as well - * (e.g. service.id, service.vendor etc.) and specialized application - * descriptors may offer further service properties. - * The returned {@code Map} - * contains a snapshot of the properties. It will not reflect further changes in the - * property values nor will the update of the Map change the corresponding - * service property. - - * @param locale the locale to be used for localizing the properties. - * If {@code null} the default locale should be used. If it is - * the empty String ({@code ""}) then raw (non-localized) values - * should be returned. + * {@code locale} argument is not the empty String. The value {@code null} + * indicates to use the default locale, for other values the specified locale + * should be used. + * + * The returned {@link java.util.Map} must contain the standard OSGi service + * properties as well (e.g. service.id, service.vendor etc.) and specialized + * application descriptors may offer further service properties. The returned + * {@code Map} contains a snapshot of the properties. It will not reflect + * further changes in the property values nor will the update of the Map change + * the corresponding service property. + * + * @param locale the locale to be used for localizing the properties. If + * {@code null} the default locale should be used. If it is the + * empty String ({@code ""}) then raw (non-localized) values + * should be returned. * * @return the application model specific and/or container implementation - * specific properties of this application descriptor. - * - * @throws IllegalStateException - * if the application descriptor is unregistered + * specific properties of this application descriptor. + * + * @throws IllegalStateException if the application descriptor is unregistered */ protected abstract Map getPropertiesSpecific(String locale); /** * Launches a new instance of an application. The {@code args} parameter - * specifies the startup parameters for the instance to be launched, it may - * be null. + * specifies the startup parameters for the instance to be launched, it may be + * null. *

    * The following steps are made: *

      @@ -254,47 +250,47 @@ public final Map getProperties(String locale) { * {@link ApplicationException#APPLICATION_LOCKED}. *
    • Calls the {@code launchSpecific()} method to create and start an * application instance. - *
    • Returns the {@code ApplicationHandle} returned by the - * launchSpecific() + *
    • Returns the {@code ApplicationHandle} returned by the launchSpecific() *
    - * The caller has to have ApplicationAdminPermission(applicationPID, - * "launch") in order to be able to perform this operation. + * The caller has to have ApplicationAdminPermission(applicationPID, "launch") + * in order to be able to perform this operation. *

    - * The {@code Map} argument of the launch method contains startup arguments - * for the application. The keys used in the Map must be non-null, non-empty - * {@code String} objects. They can be standard or application specific. - * OSGi defines the {@code org.osgi.triggeringevent} key to be used to pass - * the triggering event to a scheduled application, however in the future it - * is possible that other well-known keys will be defined. To avoid unwanted + * The {@code Map} argument of the launch method contains startup arguments for + * the application. The keys used in the Map must be non-null, non-empty + * {@code String} objects. They can be standard or application specific. OSGi + * defines the {@code org.osgi.triggeringevent} key to be used to pass the + * triggering event to a scheduled application, however in the future it is + * possible that other well-known keys will be defined. To avoid unwanted * clashes of keys, the following rules should be applied: *

      - *
    • The keys starting with the dash (-) character are application - * specific, no well-known meaning should be associated with them.
    • - *
    • Well-known keys should follow the reverse domain name based naming. - * In particular, the keys standardized in OSGi should start with + *
    • The keys starting with the dash (-) character are application specific, + * no well-known meaning should be associated with them.
    • + *
    • Well-known keys should follow the reverse domain name based naming. In + * particular, the keys standardized in OSGi should start with * {@code org.osgi.}.
    • *
    *

    - * The method is synchronous, it return only when the application instance - * was successfully started or the attempt to start it failed. + * The method is synchronous, it return only when the application instance was + * successfully started or the attempt to start it failed. *

    - * This method never returns {@code null}. If launching an application - * fails, the appropriate exception is thrown. + * This method never returns {@code null}. If launching an application fails, + * the appropriate exception is thrown. * - * @param arguments Arguments for the newly launched application, may be - * null + * @param arguments Arguments for the newly launched application, may be null * - * @return the registered ApplicationHandle, which represents the newly - * launched application instance. Never returns {@code null}. + * @return the registered ApplicationHandle, which represents the newly launched + * application instance. Never returns {@code null}. * - * @throws SecurityException if the caller doesn't have "lifecycle" - * ApplicationAdminPermission for the application. - * @throws ApplicationException if starting the application failed - * @throws IllegalStateException if the application descriptor is - * unregistered + * @throws SecurityException if the caller doesn't have "lifecycle" + * ApplicationAdminPermission for the + * application. + * @throws ApplicationException if starting the application failed + * @throws IllegalStateException if the application descriptor is + * unregistered * @throws IllegalArgumentException if the specified {@code Map} contains - * invalid keys (null objects, empty {@code String} or a key that is - * not {@code String}) + * invalid keys (null objects, empty + * {@code String} or a key that is not + * {@code String}) */ public final ApplicationHandle launch(Map arguments) throws ApplicationException { SecurityManager sm = System.getSecurityManager(); @@ -302,10 +298,12 @@ public final ApplicationHandle launch(Map arguments) throws ApplicationException sm.checkPermission(new ApplicationAdminPermission(this, ApplicationAdminPermission.LIFECYCLE_ACTION)); synchronized (locked) { if (locked[0]) - throw new ApplicationException(ApplicationException.APPLICATION_LOCKED, "Application is locked, can't launch!"); + throw new ApplicationException(ApplicationException.APPLICATION_LOCKED, + "Application is locked, can't launch!"); } if (!isLaunchableSpecific()) - throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, "Cannot launch the application!"); + throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, + "Cannot launch the application!"); checkArgs(arguments, false); try { return launchSpecific(arguments); @@ -317,103 +315,107 @@ public final ApplicationHandle launch(Map arguments) throws ApplicationException } /** - * Called by launch() to create and start a new instance in an application - * model specific way. It also creates and registeres the application handle - * to represent the newly created and started instance and registeres it. - * The method is synchronous, it return only when the application instance was + * Called by launch() to create and start a new instance in an application model + * specific way. It also creates and registeres the application handle to + * represent the newly created and started instance and registeres it. The + * method is synchronous, it return only when the application instance was * successfully started or the attempt to start it failed. *

    * This method must not return {@code null}. If launching the application * failed, and exception must be thrown. * - * @param arguments - * the startup parameters of the new application instance, may be - * null + * @param arguments the startup parameters of the new application instance, may + * be null * - * @return the registered application model - * specific application handle for the newly created and started - * instance. + * @return the registered application model specific application handle for the + * newly created and started instance. * - * @throws IllegalStateException - * if the application descriptor is unregistered - * @throws Exception - * if any problem occurs. + * @throws IllegalStateException if the application descriptor is unregistered + * @throws Exception if any problem occurs. */ protected abstract ApplicationHandle launchSpecific(Map arguments) throws Exception; /** - * This method is called by launch() to verify that according to the - * container, the application is launchable. + * This method is called by launch() to verify that according to the container, + * the application is launchable. + * + * @return true, if the application is launchable according to the container, + * false otherwise. * - * @return true, if the application is launchable according to the - * container, false otherwise. - * - * @throws IllegalStateException - * if the application descriptor is unregistered + * @throws IllegalStateException if the application descriptor is unregistered */ protected abstract boolean isLaunchableSpecific(); /** - * Schedules the application at a specified event. Schedule information - * should not get lost even if the framework or the device restarts so it - * should be stored in a persistent storage. The method registers a - * {@link ScheduledApplication} service in Service Registry, representing - * the created schedule. + * Schedules the application at a specified event. Schedule information should + * not get lost even if the framework or the device restarts so it should be + * stored in a persistent storage. The method registers a + * {@link ScheduledApplication} service in Service Registry, representing the + * created schedule. *

    * The {@code Map} argument of the method contains startup arguments for the * application. The keys used in the Map must be non-null, non-empty * {@code String} objects. The argument values must be of primitive types, - * wrapper classes of primitive types, {@code String} or arrays or - * collections of these. + * wrapper classes of primitive types, {@code String} or arrays or collections + * of these. *

    * The created schedules have a unique identifier within the scope of this * {@code ApplicationDescriptor}. This identifier can be specified in the - * {@code scheduleId} argument. If this argument is {@code null}, the - * identifier is automatically generated. + * {@code scheduleId} argument. If this argument is {@code null}, the identifier + * is automatically generated. * - * @param scheduleId the identifier of the created schedule. It can be - * {@code null}, in this case the identifier is automatically - * generated. - * @param arguments the startup arguments for the scheduled application, may - * be null - * @param topic specifies the topic of the triggering event, it may contain - * a trailing asterisk as wildcard, the empty string is treated as - * "*", must not be null - * @param eventFilter specifies and LDAP filter to filter on the properties - * of the triggering event, may be null - * @param recurring if the recurring parameter is false then the application - * will be launched only once, when the event firstly occurs. If the - * parameter is true then scheduling will take place for every event - * occurrence; i.e. it is a recurring schedule + * @param scheduleId the identifier of the created schedule. It can be + * {@code null}, in this case the identifier is automatically + * generated. + * @param arguments the startup arguments for the scheduled application, may + * be null + * @param topic specifies the topic of the triggering event, it may + * contain a trailing asterisk as wildcard, the empty string + * is treated as "*", must not be null + * @param eventFilter specifies and LDAP filter to filter on the properties of + * the triggering event, may be null + * @param recurring if the recurring parameter is false then the application + * will be launched only once, when the event firstly occurs. + * If the parameter is true then scheduling will take place + * for every event occurrence; i.e. it is a recurring + * schedule * * @return the registered scheduled application service * - * @throws NullPointerException if the topic is {@code null} - * @throws InvalidSyntaxException if the specified {@code eventFilter} is - * not syntactically correct - * @throws ApplicationException if the schedule couldn't be created. The - * possible error codes are - *

      - *
    • - * {@link ApplicationException#APPLICATION_DUPLICATE_SCHEDULE_ID} if - * the specified {@code scheduleId} is already used for this - * {@code ApplicationDescriptor}
    • - * {@link ApplicationException#APPLICATION_SCHEDULING_FAILED} if the - * scheduling failed due to some internal reason (e.g. persistent - * storage error).
    • - * {@link ApplicationException#APPLICATION_INVALID_STARTUP_ARGUMENT} - * if the specified startup argument doesn't satisfy the type or - * value constraints of startup arguments. - *
    - * @throws SecurityException if the caller doesn't have "schedule" - * ApplicationAdminPermission for the application. - * @throws IllegalStateException if the application descriptor is - * unregistered + * @throws NullPointerException if the topic is {@code null} + * @throws InvalidSyntaxException if the specified {@code eventFilter} is not + * syntactically correct + * @throws ApplicationException if the schedule couldn't be created. The + * possible error codes are + *
      + *
    • + * {@link ApplicationException#APPLICATION_DUPLICATE_SCHEDULE_ID} + * if the specified {@code scheduleId} is + * already used for this + * {@code ApplicationDescriptor} + *
    • + * {@link ApplicationException#APPLICATION_SCHEDULING_FAILED} + * if the scheduling failed due to some + * internal reason (e.g. persistent storage + * error). + *
    • + * {@link ApplicationException#APPLICATION_INVALID_STARTUP_ARGUMENT} + * if the specified startup argument doesn't + * satisfy the type or value constraints of + * startup arguments. + *
    + * @throws SecurityException if the caller doesn't have "schedule" + * ApplicationAdminPermission for the + * application. + * @throws IllegalStateException if the application descriptor is + * unregistered * @throws IllegalArgumentException if the specified {@code Map} contains - * invalid keys (null objects, empty {@code String} or a key that is - * not {@code String}) + * invalid keys (null objects, empty + * {@code String} or a key that is not + * {@code String}) */ - public final ScheduledApplication schedule(String scheduleId, Map arguments, String topic, String eventFilter, boolean recurring) throws InvalidSyntaxException, ApplicationException { + public final ScheduledApplication schedule(String scheduleId, Map arguments, String topic, String eventFilter, + boolean recurring) throws InvalidSyntaxException, ApplicationException { SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPermission(new ApplicationAdminPermission(this, ApplicationAdminPermission.SCHEDULE_ACTION)); @@ -427,11 +429,9 @@ public final ScheduledApplication schedule(String scheduleId, Map arguments, Str * launching a new instance is not possible. It does not affect the already * launched instances. * - * @throws SecurityException - * if the caller doesn't have "lock" ApplicationAdminPermission - * for the application. - * @throws IllegalStateException - * if the application descriptor is unregistered + * @throws SecurityException if the caller doesn't have "lock" + * ApplicationAdminPermission for the application. + * @throws IllegalStateException if the application descriptor is unregistered */ public final void lock() { SecurityManager sm = System.getSecurityManager(); @@ -450,19 +450,17 @@ public final void lock() { * This method is used to notify the container implementation that the * corresponding application has been locked and it should update the * {@code application.locked} service property accordingly. - * @throws IllegalStateException - * if the application descriptor is unregistered + * + * @throws IllegalStateException if the application descriptor is unregistered */ protected abstract void lockSpecific(); /** * Unsets the lock state of the application. * - * @throws SecurityException - * if the caller doesn't have "lock" ApplicationAdminPermission - * for the application. - * @throws IllegalStateException - * if the application descriptor is unregistered + * @throws SecurityException if the caller doesn't have "lock" + * ApplicationAdminPermission for the application. + * @throws IllegalStateException if the application descriptor is unregistered */ public final void unlock() { SecurityManager sm = System.getSecurityManager(); @@ -481,9 +479,8 @@ public final void unlock() { * This method is used to notify the container implementation that the * corresponding application has been unlocked and it should update the * {@code application.locked} service property accordingly. - - * @throws IllegalStateException - * if the application descriptor is unregistered + * + * @throws IllegalStateException if the application descriptor is unregistered */ protected abstract void unlockSpecific(); @@ -495,9 +492,13 @@ private boolean isPersistentlyLocked() { return AppPersistence.isLocked(this); } - private static final Collection scalars = Arrays.asList(new Class[] {String.class, Integer.class, Long.class, Float.class, Double.class, Byte.class, Short.class, Character.class, Boolean.class}); - private static final Collection scalarsArrays = Arrays.asList(new Class[] {String[].class, Integer[].class, Long[].class, Float[].class, Double[].class, Byte[].class, Short[].class, Character[].class, Boolean[].class}); - private static final Collection primitiveArrays = Arrays.asList(new Class[] {long[].class, int[].class, short[].class, char[].class, byte[].class, double[].class, float[].class, boolean[].class}); + private static final Collection scalars = Arrays.asList(new Class[] { String.class, Integer.class, Long.class, + Float.class, Double.class, Byte.class, Short.class, Character.class, Boolean.class }); + private static final Collection scalarsArrays = Arrays + .asList(new Class[] { String[].class, Integer[].class, Long[].class, Float[].class, Double[].class, + Byte[].class, Short[].class, Character[].class, Boolean[].class }); + private static final Collection primitiveArrays = Arrays.asList(new Class[] { long[].class, int[].class, + short[].class, char[].class, byte[].class, double[].class, float[].class, boolean[].class }); private static Map checkArgs(Map arguments, boolean validateValues) throws ApplicationException { if (arguments == null) @@ -506,7 +507,8 @@ private static Map checkArgs(Map arguments, boolean validateValues) throws Appli for (Iterator entries = arguments.entrySet().iterator(); entries.hasNext();) { Map.Entry entry = (Entry) entries.next(); if (!(entry.getKey() instanceof String)) - throw new IllegalArgumentException("Invalid key type: " + entry.getKey() == null ? "" : entry.getKey().getClass().getName()); + throw new IllegalArgumentException( + "Invalid key type: " + entry.getKey() == null ? "" : entry.getKey().getClass().getName()); if ("".equals(entry.getKey())) //$NON-NLS-1$ throw new IllegalArgumentException("Empty string is an invalid key"); if (validateValues) @@ -518,7 +520,7 @@ private static Map checkArgs(Map arguments, boolean validateValues) throws Appli private static void validateValue(Map.Entry entry, Map copy) throws ApplicationException { Class clazz = entry.getValue().getClass(); - // Is it in the set of scalar types + // Is it in the set of scalar types if (scalars.contains(clazz)) { copy.put(entry.getKey(), entry.getValue()); return; @@ -539,12 +541,16 @@ private static void validateValue(Map.Entry entry, Map copy) throws ApplicationE for (Iterator it = valueCollection.iterator(); it.hasNext();) { Class containedClazz = it.next().getClass(); if (!scalars.contains(containedClazz)) { - throw new ApplicationException(ApplicationException.APPLICATION_INVALID_STARTUP_ARGUMENT, "The value for key \"" + entry.getKey() + "\" is a collection that contains an invalid value of type \"" + containedClazz.getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + throw new ApplicationException(ApplicationException.APPLICATION_INVALID_STARTUP_ARGUMENT, + "The value for key \"" + entry.getKey() //$NON-NLS-1$ + + "\" is a collection that contains an invalid value of type \"" //$NON-NLS-1$ + + containedClazz.getName() + "\""); //$NON-NLS-1$ } } copy.put(entry.getKey(), new ArrayList((Collection) entry.getValue())); return; } - throw new ApplicationException(ApplicationException.APPLICATION_INVALID_STARTUP_ARGUMENT, "The value for key \"" + entry.getKey() + "\" is an invalid type \"" + clazz.getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + throw new ApplicationException(ApplicationException.APPLICATION_INVALID_STARTUP_ARGUMENT, + "The value for key \"" + entry.getKey() + "\" is an invalid type \"" + clazz.getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } diff --git a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationException.java b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationException.java index 166bf850e4f..03964c0578d 100644 --- a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationException.java +++ b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationException.java @@ -20,27 +20,27 @@ * This exception is used to indicate problems related to application lifecycle * management. * - * {@code ApplicationException} object is created by the Application Admin - * to denote an exception condition in the lifecycle of an application. + * {@code ApplicationException} object is created by the Application Admin to + * denote an exception condition in the lifecycle of an application. * {@code ApplicationException}s should not be created by developers.
    - * {@code ApplicationException}s are associated with an error code. This - * code describes the type of problem reported in this exception. The possible - * codes are: + * {@code ApplicationException}s are associated with an error code. This code + * describes the type of problem reported in this exception. The possible codes + * are: *
      - *
    • {@link #APPLICATION_LOCKED} - The application couldn't be launched + *
    • {@link #APPLICATION_LOCKED} - The application couldn't be launched * because it is locked.
    • - *
    • {@link #APPLICATION_NOT_LAUNCHABLE} - The application is not in + *
    • {@link #APPLICATION_NOT_LAUNCHABLE} - The application is not in * launchable state.
    • - *
    • {@link #APPLICATION_INTERNAL_ERROR} - An exception was thrown by the + *
    • {@link #APPLICATION_INTERNAL_ERROR} - An exception was thrown by the * application or its container during launch.
    • - *
    • {@link #APPLICATION_SCHEDULING_FAILED} - The scheduling of an application + *
    • {@link #APPLICATION_SCHEDULING_FAILED} - The scheduling of an application * failed. - *
    • {@link #APPLICATION_DUPLICATE_SCHEDULE_ID} - The application scheduling + *
    • {@link #APPLICATION_DUPLICATE_SCHEDULE_ID} - The application scheduling * failed because the specified identifier is already in use. - *
    • {@link #APPLICATION_EXITVALUE_NOT_AVAILABLE} - The exit value is not + *
    • {@link #APPLICATION_EXITVALUE_NOT_AVAILABLE} - The exit value is not * available for an application instance because the instance has not * terminated. - *
    • {@link #APPLICATION_INVALID_STARTUP_ARGUMENT} - One of the specified + *
    • {@link #APPLICATION_INVALID_STARTUP_ARGUMENT} - One of the specified * startup arguments is invalid, for example its type is not permitted. *
    * @@ -49,16 +49,15 @@ public class ApplicationException extends Exception { private static final long serialVersionUID = -7173190453622508207L; private final int errorCode; - + /** * The application couldn't be launched because it is locked. */ - public static final int APPLICATION_LOCKED = 0x01; - + public static final int APPLICATION_LOCKED = 0x01; + /** - * The application is not in launchable state, it's - * {@link ApplicationDescriptor#APPLICATION_LAUNCHABLE} - * attribute is false. + * The application is not in launchable state, it's + * {@link ApplicationDescriptor#APPLICATION_LAUNCHABLE} attribute is false. */ public static final int APPLICATION_NOT_LAUNCHABLE = 0x02; @@ -67,17 +66,17 @@ public class ApplicationException extends Exception { * during launch. The exception is available from {@code getCause()}. */ public static final int APPLICATION_INTERNAL_ERROR = 0x03; - + /** - * The application schedule could not be created due to some internal error - * (for example, the schedule information couldn't be saved due to some - * storage error). + * The application schedule could not be created due to some internal error (for + * example, the schedule information couldn't be saved due to some storage + * error). */ public static final int APPLICATION_SCHEDULING_FAILED = 0x04; - + /** - * The application scheduling failed because the specified identifier - * is already in use. + * The application scheduling failed because the specified identifier is already + * in use. */ public static final int APPLICATION_DUPLICATE_SCHEDULE_ID = 0x05; @@ -90,8 +89,8 @@ public class ApplicationException extends Exception { public static final int APPLICATION_EXITVALUE_NOT_AVAILABLE = 0x06; /** - * One of the specified startup arguments is invalid, for example its - * type is not permitted. + * One of the specified startup arguments is invalid, for example its type is + * not permitted. * * @since 1.1 */ @@ -99,18 +98,19 @@ public class ApplicationException extends Exception { /** * Creates an {@code ApplicationException} with the specified error code. - * @param errorCode The code of the error + * + * @param errorCode The code of the error */ public ApplicationException(int errorCode) { super(); this.errorCode = errorCode; } - + /** * Creates a {@code ApplicationException} that wraps another exception. * - * @param errorCode The code of the error - * @param cause The cause of this exception. + * @param errorCode The code of the error + * @param cause The cause of this exception. */ public ApplicationException(int errorCode, Throwable cause) { super(cause); @@ -119,8 +119,9 @@ public ApplicationException(int errorCode, Throwable cause) { /** * Creates an {@code ApplicationException} with the specified error code. - * @param errorCode The code of the error - * @param message The associated message + * + * @param errorCode The code of the error + * @param message The associated message */ public ApplicationException(int errorCode, String message) { super(message); @@ -130,9 +131,9 @@ public ApplicationException(int errorCode, String message) { /** * Creates a {@code ApplicationException} that wraps another exception. * - * @param errorCode The code of the error - * @param message The associated message. - * @param cause The cause of this exception. + * @param errorCode The code of the error + * @param message The associated message. + * @param cause The cause of this exception. */ public ApplicationException(int errorCode, String message, Throwable cause) { super(message, cause); @@ -140,11 +141,9 @@ public ApplicationException(int errorCode, String message, Throwable cause) { } /** - * Returns the cause of this exception or {@code null} if no cause was - * set. + * Returns the cause of this exception or {@code null} if no cause was set. * - * @return The cause of this exception or {@code null} if no cause was - * set. + * @return The cause of this exception or {@code null} if no cause was set. */ @Override public Throwable getCause() { diff --git a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationHandle.java b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationHandle.java index 1ea1f698ed6..b4874952c4d 100644 --- a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationHandle.java +++ b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ApplicationHandle.java @@ -28,15 +28,14 @@ */ public abstract class ApplicationHandle { /* - * NOTE: An implementor may also choose to replace this class in - * their distribution with a class that directly interfaces with the - * org.osgi.service.application implementation. This replacement class MUST NOT alter the - * public/protected signature of this class. + * NOTE: An implementor may also choose to replace this class in their + * distribution with a class that directly interfaces with the + * org.osgi.service.application implementation. This replacement class MUST NOT + * alter the public/protected signature of this class. */ /** - * The property key for the unique identifier (PID) of the application - * instance. + * The property key for the unique identifier (PID) of the application instance. */ public static final String APPLICATION_PID = Constants.SERVICE_PID; @@ -66,8 +65,7 @@ public abstract class ApplicationHandle { /** * The application instance is being stopped. This is the state of the - * application instance during the execution of the {@code destroy()} - * method. + * application instance during the execution of the {@code destroy()} method. */ public final static String STOPPING = "STOPPING"; @@ -77,25 +75,24 @@ public abstract class ApplicationHandle { /** * Application instance identifier is specified by the container when the - * instance is created. The instance identifier must remain static for the + * instance is created. The instance identifier must remain static for the * lifetime of the instance, it must remain the same even across framework - * restarts for the same application instance. This value must be the same - * as the {@code service.pid} service property of this application - * handle. + * restarts for the same application instance. This value must be the same as + * the {@code service.pid} service property of this application handle. *

    - * The instance identifier should follow the following scheme: - * <application descriptor PID>.<index> - * where <application descriptor PID> is the PID of the - * corresponding {@code ApplicationDescriptor} and <index> - * is a unique integer index assigned by the application container. - * Even after destroying the application index the same index value should not - * be reused in a reasonably long timeframe. + * The instance identifier should follow the following scheme: + * <application descriptor PID>.<index> where + * <application descriptor PID> is the PID of the corresponding + * {@code ApplicationDescriptor} and <index> is a unique integer + * index assigned by the application container. Even after destroying the + * application index the same index value should not be reused in a reasonably + * long timeframe. * * @param instanceId the instance identifier of the represented application - * instance. It must not be null. + * instance. It must not be null. * * @param descriptor the {@code ApplicationDescriptor} of the represented - * application instance. It must not be null. + * application instance. It must not be null. * * @throws NullPointerException if any of the arguments is null. */ @@ -109,8 +106,8 @@ protected ApplicationHandle(String instanceId, ApplicationDescriptor descriptor) } /** - * Retrieves the {@code ApplicationDescriptor} to which this - * {@code ApplicationHandle} belongs. + * Retrieves the {@code ApplicationDescriptor} to which this + * {@code ApplicationHandle} belongs. * * @return The corresponding {@code ApplicationDescriptor} */ @@ -123,43 +120,41 @@ public final ApplicationDescriptor getApplicationDescriptor() { * * @return the state of the application. * - * @throws IllegalStateException - * if the application handle is unregistered + * @throws IllegalStateException if the application handle is unregistered */ public abstract String getState(); /** - * Returns the exit value for the application instance. The timeout - * specifies how the method behaves when the application has not yet - * terminated. A negative, zero or positive value may be used. + * Returns the exit value for the application instance. The timeout specifies + * how the method behaves when the application has not yet terminated. A + * negative, zero or positive value may be used. *

      - *
    • negative - The method does not wait for termination. If the - * application has not terminated then an {@code ApplicationException} - * is thrown.
    • + *
    • negative - The method does not wait for termination. If the application + * has not terminated then an {@code ApplicationException} is thrown.
    • * - *
    • zero - The method waits until the application terminates.
    • + *
    • zero - The method waits until the application terminates.
    • * - *
    • positive - The method waits until the application terminates or the + *
    • positive - The method waits until the application terminates or the * timeout expires. If the timeout expires and the application has not * terminated then an {@code ApplicationException} is thrown.
    • *
    *

    - * The default implementation throws an - * {@code UnsupportedOperationException}. The application model should - * override this method if exit values are supported. + * The default implementation throws an {@code UnsupportedOperationException}. + * The application model should override this method if exit values are + * supported. *

    * - * @param timeout The maximum time in milliseconds to wait for the - * application to timeout. - * @return The exit value for the application instance. The value is - * application specific. + * @param timeout The maximum time in milliseconds to wait for the application + * to timeout. + * @return The exit value for the application instance. The value is application + * specific. * @throws UnsupportedOperationException If the application model does not - * support exit values. - * @throws InterruptedException If the thread is interrupted while waiting - * for the timeout. - * @throws ApplicationException If the application has not terminated. The - * error code will be - * {@link ApplicationException#APPLICATION_EXITVALUE_NOT_AVAILABLE}. + * support exit values. + * @throws InterruptedException If the thread is interrupted while + * waiting for the timeout. + * @throws ApplicationException If the application has not terminated. + * The error code will be + * {@link ApplicationException#APPLICATION_EXITVALUE_NOT_AVAILABLE}. * * @since 1.1 */ @@ -168,8 +163,8 @@ public Object getExitValue(long timeout) throws ApplicationException, Interrupte } /** - * Returns the unique identifier of this instance. This value is also - * available as a service property of this application handle's service.pid. + * Returns the unique identifier of this instance. This value is also available + * as a service property of this application handle's service.pid. * * @return the unique identifier of the instance */ @@ -178,49 +173,46 @@ public final String getInstanceId() { } /** - * The application instance's lifecycle state can be influenced by this - * method. It lets the application instance perform operations to stop - * the application safely, e.g. saving its state to a permanent storage. + * The application instance's lifecycle state can be influenced by this method. + * It lets the application instance perform operations to stop the application + * safely, e.g. saving its state to a permanent storage. *

    * The method must check if the lifecycle transition is valid; a STOPPING - * application cannot be stopped. If it is invalid then the method must - * exit. Otherwise the lifecycle state of the application instance must be - * set to STOPPING. Then the destroySpecific() method must be called to - * perform any application model specific steps for safe stopping of the - * represented application instance. + * application cannot be stopped. If it is invalid then the method must exit. + * Otherwise the lifecycle state of the application instance must be set to + * STOPPING. Then the destroySpecific() method must be called to perform any + * application model specific steps for safe stopping of the represented + * application instance. *

    - * At the end the {@code ApplicationHandle} must be unregistered. - * This method should free all the resources related to this - * {@code ApplicationHandle}. + * At the end the {@code ApplicationHandle} must be unregistered. This method + * should free all the resources related to this {@code ApplicationHandle}. *

    - * When this method is completed the application instance has already made - * its operations for safe stopping, the ApplicationHandle has been - * unregistered and its related resources has been freed. Further calls on - * this application should not be made because they may have unexpected - * results. + * When this method is completed the application instance has already made its + * operations for safe stopping, the ApplicationHandle has been unregistered and + * its related resources has been freed. Further calls on this application + * should not be made because they may have unexpected results. * - * @throws SecurityException - * if the caller doesn't have "lifecycle" - * {@code ApplicationAdminPermission} for the corresponding application. + * @throws SecurityException if the caller doesn't have "lifecycle" + * {@code ApplicationAdminPermission} for the + * corresponding application. * - * @throws IllegalStateException - * if the application handle is unregistered + * @throws IllegalStateException if the application handle is unregistered */ public final void destroy() { if (STOPPING.equals(getState())) return; SecurityManager sm = System.getSecurityManager(); if (sm != null) - sm.checkPermission(new ApplicationAdminPermission(getApplicationDescriptor(), ApplicationAdminPermission.LIFECYCLE_ACTION)); + sm.checkPermission(new ApplicationAdminPermission(getApplicationDescriptor(), + ApplicationAdminPermission.LIFECYCLE_ACTION)); destroySpecific(); } /** - * Called by the destroy() method to perform application model specific - * steps to stop and destroy an application instance safely. + * Called by the destroy() method to perform application model specific steps to + * stop and destroy an application instance safely. * - * @throws IllegalStateException - * if the application handle is unregistered + * @throws IllegalStateException if the application handle is unregistered */ protected abstract void destroySpecific(); diff --git a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ScheduledApplication.java b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ScheduledApplication.java index 4e7a9605b5c..3d65179a40b 100644 --- a/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ScheduledApplication.java +++ b/bundles/org.eclipse.equinox.app/osgi/org/osgi/service/application/ScheduledApplication.java @@ -24,8 +24,8 @@ * specified event is fired a new instance must be launched. Note that launching * operation may fail because e.g. the application is locked. *

    - * Each {@code ScheduledApplication} instance has an identifier which is - * unique within the scope of the application being scheduled. + * Each {@code ScheduledApplication} instance has an identifier which is unique + * within the scope of the application being scheduled. *

    * {@code ScheduledApplication} instances are registered as services. The * {@link #APPLICATION_PID} service property contains the PID of the application @@ -35,86 +35,85 @@ * @version $Id$ */ public interface ScheduledApplication { - + /** * The property key for the identifier of the application being scheduled. */ public static final String APPLICATION_PID = ApplicationDescriptor.APPLICATION_PID; - + /** - * The property key for the schedule identifier. The identifier is unique - * within the scope of the application being scheduled. + * The property key for the schedule identifier. The identifier is unique within + * the scope of the application being scheduled. */ public static final String SCHEDULE_ID = "schedule.id"; - + /** - * The key for the startup argument used to pass the event object that - * triggered the schedule to launch the application instance. - * The event is passed in a {@link java.security.GuardedObject} - * protected by the corresponding + * The key for the startup argument used to pass the event object that triggered + * the schedule to launch the application instance. The event is passed in a + * {@link java.security.GuardedObject} protected by the corresponding * {@link org.osgi.service.event.TopicPermission}. */ public static final String TRIGGERING_EVENT = "org.osgi.triggeringevent"; - + /** - * The topic name for the virtual timer topic. Time based schedules - * should be created using this topic. + * The topic name for the virtual timer topic. Time based schedules should be + * created using this topic. */ public static final String TIMER_TOPIC = "org/osgi/application/timer"; - + /** * The name of the year attribute of a virtual timer event. The value is * defined by {@link java.util.Calendar#YEAR}. */ public static final String YEAR = "year"; - + /** * The name of the month attribute of a virtual timer event. The value is * defined by {@link java.util.Calendar#MONTH}. */ public static final String MONTH = "month"; - + /** - * The name of the day of month attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#DAY_OF_MONTH}. + * The name of the day of month attribute of a virtual timer event. The + * value is defined by {@link java.util.Calendar#DAY_OF_MONTH}. */ public static final String DAY_OF_MONTH = "day_of_month"; - + /** - * The name of the day of week attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#DAY_OF_WEEK}. + * The name of the day of week attribute of a virtual timer event. The + * value is defined by {@link java.util.Calendar#DAY_OF_WEEK}. */ public static final String DAY_OF_WEEK = "day_of_week"; - + /** - * The name of the hour of day attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#HOUR_OF_DAY}. + * The name of the hour of day attribute of a virtual timer event. The + * value is defined by {@link java.util.Calendar#HOUR_OF_DAY}. */ public static final String HOUR_OF_DAY = "hour_of_day"; - + /** - * The name of the minute attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#MINUTE}. + * The name of the minute attribute of a virtual timer event. The value + * is defined by {@link java.util.Calendar#MINUTE}. */ public static final String MINUTE = "minute"; - - + /** - * Returns the identifier of this schedule. The identifier is unique within - * the scope of the application that the schedule is related to. + * Returns the identifier of this schedule. The identifier is unique within the + * scope of the application that the schedule is related to. + * * @return the identifier of this schedule * */ public String getScheduleId(); /** - * Queries the topic of the triggering event. The topic may contain a - * trailing asterisk as wildcard. + * Queries the topic of the triggering event. The topic may contain a trailing + * asterisk as wildcard. * * @return the topic of the triggering event * - * @throws IllegalStateException - * if the scheduled application service is unregistered + * @throws IllegalStateException if the scheduled application service is + * unregistered */ public String getTopic(); @@ -123,8 +122,8 @@ public interface ScheduledApplication { * * @return the event filter for triggering event * - * @throws IllegalStateException - * if the scheduled application service is unregistered + * @throws IllegalStateException if the scheduled application service is + * unregistered */ public String getEventFilter(); @@ -133,8 +132,8 @@ public interface ScheduledApplication { * * @return true if the schedule is recurring, otherwise returns false * - * @throws IllegalStateException - * if the scheduled application service is unregistered + * @throws IllegalStateException if the scheduled application service is + * unregistered */ public boolean isRecurring(); @@ -142,35 +141,34 @@ public interface ScheduledApplication { * Retrieves the ApplicationDescriptor which represents the application and * necessary for launching. * - * @return the application descriptor that - * represents the scheduled application + * @return the application descriptor that represents the scheduled application * - * @throws IllegalStateException - * if the scheduled application service is unregistered + * @throws IllegalStateException if the scheduled application service is + * unregistered */ public ApplicationDescriptor getApplicationDescriptor(); /** - * Queries the startup arguments specified when the application was - * scheduled. The method returns a copy of the arguments, it is not possible - * to modify the arguments after scheduling. + * Queries the startup arguments specified when the application was scheduled. + * The method returns a copy of the arguments, it is not possible to modify the + * arguments after scheduling. * - * @return the startup arguments of the scheduled application. It may be - * null if null argument was specified. + * @return the startup arguments of the scheduled application. It may be null if + * null argument was specified. * - * @throws IllegalStateException - * if the scheduled application service is unregistered + * @throws IllegalStateException if the scheduled application service is + * unregistered */ public Map getArguments(); /** * Cancels this schedule of the application. * - * @throws SecurityException - * if the caller doesn't have "schedule" - * ApplicationAdminPermission for the scheduled application. - * @throws IllegalStateException - * if the scheduled application service is unregistered + * @throws SecurityException if the caller doesn't have "schedule" + * ApplicationAdminPermission for the scheduled + * application. + * @throws IllegalStateException if the scheduled application service is + * unregistered */ public void remove(); } diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IApplication.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IApplication.java index 59c8a93ddf3..08c257f8f80 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IApplication.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IApplication.java @@ -15,9 +15,10 @@ package org.eclipse.equinox.app; /** - * Bootstrap type for an application. An IApplication represent executable - * entry points into an application. An IApplication can be configured into - * the Platform's org.eclipse.core.runtime.applications extension-point. + * Bootstrap type for an application. An IApplication represent executable entry + * points into an application. An IApplication can be configured into the + * Platform's org.eclipse.core.runtime.applications + * extension-point. * *

    * Clients may implement this interface. @@ -38,28 +39,32 @@ public interface IApplication { public static final Integer EXIT_RESTART = Integer.valueOf(23); /** - * Exit object requesting that the command passed back be executed. Typically - * this is used to relaunch Eclipse with different command line arguments. When the executable is - * relaunched the command line will be retrieved from the - * {@link IApplicationContext#EXIT_DATA_PROPERTY eclipse.exitdata} system property. + * Exit object requesting that the command passed back be executed. Typically + * this is used to relaunch Eclipse with different command line arguments. When + * the executable is relaunched the command line will be retrieved from the + * {@link IApplicationContext#EXIT_DATA_PROPERTY eclipse.exitdata} system + * property. */ public static final Integer EXIT_RELAUNCH = Integer.valueOf(24); /** - * Starts this application with the given context and returns a result. The content of - * the context is unchecked and should conform to the expectations of the application being - * invoked. This method can return the value {@link IApplicationContext#EXIT_ASYNC_RESULT} if - * the application will deliver its results asynchronously with the - * {@link IApplicationContext#setResult(Object, IApplication)} method; otherwise this method must not exit - * until the application is finished and is ready to exit. + * Starts this application with the given context and returns a result. The + * content of the context is unchecked and should conform to the expectations of + * the application being invoked. This method can return the value + * {@link IApplicationContext#EXIT_ASYNC_RESULT} if the application will deliver + * its results asynchronously with the + * {@link IApplicationContext#setResult(Object, IApplication)} method; otherwise + * this method must not exit until the application is finished and is ready to + * exit. *

    - * Applications can return any object they like. If an Integer is returned - * it is treated as the program exit code if Eclipse is exiting. + * Applications can return any object they like. If an Integer is + * returned it is treated as the program exit code if Eclipse is exiting. *

    *

    - * Note: This method is called by the platform; it is not intended - * to be called directly by clients. + * Note: This method is called by the platform; it is not intended to be called + * directly by clients. *

    + * * @return the return value of the application * @see #EXIT_OK * @see #EXIT_RESTART @@ -71,16 +76,17 @@ public interface IApplication { public Object start(IApplicationContext context) throws Exception; /** - * Forces this running application to exit. This method should wait until the - * running application is ready to exit. The {@link #start(IApplicationContext)} - * should already have exited or should exit very soon after this method exits

    + * Forces this running application to exit. This method should wait until the + * running application is ready to exit. The {@link #start(IApplicationContext)} + * should already have exited or should exit very soon after this method exits + *

    * - * This method is only called to force an application to exit. - * This method will not be called if an application exits normally from - * the {@link #start(IApplicationContext)} method. + * This method is only called to force an application to exit. This method will + * not be called if an application exits normally from the + * {@link #start(IApplicationContext)} method. *

    - * Note: This method is called by the platform; it is not intended - * to be called directly by clients. + * Note: This method is called by the platform; it is not intended to be called + * directly by clients. *

    */ public void stop(); diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IApplicationContext.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IApplicationContext.java index 40441b29adb..da07fe976a2 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IApplicationContext.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IApplicationContext.java @@ -23,6 +23,7 @@ *

    * This interface is not intended to be implemented by clients. *

    + * * @since 1.0 * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. @@ -30,97 +31,107 @@ public interface IApplicationContext { /** - * A system property that may be set by an application to specify exit data - * for the application. The value of the property must be a String. + * A system property that may be set by an application to specify exit data for + * the application. The value of the property must be a String. *

    - * Typically applications do not need to set this property. If an error is detected - * while launching or running an application then the launcher will set this property - * automatically in order to display a message to the end user. An application may - * set this property for the following reasons: + * Typically applications do not need to set this property. If an error is + * detected while launching or running an application then the launcher will set + * this property automatically in order to display a message to the end user. An + * application may set this property for the following reasons: *

    *
      - *
    • To provide the command line arguments to relaunch the eclipse platform. See - * {@link IApplication#EXIT_RELAUNCH}
    • - *
    • To provide an error message that will be displayed to the end user. This will - * cause an error dialog to be displayed to the user, this option should not be used - * by headless applications.
    • - *
    • To suppress all error dialogs displayed by the launcher this property can be - * set to the empty String. This is useful for - * headless applications where error dialogs must never be displayed.
    • + *
    • To provide the command line arguments to relaunch the eclipse platform. + * See {@link IApplication#EXIT_RELAUNCH}
    • + *
    • To provide an error message that will be displayed to the end user. This + * will cause an error dialog to be displayed to the user, this option should + * not be used by headless applications.
    • + *
    • To suppress all error dialogs displayed by the launcher this property can + * be set to the empty String. This is useful for headless + * applications where error dialogs must never be displayed.
    • *
    + * * @since 1.3 */ public static final String EXIT_DATA_PROPERTY = "eclipse.exitdata"; //$NON-NLS-1$ /** - * A key used to store arguments for the application. The content of this argument - * is unchecked and should conform to the expectations of the application being invoked. - * Typically this is a String array. + * A key used to store arguments for the application. The content of this + * argument is unchecked and should conform to the expectations of the + * application being invoked. Typically this is a String array. *

    * - * If the map used to launch an application {@link ApplicationDescriptor#launch(Map)} does - * not contain a value for this key then command line arguments used to launch - * the platform are set in the arguments of the application context. + * If the map used to launch an application + * {@link ApplicationDescriptor#launch(Map)} does not contain a value for this + * key then command line arguments used to launch the platform are set in the + * arguments of the application context. */ public static final String APPLICATION_ARGS = "application.args"; //$NON-NLS-1$ /** - * Exit object that indicates the application result will be delivered asynchronously. - * This object must be returned by the method {@link IApplication#start(IApplicationContext)} - * for applications which deliver a result asynchronously with the method + * Exit object that indicates the application result will be delivered + * asynchronously. This object must be returned by the method + * {@link IApplication#start(IApplicationContext)} for applications which + * deliver a result asynchronously with the method * {@link IApplicationContext#setResult(Object, IApplication)}. + * * @since 1.3 */ public static final Object EXIT_ASYNC_RESULT = new Object(); /** - * The arguments used for the application. The arguments from - * {@link ApplicationDescriptor#launch(Map)} are used as the arguments - * for this context when an application is launched. + * The arguments used for the application. The arguments from + * {@link ApplicationDescriptor#launch(Map)} are used as the arguments for this + * context when an application is launched. * * @return a map of application arguments. */ public Map getArguments(); /** - * This method should be called once the application is completely initialized and running. - * This method will perform certain operations that are needed once an application is running. - * One example is bringing down a splash screen if it exists. + * This method should be called once the application is completely initialized + * and running. This method will perform certain operations that are needed once + * an application is running. One example is bringing down a splash screen if it + * exists. */ public void applicationRunning(); /** - * Returns the application associated with this application context. This information - * is used to guide the runtime as to what application extension to create and execute. + * Returns the application associated with this application context. This + * information is used to guide the runtime as to what application extension to + * create and execute. * * @return this product's application or null if none */ public String getBrandingApplication(); /** - * Returns the name of the product associated with this application context. - * The name is typically used in the title bar of UI windows. + * Returns the name of the product associated with this application context. The + * name is typically used in the title bar of UI windows. * * @return the name of the product or null if none */ public String getBrandingName(); /** - * Returns the text description of the product associated with this application context. + * Returns the text description of the product associated with this application + * context. * * @return the description of the product or null if none */ public String getBrandingDescription(); - /** Returns the unique product id of the product associated with this application context. + /** + * Returns the unique product id of the product associated with this application + * context. * * @return the id of the product */ public String getBrandingId(); /** - * Returns the property with the given key of the product associated with this application context. - * null is returned if there is no such key/value pair. + * Returns the property with the given key of the product associated with this + * application context. null is returned if there is no such + * key/value pair. * * @param key the name of the property to return * @return the value associated with the given key or null if none @@ -128,35 +139,41 @@ public interface IApplicationContext { public String getBrandingProperty(String key); /** - * Returns the bundle which is responsible for the definition of the product associated with - * this application context. - * Typically this is used as a base for searching for images and other files - * that are needed in presenting the product. + * Returns the bundle which is responsible for the definition of the product + * associated with this application context. Typically this is used as a base + * for searching for images and other files that are needed in presenting the + * product. * * @return the bundle which defines the product or null if none */ public Bundle getBrandingBundle(); /** - * Sets the result of the application asynchronously. This method can only be used - * after the application's {@link IApplication#start(IApplicationContext) start} - * method has returned the value of {@link IApplicationContext#EXIT_ASYNC_RESULT}. + * Sets the result of the application asynchronously. This method can only be + * used after the application's {@link IApplication#start(IApplicationContext) + * start} method has returned the value of + * {@link IApplicationContext#EXIT_ASYNC_RESULT}. *

    - * The specified application must be the same application instance which is - * associated with this application context. In other word the application instance - * for which {@link IApplication#start(IApplicationContext)} was called with this - * application context; otherwise an IllegalArgumentException is - * thrown. + * The specified application must be the same application instance which is + * associated with this application context. In other word the application + * instance for which {@link IApplication#start(IApplicationContext)} was called + * with this application context; otherwise an + * IllegalArgumentException is thrown. *

    * - * @param result the result value for the application. May be null. - * @param application the application instance associated with this application context - * @throws IllegalStateException if {@link IApplicationContext#EXIT_ASYNC_RESULT} was - * not returned by the application's {@link IApplication#start(IApplicationContext) start} - * method or if the result has already been set for this application context. - * @throws IllegalArgumentException if the specified application is not the same - * application instance associated with this application context. - * + * @param result the result value for the application. May be null. + * @param application the application instance associated with this application + * context + * @throws IllegalStateException if + * {@link IApplicationContext#EXIT_ASYNC_RESULT} + * was not returned by the application's + * {@link IApplication#start(IApplicationContext) + * start} method or if the result has already + * been set for this application context. + * @throws IllegalArgumentException if the specified application is not the same + * application instance associated with this + * application context. + * * * @since 1.3 */ diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/Activator.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/Activator.java index 9834f8b20bc..ce680190c4d 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/Activator.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/Activator.java @@ -32,8 +32,8 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { public static final String PI_APP = "org.eclipse.equinox.app"; //$NON-NLS-1$ public static boolean DEBUG = false; private volatile static BundleContext _context; - // PackageAdmin is a system service that never goes away as long - // as the framework is active. No need to track it!! + // PackageAdmin is a system service that never goes away as long + // as the framework is active. No need to track it!! private volatile static PackageAdmin _packageAdmin; private volatile static EclipseAppContainer container; // tracks the FrameworkLog service @@ -45,7 +45,8 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { @Override public void start(BundleContext bc) { _context = bc; - // doing simple get service here because we expect the PackageAdmin service to always be available + // doing simple get service here because we expect the PackageAdmin service to + // always be available ServiceReference ref = bc.getServiceReference(PackageAdmin.class.getName()); if (ref != null) _packageAdmin = (PackageAdmin) bc.getService(ref); @@ -120,7 +121,8 @@ private void processCommandLineArgs(BundleContext bc) { public Object addingService(ServiceReference reference) { BundleContext context = _context; if (context == null) - return null; // really should never happen since we close the tracker before nulling out context + return null; // really should never happen since we close the tracker before nulling out + // context Object service = null; EclipseAppContainer startContainer = null; synchronized (this) { @@ -135,7 +137,8 @@ public Object addingService(ServiceReference reference) { startContainer = container; } } - // must not start the container while holding a lock because this will register additional services + // must not start the container while holding a lock because this will register + // additional services if (startContainer != null) { startContainer.start(); return service; @@ -168,7 +171,8 @@ public void removedService(ServiceReference reference, Object service) { currentContainer.stop(); } - // helper used to protect callers from permission checks when opening service trackers + // helper used to protect callers from permission checks when opening service + // trackers static void openTracker(final ServiceTracker tracker, final boolean allServices) { if (System.getSecurityManager() == null) tracker.open(allServices); @@ -224,7 +228,7 @@ static Bundle getBundle(IContributor contributor) { Bundle[] bundles = packageAdmin.getBundles(contributor.getName(), null); if (bundles == null) return null; - //Return the first bundle that is not installed or uninstalled + // Return the first bundle that is not installed or uninstalled for (Bundle bundle : bundles) { if ((bundle.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) { return bundle; diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AnyThreadAppLauncher.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AnyThreadAppLauncher.java index ff89f652a93..0f850bb909a 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AnyThreadAppLauncher.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AnyThreadAppLauncher.java @@ -29,7 +29,8 @@ public void run() { // pasing null will cause EclipseAppHandle to get the correct arguments appHandle.run(null); } catch (Throwable e) { - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.ERROR, 0, e.getMessage(), 0, e, null)); + Activator.log( + new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.ERROR, 0, e.getMessage(), 0, e, null)); } } diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppCommands.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppCommands.java index f9468122a25..2d0ad3d918e 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppCommands.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppCommands.java @@ -30,7 +30,8 @@ public class AppCommands implements CommandProvider { private final static String NEW_LINE = "\r\n"; //$NON-NLS-1$ private final static String TAB = "\t"; //$NON-NLS-1$ - // holds the mappings from command name to command arguments and command description + // holds the mappings from command name to command arguments and command + // description private Map commandsHelp = null; private static AppCommands instance; @@ -95,8 +96,8 @@ public String getHelp() { } /* - * This method either returns the help message for a particular command, - * or returns the help messages for all commands (if commandName is null) + * This method either returns the help message for a particular command, or + * returns the help messages for all commands (if commandName is null) */ private String getHelp(String commandName) { StringBuffer sb = new StringBuffer(); @@ -124,17 +125,23 @@ private String getHelp(String commandName) { private void initializeCommandsHelp() { commandsHelp = new LinkedHashMap<>(); - commandsHelp.put("activeApps", new String[] {Messages.console_help_activeapps_description}); //$NON-NLS-1$ - commandsHelp.put("apps", new String[] {Messages.console_help_apps_description}); //$NON-NLS-1$ - commandsHelp.put("lockApp", new String[] {Messages.console_help_arguments, Messages.console_help_lockapp_description}); //$NON-NLS-1$ - commandsHelp.put("schedApp", new String[] {Messages.console_help_schedapp_arguments, Messages.console_help_schedapp_description}); //$NON-NLS-1$ - commandsHelp.put("startApp", new String[] {Messages.console_help_arguments, Messages.console_help_startapp_description}); //$NON-NLS-1$ - commandsHelp.put("stopApp", new String[] {Messages.console_help_arguments, Messages.console_help_stopapp_description}); //$NON-NLS-1$ - commandsHelp.put("unlockApp", new String[] {Messages.console_help_arguments, Messages.console_help_unlockapp_description}); //$NON-NLS-1$ - commandsHelp.put("unschedApp", new String[] {Messages.console_help_arguments, Messages.console_help_unschedapp_description}); //$NON-NLS-1$ + commandsHelp.put("activeApps", new String[] { Messages.console_help_activeapps_description }); //$NON-NLS-1$ + commandsHelp.put("apps", new String[] { Messages.console_help_apps_description }); //$NON-NLS-1$ + commandsHelp.put("lockApp", //$NON-NLS-1$ + new String[] { Messages.console_help_arguments, Messages.console_help_lockapp_description }); + commandsHelp.put("schedApp", //$NON-NLS-1$ + new String[] { Messages.console_help_schedapp_arguments, Messages.console_help_schedapp_description }); + commandsHelp.put("startApp", //$NON-NLS-1$ + new String[] { Messages.console_help_arguments, Messages.console_help_startapp_description }); + commandsHelp.put("stopApp", //$NON-NLS-1$ + new String[] { Messages.console_help_arguments, Messages.console_help_stopapp_description }); + commandsHelp.put("unlockApp", //$NON-NLS-1$ + new String[] { Messages.console_help_arguments, Messages.console_help_unlockapp_description }); + commandsHelp.put("unschedApp", //$NON-NLS-1$ + new String[] { Messages.console_help_arguments, Messages.console_help_unschedapp_description }); } - /** Private helper method for getHelp. Formats the help headers. */ + /** Private helper method for getHelp. Formats the help headers. */ private void addHeader(String header, StringBuffer help) { help.append("---"); //$NON-NLS-1$ help.append(header); @@ -142,7 +149,7 @@ private void addHeader(String header, StringBuffer help) { help.append(NEW_LINE); } - /** Private helper method for getHelp. Formats the command descriptions. */ + /** Private helper method for getHelp. Formats the command descriptions. */ private void addCommand(String command, String description, StringBuffer help) { help.append(TAB); help.append(command); @@ -151,7 +158,10 @@ private void addCommand(String command, String description, StringBuffer help) { help.append(NEW_LINE); } - /** Private helper method for getHelp. Formats the command descriptions with command arguments. */ + /** + * Private helper method for getHelp. Formats the command descriptions with + * command arguments. + */ private void addCommand(String command, String parameters, String description, StringBuffer help) { help.append(TAB); help.append(command); @@ -162,7 +172,10 @@ private void addCommand(String command, String parameters, String description, S help.append(NEW_LINE); } - /** Private helper method for getHelp. According to its arguments chooses which one of the above addCommand methods to use. */ + /** + * Private helper method for getHelp. According to its arguments chooses which + * one of the above addCommand methods to use. + */ private void addCommand(String command, String[] attributes, StringBuffer help) { if (attributes.length == 1) { addCommand(command, attributes[0], help); @@ -190,18 +203,20 @@ public void _apps(CommandInterpreter intp) { String application = (String) app.getProperty(ApplicationDescriptor.APPLICATION_PID); intp.print(application); - if (getApplication(applicationHandles.getServiceReferences(), application, ApplicationHandle.APPLICATION_DESCRIPTOR, true) != null) - intp.print(" [running]"); //$NON-NLS-1$ + if (getApplication(applicationHandles.getServiceReferences(), application, + ApplicationHandle.APPLICATION_DESCRIPTOR, true) != null) + intp.print(" [running]"); //$NON-NLS-1$ - if (getApplication(scheduledApplications.getServiceReferences(), application, ScheduledApplication.APPLICATION_PID, true) != null) - intp.print(" [scheduled]"); //$NON-NLS-1$ + if (getApplication(scheduledApplications.getServiceReferences(), application, + ScheduledApplication.APPLICATION_PID, true) != null) + intp.print(" [scheduled]"); //$NON-NLS-1$ if (!launchableApp.match(getServiceProps(app))) { - intp.print(" [not launchable]"); //$NON-NLS-1$ + intp.print(" [not launchable]"); //$NON-NLS-1$ } else { - intp.print(" [launchable]"); //$NON-NLS-1$ + intp.print(" [launchable]"); //$NON-NLS-1$ } if (lockedApp.match(getServiceProps(app))) { - intp.print(" [locked]"); //$NON-NLS-1$ + intp.print(" [locked]"); //$NON-NLS-1$ } intp.println(); } @@ -221,7 +236,8 @@ public void _activeApps(CommandInterpreter intp) { } } - private ServiceReference getApplication(ServiceReference[] apps, String targetId, String idKey, boolean perfectMatch) { + private ServiceReference getApplication(ServiceReference[] apps, String targetId, String idKey, + boolean perfectMatch) { if (apps == null || targetId == null) return null; @@ -245,7 +261,8 @@ private ServiceReference getApplication(ServiceReference[] apps, String targetId public void _startApp(CommandInterpreter intp) throws Exception { String appId = intp.nextArgument(); - ServiceReference application = getApplication(applicationDescriptors.getServiceReferences(), appId, ApplicationDescriptor.APPLICATION_PID, false); + ServiceReference application = getApplication(applicationDescriptors.getServiceReferences(), appId, + ApplicationDescriptor.APPLICATION_PID, false); if (application == null) intp.println("\"" + appId + "\" does not exist or is ambigous."); //$NON-NLS-1$ //$NON-NLS-2$ else { @@ -258,7 +275,7 @@ public void _startApp(CommandInterpreter intp) throws Exception { HashMap launchArgs = new HashMap<>(1); if (args != null) launchArgs.put(IApplicationContext.APPLICATION_ARGS, args); - ApplicationDescriptor appDesc = (context. getService(application)); + ApplicationDescriptor appDesc = (context.getService(application)); ApplicationHandle handle = appDesc.launch(launchArgs); intp.println("Launched application instance: " + handle.getInstanceId()); //$NON-NLS-1$ } finally { @@ -271,9 +288,11 @@ public void _startApp(CommandInterpreter intp) throws Exception { public void _stopApp(CommandInterpreter intp) throws Exception { String appId = intp.nextArgument(); // first search for the application instance id - ServiceReference application = getApplication(applicationHandles.getServiceReferences(), appId, ApplicationHandle.APPLICATION_PID, false); + ServiceReference application = getApplication(applicationHandles.getServiceReferences(), appId, + ApplicationHandle.APPLICATION_PID, false); if (application == null) - application = getApplication(applicationHandles.getServiceReferences(), appId, ApplicationHandle.APPLICATION_DESCRIPTOR, false); + application = getApplication(applicationHandles.getServiceReferences(), appId, + ApplicationHandle.APPLICATION_DESCRIPTOR, false); if (application == null) intp.println("\"" + appId + "\" does not exist, is not running or is ambigous."); //$NON-NLS-1$ //$NON-NLS-2$ else { @@ -286,7 +305,8 @@ public void _stopApp(CommandInterpreter intp) throws Exception { context.ungetService(application); } } else { - intp.println("Application instance is already stopping: " + application.getProperty(ApplicationHandle.APPLICATION_PID)); //$NON-NLS-1$ + intp.println("Application instance is already stopping: " //$NON-NLS-1$ + + application.getProperty(ApplicationHandle.APPLICATION_PID)); } return; } @@ -294,7 +314,8 @@ public void _stopApp(CommandInterpreter intp) throws Exception { public void _lockApp(CommandInterpreter intp) throws Exception { String appId = intp.nextArgument(); - ServiceReference application = getApplication(applicationDescriptors.getServiceReferences(), appId, ApplicationDescriptor.APPLICATION_PID, false); + ServiceReference application = getApplication(applicationDescriptors.getServiceReferences(), appId, + ApplicationDescriptor.APPLICATION_PID, false); if (application == null) intp.println("\"" + appId + "\" does not exist or is ambigous."); //$NON-NLS-1$ //$NON-NLS-2$ else { @@ -311,7 +332,8 @@ public void _lockApp(CommandInterpreter intp) throws Exception { public void _unlockApp(CommandInterpreter intp) throws Exception { String appId = intp.nextArgument(); - ServiceReference application = getApplication(applicationDescriptors.getServiceReferences(), appId, ApplicationDescriptor.APPLICATION_PID, false); + ServiceReference application = getApplication(applicationDescriptors.getServiceReferences(), appId, + ApplicationDescriptor.APPLICATION_PID, false); if (application == null) intp.println("\"" + appId + "\" does not exist or is ambigous."); //$NON-NLS-1$ //$NON-NLS-2$ else { @@ -328,7 +350,8 @@ public void _unlockApp(CommandInterpreter intp) throws Exception { public void _schedApp(CommandInterpreter intp) throws Exception { String appId = intp.nextArgument(); - ServiceReference application = getApplication(applicationDescriptors.getServiceReferences(), appId, ApplicationDescriptor.APPLICATION_PID, false); + ServiceReference application = getApplication(applicationDescriptors.getServiceReferences(), appId, + ApplicationDescriptor.APPLICATION_PID, false); if (application == null) intp.println("\"" + appId + "\" does not exist or is ambigous."); //$NON-NLS-1$ //$NON-NLS-2$ else { @@ -347,14 +370,16 @@ public void _schedApp(CommandInterpreter intp) throws Exception { public void _unschedApp(CommandInterpreter intp) throws Exception { String appId = intp.nextArgument(); - ServiceReference application = getApplication(scheduledApplications.getServiceReferences(), appId, ScheduledApplication.APPLICATION_PID, false); + ServiceReference application = getApplication(scheduledApplications.getServiceReferences(), appId, + ScheduledApplication.APPLICATION_PID, false); if (application == null) intp.println("\"" + appId + "\" does not exist or is ambigous."); //$NON-NLS-1$ //$NON-NLS-2$ else { try { ScheduledApplication schedApp = (ScheduledApplication) context.getService(application); schedApp.remove(); - intp.println("Unscheduled application: " + application.getProperty(ApplicationDescriptor.APPLICATION_PID)); //$NON-NLS-1$ + intp.println( + "Unscheduled application: " + application.getProperty(ApplicationDescriptor.APPLICATION_PID)); //$NON-NLS-1$ } finally { context.ungetService(application); } @@ -365,7 +390,8 @@ public void _unschedApp(CommandInterpreter intp) throws Exception { * Handles the help command * * @param intp - * @return description for a particular command or false if there is no command with the specified name + * @return description for a particular command or false if there is no command + * with the specified name */ public Object _help(CommandInterpreter intp) { String commandName = intp.nextArgument(); diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java index 4a3bf00bc7a..027bb310183 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java @@ -28,7 +28,7 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; /** - * Manages all persistent data for ApplicationDescriptors (lock status, + * Manages all persistent data for ApplicationDescriptors (lock status, * scheduled applications etc.) */ public class AppPersistence implements ServiceTrackerCustomizer { @@ -78,7 +78,7 @@ private static void initConfiguration() { try { filter = context.createFilter(FILTER_PREFIX + PROP_CONFIG_AREA + "))"); //$NON-NLS-1$ } catch (InvalidSyntaxException e) { - // ignore this. It should never happen as we have tested the above format. + // ignore this. It should never happen as we have tested the above format. } configTracker = new ServiceTracker(context, filter, new AppPersistence()); configTracker.open(); @@ -91,7 +91,9 @@ private static void closeConfiguration() { } /** - * Used by {@link ApplicationDescriptor} to determine if an application is locked. + * Used by {@link ApplicationDescriptor} to determine if an application is + * locked. + * * @param desc the application descriptor * @return true if the application is persistently locked. */ @@ -102,8 +104,10 @@ public static boolean isLocked(ApplicationDescriptor desc) { } /** - * Used by {@link ApplicationDescriptor} to determine lock and unlock and application. - * @param desc the application descriptor + * Used by {@link ApplicationDescriptor} to determine lock and unlock and + * application. + * + * @param desc the application descriptor * @param locked the locked flag */ public static void saveLock(ApplicationDescriptor desc, boolean locked) { @@ -134,7 +138,9 @@ static void removeScheduledApp(EclipseScheduledApplication scheduledApp) { } /** - * Used by {@link ScheduledApplication} to persistently schedule an application launch + * Used by {@link ScheduledApplication} to persistently schedule an application + * launch + * * @param descriptor * @param arguments * @param topic @@ -142,16 +148,20 @@ static void removeScheduledApp(EclipseScheduledApplication scheduledApp) { * @param recurring * @return the scheduled application * @throws InvalidSyntaxException - * @throws ApplicationException + * @throws ApplicationException */ - public static ScheduledApplication addScheduledApp(ApplicationDescriptor descriptor, String scheduleId, Map arguments, String topic, String eventFilter, boolean recurring) throws InvalidSyntaxException, ApplicationException { + public static ScheduledApplication addScheduledApp(ApplicationDescriptor descriptor, String scheduleId, + Map arguments, String topic, String eventFilter, boolean recurring) + throws InvalidSyntaxException, ApplicationException { if (!scheduling && !checkSchedulingSupport()) - throw new ApplicationException(ApplicationException.APPLICATION_SCHEDULING_FAILED, "Cannot support scheduling without org.osgi.service.event package"); //$NON-NLS-1$ + throw new ApplicationException(ApplicationException.APPLICATION_SCHEDULING_FAILED, + "Cannot support scheduling without org.osgi.service.event package"); //$NON-NLS-1$ // check the event filter for correct syntax context.createFilter(eventFilter); EclipseScheduledApplication result; synchronized (scheduledApps) { - result = new EclipseScheduledApplication(context, getNextScheduledID(scheduleId), descriptor.getApplicationId(), arguments, topic, eventFilter, recurring); + result = new EclipseScheduledApplication(context, getNextScheduledID(scheduleId), + descriptor.getApplicationId(), arguments, topic, eventFilter, recurring); addScheduledApp(result); saveData(FILE_APPSCHEDULED); } @@ -170,19 +180,21 @@ private static void addScheduledApp(EclipseScheduledApplication scheduledApp) { scheduledApps.put(scheduledApp.getScheduleId(), scheduledApp); Hashtable serviceProps = new Hashtable<>(); if (scheduledApp.getTopic() != null) - serviceProps.put(EventConstants.EVENT_TOPIC, new String[] {scheduledApp.getTopic()}); + serviceProps.put(EventConstants.EVENT_TOPIC, new String[] { scheduledApp.getTopic() }); if (scheduledApp.getEventFilter() != null) serviceProps.put(EventConstants.EVENT_FILTER, scheduledApp.getEventFilter()); serviceProps.put(ScheduledApplication.SCHEDULE_ID, scheduledApp.getScheduleId()); serviceProps.put(ScheduledApplication.APPLICATION_PID, scheduledApp.getAppPid()); - ServiceRegistration sr = context.registerService(new String[] {ScheduledApplication.class.getName(), EVENT_HANDLER}, scheduledApp, serviceProps); + ServiceRegistration sr = context.registerService( + new String[] { ScheduledApplication.class.getName(), EVENT_HANDLER }, scheduledApp, serviceProps); scheduledApp.setServiceRegistration(sr); } private static String getNextScheduledID(String scheduledId) throws ApplicationException { if (scheduledId != null) { if (scheduledApps.get(scheduledId) != null) - throw new ApplicationException(ApplicationException.APPLICATION_DUPLICATE_SCHEDULE_ID, "Duplicate scheduled ID: " + scheduledId); //$NON-NLS-1$ + throw new ApplicationException(ApplicationException.APPLICATION_DUPLICATE_SCHEDULE_ID, + "Duplicate scheduled ID: " + scheduledId); //$NON-NLS-1$ return scheduledId; } if (nextScheduledID == Integer.MAX_VALUE) @@ -191,7 +203,8 @@ private static String getNextScheduledID(String scheduledId) throws ApplicationE while (scheduledApps.get(result) != null && nextScheduledID < Integer.MAX_VALUE) result = Integer.toString(nextScheduledID++); if (nextScheduledID == Integer.MAX_VALUE) - throw new ApplicationException(ApplicationException.APPLICATION_DUPLICATE_SCHEDULE_ID, "Maximum number of scheduled applications reached"); //$NON-NLS-1$ + throw new ApplicationException(ApplicationException.APPLICATION_DUPLICATE_SCHEDULE_ID, + "Maximum number of scheduled applications reached"); //$NON-NLS-1$ return result; } @@ -268,7 +281,8 @@ private static void loadSchedules(File schedulesData) throws IOException { String eventFilter = readString(in, false); boolean recurring = in.readBoolean(); Map args = (Map) in.readObject(); - EclipseScheduledApplication schedApp = new EclipseScheduledApplication(context, id, appPid, args, topic, eventFilter, recurring); + EclipseScheduledApplication schedApp = new EclipseScheduledApplication(context, id, appPid, args, topic, + eventFilter, recurring); addScheduledApp(schedApp); } } catch (InvalidSyntaxException | NoClassDefFoundError | ClassNotFoundException e) { @@ -286,9 +300,10 @@ private synchronized static void saveData(String fileName) { else if (FILE_APPSCHEDULED.equals(fileName)) saveSchedules(data); storageManager.lookup(fileName, true); - storageManager.update(new String[] {fileName}, new String[] {data.getName()}); + storageManager.update(new String[] { fileName }, new String[] { data.getName() }); } catch (IOException e) { - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.ERROR, 0, NLS.bind(Messages.persistence_error_saving, fileName), 0, e, null)); + Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.ERROR, 0, + NLS.bind(Messages.persistence_error_saving, fileName), 0, e, null)); } } @@ -350,7 +365,8 @@ public void run() { props.put(ScheduledApplication.MINUTE, Integer.valueOf(minute)); Event timerEvent = new Event(ScheduledApplication.TIMER_TOPIC, (Dictionary) props); EclipseScheduledApplication[] apps = null; - // poor mans implementation of dispatching events; the spec will not allow us to use event admin to dispatch the virtual timer events; boo!! + // poor mans implementation of dispatching events; the spec will not allow us to + // use event admin to dispatch the virtual timer events; boo!! synchronized (timerApps) { if (timerApps.size() == 0) continue; @@ -365,7 +381,8 @@ public void run() { } } catch (Throwable t) { String message = NLS.bind(Messages.scheduled_app_launch_error, app.getAppPid()); - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, t, null)); + Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, + 0, t, null)); } } } catch (InterruptedException e) { diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/CommandLineArgs.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/CommandLineArgs.java index c22f76c17e2..7afd50982f2 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/CommandLineArgs.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/CommandLineArgs.java @@ -20,7 +20,7 @@ public class CommandLineArgs { private static final String NO_PACKAGE_PREFIXES = "-noPackagePrefixes"; //$NON-NLS-1$ private static final String NO_UPDATE = "-noUpdate"; //$NON-NLS-1$ private static final String BOOT = "-boot"; //$NON-NLS-1$ - private static final String CLASSLOADER_PROPERTIES = "-classloaderProperties"; //$NON-NLS-1$ + private static final String CLASSLOADER_PROPERTIES = "-classloaderProperties"; //$NON-NLS-1$ private static final String PLUGINS = "-plugins"; //$NON-NLS-1$ private static final String FIRST_USE = "-firstUse"; //$NON-NLS-1$ private static final String NEW_UPDATES = "-newUpdates"; //$NON-NLS-1$ @@ -32,7 +32,7 @@ public class CommandLineArgs { // supported command line args private static final String PRODUCT = "-product"; //$NON-NLS-1$ private static final String FEATURE = "-feature"; //$NON-NLS-1$ - private static final String APPLICATION = "-application"; //$NON-NLS-1$ + private static final String APPLICATION = "-application"; //$NON-NLS-1$ // Command line args as seen by the Eclipse runtime. allArgs does NOT // include args consumed by the underlying framework (e.g., OSGi) @@ -49,7 +49,7 @@ static String[] processCommandLine(EnvironmentInfo envInfo) { return args; allArgs = args; int[] configArgs = new int[args.length]; - //need to initialize the first element to something that could not be an index. + // need to initialize the first element to something that could not be an index. configArgs[0] = -1; int configArgIndex = 0; for (int i = 0; i < args.length; i++) { @@ -74,13 +74,13 @@ static String[] processCommandLine(EnvironmentInfo envInfo) { if (args[i].equalsIgnoreCase(BOOT)) found = true; // ignored if (args[i].equalsIgnoreCase(KEYRING)) - found = true; // ignored + found = true; // ignored if (args[i].equalsIgnoreCase(PASSWORD)) found = true; // ignored if (args[i].equalsIgnoreCase(PLUGIN_CUSTOMIZATION)) found = true; // ignored - // done checking obsolete for args. Remember where an arg was found + // done checking obsolete for args. Remember where an arg was found if (found) { configArgs[configArgIndex++] = i; // check if the obsolete arg had a second param @@ -102,14 +102,14 @@ static String[] processCommandLine(EnvironmentInfo envInfo) { found = true; } - // look for the application to run. + // look for the application to run. if (args[i - 1].equalsIgnoreCase(APPLICATION)) { application = arg; envInfo.setProperty(EclipseAppContainer.PROP_ECLIPSE_APPLICATION, application); found = true; } - // done checking for args. Remember where an arg was found + // done checking for args. Remember where an arg was found if (found) { configArgs[configArgIndex++] = i - 1; configArgs[configArgIndex++] = i; diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/DefaultApplicationListener.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/DefaultApplicationListener.java index 399f594274e..87857e507e6 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/DefaultApplicationListener.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/DefaultApplicationListener.java @@ -23,10 +23,12 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; /** - * Listens for the default ApplicationHandle which run on any thread to be destroyed. This is used to force the main - * thread to wait while a default application runs on another thread. + * Listens for the default ApplicationHandle which run on any thread to be + * destroyed. This is used to force the main thread to wait while a default + * application runs on another thread. * - * A main threaded application may be launched using this class to launch the main threaded application. + * A main threaded application may be launched using this class to launch the + * main threaded application. */ public class DefaultApplicationListener implements ApplicationRunnable, ServiceTrackerCustomizer { private boolean running = true; // indicates the default application is running @@ -37,7 +39,7 @@ public class DefaultApplicationListener implements ApplicationRunnable, ServiceT public DefaultApplicationListener(EclipseAppHandle defaultApp) { ServiceReference defaultRef = defaultApp.getServiceReference(); if (defaultRef == null) { - // service has been unregistered; application has ended already, + // service has been unregistered; application has ended already, // save the result for latter result = defaultApp.waitForResult(100); handleTracker = null; @@ -64,19 +66,23 @@ public Object run(Object context) { return getResult(); // app has ended, return the result EclipseAppHandle anyThreadedDefaultApp = (EclipseAppHandle) handleTracker.getService(); if (anyThreadedDefaultApp != null) - // We now need to actual launch the application; this will run the application on another thread. + // We now need to actual launch the application; this will run the application + // on another thread. AnyThreadAppLauncher.launchEclipseApplication(anyThreadedDefaultApp); try { while (waitOnRunning()) { EclipseAppHandle mainHandle = getMainHandle(); if (mainHandle != null) { - // while we were waiting for the default application to end someone asked for a main threaded app to launch - // note that we cannot hold the this lock while launching a main threaded application + // while we were waiting for the default application to end someone asked for a + // main threaded app to launch + // note that we cannot hold the this lock while launching a main threaded + // application try { mainHandle.run(null); } catch (Throwable e) { String message = NLS.bind(Messages.application_error_starting, mainHandle.getInstanceId()); - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, e, null)); + Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, + e, null)); } unsetMainHandle(mainHandle); } @@ -118,7 +124,8 @@ public void stop() { handle.destroy(); } catch (Throwable t) { String message = NLS.bind(Messages.application_error_stopping, handle.getInstanceId()); - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, t, null)); + Activator.log( + new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, t, null)); } } } @@ -136,7 +143,8 @@ public void modifiedService(ServiceReference reference, Object service) { @Override synchronized public void removedService(ServiceReference reference, Object service) { running = false; - // only wait for 5 seconds; this may timeout if forcing an application to quit takes too long + // only wait for 5 seconds; this may timeout if forcing an application to quit + // takes too long // this should never timeout if the application exited normally. result = ((EclipseAppHandle) service).waitForResult(5000); EclipseAppHandle mainHandle = getMainHandle(); @@ -146,7 +154,8 @@ synchronized public void removedService(ServiceReference reference, Object servi mainHandle.destroy(); } catch (Throwable t) { String message = NLS.bind(Messages.application_error_stopping, mainHandle.getInstanceId()); - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, t, null)); + Activator.log( + new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, t, null)); } this.notify(); } diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppContainer.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppContainer.java index 5e5773a225e..7c2c89d83c5 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppContainer.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppContainer.java @@ -35,7 +35,8 @@ * container will discover installed eclipse applications and register the * appropriate ApplicatoinDescriptor service with the service registry. */ -public class EclipseAppContainer implements IRegistryEventListener, SynchronousBundleListener, ServiceTrackerCustomizer { +public class EclipseAppContainer + implements IRegistryEventListener, SynchronousBundleListener, ServiceTrackerCustomizer { private static final String PI_RUNTIME = "org.eclipse.core.runtime"; //$NON-NLS-1$ private static final String PT_APPLICATIONS = "applications"; //$NON-NLS-1$ private static final String PT_APP_VISIBLE = "visible"; //$NON-NLS-1$ @@ -72,7 +73,8 @@ public class EclipseAppContainer implements IRegistryEventListener, SynchronousB private boolean missingProductReported; /* @GuardedBy(lock) */ - final private Collection activeHandles = new ArrayList<>(); // the currently active application handles + final private Collection activeHandles = new ArrayList<>(); // the currently active application + // handles /* @GuardedBy(lock) */ private EclipseAppHandle activeMain; // the handle currently running on the main thread /* @GuardedBy(lock) */ @@ -83,7 +85,8 @@ public class EclipseAppContainer implements IRegistryEventListener, SynchronousB private HashMap> activeLimited; // Map of handles that have cardinality limits private String defaultAppId; private DefaultApplicationListener defaultAppListener; - private ParameterizedRunnable defaultMainThreadAppHandle; // holds the default app handle to be run on the main thread + private ParameterizedRunnable defaultMainThreadAppHandle; // holds the default app handle to be run on the main + // thread private volatile boolean missingApp = false; private MainApplicationLauncher missingAppLauncher; @@ -106,7 +109,8 @@ void start() { try { startDefaultApp(true); } catch (ApplicationException e) { - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.ERROR, 0, Messages.application_errorStartDefault, 0, e, null)); + Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.ERROR, 0, + Messages.application_errorStartDefault, 0, e, null)); } } } @@ -150,7 +154,8 @@ private EclipseAppDescriptor createAppDescriptor(IExtension appExtension) { return appDescriptor; // the appDescriptor does not exist for the app ID; create it IConfigurationElement[] configs = appExtension.getConfigurationElements(); - int flags = EclipseAppDescriptor.FLAG_CARD_SINGLETON_GLOGAL | EclipseAppDescriptor.FLAG_VISIBLE | EclipseAppDescriptor.FLAG_TYPE_MAIN_THREAD; + int flags = EclipseAppDescriptor.FLAG_CARD_SINGLETON_GLOGAL | EclipseAppDescriptor.FLAG_VISIBLE + | EclipseAppDescriptor.FLAG_TYPE_MAIN_THREAD; int cardinality = 0; if (configs.length > 0) { String sVisible = configs[0].getAttribute(PT_APP_VISIBLE); @@ -186,9 +191,12 @@ else if (PT_APP_CARDINALITY_SINGLETON_GLOBAL.equals(sCardinality)) flags |= EclipseAppDescriptor.FLAG_DEFAULT_APP; iconPath = configs[0].getAttribute(PT_APP_ICON); } - appDescriptor = new EclipseAppDescriptor(Activator.getBundle(appExtension.getContributor()), appExtension.getUniqueIdentifier(), appExtension.getLabel(), iconPath, flags, cardinality, this); + appDescriptor = new EclipseAppDescriptor(Activator.getBundle(appExtension.getContributor()), + appExtension.getUniqueIdentifier(), appExtension.getLabel(), iconPath, flags, cardinality, this); // register the appDescriptor as a service - ServiceRegistration sr = (ServiceRegistration) AccessController.doPrivileged(new RegisterService(new String[] {ApplicationDescriptor.class.getName()}, appDescriptor, appDescriptor.getServiceProperties())); + ServiceRegistration sr = (ServiceRegistration) AccessController + .doPrivileged(new RegisterService(new String[] { ApplicationDescriptor.class.getName() }, + appDescriptor, appDescriptor.getServiceProperties())); appDescriptor.setServiceRegistration(sr); // save the app descriptor in the cache apps.put(appExtension.getUniqueIdentifier(), appDescriptor); @@ -211,12 +219,14 @@ private EclipseAppDescriptor removeAppDescriptor(String applicationId) { /* * Gives access to the RegisterService privileged action. */ - PrivilegedAction getRegServiceAction(String[] serviceClasses, Object serviceObject, Dictionary serviceProps) { + PrivilegedAction getRegServiceAction(String[] serviceClasses, Object serviceObject, + Dictionary serviceProps) { return new RegisterService(serviceClasses, serviceObject, serviceProps); } /* - * PrivilegedAction used to register ApplicationDescriptor and ApplicationHandle services + * PrivilegedAction used to register ApplicationDescriptor and ApplicationHandle + * services */ private class RegisterService implements PrivilegedAction { String[] serviceClasses; @@ -248,8 +258,10 @@ void startDefaultApp(boolean delayError) throws ApplicationException { } else { defaultDesc = getAppDescriptor(applicationId); if (defaultDesc == null && !delayError) { - // the application id is not available in the registry; use a descriptor that will throw an exception - args.put(ErrorApplication.ERROR_EXCEPTION, new RuntimeException(NLS.bind(Messages.application_notFound, applicationId, getAvailableAppsMsg()))); + // the application id is not available in the registry; use a descriptor that + // will throw an exception + args.put(ErrorApplication.ERROR_EXCEPTION, new RuntimeException( + NLS.bind(Messages.application_notFound, applicationId, getAvailableAppsMsg()))); defaultDesc = getAppDescriptor(EXT_ERROR_APP); } } @@ -263,7 +275,8 @@ void startDefaultApp(boolean delayError) throws ApplicationException { if (defaultDesc != null) defaultDesc.launch(args); else - throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, Messages.application_noIdFound); + throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, + Messages.application_noIdFound); } /* @@ -284,8 +297,8 @@ private void registerAppDescriptor(String applicationId) { } /* - * Returns a list of all the available application IDs which are available - * in the extension registry. + * Returns a list of all the available application IDs which are available in + * the extension registry. */ private IExtension[] getAvailableAppExtensions() { IExtensionPoint point = extensionRegistry.getExtensionPoint(PI_RUNTIME + '.' + PT_APPLICATIONS); @@ -306,9 +319,9 @@ String getAvailableAppsMsg() { } /* - * Returns the application extension for the specified applicaiton ID. - * A RuntimeException is thrown if the extension does not exist for the - * given application ID. + * Returns the application extension for the specified applicaiton ID. A + * RuntimeException is thrown if the extension does not exist for the given + * application ID. */ IExtension getAppExtension(String applicationId) { return extensionRegistry.getExtension(PI_RUNTIME, PT_APPLICATIONS, applicationId); @@ -316,8 +329,10 @@ IExtension getAppExtension(String applicationId) { void launch(EclipseAppHandle appHandle) throws Exception { boolean isDefault = appHandle.isDefault(); - if (((EclipseAppDescriptor) appHandle.getApplicationDescriptor()).getThreadType() == EclipseAppDescriptor.FLAG_TYPE_MAIN_THREAD) { - // use the ApplicationLauncher provided by the framework to ensure it is launched on the main thread + if (((EclipseAppDescriptor) appHandle.getApplicationDescriptor()) + .getThreadType() == EclipseAppDescriptor.FLAG_TYPE_MAIN_THREAD) { + // use the ApplicationLauncher provided by the framework to ensure it is + // launched on the main thread DefaultApplicationListener curDefaultApplicationListener = null; MainApplicationLauncher curMissingAppLauncher = null; ApplicationLauncher appLauncher = null; @@ -326,11 +341,13 @@ void launch(EclipseAppHandle appHandle) throws Exception { if (appLauncher == null) { if (isDefault) { // we need to wait to allow the ApplicationLauncher to get registered; - // save the handle to be launched as soon as the ApplicationLauncher is available + // save the handle to be launched as soon as the ApplicationLauncher is + // available defaultMainThreadAppHandle = appHandle; return; } - throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, NLS.bind(Messages.application_error_noMainThread, appHandle.getInstanceId())); + throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, + NLS.bind(Messages.application_error_noMainThread, appHandle.getInstanceId())); } curDefaultApplicationListener = defaultAppListener; curMissingAppLauncher = missingAppLauncher; @@ -353,7 +370,8 @@ else if (curMissingAppLauncher != null) curDefaultApplicationListener = defaultAppListener; if (appLauncher == null) { // we need to wait to allow the ApplicationLauncher to get registered; - // save the default app listener to be launched as soon as the ApplicationLauncher is available + // save the default app listener to be launched as soon as the + // ApplicationLauncher is available defaultMainThreadAppHandle = curDefaultApplicationListener; return; } @@ -374,14 +392,16 @@ public void bundleChanged(BundleEvent event) { // if this is not the system bundle stopping then ignore the event if ((BundleEvent.STOPPING & event.getType()) == 0 || event.getBundle().getBundleId() != 0) return; - // The system bundle is stopping; better stop all applications and containers now + // The system bundle is stopping; better stop all applications and containers + // now stopAllApps(); } private void stopAllApps() { // get a stapshot of running applications try { - ServiceReference[] runningRefs = context.getServiceReferences(ApplicationHandle.class.getName(), "(!(application.state=STOPPING))"); //$NON-NLS-1$ + ServiceReference[] runningRefs = context.getServiceReferences(ApplicationHandle.class.getName(), + "(!(application.state=STOPPING))"); //$NON-NLS-1$ if (runningRefs != null) for (ServiceReference runningRef : runningRefs) { ApplicationHandle handle = (ApplicationHandle) context.getService(runningRef); @@ -390,7 +410,8 @@ private void stopAllApps() { handle.destroy(); } catch (Throwable t) { String message = NLS.bind(Messages.application_error_stopping, handle.getInstanceId()); - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, t, null)); + Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, + t, null)); } finally { if (handle != null) { context.ungetService(runningRef); @@ -415,7 +436,7 @@ private String getDefaultAppId() { if (defaultAppId != null) return defaultAppId; - //Derive the application from the product information + // Derive the application from the product information defaultAppId = getBranding() == null ? null : getBranding().getApplication(); return defaultAppId; } @@ -433,9 +454,11 @@ public IBranding getBranding() { if (productId == null) return null; } - IConfigurationElement[] entries = extensionRegistry.getConfigurationElementsFor(PI_RUNTIME, PT_PRODUCTS, productId); + IConfigurationElement[] entries = extensionRegistry.getConfigurationElementsFor(PI_RUNTIME, PT_PRODUCTS, + productId); if (entries.length > 0) { - // There should only be one product with the given id so just take the first element + // There should only be one product with the given id so just take the first + // element branding = new ProductExtensionBranding(productId, entries[0]); return branding; } @@ -448,7 +471,8 @@ public IBranding getBranding() { Object[] products = (Object[]) EclipseAppContainer.callMethod(provider, "getProducts", null, null); //$NON-NLS-1$ if (products != null) for (Object product : products) { - if (productId.equalsIgnoreCase((String) EclipseAppContainer.callMethod(product, "getId", null, null))) { //$NON-NLS-1$ + if (productId.equalsIgnoreCase( + (String) EclipseAppContainer.callMethod(product, "getId", null, null))) { //$NON-NLS-1$ branding = new ProviderExtensionBranding(product); return branding; } @@ -456,15 +480,18 @@ public IBranding getBranding() { } catch (CoreException e) { if (logEntries == null) logEntries = new ArrayList<>(3); - logEntries.add(new FrameworkLogEntry(Activator.PI_APP, NLS.bind(Messages.provider_invalid, element.getParent().toString()), 0, e, null)); + logEntries.add(new FrameworkLogEntry(Activator.PI_APP, + NLS.bind(Messages.provider_invalid, element.getParent().toString()), 0, e, null)); } } } if (logEntries != null) - Activator.log(new FrameworkLogEntry(Activator.PI_APP, Messages.provider_invalid_general, 0, null, logEntries.toArray(new FrameworkLogEntry[logEntries.size()]))); + Activator.log(new FrameworkLogEntry(Activator.PI_APP, Messages.provider_invalid_general, 0, null, + logEntries.toArray(new FrameworkLogEntry[logEntries.size()]))); if (!missingProductReported) { - Activator.log(new FrameworkLogEntry(Activator.PI_APP, NLS.bind(Messages.product_notFound, productId), 0, null, null)); + Activator.log(new FrameworkLogEntry(Activator.PI_APP, NLS.bind(Messages.product_notFound, productId), 0, + null, null)); missingProductReported = true; } return null; @@ -481,44 +508,48 @@ void lock(EclipseAppHandle appHandle) throws ApplicationException { EclipseAppDescriptor eclipseApp = (EclipseAppDescriptor) appHandle.getApplicationDescriptor(); synchronized (lock) { switch (isLocked(eclipseApp)) { - case NOT_LOCKED : - break; - case LOCKED_SINGLETON_GLOBAL_RUNNING : - throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, NLS.bind(Messages.singleton_running, activeGlobalSingleton.getInstanceId())); - case LOCKED_SINGLETON_GLOBAL_APPS_RUNNING : - throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, Messages.apps_running); - case LOCKED_SINGLETON_SCOPED_RUNNING : - throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, NLS.bind(Messages.singleton_running, activeScopedSingleton.getInstanceId())); - case LOCKED_SINGLETON_LIMITED_RUNNING : - throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, NLS.bind(Messages.max_running, eclipseApp.getApplicationId())); - case LOCKED_MAIN_THREAD_RUNNING : - throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, NLS.bind(Messages.main_running, activeMain.getInstanceId())); - default : - break; + case NOT_LOCKED: + break; + case LOCKED_SINGLETON_GLOBAL_RUNNING: + throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, + NLS.bind(Messages.singleton_running, activeGlobalSingleton.getInstanceId())); + case LOCKED_SINGLETON_GLOBAL_APPS_RUNNING: + throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, Messages.apps_running); + case LOCKED_SINGLETON_SCOPED_RUNNING: + throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, + NLS.bind(Messages.singleton_running, activeScopedSingleton.getInstanceId())); + case LOCKED_SINGLETON_LIMITED_RUNNING: + throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, + NLS.bind(Messages.max_running, eclipseApp.getApplicationId())); + case LOCKED_MAIN_THREAD_RUNNING: + throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, + NLS.bind(Messages.main_running, activeMain.getInstanceId())); + default: + break; } // ok we can now successfully lock the container switch (eclipseApp.getCardinalityType()) { - case EclipseAppDescriptor.FLAG_CARD_SINGLETON_GLOGAL : - activeGlobalSingleton = appHandle; - break; - case EclipseAppDescriptor.FLAG_CARD_SINGLETON_SCOPED : - activeScopedSingleton = appHandle; - break; - case EclipseAppDescriptor.FLAG_CARD_LIMITED : - if (activeLimited == null) - activeLimited = new HashMap<>(3); - ArrayList limited = activeLimited.get(eclipseApp.getApplicationId()); - if (limited == null) { - limited = new ArrayList<>(eclipseApp.getCardinality()); - activeLimited.put(eclipseApp.getApplicationId(), limited); - } - limited.add(appHandle); - break; - case EclipseAppDescriptor.FLAG_CARD_UNLIMITED : - break; - default : - break; + case EclipseAppDescriptor.FLAG_CARD_SINGLETON_GLOGAL: + activeGlobalSingleton = appHandle; + break; + case EclipseAppDescriptor.FLAG_CARD_SINGLETON_SCOPED: + activeScopedSingleton = appHandle; + break; + case EclipseAppDescriptor.FLAG_CARD_LIMITED: + if (activeLimited == null) + activeLimited = new HashMap<>(3); + ArrayList limited = activeLimited.get(eclipseApp.getApplicationId()); + if (limited == null) { + limited = new ArrayList<>(eclipseApp.getCardinality()); + activeLimited.put(eclipseApp.getApplicationId(), limited); + } + limited.add(appHandle); + break; + case EclipseAppDescriptor.FLAG_CARD_UNLIMITED: + break; + default: + break; } if (eclipseApp.getThreadType() == EclipseAppDescriptor.FLAG_TYPE_MAIN_THREAD) activeMain = appHandle; @@ -533,9 +564,11 @@ void unlock(EclipseAppHandle appHandle) { activeGlobalSingleton = null; else if (activeScopedSingleton == appHandle) activeScopedSingleton = null; - else if (((EclipseAppDescriptor) appHandle.getApplicationDescriptor()).getCardinalityType() == EclipseAppDescriptor.FLAG_CARD_LIMITED) { + else if (((EclipseAppDescriptor) appHandle.getApplicationDescriptor()) + .getCardinalityType() == EclipseAppDescriptor.FLAG_CARD_LIMITED) { if (activeLimited != null) { - ArrayList limited = activeLimited.get(((EclipseAppDescriptor) appHandle.getApplicationDescriptor()).getApplicationId()); + ArrayList limited = activeLimited + .get(((EclipseAppDescriptor) appHandle.getApplicationDescriptor()).getApplicationId()); if (limited != null) limited.remove(appHandle); } @@ -552,25 +585,25 @@ int isLocked(EclipseAppDescriptor eclipseApp) { if (activeGlobalSingleton != null) return LOCKED_SINGLETON_GLOBAL_RUNNING; switch (eclipseApp.getCardinalityType()) { - case EclipseAppDescriptor.FLAG_CARD_SINGLETON_GLOGAL : - if (activeHandles.size() > 0) - return LOCKED_SINGLETON_GLOBAL_APPS_RUNNING; - break; - case EclipseAppDescriptor.FLAG_CARD_SINGLETON_SCOPED : - if (activeScopedSingleton != null) - return LOCKED_SINGLETON_SCOPED_RUNNING; - break; - case EclipseAppDescriptor.FLAG_CARD_LIMITED : - if (activeLimited != null) { - ArrayList limited = activeLimited.get(eclipseApp.getApplicationId()); - if (limited != null && limited.size() >= eclipseApp.getCardinality()) - return LOCKED_SINGLETON_LIMITED_RUNNING; - } - break; - case EclipseAppDescriptor.FLAG_CARD_UNLIMITED : - break; - default : - break; + case EclipseAppDescriptor.FLAG_CARD_SINGLETON_GLOGAL: + if (activeHandles.size() > 0) + return LOCKED_SINGLETON_GLOBAL_APPS_RUNNING; + break; + case EclipseAppDescriptor.FLAG_CARD_SINGLETON_SCOPED: + if (activeScopedSingleton != null) + return LOCKED_SINGLETON_SCOPED_RUNNING; + break; + case EclipseAppDescriptor.FLAG_CARD_LIMITED: + if (activeLimited != null) { + ArrayList limited = activeLimited.get(eclipseApp.getApplicationId()); + if (limited != null && limited.size() >= eclipseApp.getCardinality()) + return LOCKED_SINGLETON_LIMITED_RUNNING; + } + break; + case EclipseAppDescriptor.FLAG_CARD_UNLIMITED: + break; + default: + break; } if (eclipseApp.getThreadType() == EclipseAppDescriptor.FLAG_TYPE_MAIN_THREAD && activeMain != null) return LOCKED_MAIN_THREAD_RUNNING; @@ -582,12 +615,14 @@ static Object callMethod(Object obj, String methodName, Class[] argTypes, Obj try { return callMethodWithException(obj, methodName, argTypes, args); } catch (Throwable t) { - Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.ERROR, 0, "Error in invoking method.", 0, t, null)); //$NON-NLS-1$ + Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.ERROR, 0, + "Error in invoking method.", 0, t, null)); //$NON-NLS-1$ } return null; } - static Object callMethodWithException(Object obj, String methodName, Class[] argTypes, Object[] args) throws Exception { + static Object callMethodWithException(Object obj, String methodName, Class[] argTypes, Object[] args) + throws Exception { try { Method method = obj.getClass().getMethod(methodName, argTypes); return method.invoke(obj, args); @@ -606,7 +641,7 @@ public Object addingService(ServiceReference reference) { ParameterizedRunnable appRunnable; synchronized (this) { appLauncher = (ApplicationLauncher) context.getService(reference); - // see if there is a default main threaded application waiting to run + // see if there is a default main threaded application waiting to run appRunnable = defaultMainThreadAppHandle; // null out so we do not attempt to start this handle again defaultMainThreadAppHandle = null; @@ -618,7 +653,10 @@ public Object addingService(ServiceReference reference) { } if (appRunnable != null) // found a main threaded app; start it now that the app launcher is available - appLauncher.launch(appRunnable, appRunnable instanceof EclipseAppHandle ? ((EclipseAppHandle) appRunnable).getArguments().get(IApplicationContext.APPLICATION_ARGS) : null); + appLauncher.launch(appRunnable, + appRunnable instanceof EclipseAppHandle + ? ((EclipseAppHandle) appRunnable).getArguments().get(IApplicationContext.APPLICATION_ARGS) + : null); return appLauncher; } diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppDescriptor.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppDescriptor.java index 4853b95e5c8..4d6c02643d4 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppDescriptor.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppDescriptor.java @@ -49,9 +49,10 @@ public class EclipseAppDescriptor extends ApplicationDescriptor { private final int cardinality; private final String name; private final URL iconURL; - private final boolean[] registrationLock = new boolean[] {true}; + private final boolean[] registrationLock = new boolean[] { true }; - protected EclipseAppDescriptor(Bundle contributor, String pid, String name, String iconPath, int flags, int cardinality, EclipseAppContainer appContainer) { + protected EclipseAppDescriptor(Bundle contributor, String pid, String name, String iconPath, int flags, + int cardinality, EclipseAppContainer appContainer) { super(pid); this.name = name; this.contributor = contributor; @@ -190,12 +191,15 @@ private String getLocation() { } /* - * Returns the appHandle. If it does not exist then one is created. + * Returns the appHandle. If it does not exist then one is created. */ private EclipseAppHandle createAppHandle(Map arguments) throws ApplicationException { EclipseAppHandle newAppHandle = new EclipseAppHandle(getInstanceID(), arguments, this); appContainer.lock(newAppHandle); - ServiceRegistration appHandleReg = (ServiceRegistration) AccessController.doPrivileged(appContainer.getRegServiceAction(new String[] {ApplicationHandle.class.getName(), IApplicationContext.class.getName()}, newAppHandle, newAppHandle.getServiceProperties())); + ServiceRegistration appHandleReg = (ServiceRegistration) AccessController + .doPrivileged(appContainer.getRegServiceAction( + new String[] { ApplicationHandle.class.getName(), IApplicationContext.class.getName() }, + newAppHandle, newAppHandle.getServiceProperties())); newAppHandle.setServiceRegistration(appHandleReg); return newAppHandle; } @@ -208,7 +212,10 @@ EclipseAppContainer getContainerManager() { public boolean matchDNChain(String pattern) { if (contributor == null) return false; - return BundleSignerCondition.getCondition(contributor, new ConditionInfo(BundleSignerCondition.class.getName(), new String[] {pattern})).isSatisfied(); + return BundleSignerCondition + .getCondition(contributor, + new ConditionInfo(BundleSignerCondition.class.getName(), new String[] { pattern })) + .isSatisfied(); } @Override @@ -235,7 +242,8 @@ int getThreadType() { } int getCardinalityType() { - return flags & (FLAG_CARD_SINGLETON_GLOGAL | FLAG_CARD_SINGLETON_SCOPED | FLAG_CARD_LIMITED | FLAG_CARD_UNLIMITED); + return flags + & (FLAG_CARD_SINGLETON_GLOGAL | FLAG_CARD_SINGLETON_SCOPED | FLAG_CARD_LIMITED | FLAG_CARD_UNLIMITED); } int getCardinality() { diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java index 23f3c5c1374..c858990f0d6 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java @@ -51,14 +51,16 @@ public class EclipseAppHandle extends ApplicationHandle implements ApplicationRu private Object result; private boolean setResult = false; private boolean setAsyncResult = false; - private final boolean[] registrationLock = new boolean[] {true}; + private final boolean[] registrationLock = new boolean[] { true }; /* * Constructs a handle for a single running instance of a eclipse application. */ EclipseAppHandle(String instanceId, Map arguments, EclipseAppDescriptor descriptor) { super(instanceId, descriptor); - defaultAppInstance = arguments == null || arguments.get(EclipseAppDescriptor.APP_DEFAULT) == null ? Boolean.FALSE : (Boolean) arguments.remove(EclipseAppDescriptor.APP_DEFAULT); + defaultAppInstance = arguments == null || arguments.get(EclipseAppDescriptor.APP_DEFAULT) == null + ? Boolean.FALSE + : (Boolean) arguments.remove(EclipseAppDescriptor.APP_DEFAULT); if (arguments == null) this.arguments = new HashMap<>(2); else @@ -68,18 +70,19 @@ public class EclipseAppHandle extends ApplicationHandle implements ApplicationRu @Override synchronized public String getState() { switch (status) { - case FLAG_STARTING : - return STARTING; - case FLAG_ACTIVE : - return ApplicationHandle.RUNNING; - case FLAG_STOPPING : - return ApplicationHandle.STOPPING; - case FLAG_STOPPED : - default : - // must only check this if the status is STOPPED; otherwise we throw exceptions before we have set the registration. - if (getServiceRegistration() == null) - throw new IllegalStateException(NLS.bind(Messages.application_error_state_stopped, getInstanceId())); - return STOPPED; + case FLAG_STARTING: + return STARTING; + case FLAG_ACTIVE: + return ApplicationHandle.RUNNING; + case FLAG_STOPPING: + return ApplicationHandle.STOPPING; + case FLAG_STOPPED: + default: + // must only check this if the status is STOPPED; otherwise we throw exceptions + // before we have set the registration. + if (getServiceRegistration() == null) + throw new IllegalStateException(NLS.bind(Messages.application_error_state_stopped, getInstanceId())); + return STOPPED; } } @@ -136,7 +139,8 @@ Dictionary getServiceProperties() { props.put(ApplicationHandle.APPLICATION_PID, getInstanceId()); props.put(ApplicationHandle.APPLICATION_STATE, getState()); props.put(ApplicationHandle.APPLICATION_DESCRIPTOR, getApplicationDescriptor().getApplicationId()); - props.put(EclipseAppDescriptor.APP_TYPE, ((EclipseAppDescriptor) getApplicationDescriptor()).getThreadTypeString()); + props.put(EclipseAppDescriptor.APP_TYPE, + ((EclipseAppDescriptor) getApplicationDescriptor()).getThreadTypeString()); props.put(ApplicationHandle.APPLICATION_SUPPORTS_EXITVALUE, Boolean.TRUE); if (defaultAppInstance.booleanValue()) props.put(EclipseAppDescriptor.APP_DEFAULT, defaultAppInstance); @@ -144,8 +148,8 @@ Dictionary getServiceProperties() { } /* - * Changes the status of this handle. This method will properly transition - * the state of this handle and will update the service registration accordingly. + * Changes the status of this handle. This method will properly transition the + * state of this handle and will update the service registration accordingly. */ private synchronized void setAppStatus(int status) { if (this.status == status) @@ -194,7 +198,8 @@ public Object run(Object context) throws Exception { Object app; synchronized (this) { if ((status & (EclipseAppHandle.FLAG_STARTING | EclipseAppHandle.FLAG_STOPPING)) == 0) - throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, NLS.bind(Messages.application_instance_stopped, getInstanceId())); + throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, + NLS.bind(Messages.application_instance_stopped, getInstanceId())); application = getConfiguration().createExecutableExtension("run"); //$NON-NLS-1$ app = application; notifyAll(); @@ -202,7 +207,8 @@ public Object run(Object context) throws Exception { if (app instanceof IApplication) tempResult = ((IApplication) app).start(this); else - tempResult = EclipseAppContainer.callMethodWithException(app, "run", new Class[] {Object.class}, new Object[] {context}); //$NON-NLS-1$ + tempResult = EclipseAppContainer.callMethodWithException(app, "run", new Class[] { Object.class }, //$NON-NLS-1$ + new Object[] { context }); if (tempResult == null) tempResult = NULL_RESULT; } finally { @@ -210,7 +216,9 @@ public Object run(Object context) throws Exception { } if (Activator.DEBUG) - System.out.println(NLS.bind(Messages.application_returned, (new String[] {getApplicationDescriptor().getApplicationId(), tempResult == null ? "null" : tempResult.toString()}))); //$NON-NLS-1$ + System.out.println(NLS.bind(Messages.application_returned, + (new String[] { getApplicationDescriptor().getApplicationId(), + tempResult == null ? "null" : tempResult.toString() }))); //$NON-NLS-1$ return tempResult; } @@ -219,9 +227,11 @@ private synchronized Object setInternalResult(Object result, boolean isAsync, IA throw new IllegalStateException("The result of the application is already set."); //$NON-NLS-1$ if (isAsync) { if (!setAsyncResult) - throw new IllegalStateException("The application must return IApplicationContext.EXIT_ASYNC_RESULT to set asynchronous results."); //$NON-NLS-1$ + throw new IllegalStateException( + "The application must return IApplicationContext.EXIT_ASYNC_RESULT to set asynchronous results."); //$NON-NLS-1$ if (application != tokenApp) - throw new IllegalArgumentException("The application is not the correct instance for this application context."); //$NON-NLS-1$ + throw new IllegalArgumentException( + "The application is not the correct instance for this application context."); //$NON-NLS-1$ } else { if (result == IApplicationContext.EXIT_ASYNC_RESULT) { setAsyncResult = true; @@ -236,7 +246,8 @@ private synchronized Object setInternalResult(Object result, boolean isAsync, IA setAppStatus(EclipseAppHandle.FLAG_STOPPING); // must ensure the STOPPING event is fired setAppStatus(EclipseAppHandle.FLAG_STOPPED); // only set the exit code property if this is the default application - // (bug 321386) only set the exit code if the result != null; when result == null we assume an exception was thrown + // (bug 321386) only set the exit code if the result != null; when result == + // null we assume an exception was thrown if (isDefault() && result != null) { int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0; // Use the EnvironmentInfo Service to set properties @@ -321,7 +332,8 @@ private synchronized IApplication getApplication() { // the handle has been initialized by the container but the launcher has not // gotten around to creating the application object and starting it yet. try { - wait(5000); // timeout after a while in case there was an internal error and there will be no application created + wait(5000); // timeout after a while in case there was an internal error and there will be + // no application created } catch (InterruptedException e) { // do nothing } @@ -329,12 +341,16 @@ private synchronized IApplication getApplication() { } private IConfigurationElement getConfiguration() { - IExtension applicationExtension = ((EclipseAppDescriptor) getApplicationDescriptor()).getContainerManager().getAppExtension(getApplicationDescriptor().getApplicationId()); + IExtension applicationExtension = ((EclipseAppDescriptor) getApplicationDescriptor()).getContainerManager() + .getAppExtension(getApplicationDescriptor().getApplicationId()); if (applicationExtension == null) - throw new RuntimeException(NLS.bind(Messages.application_notFound, getApplicationDescriptor().getApplicationId(), ((EclipseAppDescriptor) getApplicationDescriptor()).getContainerManager().getAvailableAppsMsg())); + throw new RuntimeException(NLS.bind(Messages.application_notFound, + getApplicationDescriptor().getApplicationId(), + ((EclipseAppDescriptor) getApplicationDescriptor()).getContainerManager().getAvailableAppsMsg())); IConfigurationElement[] configs = applicationExtension.getConfigurationElements(); if (configs.length == 0) - throw new RuntimeException(NLS.bind(Messages.application_invalidExtension, getApplicationDescriptor().getApplicationId())); + throw new RuntimeException( + NLS.bind(Messages.application_invalidExtension, getApplicationDescriptor().getApplicationId())); return configs[0]; } diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseScheduledApplication.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseScheduledApplication.java index 42a8bbca273..3859f9a960a 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseScheduledApplication.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseScheduledApplication.java @@ -27,7 +27,8 @@ import org.osgi.util.tracker.ServiceTracker; public class EclipseScheduledApplication implements ScheduledApplication, EventHandler { - private static final String FILTER_PREFIX = "(&(objectclass=" + ApplicationDescriptor.class.getName() + ")(" + ApplicationDescriptor.APPLICATION_PID + "="; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + private static final String FILTER_PREFIX = "(&(objectclass=" + ApplicationDescriptor.class.getName() + ")(" //$NON-NLS-1$ //$NON-NLS-2$ + + ApplicationDescriptor.APPLICATION_PID + "="; //$NON-NLS-1$ private static final String FILTER_POSTFIX = "))"; //$NON-NLS-1$ private boolean recurring; @@ -40,7 +41,8 @@ public class EclipseScheduledApplication implements ScheduledApplication, EventH private ServiceTracker appTracker; private boolean removed = false; - EclipseScheduledApplication(BundleContext context, String id, String appPid, Map args, String topic, String eventFilter, boolean recurring) throws InvalidSyntaxException { + EclipseScheduledApplication(BundleContext context, String id, String appPid, Map args, String topic, + String eventFilter, boolean recurring) throws InvalidSyntaxException { this.id = id; this.appPid = appPid; this.args = args; @@ -140,8 +142,8 @@ synchronized void setServiceRegistration(ServiceRegistration sr) { } /* - * This is used to guard the event topic argument which is passed to an application - * when we are launching it from a scheduling. + * This is used to guard the event topic argument which is passed to an + * application when we are launching it from a scheduling. */ public class TriggerGuard implements Guard { String eventTopic; diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/IBranding.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/IBranding.java index 3299e61e4f5..65b65a36966 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/IBranding.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/IBranding.java @@ -27,7 +27,7 @@ public interface IBranding { public String getId(); public String getProperty(String key); - + public Bundle getDefiningBundle(); public Object getProduct(); diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainApplicationLauncher.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainApplicationLauncher.java index 42bcbee98f9..e2d2b657795 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainApplicationLauncher.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainApplicationLauncher.java @@ -18,7 +18,8 @@ import org.osgi.service.application.ApplicationException; /** - * A main threaded application may be launched using this class to launch the main threaded application. + * A main threaded application may be launched using this class to launch the + * main threaded application. */ public class MainApplicationLauncher implements ApplicationRunnable { private final EclipseAppContainer appContainer; diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ProviderExtensionBranding.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ProviderExtensionBranding.java index 3e80f49cb2b..88ecf9f158b 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ProviderExtensionBranding.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ProviderExtensionBranding.java @@ -49,7 +49,8 @@ public String getName() { @Override public String getProperty(String key) { - return (String) EclipseAppContainer.callMethod(product, "getProperty", new Class[] {String.class}, new Object[] {key}); //$NON-NLS-1$ + return (String) EclipseAppContainer.callMethod(product, "getProperty", new Class[] { String.class }, //$NON-NLS-1$ + new Object[] { key }); } @Override