Deploy this resource.
@param resource
@param options
489551
public void deployResource(Resource resource, int options)
    {
    	String name = resource.getSymbolicName() + "/" + resource.getVersion();
        
    	Lock lock = this.getLock(name);
        try {
	        boolean acquired = lock.tryLock();
			if (acquired) {	// Good, deploy this resource
			    try {
			        Resolver resolver = repositoryAdmin.resolver();
			        resolver.add(resource);
			        int resolveAttempt = 5;
			        while (resolveAttempt-- > 0)
			        {
			            try {
			                if (resolver.resolve(options))
			                {
			                    resolver.deploy(options);
			                    break;     // Resolve successful, exception thrown on previous instruction if not
			                } else {
			                    Reason[] reqs = resolver.getUnsatisfiedRequirements();
			                    for (int i = 0; i < reqs.length; i++) {
			                        ClassServiceUtility.log(bundleContext, LogService.LOG_ERROR, "Unable to resolve: " + reqs[i]);
			                    }
			                    break;     // Resolve unsuccessful, but it did finish
			                }
			            } catch (IllegalStateException e) {
			                // If resolve unsuccessful, try again
			                if (resolveAttempt == 0)
			                    e.printStackTrace();
			            }
			        }
			    } finally {
			        lock.unlock();
			    }
			} else {	// Lock was not acquired, wait until it is unlocked and return (resource should be deployed by then)
				acquired = lock.tryLock(secondsToWait, TimeUnit.SECONDS);
				if (acquired) {
				    try {
				        // Success
				    } finally {
				        lock.unlock();
				    }
				} else {
				    // failure code here
				}
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			this.removeLock(name);
		}
    }
1151527
protected base_response add_resource(nitro_service service,options option)  throws Exception
	{
		if (!service.isLogin() && !this.get_object_type().equals("login"))
			service.login();
		String sessionid = service.get_sessionid();
		String request = resource_to_string(service, sessionid, option);
		return post_data(service,request);
	}
1048268
@Override
    public void onDeploy(DeploymentEvent event) {
        AbstractRuntimeManager runtimeManager = (AbstractRuntimeManager) event.getDeployedUnit().getRuntimeManager();        
        KieBase kieBase = runtimeManager.getEnvironment().getKieBase();
        Collection<Process> processes = kieBase.getProcesses(); 
        
        Map<String, DeployedAsset> mapProcessById = event.getDeployedUnit().getDeployedAssets()
                                                                            .stream()
                                                                            .collect(toMap(DeployedAsset::getId, asset -> asset));        
        for( Process process : processes ) {
            if( ((WorkflowProcess)process).isDynamic()) {
                String caseIdPrefix = collectCaseIdPrefix(process);
                Collection<CaseMilestone> caseMilestones = collectMilestoness(process);
                Collection<CaseStage> caseStages = collectCaseStages(event.getDeploymentId(), process.getId(), ((WorkflowProcess)process));                
                Collection<CaseRole> caseRoles = collectCaseRoles(process);
                Collection<AdHocFragment> adHocFragments = collectAdHocFragments((WorkflowProcess)process);
                Map<String, List<String>> dataAccessRestrictions = collectDataAccessRestrictions(process);
                
                CaseDefinitionImpl caseDef = new CaseDefinitionImpl((ProcessAssetDesc) mapProcessById.get(process.getId()), caseIdPrefix, caseStages, caseMilestones, caseRoles, adHocFragments, dataAccessRestrictions);
                
                availableCases.add(caseDef);
                caseIdGenerator.register(caseIdPrefix);
            }
        }
        
        // collect role information
        Collection<DeployedAsset> assets = event.getDeployedUnit().getDeployedAssets();
        List<String> roles = null;
        for( DeployedAsset asset : assets ) {
            if( asset instanceof ProcessAssetDesc ) {  
                // if it's not dynamic it's considered as not case definition
                if (!((ProcessAssetDesc) asset).isDynamic()) {
                    availableProcesses.add((ProcessAssetDesc) asset);
                }
                if (roles == null) {
                    roles = ((ProcessAssetDesc) asset).getRoles();
                }
            }
        }
        if (roles == null) {
            roles = Collections.emptyList();
        }
        deploymentRolesManager.addRolesForDeployment(event.getDeploymentId(), roles);

    }
813148
public static void copyResource(String resource, File destination) throws IOException {
        InputStream is = null;
        FileOutputStream fos = null;

        try {
            is = FileUtils.class.getResourceAsStream("/" + resource);
            fos = new FileOutputStream(destination);

            final byte[] buffer = new byte[10 * 1024];
            int len;
            while ((len = is.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }
        } finally {
            close(is);
            close(fos);
        }

    }
284942
@Override
    public void addResource(String namespace, String service, Object resource) {
        ServiceEndPoint endPoint = toEndPoint(namespace, service, resource);
        _environment.lifecycle().manage(new ManagedRegistration(_serviceRegistry, endPoint));
        _environment.jersey().register(resource);
    }
955610
public void setTargetForlder(CmsResource resource) {

        if (resource.isFolder()) {
            if (m_context.getResources().size() == 1) {
                try {
                    if (m_dialogMode.equals(DialogMode.copy)
                        | (m_dialogMode.equals(DialogMode.copy_and_move)
                            && CmsResource.getParentFolder(m_context.getResources().get(0).getRootPath()).equals(
                                resource.getRootPath()))) {
                        m_targetPath.setValue(getTargetName(m_context.getResources().get(0), resource));
                    } else {

                        m_targetPath.setValue(
                            getCms().getSitePath(resource) + getTargetName(m_context.getResources().get(0), resource));
                    }
                } catch (CmsException e) {
                    m_targetPath.setValue(getCms().getSitePath(resource));
                }
            } else {
                m_targetPath.setValue(getCms().getSitePath(resource));
            }

            updateDefaultActions(resource.getRootPath());
        } else {
            throw new CmsIllegalArgumentException(
                org.opencms.workplace.commons.Messages.get().container(
                    org.opencms.workplace.commons.Messages.ERR_COPY_MULTI_TARGET_NOFOLDER_1,
                    A_CmsUI.getCmsObject().getSitePath(resource)));
        }
    }
1315664
public static void run( Options options) throws Exception
    {
    if( options.showVersion())
      {
      System.out.println( getVersion());
      return;
      }
    logger_.info( "{}", getVersion());

    // Identify the system input definition file.
    File inputDefOption = options.getInputDef();
    if( inputDefOption != null && !inputDefOption.isAbsolute())
      {
      inputDefOption = new File( options.getWorkingDir(), inputDefOption.getPath());
      }

    File inputDefFile = inputDefOption;
    if( inputDefFile != null
        && !inputDefFile.exists()
        && !(inputDefFile = new File( inputDefOption.getPath() + "-Input.xml")).exists()
        && !(inputDefFile = new File( inputDefOption.getPath() + ".xml")).exists()
        && !(inputDefFile = new File( inputDefOption.getPath() + "-Input.json")).exists()
        && !(inputDefFile = new File( inputDefOption.getPath() + ".json")).exists())
        {
        throw new RuntimeException( "Can't locate input file for path=" + options.getInputDef());
        }

    File inputDir =
      inputDefFile==null
      ? options.getWorkingDir()
      : inputDefFile.getParentFile();

    Resource.Type defaultContentType =
      firstNonNull
      ( options.getContentType(),
        Resource.Type.of( inputDefFile),
        Resource.Type.XML);

    // Read the system input definition.
    logger_.info( "Reading system input definition={}", inputDefFile);
    SystemInputDef inputDef = null;
    try( SystemInputResource reader = withDefaultType( SystemInputResource.of( inputDefFile), defaultContentType))
      {
      inputDef = reader.getSystemInputDef();
      }
    catch( Exception e)
      {
      throw new RuntimeException( "Can't read input definition file=" + inputDefFile, e);
      }

    // Test definition defined?
    String projectName = getProjectName( inputDefFile);
    File testDefFile = options.getTestDef();
    if( testDefFile == null && inputDefFile != null)
      {
      // No, derive default from input file.
      testDefFile = withDefaultType( new File( projectName + "-Test"), defaultContentType);
      }

    // Identify base test definition file.
    File baseDefFile = testDefFile;
    if( baseDefFile != null && !baseDefFile.isAbsolute())
      {
      // For relative path, read base test definitions from input directory.
      baseDefFile = new File( inputDir, baseDefFile.getPath());
      }

    // Output file defined?
    File outputDir = options.getOutDir();
    File outputFile = options.getOutFile();
    if ( outputFile == null)
      {
      // No, defaults to...
      outputFile =
        // ... JUnit test class file, if generating JUnit
        options.getTransformType() == Options.TransformType.JUNIT && inputDefFile != null
        ? new File( projectName.replaceAll( "\\W+", "") + "Test.java") :

        // ... HTML file, if generating HTML
        options.getTransformType() == Options.TransformType.HTML && inputDefFile != null
        ? new File( projectName + "-Test.htm") :

        // ... else test definition file.
        testDefFile;
      }
    if( outputFile != null)
      {
      // Ensure output directory exists.
      if( outputDir == null)
        {
        outputDir =
          outputFile.isAbsolute()
          ? outputFile.getParentFile()
          : inputDir;
        }
      if( !outputDir.exists() && !outputDir.mkdirs())
        {
        throw new RuntimeException( "Can't create output directory=" + outputDir);
        }

      outputFile =
        new File
        ( outputDir,
          outputFile.isAbsolute()? outputFile.getName() : outputFile.getPath());
      }

    SystemTestDef baseDef = null;
    if( options.isExtended() && baseDefFile != null && baseDefFile.exists())
      {
      // Read the previous base test definitions.
      logger_.info( "Reading base test definition={}", baseDefFile);
      try( SystemTestResource reader = withDefaultType( SystemTestResource.of( baseDefFile), defaultContentType))
        {
        baseDef = reader.getSystemTestDef();
        }
      catch( Exception e)
        {
        throw new RuntimeException( "Can't read test definition file=" + baseDefFile, e);
        }
      }

    // Identify the generator definition file.
    File genDefFile = options.getGenDef();
    File genDefDefault = null;
    if( genDefFile != null)
      {
      if( !genDefFile.isAbsolute())
        {
        genDefFile = new File( inputDir, genDefFile.getPath());
        }
      }
    else if( inputDefFile != null)
      {
      genDefDefault = withDefaultType( new File( inputDir, projectName + "-Generators"), defaultContentType);
      if( genDefDefault.exists())
        {
        genDefFile = genDefDefault;
        }
      }

    // Generator definitions specified?
    IGeneratorSet genDef = null;
    if( genDefFile != null)
      {
      // Yes, read generator definitions.
      logger_.info( "Reading generator definition={}", genDefFile);
      try( GeneratorSetResource reader = withDefaultType( GeneratorSetResource.of( genDefFile), defaultContentType))
        {
        genDef = reader.getGeneratorSet();
        }
      catch( Exception e)
        {
        throw new RuntimeException( "Can't read generator definition file=" + genDefFile, e);
        }
      }
    else
      {
      // No, use default TupleGenerator.
      genDef = GeneratorSet.basicGenerator();
      }

    // Generate new test definitions.
    SystemTestDef testDef = Tcases.getTests( inputDef, genDef, baseDef, options.getGeneratorOptions());

    // Identify test definition transformations.
    AbstractFilter transformer = null;
    File transformDefFile = options.getTransformDef();
    if( transformDefFile != null)
      {
      if( !transformDefFile.isAbsolute())
        {
        transformDefFile = new File( inputDir, transformDefFile.getPath());
        }
      transformer = new TransformFilter( transformDefFile, options.getTransformParams());
      }
    else if( options.getTransformType() == Options.TransformType.JUNIT)
      {
      transformer = new TestDefToJUnitFilter( options.getTransformParams());
      }
    else if( options.getTransformType() == Options.TransformType.HTML)
      {
      transformer = new TestDefToHtmlFilter();
      }

    if( transformer != null)
      {
      if( outputFile != null && outputFile.equals( baseDefFile) && baseDefFile.exists())
        {
        throw new RuntimeException( "Transformed output will overwrite test definition file=" + baseDefFile);
        }
      transformer.setTarget( outputFile);
      }

    // Write new test definitions.
    try
      {
      logger_.info( "Updating test definition file={}", outputFile);

      OutputStream output =
        // Transformed output?
        transformer != null?
        transformer.getSource() :

        // Output file?
        outputFile != null?
        new FileOutputStream( outputFile) :

        // Standard output?
        null;

      Resource.Type outputFileType = firstNonNull( Resource.Type.of( withDefaultType( outputFile, defaultContentType)), defaultContentType);
      if( outputFileType == Resource.Type.JSON)
        {
        TcasesJson.writeTests( testDef, output);
        }
      else
        {
        TcasesIO.writeTests( testDef, output);
        }
      }
    catch( Exception e)
      {
      throw new RuntimeException( "Can't write test definition file=" + outputFile, e);
      }

    // Write any updates to generator definitions.
    File genUpdateFile =
      genDefFile != null?
      genDefFile :

      genDefDefault != null?
      genDefDefault :

      null;

    if( genUpdateFile != null && (options.getRandomSeed() != null || options.getDefaultTupleSize() != null))
      {
      logger_.info( "Updating generator definition={}", genUpdateFile);
      try
        {
        Resource.Type genUpdateType = firstNonNull( Resource.Type.of( withDefaultType( genUpdateFile, defaultContentType)), defaultContentType);
        if( genUpdateType == Resource.Type.JSON)
          {
          TcasesJson.writeGenerators( genDef, new FileOutputStream( genUpdateFile));
          }
        else
          {
          TcasesIO.writeGenerators( genDef, new FileOutputStream( genUpdateFile));
          }
        }
      catch( Exception e)
        {
        throw new RuntimeException( "Can't write generator definition file=" + genUpdateFile, e);
        }
      }
    }
683865
public Configuration setOptions(Option... options) {
        return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListeners).build();
    }
1107266
public function authorizePermissionResource($resource, array $options = [])
    {
        $permissions = $this->resourcePermissionMap();
        $collection  = new Collection;
        foreach ($permissions as $method => $ability) {
            $collection->push(new Fluent([
                'ability' => $ability,
                'method'  => $method,
            ]));
        }

        $collection->groupBy('ability')->each(function ($permission, $ability) use ($resource, $options) {
            $this->middleware("can:{$resource}.{$ability}")
                 ->only($permission->pluck('method')->toArray());
        });
    }
999196
public static void setOptions(Option firstOption, Option... rest) {
        configuration = configuration.withOptions(Options.empty().with(firstOption, rest));
    }
417337
public void addResource(String resource) {

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_MOD_RESOURCE_1, resource));
        }
        m_resources.add(resource);
    }
