Package org.apache.tools.ant

Examples of org.apache.tools.ant.Project


    // let's convert the message (which is only a bundle key right now) to the actual localized message
    message = Msg.createMsg(m_bundle, m_locale, message, m_arguments.toArray()).toString();

    // if property is set, put the message text in that property, otherwise, we echo the message
    if (m_property != null) {
      Project proj = getOwningTarget().getProject();
      proj.setNewProperty(m_property, message);
    }
    else {
      super.execute();
    }
View Full Code Here


    bpInfo.postProcessUsingMap(ignoredReferencedPackages, allImpExpPkgs);
    //log(bpInfo.toString(), Project.MSG_INFO);

    // Data collection done - write back properties
    final Project proj = getProject();

    if(!"".equals(exportsProperty)) {
      // A property name for the Export-Package header value has been specified
      final String exportsVal = proj.getProperty(exportsProperty);
      if (BundleManifestTask.isPropertyValueEmpty(exportsVal)) {
        // No value given, shall it be derived?
        if (!bImportsOnly) {
          if (0==providedExportSet.size()) {
            proj.setProperty(exportsProperty,
                             BundleManifestTask.BUNDLE_EMPTY_STRING);
            log("No packages exported, leaving '" +exportsProperty +"' empty.",
                Project.MSG_VERBOSE);
          } else {
            final String newExportsVal
              = buildExportPackagesValue(providedExportSet);
            log("Setting '" +exportsProperty +"' to '"+newExportsVal +"'",
                Project.MSG_VERBOSE);
            proj.setProperty(exportsProperty, newExportsVal);
          }
        }
      } else {
        // Export-Package given; add version and uses directives.
        final String newExportsVal = validateExportPackagesValue(exportsVal);
        if (!exportsVal.equals(newExportsVal)) {
          log("Updating \"" +exportsProperty +"\" to \""+newExportsVal +"\"",
              Project.MSG_VERBOSE);
          proj.setProperty(exportsProperty, newExportsVal);
        }
      }
    }


    if(!"".equals(importsProperty)) {
      String importsVal = proj.getProperty(importsProperty);
      if (BundleManifestTask.isPropertyValueEmpty(importsVal)) {
        // No Import-Package given; use derived value.
        if (0==importSet.size()) {
          log("No packages to import, leaving \"" +importsProperty +"\" empty.",
              Project.MSG_VERBOSE);
          proj.setProperty(importsProperty,
                           BundleManifestTask.BUNDLE_EMPTY_STRING);
        } else {
          importsVal = toString(importSet, ",");
          log("Setting \"" +importsProperty +"\" to \""+importsVal +"\"",
              Project.MSG_VERBOSE);
          proj.setProperty(importsProperty, importsVal);
        }
      } else {
        // Import-Package given; check that all derived packages are
        // present and that there are no duplicated packages.
        final TreeSet givenImportSet = new TreeSet();
        final Iterator impIt = Util.parseEntries("import.package",importsVal,
                                                 true, true, false );
        while (impIt.hasNext()) {
          final Map impEntry = (Map) impIt.next();
          final String pkgName = (String) impEntry.get("$key");
          if (!givenImportSet.add( pkgName )) {
            final String msg = "The package '" +pkgName
              +"' is mentioned twice in the given 'Import-Package' manifest "
              +"header: '" +importsVal +"'.";
            log(msg, Project.MSG_ERR);
            throw new BuildException(msg, getLocation());
          }
        }
        givenImportSet.removeAll(bpInfo.getProvidedPackages());
        final TreeSet missingImports = new TreeSet(importSet);
        missingImports.removeAll(givenImportSet);
        if (0<missingImports.size()) {
          log("External packages: "+importSet,      Project.MSG_ERR);
          log("Imported packages: "+givenImportSet, Project.MSG_ERR);
          log("Provided packages: "+bpInfo.getProvidedPackages(),
              Project.MSG_ERR);

          final String msg = "The following external packages are used by "
            +"the bundle but not mentioned in the Import-Package manifest "
            +"header: " +missingImports;
          log(msg, Project.MSG_ERR );
          if (failOnImports) {
            throw new BuildException(msg, getLocation());
          }
        }
        final TreeSet extraImports = new TreeSet(givenImportSet);
        extraImports.removeAll(importSet);
        if (0<extraImports.size()) {
          log("External packages: "+importSet, Project.MSG_ERR);
          log("Imported packages: "+givenImportSet, Project.MSG_ERR);

          log("The following packages are mentioned in the Import-Package"
              +" manifest header but not used by the included classes: "
             +extraImports, Project.MSG_WARN );
        }
      }
    }

    // Try to be a bit clever when writing back bundle activator
    if(!"".equals(activatorProperty) && bSetActivator) {
      final String activatorVal = proj.getProperty(activatorProperty);
      if (BundleManifestTask.isPropertyValueEmpty(activatorVal)) {
        // No Bundle-Activator given; use derived value if possible.
        switch(bpInfo.countProvidedActivatorClasses()) {
        case 0:
          if (!bActivatorOptional) {
            final String msg1 = "Requested to derive Bundle-Activator but "
              +"there is no class implementing BundleActivator.";
            log(msg1, Project.MSG_ERR);
            if (failOnActivator) {
              throw new BuildException(msg1, getLocation());
            }
          }
          break;
        case 1:
          String clazz = bpInfo.getActivatorClass();
          proj.setProperty(activatorProperty, clazz);
          break;
        default:
          final String msg2 = "Manual selection of Bundle-Activator "
            +"is needed since the set of included classes contains "
            +"more than one candidate: "
            +bpInfo.providedActivatorClassesAsString();
          log(msg2, Project.MSG_ERR);
          if (failOnActivator) {
            throw new BuildException(msg2, getLocation());
          }
        }
      } else {
        // Bundle-Activator given; check that it is correct.
        if (0==bpInfo.countProvidedActivatorClasses()) {
          log("No class implementing BundleActivator found", Project.MSG_ERR);
        } else {
          final String givenClazz = proj.getProperty(activatorProperty).trim();
          if (!bpInfo.providesActivatorClass(givenClazz)) {
            final String msg = "The specified BundleActivator '" +givenClazz
              +"' is not a member of the set of included classes that"
              +"  implements BundleActivator: "
              +bpInfo.providedActivatorClassesAsString();
            log(msg, Project.MSG_WARN);
            if (failOnActivator) {
              throw new BuildException(msg, getLocation());
            }
          }
        }
      }
    }

    final Set foundationMissing = new TreeSet();
    final Set minimumMissing    = new TreeSet();
    final Set smfMissing        = new TreeSet();

    for(Iterator it = bpInfo.getReferencedClasses().iterator(); it.hasNext();) {
      final String s = (String)it.next();
      if(s.endsWith("[]")) {
      } else {
        if(!bpInfo.providesClass(s)) {
          if(bPrintClasses) {
            System.out.println(s);
          }
          if(!EE.isFoundation(s)) {
            if(!isImported(s)) {
              foundationMissing.add(s);
            }
          }
          if(!EE.isMinimum(s)) {
            if(!isImported(s)) {
              minimumMissing.add(s);
            }
          }
          if(!EE.isSMF(s)) {
            if(!isImported(s)) {
              smfMissing.add(s);
            }
          }
        }
      }
    }

    if(bCheckFoundationEE) {
      checkEE(foundationMissing, "foundation");
    }

    if(bCheckMinimumEE) {
      checkEE(minimumMissing, "minimum");
    }

    if(bCheckSMFEE) {
      checkEE(smfMissing, "SMF");
    }

    /* Handle the implicitImport flag. */
    if(bImplicitImports
       && !"".equals(importsProperty)
       && !"".equals(exportsProperty) ) {
      String importsSpec = proj.getProperty(importsProperty);
      log("implicitImport - before: "+importsSpec, Project.MSG_VERBOSE);
      importSet.clear();
      if (!BundleManifestTask.isPropertyValueEmpty(importsSpec)) {
        final Iterator impIt = Util.parseEntries("import.package",importsSpec,
                                                 true, true, false );
        while (impIt.hasNext()) {
          final Map impEntry = (Map) impIt.next();
          importSet.add( impEntry.get("$key") );
        }
      } else {
        // Spec is empty, must remove the emtpy value marker for now.
        importsSpec = "";
      }
      final StringBuffer sb = new StringBuffer(importsSpec);

      final String exportsSpec = proj.getProperty(exportsProperty);
      if (!BundleManifestTask.isPropertyValueEmpty(exportsSpec)) {
        final Iterator expIt = Util.parseEntries("export.package",exportsSpec,
                                                 true, true, false );
        while (expIt.hasNext()) {
          final Map expEntry = (Map) expIt.next();
          String pkg = (String) expEntry.get("$key");
          if (!importSet.contains(pkg)) {
            final String ver = (String) expEntry.get("version");
            final String sver = (String) expEntry.get("specification-version");
            if (null!=ver) {
              pkg += ";version="+ver;
            } else if (null!=sver) {
              pkg += ";specification-version="+sver;
            }
            log("implicitImport - adding: "+pkg, Project.MSG_DEBUG);
            if (0<sb.length()) {
              sb.append(",");
            }
            sb.append(pkg);
          }
        }
        importsSpec = sb.toString();
        if (0==importsSpec.length()) {
          importsSpec = BundleManifestTask.BUNDLE_EMPTY_STRING;
        }
        log("implicitImport - after: "+importsSpec, Project.MSG_VERBOSE);
        proj.setProperty(importsProperty, importsSpec );
      }
    }
  }
