Example #1
0
 protected void addToPath(Path path, File f) throws Exception {
   if (!osgi || !f.isDirectory()) {
     path.createPathElement().setLocation(f);
     return;
   }
   File manifest = new File(f, "META-INF/MANIFEST.MF");
   if (!manifest.exists()) {
     path.createPathElement().setLocation(f);
     return;
   }
   BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
   List /* <String> */ cp = bundleInfo.getClasspath();
   if (cp == null) {
     path.createPathElement().setLocation(f);
     return;
   }
   for (int i = 0; i < cp.size(); i++) {
     String p = (String) cp.get(i);
     if (p.equals(".")) {
       path.createPathElement().setLocation(f);
     } else {
       path.createPathElement().setLocation(new File(f, p));
     }
   }
 }
Example #2
0
  private void addSourcePath(Resource resource, Javadoc javadoc, Path source) {
    //
    // handle the target resource
    //

    if (null != resource.getBaseDir()) {
      File src = new File(resource.getBaseDir(), "target/build/main");
      if (src.exists()) {
        log("Adding src path: " + src);
        source.createPathElement().setLocation(src);
        final DirSet packages = new DirSet();
        packages.setDir(src);
        packages.setIncludes("**/*");
        String excludes = getPackageExcludes(resource);
        if (null != excludes) {
          packages.setExcludes(excludes);
        }
        javadoc.addPackageset(packages);
      }
    }

    // add providers

    String path = resource.getResourcePath();
    Resource[] providers = resource.getAggregatedProviders(Scope.RUNTIME, true, false);
    for (int i = 0; i < providers.length; i++) {
      Resource provider = providers[i];
      if (provider.getResourcePath().startsWith(path)) {
        String flag = provider.getProperty("project.javadoc.exclude", "false");
        if ("false".equals(flag)) {
          File basedir = provider.getBaseDir();
          if (null != basedir) {
            File src = new File(basedir, "target/build/main");
            if (src.exists()) {
              log("Adding src path: " + src);
              source.createPathElement().setLocation(src);
              final DirSet packages = new DirSet();
              packages.setDir(src);
              packages.setIncludes("**/**");
              String excludes = getPackageExcludes(provider);
              if (null != excludes) {
                packages.setExcludes(excludes);
              }
              javadoc.addPackageset(packages);
            }
          }
        }
      }
    }
  }
Example #3
0
  private Path buildClasspath(Build build, Scope scope, String tag) {
    List<File> jars = build.getSolver().getClasspath(scope, tag);
    Path cp = new Path(getProject());
    // output folder
    PathElement of = cp.createPathElement();
    of.setLocation(build.getConfig().getOutputDirectory(scope));
    if (!scope.isDefault()) {
      of.setLocation(build.getConfig().getOutputDirectory(Scope.compile));
    }

    // add project dependencies
    for (File folder : buildDependentProjectsClasspath(build)) {
      PathElement element = cp.createPathElement();
      element.setLocation(folder);
    }

    // jars
    for (File jar : jars) {
      PathElement element = cp.createPathElement();
      element.setLocation(jar);
    }

    return cp;
  }
Example #4
0
  /** Constructor. */
  public RunClasspath() {
    super(ProjectLocator.getAntProject());
    type = "RUN";
    createPathElement().setLocation(ModulesTxt.instance().getParentFile());
    for (Module module : ModuleTree.instance()) {
      append(makeRunClasspathPart(module));
    }

    // add the files from the CLASSPATH environement variable
    String classpath = System.getenv("CLASSPATH");
    if (classpath != null && !classpath.trim().isEmpty()) {
      final Path path = new Path(ProjectLocator.getAntProject());
      for (String pathStr : classpath.split(File.pathSeparator)) {
        path.createPathElement().setPath(pathStr);
      }
      append(path);
      System.out.println("adding $CLASSPATH to RunClassPath: " + path);
    }
  }
