List of usage examples for org.apache.maven.project MavenProject getVersion
public String getVersion()
From source file:org.fusesource.ide.server.karaf.core.server.subsystems.Karaf2xPublishController.java
License:Open Source License
private String getModuleVersion(IModule module) throws CoreException { IProgressMonitor monitor = new NullProgressMonitor(); IProject project = module.getProject(); IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry() .create(project.getFile(IMavenConstants.POM_FILE_NAME), true, monitor); MavenProject mavenProject = facade.getMavenProject(monitor); return mavenProject.getVersion(); }
From source file:org.gephi.maven.ModuleUtils.java
License:Apache License
/** * Investigate modules dependencies and return a map where keys are * top-level modules and values are all modules that it depends on plus the * key module.//from ww w . ja v a 2 s . c om * * @param modules list of modules * @param log log * @return map that represents the tree of modules */ protected static Map<MavenProject, List<MavenProject>> getModulesTree(List<MavenProject> modules, Log log) { Map<MavenProject, List<MavenProject>> result = new LinkedHashMap<MavenProject, List<MavenProject>>(); for (MavenProject proj : modules) { List<Dependency> dependencies = proj.getDependencies(); log.debug("Investigating the " + dependencies.size() + " dependencies of project '" + proj.getName() + "'"); // Init List<MavenProject> deps = new ArrayList<MavenProject>(); deps.add(proj); result.put(proj, deps); // Add all module-based dependencies for (Dependency d : dependencies) { for (MavenProject projDependency : modules) { if (projDependency != proj && projDependency.getArtifactId().equals(d.getArtifactId()) && projDependency.getGroupId().equals(d.getGroupId()) && projDependency.getVersion().equals(d.getVersion())) { log.debug("Found a dependency that matches another module '" + proj.getName() + "' -> '" + projDependency.getName() + "'"); deps.add(projDependency); } } } } // Remove modules that are entirely dependencies of others List<MavenProject> toBeRemoved = new ArrayList<MavenProject>(); for (MavenProject proj : modules) { List<MavenProject> projDeps = result.get(proj); for (MavenProject proj2 : modules) { if (proj != proj2) { if (result.get(proj2).containsAll(projDeps)) { log.debug("Remove '" + proj.getName() + "' from list of top modules because is a dependency of '" + proj2.getName() + "'"); toBeRemoved.add(proj); break; } } } } for (MavenProject mp : toBeRemoved) { result.remove(mp); } return result; }
From source file:org.gephi.maven.ModuleUtils.java
License:Apache License
protected static String getModuleDownloadPath(MavenProject topPlugin, List<MavenProject> modules, File directory, Log log) throws MojoExecutionException { File dest;/* w ww . j a va 2 s. c o m*/ if (modules.size() > 1) { dest = new File(directory, topPlugin.getArtifactId() + "-" + topPlugin.getVersion() + ".zip"); log.debug("The plugin '" + topPlugin + "' is a suite, creating zip archive at '" + dest.getAbsolutePath() + "'"); // Verify files exist and add to archive try { ZipArchiver archiver = new ZipArchiver(); for (MavenProject module : modules) { File f = new File(directory, module.getArtifactId() + "-" + module.getVersion() + ".nbm"); if (!f.exists()) { throw new MojoExecutionException( "The NBM file '" + f.getAbsolutePath() + "' can't be found"); } archiver.addFile(f, f.getName()); log.debug(" Add file '" + f.getAbsolutePath() + "' to the archive"); } archiver.setCompress(false); archiver.setDestFile(dest); archiver.setForced(true); archiver.createArchive(); log.info("Created ZIP archive for project '" + topPlugin.getName() + "' at '" + dest.getAbsolutePath() + "'"); } catch (IOException ex) { throw new MojoExecutionException( "Something went wrong with the creation of the ZIP archive for project '" + topPlugin.getName() + "'", ex); } catch (ArchiverException ex) { throw new MojoExecutionException( "Something went wrong with the creation of the ZIP archive for project '" + topPlugin.getName() + "'", ex); } } else { dest = new File(directory, topPlugin.getArtifactId() + "-" + topPlugin.getVersion() + ".nbm"); log.debug("The plugin is not a suite, return nbm file '" + dest.getAbsolutePath() + "'"); } return dest.getName(); }
From source file:org.guvnor.ala.build.maven.executor.MavenBuildExecConfigExecutor.java
License:Apache License
@Override public Optional<BinaryConfig> apply(final MavenBuild mavenBuild, final MavenBuildExecConfig mavenBuildExecConfig) { final Project project = mavenBuild.getProject(); final MavenProject mavenProject = build(project, mavenBuild.getGoals(), mavenBuild.getProperties()); final Path path = FileSystems.getFileSystem(URI.create("file://default")) .getPath(project.getTempDir() + "/target/" + project.getExpectedBinary()); final MavenBinary binary = new MavenProjectBinaryImpl(path, project, mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); buildRegistry.registerBinary(binary); return Optional.of(binary); }
From source file:org.guvnor.common.services.project.backend.server.ModuleRepositoryResolverImpl.java
License:Apache License
@Override public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact(final String pomXML, final MavenRepositoryMetadata... filter) { GAVPreferences gavPreferences = gavPreferencesProvider.get(); gavPreferences.load();//from w w w. j av a2 s. co m if (gavPreferences.isConflictingGAVCheckDisabled()) { return Collections.EMPTY_SET; } final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); final GAV gav = new GAV(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact = new HashSet<MavenRepositoryMetadata>(); repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject)); //Filter results if necessary if (filter != null && filter.length > 0) { repositoriesResolvingArtifact.retainAll(Arrays.asList(filter)); } return repositoriesResolvingArtifact; }
From source file:org.guvnor.common.services.project.backend.server.ProjectRepositoryResolverImpl.java
License:Apache License
@Override public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact(final String pomXML, final MavenRepositoryMetadata... filter) { if (isCheckConflictingGAVDisabled) { return Collections.EMPTY_SET; }/* w w w. j a v a 2 s. com*/ final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); final GAV gav = new GAV(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact = new HashSet<MavenRepositoryMetadata>(); repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject)); //Filter results if necessary if (filter != null && filter.length > 0) { repositoriesResolvingArtifact.retainAll(Arrays.asList(filter)); } return repositoriesResolvingArtifact; }
From source file:org.guvnor.common.services.project.backend.server.RepositoryResolverTestUtils.java
License:Apache License
/** * Install a Maven Project to the local Maven Repository * @param mavenProject/*w ww . j a va2 s .co m*/ * @param pomXml */ public static void installArtifact(final MavenProject mavenProject, final String pomXml) { final ReleaseId releaseId = new ReleaseIdImpl(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); final Aether aether = new Aether(mavenProject); final MavenRepository mavenRepository = new MavenRepository(aether) { //Nothing to override, just a sub-class to expose Constructor }; mavenRepository.deployArtifact(releaseId, "content".getBytes(), pomXml.getBytes()); }
From source file:org.guvnor.common.services.project.backend.server.RepositoryResolverTestUtils.java
License:Apache License
/** * Deploy a Maven Project to the 'Remote' Maven Repository defined in the Project's {code}<distribtionManagement>{code} section. * @param mavenProject/* w w w . ja v a 2s . c o m*/ * @param pomXml */ public static void deployArtifact(final MavenProject mavenProject, final String pomXml) { final ReleaseId releaseId = new ReleaseIdImpl(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); //Create temporary files for the JAR and POM final Aether aether = new Aether(mavenProject); final File jarFile = new File(System.getProperty("java.io.tmpdir"), toFileName(releaseId, null) + ".jar"); try { FileOutputStream fos = new FileOutputStream(jarFile); fos.write("content".getBytes()); fos.flush(); fos.close(); } catch (IOException e) { throw new RuntimeException(e); } final File pomFile = new File(System.getProperty("java.io.tmpdir"), toFileName(releaseId, null) + ".pom"); try { FileOutputStream fos = new FileOutputStream(pomFile); fos.write(pomXml.getBytes()); fos.flush(); fos.close(); } catch (IOException e) { throw new RuntimeException(e); } //Artifact representing the JAR Artifact jarArtifact = new DefaultArtifact(releaseId.getGroupId(), releaseId.getArtifactId(), "jar", releaseId.getVersion()); jarArtifact = jarArtifact.setFile(jarFile); //Artifact representing the POM Artifact pomArtifact = new SubArtifact(jarArtifact, "", "pom"); pomArtifact = pomArtifact.setFile(pomFile); //Read <distributionManagement> section final DistributionManagement distributionManagement = mavenProject.getDistributionManagement(); if (distributionManagement != null) { final DeployRequest deployRequest = new DeployRequest(); deployRequest.addArtifact(jarArtifact).addArtifact(pomArtifact).setRepository( getRemoteRepoFromDeployment(distributionManagement.getRepository(), aether.getSession())); try { aether.getSystem().deploy(aether.getSession(), deployRequest); } catch (DeploymentException e) { throw new RuntimeException(e); } } }
From source file:org.heneveld.maven.license_audit.util.Coords.java
public static Coords of(MavenProject x) { // prefer artifact coords as that will be canonical, but it might not be available, e.g. for root project if (x.getArtifact() != null) return of(x.getArtifact()); return new Coords(x.getGroupId(), x.getArtifactId(), x.getVersion(), x.getVersion(), "", ""); }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
/** * @param jar//from ww w . j a v a 2 s.c o m * @throws IOException */ private void doMavenMetadata(MavenProject currentProject, Jar jar) throws IOException { String path = "META-INF/maven/" + currentProject.getGroupId() + "/" + currentProject.getArtifactId(); File pomFile = new File(currentProject.getBasedir(), "pom.xml"); jar.putResource(path + "/pom.xml", new FileResource(pomFile)); Properties p = new Properties(); p.put("version", currentProject.getVersion()); p.put("groupId", currentProject.getGroupId()); p.put("artifactId", currentProject.getArtifactId()); ByteArrayOutputStream out = new ByteArrayOutputStream(); p.store(out, "Generated by org.hsc.novelSpider.bundleplugin"); jar.putResource(path + "/pom.properties", new EmbeddedResource(out.toByteArray(), System.currentTimeMillis())); }