View Full Code Here

    String line = in.readLine();
    while (null!=line) {
      srcRoots.add(line.trim());
      line = in.readLine();
    }
    Project proj = getProject();
    if (null!=srcPropertyName) {
      String sourcepath = proj.getProperty(srcPropertyName);
      if (null==sourcepath) sourcepath = "";

      StringBuffer sb
        = new StringBuffer(sourcepath.length() +50*srcRoots.size());
      sb.append(sourcepath);

      for (Iterator it = srcRoots.iterator(); it.hasNext(); ) {
        if (sb.length()>0) sb.append(",");
        sb.append(it.next());
      }
      proj.setProperty(srcPropertyName, sb.toString());
    }
    if (null!=srcPathId) {
      Path path = new Path(proj);
      for (Iterator it = srcRoots.iterator(); it.hasNext(); ) {
        path.setLocation(new File( (String) it.next() ));
      }
      log("Created path: "+path,Project.MSG_DEBUG);
      Path oldPath = (Path) proj.getReference(srcPathId);
      if (null!=oldPath) {
        oldPath.add(path);
        log(srcPathId +" after extension: "+oldPath, Project.MSG_VERBOSE);
      } else {
        proj.addReference(srcPathId, path);
        log("Created \"" +srcPathId +"\": "+path, Project.MSG_VERBOSE);
      }
    }
  }
