Search in sources :

Example 21 with Import

use of org.kie.soup.project.datamodel.imports.Import in project kie-wb-common by kiegroup.

the class ExternalDataObjectsPresenterTest method testAddNewExternalDataObjects.

@Test
public void testAddNewExternalDataObjects() {
    externalDataObjectsPresenter.addNewExternalDataObjects();
    verify(itemPresenters).add(new Import(""));
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) Test(org.junit.Test)

Example 22 with Import

use of org.kie.soup.project.datamodel.imports.Import in project kie-wb-common by kiegroup.

the class ProjectScreenModelTest method testHashCode.

@Test
public void testHashCode() {
    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOM(new POM("test", "test", "url", new GAV("groupID", "artifactID", "version")));
    final MavenRepository repository = new MavenRepository();
    repository.setId("guvnor-m2-repo");
    repository.setName("Guvnor M2 Repo");
    repository.setUrl("http://localhost/maven2/");
    model.getPOM().addRepository(repository);
    model.setPOMMetaData(new Metadata());
    model.setKModule(new KModuleModel());
    model.setKModuleMetaData(new Metadata());
    model.setProjectTagsMetaData(new Metadata());
    model.setProjectImports(new ProjectImports());
    model.setProjectImportsMetaData(new Metadata());
    final int hashCode1 = model.hashCode();
    assertTrue(hashCode1 <= Integer.MAX_VALUE);
    assertTrue(hashCode1 >= Integer.MIN_VALUE);
    model.getProjectImports().getImports().addImport(new Import("java.lang.List"));
    final int hashCode2 = model.hashCode();
    assertTrue(hashCode2 <= Integer.MAX_VALUE);
    assertTrue(hashCode2 >= Integer.MIN_VALUE);
    assertNotEquals(hashCode1, hashCode2);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) MavenRepository(org.guvnor.common.services.project.model.MavenRepository) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) GAV(org.guvnor.common.services.project.model.GAV) POM(org.guvnor.common.services.project.model.POM) KModuleModel(org.kie.workbench.common.services.shared.kmodule.KModuleModel) Test(org.junit.Test)

Example 23 with Import

use of org.kie.soup.project.datamodel.imports.Import in project kie-wb-common by kiegroup.

the class IncrementalDataModelServiceImpl method getUpdates.

@Override
public PackageDataModelOracleIncrementalPayload getUpdates(final Path resourcePath, final Imports imports, final String factType) {
    PortablePreconditions.checkNotNull("resourcePath", resourcePath);
    PortablePreconditions.checkNotNull("imports", imports);
    PortablePreconditions.checkNotNull("factType", factType);
    final PackageDataModelOracleIncrementalPayload dataModel = new PackageDataModelOracleIncrementalPayload();
    try {
        // Check resource was within a Module structure
        final KieModule project = resolveModule(resourcePath);
        if (project == null) {
            return dataModel;
        }
        // Check resource was within a Package structure
        final Package pkg = resolvePackage(resourcePath);
        if (pkg == null) {
            return dataModel;
        }
        // Get the fully qualified class name of the fact type
        String fullyQualifiedClassName = factType;
        // Retrieve (or build) oracle and populate incremental content
        final PackageDataModelOracle oracle = cachePackages.assertPackageDataModelOracle(project, pkg);
        // Check if the FactType is already known to the DataModelOracle, otherwise we need to find the FQCN
        if (oracle.getModuleModelFields().get(fullyQualifiedClassName) == null) {
            for (Import imp : imports.getImports()) {
                if (imp.getType().endsWith(factType)) {
                    fullyQualifiedClassName = imp.getType();
                    break;
                }
            }
        }
        // If the FactType isn't recognised try using the Package Name
        if (oracle.getModuleModelFields().get(fullyQualifiedClassName) == null) {
            fullyQualifiedClassName = pkg.getPackageName() + "." + factType;
        }
        // If the FactType still isn't recognised return an empty payload
        if (oracle.getModuleModelFields().get(fullyQualifiedClassName) == null) {
            return dataModel;
        }
        DataModelOracleUtilities.populateDataModel(oracle, dataModel, fullyQualifiedClassName);
        return dataModel;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : PackageDataModelOracleIncrementalPayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleIncrementalPayload) Import(org.kie.soup.project.datamodel.imports.Import) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Package(org.guvnor.common.services.project.model.Package) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 24 with Import

use of org.kie.soup.project.datamodel.imports.Import in project kie-wb-common by kiegroup.

the class Builder method build.

public BuildResults build() {
    final BuildResults results = new BuildResults(projectGAV);
    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
        try {
            final Results kieResults = ((InternalKieBuilder) kieBuilder).buildAll(classFilter).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 {
            final PomModel pomModel = ((KieBuilderImpl) kieBuilder).getPomModel();
            if (pomModel != null) {
                pomModelCache.setEntry(project, pomModel);
            }
        }
    }
    // 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 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));
            }
        }
    }
    // Store the project dependencies ClassLoader for optimization purposes.
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(getKieModuleIgnoringErrors(), DependencyFilter.COMPILE_FILTER);
    updateDependenciesClassLoader(project, kieModuleMetaData);
    results.addAllBuildMessages(verifyClasses(kieModuleMetaData));
    return results;
}
Also used : Path(org.uberfire.java.nio.file.Path) BuildValidationHelper(org.guvnor.common.services.project.builder.service.BuildValidationHelper) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) KieBuilderImpl(org.drools.compiler.kie.builder.impl.KieBuilderImpl) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) Import(org.kie.soup.project.datamodel.imports.Import) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) Imports(org.kie.soup.project.datamodel.imports.Imports) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) IncrementalResults(org.kie.internal.builder.IncrementalResults) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) Results(org.kie.api.builder.Results) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) PomModel(org.appformer.maven.support.PomModel) Map(java.util.Map) HashMap(java.util.HashMap)

Example 25 with Import

use of org.kie.soup.project.datamodel.imports.Import in project kie-wb-common by kiegroup.

the class ImportsWidgetViewImplTest method checkAddImportSortsAlphabetically.

@Test
public void checkAddImportSortsAlphabetically() {
    final Import newImport = new Import("new1");
    when(addImportPopup.getImportType()).thenReturn(newImport.getType());
    when(presenter.isInternalImport(eq(newImport))).thenReturn(false);
    view.makeAddImportCommand().execute();
    verify(lockRequired).fire(any(LockRequiredEvent.class));
    final List<Import> imports = view.getDataProvider().getList();
    assertEquals(5, imports.size());
    assertEquals(internal2, imports.get(0));
    assertEquals(internal1, imports.get(1));
    assertEquals(newImport, imports.get(2));
    assertEquals(model2, imports.get(3));
    assertEquals(model1, imports.get(4));
}
Also used : LockRequiredEvent(org.uberfire.client.mvp.LockRequiredEvent) Import(org.kie.soup.project.datamodel.imports.Import) Test(org.junit.Test)

Aggregations

Import (org.kie.soup.project.datamodel.imports.Import)103 Test (org.junit.Test)79 Imports (org.kie.soup.project.datamodel.imports.Imports)26 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)25 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)14 ArrayList (java.util.ArrayList)12 Path (org.uberfire.java.nio.file.Path)12 Query (org.apache.lucene.search.Query)11 FactData (org.drools.workbench.models.testscenarios.shared.FactData)11 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)11 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)11 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)11 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)10 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)9 KieSession (org.kie.api.runtime.KieSession)9 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)9 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)9 Path (org.uberfire.backend.vfs.Path)9 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)8 Analyzer (org.drools.verifier.core.main.Analyzer)7