List of usage examples for org.apache.maven.project MavenProject getId
public String getId()
From source file:com.soebes.maven.extensions.incremental.IncrementalModuleBuilder.java
License:Apache License
@Override public void build(final MavenSession session, final ReactorContext reactorContext, ProjectBuildList projectBuilds, final List<TaskSegment> taskSegments, ReactorBuildStatus reactorBuildStatus) throws ExecutionException, InterruptedException { // Think about this? if (!session.getCurrentProject().isExecutionRoot()) { LOGGER.info("Not executing in root."); }//from w w w . j av a 2 s .c om Path projectRootpath = session.getTopLevelProject().getBasedir().toPath(); if (!havingScmDeveloperConnection(session)) { LOGGER.warn("There is no scm developer connection configured."); LOGGER.warn("So we can't estimate which modules have changed."); return; } // TODO: Make more separation of concerns..(Extract the SCM Code from // here? ScmRepository repository = null; try { // Assumption: top level project contains the SCM entry. repository = scmManager .makeScmRepository(session.getTopLevelProject().getScm().getDeveloperConnection()); } catch (ScmRepositoryException | NoSuchScmProviderException e) { LOGGER.error("Failure during makeScmRepository", e); return; } StatusScmResult result = null; try { result = scmManager.status(repository, new ScmFileSet(session.getTopLevelProject().getBasedir())); } catch (ScmException e) { LOGGER.error("Failure during status", e); return; } List<ScmFile> changedFiles = result.getChangedFiles(); if (changedFiles.isEmpty()) { LOGGER.info(" Nothing has been changed."); } else { for (ScmFile scmFile : changedFiles) { LOGGER.info(" Changed file: " + scmFile.getPath() + " " + scmFile.getStatus()); } ModuleCalculator mc = new ModuleCalculator(session.getProjectDependencyGraph().getSortedProjects(), changedFiles); List<MavenProject> calculateChangedModules = mc.calculateChangedModules(projectRootpath); for (MavenProject mavenProject : calculateChangedModules) { LOGGER.info("Changed Project: " + mavenProject.getId()); } IncrementalModuleBuilderImpl incrementalModuleBuilderImpl = new IncrementalModuleBuilderImpl( calculateChangedModules, lifecycleModuleBuilder, session, reactorContext, taskSegments); // Really build only changed modules. incrementalModuleBuilderImpl.build(); } }
From source file:com.soebes.maven.extensions.incremental.IncrementalModuleBuilderImpl.java
License:Apache License
public void build() throws ExecutionException, InterruptedException { this.mavenSession.setProjects(this.projects); logger.info("New Calculated Reactor:"); for (MavenProject mavenProject : this.mavenSession.getProjects()) { logger.info(" {}", mavenProject.getName()); }/*from www . j av a2 s. c o m*/ for (TaskSegment taskSegment : this.taskSegments) { logger.debug("Segment"); List<Object> tasks = taskSegment.getTasks(); for (Object task : tasks) { logger.debug(" Task:" + task); } for (MavenProject mavenProject : mavenSession.getProjects()) { logger.info("Building project: {}", mavenProject.getId()); lifecycleModuleBuilder.buildProject(mavenSession, reactorContext, mavenProject, taskSegment); } } }
From source file:com.soebes.maven.extensions.ProjectTimer.java
License:Apache License
private String getProjectId(MavenProject mavenProject) { return mavenProject.getId(); }
From source file:de.eacg.ecs.plugin.ScanAndTransferMojo.java
private void printStats(Set<Map.Entry<String, SortedSet<MavenProject>>> licenseAndProjectSet, Set<Map.Entry<MavenProject, String[]>> projectsAndLicenseSet) { Log log = getLog();/*from www . j a v a 2s . co m*/ if (log.isInfoEnabled() && this.verbose) { log.info("Dependencies found:"); for (Map.Entry<MavenProject, String[]> entry : projectsAndLicenseSet) { MavenProject project = entry.getKey(); String[] licenses = entry.getValue(); log.info(String.format("%s %s, %s", project.getId(), project.getName(), Arrays.toString(licenses))); } } if (log.isInfoEnabled()) { log.info("Licenses found:"); for (Map.Entry<String, SortedSet<MavenProject>> entry : licenseAndProjectSet) { log.info(String.format("%-75s %d", entry.getKey(), entry.getValue().size())); } } }
From source file:hudson.maven.reporters.MavenFingerprinter.java
License:Open Source License
private void recordParents(MavenBuildProxy build, MavenProject pom, BuildListener listener) throws IOException, InterruptedException { Map<String, String> modelParents = build.getMavenBuildInformation().modelParents; ArtifactRepository localRepository = getLocalRepository(build.getMavenBuildInformation(), pom); if (localRepository == null) { listener.error(//from www.j a v a2s. c om "Could not find local repository for " + build.getMavenBuildInformation().getMavenVersion()); return; } String parent = modelParents.get(pom.getId()); while (parent != null) { String[] parts = parent.split(":"); assert parts.length == 4 : parent; // Maven 2.x lacks DefaultArtifact constructor with String version and ArtifactRepository.find: Artifact parentArtifact = new DefaultArtifact(parts[0], parts[1], VersionRange.createFromVersion(parts[3]), null, parts[2], null, new DefaultArtifactHandler(parts[2])); File parentFile = new File(localRepository.getBasedir(), localRepository.pathOf(parentArtifact)); // we need to include the artifact Id for poms as well, otherwise a project with the same groupId would override its parent's fingerprint record(parts[0] + ":" + parts[1], parentFile, used); parent = modelParents.get(parent); } }
From source file:io.sarl.maven.docs.AbstractDocumentationMojo.java
License:Apache License
private Properties createProjectProperties() { final Properties props = new Properties(); final MavenProject prj = this.session.getCurrentProject(); props.put("project.groupId", prj.getGroupId()); //$NON-NLS-1$ props.put("project.artifactId", prj.getArtifactId()); //$NON-NLS-1$ props.put("project.basedir", prj.getBasedir()); //$NON-NLS-1$ props.put("project.description", prj.getDescription()); //$NON-NLS-1$ props.put("project.id", prj.getId()); //$NON-NLS-1$ props.put("project.inceptionYear", prj.getInceptionYear()); //$NON-NLS-1$ props.put("project.name", prj.getName()); //$NON-NLS-1$ props.put("project.version", prj.getVersion()); //$NON-NLS-1$ props.put("project.url", prj.getUrl()); //$NON-NLS-1$ props.put("project.encoding", this.encoding); //$NON-NLS-1$ return props; }
From source file:ms.dew.devops.kernel.config.ConfigBuilder.java
License:Apache License
private static FinalProjectConfig doBuildProject(DewConfig dewConfig, AppKindPlugin appKindPlugin, DeployPlugin deployPlugin, MavenProject mavenProject, String inputProfile, String inputDockerHost, String inputDockerRegistryUrl, String inputDockerRegistryUserName, String inputDockerRegistryPassword, String inputKubeBase64Config, Optional<String> dockerHostAppendOpt, Optional<String> dockerRegistryUrlAppendOpt, Optional<String> dockerRegistryUserNameAppendOpt, Optional<String> dockerRegistryPasswordAppendOpt, Optional<String> kubeBase64ConfigAppendOpt) throws InvocationTargetException, IllegalAccessException { FinalProjectConfig finalProjectConfig = new FinalProjectConfig(); if (inputProfile.equalsIgnoreCase(FLAG_DEW_DEVOPS_DEFAULT_PROFILE)) { $.bean.copyProperties(finalProjectConfig, dewConfig); } else {/*from ww w.ja va 2 s . c o m*/ $.bean.copyProperties(finalProjectConfig, dewConfig.getProfiles().get(inputProfile)); } // setting basic finalProjectConfig.setId(mavenProject.getId()); finalProjectConfig.setAppKindPlugin(appKindPlugin); finalProjectConfig.setDeployPlugin(deployPlugin); finalProjectConfig.setProfile(inputProfile); finalProjectConfig.setAppGroup(mavenProject.getGroupId()); finalProjectConfig.setAppName(mavenProject.getArtifactId()); finalProjectConfig.setSkip(false); if (mavenProject.getName() != null && !mavenProject.getName().trim().isEmpty()) { finalProjectConfig.setAppShowName(mavenProject.getName()); } else { finalProjectConfig.setAppShowName(mavenProject.getArtifactId()); } // ? if (inputDockerHost != null && !inputDockerHost.trim().isEmpty()) { finalProjectConfig.getDocker().setHost(inputDockerHost.trim()); } if (inputDockerRegistryUrl != null && !inputDockerRegistryUrl.trim().isEmpty()) { finalProjectConfig.getDocker().setRegistryUrl(inputDockerRegistryUrl.trim()); } if (inputDockerRegistryUserName != null && !inputDockerRegistryUserName.trim().isEmpty()) { finalProjectConfig.getDocker().setRegistryUserName(inputDockerRegistryUserName.trim()); } if (inputDockerRegistryPassword != null && !inputDockerRegistryPassword.trim().isEmpty()) { finalProjectConfig.getDocker().setRegistryPassword(inputDockerRegistryPassword.trim()); } if (inputKubeBase64Config != null && !inputKubeBase64Config.trim().isEmpty()) { finalProjectConfig.getKube().setBase64Config(inputKubeBase64Config.trim()); } // setting path finalProjectConfig.setDirectory(mavenProject.getBasedir().getPath() + File.separator); finalProjectConfig.setTargetDirectory(finalProjectConfig.getDirectory() + "target" + File.separator); // setting git info finalProjectConfig.setScmUrl(GitHelper.inst().getScmUrl()); finalProjectConfig.setGitCommit(GitHelper.inst().getCurrentCommit()); finalProjectConfig.setImageVersion(finalProjectConfig.getGitCommit()); finalProjectConfig.setAppVersion(finalProjectConfig.getGitCommit()); // setting custom config by app kind finalProjectConfig.getAppKindPlugin().customConfig(finalProjectConfig); // setting reuse version fillReuseVersionInfo(finalProjectConfig, dewConfig, dockerHostAppendOpt, dockerRegistryUrlAppendOpt, dockerRegistryUserNameAppendOpt, dockerRegistryPasswordAppendOpt, kubeBase64ConfigAppendOpt); return finalProjectConfig; }
From source file:net.erdfelt.maven.graphing.MultimoduleGraphMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Found " + projects.size() + " Project(s)"); Graph graph = new Graph(); getLog().debug("Using: " + graphRenderer); try {// w w w . j a va 2 s . co m Iterator it = projects.iterator(); while (it.hasNext()) { MavenProject project = (MavenProject) it.next(); List deps = project.getDependencies(); if (!StringUtils.equals("pom", project.getPackaging())) { Node currentNode = graph.addNode(toNode(project)); getLog().info(" Project: " + project.getId() + " - " + deps.size() + " dep(s)"); addDependenciesToGraph(graph, currentNode, deps); } } if (graph.getDecorator() == null) { graph.setDecorator(new GraphDecorator()); } graph.getDecorator().setTitle("Module Relationship"); graph.getDecorator().setOrientation(GraphDecorator.LEFT_TO_RIGHT); graphRenderer.render(graph, new File("target/graph-multimodule.png")); } catch (GraphConstraintException e) { getLog().error("Unable to generate graph."); } catch (IOException e) { getLog().error("Unable to generate graph.", e); } catch (GraphingException e) { getLog().error("Unable to generate graph.", e); } }
From source file:net.java.jpatch.maven.common.AbstractMavenMojo.java
License:Apache License
/** * Build MAVEN project.//from www.j a v a2 s .co m * * @param project the MAVEN project. * @param buildGoals the goals; * @param buildProfiles the profiles; * * @return the build summary. */ private BuildSummary buildMavenProject(MavenProject project, List<String> buildGoals, List<String> buildProfiles) { BuildSummary result; InvocationRequest request = new InvocationBuildRequest(); request.setPomFile(project.getFile()); request.setGoals(buildGoals); request.setRecursive(false); request.setProfiles(buildProfiles); request.setProperties(properties); Date startTime = new Date(); try { getLog().info(""); getLog().info("Build project [" + project.getId() + "]"); getLog().info("Command " + new MavenCommandLineBuilder().build(request)); getLog().info(""); InvocationResult invokerResult = invoker.execute(request); if (invokerResult.getExecutionException() != null) { throw invokerResult.getExecutionException(); } if (invokerResult.getExitCode() != 0) { throw new MojoFailureException("Exit code was " + invokerResult.getExitCode()); } result = new BuildSuccess(project, new Date().getTime() - startTime.getTime()); } catch (Exception e) { Date finished = new Date(); result = new BuildFailure(project, finished.getTime() - startTime.getTime(), e); } return result; }
From source file:net.java.jpatch.maven.common.AbstractPatchMojo.java
License:Apache License
/** * Create the build item.// ww w.j a va 2s.c om * * @return the build event. * * @throws MojoExecutionException if the method fails. */ protected List<MavenProject> loadMavenProjectsForPatch(Properties releaseProperties, Artifact patchArtifact) throws MojoExecutionException { // Load projects List<MavenProject> mavenProjects = loadMavenProjects(); // Filter the projects List<MavenProject> filterProjects = filterMavenProjects(mavenProjects, getPackages()); // Create patch target directory File diffDirectory = createTargetDirectory(patchArtifact.getVersion()); // Check the SCM status List<MavenProject> scmProjects = new ArrayList<MavenProject>(); for (MavenProject project : filterProjects) { String revision = releaseProperties.getProperty(project.getId(), null); if (revision != null) { if (checkSCM(project, revision, diffDirectory)) { scmProjects.add(project); } } else { getLog().warn("Missing revision for the project " + project.getId()); } } return scmProjects; }