List of usage examples for org.apache.maven.project MavenProject getDependencies
public List<Dependency> getDependencies()
From source file:ch.sourcepond.maven.release.reactor.DefaultReactor.java
License:Apache License
public String getChangedDependencyOrNull(final MavenProject project) { String changedDependency = null; for (final ReleasableModule module : this) { if (module.getVersion().hasChanged()) { for (final Dependency dependency : project.getDependencies()) { if (dependency.getGroupId().equals(module.getGroupId()) && dependency.getArtifactId().equals(module.getArtifactId())) { changedDependency = dependency.getArtifactId(); break; }/*from w w w. ja v a 2s . co m*/ } if (project.getParent() != null && (project.getParent().getGroupId().equals(module.getGroupId()) && project.getParent().getArtifactId().equals(module.getArtifactId()))) { changedDependency = project.getParent().getArtifactId(); break; } } if (changedDependency != null) { break; } } return changedDependency; }
From source file:ch.sourcepond.maven.release.substitution.DefaultVersionSubstitution.java
License:Apache License
@Override public String getActualVersionOrNull(final MavenProject project, final Dependency originalDependency) { return getActualVersionOrNull(project.getDependencies(), originalDependency, dependencyAdapter); }
From source file:ch.sventschui.maven.visualizer.VisualizerMojo.java
License:Apache License
public void execute() throws MojoExecutionException { this.createOutputDir(); for (String directory : this.directories) { this.poms.addAll(FileUtils.listFiles(new File(directory), new PomFileFilter(), new TargetFileFilter())); }/* w w w . j a v a 2 s. co m*/ for (File pom : this.poms) { Model model = null; FileReader reader = null; MavenXpp3Reader mavenreader = new MavenXpp3Reader(); try { reader = new FileReader(pom); model = mavenreader.read(reader); model.setPomFile(pom); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } MavenProject project = new MavenProject(model); MavenArtifact base = new MavenArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion()); if (this.filter.matches(base)) { this.store.addArtifact(base); for (Dependency artifact : project.getDependencies()) { MavenArtifact dependency = new MavenArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); if (this.filter.matches(dependency)) { this.store.addArtifact(dependency); this.store.addRelationship(base, dependency); } } } } try { FileWriter fstream = new FileWriter(new File(this.outputDir, "test.json")); BufferedWriter out = new BufferedWriter(fstream); out.write(this.store.toJSON()); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:cn.wanghaomiao.maven.plugin.seimi.AbstractWarMojo.java
License:Apache License
/** * Builds the webapp for the specified project with the new packaging task thingy * <p/>/*from w w w. j a v a 2 s .c o m*/ * Classes, libraries and tld files are copied to the <tt>webappDirectory</tt> during this phase. * * @param mavenProject the maven project * @param webapplicationDirectory the target directory * @throws MojoExecutionException if an error occurred while packaging the webapp * @throws MojoFailureException if an unexpected error occurred while packaging the webapp * @throws IOException if an error occurred while copying the files */ @SuppressWarnings("unchecked") public void buildWebapp(MavenProject mavenProject, File webapplicationDirectory) throws MojoExecutionException, MojoFailureException, IOException { WebappStructure cache; if (useCache && cacheFile.exists()) { // CHECKSTYLE_OFF: LineLength cache = new WebappStructure(mavenProject.getDependencies(), webappStructureSerialier.fromXml(cacheFile)); // CHECKSTYLE_ON: LineLength } else { cache = new WebappStructure(mavenProject.getDependencies(), null); } // CHECKSTYLE_OFF: LineLength final long startTime = System.currentTimeMillis(); getLog().info( "Assembling webapp [" + mavenProject.getArtifactId() + "] in [" + webapplicationDirectory + "]"); final OverlayManager overlayManager = new OverlayManager(overlays, mavenProject, dependentWarIncludes, dependentWarExcludes, currentProjectOverlay); final List<WarPackagingTask> packagingTasks = getPackagingTasks(overlayManager); // CHECKSTYLE_ON: LineLength List<FileUtils.FilterWrapper> defaultFilterWrappers; try { MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(); mavenResourcesExecution.setEscapeString(escapeString); mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering); mavenResourcesExecution.setMavenProject(mavenProject); if (filters == null) { filters = getProject().getBuild().getFilters(); } mavenResourcesExecution.setFilters(filters); mavenResourcesExecution.setEscapedBackslashesInFilePath(escapedBackslashesInFilePath); mavenResourcesExecution.setMavenSession(this.session); mavenResourcesExecution.setEscapeString(this.escapeString); mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering); defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers(mavenResourcesExecution); } catch (MavenFilteringException e) { getLog().error("fail to build filering wrappers " + e.getMessage()); throw new MojoExecutionException(e.getMessage(), e); } final WarPackagingContext context = new DefaultWarPackagingContext(webapplicationDirectory, cache, overlayManager, defaultFilterWrappers, getNonFilteredFileExtensions(), filteringDeploymentDescriptors, this.artifactFactory, resourceEncoding, useJvmChmod); for (WarPackagingTask warPackagingTask : packagingTasks) { warPackagingTask.performPackaging(context); } // Post packaging final List<WarPostPackagingTask> postPackagingTasks = getPostPackagingTasks(); for (WarPostPackagingTask task : postPackagingTasks) { task.performPostPackaging(context); } getLog().info("Webapp assembled in [" + (System.currentTimeMillis() - startTime) + " msecs]"); }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.JeeUtils.java
License:Apache License
private static String findEjbVersionInDependencies(MavenProject project) { String version = IdeUtils.getArtifactVersion(new String[] { "ejb", "ejb-api", "geronimo-spec-ejb" }, project.getDependencies(), 3); // For new Geronimo APIs, the version of the artifact isn't the one of the spec if (version == null) { if (IdeUtils.getArtifactVersion(new String[] { "geronimo-ejb_2.1_spec" }, project.getDependencies(), 3) != null) {/*from w w w . j a va2 s.c o m*/ return JeeDescriptor.EJB_2_1; } } if (version == null) { if (IdeUtils.getArtifactVersion(new String[] { "geronimo-ejb_3.0_spec" }, project.getDependencies(), 3) != null) { return JeeDescriptor.EJB_3_0; } } // if no version found try dependencies of referenced projects if (version == null) { Iterator it = project.getProjectReferences().keySet().iterator(); while (it.hasNext()) { Object key = it.next(); MavenProject refProject = (MavenProject) project.getProjectReferences().get(key); version = findEjbVersionInDependencies(refProject); if (version != null) // version found in dependencies { break; } } } return version; }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.JeeUtils.java
License:Apache License
private static String findJeeVersionInDependencies(MavenProject project) { String version = IdeUtils.getArtifactVersion(new String[] { "javaee-api", "j2ee", "geronimo-spec-j2ee" }, project.getDependencies(), 3); // For new Geronimo APIs, the version of the artifact isn't the one of the spec if (version == null) { if (IdeUtils.getArtifactVersion(new String[] { "geronimo-j2ee_1.4_spec" }, project.getDependencies(), 3) != null) {// w w w .j ava2 s . com return JeeDescriptor.JEE_1_4; } } // if no version found try dependencies of referenced projects if (version == null) { Iterator it = project.getProjectReferences().keySet().iterator(); while (it.hasNext()) { Object key = it.next(); MavenProject refProject = (MavenProject) project.getProjectReferences().get(key); version = findJeeVersionInDependencies(refProject); if (version != null) // version found in dependencies { break; } } } return version; }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.JeeUtils.java
License:Apache License
private static String findServletVersionInDependencies(MavenProject project) { String version = IdeUtils.getArtifactVersion( new String[] { "servlet-api", "servletapi", "geronimo-spec-servlet" }, project.getDependencies(), 3);/* ww w . jav a 2 s. c om*/ // For new Geronimo APIs, the version of the artifact isn't the one of the spec if (version == null) { if (IdeUtils.getArtifactVersion(new String[] { "geronimo-servlet_2.4_spec" }, project.getDependencies(), 3) != null) { return JeeDescriptor.SERVLET_2_4; } } if (version == null) { if (IdeUtils.getArtifactVersion(new String[] { "geronimo-servlet_2.5_spec" }, project.getDependencies(), 3) != null) { return JeeDescriptor.SERVLET_2_5; } } // if no version found try dependencies of referenced projects if (version == null) { Iterator it = project.getProjectReferences().keySet().iterator(); while (it.hasNext()) { Object key = it.next(); MavenProject refProject = (MavenProject) project.getProjectReferences().get(key); version = findServletVersionInDependencies(refProject); if (version != null) // version found in dependencies { break; } } } return version; }
From source file:com.asual.summer.onejar.OneJarMojo.java
License:Apache License
public void execute() throws MojoExecutionException { JarOutputStream out = null;/*from w w w. j ava2 s .co m*/ JarInputStream in = null; try { File jarFile = new File(buildDirectory, jarName); File warFile = new File(buildDirectory, warName); Manifest manifest = new Manifest(new ByteArrayInputStream("Manifest-Version: 1.0\n".getBytes("UTF-8"))); manifest.getMainAttributes().putValue("Main-Class", JAR_MAIN_CLASS); manifest.getMainAttributes().putValue("One-Jar-Main-Class", ONE_JAR_MAIN_CLASS); out = new JarOutputStream(new FileOutputStream(jarFile, false), manifest); in = new JarInputStream(getClass().getClassLoader().getResourceAsStream(ONE_JAR_DIST)); putEntry(out, new FileInputStream(warFile), new ZipEntry(JAR_CLASSPATH + warFile.getName())); for (Artifact artifact : pluginArtifacts) { if (artifact.getArtifactId().equalsIgnoreCase("summer-onejar")) { artifact.updateVersion(artifact.getVersion(), localRepository); putEntry(out, new FileInputStream(artifact.getFile()), new ZipEntry(JAR_CLASSPATH + artifact.getFile().getName())); MavenProject project = mavenProjectBuilder.buildFromRepository(artifact, remoteArtifactRepositories, localRepository); List<Dependency> dependencies = project.getDependencies(); for (Dependency dependency : dependencies) { if (!"provided".equals(dependency.getScope())) { Artifact dependencyArtifact = artifactFactory.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType()); dependencyArtifact.updateVersion(dependencyArtifact.getVersion(), localRepository); putEntry(out, new FileInputStream(dependencyArtifact.getFile()), new ZipEntry(JAR_CLASSPATH + dependencyArtifact.getFile().getName())); } } } } while (true) { ZipEntry entry = in.getNextEntry(); if (entry != null) { putEntry(out, in, entry); } else { break; } } projectHelper.attachArtifact(project, "jar", jarFile); } catch (Exception e) { getLog().error(e.getMessage(), e); throw new MojoExecutionException(e.getMessage(), e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } }
From source file:com.baidu.jprotobuf.mojo.PreCompileMojo.java
License:Apache License
/** * Resolve the executable dependencies for the specified project * /* ww w. j a v a2 s .c o m*/ * @param executablePomArtifact the project's POM * @return a set of Artifacts * @throws MojoExecutionException if a failure happens */ private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact) throws MojoExecutionException { Set<Artifact> executableDependencies; try { MavenProject executableProject = this.projectBuilder.buildFromRepository(executablePomArtifact, this.remoteRepositories, this.localRepository); // get all of the dependencies for the executable project List<Dependency> dependencies = executableProject.getDependencies(); // make Artifacts of all the dependencies Set<Artifact> dependencyArtifacts = MavenMetadataSource.createArtifacts(this.artifactFactory, dependencies, null, null, null); // not forgetting the Artifact of the project itself dependencyArtifacts.add(executableProject.getArtifact()); // resolve all dependencies transitively to obtain a comprehensive list of assemblies ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, null, Collections.emptyList()); executableDependencies = result.getArtifacts(); } catch (Exception ex) { throw new MojoExecutionException("Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex); } return executableDependencies; }
From source file:com.github.alexfalappa.nbspringboot.projects.customizer.BootPanelProvider.java
License:Apache License
private boolean prjHasDepContaining(Lookup context, String txt) { Project prj = context.lookup(Project.class); if (prj != null) { NbMavenProject nbMvn = prj.getLookup().lookup(NbMavenProject.class); if (nbMvn != null) { MavenProject mvnPrj = nbMvn.getMavenProject(); for (Object o : mvnPrj.getDependencies()) { Dependency d = (Dependency) o; if (d.getArtifactId().contains(txt)) { return true; }//from w ww .j a v a 2s . c o m } } } return false; }