@Override
  public Collection<? extends Action> getProjectActions(AbstractProject<?, ?> project) {
    ArrayList<TestflightBuildAction> actions = new ArrayList<TestflightBuildAction>();
    RunList<? extends AbstractBuild<?, ?>> builds = project.getBuilds();

    Collection predicated =
        CollectionUtils.select(
            builds,
            new Predicate() {
              public boolean evaluate(Object o) {
                Result result = ((AbstractBuild<?, ?>) o).getResult();
                if (result == null) return false; // currently running builds can have a null result
                return result.isBetterOrEqualTo(Result.SUCCESS);
              }
            });

    ArrayList<AbstractBuild<?, ?>> filteredList = new ArrayList<AbstractBuild<?, ?>>(predicated);

    Collections.reverse(filteredList);
    for (AbstractBuild<?, ?> build : filteredList) {
      List<TestflightBuildAction> testflightActions = build.getActions(TestflightBuildAction.class);
      if (testflightActions != null && testflightActions.size() > 0) {
        for (TestflightBuildAction action : testflightActions) {
          actions.add(new TestflightBuildAction(action));
        }
        break;
      }
    }

    return actions;
  }
Exemplo n.º 2
0
  /** Get a list of security group ids for the slave */
  private List<String> getEc2SecurityGroups(AmazonEC2 ec2) throws AmazonClientException {
    List<String> groupIds = new ArrayList<String>();

    DescribeSecurityGroupsResult groupResult =
        getSecurityGroupsBy("group-name", securityGroupSet, ec2);
    if (groupResult.getSecurityGroups().size() == 0) {
      groupResult = getSecurityGroupsBy("group-id", securityGroupSet, ec2);
    }

    for (SecurityGroup group : groupResult.getSecurityGroups()) {
      if (group.getVpcId() != null && !group.getVpcId().isEmpty()) {
        List<Filter> filters = new ArrayList<Filter>();
        filters.add(new Filter("vpc-id").withValues(group.getVpcId()));
        filters.add(new Filter("state").withValues("available"));
        filters.add(new Filter("subnet-id").withValues(getSubnetId()));

        DescribeSubnetsRequest subnetReq = new DescribeSubnetsRequest();
        subnetReq.withFilters(filters);
        DescribeSubnetsResult subnetResult = ec2.describeSubnets(subnetReq);

        List<Subnet> subnets = subnetResult.getSubnets();
        if (subnets != null && !subnets.isEmpty()) {
          groupIds.add(group.getGroupId());
        }
      }
    }

    if (securityGroupSet.size() != groupIds.size()) {
      throw new AmazonClientException(
          "Security groups must all be VPC security groups to work in a VPC context");
    }

    return groupIds;
  }
  @Override
  public boolean perform(
      AbstractBuild<?, ?> build, Launcher launcher, final BuildListener listener) {
    if (build.getResult().isWorseOrEqualTo(Result.FAILURE)) return false;

    listener.getLogger().println(Messages.TestflightRecorder_InfoUploading());

    try {
      EnvVars vars = build.getEnvironment(listener);

      String workspace = vars.expand("$WORKSPACE");

      List<TestflightUploader.UploadRequest> urList =
          new ArrayList<TestflightUploader.UploadRequest>();

      for (TestflightTeam team : createDefaultPlusAdditionalTeams()) {
        try {
          TestflightUploader.UploadRequest ur = createPartialUploadRequest(team, vars, build);
          urList.add(ur);
        } catch (MisconfiguredJobException mje) {
          listener.getLogger().println(mje.getConfigurationMessage());
          return false;
        }
      }

      for (TestflightUploader.UploadRequest ur : urList) {
        TestflightRemoteRecorder remoteRecorder =
            new TestflightRemoteRecorder(workspace, ur, listener);

        final List<Map> parsedMaps;

        try {
          Object result = launcher.getChannel().call(remoteRecorder);
          parsedMaps = (List<Map>) result;
        } catch (UploadException ue) {
          listener
              .getLogger()
              .println(Messages.TestflightRecorder_IncorrectResponseCode(ue.getStatusCode()));
          listener.getLogger().println(ue.getResponseBody());
          return false;
        }

        if (parsedMaps.size() == 0) {
          listener.getLogger().println(Messages.TestflightRecorder_NoUploadedFile(ur.filePaths));
          return false;
        }
        for (Map parsedMap : parsedMaps) {
          addTestflightLinks(build, listener, parsedMap);
        }
      }
    } catch (Throwable e) {
      listener.getLogger().println(e);
      e.printStackTrace(listener.getLogger());
      return false;
    }

    return true;
  }
Exemplo n.º 4
0
  public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
    modules = Collections.emptyMap(); // needed during load
    super.onLoad(parent, name);

    modules =
        loadChildren(
            this,
            getModulesDir(),
            new Function1<ModuleName, MavenModule>() {
              public ModuleName call(MavenModule module) {
                return module.getModuleName();
              }
            });
    // update the transient nest level field.
    MavenModule root = getRootModule();
    if (root != null && root.getChildren() != null) {
      List<MavenModule> sortedList = new ArrayList<MavenModule>();
      Stack<MavenModule> q = new Stack<MavenModule>();
      root.nestLevel = 0;
      q.push(root);
      while (!q.isEmpty()) {
        MavenModule p = q.pop();
        sortedList.add(p);
        List<MavenModule> children = p.getChildren();
        if (children != null) {
          for (MavenModule m : children) m.nestLevel = p.nestLevel + 1;
          for (int i = children.size() - 1; i >= 0; i--) // add them in the reverse order
          q.push(children.get(i));
        }
      }
      this.sortedActiveModules = sortedList;
    } else {
      this.sortedActiveModules = getDisabledModules(false);
    }

    if (reporters == null)
      reporters = new DescribableList<MavenReporter, Descriptor<MavenReporter>>(this);
    reporters.setOwner(this);
    if (publishers == null)
      publishers = new DescribableList<Publisher, Descriptor<Publisher>>(this);
    publishers.setOwner(this);
    if (buildWrappers == null)
      buildWrappers = new DescribableList<BuildWrapper, Descriptor<BuildWrapper>>(this);
    buildWrappers.setOwner(this);

    updateTransientActions();
  }