Changeset 5596


Ignore:
Timestamp:
Mar 18, 2011, 11:46:24 AM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #1592: Unified installation procedure for plug-ins, extensions and more...

When a new instance of a plug-in is created through the BASE core API using the PluginDefinition.newInstance(Class) and the given class wasn't loaded by the default classloader, we'll try to use the classloader of the given class first to try to avoid ClassCastExceptions later.

This means that the second statement below now has a chance to succeed even if the first fails.

  • X x = (X)plugin.newInstance();
  • X x = plugin.newInstance(X.class);
Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/PluginDefinition.java

    r5595 r5596  
    10821082  {
    10831083    checkPermission(Permission.USE);
    1084     return newInstance(getJarPath(), getClassName(), false);
     1084    return newInstance(getJarPath(), getClassName(), null, false);
    10851085  }
    10861086
     
    11051105    throws PermissionDeniedException, BaseException
    11061106  {
    1107     Plugin p = newInstance();
     1107    checkPermission(Permission.USE);
     1108    ClassLoader alternateClassLoader = null;
     1109    if (clazz.getClassLoader() != this.getClass().getClassLoader())
     1110    {
     1111      alternateClassLoader = clazz.getClassLoader();
     1112    }
     1113    Plugin p = newInstance(getJarPath(), getClassName(), alternateClassLoader, false);
    11081114    if (!clazz.isInstance(p))
    11091115    {
     
    11491155    @return The created instance
    11501156  */
    1151   private Plugin newInstance(String jarPath, String className, boolean unloadBefore)
     1157  private Plugin newInstance(String jarPath, String className, ClassLoader alternateClassLoader, boolean unloadBefore)
    11521158    throws BaseException
    11531159  {
     
    11551161    {
    11561162      Class c = null;
     1163      if (alternateClassLoader != null)
     1164      {
     1165        try
     1166        {
     1167          c = ClassUtil.checkAndLoadClass(alternateClassLoader, className, true, Plugin.class);
     1168        }
     1169        catch (Exception ex)
     1170        {}
     1171      }
    11571172      if (jarPath == null)
    11581173      {
     
    12951310    String jarPath = jarFile == null ?
    12961311        null : new java.io.File(Application.getPluginsDirectory(), jarFile).getAbsolutePath();
    1297     Plugin plugin = newInstance(jarPath, className, true);
     1312    Plugin plugin = newInstance(jarPath, className, null, true);
    12981313
    12991314    // The plugin type
  • trunk/src/test/JarPlugin.java

    r4889 r5596  
    6262  public void run(Request request, Response response, ProgressReporter progress)
    6363  {
     64    job.getPluginDefinition().newInstance(JarPluginInterface.class);
    6465    response.setDone("Ok");
    6566  }
  • trunk/src/test/TestPluginDefinition.java

    r5340 r5596  
    6262    test_list();
    6363
     64    int jobId = test_execute(id2, "foo", false);
     65   
    6466    // extra test: test permissions
    6567    test_set_permissions(id3, Item.NEWS, true, null, null);
     
    7577    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
    7678   
     79    TestJob.test_delete(jobId);
    7780    TestJob.test_delete(job1Id);
    7881    TestJob.test_delete(job2Id);
Note: See TracChangeset for help on using the changeset viewer.