@Override
 public int hashCode() {
   int result = pom != null ? pom.hashCode() : 0;
   result = 31 * result + (KModule != null ? KModule.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (POMMetaData != null ? POMMetaData.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (KModuleMetaData != null ? KModuleMetaData.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (projectImports != null ? projectImports.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (projectImportsMetaData != null ? projectImportsMetaData.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (projectTagsMetaData != null ? projectTagsMetaData.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (pathToPOM != null ? pathToPOM.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (pathToKModule != null ? pathToKModule.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (pathToImports != null ? pathToImports.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (pathToWhiteList != null ? pathToWhiteList.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (whiteList != null ? whiteList.hashCode() : 0);
   result = ~~result;
   result = 31 * result + (whiteListMetaData != null ? whiteListMetaData.hashCode() : 0);
   result = ~~result;
   return result;
 }
  private void createNewImports(
      final Path context, final List<Import> imports, final ConversionResult result) {

    if (imports == null || imports.isEmpty()) {
      return;
    }

    // Load existing PackageImports
    ProjectImports projectImports = new ProjectImports();
    final org.uberfire.java.nio.file.Path nioExternalImportsPath =
        Paths.convert(context).resolve("project.imports");
    final Path externalImportsPath = Paths.convert(nioExternalImportsPath);
    if (Files.exists(nioExternalImportsPath)) {
      projectImports = importsService.load(externalImportsPath);
    }

    // Make collections of existing Imports so we don't duplicate them when adding the new
    List<String> existingImports = new ArrayList<String>();
    for (org.drools.workbench.models.datamodel.imports.Import item :
        projectImports.getImports().getImports()) {
      existingImports.add(item.getType());
    }

    // Add imports
    boolean isModified = false;
    for (Import item : imports) {
      if (!existingImports.contains(item.getClassName())) {
        isModified = true;
        result.addMessage(
            "Created Import for '" + item.getClassName() + "'.", ConversionMessageType.INFO);
        projectImports
            .getImports()
            .addImport(
                new org.drools.workbench.models.datamodel.imports.Import(item.getClassName()));
      }
    }

    // Save update
    if (isModified) {
      final Metadata metadata = metadataService.getMetadata(context);
      importsService.save(
          externalImportsPath, projectImports, metadata, "Imports added during XLS conversion");
    }
  }
Пример #3
0
 private ProjectImports createProjectImports() {
   ProjectImports imports = new ProjectImports();
   imports.getImports().addImport(new Import("java.lang.Number"));
   return imports;
 }
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    ProjectScreenModel that = (ProjectScreenModel) o;

    if (KModule != null ? !KModule.equals(that.KModule) : that.KModule != null) {
      return false;
    }
    if (KModuleMetaData != null
        ? !KModuleMetaData.equals(that.KModuleMetaData)
        : that.KModuleMetaData != null) {
      return false;
    }
    if (POMMetaData != null ? !POMMetaData.equals(that.POMMetaData) : that.POMMetaData != null) {
      return false;
    }
    if (pathToImports != null
        ? !pathToImports.equals(that.pathToImports)
        : that.pathToImports != null) {
      return false;
    }
    if (pathToKModule != null
        ? !pathToKModule.equals(that.pathToKModule)
        : that.pathToKModule != null) {
      return false;
    }
    if (pathToPOM != null ? !pathToPOM.equals(that.pathToPOM) : that.pathToPOM != null) {
      return false;
    }
    if (pom != null ? !pom.equals(that.pom) : that.pom != null) {
      return false;
    }
    if (projectTagsMetaData != null
        ? !projectTagsMetaData.equals(that.projectTagsMetaData)
        : that.projectTagsMetaData != null) {
      return false;
    }
    if (projectImports != null
        ? !projectImports.equals(that.projectImports)
        : that.projectImports != null) {
      return false;
    }
    if (projectImportsMetaData != null
        ? !projectImportsMetaData.equals(that.projectImportsMetaData)
        : that.projectImportsMetaData != null) {
      return false;
    }
    if (pathToWhiteList != null
        ? !pathToWhiteList.equals(that.pathToWhiteList)
        : that.pathToWhiteList != null) {
      return false;
    }
    if (whiteList != null ? !whiteList.equals(that.whiteList) : that.whiteList != null) {
      return false;
    }
    if (whiteListMetaData != null
        ? !whiteListMetaData.equals(that.whiteListMetaData)
        : that.whiteListMetaData != null) {
      return false;
    }

    return true;
  }
  @Override
  public void setContent(final ProjectImports importTypes, final boolean isReadOnly) {
    checkNotNull("importTypes", importTypes);

    view.setContent(importTypes.getImports().getImports(), isReadOnly);
  }
Пример #6
0
  public BuildResults build() {
    synchronized (kieFileSystem) {
      // KieBuilder is not re-usable for successive "full" builds
      kieBuilder = createKieBuilder(kieFileSystem);

      // Record RTEs from KieBuilder - that can fail if a rule uses an inaccessible class
      final BuildResults results = new BuildResults(projectGAV);
      try {
        final Results kieResults = kieBuilder.buildAll().getResults();
        results.addAllBuildMessages(convertMessages(kieResults.getMessages(), handles));

      } catch (LinkageError e) {
        final String msg = MessageFormat.format(ERROR_CLASS_NOT_FOUND, e.getLocalizedMessage());
        logger.warn(msg);
        results.addBuildMessage(makeWarningMessage(msg));

      } catch (Throwable e) {
        final String msg = e.getLocalizedMessage();
        logger.error(msg, e);
        results.addBuildMessage(makeErrorMessage(msg));

      } finally {
        pomModelCache.setEntry(project, ((KieBuilderImpl) kieBuilder).getPomModel());
      }

      // Add validate messages from external helpers
      for (Map.Entry<Path, BuildValidationHelper> e : nonKieResourceValidationHelpers.entrySet()) {
        final org.uberfire.backend.vfs.Path vfsPath = Paths.convert(e.getKey());
        final List<ValidationMessage> validationMessages = e.getValue().validate(vfsPath);
        nonKieResourceValidationHelperMessages.put(e.getKey(), validationMessages);
        results.addAllBuildMessages(convertValidationMessages(validationMessages));
      }

      // Check external imports are available. These are loaded when a DMO is requested, but it's
      // better to report them early
      final org.uberfire.java.nio.file.Path nioExternalImportsPath =
          projectRoot.resolve("project.imports");
      if (Files.exists(nioExternalImportsPath)) {
        final org.uberfire.backend.vfs.Path externalImportsPath =
            Paths.convert(nioExternalImportsPath);
        final ProjectImports projectImports = importsService.load(externalImportsPath);
        final Imports imports = projectImports.getImports();
        for (final Import item : imports.getImports()) {
          final String fullyQualifiedClassName = item.getType();
          try {
            Class clazz = this.getClass().getClassLoader().loadClass(item.getType());

          } catch (ClassNotFoundException cnfe) {
            logger.warn(cnfe.getMessage());
            final String msg = MessageFormat.format(ERROR_CLASS_NOT_FOUND, fullyQualifiedClassName);
            results.addBuildMessage(makeWarningMessage(msg));
          }
        }
      }

      // At the end we are interested to ensure that external .jar files referenced as dependencies
      // don't have
      // referential inconsistencies. We will at least provide a basic algorithm to ensure that if
      // an external class
      // X references another external class Y, Y is also accessible by the class loader.
      final KieModuleMetaData kieModuleMetaData =
          KieModuleMetaData.Factory.newKieModuleMetaData(
              ((InternalKieBuilder) kieBuilder).getKieModuleIgnoringErrors());
      final Set<String> packageNamesWhiteList =
          packageNameWhiteList.filterPackageNames(project, kieModuleMetaData.getPackages());
      // store the project dependencies ClassLoader for optimization purposes.
      updateDependenciesClassLoader(project, kieModuleMetaData);

      for (final String packageName : kieModuleMetaData.getPackages()) {
        if (packageNamesWhiteList.contains(packageName)) {
          for (final String className : kieModuleMetaData.getClasses(packageName)) {
            final String fullyQualifiedClassName = packageName + "." + className;
            try {
              final Class clazz = kieModuleMetaData.getClass(packageName, className);
              if (clazz != null) {
                final TypeSource typeSource = getClassSource(kieModuleMetaData, clazz);
                if (TypeSource.JAVA_DEPENDENCY == typeSource) {
                  verifyExternalClass(clazz);
                }
              } else {
                final String msg =
                    MessageFormat.format(ERROR_EXTERNAL_CLASS_VERIFICATON, fullyQualifiedClassName);
                logger.warn(msg);
              }

            } catch (Throwable e) {
              final String msg =
                  MessageFormat.format(ERROR_EXTERNAL_CLASS_VERIFICATON, fullyQualifiedClassName);
              logger.warn(msg);
              results.addBuildMessage(makeWarningMessage(msg));
            }
          }
        }
      }

      return results;
    }
  }