View Full Code Here

          pkgs.add(exPkg);
        }
      }
      line = in.readLine();
    }
    Project proj = getProject();
    if (null!=pkgPropertyName) {
      String packagenames = proj.getProperty(pkgPropertyName);
      if (null==packagenames) packagenames = "";

      StringBuffer sb
        = new StringBuffer(packagenames.length() +50*pkgs.size());
      sb.append(packagenames);

      for (Iterator it =pkgs.iterator(); it.hasNext(); ) {
        if (sb.length()>0) sb.append(",");
        sb.append(it.next());
      }
      proj.setProperty(pkgPropertyName, sb.toString());
      log("Setting property '" +pkgPropertyName +"' -> " +sb.toString(),
          Project.MSG_VERBOSE);
    }
  }
View Full Code Here

   *         then its list item will be a zip file set.
   */
  public List getFileSets(boolean failOnClassPath)
  {
    final List res = new ArrayList();
    final Project proj = getProject();

    if (dir==null) {
      throw new BuildException("The dir attribute (root of the bundle "
                               +"class path) is required.");
    } else if (!dir.exists()) {
View Full Code Here

      }
      if (st.hasMoreTokens())
        sb.append(",");
    }

    final Project proj = getProject();

    // Conversion done - write back properties
    if (null!=propertyName) {
      proj.setProperty(propertyName, sb.toString());
      log("Converted \"" +bundleClasspath +"\" to pattern \""
          +sb.toString() +"\"",
          Project.MSG_VERBOSE);
    }

    if (null!=filesetId) {
      final FileSet fileSet = new FileSet();
      fileSet.setProject(proj);
      if (dir.exists()) {
        fileSet.setDir(dir);
        fileSet.setIncludes(sb.toString());
      } else {
        log("Bundle class path root dir '" +dir
            +"' does not exist, returning empty file set.",
            Project.MSG_DEBUG);
        fileSet.setDir(new File("."));
        fileSet.setExcludes("**/*");
      }
      proj.addReference(filesetId, fileSet);
      log("Converted bundle class path \"" +bundleClasspath
          +"\" to file set with id '" +filesetId
          +"' and files \"" +fileSet +"\"",
          Project.MSG_VERBOSE);
    }
