List of usage examples for org.apache.maven.project MavenProject getPackaging
public String getPackaging()
From source file:io.github.wanghuayao.maven.plugin.oaktree.CreateTreeMojo.java
License:Apache License
public void execute() throws MojoExecutionException { log = getLog();// w ww .j ava 2s.c om try { OakProperties properties = new OakProperties(); dependencyArtifacts = "io.github.wanghuayao:maven-plugin-oaktree:" + properties.getVersion() + ":dependency-artifacts"; filter = new ProcessingFilter(likePatten, hitePatten, deep); MavenProject mp = (MavenProject) this.getPluginContext().get("project"); String mavenHomeStr = removeUnusedCharInPath(mavenHome.getPath()); File mvnExecFile = new File(mavenHomeStr + "/bin/mvn"); mvnExec = mvnExecFile.getPath(); String os = System.getProperty("os.name"); if (os.toLowerCase().startsWith("win")) { mvnExec = mvnExec + ".cmd"; isWindwos = true; } File okaBaseDir = new File(outputDirectory, "oaktree"); File okadependencyDir = new File(okaBaseDir, "dependency"); if (!okadependencyDir.exists()) { okadependencyDir.mkdirs(); } okadependencyOutputDir = okadependencyDir.getPath(); ArtifactItem rootItem = new ArtifactItem(mp.getGroupId(), mp.getArtifactId(), mp.getPackaging(), mp.getVersion()); File rootPom = mp.getFile(); int startDeep = 2; for (Object obj : mp.getDependencyArtifacts()) { DefaultArtifact artifact = (DefaultArtifact) obj; ArtifactItem chieldern = ArtifactItem.valueOf(artifact); if (filter.isGoOnProcessing(chieldern, startDeep)) { calcDependancy(chieldern, startDeep); rootItem.addChildren(chieldern); } } FileWriter w = null; try { File okaFile = new File(okaBaseDir, "okatree.txt"); if (okaFile.exists()) { okaFile.delete(); } w = new FileWriter(okaFile); log.info("writing file : " + okaFile.getPath()); printArtifactItem(w, rootItem, ""); log.info("writing complete."); } finally { StreamUtils.quiteClose(w); } } catch (Exception ex) { getLog().error(ex.getMessage(), ex); throw new MojoExecutionException(ex.getMessage(), ex); } }
From source file:io.takari.maven.plugins.Deploy.java
License:Open Source License
private void installProject(MavenProject project) throws MojoExecutionException { DeployRequest deployRequest = new DeployRequest(); if ("pom".equals(project.getPackaging())) { ///*from www. j a v a2 s.c o m*/ // POM-project primary artifact // Artifact artifact = AetherUtils.toArtifact(project.getArtifact()); artifact = artifact.setFile(project.getFile()); deployRequest.addArtifact(artifact); } else { // // Primary artifact // Artifact artifact = AetherUtils.toArtifact(project.getArtifact()); deployRequest.addArtifact(artifact); // // POM // Artifact pomArtifact = new SubArtifact(artifact, "", "pom"); pomArtifact = pomArtifact.setFile(project.getFile()); deployRequest.addArtifact(pomArtifact); } // // Attached artifacts // for (org.apache.maven.artifact.Artifact attachedArtifact : project.getAttachedArtifacts()) { deployRequest.addArtifact(AetherUtils.toArtifact(attachedArtifact)); } deployRequest.setRepository(remoteRepository(project)); try { repositorySystem.deploy(repositorySystemSession, deployRequest); } catch (DeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:io.takari.maven.plugins.Install.java
License:Open Source License
private void installProject(MavenProject project) throws MojoExecutionException { InstallRequest installRequest = new InstallRequest(); if ("pom".equals(project.getPackaging())) { //// w w w . j av a 2 s . c om // POM-project primary artifact // Artifact artifact = AetherUtils.toArtifact(project.getArtifact()); artifact = artifact.setFile(project.getFile()); installRequest.addArtifact(artifact); } else { // // Primary artifact // Artifact artifact = AetherUtils.toArtifact(project.getArtifact()); installRequest.addArtifact(artifact); // // POM // Artifact pomArtifact = new SubArtifact(artifact, "", "pom"); pomArtifact = pomArtifact.setFile(project.getFile()); installRequest.addArtifact(pomArtifact); } // // Attached artifacts // for (org.apache.maven.artifact.Artifact attachedArtifact : project.getAttachedArtifacts()) { installRequest.addArtifact(AetherUtils.toArtifact(attachedArtifact)); } try { repositorySystem.install(repositorySystemSession, installRequest); } catch (InstallationException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:ms.dew.devops.maven.function.AppKindPluginSelector.java
License:Apache License
/** * Select app kind plugin./*from ww w . j a v a 2 s . c o m*/ * * @param mavenProject the maven project * @return the optional */ public static Optional<AppKindPlugin> select(MavenProject mavenProject) { if (mavenProject.getPackaging().equalsIgnoreCase("maven-plugin")) { return Optional.empty(); } if (new File(mavenProject.getBasedir().getPath() + File.separator + "package.json").exists()) { return Optional.of(new FrontendNodeAppKindPlugin()); } if (mavenProject.getPackaging().equalsIgnoreCase("jar") && new File(mavenProject.getBasedir().getPath() + File.separator + "src" + File.separator + "main" + File.separator + "resources").exists() && Arrays .stream(new File(mavenProject.getBasedir().getPath() + File.separator + "src" + File.separator + "main" + File.separator + "resources").listFiles()) .anyMatch((res -> res.getName().toLowerCase().contains("application") || res.getName().toLowerCase().contains("bootstrap"))) && mavenProject.getArtifacts().stream() .map(artifact -> artifact.getGroupId() + ":" + artifact.getArtifactId()) .anyMatch("org.springframework.boot:spring-boot-starter-web"::equalsIgnoreCase)) { return Optional.of(new JvmServiceSpringBootAppKindPlugin()); } if (mavenProject.getPackaging().equalsIgnoreCase("jar")) { return Optional.of(new JvmLibAppKindPlugin()); } if (mavenProject.getPackaging().equalsIgnoreCase("pom")) { return Optional.of(new PomAppKindPlugin()); } return Optional.empty(); }
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 {//from w w w . j a v a 2 s .c om 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.erdfelt.maven.graphing.MultimoduleGraphMojo.java
License:Apache License
private boolean isMultiModuleDependency(Dependency dep) { boolean ret = false; Iterator it = projects.iterator(); while (it.hasNext()) { MavenProject project = (MavenProject) it.next(); if (StringUtils.equals(project.getGroupId(), dep.getGroupId()) && StringUtils.equals(project.getArtifactId(), dep.getArtifactId()) && StringUtils.equals(project.getPackaging(), dep.getType())) { // Found dep that matches on groupId / artifactId / type only. if (ignoreVersions) { // No test of version. ret = true;/*from w w w . j a va 2s. c o m*/ break; } else if (StringUtils.equals(project.getVersion(), dep.getVersion())) { // Found dep that matches on version too. ret = true; break; } } } return ret; }
From source file:net.erdfelt.maven.graphing.MultimoduleGraphMojo.java
License:Apache License
private Node toNode(MavenProject project) { return toNode(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging()); }
From source file:net.java.jpatch.maven.common.AbstractMavenMojo.java
License:Apache License
protected static List<MavenProject> filterMavenProjects(List<MavenProject> projects, Set<String> packages) throws MojoExecutionException { List<MavenProject> result = new ArrayList<MavenProject>(); for (MavenProject project : projects) { if (packages.contains(project.getPackaging())) { result.add(project);//from w w w .jav a 2s .c o m } } return result; }
From source file:net.leadware.wildfly.plugin.deployment.PackageType.java
License:Open Source License
/** * Resolves the package type from the maven project. * * @param project the maven project/* ww w. j a v a 2s . c om*/ * * @return the package type */ public static PackageType resolve(final MavenProject project) { final String packaging = project.getPackaging(); if (DEFAULT_TYPES.containsKey(packaging)) { return DEFAULT_TYPES.get(packaging); } return new PackageType(packaging); }
From source file:net.oneandone.maven.plugins.billofmaterials.CreateBillOfMaterialsMojo.java
License:Apache License
/** * Creates a list of all artifacts for the build. * @return a list of all artifacts for the build including the attached ones. *///from w w w.j a v a 2s . co m final List<File> getListOfArtifactsAsFiles() { final MavenProject project = getProject(); final List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); // We need a copy here as otherwise install and deploy will choke later on because // we attach the POM as well. final List<File> files = new ArrayList<>( Collections2.filter(Lists.transform(attachedArtifacts, toFileFunction), Files.isFile())); final String packaging = project.getPackaging(); // POMs return null as their artifact, which will crash the transformation lateron. if (!"pom".equals(packaging)) { files.add(project.getArtifact().getFile()); } return files; }