Example #5
0
  /**
   * Add the directories matched by the nested dirsets to the resulting packages list and the base
   * directories of the dirsets to the Path. It also handles the packages and excludepackages
   * attributes and elements.
   *
   * @param resultantPackages a list to which we add the packages found
   * @param sourcePath a path to which we add each basedir found
   * @since 1.5
   */
  private void parsePackages(List<String> resultantPackages, Path sourcePath) {
    List<String> addedPackages = new ArrayList<String>();
    List<DirSet> dirSets = new ArrayList<DirSet>(packageSets);

    // for each sourcePath entry, add a directoryset with includes
    // taken from packagenames attribute and nested package
    // elements and excludes taken from excludepackages attribute
    // and nested excludepackage elements
    if (this.sourcePath != null) {
      PatternSet ps = new PatternSet();
      if (packageNames.size() > 0) {
        for (String pn : packageNames) {
          String pkg = pn.replace('.', '/');
          if (pkg.endsWith("*")) {
            pkg += "*";
          }
          ps.createInclude().setName(pkg);
        }
      } else {
        ps.createInclude().setName("**");
      }

      for (String epn : excludePackageNames) {
        String pkg = epn.replace('.', '/');
        if (pkg.endsWith("*")) {
          pkg += "*";
        }
        ps.createExclude().setName(pkg);
      }

      String[] pathElements = this.sourcePath.list();
      for (String pathElement : pathElements) {
        File dir = new File(pathElement);
        if (dir.isDirectory()) {
          DirSet ds = new DirSet();
          ds.setDefaultexcludes(useDefaultExcludes);
          ds.setDir(dir);
          ds.createPatternSet().addConfiguredPatternset(ps);
          dirSets.add(ds);
        } else {
          log.warn("Skipping " + pathElement + " since it is no directory.");
        }
      }
    }

    for (DirSet ds : dirSets) {
      File baseDir = ds.getDir(getProject());
      log.debug("scanning " + baseDir + " for packages.");
      DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
      String[] dirs = dsc.getIncludedDirectories();
      boolean containsPackages = false;
      for (String dir : dirs) {
        // are there any groovy or java files in this directory?
        File pd = new File(baseDir, dir);
        String[] files =
            pd.list(
                new FilenameFilter() {
                  public boolean accept(File dir1, String name) {
                    if (!includeNoSourcePackages && name.equals("package.html")) return true;
                    final StringTokenizer tokenizer = new StringTokenizer(extensions, ":");
                    while (tokenizer.hasMoreTokens()) {
                      String ext = tokenizer.nextToken();
                      if (name.endsWith(ext)) return true;
                    }
                    return false;
                  }
                });

        for (String filename : Arrays.asList(files)) {
          sourceFilesToDoc.add(dir + File.separator + filename);
        }

        if (files.length > 0) {
          if ("".equals(dir)) {
            log.warn(
                baseDir
                    + " contains source files in the default package,"
                    + " you must specify them as source files not packages.");
          } else {
            containsPackages = true;
            String pn = dir.replace(File.separatorChar, '.');
            if (!addedPackages.contains(pn)) {
              addedPackages.add(pn);
              resultantPackages.add(pn);
            }
          }
        }
      }
      if (containsPackages) {
        // We don't need to care for duplicates here,
        // Path.list does it for us.
        sourcePath.createPathElement().setLocation(baseDir);
      } else {
        log.verbose(baseDir + " doesn't contain any packages, dropping it.");
      }
    }
  }
Example #6
0
 /**
  * Add a reference to the installed/deployed file for processing in Ant.
  *
  * @param file
  */
 private void reference(File file) {
   if (installedArtifacts != null) {
     installedArtifacts.createPathElement().setLocation(file);
   }
 }
