Regole di accesso

The Eclipse 3.1 runtime gives the plug-in developer the option to control plug-in code visibility to downstream plug-ins on a per-package basis.

È possibile classificare i pacchetti come:

  1. Accessibile
  2. Proibito
  3. Interno
  4. Interno con amici

PDE traduce queste regole di visibilità di runtime regole di limiti di accesso al compilatore durante la compilazione. As a result, a violation of a visibility rule is flagged by the compiler as a warning or an error - depending on the severity of that violation.

With this type of support at compile time, one is never caught by surprise by runtime class loading errors and is always aware of internal type references.

 

Pacchetti accessibili

I pacchetti accessibili sono sempre visibili.  Mentre i pacchetti API devono appartenere sempre alla categoria di plugin downstream, per i pacchetti accessibili lo sviluppatore può decidere quali altri pacchetti esportati dal plugin devono avere questo livello di visibilità.

Per dichiarare un pacchetto accessibile, è necessario aggiungerlo alla sezione Pacchetti esportati nel Runtime dell'editor manifest del plugin e lasciare l'impostazione di visibilità predefinita nello stato in cui si trova.

Accessible Packages

 

Pacchetti proibiti

È possibile nascondere i pacchetti dai plugin di downstream in qualsiasi momento escludendoli dall'elenco nella sezione Pacchetti esportati nella pagina Runtime dell'editor manifest del plugin.

References to types from a forbidden package result in class loading errors at runtime.

 Per evitare questo problema:

  1. The compiler will flag references to forbidden packages with an error.
  2. Types from forbidden packages are NOT available as proposals in the content assist.

Note:

  1. All plug-ins in the Eclipse SDK enumerate all their packages in the Exported Packages section; therefore, none of the packages in the SDK have forbidden access.
  2. The severity level for forbidden references is set on the Java > Compiler > Errors/Warnings > Deprecated and restricted API preference page.

    It is strongly recommended that the severity of a forbidden reference is kept at error.

    Preferenza proibita

 

Internal Packages

I pacchetti interni non sono destinati per l'uso con plugin downstream. Tali pacchetti sono visibili ai plugin di downstream per impostazione predefinita.

I pacchetti interni sono vengono nascosti ai plugin di downstream solo quando Eclipse viene avviato in modalità strict (ad esempio quando viene avviato con l'argomento -Dosgi.resolverMode=strict).

I pacchetti interni devono trovarsi nella sezione Pacchetti esportati della pagina Runtime dell'editor manifest del plugin con l'opzione Nascosto selezionata.

discouraged access

Per impedire che i plugin di downstream facciano riferimento ai pacchetti interni:

discouraged access

discouraged content assist

The severity level for discouraged references can be set on the Java > Compiler > Errors/Warnings > Deprecated and restricted API preference page.

Discouraged preferences

 

Pacchetti interni con amici

È importante per un plugin poter garantire pieno accesso ai pacchetti interni a quei plugin definiti "amici". Ad esempio, il codice PDE è suddiviso tra più plugin e il plugin org.eclipse.pde.ui deve avere pieno accesso ai pacchetti interni di org.eclipse.pde.core.

In the example below, the the org.eclipse.pde.ui friend plug-in has full access to the org.eclipse.pde.internal.core.bundle package from the org.eclipse.pde.core plug-in.

Friends

Gli amici possono fare riferimento a qualsiasi tipo dal pacchetto org.eclipse.pde.internal.core.bundle.

On the other hand, if any other plug-in references a type from the org.eclipse.pde.internal.core.bundle package, the compiler flags the reference as a discouraged reference as described in the previous section.

 

Come abilitare le limitazioni all'accesso

To take advantage of the PDE access restriction support, the only requirement is that the plug-ins in question contain an OSGi bundle MANIFEST.MF. PDE will take care of the rest including the management of the plug-in classpath.

If the plug-in does not contain a MANIFEST.MF file, that file can be created as follows:

  1. Open the plugin.xml in the plug-in manifest editor.
  2. Nella sezione Contenuto del plugin della pagina Panoramica, fare clic sul collegamento 'Crea un file manifest dell'insieme OSG'.

convert to manifest.mf

 

Esame delle regole di accesso

È possibile esaminare le regole di limitazione all'accesso imposte in ciascun percorso classi da PDE nella pagina delle proprietà Percorso di generazione Java del progetto di plugin.

Java Build Path Properties