List of usage examples for org.apache.maven.project MavenProject getPackaging
public String getPackaging()
From source file:org.universAAL.support.directives.checks.DependencyManagementCheckFix.java
License:Apache License
private Map<DependencyID, String> getActualVersions(MavenProject mavenProject2) { TreeMap<DependencyID, String> versionMap = new TreeMap<DependencyID, String>(); boolean containsSubPOMProjects = includesPOMSubProjects(mavenProject2); for (MavenProject mavenProject : reactorProjects) { if (mavenProject.getVersion() != null && (!mavenProject.getPackaging().equals("pom") || containsSubPOMProjects)) { // Check if its a pom, add it if not! versionMap.put(new DependencyID(mavenProject.getGroupId(), mavenProject.getArtifactId()), mavenProject.getVersion()); getLog().debug("added to ActualVersions: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion()); }//from ww w . j a va 2s. c o m } return versionMap; }
From source file:org.universAAL.support.directives.checks.LicenseFileCheckFix.java
License:Apache License
/** {@inheritDoc} */ public boolean check(MavenProject mavenproject, Log log) throws MojoExecutionException, MojoFailureException { String message = ""; if (mavenproject.getPackaging().equals("pom")) { return true; }/*from w w w.j av a 2 s . c o m*/ for (int i = 0; i < files.length; i++) { if (!new File(mavenproject.getBasedir(), files[i]).exists()) { message += NOT_FOUND + files[i] + "\n"; } } for (int i = 0; i < exFiles.length; i++) { if (new File(mavenproject.getBasedir(), exFiles[i]).exists()) { message += FOUND + exFiles[i] + "\n"; } } if (!message.isEmpty()) { throw new MojoFailureException(message); } return true; }
From source file:org.universAAL.support.directives.checks.MavenCoordinateCheck.java
License:Apache License
/** {@inheritDoc} */ public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException { String artifactIdMatchString = mavenProject.getProperties().getProperty(ARTIFACT_ID_MATCH_PROP, DEFAULT_MATCH);//from ww w . ja v a 2 s . c o m String groupIdMatchString = mavenProject.getProperties().getProperty(GROUP_ID_MATCH_PROP, DEFAULT_MATCH); String nameMatchString = mavenProject.getProperties().getProperty(NAME_MATCH_PROP, DEFAULT_MATCH); String versionMatchString = mavenProject.getProperties().getProperty(VERSION_MATCH_PROP, DEFAULT_MATCH); Pattern pAId = Pattern.compile(artifactIdMatchString); Pattern pGId = Pattern.compile(groupIdMatchString); Pattern pVer = Pattern.compile(versionMatchString); Pattern pNam = Pattern.compile(nameMatchString); Matcher mAId = pAId.matcher(mavenProject.getArtifactId()); Matcher mGId = pGId.matcher(mavenProject.getGroupId()); Matcher mVer = pVer.matcher(mavenProject.getVersion()); Matcher mNam = pNam.matcher(mavenProject.getName()); StringBuffer message = new StringBuffer(); if (!mAId.find()) { message.append("ArtifactId: " + mavenProject.getArtifactId() + DOES_NOT_MATCH_CONVENTION + artifactIdMatchString + "\n"); } if (!mGId.find()) { message.append("GroupId: " + mavenProject.getGroupId() + DOES_NOT_MATCH_CONVENTION + groupIdMatchString + "\n"); } if (!mVer.find()) { message.append("Version: " + mavenProject.getVersion() + DOES_NOT_MATCH_CONVENTION + versionMatchString + "\n"); } if (!mNam.find()) { message.append("Artifact Name: " + mavenProject.getName() + DOES_NOT_MATCH_CONVENTION + nameMatchString + "\n"); } if (message.length() > 0) { throw new MojoFailureException(message.toString()); } Model pomFileModel = null; try { pomFileModel = PomWriter.readPOMFile(mavenProject); } catch (Exception e) { } if (!mavenProject.getPackaging().equals("pom") && pomFileModel != null && (pomFileModel.getProperties().containsKey(ARTIFACT_ID_MATCH_PROP) || pomFileModel.getProperties().containsKey(GROUP_ID_MATCH_PROP) || pomFileModel.getProperties().containsKey(VERSION_MATCH_PROP) || pomFileModel.getProperties().containsKey(NAME_MATCH_PROP))) { throw new MojoFailureException("This project has declared naming conventions when it shoudln't.\n" + "This is probably an attempt to skip this directive, SHAME ON YOU!"); } return true; }
From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java
License:Apache License
private String getErrorMessge(MavenProject mavenProject) { if (mavenProject.getPackaging().equals("pom")) { String err = MODULES_NOT_CONFIGURED_ROOT; for (String mod : toBeFixed) { err += "\n\t" + mod + ", folder should be listed as a module?"; }//from w w w . jav a2s . co m return err; } return ""; }
From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java
License:Apache License
/** * Checks the project is a POM and a parent POM (ie it has no source). * @param mavenProject2// w w w .jav a 2 s . c om * @param log log element to output log info. * @return */ private boolean isAparentPOM(MavenProject mavenProject2, Log log) { boolean isAPOM = mavenProject2.getPackaging().equals("pom"); boolean containsSRC = false; for (File f : mavenProject2.getBasedir().listFiles()) { if (f.isDirectory()) { containsSRC |= f.getName().contains("src"); log.debug(f.getName()); log.debug(Boolean.toString(containsSRC)); } } return isAPOM & !containsSRC; }
From source file:org.whitesource.bamboo.agent.MavenOssInfoExtractor.java
License:Apache License
private boolean shouldProcess(MavenProject project) { if (project == null) { return false; }//from www . j a va 2s.c o m boolean process = true; if (ignorePomModules && "pom".equals(project.getPackaging())) { process = false; } else if (!excludes.isEmpty() && matchAny(project.getArtifactId(), excludes)) { process = false; } else if (!includes.isEmpty() && matchAny(project.getArtifactId(), includes)) { process = true; } return process; }
From source file:org.wso2.developerstudio.eclipse.maven.multi.module.handlers.MavenParentProjectList.java
License:Open Source License
public List<ListData> getListData(String modelProperty, ProjectDataModel model) { List<ListData> list = new ArrayList<ListData>(); boolean requiredParent = ((MvnMultiModuleModel) model).isRequiredParent(); boolean updateMode = ((MvnMultiModuleModel) model).isUpdateMode(); if (requiredParent && !updateMode) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject[] projects = root.getProjects(); for (IProject project : projects) { try { if (project.isOpen()) { File pomFile = project.getFile("pom.xml").getLocation().toFile(); if (pomFile.exists()) { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile); if (mavenProject.getPackaging().equals("pom")) { Parent parent = new Parent(); parent.setArtifactId(mavenProject.getArtifactId()); parent.setGroupId(mavenProject.getGroupId()); parent.setVersion(mavenProject.getVersion()); try { String relativePath = FileUtils.getRelativePath(model.getLocation(), pomFile); parent.setRelativePath(relativePath); ListData data = new ListData(parent.getArtifactId(), parent); list.add(data); } catch (Exception e) { log.error(e.getMessage(), e); }//from www .ja v a2 s .co m } } } } catch (Exception e) { log.error("Error reading project list", e); } } } return list; }
From source file:org.wso2.developerstudio.eclipse.maven.multi.module.handlers.MavenPomGeneratorHandler.java
License:Open Source License
public Object execute(ExecutionEvent arg0) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(arg0); IProject selectedUIElement = (IProject) selection.getFirstElement(); IFile pomFile = null;// www . ja v a2 s. c om boolean openQuestion = false; if (selectedUIElement.isOpen()) { pomFile = selectedUIElement.getFile("pom.xml"); if (pomFile.exists()) { // Check for the packaging type try { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); String packagingType = mavenProject.getPackaging(); if (!"pom".equalsIgnoreCase(packagingType)) { // If not pom ask user to confirm the pom overwrte operation openQuestion = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "Generate POM for the Project", "Are you sure you want to overwite the existing pom file?"); // If confirms, back up the pom and create the aggregator pom if (openQuestion) { IFolder backupFolder = selectedUIElement.getFolder("BACK_UP"); IFile backupFile = backupFolder.getFile("pom.xml"); FileUtils.copy(pomFile.getLocation().toFile(), backupFile.getLocation().toFile()); selectedUIElement.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // Open the new wizard openWizard(MAVEN_MUL_MODULE_WIZARD_ID, selectedUIElement); } } else { // If it is pom, extract the maven info and pop up the // wizard with that data and preserve the current // content and just add the new content openWizard(MAVEN_MUL_MODULE_WIZARD_ID, selectedUIElement); } } catch (Exception e) { log.error("Error occured while tying to access the maven project corresponding to pom file", e); } } else { openWizard(MAVEN_MUL_MODULE_WIZARD_ID, selectedUIElement); } } return null; }
From source file:org.wso2.developerstudio.eclipse.maven.multi.module.handlers.MvnMultiModuleWizard.java
License:Open Source License
public boolean performFinish() { // If the multiModuleProject is not empty, then this is thru UI. Just // generate the POM MavenProject mavenProject = MavenUtils.createMavenProject(moduleModel.getGroupId(), moduleModel.getArtifactId(), moduleModel.getVersion(), "pom"); if (moduleModel.isRequiredParent()) { Parent parent = new Parent(); parent.setArtifactId(moduleModel.getParentArtifact()); parent.setGroupId(moduleModel.getParentGroup()); parent.setVersion(moduleModel.getParentVersion()); String relativePath = moduleModel.getRelativePath(); if (relativePath != null && !relativePath.trim().isEmpty()) { parent.setRelativePath(relativePath); }//from w w w. j a va 2s .c o m mavenProject.getModel().setParent(parent); } else { mavenProject.getModel().setParent(null); } List modules = mavenProject.getModules(); List<IProject> selectedProjects = moduleModel.getSelectedProjects(); selectedProjects = sortProjects(selectedProjects); if (multiModuleProject != null) { IFile pomFile = multiModuleProject.getFile("pom.xml"); if (pomFile.exists()) { // Parse the pom and see the packaging type try { MavenProject mavenProject2 = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); String packaging = mavenProject2.getPackaging(); if (!"pom".equalsIgnoreCase(packaging)) { addMavenModules(multiModuleProject, mavenProject, modules, selectedProjects, pomFile); } else { modules = mavenProject2.getModules(); mavenProject2.setGroupId(moduleModel.getGroupId()); mavenProject2.setArtifactId(moduleModel.getArtifactId()); mavenProject2.setVersion(moduleModel.getVersion()); mavenProject2.getModel().setParent(mavenProject.getModel().getParent()); addMavenModules(multiModuleProject, mavenProject2, modules, selectedProjects, pomFile); } } catch (Exception e) { log.error("Error occured while trying to generate the Maven Project for the Project Pom", e); } } else { // Since pom is not there, just create the new pom with all the // necessary things addMavenModules(multiModuleProject, mavenProject, modules, selectedProjects, pomFile); } // Adding Maven Multi Module Nature to POM generated Project addMavenMultiModuleProjectNature(multiModuleProject); } else { try { moduleModel.setProjectName(moduleModel.getArtifactId()); project = createNewProject(); addMavenMultiModuleProjectNature(project); addMavenModules(project, mavenProject, modules, selectedProjects, project.getFile("pom.xml")); } catch (CoreException e) { log.error("Error occured while creating the new Maven Multi Module Project", e); } catch (ObserverFailedException e) { log.error("Error occured while trying to inject values to the Project Model", e); } } return true; }
From source file:org.wso2.developerstudio.eclipse.platform.ui.handlers.MavenPomGeneratorHandler.java
License:Open Source License
public Object execute(ExecutionEvent arg0) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(arg0); IProject selectedUIElement = (IProject) selection.getFirstElement(); IFile pomFile = null;// w ww . j a va 2 s. c o m boolean openQuestion = false; if (selectedUIElement.isOpen()) { pomFile = selectedUIElement.getFile("pom.xml"); if (pomFile.exists()) { // Check for the packaging type try { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); String packagingType = mavenProject.getPackaging(); if (!"pom".equalsIgnoreCase(packagingType)) { // If not pom ask user to confirm the pom overwrte operation openQuestion = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "Generate POM for the Project", "Are you sure you want to overwite the existing pom file?"); // If confirms, back up the pom and create the aggregator pom if (openQuestion) { IFolder backupFolder = selectedUIElement.getFolder("BACK_UP"); IFile backupFile = backupFolder.getFile("pom.xml"); FileUtils.copy(pomFile.getLocation().toFile(), backupFile.getLocation().toFile()); selectedUIElement.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // Open the new wizard openWizard(MAVEN_MUL_MODULE_WIZARD_ID, selectedUIElement); } } else { // If it is pom, extract the maven info and pop up the wizard with that data and preserve the current content and just add the new content openWizard(MAVEN_MUL_MODULE_WIZARD_ID, selectedUIElement); } } catch (Exception e) { log.error("Error occured while tying to access the maven project corresponding to pom file", e); } } else { openWizard(MAVEN_MUL_MODULE_WIZARD_ID, selectedUIElement); } } return null; }