List of usage examples for org.apache.maven.project MavenProject getParent
public MavenProject getParent()
From source file:org.revapi.maven.AbstractVersionModifyingMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (skip) {//from www . j a v a2s.c o m return; } AnalysisResults analysisResults; if (!initializeComparisonArtifacts()) { //we've got non-file artifacts, for which there is no reason to run analysis DefaultArtifact oldArtifact = new DefaultArtifact(oldArtifacts[0]); analysisResults = new AnalysisResults(ApiChangeLevel.NO_CHANGE, oldArtifact.getVersion()); } else { analysisResults = analyzeProject(project); } if (analysisResults == null) { return; } ApiChangeLevel changeLevel = analysisResults.apiChangeLevel; if (singleVersionForAllModules) { File changesFile = getChangesFile(); try (PrintWriter out = new PrintWriter(new FileOutputStream(changesFile, true))) { out.println( project.getArtifact().toString() + "=" + changeLevel + "," + analysisResults.baseVersion); } catch (IOException e) { throw new MojoExecutionException("Failure while updating the changes tracking file.", e); } } else { Version v = nextVersion(analysisResults.baseVersion, changeLevel); updateProjectVersion(project, v); } if (singleVersionForAllModules && project.equals(mavenSession.getProjects().get(mavenSession.getProjects().size() - 1))) { try (BufferedReader rdr = new BufferedReader(new FileReader(getChangesFile()))) { Map<String, AnalysisResults> projectChanges = new HashMap<>(); String line; while ((line = rdr.readLine()) != null) { int equalsIdx = line.indexOf('='); String projectGav = line.substring(0, equalsIdx); String changeAndBaseVersion = line.substring(equalsIdx + 1); int commaIdx = changeAndBaseVersion.indexOf(','); String change = changeAndBaseVersion.substring(0, commaIdx); String baseVersion = changeAndBaseVersion.substring(commaIdx + 1); changeLevel = ApiChangeLevel.valueOf(change); projectChanges.put(projectGav, new AnalysisResults(changeLevel, baseVersion)); } //establish the tree hierarchy of the projects Set<MavenProject> roots = new HashSet<>(); Map<MavenProject, Set<MavenProject>> children = new HashMap<>(); Deque<MavenProject> unprocessed = new ArrayDeque<>(mavenSession.getProjects()); while (!unprocessed.isEmpty()) { MavenProject pr = unprocessed.pop(); if (!projectChanges.containsKey(pr.getArtifact().toString())) { continue; } MavenProject pa = pr.getParent(); if (roots.contains(pa)) { roots.remove(pr); AnalysisResults paR = projectChanges.get(pa.getArtifact().toString()); AnalysisResults prR = projectChanges.get(pr.getArtifact().toString()); if (prR.apiChangeLevel.ordinal() > paR.apiChangeLevel.ordinal()) { paR.apiChangeLevel = prR.apiChangeLevel; } children.get(pa).add(pr); } else { roots.add(pr); } children.put(pr, new HashSet<MavenProject>()); } Iterator<MavenProject> it = roots.iterator(); while (it.hasNext()) { Deque<MavenProject> tree = new ArrayDeque<>(); MavenProject p = it.next(); tree.add(p); it.remove(); AnalysisResults results = projectChanges.get(p.getArtifact().toString()); Version v = nextVersion(results.baseVersion, results.apiChangeLevel); while (!tree.isEmpty()) { MavenProject current = tree.pop(); updateProjectVersion(current, v); Set<MavenProject> c = children.get(current); if (c != null) { for (MavenProject cp : c) { updateProjectParentVersion(cp, v); } tree.addAll(c); } } } } catch (IOException e) { throw new MojoExecutionException("Failure while reading the changes tracking file.", e); } } }
From source file:org.robovm.maven.plugin.AbstractRoboVMMojo.java
License:Apache License
public Config buildArchive(OS os, Arch arch, TargetType targetType) throws MojoExecutionException, MojoFailureException { getLog().info("Building RoboVM app for: " + os + " (" + arch + ")"); Config.Builder builder;/* w w w . jav a 2s. com*/ try { builder = new Config.Builder(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } // load config base file if it exists (and properties) if (propertiesFile != null) { if (!propertiesFile.exists()) { throw new MojoExecutionException( "Invalid 'propertiesFile' specified for RoboVM compile: " + propertiesFile); } try { getLog().debug( "Including properties file in RoboVM compiler config: " + propertiesFile.getAbsolutePath()); builder.addProperties(propertiesFile); } catch (IOException e) { throw new MojoExecutionException( "Failed to add properties file to RoboVM config: " + propertiesFile); } } else { File file = new File(project.getBasedir(), "robovm.properties"); if (file.exists()) { getLog().debug("Using default properties file: " + file.getAbsolutePath()); try { builder.addProperties(file); } catch (IOException e) { throw new MojoExecutionException("Failed to add properties file to RoboVM config: " + file, e); } } } if (configFile != null) { if (!configFile.exists()) { throw new MojoExecutionException( "Invalid 'configFile' specified for RoboVM compile: " + configFile); } try { getLog().debug("Loading config file for RoboVM compiler: " + configFile.getAbsolutePath()); builder.read(configFile); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config file: " + configFile); } } else { File file = new File(project.getBasedir(), "robovm.xml"); if (file.exists()) { getLog().debug("Using default config file: " + file.getAbsolutePath()); try { builder.read(file); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config file: " + file, e); } } } // Read embedded RoboVM <config> if there is one Plugin plugin = project.getPlugin("org.robovm:robovm-maven-plugin"); MavenProject p = project; while (p != null && plugin == null) { plugin = p.getPluginManagement().getPluginsAsMap().get("org.robovm:robovm-maven-plugin"); p = p.getParent(); } if (plugin != null) { getLog().debug("Reading RoboVM plugin configuration from " + p.getFile().getAbsolutePath()); Xpp3Dom configDom = (Xpp3Dom) plugin.getConfiguration(); if (configDom != null && configDom.getChild("config") != null) { StringWriter sw = new StringWriter(); XMLWriter xmlWriter = new PrettyPrintXMLWriter(sw, "UTF-8", null); Xpp3DomWriter.write(xmlWriter, configDom.getChild("config")); try { builder.read(new StringReader(sw.toString()), project.getBasedir()); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config embedded in POM", e); } } } File tmpDir = new File(new File(installDir, os.name()), arch.name()); try { FileUtils.deleteDirectory(tmpDir); } catch (IOException e) { throw new MojoExecutionException("Failed to clean output dir " + tmpDir, e); } tmpDir.mkdirs(); builder.home(new Config.Home(unpackRoboVMDist())).logger(getRoboVMLogger()).tmpDir(tmpDir) .targetType(targetType).skipInstall(true).installDir(installDir).os(os).arch(arch); if (iosSkipSigning) { builder.iosSkipSigning(true); } else { if (iosSignIdentity != null) { getLog().debug("Using explicit iOS Signing identity: " + iosSignIdentity); builder.iosSignIdentity(SigningIdentity.find(SigningIdentity.list(), iosSignIdentity)); } if (iosProvisioningProfile != null) { getLog().debug("Using explicit iOS provisioning profile: " + iosProvisioningProfile); builder.iosProvisioningProfile( ProvisioningProfile.find(ProvisioningProfile.list(), iosProvisioningProfile)); } } builder.clearClasspathEntries(); // add JavaFX if needed if (includeJFX) { getLog().info("Including JavaFX Runtime in build"); // add jfxrt.jar from 78 backport to classpath File jfxJar = resolveJavaFXBackportRuntimeArtifact(); getLog().debug("JavaFX backport runtime JAR found at: " + jfxJar); builder.addClasspathEntry(jfxJar); // add backport compatibility additions to classpath File jfxCompatJar = resolveJavaFXBackportCompatibilityArtifact(); getLog().debug("JavaFX backport compatibilty JAR found at: " + jfxCompatJar); builder.addClasspathEntry(jfxCompatJar); // include native files as resources File iosNativesBaseDir = unpackJavaFXNativeIOSArtifact(); // builder.addLib(new File(iosNativesBaseDir, "libdecora-sse-" + // arch.getClangName() + ".a").getAbsolutePath()); builder.addLib(new Lib( new File(iosNativesBaseDir, "libglass-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libjavafx-font-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libjavafx-iio-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libprism-common-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libprism-es2-" + arch.getClangName() + ".a").getAbsolutePath(), true)); // builder.addLib(new File(iosNativesBaseDir, "libprism-sw-" + // arch.getClangName() + ".a").getAbsolutePath()); // add default 'roots' needed for JFX to work builder.addForceLinkClass("com.sun.javafx.tk.quantum.QuantumToolkit"); builder.addForceLinkClass("com.sun.prism.es2.ES2Pipeline"); builder.addForceLinkClass("com.sun.prism.es2.IOSGLFactory"); builder.addForceLinkClass("com.sun.glass.ui.ios.**.*"); builder.addForceLinkClass("javafx.scene.CssStyleHelper"); builder.addForceLinkClass("com.sun.prism.shader.**.*"); builder.addForceLinkClass("com.sun.scenario.effect.impl.es2.ES2ShaderSource"); builder.addForceLinkClass("com.sun.javafx.font.coretext.CTFactory"); builder.addForceLinkClass("sun.util.logging.PlatformLogger"); // add default 'frameworks' needed for JFX to work builder.addFramework("UIKit"); builder.addFramework("OpenGLES"); builder.addFramework("QuartzCore"); builder.addFramework("CoreGraphics"); builder.addFramework("CoreText"); builder.addFramework("ImageIO"); builder.addFramework("MobileCoreServices"); // todo do we need to exclude built-in JFX from JDK classpath? } // configure the runtime classpath try { for (Object object : project.getRuntimeClasspathElements()) { String path = (String) object; if (getLog().isDebugEnabled()) { getLog().debug("Including classpath element for RoboVM app: " + path); } builder.addClasspathEntry(new File(path)); } } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error resolving application classpath for RoboVM build", e); } // execute the RoboVM build try { getLog().info("Compiling RoboVM app, this could take a while, especially the first time round"); Config config = configure(builder); AppCompiler compiler = new AppCompiler(config); compiler.compile(); return config; } catch (IOException e) { throw new MojoExecutionException("Error building RoboVM executable for app", e); } }
From source file:org.smallmind.license.SourceNoticeMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { MavenProject rootProject = project; Stencil[] mergedStencils;/*from w ww . j a v a 2 s . co m*/ char[] buffer = new char[8192]; while ((root == null) ? !(rootProject.getParent() == null) : !(root.getGroupId().equals(rootProject.getGroupId()) && root.getArtifactId().equals(rootProject.getArtifactId()))) { rootProject = rootProject.getParent(); } mergedStencils = new Stencil[(stencils != null) ? stencils.length + DEFAULT_STENCILS.length : DEFAULT_STENCILS.length]; System.arraycopy(DEFAULT_STENCILS, 0, mergedStencils, 0, DEFAULT_STENCILS.length); if (stencils != null) { System.arraycopy(stencils, 0, mergedStencils, DEFAULT_STENCILS.length, stencils.length); } for (Rule rule : rules) { FileFilter[] fileFilters; String[] noticeArray; boolean noticed; boolean stenciled; if (verbose) { getLog().info(String.format("Processing rule(%s)...", rule.getId())); } noticed = true; if (rule.getNotice() == null) { if (!allowNoticeRemoval) { throw new MojoExecutionException("No notice was provided for rule(" + rule.getId() + "), but notice removal has not been enabled(allowNoticeRemoval = false)"); } noticeArray = null; } else { File noticeFile; noticeFile = new File(rule.getNotice()); if ((noticeArray = getFileAsLineArray(noticeFile.isAbsolute() ? noticeFile.getAbsolutePath() : rootProject.getBasedir() + System.getProperty("file.separator") + noticeFile.getPath())) == null) { noticed = false; } } if (!noticed) { getLog().warn(String.format("Unable to acquire the notice file(%s), skipping notice updating...", rule.getNotice())); } else { if ((rule.getFileTypes() == null) || (rule.getFileTypes().length == 0)) { throw new MojoExecutionException("No file types were specified for rule(" + rule.getId() + ")"); } fileFilters = new FileFilter[rule.getFileTypes().length]; for (int count = 0; count < fileFilters.length; count++) { fileFilters[count] = new FileTypeFilenameFilter(rule.getFileTypes()[count]); } stenciled = false; for (Stencil stencil : mergedStencils) { if (stencil.getId().equals(rule.getStencilId())) { stenciled = true; updateNotice(stencil, noticeArray, buffer, project.getBuild().getSourceDirectory(), fileFilters); updateNotice(stencil, noticeArray, buffer, project.getBuild().getScriptSourceDirectory(), fileFilters); if (includeResources) { for (Resource resource : project.getBuild().getResources()) { updateNotice(stencil, noticeArray, buffer, resource.getDirectory(), fileFilters); } } if (includeTests) { updateNotice(stencil, noticeArray, buffer, project.getBuild().getTestSourceDirectory(), fileFilters); if (includeResources) { for (Resource testResource : project.getBuild().getTestResources()) { updateNotice(stencil, noticeArray, buffer, testResource.getDirectory(), fileFilters); } } } break; } } if (!stenciled) { throw new MojoExecutionException( "No stencil found with id(" + rule.getStencilId() + ") for rule(" + rule.getId() + ")"); } } } }
From source file:org.smallmind.license.TargetLicenseMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { if ((new File(project.getBuild().getOutputDirectory())).exists()) { MavenProject rootProject = project; byte[] buffer = new byte[8192]; while ((root == null) ? !(rootProject.getParent() == null) : !(root.getGroupId().equals(rootProject.getGroupId()) && root.getArtifactId().equals(rootProject.getArtifactId()))) { rootProject = rootProject.getParent(); }/*from ww w. j a v a 2s. c o m*/ for (String license : licenses) { File licenseFile; File copyFile; FileInputStream inputStream; FileOutputStream outputStream; int bytesRead; if (!(licenseFile = new File(license)).isAbsolute()) { licenseFile = new File(rootProject.getBasedir() + System.getProperty("file.separator") + licenseFile.getPath()); } if (!licenseFile.exists()) { getLog().warn( String.format("Unable to acquire the license file(%s), skipping license copying...", licenseFile.getAbsolutePath())); } else { if (verbose) { getLog().info(String.format("Copying license(%s)...", licenseFile.getName())); } copyFile = new File(project.getBuild().getOutputDirectory() + System.getProperty("file.separator") + licenseFile.getName()); try { outputStream = new FileOutputStream(copyFile); } catch (IOException ioException) { throw new MojoExecutionException( "Unable to create output license file (" + copyFile.getAbsolutePath() + ")", ioException); } try { inputStream = new FileInputStream(licenseFile); while ((bytesRead = inputStream.read(buffer)) >= 0) { outputStream.write(buffer, 0, bytesRead); } inputStream.close(); } catch (IOException ioException) { copyFile.delete(); throw new MojoExecutionException( "Problem in copying output license file (" + copyFile.getAbsolutePath() + ")", ioException); } try { outputStream.close(); } catch (IOException ioException) { throw new MojoExecutionException( "Problem in closing license file (" + licenseFile.getAbsolutePath() + ")", ioException); } } } } }
From source file:org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator.java
License:Open Source License
/** * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=356725. * Loads the parent project hierarchy if needed. * @param facade//ww w. j a v a 2s . c o m * @param monitor * @return true if parent projects had to be loaded. * @throws CoreException */ private boolean loadParentHierarchy(IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException { boolean loadedParent = false; MavenProject mavenProject = facade.getMavenProject(); try { if (mavenProject.getModel().getParent() == null || mavenProject.getParent() != null) { //If the getParent() method is called without error, // we can assume the project has been fully loaded, no need to continue. return false; } } catch (IllegalStateException e) { //The parent can not be loaded properly } MavenExecutionRequest request = null; while (mavenProject != null && mavenProject.getModel().getParent() != null) { if (monitor.isCanceled()) { break; } if (request == null) { request = projectManager.createExecutionRequest(facade, monitor); } MavenProject parentProject = maven.resolveParentProject(request, mavenProject, monitor); if (parentProject != null) { mavenProject.setParent(parentProject); loadedParent = true; } mavenProject = parentProject; } return loadedParent; }
From source file:org.sourcepit.b2.internal.generator.ModulePomBuilder.java
License:Apache License
private List<Model> cloneModelHierarchy(MavenProject project) { List<Model> models = new ArrayList<Model>(); MavenProject currentProject = project; while (currentProject != null) { models.add(currentProject.getOriginalModel().clone()); currentProject = currentProject.getParent(); }/*from w w w . j ava2s .c om*/ return models; }
From source file:org.sourcepit.b2.release.B2ReleaseHelper.java
License:Apache License
public MavenProject determineModuleMavenProject(MavenProject mavenProject) { MavenProject parentProject = mavenProject; while (parentProject != null) { if (bridge.getModule(parentProject) != null) { return parentProject; }//from w w w .ja v a 2s. c o m parentProject = parentProject.getParent(); } throw new IllegalStateException("Unable to determine module project for maven project " + mavenProject); }
From source file:org.sourcepit.b2.release.B2ScmHelper.java
License:Apache License
private MavenProject determineModuleMavenProject(MavenProject mavenProject) { MavenProject parentProject = mavenProject; while (parentProject != null) { if (bridge.getModule(parentProject) != null) { return parentProject; }/*w ww . jav a2 s .c o m*/ parentProject = parentProject.getParent(); } throw new IllegalStateException("Unable to determine module project for maven project " + mavenProject); }
From source file:org.sourcepit.tpmp.change.ChecksumTargetPlatformConfigurationChangeDiscoverer.java
License:Apache License
private String computeProjectChecksum(File statusCacheDir, MavenSession session, MavenProject project) { final List<MavenProject> projects = new ArrayList<MavenProject>(); projects.add(project);/*from w w w.jav a2s . com*/ MavenProject parent = project.getParent(); while (parent != null) { projects.add(parent); parent = parent.getParent(); } return computeProjectsChecksum(statusCacheDir, session, projects); }
From source file:org.srcdeps.mvn.plugin.SrcdepsInitMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); org.srcdeps.core.GavSet.Builder gavSetBuilder = GavSet.builder() // .includes(includes) // .excludes(excludes);/*from w ww .j a v a 2 s . c om*/ if (excludeSnapshots) { gavSetBuilder.excludeSnapshots(); } this.gavSet = gavSetBuilder.build(); log.info("Using includes and excludes [{}]", gavSet); log.info("Supported SCMs: {}", scms); if (skip || !multiModuleRootDir.equals(session.getCurrentProject().getBasedir())) { log.info(getClass().getSimpleName() + " skipped"); } else { Configuration.Builder config = Configuration.builder() // .configModelVersion(Configuration.getLatestConfigModelVersion()).commentBefore("") // .commentBefore("srcdeps.yaml - the srcdeps configuration file") // .commentBefore("") // .commentBefore( "The full srcdeps.yaml reference can be found under https://github.com/srcdeps/srcdeps-core/tree/master/doc/srcdeps.yaml") // .commentBefore("") // .commentBefore("This file was generated by the following command:") // .commentBefore("") // .commentBefore(" mvn org.srcdeps.mvn:srcdeps-maven-plugin:init") // .commentBefore("") // ; ScmRepositoryIndex index = new ScmRepositoryIndex(session, repoSession, repositorySystem, projectBuilder, scms); log.debug("Going over [{}] reactor projects", reactorProjects.size()); /* first add the reactor projects to seenGas so that they get ignored */ for (MavenProject project : reactorProjects) { index.ignoreGav(project.getGroupId(), project.getArtifactId(), project.getVersion()); } for (MavenProject project : reactorProjects) { final List<Dependency> dependencies = project.getDependencies(); log.info("Project [{}] has [{}] dependencies", project.getArtifactId(), dependencies == null ? 0 : dependencies.size()); if (dependencies != null) { for (Dependency dependency : dependencies) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { /* Ignore system scope */ index.addGav(g, a, v, failOnUnresolvable); } } } final DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { final List<Dependency> managedDeps = dependencyManagement.getDependencies(); if (managedDeps != null) { for (Dependency dependency : managedDeps) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { /* Ignore system scope */ index.addGav(g, a, v, false); } } } } MavenProject parent = project.getParent(); if (parent != null) { final String g = parent.getGroupId(); final String a = parent.getArtifactId(); final String v = parent.getVersion(); if (gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } Map<String, Builder> repos = index.createSortedScmRepositoryMap(); if (repos.size() == 0) { /* add some dummy repo so that we do not write an empty srcdeps.yaml file */ ScmRepository.Builder dummyRepo = ScmRepository.builder() // .commentBefore( "FIXME: srcdeps-maven-plugin could not authomatically identify any SCM URLs for dependencies in this project") // .commentBefore( " and has added this dummy repository only as a starting point for you to proceed manually") // .id("org.my-group") // .selector("org.my-group") // .url("git:https://github.com/my-org/my-project.git") // ; repos.put(dummyRepo.getName(), dummyRepo); } config // .repositories(repos) // .accept(new OverrideVisitor(System.getProperties())) // .accept(new DefaultsAndInheritanceVisitor()) // ; final Path srcdepsYamlPath = multiModuleRootDir.toPath().resolve("srcdeps.yaml"); try { YamlWriterConfiguration yamlWriterConfiguration = YamlWriterConfiguration.builder().build(); try (Writer out = Files.newBufferedWriter(srcdepsYamlPath, Charset.forName(encoding))) { config.accept(new YamlWriterVisitor(out, yamlWriterConfiguration)); } } catch (IOException e) { throw new MojoExecutionException(String.format("Could not write [%s]", srcdepsYamlPath), e); } } }