@Override public boolean isPom(final Path resource) { try { // Null resource paths cannot resolve to a Project if (resource == null) { return false; } // Check if path equals pom.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 pomFilePath = Paths.convert(project.getPomXMLPath()); return path.startsWith(pomFilePath); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
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)); } }
@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; }
@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 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); } }