872304
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $targetPath = $deployment->getApplicationReleasePath($application);
        $this->shell->executeOrSimulate(
            'cd '.$targetPath.' && FLOW_CONTEXT='.$options['context'].' ./flow typo3.flow:cache:flush',
            $node,
            $deployment
        );
    }
950518
public void setImage(Resource resource)
    {
        ImageIcon image = null;
        if (resource != null && resource.exists())
        {
            try
            {
                image = new ImageIcon(resource.getURL());
            }
            catch (IOException e)
            {
                logger.warn("Error reading resource: " + resource);
                throw new RuntimeException("Error reading resource " + resource, e);
            }
        }
        setImage(image);
    }
337778
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        Assert::isInstanceOf($application, Flow::class, sprintf('Flow application needed for PublishResourcesTask, got "%s"', get_class($application)));

        if ($application->getVersion() >= '3.0') {
            $targetPath = $deployment->getApplicationReleasePath($application);
            $this->shell->executeOrSimulate($application->buildCommand($targetPath, 'resource:publish'), $node, $deployment);
        }
    }
1186019
public function apiResources(array $resources, array $options = [])
    {
        foreach ($resources as $name => $controller) {
            $this->apiResource($name, $controller, $options);
        }
    }
182239
public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
    {
        $releaseIdentifier = $deployment->getReleaseIdentifier();
        $releasesPath = $application->getReleasesPath();
        $commands = [
            "mkdir -p $releasesPath/$releaseIdentifier/Data",
            "cd $releasesPath/$releaseIdentifier",
            'ln -sf ../../../shared/Data/Logs ./Data/Logs',
            'ln -sf ../../../shared/Data/Persistent ./Data/Persistent'
        ];
        $this->shell->executeOrSimulate($commands, $node, $deployment);
    }
