@Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String cmd = req.getParameter("cmd");
    String argList = req.getParameter("args");

    List<String> args;
    if (Strings.isValid(argList)) {
      args = Arrays.asList(argList.split(","));
    } else {
      args = Collections.emptyList();
    }
    resp.setStatus(HttpServletResponse.SC_OK);
    CommandInterpreter interpreter =
        new HttpCommandInterpreter(context, resp.getWriter(), args.iterator());
    Object object = interpreter.execute(cmd);
    if (object instanceof Job) {
      Job job = (Job) object;
      try {
        job.join();
        IStatus status = job.getResult();
        interpreter.println(status.toString());
      } catch (InterruptedException ex) {
        interpreter.print(ex);
      }
    }
  }
 @Override
 public final String toString() {
   if (!hasErrors()) {
     return "*no-errors*";
   } else {
     return firstError.toString();
   }
 }
Exemplo n.º 3
0
  public void testGetAction() {
    final ArrayList actionsList1 = new ArrayList();
    InstallableUnitPhase phase1 =
        new InstallableUnitPhase("test", 1) {
          protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) {
            List<ProvisioningAction> actions = getActions(operand.second(), "test1");
            actionsList1.addAll(actions);
            return actions;
          }
        };
    final ArrayList actionsList2 = new ArrayList();
    InstallableUnitPhase phase2 =
        new InstallableUnitPhase("test", 1) {
          protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) {
            List<ProvisioningAction> actions = getActions(operand.second(), "test2");
            actionsList2.addAll(actions);
            return actions;
          }
        };

    PhaseSet phaseSet = new TestPhaseSet(new Phase[] {phase1, phase2});
    IProfile profile = createProfile("PhaseTest");

    Map instructions = new HashMap();
    instructions.put("test1", MetadataFactory.createTouchpointInstruction("test1.test()", null));
    instructions.put("test2", MetadataFactory.createTouchpointInstruction("test2.test()", null));
    ITouchpointData touchpointData = MetadataFactory.createTouchpointData(instructions);
    IInstallableUnit unit =
        createIU(
            "test",
            Version.create("1.0.0"),
            null,
            NO_REQUIRES,
            new IProvidedCapability[0],
            NO_PROPERTIES,
            ITouchpointType.NONE,
            touchpointData,
            false);
    IProvisioningPlan plan = engine.createPlan(profile, null);
    plan.addInstallableUnit(unit);
    IStatus status = engine.perform(plan, phaseSet, new NullProgressMonitor());
    if (!status.isOK()) {
      fail(status.toString());
    }

    assertEquals(
        TestAction.class,
        ((ParameterizedProvisioningAction) actionsList1.get(0)).getAction().getClass());
    assertEquals(
        TestAction.class,
        ((ParameterizedProvisioningAction) actionsList2.get(0)).getAction().getClass());
  }
 @Override
 public void handleError(IStatus status) {
   try {
     IMarker m = file.createMarker(IMarker.PROBLEM);
     // m.setAttribute(IMarker.LINE_NUMBER, line);
     m.setAttribute(IMarker.MESSAGE, status.toString());
     m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
     m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
   } catch (CoreException e) {
     // an error while marking an error, lets throw it
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 5
0
  public void testTransferError() throws Exception {
    File simpleRepo = getTestData("simple repository", "testData/artifactRepo/transferTestRepo");
    IArtifactRepository source = null;
    IArtifactRepository target = null;
    try {
      source =
          getArtifactRepositoryManager()
              .loadRepository(simpleRepo.toURI(), new NullProgressMonitor());
      target = createArtifactRepository(new File(getTempFolder(), getName()).toURI(), null);
    } catch (ProvisionException e) {
      fail("failing setting up the tests", e);
    }

    IArtifactDescriptor sourceDescriptor =
        getArtifactKeyFor(
            source, "osgi.bundle", "missingFromFileSystem", Version.createOSGi(1, 0, 0))[0];
    SimpleArtifactDescriptor targetDescriptor = new SimpleArtifactDescriptor(sourceDescriptor);
    targetDescriptor.setRepositoryProperty("artifact.folder", "true");
    class TestRequest extends MirrorRequest {
      public TestRequest(
          IArtifactKey key,
          IArtifactRepository targetRepository,
          Map<String, String> targetDescriptorProperties,
          Map<String, String> targetRepositoryProperties) {
        super(
            key,
            targetRepository,
            targetDescriptorProperties,
            targetRepositoryProperties,
            getTransport());
      }

      public void setSource(IArtifactRepository source) {
        super.setSourceRepository(source);
      }
    }
    TestRequest request =
        new TestRequest(
            new ArtifactKey("osgi.bundle", "missingFromFileSystem", Version.createOSGi(1, 0, 0)),
            target,
            null,
            null);
    request.setSource(source);
    IStatus s =
        transferSingle(request, targetDescriptor, sourceDescriptor, new NullProgressMonitor());
    assertTrue(s.toString(), s.getException().getClass() == FileNotFoundException.class);
  }
Exemplo n.º 6
0
  /**
   * (inheritDoc)
   *
   * @param listener
   * @see org.goko.featuremanager.service.IFeatureManager#install(java.util.List)
   */
  @Override
  public IStatus install(
      List<GkInstallableUnit> units, IProgressMonitor monitor, IJobChangeListener listener)
      throws GkException {
    // get the repository managers and define our repositories
    IMetadataRepositoryManager manager =
        (IMetadataRepositoryManager)
            getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);

    List<IInstallableUnit> p2Units = new ArrayList<IInstallableUnit>();
    for (GkInstallableUnit gkInstallableUnit : units) {
      if (!gkInstallableUnit.isInstalled()) {
        p2Units.add(gkInstallableUnit.getBaseUnit());
      }
    }
    final InstallOperation installOperation =
        new InstallOperation(new ProvisioningSession(getProvisioningAgent()), p2Units);
    LOG.info("installOperation created " + String.valueOf(installOperation));

    IStatus operationStatus = installOperation.resolveModal(monitor);
    LOG.info("operationStatus " + String.valueOf(operationStatus));

    if (operationStatus.getSeverity() > IStatus.WARNING) {
      LOG.error("installOperation detail :" + installOperation.getResolutionDetails());

      LOG.error("Install operation failed :" + operationStatus.toString());
      if (operationStatus.isMultiStatus()) {
        for (IStatus status : operationStatus.getChildren()) {
          LOG.error("   + " + status.getMessage());
        }
      }
      LOG.error(new CoreException(operationStatus));
      return operationStatus;
    }

    final ProvisioningJob provisioningJob = installOperation.getProvisioningJob(monitor);
    LOG.info("ProvisioningJob created " + String.valueOf(provisioningJob));

    provisioningJob.schedule();

    provisioningJob.addJobChangeListener(listener);

    LOG.info("Installation of feature done");

    return operationStatus;
  }
 public void logging(IStatus status, String plugin) {
   if (status.getSeverity() == IStatus.ERROR) fail(status.toString());
 }