View Full Code Here

    long r = value -i*factor; // Remainder.
    // Convert r to a decimal fraction
    double fraction  = ((double) r)/((double) factor);
    formatedValue = formatValue(i, fraction);

    Project project = getProject();
    project.setProperty(property, formatedValue +sep +suffixes[ix] +unit);
  }
View Full Code Here

   */
  private void addAttributesFromProperties(Manifest mf)
  {
    if (null!=attributePropertyPrefix) {
      int       prefixLength = attributePropertyPrefix.length();
      Project   project      = getProject();
      Manifest.Section mainS = mf.getMainSection();
      Hashtable properties   = project.getProperties();
      for (Enumeration pe = properties.keys(); pe.hasMoreElements();) {
        String key = (String) pe.nextElement();
        if (key.startsWith(attributePropertyPrefix)) {
          String attrName  = key.substring(prefixLength);
          String attrValue = (String) properties.get(key);
View Full Code Here

   * prefix and the value will be the property value.
   */
  private void updatePropertiesFromMainSectionAttributeValues(Manifest mf)
  {
    if (null!=attributePropertyPrefix) {
      Project   project      = getProject();
      Manifest.Section mainS = mf.getMainSection();
      for (Enumeration ae = mainS.getAttributeKeys(); ae.hasMoreElements();) {
        String key = (String) ae.nextElement();
        Manifest.Attribute attr = mainS.getAttribute(key);
        // Ensure that the default case is used for OSGi specified attributes
        String propKey = attributePropertyPrefix
          + (osgiAttrNamesMap.containsKey(key)
             ? osgiAttrNamesMap.get(key) : attr.getName() );
        String propVal = attr.getValue();
        log("setting '" +propKey +"'='"+propVal+"'.", Project.MSG_VERBOSE);
        project.setProperty(propKey,propVal);
      }
    }
  }
View Full Code Here

   * @return
   */
  protected int execInOtherVM(String[] args) {
    try {

      Project project = getProject();
      PumpStreamHandler handler = new LogStreamHandler(this, verbose ? Project.MSG_VERBOSE : Project.MSG_INFO,
          Project.MSG_WARN);

      // replace above two lines with what follows as an aid to debugging when running the unit tests....
      // LogStreamHandler handler = new LogStreamHandler(this,
      // Project.MSG_INFO, Project.MSG_WARN) {
      //
      // ByteArrayOutputStream baos = new ByteArrayOutputStream();
      // /* (non-Javadoc)
      // * @see org.apache.tools.ant.taskdefs.PumpStreamHandler#createProcessOutputPump(java.io.InputStream,
      // java.io.OutputStream)
      // */
      // protected void createProcessErrorPump(InputStream is,
      // OutputStream os) {
      // super.createProcessErrorPump(is, baos);
      // }
      //
      // /* (non-Javadoc)
      // * @see org.apache.tools.ant.taskdefs.LogStreamHandler#stop()
      // */
      // public void stop() {
      // byte[] written = baos.toByteArray();
      // System.err.print(new String(written));
      // super.stop();
      // }
      // };

      Execute exe = new Execute(handler);
      exe.setAntRun(project);
      exe.setWorkingDirectory(project.getBaseDir());
      exe.setCommandline(args);
      try {
        if (executingInOtherVM) {
          String s = "already running in other vm?";
          throw new BuildException(s, location);
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.Project

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.