356600
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
        final ServiceModuleLoader deploymentModuleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
        final List<ResourceRoot> allResourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit);
        DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();

        Set<ModuleIdentifier> additionalModules = new HashSet<>();
        for(AdditionalModuleSpecification i : top.getAttachmentList(Attachments.ADDITIONAL_MODULES)) {
            additionalModules.add(i.getModuleIdentifier());
        }
        for (final ResourceRoot resourceRoot : allResourceRoots) {
            final Manifest manifest = resourceRoot.getAttachment(Attachments.MANIFEST);
            if (manifest == null)
                continue;

            final String dependencyString = ManifestHelper.getMainAttributeValue(manifest, DEPENDENCIES_ATTR);
            if (dependencyString == null)
                continue;

            if(deploymentUnit.getParent() == null &&
                    SubDeploymentMarker.isSubDeployment(resourceRoot)) {
                //we do not want ears reading sub deployments manifests
                continue;
            }

            final String[] dependencyDefs = dependencyString.split(",");
            for (final String dependencyDef : dependencyDefs) {
                final String trimmed = dependencyDef.trim();
                if(trimmed.isEmpty()) {
                    continue;
                }
                final String[] dependencyParts = trimmed.split(" ");

                final ModuleIdentifier dependencyId = ModuleIdentifier.fromString(dependencyParts[0]);
                final boolean export = containsParam(dependencyParts, EXPORT_PARAM);
                final boolean optional = containsParam(dependencyParts, OPTIONAL_PARAM);
                final boolean services = containsParam(dependencyParts, SERVICES_PARAM);
                final boolean annotations = containsParam(dependencyParts, ANNOTATIONS_PARAM);
                final boolean metaInf = containsParam(dependencyParts, META_INF);
                final ModuleLoader dependencyLoader;
                if (dependencyId.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX)) {
                    dependencyLoader = deploymentModuleLoader;
                } else {
                    dependencyLoader = Module.getBootModuleLoader();
                }
                if(annotations) {
                    deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, dependencyId);
                    if(dependencyLoader == deploymentModuleLoader && !additionalModules.contains(dependencyId)) {
                        //additional modules will not be created till much later, a dep on them would fail
                        phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId));
                    }
                }

                final ModuleDependency dependency = new ModuleDependency(dependencyLoader, dependencyId, optional, export, services, true);
                if(metaInf) {
                    dependency.addImportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), true);
                    dependency.addImportFilter(PathFilters.getMetaInfFilter(), true);
                }
                deploymentUnit.addToAttachmentList(Attachments.MANIFEST_DEPENDENCIES, dependency);
            }
        }

    }