@Override
  public ConversionResult convert(final Path path) {

    ConversionResult result = new ConversionResult();

    // Check Asset is of the correct format
    if (!xlsDTableType.accept(path)) {
      result.addMessage("Source Asset is not an XLS Decision Table.", ConversionMessageType.ERROR);
      return result;
    }

    // Perform conversion!
    final GuidedDecisionTableGeneratorListener listener = parseAssets(path, result);

    // Root path for new resources is the same folder as the XLS file
    final Path context = Paths.convert(Paths.convert(path).getParent());

    // Add Ancillary resources
    createNewImports(context, listener.getImports(), result);
    createNewFunctions(context, listener.getImports(), listener.getFunctions(), result);
    createNewQueries(context, listener.getImports(), listener.getQueries(), result);
    makeNewJavaTypes(context, listener.getTypeDeclarations(), result);
    createNewGlobals(context, listener.getGlobals(), result);

    // Add Web Guided Decision Tables
    createNewDecisionTables(
        context, listener.getImports(), listener.getGuidedDecisionTables(), result);

    return result;
  }
  @Override
  public Path create(
      final Path context, final String fileName, final String content, final String comment) {
    try {
      // Get the template for new Work Item Definitions, stored as a configuration item
      String defaultDefinition =
          workItemDefinitionElements
              .getDefinitionElements()
              .get(WORK_ITEMS_EDITOR_SETTINGS_DEFINITION);
      if (defaultDefinition == null) {
        defaultDefinition = "";
      }
      defaultDefinition = defaultDefinition.replaceAll("\\|", "");

      // Write file to VFS
      final org.uberfire.java.nio.file.Path nioPath = Paths.convert(context).resolve(fileName);
      final Path newPath = Paths.convert(nioPath);

      if (ioService.exists(nioPath)) {
        throw new FileAlreadyExistsException(nioPath.toString());
      }

      ioService.write(nioPath, defaultDefinition, makeCommentedOption(comment));

      return newPath;

    } catch (Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }
Example #3
0
  @Override
  public Package resolveParentPackage(final Package pkg) {
    final Set<String> packageNames = new HashSet<String>();

    final org.uberfire.java.nio.file.Path nioProjectRootPath =
        Paths.convert(pkg.getProjectRootPath());
    packageNames.addAll(
        getPackageNames(
            nioProjectRootPath,
            Paths.convert(pkg.getPackageMainSrcPath()).getParent(),
            true,
            false,
            false));

    // Construct Package objects for each package name
    for (String packagePathSuffix : packageNames) {
      for (String src : sourcePaths) {
        if (packagePathSuffix == null) {
          return null;
        }
        final org.uberfire.java.nio.file.Path nioPackagePath =
            nioProjectRootPath.resolve(src).resolve(packagePathSuffix);
        if (Files.exists(nioPackagePath)) {
          return resolvePackage(Paths.convert(nioPackagePath));
        }
      }
    }

    return null;
  }
  @Override
  public Path save(
      final Path path, final KModuleModel content, final Metadata metadata, final String comment) {
    try {
      if (metadata == null) {
        ioService.write(
            paths.convert(path),
            moduleContentHandler.toString(content),
            makeCommentedOption(comment));
      } else {
        ioService.write(
            paths.convert(path),
            moduleContentHandler.toString(content),
            metadataService.setUpAttributes(path, metadata),
            makeCommentedOption(comment));
      }

      // The pom.xml, kmodule.xml and project.imports are all saved from ProjectScreenPresenter
      // We only raise InvalidateDMOProjectCacheEvent and ResourceUpdatedEvent(pom.xml) events once
      // in POMService.save to avoid duplicating events (and re-construction of DMO).

      return path;

    } catch (Exception e) {
      e.printStackTrace();
      throw ExceptionUtilities.handleException(e);
    }
  }
Example #5
0
  @Override
  public boolean isKModule(final Path resource) {
    try {
      // Null resource paths cannot resolve to a Project
      if (resource == null) {
        return false;
      }

      // Check if path equals kmodule.xml
      final Project project = resolveProject(resource);
      // It's possible that the Incremental Build attempts to act on a Project file before the
      // project has been fully created.
      // This should be a short-term issue that will be resolved when saving a project batches
      // pom.xml, kmodule.xml and project.imports
      // etc into a single git-batch. At present they are saved individually leading to multiple
      // Incremental Build requests.
      if (project == null) {
        return false;
      }

      final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize();
      final org.uberfire.java.nio.file.Path kmoduleFilePath =
          Paths.convert(project.getKModuleXMLPath());
      return path.startsWith(kmoduleFilePath);

    } catch (Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }
  @Override
  public Path setUpKModuleStructure(final Path projectRoot) {
    try {
      // Create project structure
      final org.kie.commons.java.nio.file.Path nioRoot = paths.convert(projectRoot);

      ioService.createDirectory(nioRoot.resolve("src/main/java"));
      ioService.createDirectory(nioRoot.resolve("src/main/resources"));
      ioService.createDirectory(nioRoot.resolve("src/test/java"));
      ioService.createDirectory(nioRoot.resolve("src/test/resources"));

      final org.kie.commons.java.nio.file.Path pathToKModuleXML =
          nioRoot.resolve("src/main/resources/META-INF/kmodule.xml");
      ioService.createFile(pathToKModuleXML);
      ioService.write(pathToKModuleXML, moduleContentHandler.toString(new KModuleModel()));

      // Don't raise a NewResourceAdded event as this is handled at the Project level in
      // ProjectServices

      return paths.convert(pathToKModuleXML);

    } catch (Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }
Example #7
0
  @Override
  public void copy(final Path pathToPomXML, final String newName, final String comment) {
    try {
      final org.uberfire.java.nio.file.Path projectDirectory =
          Paths.convert(pathToPomXML).getParent();
      final org.uberfire.java.nio.file.Path newProjectPath =
          projectDirectory.resolveSibling(newName);

      final POM content = pomService.load(pathToPomXML);

      if (newProjectPath.equals(projectDirectory)) {
        return;
      }

      if (ioService.exists(newProjectPath)) {
        throw new FileAlreadyExistsException(newProjectPath.toString());
      }

      content.setName(newName);
      final Path newPathToPomXML = Paths.convert(newProjectPath.resolve("pom.xml"));
      ioService.startBatch();
      ioService.copy(projectDirectory, newProjectPath, makeCommentedOption(comment));
      pomService.save(newPathToPomXML, content, null, comment);
      ioService.endBatch();
      final Project newProject = resolveProject(Paths.convert(newProjectPath));
      newProjectEvent.fire(new NewProjectEvent(newProject, sessionInfo));

    } catch (final Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }
Example #8
0
  @Override
  public Package resolveDefaultPackage(final Project project) {
    final Set<String> packageNames = new HashSet<String>();
    if (project == null) {
      return null;
    }
    // Build a set of all package names across /src/main/java, /src/main/resources, /src/test/java
    // and /src/test/resources paths
    // It is possible (if the project was not created within the workbench that some packages only
    // exist in certain paths)
    final Path projectRoot = project.getRootPath();
    final org.uberfire.java.nio.file.Path nioProjectRootPath = Paths.convert(projectRoot);
    for (String src : sourcePaths) {
      final org.uberfire.java.nio.file.Path nioPackageRootSrcPath = nioProjectRootPath.resolve(src);
      packageNames.addAll(
          getPackageNames(nioProjectRootPath, nioPackageRootSrcPath, true, true, false));
    }

    // Construct Package objects for each package name
    final java.util.Set<String> resolvedPackages = new java.util.HashSet<String>();
    for (String packagePathSuffix : packageNames) {
      for (String src : sourcePaths) {
        final org.uberfire.java.nio.file.Path nioPackagePath =
            nioProjectRootPath.resolve(src).resolve(packagePathSuffix);
        if (Files.exists(nioPackagePath) && !resolvedPackages.contains(packagePathSuffix)) {
          return resolvePackage(Paths.convert(nioPackagePath));
        }
      }
    }

    return null;
  }
  public Path save(final Path resource, final InputStream content, final String comment) {
    log.info("USER:"******" UPDATING asset [" + resource.getFileName() + "]");

    try {
      final org.kie.commons.java.nio.file.Path nioPath = paths.convert(resource);
      final OutputStream outputStream =
          ioService.newOutputStream(nioPath, makeCommentedOption(comment));
      IOUtils.copy(content, outputStream);
      outputStream.flush();
      outputStream.close();

      // Read Path to ensure attributes have been set
      final Path newPath = paths.convert(nioPath);

      // Signal update to interested parties
      resourceUpdatedEvent.fire(new ResourceUpdatedEvent(newPath, sessionInfo));

      return newPath;

    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw ExceptionUtilities.handleException(e);

    } finally {
      try {
        content.close();
      } catch (IOException e) {
        throw ExceptionUtilities.handleException(e);
      }
    }
  }
  @Override
  public Path save(
      final Path context, final String fileName, final String content, final String comment) {
    final Path newPath = paths.convert(paths.convert(context).resolve(fileName), false);

    save(newPath, content, comment);

    return newPath;
  }
Example #11
0
  public Project simpleProjectInstance(final org.uberfire.java.nio.file.Path nioProjectRootPath) {
    final Path projectRootPath = Paths.convert(nioProjectRootPath);

    return new Project(
        projectRootPath,
        Paths.convert(nioProjectRootPath.resolve(POM_PATH)),
        Paths.convert(nioProjectRootPath.resolve(KMODULE_PATH)),
        Paths.convert(nioProjectRootPath.resolve(PROJECT_IMPORTS_PATH)),
        projectRootPath.getFileName());
  }
  @Override
  public Map getRangesMap(String namespace) {
    TreeMap treeMap = new TreeMap<String, String>();

    FormEditorContext context = formEditorContextManager.getRootEditorContext(namespace);

    if (context == null) return treeMap;

    Path currentForm = null;
    try {
      currentForm = paths.convert(ioService.get(new URI(context.getPath())));
    } catch (Exception e) {
      log.warn("Unable to load asset on '" + context.getPath() + "': ", e);
      return treeMap;
    }
    String currentFormDirUri = getFormDirUri(currentForm);
    String currentFormName = currentForm.getFileName();

    Project project = projectService.resolveProject(currentForm);

    FileUtils utils = FileUtils.getInstance();

    List<org.kie.commons.java.nio.file.Path> nioPaths =
        new ArrayList<org.kie.commons.java.nio.file.Path>();
    nioPaths.add(paths.convert(project.getRootPath()));

    Collection<FileUtils.ScanResult> forms = utils.scan(ioService, nioPaths, "form", true);

    String resourcesPath =
        paths
            .convert(projectService.resolveProject(currentForm).getRootPath())
            .resolve(SubformFinderService.MAIN_RESOURCES_PATH)
            .toUri()
            .getPath();

    Path formPath;
    String formDirUri;
    String formName;
    for (FileUtils.ScanResult form : forms) {
      formPath = paths.convert(form.getFile());
      formDirUri = getFormDirUri(formPath);
      formName = formPath.getFileName();

      if (currentFormDirUri.equals(formDirUri)
          && !formName.startsWith(".")
          && !currentFormName.equals(formName)) {
        treeMap.put(formPath.getFileName(), formPath.getFileName());
      }
    }
    return treeMap;
  }
  @Override
  public Path create(
      final Path context, final String fileName, final GlobalsModel content, final String comment) {
    final Path newPath = paths.convert(paths.convert(context).resolve(fileName), false);

    ioService.write(
        paths.convert(newPath),
        GlobalsPersistence.getInstance().marshal(content),
        makeCommentedOption(comment));

    // Signal creation to interested parties
    resourceAddedEvent.fire(new ResourceAddedEvent(newPath));

    return newPath;
  }
  private List<String> loadWorkItemImages(final Path resourcePath) {
    final Path projectRoot = projectService.resolveProject(resourcePath).getRootPath();
    final org.uberfire.java.nio.file.Path nioProjectPath = Paths.convert(projectRoot);
    final org.uberfire.java.nio.file.Path nioResourceParent =
        Paths.convert(resourcePath).getParent();

    final Collection<org.uberfire.java.nio.file.Path> imagePaths =
        fileDiscoveryService.discoverFiles(nioProjectPath, imageFilter, true);
    final List<String> images = new ArrayList<String>();
    for (org.uberfire.java.nio.file.Path imagePath : imagePaths) {
      final org.uberfire.java.nio.file.Path relativePath = nioResourceParent.relativize(imagePath);
      images.add(relativePath.toString());
    }
    return images;
  }
  private void visitPaths(final DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream) {
    for (final org.uberfire.java.nio.file.Path path : directoryStream) {
      if (Files.isDirectory(path)) {
        visitPaths(Files.newDirectoryStream(path));

      } else {
        // Don't process dotFiles
        if (!dotFileFilter.accept(path)) {

          // Resource Type might require "external" validation (i.e. it's not covered by Kie)
          final BuildValidationHelper validator = getBuildValidationHelper(path);
          if (validator != null) {
            nonKieResourceValidationHelpers.put(path, validator);
          }

          // Add new resource
          final String destinationPath =
              path.toUri().toString().substring(projectPrefix.length() + 1);
          final InputStream is = ioService.newInputStream(path);
          final BufferedInputStream bis = new BufferedInputStream(is);
          kieFileSystem.write(
              destinationPath,
              KieServices.Factory.get().getResources().newInputStreamResource(bis));
          handles.put(getBaseFileName(destinationPath), Paths.convert(path));

          // Java classes are handled by KIE so we can safely post-process them here
          addJavaClass(path);
        }
      }
    }
  }
 @Override
 public void save(final Path path, final GuidedDecisionTable52 model, final String comment) {
   ioService.write(
       paths.convert(path),
       GuidedDTXMLPersistence.getInstance().marshal(model),
       makeCommentedOption(comment));
 }
  @Test
  public void testNonPackageResourceUpdated() throws Exception {
    // This tests changes to a resource that is neither pom.xml nor kmodule.xml nor within a Package
    final Bean buildChangeListenerBean =
        (Bean)
            beanManager
                .getBeans(org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class)
                .iterator()
                .next();
    final CreationalContext cc = beanManager.createCreationalContext(buildChangeListenerBean);
    final org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder buildChangeListener =
        (org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder)
            beanManager.getReference(
                buildChangeListenerBean,
                org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class,
                cc);

    final URL resourceUrl = this.getClass().getResource("/BuildChangeListenerRepo/project.imports");
    final org.uberfire.java.nio.file.Path nioResourcePath = fs.getPath(resourceUrl.toURI());
    final Path resourcePath = paths.convert(nioResourcePath);

    // Force full build before attempting incremental changes
    final KieProject project = projectService.resolveProject(resourcePath);
    final BuildResults buildResults = buildService.build(project);
    assertNotNull(buildResults);
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());

    // Perform incremental build (Without a full Build first)
    buildChangeListener.updateResource(resourcePath);

    final IncrementalBuildResults incrementalBuildResults =
        buildResultsObserver.getIncrementalBuildResults();
    assertNull(incrementalBuildResults);
  }
  public Builder(
      final Project project,
      final IOService ioService,
      final KieProjectService projectService,
      final ProjectImportsService importsService,
      final List<BuildValidationHelper> buildValidationHelpers,
      final PackageNameWhiteList packageNameWhiteList,
      final LRUProjectDependenciesClassLoaderCache dependenciesClassLoaderCache,
      final LRUPomModelCache pomModelCache) {
    this.project = project;
    this.ioService = ioService;
    this.projectService = projectService;
    this.importsService = importsService;
    this.buildValidationHelpers = buildValidationHelpers;
    this.packageNameWhiteList = packageNameWhiteList;
    this.projectGAV = project.getPom().getGav();
    this.projectRoot = Paths.convert(project.getRootPath());
    this.projectPrefix = projectRoot.toUri().toString();
    this.kieServices = KieServices.Factory.get();
    this.kieFileSystem = kieServices.newKieFileSystem();
    this.dependenciesClassLoaderCache = dependenciesClassLoaderCache;
    this.pomModelCache = pomModelCache;

    DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream =
        Files.newDirectoryStream(projectRoot);
    visitPaths(directoryStream);
  }
  public Path save(
      final Path resource,
      final InputStream content,
      final String sessionId,
      final String comment) {
    log.info("USER:"******" UPDATING asset [" + resource.getFileName() + "]");

    try {
      final org.uberfire.java.nio.file.Path nioPath = Paths.convert(resource);
      final OutputStream outputStream =
          ioService.newOutputStream(nioPath, makeCommentedOption(sessionId, comment));
      IOUtils.copy(content, outputStream);
      outputStream.flush();
      outputStream.close();

      return resource;

    } catch (Exception e) {
      throw ExceptionUtilities.handleException(e);

    } finally {
      try {
        content.close();
      } catch (IOException e) {
        throw new org.uberfire.java.nio.IOException(e.getMessage());
      }
    }
  }
Example #20
0
 @Override
 public void saveKModule(
     String commitMessage, final Path path, final KModuleModel model, Metadata metadata) {
   if (metadata == null) {
     ioService.write(
         paths.convert(path),
         moduleContentHandler.toString(model),
         makeCommentedOption(commitMessage));
   } else {
     ioService.write(
         paths.convert(path),
         moduleContentHandler.toString(model),
         metadataService.setUpAttributes(path, metadata),
         makeCommentedOption(commitMessage));
   }
 }
  @Override
  public void save(
      final Path resource,
      final GuidedDecisionTable52 model,
      final ResourceConfig config,
      final Metadata metadata,
      final String comment) {

    final org.kie.commons.java.nio.file.Path path = paths.convert(resource);

    Map<String, Object> attrs;

    try {
      attrs = ioService.readAttributes(path);
    } catch (final NoSuchFileException ex) {
      attrs = new HashMap<String, Object>();
    }

    if (config != null) {
      attrs = resourceConfigService.configAttrs(attrs, config);
    }
    if (metadata != null) {
      attrs = metadataService.configAttrs(attrs, metadata);
    }

    ioService.write(
        path,
        GuidedDTXMLPersistence.getInstance().marshal(model),
        attrs,
        makeCommentedOption(comment));
  }
  public List<ValidationMessage> validate(
      final Path resourcePath,
      final InputStream resource,
      final DirectoryStream.Filter<org.uberfire.java.nio.file.Path>... supportingFileFilters) {

    final Project project = projectService.resolveProject(resourcePath);
    if (project == null) {
      return Collections.emptyList();
    }

    final KieServices kieServices = KieServices.Factory.get();
    final KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
    final String projectPrefix = project.getRootPath().toURI();

    // Add Java Model files
    final org.uberfire.java.nio.file.Path nioProjectRoot = paths.convert(project.getRootPath());
    final DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream =
        Files.newDirectoryStream(nioProjectRoot);
    visitPaths(projectPrefix, kieFileSystem, directoryStream, supportingFileFilters);

    // Add resource to be validated
    final String destinationPath = resourcePath.toURI().substring(projectPrefix.length() + 1);
    final BufferedInputStream bis = new BufferedInputStream(resource);

    kieFileSystem.write(
        destinationPath, KieServices.Factory.get().getResources().newInputStreamResource(bis));

    // Validate
    final KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
    final Results kieResults = kieBuilder.buildAll().getResults();
    final List<ValidationMessage> results = convertMessages(kieResults);

    return results;
  }
  @Override
  public List<JBPMProcessModel> getAvailableProcessModels(Path path) {

    Project project = projectService.resolveProject(path);

    FileUtils utils = FileUtils.getInstance();

    List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<>();

    nioPaths.add(Paths.convert(project.getRootPath()));

    Collection<FileUtils.ScanResult> processes = utils.scan(ioService, nioPaths, "bpmn2", true);

    List<JBPMProcessModel> result = new ArrayList<>();

    for (FileUtils.ScanResult process : processes) {
      org.uberfire.java.nio.file.Path formPath = process.getFile();

      try {
        ResourceSet resourceSet = new ResourceSetImpl();

        resourceSet
            .getResourceFactoryRegistry()
            .getExtensionToFactoryMap()
            .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new DroolsResourceFactoryImpl());
        resourceSet.getPackageRegistry().put(DroolsPackage.eNS_URI, DroolsPackage.eINSTANCE);
        resourceSet
            .getResourceFactoryRegistry()
            .getExtensionToFactoryMap()
            .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new Bpmn2ResourceFactoryImpl());
        resourceSet
            .getPackageRegistry()
            .put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);

        XMLResource outResource =
            (XMLResource)
                resourceSet.createResource(
                    URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
        outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
        outResource.setEncoding("UTF-8");

        Map<String, Object> options = new HashMap<String, Object>();
        options.put(XMLResource.OPTION_ENCODING, "UTF-8");
        outResource.load(ioService.newInputStream(formPath), options);

        DocumentRoot root = (DocumentRoot) outResource.getContents().get(0);

        Definitions definitions = root.getDefinitions();

        BusinessProcessFormModel processFormModel =
            bpmnFormModelGenerator.generateProcessFormModel(definitions);
        List<TaskFormModel> taskModels = bpmnFormModelGenerator.generateTaskFormModels(definitions);

        result.add(new JBPMProcessModel(processFormModel, taskModels));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return result;
  }
  public InputStream load(final Path path, final String sessionId) {
    try {
      final InputStream inputStream =
          ioService.newInputStream(Paths.convert(path), StandardOpenOption.READ);

      // Signal opening to interested parties
      resourceOpenedEvent.fire(
          new ResourceOpenedEvent(
              path,
              new SessionInfo() {
                @Override
                public String getId() {
                  return sessionId;
                }

                @Override
                public Identity getIdentity() {
                  return identity;
                }
              }));

      return inputStream;

    } catch (Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }
Example #25
0
  @Override
  public void delete(final Path pathToPomXML, final String comment) {
    try {
      final org.uberfire.java.nio.file.Path projectDirectory =
          Paths.convert(pathToPomXML).getParent();
      final Project project2Delete = resolveProject(Paths.convert(projectDirectory));

      ioService.delete(
          projectDirectory,
          StandardDeleteOption.NON_EMPTY_DIRECTORIES,
          new CommentedOption(sessionInfo.getId(), identity.getName(), null, comment));
      deleteProjectEvent.fire(new DeleteProjectEvent(project2Delete));
    } catch (final Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }
  public IncrementalBuildResults applyBatchResourceChanges(
      final Map<org.uberfire.backend.vfs.Path, Collection<ResourceChange>> changes) {
    synchronized (kieFileSystem) {
      checkNotNull("changes", changes);

      checkAFullBuildHasBeenPerformed();

      // Add all changes to KieFileSystem before executing the build
      final List<String> changedFilesKieBuilderPaths = new ArrayList<String>();
      final List<ValidationMessage> nonKieResourceValidatorAddedMessages =
          new ArrayList<ValidationMessage>();
      final List<ValidationMessage> nonKieResourceValidatorRemovedMessages =
          new ArrayList<ValidationMessage>();

      for (final Map.Entry<org.uberfire.backend.vfs.Path, Collection<ResourceChange>>
          pathCollectionEntry : changes.entrySet()) {
        for (final ResourceChange change : pathCollectionEntry.getValue()) {
          final ResourceChangeType type = change.getType();
          final Path resource = Paths.convert(pathCollectionEntry.getKey());

          checkNotNull("type", type);
          checkNotNull("resource", resource);

          final String destinationPath =
              resource.toUri().toString().substring(projectPrefix.length() + 1);
          changedFilesKieBuilderPaths.add(destinationPath);
          switch (type) {
            case ADD:
            case UPDATE:
              // Only files can be processed
              if (!Files.isRegularFile(resource)) {
                continue;
              }

              update(
                  nonKieResourceValidatorAddedMessages,
                  nonKieResourceValidatorRemovedMessages,
                  resource,
                  destinationPath);

              break;
            case DELETE:
              delete(nonKieResourceValidatorRemovedMessages, resource, destinationPath);
          }
        }
      }

      // Perform the Incremental build and get messages from incremental build
      final IncrementalBuildResults results = new IncrementalBuildResults(projectGAV);
      buildIncrementally(results, toArray(changedFilesKieBuilderPaths));

      // Copy in BuildMessages for non-KIE resources
      results.addAllAddedMessages(convertValidationMessages(nonKieResourceValidatorAddedMessages));
      results.addAllRemovedMessages(
          convertValidationMessages(nonKieResourceValidatorRemovedMessages));

      return results;
    }
  }
Example #27
0
  public String getSource(final Path path) throws SourceGenerationFailedException {
    final org.uberfire.java.nio.file.Path convertedPath = Paths.convert(path);

    if (sourceServices.hasServiceFor(convertedPath)) {
      return sourceServices.getServiceFor(convertedPath).getSource(convertedPath);
    } else {
      return "";
    }
  }
 private String getFullyQualifiedClassName(final Path path) {
   final Package pkg = projectService.resolvePackage(Paths.convert(path));
   final String packageName = pkg.getPackageName();
   if (packageName == null) {
     return null;
   }
   final String className = path.getFileName().toString().replace(".java", "");
   return (packageName.equals("") ? className : packageName + "." + className);
 }
 private BuildValidationHelper getBuildValidationHelper(final Path nioResource) {
   for (BuildValidationHelper validator : buildValidationHelpers) {
     final org.uberfire.backend.vfs.Path resource = Paths.convert(nioResource);
     if (validator.accepts(resource)) {
       return validator;
     }
   }
   return null;
 }
  @Override
  public GlobalsModel load(final Path path) {
    final String content = ioService.readAllString(paths.convert(path));

    // Signal opening to interested parties
    resourceOpenedEvent.fire(new ResourceOpenedEvent(path));

    return GlobalsPersistence.getInstance().unmarshal(content);
  }