Search in sources :

Example 1 with InvalidDashPackage

use of net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage in project processdash by dtuma.

the class TeamStartBootstrap method initiateTemplateLoad.

/** Ask the dashboard to begin the process of loading a new template.
     * 
     * @return null on success; else an error message describing the
     * problem encountered.
     */
private String initiateTemplateLoad(String templateID, File templateFile, String continuationURI) {
    String templatePath = templateFile.getPath();
    String templateDir = templateFile.getParent();
    // Check to ensure that the template is contained in a 'jar'
    // or 'zip' file.
    String suffix = templatePath.substring(templatePath.length() - 4).toLowerCase();
    if (!suffix.equals(".jar") && !suffix.equals(".zip"))
        return resources.getString("Errors.Only_Jar_Zip");
    // Make certain the file can be found.
    if (!templateFile.isFile())
        return resources.getString("Errors.Cannot_Find_File");
    // Make certain that access permissions allow us to read the file
    if (!templateFile.canRead())
        return resources.getString("Errors.Cannot_Read_File");
    // Check to make certain the file is a valid dashboard package, and
    // is compatible with this version of the dashboard.
    boolean upgradeNeeded = true;
    try {
        DashPackage dashPackage = getDashPackageForFile(templateFile);
        String currentDashVersion = (String) env.get(WebServer.PACKAGE_ENV_PREFIX + "pspdash");
        if (dashPackage.isIncompatible(currentDashVersion)) {
            String requiredVersion = dashPackage.requiresDashVersion;
            if (requiredVersion.endsWith("+")) {
                requiredVersion = requiredVersion.substring(0, requiredVersion.length() - 1);
                return resources.format("Errors.Version_Mismatch.Need_Upgrade_FMT", requiredVersion, currentDashVersion);
            } else {
                return resources.format("Errors.Version_Mismatch.Exact_FMT", requiredVersion, currentDashVersion);
            }
        }
        upgradeNeeded = upgradeIsNeeded(dashPackage);
    } catch (InvalidDashPackage idp) {
        return resources.getString("Errors.Invalid_Dash_Package");
    } catch (Exception e) {
        logger.log(Level.WARNING, "Unable to read team process add-on", e);
        return resources.getString("Errors.Cannot_Read_File");
    }
    // Initiate the loading of the template definition.
    new TemplateLoadTask(templatePath, templateDir, upgradeNeeded);
    return null;
}
Also used : InvalidDashPackage(net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage) DashPackage(net.sourceforge.processdash.templates.DashPackage) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidDashPackage(net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage)

Example 2 with InvalidDashPackage

use of net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage in project processdash by dtuma.

the class TemplateLoader method addTemplateJar.

/** Add a specific template to the search list.
     *
     * Note: this bypasses the package consistency checking that is
     * normally performed.  The package will be added even if it is
     * incompatible with the current version of the dashboard.  In
     * addition, if it makes another dashboard package obsolete, that
     * package will not be removed.  The package named will be added
     * to the beginning of the search list.
     */
public static boolean addTemplateJar(DataRepository data, DashHierarchy templates, String jarfileName) {
    ADD_TEMPLATE_JAR_PERMISSION.checkPermission();
    try {
        // compute the "template url" of the jarfile.
        File jarfile = new File(jarfileName);
        String jarURL = jarfile.toURI().toURL().toString();
        URL jarfileTemplateURL = jarfileTemplateURL(jarURL);
        // then nothing needs to be done.
        if (mcf_url_list.contains(jarfileTemplateURL))
            return true;
        for (int i = template_url_list.length; i-- > 0; ) if (jarfileTemplateURL.equals(template_url_list[i]))
            return true;
        // find and process templates in the jarfile.
        JarSearchResult searchResult = searchJarForTemplates(templates, jarURL, data);
        if (searchResult != JarSearchResult.None) {
            // add applicable rollup templates. (This will regenerate
            // other rollup templates, but that shouldn't hurt anything.)
            generateRollupTemplates(templates, data);
            // recreate the process root.
            createProcessRoot(templates);
        }
        // insert the new url at the beginning of the template list.
        if (searchResult != JarSearchResult.Mcf) {
            URL[] new_list = new URL[template_url_list.length + 1];
            // src
            System.arraycopy(// src
            template_url_list, // src
            0, // dest
            new_list, // dest
            1, template_url_list.length);
            new_list[0] = jarfileTemplateURL;
            template_url_list = new_list;
        }
        // create a dash package and add it to our list
        try {
            dashPackages.add(0, new DashPackage(jarfileTemplateURL));
        } catch (InvalidDashPackage idp) {
        }
        return true;
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    return false;
}
Also used : IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) InvalidDashPackage(net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage) URL(java.net.URL) InvalidDashPackage(net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage)

Example 3 with InvalidDashPackage

use of net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage in project processdash by dtuma.

the class TeamStartBootstrap method getDashPackageForFile.

private DashPackage getDashPackageForFile(File templateFile) throws MalformedURLException, InvalidDashPackage {
    String jarURL = templateFile.toURI().toURL().toString();
    URL url = new URL("jar:" + jarURL + "!/Templates/");
    DashPackage dashPackage = new DashPackage(url);
    return dashPackage;
}
Also used : InvalidDashPackage(net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage) DashPackage(net.sourceforge.processdash.templates.DashPackage) URL(java.net.URL)

Aggregations

InvalidDashPackage (net.sourceforge.processdash.templates.DashPackage.InvalidDashPackage)3 IOException (java.io.IOException)2 URL (java.net.URL)2 DashPackage (net.sourceforge.processdash.templates.DashPackage)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ZipFile (java.util.zip.ZipFile)1