Changeset 4113


Ignore:
Timestamp:
Jan 31, 2008, 11:21:59 AM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #913: Plug-in JAR paths should support paths relative to the plugins.dir setting in base.config

Location:
trunk/src/core/net/sf/basedb/core
Files:
5 edited

Legend:

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

    r4112 r4113  
    519519  public String getValidatorJarPath()
    520520  {
    521     return getData().getValidatorJarPath();
     521    return PluginDefinition.convertToAbsolute(getData().getValidatorJarPath());
    522522  }
    523523 
     
    533533  {
    534534    checkPermission(Permission.WRITE);
     535    validatorJarPath = PluginDefinition.convertToRelative(validatorJarPath);
    535536    getData().setValidatorJarPath(StringUtil.setNullableString(validatorJarPath,
    536537      "validatorJarPath", MAX_JARPATH_LENGTH));
     
    546547  public DataFileValidator getValidator()
    547548  {
    548     String validatorClass = getData().getValidatorClass();
     549    String validatorClass = getValidatorClass();
    549550    if (validatorClass == null) return null;
    550551    DataFileValidator validator = null;
     
    596597  public String getMetadataReaderJarPath()
    597598  {
    598     return getData().getMetadataReaderJarPath();
     599    return PluginDefinition.convertToAbsolute(getData().getMetadataReaderJarPath());
    599600  }
    600601 
     
    610611  {
    611612    checkPermission(Permission.WRITE);
     613    metadataReaderJarPath = PluginDefinition.convertToRelative(metadataReaderJarPath);
    612614    getData().setMetadataReaderJarPath(StringUtil.setNullableString(metadataReaderJarPath,
    613615      "metadataReaderJarPath", MAX_JARPATH_LENGTH));
     
    622624  public DataFileMetadataReader getMetadataReader()
    623625  {
    624     String readerClass = getData().getMetadataReaderClass();
     626    String readerClass = getMetadataReaderClass();
    625627    if (readerClass == null) return null;
    626628    DataFileMetadataReader reader = null;
    627629    try
    628630    {
    629       String jarPath = getValidatorJarPath();
     631      String jarPath = getMetadataReaderJarPath();
    630632      ClassLoader loader = jarPath == null ? null : JarClassLoader.getInstance(jarPath);
    631633      reader = (DataFileMetadataReader)ClassUtil.checkAndLoadClass(
  • trunk/src/core/net/sf/basedb/core/Install.java

    r4112 r4113  
    107107    method.
    108108  */
    109   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(50).intValue();
     109  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(51).intValue();
    110110 
    111111  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/JobAgentSettings.java

    r3675 r4113  
    222222    if (jarPath == null)
    223223    {
    224       jarPath = data.getPluginDefinition().getJarPath();
     224      jarPath = PluginDefinition.convertToAbsolute(data.getPluginDefinition().getJarPath());
    225225    }
    226226    return jarPath;
  • trunk/src/core/net/sf/basedb/core/PluginDefinition.java

    r4040 r4113  
    122122  public static final int MAX_URL_LENGTH = PluginDefinitionData.MAX_URL_LENGTH;
    123123
     124  /**
     125    Convert a plug-in path to a path relative to the <code>plugins.dir</code>
     126    setting in <code>base.config</code>. If no plug-in directory has been
     127    specified or if the path is null nothing is done. If the given path is
     128    a subpath to the <code>plugins.dir</code> path the common path is replaced
     129    with <code>%plugins.dir%</code> For example:
     130    <pre class="code>"
     131path          = /usr/local/base/plugins/myplugin.jar
     132plugins.dir   = /usr/local/base/plugins
     133relative path = %plugins.dir%/myplugin.jar
     134</pre>
     135
     136    @param path The absolute path
     137    @return The relative path
     138    @since 2.6
     139    @see #convertToAbsolute(String)
     140  */
     141  public static String convertToRelative(String path)
     142  {
     143    if (path == null) return null;
     144    String pluginsDir = Config.getString("plugins.dir");
     145    if (pluginsDir == null) return path;
     146    if (path.startsWith(pluginsDir))
     147    {
     148      path = "%plugins.dir%" + path.substring(pluginsDir.length());
     149    }
     150    return path;
     151  }
     152 
     153  /**
     154    Convert a relative plug-in path to an absolute path. This is the
     155    reverse of the {@link #convertToRelative(String)} method.
     156 
     157    @param path The relative path
     158    @return The absolute path
     159    @since 2.6
     160  */
     161  public static String convertToAbsolute(String path)
     162  {
     163    if (path == null) return path;
     164    String pluginsDir = Config.getString("plugins.dir");
     165    if (pluginsDir == null) return path;
     166    if (path.startsWith("%plugins.dir%"))
     167    {
     168      path = pluginsDir + path.substring("%plugins.dir%".length());
     169    }
     170    return path;
     171  }
     172 
    124173  /**
    125174    Create a new <code>PluginDefinition</code> item.
     
    551600  public String getJarPath()
    552601  {
    553     return getData().getJarPath();
     602    return convertToAbsolute(getData().getJarPath());
    554603  }
    555604  /**
     
    559608    throws InvalidDataException
    560609  {
    561     getData().setJarPath(StringUtil.setNullableString(jarPath, "jarPath", MAX_JARPATH_LENGTH));
     610    getData().setJarPath(StringUtil.setNullableString(convertToRelative(jarPath),
     611        "jarPath", MAX_JARPATH_LENGTH));
    562612  }
    563613 
     
    10581108  {
    10591109    checkPermission(Permission.USE);
    1060     return newInstance(getData().getJarPath(), getData().getClassName(), false);
     1110    return newInstance(getJarPath(), getClassName(), false);
    10611111  }
    10621112
     
    10651115  {
    10661116    checkPermission(Permission.USE);
    1067     return newInstance(jarPath == null ? getData().getJarPath() : jarPath, getData().getClassName(), false);
     1117    return newInstance(jarPath == null ? getJarPath() : jarPath, getClassName(), false);
    10681118  }
    10691119 
  • trunk/src/core/net/sf/basedb/core/Update.java

    r4112 r4113  
    584584    </td>
    585585  </tr>
     586  <tr>
     587    <td>51</td>
     588    <td>
     589      External plug-in paths should be relative to the plugins.dir setting
     590      in base.config. The update loads all PluginDefinitions with a JAR path
     591      and convert the path with {@link PluginDefinition#convertToRelative(String)}.
     592    </td>
     593  </tr>
    586594 
    587595  </table>
     
    828836        if (progress != null) progress.display((int)(49*progress_factor), "Updating schema version: " + schemaVersion + " -> 50...");
    829837        schemaVersion = setSchemaVersionInTransaction(session, 50);
     838      }
     839     
     840      if (schemaVersion < 51)
     841      {
     842        if (progress != null) progress.display((int)(50*progress_factor), "--Updating schema version: " + schemaVersion + " -> 51...");
     843        schemaVersion = updateToSchemaVersion51(session);
    830844      }
    831845     
     
    20722086    return schemaVersion;
    20732087  }
     2088 
     2089  /**
     2090    Change all plug-ins with an absolute JAR path to relative
     2091    paths.
     2092   
     2093    @return The new schema version (=51)
     2094  */
     2095  private static int updateToSchemaVersion51(org.hibernate.Session session)
     2096    throws BaseException
     2097  {
     2098    final int schemaVersion = 51;
     2099    org.hibernate.Transaction tx = null;
     2100    try
     2101    {
     2102      tx = HibernateUtil.newTransaction(session);
     2103     
     2104      // Change property values
     2105      org.hibernate.Query query = HibernateUtil.createQuery(session,
     2106        "SELECT pd FROM PluginDefinitionData pd WHERE NOT pd.jarPath IS NULL");
     2107      List<PluginDefinitionData> plugins =
     2108        HibernateUtil.loadList(PluginDefinitionData.class, query, null);
     2109     
     2110      for (PluginDefinitionData pd : plugins)
     2111      {
     2112        pd.setJarPath(PluginDefinition.convertToRelative(pd.getJarPath()));
     2113      }
     2114     
     2115      // Update the schema version number
     2116      setSchemaVersion(session, schemaVersion);
     2117 
     2118      // Commit the changes
     2119      HibernateUtil.commit(tx);
     2120      log.info("updateToSchemaVersion51: OK");
     2121    }
     2122    catch (BaseException ex)
     2123    {
     2124      if (tx != null) HibernateUtil.rollback(tx);
     2125      log.error("updateToSchemaVersion51: FAILED", ex);
     2126      throw ex;
     2127    }
     2128    return schemaVersion;
     2129  }
    20742130 
    20752131  /**
Note: See TracChangeset for help on using the changeset viewer.