List of usage examples for org.apache.maven.project MavenProject getName
public String getName()
From source file:aQute.bnd.maven.reporter.plugin.entries.mavenproject.CommonInfoPlugin.java
private String extractName(MavenProject project) { return project.getName() != null && !project.getName().isEmpty() ? project.getName() : null; }
From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java
License:Apache License
/** * Create a temporary file and fill it with Proguard configuration. * /*from w w w. j av a2s.c o m*/ * @param pArgsList List of args to push in Proguard configuration file * @param pMavenProject current project * @exception MojoExecutionException Exception throw if problem occurs on file creation */ private static File createFileConfiguration(List<String> pArgsList, MavenProject pMavenProject, File pOutputDirectory) throws MojoExecutionException { File vTempFile = null; try { String vFileName = pMavenProject.getName() + "arguments-inlining.proguardconf"; vTempFile = new File(pOutputDirectory.getAbsolutePath(), vFileName); Writer vWriter = new BufferedWriter(new FileWriter(vTempFile)); // Get iterator Iterator<String> vArgsIterator = pArgsList.iterator(); // Iterate and add each line with a space behind while (vArgsIterator.hasNext()) { String vNextArg = vArgsIterator.next(); vWriter.write(vNextArg + " "); } IOUtils.closeQuietly(vWriter); } catch (IOException pException) { throw new MojoExecutionException("Unable to create proguard configuration file ", pException); } return vTempFile; }
From source file:com.ardoq.mavenImport.ArdoqMavenImport.java
public List<String> startImport(List<String> importList, MavenUtil mavenUtil) throws IOException, Exception { if (importList.isEmpty()) { throw new Exception("At least one artifact must be specified!"); }/*from ww w .j a v a2 s . co m*/ ArdoqClient ardoqClient = new ArdoqClient(host, token); ardoqClient.setOrganization(org); ardoqClient.setLogLevel(RestAdapter.LogLevel.FULL); if (workspaceName == null || workspaceName.trim().length() == 0) { String artifactStr = importList.get(0); MavenProject mavenProject = mavenUtil.loadProject(artifactStr); workspaceName = "Maven project " + mavenProject.getName(); } Workspace workspace = findOrCreateWorkspace(importList, ardoqClient); Model model = ardoqClient.model().getModelById(workspace.getComponentModel()); System.out.println(model); String COMPONENT_TYPE_PROJECT = model.getComponentTypeByName("Project"); String COMPONENT_TYPE_GROUP = model.getComponentTypeByName("Group"); String COMPONENT_TYPE_ARTIFACT = model.getComponentTypeByName("Artifact"); String COMPONENT_TYPE_VERSION = model.getComponentTypeByName("Version"); Map<String, Field> fields = getModelFields(ardoqClient, model); ensureFieldExist(ardoqClient.field(), model, fields, "license", Arrays.asList(COMPONENT_TYPE_PROJECT, COMPONENT_TYPE_GROUP, COMPONENT_TYPE_ARTIFACT, COMPONENT_TYPE_VERSION), FieldType.TEXT, ""); ensureFieldExist(ardoqClient.field(), model, fields, "groupId", Arrays.asList(COMPONENT_TYPE_PROJECT, COMPONENT_TYPE_GROUP, COMPONENT_TYPE_ARTIFACT, COMPONENT_TYPE_VERSION), FieldType.TEXT, ""); ensureFieldExist(ardoqClient.field(), model, fields, "artifactId", Arrays.asList(COMPONENT_TYPE_PROJECT, COMPONENT_TYPE_ARTIFACT, COMPONENT_TYPE_VERSION), FieldType.TEXT, ""); ensureFieldExist(ardoqClient.field(), model, fields, "version", Arrays.asList(COMPONENT_TYPE_PROJECT, COMPONENT_TYPE_VERSION), FieldType.TEXT, ""); SyncUtil ardoqSync = new SyncUtil(ardoqClient, workspace); workspace.setViews(Arrays.asList("processflow", "componenttree", "tableview", "reader", "integrations")); ProjectSync projectSync = new ProjectSync(ardoqSync, mavenUtil); workspaceID = workspace.getId(); List<String> projectIDs = projectSync.syncProjects(importList); projectSync.addExclusions(mavenUtil); System.out.println("updating workspace"); ardoqSync.updateWorkspaceIfDifferent(workspace); System.out.println("Deleting not synced references"); ardoqSync.deleteNotSyncedItems(); return projectIDs; }
From source file:com.ardoq.mavenImport.ProjectSync.java
/** * Returns Ardoq project component ID/*from w w w .ja va 2 s .c o m*/ * @param project * @return */ private String syncProject(MavenProject project) { String componentName = project.getName(); if (componentNameIdMap.containsKey(componentName)) { return componentNameIdMap.get(componentName); } Component ardoqProjectComponent = new Component(componentName, ardoqSync.getWorkspace().getId(), "", COMPONENT_TYPE_PROJECT); ardoqProjectComponent.setDescription(buildProjectDescription(project)); Map<String, Object> fields = new HashMap<String, Object>(); fields.put("groupId", project.getGroupId()); fields.put("artifactId", project.getArtifactId()); fields.put("version", project.getVersion()); mavenUtil.addLicense(project, fields); ardoqProjectComponent.setFields(fields); ardoqProjectComponent = ardoqSync.addComponent(ardoqProjectComponent); componentNameIdMap.put(componentName, ardoqProjectComponent.getId()); Map<String, Integer> refTypes = ardoqSync.getModel().getReferenceTypes(); syncProjectArtifact(project, ardoqProjectComponent, refTypes); syncProjectParent(project, ardoqProjectComponent, refTypes); syncProjectModules(project, ardoqProjectComponent, refTypes); return ardoqProjectComponent.getId(); }
From source file:com.ardoq.mavenImport.ProjectSync.java
/** * NB! only modules named the same as the artifact will be synced * @param project/*from www . ja v a 2s. c om*/ * @param ardoqProjectComponent * @param refTypes * @throws DependencyCollectionException */ private void syncProjectModules(MavenProject project, Component ardoqProjectComponent, Map<String, Integer> refTypes) { for (String module : project.getModules()) { try { String groupId = project.getGroupId(); String artifactId = module; String version = project.getVersion(); String id = groupId + ":" + artifactId + ":" + version; String moduleComponentId = syncProject(id); if (moduleComponentId != null) { int refType = refTypes.get("Module"); Reference ref = new Reference(ardoqSync.getWorkspace().getId(), "artifact", ardoqProjectComponent.getId(), moduleComponentId, refType); ardoqSync.addReference(ref); } else { System.err.println("Error adding reference from " + ardoqProjectComponent.getId() + " " + moduleComponentId); } } catch (ArtifactResolutionException e) { System.out.println("***************************************************************"); System.out.println("* Error syncing Maven module " + module + " of " + project.getName()); System.out.println("* This tool assumes that the module name equals the artifactId. "); System.out.println("* -> ignoring and carrying on.. "); System.out.println("***************************************************************"); } } }
From source file:com.collir24.policyextractor.PolicyExtractorReport.java
License:Apache License
@Override protected void executeReport(Locale locale) throws MavenReportException { ResourceBundle localizedResources = getBundle(locale); Set<String> policySet = new TreeSet<String>(); Sink sink = getSink();//from w ww.jav a 2 s.co m sink.head(); sink.title(); sink.text(localizedResources.getString("report.pagetitle")); sink.title_(); sink.head_(); sink.body(); MavenProject project = getProject(); sink.sectionTitle1(); sink.text(localizedResources.getString("report.sectiontitle")); sink.sectionTitle1_(); Build build = project.getBuild(); sink.sectionTitle2(); sink.text(MessageFormat.format(localizedResources.getString("report.reportfor"), project.getName())); sink.sectionTitle2_(); sink.paragraph(); sink.text(localizedResources.getString("report.local.description")); sink.lineBreak(); sink.italic(); sink.text(localizedResources.getString("report.disclaimer")); sink.italic_(); sink.paragraph_(); Set<String> localProjectPolicySet = generateProjectPermissions(sink, project, build); generatePolicy(localProjectPolicySet, sink, null); policySet.addAll(localProjectPolicySet); sink.sectionTitle2(); sink.text(localizedResources.getString("report.allpermissions.title")); sink.sectionTitle2_(); sink.paragraph(); sink.text(localizedResources.getString("report.dependencies.description")); sink.paragraph_(); @SuppressWarnings("unchecked") Set<Artifact> artefacts = project.getArtifacts(); for (Artifact a : artefacts) { if (a.getScope().equals("test")) { continue; } JarFile jf; try { jf = new JarFile(a.getFile().getAbsolutePath()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Can't open file at: " + a.getFile().getAbsolutePath(), e); continue; } localProjectPolicySet = generateArtifactPermissions(sink, a, jf); generatePolicy(localProjectPolicySet, sink, a.getFile().getName()); policySet.addAll(localProjectPolicySet); } sink.sectionTitle2(); sink.text(localizedResources.getString("report.generatedpolicy.title")); sink.sectionTitle2_(); sink.paragraph(); sink.text(localizedResources.getString("report.generatedpolicy.description")); sink.paragraph_(); generatePolicy(policySet, sink, null); sink.sectionTitle2(); sink.text(localizedResources.getString("report.visualization.title")); sink.sectionTitle2_(); sink.paragraph(); String graphFilePath = outputDirectory + "/policyextractor.png"; new VisualizationGenerator(new File(graphFilePath)).generateVisualization(permissionList); sink.rawText("<img src=\"policyextractor.png\" width=\"300\">"); // sink.figure(); // sink.figureGraphics("policyextractor.png"); // sink.figure_(); sink.link("policyextractor.gexf"); sink.text("Graph Source"); sink.link_(); sink.paragraph_(); sink.body_(); sink.flush(); sink.close(); }
From source file:com.datacoper.maven.util.DCProjectUtil.java
private static MavenProject validateAndStartModule(MavenProject parentProjetct, String moduleName) throws DcRuntimeException { if (!parentProjetct.getModules().contains(moduleName)) { throw new DcRuntimeException("Module {0} is not located in parent project {0}", moduleName, parentProjetct.getName()); }/* w w w .j a v a 2s.c o m*/ String pathParent = parentProjetct.getBasedir().getPath(); MavenProject mavenProject = MavenUtil.startNewProject(pathParent.concat("/").concat(moduleName)); return mavenProject; }
From source file:com.effectivemaven.centrepoint.maven.repository.CentralRepositoryService.java
License:Apache License
public Project retrieveProject(String groupId, String artifactId, String version) throws RepositoryException { // get the project from the repository Artifact artifact = artifactFactory.createProjectArtifact(groupId, artifactId, version); MavenProject mavenProject; try {/*from ww w .java2 s .c om*/ mavenProject = projectBuilder.buildFromRepository(artifact, Collections.singletonList(repository), localRepository); } catch (ProjectBuildingException e) { throw new RepositoryException(e.getMessage(), e); } // populate the Centrepoint model from the Maven project Project project = new Project(); project.setId(MavenCoordinates.constructProjectId(groupId, artifactId)); project.setVersion(version); MavenCoordinates coordinates = new MavenCoordinates(); coordinates.setGroupId(groupId); coordinates.setArtifactId(artifactId); project.addExtensionModel(coordinates); project.setDescription(mavenProject.getDescription()); project.setName(mavenProject.getName()); if (mavenProject.getCiManagement() != null) { project.setCiManagementUrl(mavenProject.getCiManagement().getUrl()); } if (mavenProject.getIssueManagement() != null) { project.setIssueTrackerUrl(mavenProject.getIssueManagement().getUrl()); } if (mavenProject.getScm() != null) { project.setScmUrl(mavenProject.getScm().getUrl()); } project.setUrl(mavenProject.getUrl()); DistributionManagement distMgmt = mavenProject.getDistributionManagement(); if (distMgmt != null) { project.setRepositoryUrl(distMgmt.getRepository().getUrl()); project.setSnapshotRepositoryUrl(distMgmt.getSnapshotRepository().getUrl()); } return project; }
From source file:com.github.zhve.ideaplugin.IdeaListMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { ArtifactDependencyResolver resolver = new ArtifactDependencyResolver(getLog(), artifactFactory, artifactResolver, localRepository, artifactMetadataSource); ArtifactHolder artifactHolder = new ArtifactHolder(getLog(), resolver, reactorProjects); for (MavenProject project : reactorProjects) { List<Artifact> list = new ArrayList<Artifact>(artifactHolder.getDependencies(project)); Collections.sort(list, ArtifactComparator.INSTANCE); getLog().info(" \n" + "[INFO] ------------------------------------------------------------------------\n" + "[INFO] Listing " + project.getName() + " " + project.getId() + "\n" + "[INFO] ------------------------------------------------------------------------\n" + "[INFO] \n" + "[INFO] --- \n" + "[INFO] "); getLog().info("The following files have been resolved:"); for (Artifact artifact : list) getLog().info(/* w w w . j a va 2 s. c o m*/ " " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":" + (artifact.getClassifier() != null ? artifact.getClassifier() + ":" : "") + artifact.getVersion() + ":" + artifact.getScope()); getLog().info(""); } }
From source file:com.helger.maven.buildinfo.GenerateBuildInfoMojo.java
License:Apache License
private Map<String, String> _determineBuildInfoProperties() { // Get the current time, using the time zone specified in the settings final DateTime aDT = PDTFactory.getCurrentDateTime(); // Build the default properties final Map<String, String> aProps = new LinkedHashMap<String, String>(); // Version 1: initial // Version 2: added dependency information; added per build plugin the key // property// w ww. j a va2 s. co m aProps.put("buildinfo.version", "2"); // Project information aProps.put("project.groupid", project.getGroupId()); aProps.put("project.artifactid", project.getArtifactId()); aProps.put("project.version", project.getVersion()); aProps.put("project.name", project.getName()); aProps.put("project.packaging", project.getPackaging()); // Parent project information (if available) final MavenProject aParentProject = project.getParent(); if (aParentProject != null) { aProps.put("parentproject.groupid", aParentProject.getGroupId()); aProps.put("parentproject.artifactid", aParentProject.getArtifactId()); aProps.put("parentproject.version", aParentProject.getVersion()); aProps.put("parentproject.name", aParentProject.getName()); } // All reactor projects (nested projects) // Don't emit this, if this is "1" as than only the current project would be // listed if (reactorProjects != null && reactorProjects.size() != 1) { final String sPrefix = "reactorproject."; // The number of reactor projects aProps.put(sPrefix + "count", Integer.toString(reactorProjects.size())); // Show details of all reactor projects, index starting at 0 int nIndex = 0; for (final MavenProject aReactorProject : reactorProjects) { aProps.put(sPrefix + nIndex + ".groupid", aReactorProject.getGroupId()); aProps.put(sPrefix + nIndex + ".artifactid", aReactorProject.getArtifactId()); aProps.put(sPrefix + nIndex + ".version", aReactorProject.getVersion()); aProps.put(sPrefix + nIndex + ".name", aReactorProject.getName()); ++nIndex; } } // Build Plugins final List<?> aBuildPlugins = project.getBuildPlugins(); if (aBuildPlugins != null) { final String sPrefix = "build.plugin."; // The number of build plugins aProps.put(sPrefix + "count", Integer.toString(aBuildPlugins.size())); // Show details of all plugins, index starting at 0 int nIndex = 0; for (final Object aObj : aBuildPlugins) { final Plugin aPlugin = (Plugin) aObj; aProps.put(sPrefix + nIndex + ".groupid", aPlugin.getGroupId()); aProps.put(sPrefix + nIndex + ".artifactid", aPlugin.getArtifactId()); aProps.put(sPrefix + nIndex + ".version", aPlugin.getVersion()); final Object aConfiguration = aPlugin.getConfiguration(); if (aConfiguration != null) { // Will emit an XML structure! aProps.put(sPrefix + nIndex + ".configuration", aConfiguration.toString()); } aProps.put(sPrefix + nIndex + ".key", aPlugin.getKey()); ++nIndex; } } // Build dependencies final List<?> aDependencies = project.getDependencies(); if (aDependencies != null) { final String sDepPrefix = "dependency."; // The number of build plugins aProps.put(sDepPrefix + "count", Integer.toString(aDependencies.size())); // Show details of all dependencies, index starting at 0 int nDepIndex = 0; for (final Object aDepObj : aDependencies) { final Dependency aDependency = (Dependency) aDepObj; aProps.put(sDepPrefix + nDepIndex + ".groupid", aDependency.getGroupId()); aProps.put(sDepPrefix + nDepIndex + ".artifactid", aDependency.getArtifactId()); aProps.put(sDepPrefix + nDepIndex + ".version", aDependency.getVersion()); aProps.put(sDepPrefix + nDepIndex + ".type", aDependency.getType()); if (aDependency.getClassifier() != null) aProps.put(sDepPrefix + nDepIndex + ".classifier", aDependency.getClassifier()); aProps.put(sDepPrefix + nDepIndex + ".scope", aDependency.getScope()); if (aDependency.getSystemPath() != null) aProps.put(sDepPrefix + nDepIndex + ".systempath", aDependency.getSystemPath()); aProps.put(sDepPrefix + nDepIndex + ".optional", Boolean.toString(aDependency.isOptional())); aProps.put(sDepPrefix + nDepIndex + ".managementkey", aDependency.getManagementKey()); // Add all exclusions of the current dependency final List<?> aExclusions = aDependency.getExclusions(); if (aExclusions != null) { final String sExclusionPrefix = sDepPrefix + nDepIndex + ".exclusion."; // The number of build plugins aProps.put(sExclusionPrefix + "count", Integer.toString(aExclusions.size())); // Show details of all dependencies, index starting at 0 int nExclusionIndex = 0; for (final Object aExclusionObj : aExclusions) { final Exclusion aExclusion = (Exclusion) aExclusionObj; aProps.put(sExclusionPrefix + nExclusionIndex + ".groupid", aExclusion.getGroupId()); aProps.put(sExclusionPrefix + nExclusionIndex + ".artifactid", aExclusion.getArtifactId()); ++nExclusionIndex; } } ++nDepIndex; } } // Build date and time aProps.put("build.datetime", aDT.toString()); aProps.put("build.datetime.millis", Long.toString(aDT.getMillis())); aProps.put("build.datetime.date", aDT.toLocalDate().toString()); aProps.put("build.datetime.time", aDT.toLocalTime().toString()); aProps.put("build.datetime.timezone", aDT.getZone().getID()); final int nOfsMilliSecs = aDT.getZone().getOffset(aDT); aProps.put("build.datetime.timezone.offsethours", Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_HOUR)); aProps.put("build.datetime.timezone.offsetmins", Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_MINUTE)); aProps.put("build.datetime.timezone.offsetsecs", Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_SECOND)); aProps.put("build.datetime.timezone.offsetmillisecs", Integer.toString(nOfsMilliSecs)); // Emit system properties? if (withAllSystemProperties || CollectionHelper.isNotEmpty(selectedSystemProperties)) for (final Map.Entry<String, String> aEntry : CollectionHelper .getSortedByKey(SystemProperties.getAllProperties()).entrySet()) { final String sName = aEntry.getKey(); if (withAllSystemProperties || _matches(selectedSystemProperties, sName)) if (!_matches(ignoredSystemProperties, sName)) aProps.put("systemproperty." + sName, aEntry.getValue()); } // Emit environment variable? if (withAllEnvVars || CollectionHelper.isNotEmpty(selectedEnvVars)) for (final Map.Entry<String, String> aEntry : CollectionHelper.getSortedByKey(System.getenv()) .entrySet()) { final String sName = aEntry.getKey(); if (withAllEnvVars || _matches(selectedEnvVars, sName)) if (!_matches(ignoredEnvVars, sName)) aProps.put("envvar." + sName, aEntry.getValue()); } return aProps; }