コード例 #1
0
 @Override
 protected void tearDown() throws Exception {
   framework.stop();
   framework.waitForStop(10000);
   IO.delete(tmp);
   super.tearDown();
 }
コード例 #2
0
  private void generateResourcesFile(final File resfile) {

    final Framework framework = projectResourceMgr.getFramework();
    final NodeEntryImpl node = framework.createFrameworkNode();
    node.setFrameworkProject(getName());
    final NodesFileGenerator generator;
    if (resfile.getName().endsWith(".xml")) {
      generator = new ResourceXMLGenerator(resfile);
    } else if (resfile.getName().endsWith(".yaml")) {
      generator = new NodesYamlGenerator(resfile);
    } else {
      getLogger()
          .error(
              "Unable to generate resources file. Unrecognized extension for dest file: "
                  + resfile.getAbsolutePath());
      return;
    }
    generator.addNode(node);
    try {
      generator.generate();
    } catch (IOException e) {
      getLogger().error("Unable to generate resources file: " + e.getMessage(), e);
    } catch (NodesGeneratorException e) {
      getLogger().error("Unable to generate resources file: " + e.getMessage(), e);
    }

    getLogger().debug("generated resources file: " + resfile.getAbsolutePath());
  }
コード例 #3
0
  @Override
  protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();

    configuration = new HashMap<String, Object>();
    configuration.put(
        Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, new File(tmp, "fwstorage").getAbsolutePath());
    configuration.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.4");
    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    BundleContext context = framework.getBundleContext();

    String[] bundles = {
      "../cnf/repo/osgi.cmpn/osgi.cmpn-4.3.1.jar", "testdata/slf4j-simple-1.7.12.jar",
      "testdata/slf4j-api-1.7.12.jar", "testdata/org.apache.aries.util-1.1.0.jar",
      "testdata/org.apache.aries.jmx-1.1.1.jar", "generated/biz.aQute.remote.test.jmx.jar"
    };

    for (String bundle : bundles) {
      String location = "reference:" + IO.getFile(bundle).toURI().toString();
      Bundle b = context.installBundle(location);
      if (!bundle.contains("slf4j-simple")) {
        b.start();
      }
    }

    super.setUp();
  }
コード例 #4
0
 public static void generateStubs(Framework framework, File location) {
   final StringBuilder builder = new StringBuilder();
   builder
       .append("# This is a machine generated stub for: ")
       .append(framework.getName())
       .append("\n");
   builder
       .append("# Created on: ")
       .append(DateFormatUtil.formatDateTime(new Date()))
       .append("\n\n");
   for (Class aClass : framework.getClasses()) {
     generateClassStub(builder, framework, aClass);
   }
   for (Function function : framework.getFunctions()) {
     generateFunctionStub(builder, function, "");
   }
   for (Constant constant : framework.getConstants()) {
     generateConstantStub(builder, constant);
   }
   for (Map.Entry<String, String> entry : framework.getFunctionAliases().entrySet()) {
     generateAlias(builder, entry);
   }
   try {
     FileUtil.writeToFile(location, builder.toString());
   } catch (Throwable ignored) {
   }
 }
