Package org.pentaho.packageManagement

Examples of org.pentaho.packageManagement.Package


      // try and load any jar files and add to the classpath
      File[] contents = PACKAGES_DIR.listFiles();
      for (int i = 0 ; i < contents.length; i++) {
        if (contents[i].isDirectory()) {
          try {
            Package toLoad = getInstalledPackageInfo(contents[i].getName());
            boolean load;
            // Only perform the check against the current version of Weka if there exists
            // a Description.props file
            if (toLoad != null) {
View Full Code Here


   * @throws Exception if a version can't be found that satisfies the constraint
   * or an error occurs while communicating with the respository
   */
  public static Package mostRecentVersionWithRespectToConstraint(PackageConstraint toCheck)
    throws Exception {
    Package target = toCheck.getPackage();
    Package result = null;
   

    List<Object> availableVersions =
      PACKAGE_MANAGER.getRepositoryPackageVersions(target.getName());

    // version numbers will be in descending sorted order from the repository
    // we want the most recent version that meets the target constraint
    for (Object version : availableVersions) {
      Package candidate = PACKAGE_MANAGER.getRepositoryPackageInfo(target.getName(), version);
      if (toCheck.checkConstraint(candidate)) {
        /*System.out.println("**** Most recent version of " + target.getName()
            + "that meets the constraint " + toCheck.toString() + " is "
            + candidate.toString()); */
        result = candidate;
View Full Code Here

 
  public static void installPackageFromRepository(String packageName,
      String version, PrintStream... progress)
    throws Exception {   
    useCacheOrOnlineRepository();
    Package toLoad = getRepositoryPackageInfo(packageName);
   
    Object specialInstallMessage =
      toLoad.getPackageMetaDataElement("MessageToDisplayOnInstallation");
    if (specialInstallMessage != null &&
        specialInstallMessage.toString().length() > 0) {
      String siM = specialInstallMessage.toString();
      try {
        siM = Environment.getSystemWide().substitute(siM);
View Full Code Here

  }
 
  public static String installPackageFromArchive(String packageArchivePath,
      PrintStream... progress) throws Exception {
    useCacheOrOnlineRepository();   
    Package toInstall = PACKAGE_MANAGER.getPackageArchiveInfo(packageArchivePath);
   
    Object specialInstallMessage =
      toInstall.getPackageMetaDataElement("MessageToDisplayOnInstallation");
    if (specialInstallMessage != null &&
        specialInstallMessage.toString().length() > 0) {
      String siM = specialInstallMessage.toString();
      try {
        siM = Environment.getSystemWide().substitute(siM);
      } catch (Exception ex) {
        // quietly ignore
      }
      String message = "**** Special installation message ****\n"
        + siM
            + "\n**** Special installation message ****";
      for (PrintStream p : progress) {
        p.println(message);
      }
    }
   
    PACKAGE_MANAGER.installPackageFromArchive(packageArchivePath, progress);
   
    boolean loadIt = checkForMissingClasses(toInstall, progress);
    if (loadIt) {
      File packageRoot =
        new File(PACKAGE_MANAGER.getPackageHome() + File.separator
            + toInstall.getName());
      loadIt = checkForMissingFiles(toInstall, packageRoot, progress);
      if (loadIt) {
        loadPackageDirectory(packageRoot, false);
      }
    }
   
    return toInstall.getName();
  }
View Full Code Here

 
  public static String installPackageFromURL(URL packageURL, PrintStream... progress) throws Exception {
    useCacheOrOnlineRepository();   
    String packageName = PACKAGE_MANAGER.installPackageFromURL(packageURL, progress);
   
    Package installed = PACKAGE_MANAGER.getInstalledPackageInfo(packageName);
   
    Object specialInstallMessage =
      installed.getPackageMetaDataElement("MessageToDisplayOnInstallation");
    if (specialInstallMessage != null &&
        specialInstallMessage.toString().length() > 0) {
      String message = "**** Special installation message ****\n"
        + specialInstallMessage.toString()
            + "\n**** Special installation message ****";
      for (PrintStream p : progress) {
        p.println(message);
      }
    }
   
    boolean loadIt = checkForMissingClasses(installed, progress);
    if (loadIt) {
      File packageRoot =
        new File(PACKAGE_MANAGER.getPackageHome() + File.separator
            + installed.getName());
      loadIt = checkForMissingFiles(installed, packageRoot, progress);
      if (loadIt) {
        loadPackageDirectory(packageRoot, false);
      }
    }
View Full Code Here

  }
 
  private static void installPackageFromRepository(String packageName, String version,
      boolean force) throws Exception {
       
    Package toInstall = null;
    try {
      toInstall = getRepositoryPackageInfo(packageName, version);
    } catch (Exception ex) {
      System.err.println("[WekaPackageManager] Package " + packageName + " at version " + version
          + " doesn't seem to exist!");
      //System.exit(1);
      return;
    }
    // First check to see if this package is compatible with the base system
   
    if (!force) {
      boolean ok = toInstall.isCompatibleBaseSystem();
     
      if (!ok) {
        List<Dependency> baseSysDep = toInstall.getBaseSystemDependency();
        StringBuffer depList = new StringBuffer();
        for (Dependency bd : baseSysDep) {
          depList.append(bd.getTarget().toString() + " ");
        }
        System.err.println("Can't install package " + packageName
            + " because it requires " + depList.toString());
        return;
      }     
     
      // true if this package is already installed. In which case we need to check
      // if changing this package will impact other already installed packages
      boolean upOrDowngrading = false;
      if (toInstall.isInstalled()) {
        Package installedVersion = getInstalledPackageInfo(packageName);
        if (!toInstall.equals(installedVersion)) {

          System.out.println("Package " + packageName + "[" + installedVersion
              + "] is already installed. Replace with " + toInstall +" [y/n]?");
         
          String response = queryUser();
          if (response != null && (response.equalsIgnoreCase("n") ||
              response.equalsIgnoreCase("no"))) {
            return; // bail out here
          }
          upOrDowngrading = true;
        } else {
          System.out.println("Package " + packageName + "[" + installedVersion
              + "] is already installed. Install again [y/n]?");
          String response = queryUser();
          if (response != null && (response.equalsIgnoreCase("n") ||
              response.equalsIgnoreCase("no"))) {
            return; // bail out here
          }
        }
      }

      // Now get a full list of dependencies for this package and
      // check for any conflicts
      Map<String, List<Dependency>> conflicts = new HashMap<String, List<Dependency>>();
      List<Dependency> dependencies = getAllDependenciesForPackage(toInstall, conflicts);

      if (conflicts.size() > 0) {
        System.err.println("Package " + packageName + " requires the following packages:\n");
        Iterator<Dependency> depI = dependencies.iterator();
        while (depI.hasNext()) {
          Dependency d = depI.next();
          System.err.println("\t" + d);
        }
       
        System.err.println("\nThere are conflicting dependencies:\n");
        Set<String> pNames = conflicts.keySet();
        Iterator<String> pNameI = pNames.iterator();
        while (pNameI.hasNext()) {
          String pName = pNameI.next();
          System.err.println("Conflicts for " + pName);
          List<Dependency> confsForPackage = conflicts.get(pName);
          Iterator<Dependency> confs = confsForPackage.iterator();
          while (confs.hasNext()) {
            Dependency problem = confs.next();
            System.err.println("\t" + problem);
          }
        }
       
        System.err.println("Unable to continue with installation.");
        return; // bail out here.
      }
     
      // Next check all dependencies against what is installed and
      // inform the user about which installed packages will be altered. Also
      // build the list of only those packages that need to be installed or
      // upgraded (excluding those that are already installed and are OK).
      List<PackageConstraint> needsUpgrade = new ArrayList<PackageConstraint>();
      List<Package> finalListToInstall = new ArrayList<Package>();
     
      Iterator<Dependency> depI = dependencies.iterator();
      while (depI.hasNext()) {
        Dependency toCheck = depI.next();
        if (toCheck.getTarget().getPackage().isInstalled()) {
          String toCheckName =
            toCheck.getTarget().getPackage().
            getPackageMetaDataElement("PackageName").toString();
          Package installedVersion = PACKAGE_MANAGER.getInstalledPackageInfo(toCheckName);
          if (!toCheck.getTarget().checkConstraint(installedVersion)) {
            needsUpgrade.add(toCheck.getTarget());
            Package mostRecent = toCheck.getTarget().getPackage();
            if (toCheck.getTarget() instanceof
                org.pentaho.packageManagement.VersionPackageConstraint) {
              mostRecent =
                WekaPackageManager.mostRecentVersionWithRespectToConstraint(toCheck.getTarget());
            }
            finalListToInstall.add(mostRecent);
          }
        } else {
          Package mostRecent = toCheck.getTarget().getPackage();
          if (toCheck.getTarget() instanceof
              org.pentaho.packageManagement.VersionPackageConstraint) {
            mostRecent =
              WekaPackageManager.mostRecentVersionWithRespectToConstraint(toCheck.getTarget());
          }
          finalListToInstall.add(mostRecent);
        }
      }

      if (needsUpgrade.size() > 0) {
        System.out.println("The following packages will be upgraded in order to install "
            + packageName);
        Iterator<PackageConstraint> upI = needsUpgrade.iterator();
        while (upI.hasNext()) {
          PackageConstraint tempC = upI.next();
          System.out.println("\t" + tempC);
        }

        System.out.print("\nOK to continue [y/n]? > ");
        String response = queryUser();
        if (response != null && (response.equalsIgnoreCase("n") ||
            response.equalsIgnoreCase("no"))) {
          return; // bail out here
        }

        // now take a look at the other installed packages and see if
        // any would have a problem when these ones are upgraded
        boolean conflictsAfterUpgrade = false;
        List<Package> installed = getInstalledPackages();
        List<Package> toUpgrade = new ArrayList<Package>();
        upI = needsUpgrade.iterator();
        while (upI.hasNext()) {
          toUpgrade.add(upI.next().getPackage());
        }
       
        // add the actual package the user is wanting to install if it
        // is going to be an up/downgrade rather than a first install since
        // other installed packages may depend on the currently installed version
        // and thus could be affected after the up/downgrade
        toUpgrade.add(toInstall);
       
        for (int i = 0; i < installed.size(); i++) {
          Package tempP = installed.get(i);
          String tempPName = tempP.getName();
          boolean checkIt = true;
          for (int j = 0; j < needsUpgrade.size(); j++) {
            if (tempPName.equals(needsUpgrade.get(j).getPackage().getName())) {
              checkIt = false;
              break;
            }
          }

          if (checkIt) {
            List<Dependency> problem = tempP.getIncompatibleDependencies(toUpgrade);
            if (problem.size() > 0) {
              conflictsAfterUpgrade = true;

              System.err.println("Package " + tempP.getName() + " will have a compatibility" +
              "problem with the following packages after upgrading them:");
              Iterator<Dependency> dI = problem.iterator();
              while (dI.hasNext()) {
                System.err.println("\t" + dI.next().getTarget().getPackage());
              }
View Full Code Here

    result.append("Installed\tRepository\tPackage\n");
    result.append("=========\t==========\t=======\n");
   
    Iterator<Package> i = packageList.iterator();
    while (i.hasNext()) {
      Package p = i.next();
      String installedV = "-----    ";
      String repositoryV = "-----     ";
      if (p.isInstalled()) {
        Package installedP = getInstalledPackageInfo(p.getName());
        installedV = installedP.getPackageMetaDataElement("Version").toString() + "    ";
        try {
          Package repP = getRepositoryPackageInfo(p.getName());
          repositoryV = repP.getPackageMetaDataElement("Version").toString() + "     ";
        } catch (Exception ex) {
          // not at the repository
        }
      } else {
        repositoryV = p.getPackageMetaDataElement("Version").toString() + "     ";
View Full Code Here

          StringBuffer confirmList = new StringBuffer();
         
          for (int i = 0; i < selectedRows.length; i++) {
            String packageName = m_table.getValueAt(selectedRows[i],
                getColumnIndex(PACKAGE_COLUMN)).toString();
            Package p = null;
            try {
              p = WekaPackageManager.getRepositoryPackageInfo(packageName);
            } catch (Exception e1) {        
//              e1.printStackTrace();
  //            continue;
              // see if we can get installed package info
              try {
              p = WekaPackageManager.getInstalledPackageInfo(packageName);
              } catch (Exception e2) {
                e2.printStackTrace();
                continue;
              }
            }
           
            if (p.isInstalled()) {
              packageNames.add(packageName);
              confirmList.append(packageName + "\n");
            }
          }
         
View Full Code Here

        if (!enableInstall || !enableUninstall) {
          enableInstall = true; // we should always be able to install an already installed package
          String packageName = m_table.getValueAt(selectedRows[i],
              getColumnIndex(PACKAGE_COLUMN)).toString();
          try {
            Package p = WekaPackageManager.getRepositoryPackageInfo(packageName);
            if (!enableUninstall) {
              enableUninstall = p.isInstalled();
            }

            /*if (!enableInstall) {
              enableInstall = !p.isInstalled();
            } */
 
View Full Code Here

  //      String[] repVersions = getRepVersions2(p.getName(), repositoryV);
//        repositoryV = repositoryV + " " + repString;
       
        if (p.isInstalled()) {       
          try {
            Package installed = WekaPackageManager.getInstalledPackageInfo(p.getName());
            installedV = installed.getPackageMetaDataElement("Version").toString();           
          } catch (Exception ex) {
            ex.printStackTrace();
            displayErrorDialog("An error has occurred while trying to obtain" +
                " installed package info", ex);
          }
View Full Code Here

TOP

Related Classes of org.pentaho.packageManagement.Package

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.