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(""));
}
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);
}
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);
}
}
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;
}
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));
}
Aggregations