Example #7
0
  /** Make part of the run classpath. */
  private Path makeRunClasspathPart(Module module) {
    Path classpathPart = new Path(ProjectLocator.getAntProject());
    File targetClassesDir = module.getTargetClasses();
    classpathPart.createPathElement().setLocation(targetClassesDir);
    classpathPart.createPathElement().setLocation(module.getSrc());
    // System.out.println("RunClasspath:" + m + " " + m.getSrc());
    classpathPart.createPathElement().setLocation(module.getResourcesDir());
    classpathPart.createPathElement().setLocation(module.getConfigsDir());

    // see if we should add the 64 bit library to the classpath
    // NOTE: we want the 64 bit library directory in the classpath
    // since ptolemy.data.expr.UtilityFunctions.loadLibrary() searches
    // the classpath for a JNI library if it is not found in
    // java.library.path.
    if (LibPath.use64BitLibs()) {
      classpathPart.createPathElement().setLocation(module.getLib64Dir());
    }
    classpathPart.createPathElement().setLocation(module.getLibDir());
    classpathPart.createPathElement().setLocation(module.getLibImagesDir());

    // Add target jar if the target classes dir does not exist
    if (!targetClassesDir.exists()) {
      if (module.getTargetJar().exists()) {
        classpathPart.createPathElement().setLocation(module.getTargetJar());
      }
    }
    // End add target jar
    if (!module.getLibDir().exists()) {
      return classpathPart;
    }

    // Get jars from the lib directory.
    if (module.getLibDir().isDirectory()) {
      // use wildcards to reduce the size of the classpath.
      // this gets around the maximum path length on windows.
      DirSet jarDirs = new DirSet();
      jarDirs.setProject(ProjectLocator.getAntProject());
      jarDirs.setDir(module.getLibDir());
      jarDirs.setIncludes("**/*");
      Iterator<Resource> i = jarDirs.iterator();
      while (i.hasNext()) {
        Resource resource = i.next();
        if (resource instanceof FileResource) {
          File file = ((FileResource) resource).getFile();
          // System.out.println(file);
          if (file.isDirectory()) {
            File wildcardFile = new File(file, "*");
            classpathPart.createPathElement().setLocation(wildcardFile);
            // System.out.println("adding to cp: " + wildcardFile);
          }
        }
      }
    }
    // Add the jars in ptolemy, which are located in src/lib
    if (module.isPtolemy()) {
      File srcFile = module.getSrc();
      File srcLibDir = new File(srcFile, "lib");
      if (srcLibDir.isDirectory()) {
        File wildcardFile = new File(srcLibDir, "*");
        classpathPart.createPathElement().setLocation(wildcardFile);
      }
    }

    // add the workflow demos directory so that the demos may be accessed
    // by ptolemy.actor.gui.HTMLViewer when showing the Help documentation
    // see http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5194
    File userModuleWorkflowDir =
        new File(
            DotKeplerManager.getInstance().getPersistentModuleWorkflowsDirString()
                + File.separator
                + module.getName()
                + File.separator
                + "demos");

    File systemModuleDemoDir = module.getDemosDir();
    // NOTE: the first time kepler starts with a new version of a module,
    // the demos directories have not been copied into KeplerData. if
    // the demo directory exists for the module in the location where
    // kepler is installed, add the demo directory for where it will be
    // copied once kepler starts.
    // see http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5895
    if (systemModuleDemoDir.exists() && systemModuleDemoDir.isDirectory()) {

      // it appears that a directory needs to exist before it can be added
      // to the classpath
      if (!userModuleWorkflowDir.exists() && !userModuleWorkflowDir.mkdirs()) {
        PrintError.message("Could not create directory " + userModuleWorkflowDir);
      }
      classpathPart.createPathElement().setLocation(userModuleWorkflowDir);
    }
    return classpathPart;
  }
  @Override
  public void execute() throws BuildException {
    Project antProject = getProject();

    // get the SDK location
    String sdkLocation = antProject.getProperty(ProjectProperties.PROPERTY_SDK);

    // check if it's valid and exists
    if (sdkLocation == null || sdkLocation.length() == 0) {
      throw new BuildException("SDK Location is not set.");
    }

    File sdk = new File(sdkLocation);
    if (sdk.isDirectory() == false) {
      throw new BuildException(String.format("SDK Location '%s' is not valid.", sdkLocation));
    }

    // get the target property value
    String targetHashString = antProject.getProperty(ProjectProperties.PROPERTY_TARGET);
    if (targetHashString == null) {
      throw new BuildException("Android Target is not set.");
    }

    // load up the sdk targets.
    final ArrayList<String> messages = new ArrayList<String>();
    SdkManager manager =
        SdkManager.createManager(
            sdkLocation,
            new ISdkLog() {
              public void error(Throwable t, String errorFormat, Object... args) {
                if (errorFormat != null) {
                  messages.add(String.format("Error: " + errorFormat, args));
                }
                if (t != null) {
                  messages.add("Error: " + t.getMessage());
                }
              }

              public void printf(String msgFormat, Object... args) {
                messages.add(String.format(msgFormat, args));
              }

              public void warning(String warningFormat, Object... args) {
                messages.add(String.format("Warning: " + warningFormat, args));
              }
            });

    if (manager == null) {
      // since we failed to parse the SDK, lets display the parsing output.
      for (String msg : messages) {
        System.out.println(msg);
      }
      throw new BuildException("Failed to parse SDK content.");
    }

    // resolve it
    IAndroidTarget androidTarget = manager.getTargetFromHashString(targetHashString);

    if (androidTarget == null) {
      throw new BuildException(String.format("Unable to resolve target '%s'", targetHashString));
    }

    // display it
    System.out.println("Project Target: " + androidTarget.getName());
    if (androidTarget.isPlatform() == false) {
      System.out.println("Vendor: " + androidTarget.getVendor());
    }
    System.out.println("Platform Version: " + androidTarget.getApiVersionName());
    System.out.println("API level: " + androidTarget.getApiVersionNumber());

    // sets up the properties to find android.jar/framework.aidl
    String androidJar = androidTarget.getPath(IAndroidTarget.ANDROID_JAR);
    String androidAidl = androidTarget.getPath(IAndroidTarget.ANDROID_AIDL);
    antProject.setProperty(PROPERTY_ANDROID_JAR, androidJar);
    antProject.setProperty(PROPERTY_ANDROID_AIDL, androidAidl);

    // sets up the boot classpath

    // create the Path object
    Path bootclasspath = new Path(antProject);

    // create a PathElement for the framework jar
    PathElement element = bootclasspath.createPathElement();
    element.setPath(androidJar);

    // create PathElement for each optional library.
    IOptionalLibrary[] libraries = androidTarget.getOptionalLibraries();
    if (libraries != null) {
      HashSet<String> visitedJars = new HashSet<String>();
      for (IOptionalLibrary library : libraries) {
        String jarPath = library.getJarPath();
        if (visitedJars.contains(jarPath) == false) {
          visitedJars.add(jarPath);

          element = bootclasspath.createPathElement();
          element.setPath(library.getJarPath());
        }
      }
    }

    // finally sets the path in the project with a reference
    antProject.addReference(REF_CLASSPATH, bootclasspath);

    // find the file to import, and import it.
    String templateFolder = androidTarget.getPath(IAndroidTarget.TEMPLATES);

    // make sure the file exists.
    File templates = new File(templateFolder);
    if (templates.isDirectory() == false) {
      throw new BuildException(
          String.format("Template directory '%s' is missing.", templateFolder));
    }

    // now check the rules file exists.
    File rules = new File(templateFolder, ANDROID_RULES);
    if (rules.isFile() == false) {
      throw new BuildException(String.format("Build rules file '%s' is missing.", templateFolder));
    }

    // set the file location to import
    setFile(rules.getAbsolutePath());

    // and import it
    super.execute();
  }