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; }
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); }
@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); } }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override public void addRole(final Project project, final String role) { ConfigGroup thisProjectConfig = findProjectConfig(project.getRootPath()); if (thisProjectConfig == null) { thisProjectConfig = configurationFactory.newConfigGroup( ConfigType.PROJECT, project.getRootPath().toURI(), "Project '" + project.getProjectName() + "' configuration"); thisProjectConfig.addConfigItem( configurationFactory.newConfigItem("security:roles", new ArrayList<String>())); configurationService.addConfiguration(thisProjectConfig); } if (thisProjectConfig != null) { final ConfigItem<List> roles = thisProjectConfig.getConfigItem("security:roles"); roles.getValue().add(role); configurationService.updateConfiguration(thisProjectConfig); } else { throw new IllegalArgumentException("Project " + project.getProjectName() + " not found"); } }
@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; }
@Test public void testNewProjectCreation() throws URISyntaxException { final URI fs = new URI("git://test"); try { FileSystems.getFileSystem(fs); } catch (FileSystemNotFoundException e) { FileSystems.newFileSystem(fs, new HashMap<String, Object>()); } final Repository repository = mock(Repository.class); final String name = "p0"; final POM pom = new POM(); final String baseURL = "/"; final Path repositoryRootPath = mock(Path.class); when(repository.getRoot()).thenReturn(repositoryRootPath); when(repositoryRootPath.toURI()).thenReturn("git://test"); pom.getGav().setGroupId("org.kie.workbench.services"); pom.getGav().setArtifactId("kie-wb-common-services-test"); pom.getGav().setVersion("1.0.0-SNAPSHOT"); when(pomService.load(any(Path.class))).thenReturn(pom); final AbstractProjectService projectServiceSpy = spy(projectService); final Project project = projectServiceSpy.newProject(repository, name, pom, baseURL); verify(projectServiceSpy, times(1)) .simpleProjectInstance(any(org.uberfire.java.nio.file.Path.class)); assertEquals(pom, project.getPom()); }
private Package makePackage(final Project project, final Path resource) { final Path projectRoot = project.getRootPath(); final org.uberfire.java.nio.file.Path nioProjectRoot = Paths.convert(projectRoot); final org.uberfire.java.nio.file.Path nioMainSrcPath = nioProjectRoot.resolve(MAIN_SRC_PATH); final org.uberfire.java.nio.file.Path nioTestSrcPath = nioProjectRoot.resolve(TEST_SRC_PATH); final org.uberfire.java.nio.file.Path nioMainResourcesPath = nioProjectRoot.resolve(MAIN_RESOURCES_PATH); final org.uberfire.java.nio.file.Path nioTestResourcesPath = nioProjectRoot.resolve(TEST_RESOURCES_PATH); org.uberfire.java.nio.file.Path nioResource = Paths.convert(resource); if (Files.isRegularFile(nioResource)) { nioResource = nioResource.getParent(); } String packageName = null; org.uberfire.java.nio.file.Path packagePath = null; if (nioResource.startsWith(nioMainSrcPath)) { packagePath = nioMainSrcPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioTestSrcPath)) { packagePath = nioTestSrcPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioMainResourcesPath)) { packagePath = nioMainResourcesPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } else if (nioResource.startsWith(nioTestResourcesPath)) { packagePath = nioTestResourcesPath.relativize(nioResource); packageName = packagePath.toString().replaceAll("/", "."); } // Resource was not inside a package if (packageName == null) { return null; } final Path mainSrcPath = Paths.convert(nioMainSrcPath.resolve(packagePath)); final Path testSrcPath = Paths.convert(nioTestSrcPath.resolve(packagePath)); final Path mainResourcesPath = Paths.convert(nioMainResourcesPath.resolve(packagePath)); final Path testResourcesPath = Paths.convert(nioTestResourcesPath.resolve(packagePath)); final String displayName = getPackageDisplayName(packageName); final Package pkg = new Package( project.getRootPath(), mainSrcPath, testSrcPath, mainResourcesPath, testResourcesPath, packageName, displayName, getPackageRelativeCaption(displayName, resource.getFileName())); return pkg; }
@Override public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact( final GAV gav, final Project project, final MavenRepositoryMetadata... filter) { GAVPreferences gavPreferences = gavPreferencesProvider.get(); final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo = scopeResolutionStrategies.getUserInfoFor( GuvnorPreferenceScopes.PROJECT, project.getEncodedIdentifier()); gavPreferences.load(scopeResolutionStrategyInfo); if (gavPreferences.isConflictingGAVCheckDisabled()) { return Collections.EMPTY_SET; } final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact = new HashSet<MavenRepositoryMetadata>(); try { // Load Project's pom.xml final Path pomXMLPath = project.getPomXMLPath(); final org.uberfire.java.nio.file.Path nioPomXMLPath = Paths.convert(pomXMLPath); final String pomXML = ioService.readAllString(nioPomXMLPath); final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject)); // Filter results if necessary if (filter != null && filter.length > 0) { repositoriesResolvingArtifact.retainAll(Arrays.asList(filter)); } } catch (IllegalArgumentException iae) { log.error( "Unable to get Remote Repositories for Project '" + project.getProjectName() + "'. Returning empty Collection. ", iae); } catch (NoSuchFileException nsfe) { log.error( "Unable to get Remote Repositories for Project '" + project.getProjectName() + "'. Returning empty Collection. ", nsfe); } catch (org.uberfire.java.nio.IOException ioe) { log.error( "Unable to get Remote Repositories for Project '" + project.getProjectName() + "'. Returning empty Collection. ", ioe); } return repositoriesResolvingArtifact; }
@Before public void setup() { ApplicationPreferences.setUp(new HashMap<String, String>()); // The BuildOptions widget is manipulated in the Presenter so we need some nasty mocking when(view.getBuildOptionsButton()).thenReturn(buildOptions); when(buildOptions.getWidget(eq(0))).thenReturn(buildOptionsButton1); when(buildOptions.getWidget(eq(1))).thenReturn(buildOptionsMenu); when(buildOptionsMenu.getWidget(eq(0))).thenReturn(buildOptionsMenuButton1); when(buildOptionsMenu.getWidget(eq(1))).thenReturn(buildOptionsMenuButton1); constructProjectScreenPresenter( new CallerMock<BuildService>(buildService), new CallerMock<AssetManagementService>(assetManagementServiceMock)); // Mock ProjectScreenService final POM pom = new POM(new GAV("groupId", "artifactId", "version")); model = new ProjectScreenModel(); model.setPOM(pom); when(projectScreenService.load(any(org.uberfire.backend.vfs.Path.class))).thenReturn(model); // Mock BuildService when(buildService.buildAndDeploy(any(Project.class))).thenReturn(new BuildResults()); // Mock LockManager initialisation final Path path = mock(Path.class); final Metadata pomMetadata = mock(Metadata.class); model.setPOMMetaData(pomMetadata); when(pomMetadata.getPath()).thenReturn(path); final Metadata kmoduleMetadata = mock(Metadata.class); model.setKModuleMetaData(kmoduleMetadata); when(kmoduleMetadata.getPath()).thenReturn(path); final Metadata importsMetadata = mock(Metadata.class); model.setProjectImportsMetaData(importsMetadata); when(importsMetadata.getPath()).thenReturn(path); // Mock ProjectContext final Repository repository = mock(Repository.class); when(context.getActiveRepository()).thenReturn(repository); when(repository.getAlias()).thenReturn("repository"); when(repository.getCurrentBranch()).thenReturn("master"); final Project project = mock(Project.class); when(project.getProjectName()).thenReturn("project"); when(context.getActiveProject()).thenReturn(project); // Trigger initialisation of view. Unfortunately this is the only way to initialise a Project in // the Presenter context.onProjectContextChanged( new ProjectContextChangeEvent(mock(OrganizationalUnit.class), repository, project)); verify(view, times(1)).showBusyIndicator(eq(CommonConstants.INSTANCE.Loading())); verify(view, times(1)).hideBusyIndicator(); }
@Override public Set<MavenRepositoryMetadata> getRemoteRepositoriesMetaData(final Project project) { if (project == null) { return Collections.emptySet(); } final Set<MavenRepositoryMetadata> repositories = new HashSet<MavenRepositoryMetadata>(); try { // Load Project's pom.xml final Path pomXMLPath = project.getPomXMLPath(); final org.uberfire.java.nio.file.Path nioPomXMLPath = Paths.convert(pomXMLPath); final String pomXML = ioService.readAllString(nioPomXMLPath); final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); final Aether aether = new Aether(mavenProject); final Map<MavenRepositorySource, Collection<RemoteRepository>> remoteRepositories = getRemoteRepositories(mavenProject); // Local Repository repositories.add( makeRepositoryMetaData( aether.getSession().getLocalRepository(), MavenRepositorySource.LOCAL)); if (remoteRepositories.isEmpty()) { return repositories; } for (Map.Entry<MavenRepositorySource, Collection<RemoteRepository>> e : remoteRepositories.entrySet()) { repositories.addAll(makeRepositoriesMetaData(e.getValue(), e.getKey())); } } catch (IllegalArgumentException iae) { log.error( "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ", project.getProjectName(), iae); } catch (NoSuchFileException nsfe) { log.error( "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ", project.getProjectName(), nsfe); } catch (org.uberfire.java.nio.IOException ioe) { log.error( "Unable to get Remote Repositories for Project '%s'. Returning empty Collection. ", project.getProjectName(), ioe); } return repositories; }
@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; }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override public void removeRole(final Project project, final String role) { final ConfigGroup thisProjectConfig = findProjectConfig(project.getRootPath()); if (thisProjectConfig != null) { final ConfigItem<List> roles = thisProjectConfig.getConfigItem("security:roles"); roles.getValue().remove(role); configurationService.updateConfiguration(thisProjectConfig); } else { throw new IllegalArgumentException("Project " + project.getProjectName() + " not found"); } }
@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; }
private Project makeProject(final org.uberfire.java.nio.file.Path nioProjectRootPath) { final Path projectRootPath = Paths.convert(nioProjectRootPath); final Project project = simpleProjectInstance(nioProjectRootPath); // Copy in Security Roles required to access this resource final ConfigGroup projectConfiguration = findProjectConfig(projectRootPath); if (projectConfiguration != null) { ConfigItem<List<String>> roles = projectConfiguration.getConfigItem("security:roles"); if (roles != null) { for (String role : roles.getValue()) { project.getRoles().add(role); } } } return project; }
private void updateDependenciesClassLoader( final Project project, final KieModuleMetaData kieModuleMetaData) { KieProject kieProject = projectService.resolveProject(project.getPomXMLPath()); if (kieProject != null) { dependenciesClassLoaderCache.setDependenciesClassLoader( kieProject, LRUProjectDependenciesClassLoaderCache.buildClassLoader(kieProject, kieModuleMetaData)); } }
public void onProjectDelete(@Observes final DeleteProjectEvent event) { if (!getView().isVisible()) { return; } if (!Utils.isInRepository(activeRepository, event.getProject())) { return; } if (authorizationManager.authorize(event.getProject(), identity)) { if (activeProject != null && activeProject.equals(event.getProject())) { activeProject = null; } doInitialiseViewForActiveContext( activeOrganizationalUnit, activeRepository, null, null, null, true); } }
@Override public String execute(CliContext context) { StringBuffer result = new StringBuffer(); WeldContainer container = context.getContainer(); OrganizationalUnitService organizationalUnitService = container.instance().select(OrganizationalUnitService.class).get(); RepositoryService repositoryService = container.instance().select(RepositoryService.class).get(); ExplorerService projectExplorerService = container.instance().select(ExplorerService.class).get(); InputReader input = context.getInput(); System.out.print(">>Repository alias:"); String alias = input.nextLine(); Repository repo = repositoryService.getRepository(alias); if (repo == null) { return "No repository " + alias + " was found"; } OrganizationalUnit ou = null; Collection<OrganizationalUnit> units = organizationalUnitService.getOrganizationalUnits(); for (OrganizationalUnit unit : units) { if (unit.getRepositories().contains(repo)) { ou = unit; break; } } if (ou == null) { return "Could not find Organizational Unit containing repository. Unable to proceed."; } ArrayList<Project> projects = new ArrayList<Project>(); ProjectExplorerContentQuery query = new ProjectExplorerContentQuery(ou, repo, "master"); query.setOptions(new ActiveOptions()); ProjectExplorerContent content = projectExplorerService.getContent(query); projects.addAll(content.getProjects()); if (projects.size() == 0) { return "No projects found in repository " + alias; } int projectIndex = 0; while (projectIndex == 0) { System.out.println(">>Select project:"); for (int i = 0; i < projects.size(); i++) { System.out.println((i + 1) + ") " + projects.get(i).getProjectName()); } try { projectIndex = Integer.parseInt(input.nextLine()); } catch (NumberFormatException e) { System.out.println("Invalid index"); } if (projectIndex < 1 || projectIndex > projects.size()) { projectIndex = 0; System.out.println("Invalid index"); } } Project project = projects.get(projectIndex - 1); result.append("\tProject " + project.getProjectName() + "\n"); result.append("\t Modules: " + project.getModules() + "\n"); result.append("\t Root path: " + project.getRootPath().toURI() + "\n"); result.append("\t Pom path: " + project.getPomXMLPath().toURI() + "\n"); return result.toString(); }
@Override public ExecutionResults execute(CommandContext ctx) throws Exception { try { ExecutionResults executionResults = new ExecutionResults(); String repository = (String) getParameter(ctx, "GitRepository"); if (repository.endsWith(".git")) { repository = repository.substring(0, repository.length() - 4); } String branchToUpdate = (String) getParameter(ctx, "BranchName"); String version = (String) getParameter(ctx, "Version"); if (version == null) { version = "1.0.0"; } else if (!version.endsWith("-SNAPSHOT")) { version = version.concat("-SNAPSHOT"); } BeanManager beanManager = CDIUtils.lookUpBeanManager(ctx); logger.debug("BeanManager " + beanManager); POMService pomService = CDIUtils.createBean(POMService.class, beanManager); logger.debug("POMService " + pomService); IOService ioService = CDIUtils.createBean(IOService.class, beanManager, new NamedLiteral("ioStrategy")); logger.debug("IoService " + ioService); if (ioService != null) { ProjectService projectService = CDIUtils.createBean(new TypeLiteral<ProjectService<?>>() {}.getType(), beanManager); RepositoryService repositoryService = CDIUtils.createBean(RepositoryService.class, beanManager); logger.debug("RepositoryService " + repositoryService); if (repositoryService != null) { Repository repo = repositoryService.getRepository(repository); repo = repositoryService.getRepository(repo.getBranchRoot(branchToUpdate + "-" + version)); logger.debug("Updated repository " + repo); // update all pom.xml files of projects on the dev branch Set<Project> projects = getProjects(repo, ioService, projectService); for (Project project : projects) { POM pom = pomService.load(project.getPomXMLPath()); pom.getGav().setVersion(version); pomService.save( project.getPomXMLPath(), pom, null, "Update project version on development branch"); executionResults.setData(project.getProjectName() + "-GAV", pom.getGav().toString()); } } } return executionResults; } catch (Throwable e) { throw new AssetManagementRuntimeException(e); } }
@Before public void setup() { ioService = mock(IOService.class); pomService = mock(POMService.class); final KModuleService kModuleService = mock(KModuleService.class); final ProjectConfigurationContentHandler projectConfigurationContentHandler = new ProjectConfigurationContentHandler(); final ConfigurationService configurationService = mock(ConfigurationService.class); final ConfigurationFactory configurationFactory = mock(ConfigurationFactory.class); final Event<NewProjectEvent> newProjectEvent = mock(Event.class); final Event<NewPackageEvent> newPackageEvent = mock(Event.class); final Event<RenameProjectEvent> renameProjectEvent = mock(Event.class); final Event<DeleteProjectEvent> deleteProjectEvent = mock(Event.class); final Event<InvalidateDMOProjectCacheEvent> invalidateDMOCache = mock(Event.class); final User identity = mock(User.class); final SessionInfo sessionInfo = mock(SessionInfo.class); final Project project = mock(Project.class); final Path projectRootPath = mock(Path.class); when(project.getRootPath()).thenReturn(projectRootPath); when(projectRootPath.toURI()).thenReturn("git://test/p0"); when(ioService.createDirectory(any(org.uberfire.java.nio.file.Path.class))) .thenAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return invocation.getArguments()[0]; } }); projectService = new ProjectServiceImpl( ioService, pomService, kModuleService, projectConfigurationContentHandler, configurationService, configurationFactory, newProjectEvent, newPackageEvent, renameProjectEvent, deleteProjectEvent, invalidateDMOCache, identity, sessionInfo) { @Override // Override as we don't have the Project Structure set-up in this test protected boolean hasPom(final org.uberfire.java.nio.file.Path path) { return true; } @Override // Override as we don't have the Project Structure set-up in this test protected boolean hasKModule(final org.uberfire.java.nio.file.Path path) { return true; } @Override // Override Package resolution as we don't have the Project Structure set-up in this test public Package resolvePackage(final Path resource) { return makePackage(project, resource); } }; assertNotNull(projectService); }