コード例 #1
0
  @Override
  public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {

    EnvVars env = build.getEnvironment(listener);
    env.overrideAll(build.getBuildVariables());

    EnvVariableResolver helper = new EnvVariableResolver(build, listener);

    boolean success = true;
    System.out.println("Loading Blueprint !");

    int counter = 1;
    for (BlueprintParam param : params) {

      System.out.println("Creating package from directory : " + param.getBlueprintPath());

      // Resolve any environment variables in the parameters
      BlueprintParam fparam =
          new BlueprintParam(
              helper.replaceBuildParamWithValue(param.getServerUrl()),
              helper.replaceBuildParamWithValue(param.getUserName()),
              helper.replaceBuildParamWithValue(param.getPassword()),
              helper.replaceBuildParamWithValue(param.getTenant()),
              param.getPackageBlueprint(),
              env.get("WORKSPACE") + "/" + param.getBlueprintPath(),
              param.getOverWrite(),
              param.getPublishBlueprint(),
              param.getServiceCategory());

      final Blueprint blueprint = newBlueprint(listener.getLogger(), fparam);

      try {
        if (blueprint.Create()) {
          this.blueprintList.add(blueprint);

        } else {
          build.setResult(Result.FAILURE);
          success = false;
          break;
        }
      } catch (ArchiveException e) {
        e.printStackTrace();
      }
    }
    return success;
  }
コード例 #2
0
    public boolean accept(Path file) {
      try {
        FileSystem fs = file.getFileSystem(conf);
        boolean unpack = conf.getBoolean(unpackParamName, true);

        if (defaultIgnores.accept(file) && fs.getFileStatus(file).isDir() == false) {
          String URI = file.toUri().toString();

          // detect whether a file is likely to be an archive
          // TODO extend to other known types
          if (unpack && URI.toLowerCase().endsWith(".zip")) {
            FSDataInputStream fis = null;
            try {
              fis = fs.open(file);
              ArchiveInputStream input =
                  new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(fis));
              ArchiveEntry entry = null;
              while ((entry = input.getNextEntry()) != null) {
                String name = entry.getName();
                long size = entry.getSize();
                byte[] content = new byte[(int) size];
                input.read(content);
                key.set(name);
                // fill the values for the content object
                value.setUrl(name);
                value.setContent(content);

                writer.append(key, value);
                counter++;
                if (reporter != null) {
                  reporter.incrCounter(Counters.DOC_COUNT, 1);
                }
              }

            } catch (ArchiveException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            } finally {
              fis.close();
            }

          } else {
            // Hmm, kind of dangerous to do this
            byte[] fileBArray = new byte[(int) fs.getFileStatus(file).getLen()];
            FSDataInputStream fis = null;
            try {
              fis = fs.open(file);
              fis.readFully(0, fileBArray);
              fis.close();
              key.set(URI);
              // fill the values for the content object
              value.setUrl(URI);
              value.setContent(fileBArray);

              writer.append(key, value);
              counter++;
              if (reporter != null) {
                reporter.incrCounter(Counters.DOC_COUNT, 1);
              }
            } catch (FileNotFoundException e) {
              throw new RuntimeException(e);
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }
        }
        // if it is a directory, accept it so we can possibly recurse on
        // it,
        // otherwise we don't care about actually accepting the file,
        // since
        // all the work is done in the accept method here.
        return fs.getFileStatus(file).isDir();
      } catch (IOException e) {
        log.error("Exception", e);
      }
      return false;
    }