コード例 #5
0
  @Override
  protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();
    IO.copy(IO.getFile("testdata/ws"), tmp);
    workspace = Workspace.getWorkspace(tmp);
    workspace.refresh();

    InfoRepository repo = workspace.getPlugin(InfoRepository.class);
    t1 = create("bsn-1", new Version(1, 0, 0));
    t2 = create("bsn-2", new Version(1, 0, 0));

    repo.put(new FileInputStream(t1), null);
    repo.put(new FileInputStream(t2), null);
    t1 = repo.get("bsn-1", new Version(1, 0, 0), null);
    t2 = repo.get("bsn-2", new Version(1, 0, 0), null);
    repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null);

    workspace.getPlugins().add(repo);

    File storage = IO.getFile("generated/storage-1");
    storage.mkdirs();

    configuration = new HashMap<String, Object>();
    configuration.put(
        Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath());

    configuration.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2");

    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    context = framework.getBundleContext();
    location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString();
    agent = context.installBundle(location);
    agent.start();

    thread =
        new Thread() {
          @Override
          public void run() {
            try {
              Main.main(
                  new String[] {
                    "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et"
                  });
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        };
    thread.setDaemon(true);
    thread.start();

    super.setUp();
  }
コード例 #6
0
 Object setContextFinder() {
   if (!SET_TCCL) return Boolean.FALSE;
   Thread currentThread = Thread.currentThread();
   ClassLoader previousTCCL = currentThread.getContextClassLoader();
   ClassLoader contextFinder = framework.getContextFinder();
   if (previousTCCL != contextFinder) {
     currentThread.setContextClassLoader(framework.getContextFinder());
     return previousTCCL;
   }
   return Boolean.FALSE;
 }
コード例 #7
0
 @Override
 protected void tearDown() throws Exception {
   super.tearDown();
   framework.stop();
   IO.delete(tmp);
   Main.stop();
   IO.delete(IO.getFile("generated/cache"));
   IO.delete(IO.getFile("generated/storage"));
   framework.waitForStop(100000);
   super.tearDown();
 }
コード例 #8
0
 /**
  * Create a NodeFileParser given the project and the source file, using the predetermined format
  *
  * @param file the nodes resource file
  * @param format the file format
  * @return a new parser based on the determined format
  * @throws ResourceModelSourceException if the format is not supported
  */
 protected ResourceFormatParser createParser(final File file, final String format)
     throws ResourceModelSourceException {
   try {
     if (null != format) {
       return framework.getResourceFormatParserService().getParserForFormat(format);
     } else {
       return framework.getResourceFormatParserService().getParserForFileExtension(file);
     }
   } catch (UnsupportedFormatException e) {
     throw new ResourceModelSourceException(e);
   }
 }
コード例 #9
0
 /**
  * Return specific nodes resources file path for the project, based on the
  * framework.nodes.file.name property
  *
  * @return
  */
 public String getNodesResourceFilePath() {
   if (hasProperty(PROJECT_RESOURCES_FILE_PROPERTY)) {
     return new File(getProperty(PROJECT_RESOURCES_FILE_PROPERTY)).getAbsolutePath();
   }
   final Framework framework = projectResourceMgr.getFramework();
   final String s;
   if (framework.hasProperty(Framework.NODES_RESOURCES_FILE_PROP)) {
     return new File(getEtcDir(), framework.getProperty(Framework.NODES_RESOURCES_FILE_PROP))
         .getAbsolutePath();
   } else {
     return new File(getEtcDir(), NODES_XML).getAbsolutePath();
   }
 }
コード例 #10
0
 protected void setUp() {
   super.setUp();
   testFramework = getFrameworkInstance();
   testnode = testFramework.getFrameworkNodeName();
   final FrameworkProject frameworkProject =
       testFramework.getFrameworkProjectMgr().createFrameworkProject(TEST_PROJECT);
   File resourcesfile = new File(frameworkProject.getNodesResourceFilePath());
   // copy test nodes to resources file
   try {
     FileUtils.copyFileStreams(
         new File("src/test/resources/com/dtolabs/rundeck/core/common/test-nodes1.xml"),
         resourcesfile);
   } catch (IOException e) {
     throw new RuntimeException("Caught Setup exception: " + e.getMessage(), e);
   }
 }
コード例 #11
0
 /**
  * @return specific nodes resources file path for the project, based on the
  *     framework.nodes.file.name property
  */
 public static String getNodesResourceFilePath(IRundeckProject project, Framework framework) {
   if (project.hasProperty(ProjectNodeSupport.PROJECT_RESOURCES_FILE_PROPERTY)) {
     return new File(project.getProperty(ProjectNodeSupport.PROJECT_RESOURCES_FILE_PROPERTY))
         .getAbsolutePath();
   }
   if (null != framework) {
     File etcDir = new File(framework.getFrameworkProjectsBaseDir(), project.getName() + "/etc/");
     if (framework.hasProperty(Framework.NODES_RESOURCES_FILE_PROP)) {
       return new File(etcDir, framework.getProperty(Framework.NODES_RESOURCES_FILE_PROP))
           .getAbsolutePath();
     } else {
       return new File(etcDir, ProjectNodeSupport.NODES_XML).getAbsolutePath();
     }
   } else {
     return null;
   }
 }
コード例 #12
0
  /**
   * Remove a service listener. The listener is removed from the context bundle's list of listeners.
   * See {@link #getBundle() getBundle()} for a definition of context bundle.
   *
   * <p>If this method is called with a listener which is not registered, then this method does
   * nothing.
   *
   * @param listener The service listener to remove.
   * @exception java.lang.IllegalStateException If the bundle context has stopped.
   */
  public void removeServiceListener(ServiceListener listener) {
    checkValid();

    if (listener == null) {
      throw new IllegalArgumentException();
    }
    framework.getServiceRegistry().removeServiceListener(this, listener);
  }
コード例 #13
0
  /**
   * Add a service listener with a filter. {@link ServiceListener}s are notified when a service has
   * a lifecycle state change. See {@link #getServiceReferences(String, String)
   * getServiceReferences} for a description of the filter syntax. The listener is added to the
   * context bundle's list of listeners. See {@link #getBundle() getBundle()} for a definition of
   * context bundle.
   *
   * <p>The listener is called if the filter criteria is met. To filter based upon the class of the
   * service, the filter should reference the "objectClass" property. If the filter paramater is
   * <code>null</code>, all services are considered to match the filter.
   *
   * <p>If the Java runtime environment supports permissions, then additional filtering is done.
   * {@link AbstractBundle#hasPermission(Object) Bundle.hasPermission} is called for the bundle
   * which defines the listener to validate that the listener has the {@link ServicePermission}
   * permission to <code>"get"</code> the service using at least one of the named classes the
   * service was registered under.
   *
   * @param listener The service listener to add.
   * @param filter The filter criteria.
   * @exception InvalidSyntaxException If the filter parameter contains an invalid filter string
   *     which cannot be parsed.
   * @see ServiceEvent
   * @see ServiceListener
   * @exception java.lang.IllegalStateException If the bundle context has stopped.
   */
  public void addServiceListener(ServiceListener listener, String filter)
      throws InvalidSyntaxException {
    checkValid();

    if (listener == null) {
      throw new IllegalArgumentException();
    }
    framework.getServiceRegistry().addServiceListener(this, listener, filter);
  }
コード例 #14
0
  /**
   * Retrieve the value of the named environment property.
   *
   * @param key The name of the requested property.
   * @return The value of the requested property, or <code>null</code> if the property is undefined.
   */
  public String getProperty(String key) {
    SecurityManager sm = System.getSecurityManager();

    if (sm != null) {
      sm.checkPropertyAccess(key);
    }

    return (framework.getProperty(key));
  }
コード例 #15
0
  /** Destroy the wrapper. This is called when the bundle is stopped. */
  protected void close() {
    valid = false; /* invalidate context */

    final ServiceRegistry registry = framework.getServiceRegistry();

    registry.removeAllServiceListeners(this);
    framework.removeAllListeners(this);

    /* service's registered by the bundle, if any, are unregistered. */
    registry.unregisterServices(this);

    /* service's used by the bundle, if any, are released. */
    registry.releaseServicesInUse(this);

    synchronized (contextLock) {
      servicesInUse = null;
    }
  }
コード例 #16
0
  private void generateResourcesFile(final File resfile, final String format)
      throws ResourceModelSourceException {
    final NodeEntryImpl node = framework.createFrameworkNode();
    node.setFrameworkProject(configuration.project);
    final ResourceFormatGenerator generator;
    if (null != format) {
      try {
        generator = framework.getResourceFormatGeneratorService().getGeneratorForFormat(format);
      } catch (UnsupportedFormatException e) {
        throw new ResourceModelSourceException(e);
      }
    } else {
      try {
        generator =
            framework.getResourceFormatGeneratorService().getGeneratorForFileExtension(resfile);
      } catch (UnsupportedFormatException e) {
        throw new ResourceModelSourceException(e);
      }
    }
    if (configuration.includeServerNode) {
      NodeSetImpl nodes = new NodeSetImpl();
      nodes.putNode(node);

      if (!resfile.getParentFile().exists()) {
        if (!resfile.getParentFile().mkdirs()) {
          throw new ResourceModelSourceException(
              "Parent dir for resource file does not exists, and could not be created: " + resfile);
        }
      }

      try {
        final FileOutputStream stream = new FileOutputStream(resfile);
        try {
          generator.generateDocument(nodes, stream);
        } finally {
          stream.close();
        }
      } catch (IOException e) {
        throw new ResourceModelSourceException(e);
      } catch (ResourceFormatGeneratorException e) {
        throw new ResourceModelSourceException(e);
      }
    }
  }
コード例 #17
0
  private static PermissionInfo[] getPermissionInfos(URL resource, Framework framework) {
    if (resource == null) return null;
    PermissionInfo[] info = EMPTY_PERM_INFO;
    DataInputStream in = null;
    try {
      in = new DataInputStream(resource.openStream());
      ArrayList permissions = new ArrayList();
      BufferedReader reader;
      try {
        reader = new BufferedReader(new InputStreamReader(in, "UTF8")); // $NON-NLS-1$
      } catch (UnsupportedEncodingException e) {
        reader = new BufferedReader(new InputStreamReader(in));
      }

      while (true) {
        String line = reader.readLine();
        if (line == null) /* EOF */ break;
        line = line.trim();
        if ((line.length() == 0)
            || line.startsWith("#")
            || line.startsWith("//")) /* comments */ // $NON-NLS-1$ //$NON-NLS-2$
        continue;

        try {
          permissions.add(new PermissionInfo(line));
        } catch (IllegalArgumentException iae) {
          /* incorrectly encoded permission */
          if (framework != null)
            framework.publishFrameworkEvent(FrameworkEvent.ERROR, framework.getBundle(0), iae);
        }
      }
      int size = permissions.size();
      if (size > 0) info = (PermissionInfo[]) permissions.toArray(new PermissionInfo[size]);
    } catch (IOException e) {
      // do nothing
    } finally {
      try {
        if (in != null) in.close();
      } catch (IOException ee) {
        // do nothing
      }
    }
    return info;
  }
コード例 #18
0
 private static void generateClassStub(StringBuilder builder, Framework framework, Class aClass) {
   builder.append("class ").append(aClass.getName());
   final String parent =
       InheritanceInfoHolder.getInstance()
           .getInheritance(aClass.getName(), framework.getVersion());
   if (parent != null) {
     builder.append(" < ").append(parent);
   }
   builder.append("\n");
   for (Function function : aClass.getFunctions()) {
     generateFunctionStub(builder, function, "  ");
   }
   builder.append("end\n\n");
 }
コード例 #19
0
 public void testAll() throws Exception {
   assertTrue(
       Framework.executeTest("=COS(" + Math.PI + "/6)", Double.valueOf(0.8660254037844387)));
   assertTrue(Framework.executeTest("=COS(RADIANS(60))", Double.valueOf(0.5000000000000001)));
   assertTrue(Framework.executeTest("=COS(RADIANS(-30))", Double.valueOf(0.8660254037844387)));
   assertTrue(Framework.executeTest("=COS(0.785398163)", Double.valueOf(0.7071067814675859)));
   assertTrue(Framework.executeTest("=COS(\"0.0\")", Double.valueOf(1)));
   assertTrue(Framework.executeTestExpectFailure("=COS(\"abc\")"));
 }
コード例 #20
0
ファイル: Main.java プロジェクト: ReedFlake/CommandTeleporter
    @Override
    public boolean execute(
        final CommandSender sender, final String commandLabel, final String[] args) {
      if (this.getPos() != null) {
        if (sender instanceof Player) {
          if (sender.hasPermission("commandtp." + this.nome.toLowerCase().trim())) {
            Bukkit.getScheduler()
                .runTaskAsynchronously(
                    Framework.<Main>getPlugin("CommandTeleporter"),
                    new Runnable() {
                      @Override
                      public void run() {
                        ((Player) sender).teleport(Warp.this.getPos());
                        sender.sendMessage(
                            ChatColor.translateAlternateColorCodes(
                                '&',
                                Main.data
                                    .getString("mensagens.tp")
                                    .replace("{nome}", Warp.this.getDisplayName())));
                        if (Main.data.getBoolean("uselogs")) {
                          Main.logs.addLog(
                              "Jogador '"
                                  + sender.getName()
                                  + "' teleportou-se até o local '"
                                  + Warp.this.nome
                                  + "'");
                        }
                      }
                    });

            return true;
          } else {
            sender.sendMessage(
                ChatColor.translateAlternateColorCodes(
                    '&',
                    Main.data
                        .getString("mensagens.permissão_pos")
                        .replace("{nome}", this.getDisplayName())));
            return false;
          }
        } else {
          sender.sendMessage("[CommandTeleporter] Comando bloqueado no console!");
          return false;
        }
      } else {
        sender.sendMessage("§4» §cLocalização não definida (contate um admin).");
        return false;
      }
    }
コード例 #21
0
  /**
   * Get a service's service object. Retrieves the service object for a service. A bundle's use of a
   * service is tracked by a use count. Each time a service's service object is returned by {@link
   * #getService}, the context bundle's use count for the service is incremented by one. Each time
   * the service is release by {@link #ungetService}, the context bundle's use count for the service
   * is decremented by one. When a bundle's use count for a service drops to zero, the bundle should
   * no longer use the service. See {@link #getBundle()} for a definition of context bundle.
   *
   * <p>This method will always return <code>null</code> when the service associated with this
   * reference has been unregistered.
   *
   * <p>The following steps are followed to get the service object:
   *
   * <ol>
   *   <li>If the service has been unregistered, <code>null</code> is returned.
   *   <li>The context bundle's use count for this service is incremented by one.
   *   <li>If the context bundle's use count for the service is now one and the service was
   *       registered with a {@link ServiceFactory}, the {@link ServiceFactory#getService
   *       ServiceFactory.getService} method is called to create a service object for the context
   *       bundle. This service object is cached by the framework. While the context bundle's use
   *       count for the service is greater than zero, subsequent calls to get the services's
   *       service object for the context bundle will return the cached service object. <br>
   *       If the service object returned by the {@link ServiceFactory} is not an <code>instanceof
   *       </code> all the classes named when the service was registered or the {@link
   *       ServiceFactory} throws an exception, <code>null</code> is returned and a {@link
   *       FrameworkEvent} of type {@link FrameworkEvent#ERROR} is broadcast.
   *   <li>The service object for the service is returned.
   * </ol>
   *
   * @param reference A reference to the service whose service object is desired.
   * @return A service object for the service associated with this reference, or <code>null</code>
   *     if the service is not registered.
   * @exception java.lang.SecurityException If the caller does not have {@link ServicePermission}
   *     permission to "get" the service using at least one of the named classes the service was
   *     registered under and the Java runtime environment supports permissions.
   * @exception java.lang.IllegalStateException If the bundle context has stopped.
   * @see #ungetService
   * @see ServiceFactory
   */
  public <S> S getService(ServiceReference<S> reference) {
    checkValid();
    if (reference == null)
      throw new NullPointerException("A null service reference is not allowed."); // $NON-NLS-1$
    synchronized (contextLock) {
      if (servicesInUse == null)
        // Cannot predict how many services a bundle will use, start with a small table.
        servicesInUse = new HashMap<ServiceRegistrationImpl<?>, ServiceUse<?>>(10);
    }

    @SuppressWarnings("unchecked")
    S service =
        (S) framework.getServiceRegistry().getService(this, (ServiceReferenceImpl<S>) reference);
    return service;
  }
コード例 #22
0
  /**
   * Remove a framework listener. The listener is removed from the context bundle's list of
   * listeners. See {@link #getBundle() getBundle()} for a definition of context bundle.
   *
   * <p>If this method is called with a listener which is not registered, then this method does
   * nothing.
   *
   * @param listener The framework listener to remove.
   * @exception java.lang.IllegalStateException If the bundle context has stopped.
   */
  public void removeFrameworkListener(FrameworkListener listener) {
    checkValid();
    if (listener == null) {
      throw new IllegalArgumentException();
    }

    if (Debug.DEBUG_EVENTS) {
      String listenerName =
          listener.getClass().getName()
              + "@"
              + Integer.toHexString(System.identityHashCode(listener)); // $NON-NLS-1$
      Debug.println(
          "removeFrameworkListener["
              + bundle
              + "]("
              + listenerName
              + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }

    framework.removeFrameworkListener(listener, this);
  }
コード例 #23
0
 private void loadNodes(final File nodesFile, final String format)
     throws ResourceModelSourceException {
   if (!nodesFile.isFile() && configuration.generateFileAutomatically) {
     generateResourcesFile(nodesFile, format);
   } else if (configuration.includeServerNode) {
     final NodeEntryImpl node = framework.createFrameworkNode();
     nodeSet.putNode(node);
   }
   if (nodesFile.isFile()) {
     final ResourceFormatParser parser = createParser(nodesFile, format);
     try {
       final INodeSet set = parser.parseDocument(nodesFile);
       if (null != set) {
         nodeSet.putNodes(set);
       }
     } catch (ResourceFormatParserException e) {
       throw new ResourceModelSourceException(e);
     }
   } else if (configuration.requireFileExists) {
     throw new ResourceModelSourceException("File does not exist: " + nodesFile);
   }
 }
コード例 #24
0
  /**
   * Return true in these cases: 1. project.properties allows URL and framework.properties allows
   * URL. 2. project.properties allows URL and no regexes are set in framework.properties 3.
   * project.properties no regexes are set, and framework.properites allows URL.
   */
  boolean isAllowedProviderURL(final String providerURL) {

    // whitelist the configured providerURL
    if (hasProperty(PROJECT_RESOURCES_URL_PROPERTY)
        && getProperty(PROJECT_RESOURCES_URL_PROPERTY).equals(providerURL)) {
      return true;
    }
    // check regex properties for project props
    int i = 0;
    boolean projpass = false;
    boolean setproj = false;
    while (hasProperty(PROJECT_RESOURCES_ALLOWED_URL_PREFIX + i)) {
      setproj = true;
      final String regex = getProperty(PROJECT_RESOURCES_ALLOWED_URL_PREFIX + i);
      final Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
      final Matcher matcher = pat.matcher(providerURL);
      if (matcher.matches()) {
        logger.debug(
            "ProviderURL allowed by project property \"project.resources.allowedURL."
                + i
                + "\": "
                + regex);
        projpass = true;
        break;
      }
      i++;
    }
    if (!projpass && setproj) {
      // was checked but failed match
      return false;
    }
    assert projpass ^ !setproj;
    // check framework props
    i = 0;

    final Framework framework = getFrameworkProjectMgr().getFramework();
    final boolean setframework = framework.hasProperty(FRAMEWORK_RESOURCES_ALLOWED_URL_PREFIX + i);
    if (!setframework && projpass) {
      // unset in framework.props, allowed by project.props
      return true;
    }
    if (!setframework && !setproj) {
      // unset in both
      return false;
    }
    while (framework.hasProperty(FRAMEWORK_RESOURCES_ALLOWED_URL_PREFIX + i)) {
      final String regex = framework.getProperty(FRAMEWORK_RESOURCES_ALLOWED_URL_PREFIX + i);
      final Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
      final Matcher matcher = pat.matcher(providerURL);
      if (matcher.matches()) {
        logger.debug(
            "ProviderURL allowed by framework property \"framework.resources.allowedURL."
                + i
                + "\": "
                + regex);
        // allowed by framework.props, and unset or allowed by project.props,
        return true;
      }
      i++;
    }
    if (projpass) {
      logger.warn(
          "providerURL was allowed by project.properties, but is not allowed by framework.properties: "
              + providerURL);
    }
    return false;
  }
コード例 #25
0
ファイル: Plugins.java プロジェクト: xathrya/jsploit
 public Plugins(Framework f) {
   Console.out("Plugins Module called.");
   this.framework = f;
   exploits = (RubyObject) framework.invoke("plugins");
 }
コード例 #26
0
  public void testGenericItem() {

    {
      // test jobref item
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
      final testWorkflowCmdItem item = new testWorkflowCmdItem();
      item.type = "my-type";
      commands.add(item);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      interpreterService.registerInstance("my-type", interpreterMock);
      interpreterService.registerInstance("exec", failMock);
      interpreterService.registerInstance("script", failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);

      // set resturn result
      interpreterMock.resultList.add(
          new InterpreterResult() {
            public boolean isSuccess() {
              return true;
            }
          });

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(1, interpreterMock.executionItemList.size());
      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof testWorkflowCmdItem);
      testWorkflowCmdItem execItem = (testWorkflowCmdItem) executionItem1;
      assertNotNull(execItem.getType());
      assertEquals("my-type", execItem.getType());
      assertEquals(1, interpreterMock.executionContextList.size());
      final ExecutionContext executionContext = interpreterMock.executionContextList.get(0);
      assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
      assertNull(executionContext.getArgs());
      assertNull(executionContext.getDataContext());
      assertEquals(0, executionContext.getLoglevel());
      assertEquals("user1", executionContext.getUser());
      assertEquals(nodeset, executionContext.getNodeSelector());
    }
  }
コード例 #27
0
  public void testExecuteWorkflow() throws Exception {
    {
      final FrameworkProject frameworkProject =
          testFramework.getFrameworkProjectMgr().getFrameworkProject(TEST_PROJECT);
      final INodeSet nodes = frameworkProject.getNodeSet();
      assertNotNull(nodes);
      assertEquals(2, nodes.getNodes().size());
    }

    {
      // test empty workflow
      final NodeSet nodeset = new NodeSet();
      final WorkflowImpl workflow =
          new WorkflowImpl(new ArrayList<ExecutionItem>(), 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(
          WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, interpreterMock);
      interpreterService.registerInstance(
          WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, interpreterMock);
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE,
      // interpreterMock);

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(0, interpreterMock.executionItemList.size());
    }
    {
      // test undefined workflow item
      final NodeSet nodeset = new NodeSet();
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
      commands.add(new testWorkflowCmdItem());

      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset.nodeSelectorWithDefaultAll())
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(
          WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, interpreterMock);
      interpreterService.registerInstance(
          WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, interpreterMock);
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE,
      // interpreterMock);

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertFalse(result.isSuccess());
      assertEquals(0, interpreterMock.executionItemList.size());
      assertNotNull("threw exception: " + result.getException(), result.getException());
      assertTrue(
          "threw exception: " + result.getException(),
          result.getException() instanceof WorkflowStepFailureException);
      assertEquals(
          "threw exception: " + result.getException(),
          "Step 1 of the workflow threw an exception: Failed dispatching to node test1: provider name was null for Service: CommandInterpreter",
          result.getException().getMessage());
    }

    {
      // test script exec item
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
      final ExecutionItem testWorkflowCmdItem =
          new ScriptFileCommandBase() {
            @Override
            public String getScript() {
              return "a command";
            }
          };
      commands.add(testWorkflowCmdItem);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      interpreterService.registerInstance("exec", failMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE, failMock);

      // set resturn result
      interpreterMock.resultList.add(
          new InterpreterResult() {
            public boolean isSuccess() {
              return true;
            }
          });

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(1, interpreterMock.executionItemList.size());
      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof ScriptFileCommandExecutionItem);
      ScriptFileCommandExecutionItem scriptItem = (ScriptFileCommandExecutionItem) executionItem1;
      assertEquals("a command", scriptItem.getScript());
      assertNull(scriptItem.getScriptAsStream());
      assertNull(scriptItem.getServerScriptFilePath());
      assertEquals(1, interpreterMock.executionContextList.size());
      final ExecutionContext executionContext = interpreterMock.executionContextList.get(0);
      assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
      assertNull(executionContext.getArgs());
      assertNull(executionContext.getDataContext());
      assertEquals(0, executionContext.getLoglevel());
      assertEquals("user1", executionContext.getUser());
      assertEquals(
          "expected " + nodeset + ", but was " + executionContext.getNodeSelector(),
          nodeset,
          executionContext.getNodeSelector());
    }
    {
      // test command exec item
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
      final ExecutionItem testWorkflowCmdItem =
          new ExecCommandBase() {
            @Override
            public String[] getCommand() {
              return new String[] {"a", "command"};
            }
          };

      commands.add(testWorkflowCmdItem);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE, failMock);

      // set resturn result
      interpreterMock.resultList.add(
          new InterpreterResult() {
            public boolean isSuccess() {
              return true;
            }
          });

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(1, interpreterMock.executionItemList.size());
      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof ExecCommandExecutionItem);
      ExecCommandExecutionItem execItem = (ExecCommandExecutionItem) executionItem1;
      assertNotNull(execItem.getCommand());
      assertEquals(2, execItem.getCommand().length);
      assertEquals("a", execItem.getCommand()[0]);
      assertEquals("command", execItem.getCommand()[1]);
      assertEquals(1, interpreterMock.executionContextList.size());
      final ExecutionContext executionContext = interpreterMock.executionContextList.get(0);
      assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
      assertNull(executionContext.getArgs());
      assertNull(executionContext.getDataContext());
      assertEquals(0, executionContext.getLoglevel());
      assertEquals("user1", executionContext.getUser());
      assertEquals(nodeset, executionContext.getNodeSelector());
    }
    {
      // test workflow of three successful items
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();

      final ExecutionItem testWorkflowCmdItem =
          new ExecCommandBase() {
            @Override
            public String[] getCommand() {
              return new String[] {"a", "2", "command"};
            }
          };

      commands.add(testWorkflowCmdItem);

      final ExecutionItem testWorkflowCmdItemScript =
          new ScriptFileCommandBase() {
            @Override
            public String getScript() {
              return "a command";
            }

            @Override
            public String[] getArgs() {
              return new String[] {"-testargs", "1"};
            }
          };
      commands.add(testWorkflowCmdItemScript);

      final ExecutionItem testWorkflowCmdItemScript2 =
          new ScriptFileCommandBase() {
            @Override
            public String getServerScriptFilePath() {
              return "/some/file/path";
            }

            @Override
            public String[] getArgs() {
              return new String[] {"-testargs", "2"};
            }
          };
      commands.add(testWorkflowCmdItemScript2);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .args(new String[] {"test", "args"})
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE,
      // interpreterMock);
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);

      // set resturn results
      interpreterMock.resultList.add(new testResult(true, 0));
      interpreterMock.resultList.add(new testResult(true, 1));
      interpreterMock.resultList.add(new testResult(true, 2));

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(1, result.getResultSet().size());
      assertNotNull(result.getResultSet());
      assertNotNull(
          "missing key " + testnode + ": " + result.getResultSet().keySet(),
          result.getResultSet().get(testnode));
      final List<StatusResult> test1 = result.getResultSet().get(testnode);
      assertEquals(3, test1.size());
      for (final int i : new int[] {0, 1, 2}) {
        final StatusResult interpreterResult = test1.get(i);
        assertTrue(interpreterResult instanceof testResult);
        testResult val = (testResult) interpreterResult;
        assertTrue(val.isSuccess());
        assertEquals(i, val.flag);
      }

      assertEquals(3, interpreterMock.executionItemList.size());

      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof ExecCommandExecutionItem);
      ExecCommandExecutionItem execItem = (ExecCommandExecutionItem) executionItem1;
      assertNotNull(execItem.getCommand());
      assertEquals(3, execItem.getCommand().length);
      assertEquals("a", execItem.getCommand()[0]);
      assertEquals("2", execItem.getCommand()[1]);
      assertEquals("command", execItem.getCommand()[2]);

      final ExecutionItem item2 = interpreterMock.executionItemList.get(1);
      assertTrue(
          "wrong class: " + item2.getClass().getName(),
          item2 instanceof ScriptFileCommandExecutionItem);
      ScriptFileCommandExecutionItem scriptItem = (ScriptFileCommandExecutionItem) item2;
      assertEquals("a command", scriptItem.getScript());
      assertNull(scriptItem.getScriptAsStream());
      assertNull(scriptItem.getServerScriptFilePath());

      final ExecutionItem item3 = interpreterMock.executionItemList.get(2);
      assertTrue(
          "wrong class: " + item3.getClass().getName(),
          item2 instanceof ScriptFileCommandExecutionItem);
      ScriptFileCommandExecutionItem scriptItem2 = (ScriptFileCommandExecutionItem) item3;
      assertNull(scriptItem2.getScript());
      assertNull(scriptItem2.getScriptAsStream());
      assertEquals("/some/file/path", scriptItem2.getServerScriptFilePath());
      assertNotNull(scriptItem2.getArgs());
      assertEquals(2, scriptItem2.getArgs().length);
      assertEquals("-testargs", scriptItem2.getArgs()[0]);
      assertEquals("2", scriptItem2.getArgs()[1]);

      assertEquals(3, interpreterMock.executionContextList.size());

      for (final int i : new int[] {0, 1, 2}) {
        final ExecutionContext executionContext = interpreterMock.executionContextList.get(i);
        assertEquals("item " + i, TEST_PROJECT, executionContext.getFrameworkProject());
        assertNull("item " + i, executionContext.getDataContext());
        assertEquals("item " + i, 0, executionContext.getLoglevel());
        assertEquals("item " + i, "user1", executionContext.getUser());
        assertEquals("item " + i, nodeset, executionContext.getNodeSelector());
        assertNotNull("item " + i, executionContext.getArgs());
        assertEquals("item " + i, 2, executionContext.getArgs().length);
        assertEquals("item " + i, "test", executionContext.getArgs()[0]);
        assertEquals("item " + i, "args", executionContext.getArgs()[1]);
      }
    }
    {
      // test a workflow with a failing item (1), with keepgoing=false
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();

      final ExecutionItem testWorkflowCmdItem =
          new ExecCommandBase() {
            @Override
            public String[] getCommand() {
              return new String[] {"a", "2", "command"};
            }
          };

      commands.add(testWorkflowCmdItem);

      final ExecutionItem testWorkflowCmdItemScript =
          new ScriptFileCommandBase() {
            @Override
            public String getScript() {
              return "a command";
            }

            @Override
            public String[] getArgs() {
              return new String[] {"-testargs", "1"};
            }
          };
      commands.add(testWorkflowCmdItemScript);

      final ExecutionItem testWorkflowCmdItemScript2 =
          new ScriptFileCommandBase() {
            @Override
            public String getServerScriptFilePath() {
              return "/some/file/path";
            }

            @Override
            public String[] getArgs() {
              return new String[] {"-testargs", "2"};
            }
          };
      commands.add(testWorkflowCmdItemScript2);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      workflow.setKeepgoing(false);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE,
      // interpreterMock);
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);

      // set resturn results, fail on second item
      interpreterMock.resultList.add(new testResult(true, 0));
      interpreterMock.resultList.add(new testResult(false, 1));
      interpreterMock.resultList.add(new testResult(true, 2));

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertFalse(result.isSuccess());
      assertNotNull("threw exception: " + result.getException(), result.getException());
      assertTrue(
          "threw exception: " + result.getException(),
          result.getException() instanceof WorkflowStepFailureException);
      WorkflowStepFailureException wfsfe = (WorkflowStepFailureException) result.getException();
      assertEquals(2, wfsfe.getWorkflowStep());
      assertNotNull(wfsfe.getExecutionResult());
      final ExecutionResult executionResult = wfsfe.getExecutionResult();
      assertNotNull(executionResult.getResultObject());
      assertNotNull(executionResult.getResultObject().getResults());
      assertEquals(1, executionResult.getResultObject().getResults().size());
      assertNotNull(executionResult.getResultObject().getResults().get(testnode));
      final StatusResult testnode1 = executionResult.getResultObject().getResults().get(testnode);
      assertNotNull(testnode1);
      assertTrue(testnode1 instanceof testResult);
      testResult failResult = (testResult) testnode1;
      assertEquals(1, failResult.flag);

      assertEquals(1, result.getResultSet().size());
      assertNotNull(result.getResultSet());
      assertNotNull(
          "missing key" + testnode + ": " + result.getResultSet().keySet(),
          result.getResultSet().get(testnode));
      final List<StatusResult> test1 = result.getResultSet().get(testnode);
      assertEquals(2, test1.size());
      for (final int i : new int[] {0, 1}) {
        final StatusResult interpreterResult = test1.get(i);
        assertTrue(interpreterResult instanceof testResult);
        testResult val = (testResult) interpreterResult;
        assertEquals(i, val.flag);
        if (0 == i) {
          assertTrue(val.isSuccess());
        } else {
          assertFalse(val.isSuccess());
        }
      }

      assertEquals(2, interpreterMock.executionItemList.size());

      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof ExecCommandExecutionItem);
      ExecCommandExecutionItem execItem = (ExecCommandExecutionItem) executionItem1;
      assertNotNull(execItem.getCommand());
      assertEquals(3, execItem.getCommand().length);
      assertEquals("a", execItem.getCommand()[0]);
      assertEquals("2", execItem.getCommand()[1]);
      assertEquals("command", execItem.getCommand()[2]);

      final ExecutionItem item2 = interpreterMock.executionItemList.get(1);
      assertTrue(
          "wrong class: " + item2.getClass().getName(),
          item2 instanceof ScriptFileCommandExecutionItem);
      ScriptFileCommandExecutionItem scriptItem = (ScriptFileCommandExecutionItem) item2;
      assertEquals("a command", scriptItem.getScript());
      assertNull(scriptItem.getScriptAsStream());
      assertNull(scriptItem.getServerScriptFilePath());
      assertNotNull(scriptItem.getArgs());
      assertEquals(2, scriptItem.getArgs().length);
      assertEquals("-testargs", scriptItem.getArgs()[0]);
      assertEquals("1", scriptItem.getArgs()[1]);

      assertEquals(2, interpreterMock.executionContextList.size());

      for (final int i : new int[] {0, 1}) {
        final ExecutionContext executionContext = interpreterMock.executionContextList.get(i);
        assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
        assertNull(executionContext.getDataContext());
        assertEquals(0, executionContext.getLoglevel());
        assertEquals("user1", executionContext.getUser());
        assertEquals(nodeset, executionContext.getNodeSelector());
        assertNull(executionContext.getArgs());
      }
    }
  }
コード例 #28
0
 public BundleContext(Framework framework, Bundle bundle) {
   this.framework = framework;
   this.bundle = bundle;
   this.context = framework.createServiceContext(this);
 }
コード例 #29
0
 /*
  * (non-Javadoc)
  *
  * @see com.yipsilon.osgi.IBundleContext#removeFrameworkListener(com.yipsilon.osgi.IFrameworkListener)
  */
 public void removeFrameworkListener(IFrameworkListener listener) {
   framework.removeFrameworkListener(listener);
 }
コード例 #30
0
 /*
  * (non-Javadoc)
  *
  * @see com.yipsilon.osgi.IBundleContext#removeBundleListener(com.yipsilon.osgi.IBundleListener)
  */
 public void removeBundleListener(IBundleListener listener) {
   framework.removeBundleListener(listener);
 }