Пример #1
0
 /**
  * Analyze a resource by checking its suffix and delegate to {@link #analyzeClass(Resource)},
  * {@link #analyzeJar(Resource)}, etc.
  *
  * @param res The resource to be analyzed.
  */
 protected void analyze(Resource res) throws BuildException {
   if (res.getName().endsWith(".class")) {
     analyzeClass(res);
   } else if (res.getName().endsWith(".jar")) {
     analyzeJar(res);
   } else if (res.getName().endsWith("/packageinfo")) {
     analyzePackageinfo(res);
   } else {
     // Just ignore all other files
   }
 }
  private void doExecute() throws BuildException {
    for (AddUser userAdder : users) {
      userAdder.execute();
    }

    final ExternalHostSystem host =
        new ExternalHostSystem(SUPPORTED_FEATURES, getHost(), getPort(), this, getShabang(), null);
    final ProtocolSessionBuilder builder = new ProtocolSessionBuilder();

    if (scripts == null) {
      scripts = new Union();
      scripts.add(new FileResource(script));
    }

    for (Iterator<?> it = scripts.iterator(); it.hasNext(); ) {
      final Resource resource = (Resource) it.next();
      try {
        final Runner runner = new Runner();

        try {

          final InputStream inputStream = resource.getInputStream();
          final String name = resource.getName();
          builder.addProtocolLines(
              name == null ? "[Unknown]" : name, inputStream, runner.getTestElements());
          runner.runSessions(host);

        } catch (UnsupportedOperationException e) {
          log("Resource cannot be read: " + resource.getName(), Project.MSG_WARN);
        }
      } catch (IOException e) {
        throw new BuildException("Cannot load script " + resource.getName(), e);
      } catch (Exception e) {
        log(e.getMessage(), Project.MSG_ERR);
        throw new BuildException(
            "[FAILURE] in script " + resource.getName() + "\n" + e.getMessage(), e);
      }
    }
  }
Пример #3
0
  public List<String> getKeyRings() throws IOException {
    List<String> keys = new ArrayList<String>();
    for (Resource resource : keyrings) {
      log("Include keyring: " + resource.getName());
      String key =
          FileUtils.readFully(
              new InputStreamReader(resource.getInputStream(), StandardCharsets.US_ASCII));
      if (key != null) {
        keys.add(key);
      }
    }

    return keys;
  }
Пример #4
0
 /**
  * Implementation of ResourceSelector.isSelected().
  *
  * @param resource The resource to check
  * @return whether the resource is selected
  * @see ResourceSelector#isSelected(Resource)
  */
 public boolean isSelected(Resource resource) {
   if (resource.isFilesystemOnly()) {
     // We have a 'resourced' file, so reconvert it and use
     // the 'old' implementation.
     FileResource fileResource = (FileResource) resource;
     File file = fileResource.getFile();
     String filename = fileResource.getName();
     File basedir = fileResource.getBaseDir();
     return isSelected(basedir, filename, file);
   } else {
     try {
       // How to handle non-file-Resources? I copy temporarily the
       // resource to a file and use the file-implementation.
       FileUtils fu = FileUtils.getFileUtils();
       File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false);
       Resource tmpResource = new FileResource(tmpFile);
       ResourceUtils.copyResource(resource, tmpResource);
       boolean isSelected =
           isSelected(tmpFile.getParentFile(), tmpFile.getName(), resource.toLongString());
       tmpFile.delete();
       return isSelected;
     } catch (UnsupportedOperationException uoe) {
       log(
           "The resource '"
               + resource.getName()
               + "' does not provide an InputStream, so it is not checked. "
               + "Akkording to 'selres' attribute value it is "
               + ((selectResourcesWithoutInputStream) ? "" : " not")
               + "selected.",
           Project.MSG_INFO);
       return selectResourcesWithoutInputStream;
     } catch (Exception e) {
       throw new BuildException(e);
     }
   }
 }
Пример #5
0
  public List<Map<String, Object>> getPackages() throws IOException {
    List<Map<String, Object>> packages = new ArrayList<Map<String, Object>>();

    for (SPK spk : spks) {
      log("Include SPK: " + spk.file.getName());

      // make sure file is cached locally
      if (spk.url != null) {
        log("Using " + spk.url);
        if (!spk.file.exists()) {
          spk.file.getParentFile().mkdirs();
        }
        if (spk.url == null) {
          spk.url = spk.url;
        }
        Get get = new Get();
        get.bindToOwner(this);
        get.setQuiet(true);
        get.setUseTimestamp(true);
        get.setSrc(spk.url);
        get.setDest(spk.file);
        get.execute();
      } else {
        log("Using " + spk.file);
      }

      // import SPK INFO
      Map<String, Object> info = new LinkedHashMap<String, Object>();

      TarFileSet tar = new TarFileSet();
      tar.setProject(getProject());
      tar.setSrc(spk.file);
      tar.setIncludes(INFO);
      for (Resource resource : tar) {
        if (INFO.equals(resource.getName())) {
          String text =
              FileUtils.readFully(
                  new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8));
          for (String line : text.split("\\R")) {
            String[] s = line.split("=", 2);
            if (s.length == 2) {
              if (s[1].startsWith("\"") && s[1].endsWith("\"")) {
                s[1] = s[1].substring(1, s[1].length() - 1);
              }
              importSpkInfo(info, s[0], s[1]);
            }
          }
        }
      }
      log(String.format("Imported %d fields from SPK: %s", info.size(), info.keySet()));

      // add thumbnails and snapshots
      if (spk.thumbnail.size() > 0) {
        info.put(THUMBNAIL, spk.thumbnail.toArray(new String[0]));
      }
      if (spk.snapshot.size() > 0) {
        info.put(SNAPSHOT, spk.snapshot.toArray(new String[0]));
      }

      // add user-defined fields
      info.putAll(spk.infoList);

      // automatically generate file size and checksum fields
      if (!info.containsKey(LINK)) {
        info.put(LINK, spk.url);
      }
      info.put(MD5, md5(spk.file));
      info.put(SIZE, spk.file.length());

      packages.add(info);
    }

    return packages;
  }
Пример #6
0
  /**
   * Tells which sources should be reprocessed based on the last modification date of targets.
   *
   * @param logTo where to send (more or less) interesting output.
   * @param source ResourceCollection.
   * @param mapper filename mapper indicating how to find the target Resources.
   * @param targets object able to map a relative path as a Resource.
   * @param granularity The number of milliseconds leeway to give before deciding a target is out of
   *     date.
   * @return ResourceCollection.
   * @since Ant 1.7
   */
  public static ResourceCollection selectOutOfDateSources(
      ProjectComponent logTo,
      ResourceCollection source,
      FileNameMapper mapper,
      ResourceFactory targets,
      long granularity) {
    if (source.size() == 0) {
      logTo.log("No sources found.", Project.MSG_VERBOSE);
      return Resources.NONE;
    }
    source = Union.getInstance(source);
    logFuture(logTo, source, granularity);

    Union result = new Union();
    for (Iterator iter = source.iterator(); iter.hasNext(); ) {
      Resource sr = (Resource) iter.next();
      String srName = sr.getName();
      srName = srName == null ? srName : srName.replace('/', File.separatorChar);

      String[] targetnames = null;
      try {
        targetnames = mapper.mapFileName(srName);
      } catch (Exception e) {
        logTo.log("Caught " + e + " mapping resource " + sr, Project.MSG_VERBOSE);
      }
      if (targetnames == null || targetnames.length == 0) {
        logTo.log(sr + " skipped - don\'t know how to handle it", Project.MSG_VERBOSE);
        continue;
      }
      Union targetColl = new Union();
      for (int i = 0; i < targetnames.length; i++) {
        targetColl.add(targets.getResource(targetnames[i].replace(File.separatorChar, '/')));
      }
      // find the out-of-date targets:
      Restrict r = new Restrict();
      r.add(
          new And(
              new ResourceSelector[] {
                Type.FILE,
                new Or(new ResourceSelector[] {NOT_EXISTS, new Outdated(sr, granularity)})
              }));
      r.add(targetColl);
      if (r.size() > 0) {
        result.add(sr);
        Resource t = (Resource) (r.iterator().next());
        logTo.log(
            sr.getName()
                + " added as "
                + t.getName()
                + (t.isExists() ? " is outdated." : " doesn\'t exist."),
            Project.MSG_VERBOSE);
        continue;
      }
      // log uptodateness of all targets:
      logTo.log(
          sr.getName()
              + " omitted as "
              + targetColl.toString()
              + (targetColl.size() == 1 ? " is" : " are ")
              + " up to date.",
          Project.MSG_VERBOSE);
    }
    return result;
  }