List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.efaps.maven_java5.EfapsAnnotationDescriptorExtractor.java
License:Open Source License
/** * * @param _project// w w w . j av a2s .co m * @param _pluginDescriptor */ public List<MojoDescriptor> execute(final MavenProject _project, final PluginDescriptor _pluginDescriptor) throws InvalidPluginDescriptorException { final List<MojoDescriptor> descriptors = new ArrayList<MojoDescriptor>(); // check all compiled classes for mojos final File classesDirectory = new File(_project.getBuild().getOutputDirectory()); final DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(classesDirectory); scanner.setIncludes(new String[] { "**/*.class" }); scanner.scan(); if (getLogger().isDebugEnabled()) { getLogger().debug("Scanning " + scanner.getIncludedFiles().length + " classes"); } final String[] included = scanner.getIncludedFiles(); if (included.length > 0) { final ClassLoader cl = getClassLoader(_project); for (final String file : scanner.getIncludedFiles()) { final MojoDescriptor desc = scan(cl, file.substring(0, file.lastIndexOf(".class")).replace('/', '.')); if (desc != null) { desc.setPluginDescriptor(_pluginDescriptor); descriptors.add(desc); if (getLogger().isInfoEnabled()) { getLogger().info("Found mojo " + desc.getImplementation()); } } } } final Resource resource = new Resource(); resource.setDirectory(classesDirectory.getAbsolutePath()); resource.setIncludes(Collections.EMPTY_LIST); resource.setExcludes(Collections.EMPTY_LIST); _project.addResource(resource); return descriptors; }
From source file:org.efaps.maven_java5.EfapsAnnotationDescriptorExtractor.java
License:Open Source License
/** * * @param _project maven project//from w ww. j a v a 2s . c o m * @return * @throws InvalidPluginDescriptorException */ protected ClassLoader getClassLoader(final MavenProject _project) throws InvalidPluginDescriptorException { final List<URL> urls = new ArrayList<URL>(); // append all compile dependencies to the urls final Set<Artifact> toResolve = new HashSet<Artifact>(); for (final Object obj : _project.getDependencies()) { final Dependency dependency = (Dependency) obj; final String scope = dependency.getScope(); if (isCompileScope(scope)) { final Artifact artifact = this.artifactFactory.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), scope, dependency.getType()); toResolve.add(artifact); } } try { final ArtifactResolutionResult result = this.artifactResolver.resolveTransitively(toResolve, _project.getArtifact(), getManagedVersionMap(_project), getLocalRepository(), _project.getRemoteArtifactRepositories(), this.artifactMetadataSource, this.filter); for (final Object obj : result.getArtifacts()) { final Artifact artifact = (Artifact) obj; urls.add(artifact.getFile().toURL()); } } catch (final Exception e) { throw new InvalidPluginDescriptorException( "Failed to resolve transitively artifacts: " + e.getMessage(), e); } // append compile class path elements for (final Object obj : _project.getArtifacts()) { final Artifact cpe = (Artifact) obj; try { urls.add(cpe.getFile().toURL()); // URI().toURL() ); } catch (final MalformedURLException e) { getLogger().warn("Cannot convert '" + cpe + "' to URL", e); } } // append target output directory (where the compiled files are) try { urls.add(new File(_project.getBuild().getOutputDirectory()).toURL()); } catch (final MalformedURLException e) { getLogger().warn("Cannot convert '" + _project.getBuild().getOutputDirectory() + "' to URL", e); } if (getLogger().isDebugEnabled()) { getLogger().debug("URLS: \n" + urls.toString().replaceAll(",", "\n ")); } else if (getLogger().isInfoEnabled()) { getLogger().info("URLS: \n" + urls.toString().replaceAll(",", "\n ")); } return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); }
From source file:org.eluder.coveralls.maven.plugin.util.CoverageParsersFactory.java
License:Open Source License
public List<CoverageParser> createParsers() throws IOException { List<CoverageParser> parsers = new ArrayList<CoverageParser>(); List<MavenProject> projects = new MavenProjectCollector(project).collect(); ExistingFiles jacocoFiles = ExistingFiles.create(jacocoReports); ExistingFiles coberturaFiles = ExistingFiles.create(coberturaReports); ExistingFiles sagaFiles = ExistingFiles.create(sagaReports); for (MavenProject p : projects) { File reportingDirectory = new File(p.getModel().getReporting().getOutputDirectory()); File buildDirectory = new File(p.getBuild().getDirectory()); jacocoFiles.add(new File(reportingDirectory, JACOCO_FILE)); coberturaFiles.add(new File(reportingDirectory, COBERTURA_FILE)); sagaFiles.add(new File(buildDirectory, SAGA_FILE)); }//from ww w . jav a 2s . c o m for (File jacocoFile : jacocoFiles) { parsers.add(new JaCoCoParser(jacocoFile, sourceLoader)); } for (File coberturaFile : coberturaFiles) { parsers.add(new CoberturaParser(coberturaFile, sourceLoader)); } for (File sagaFile : sagaFiles) { parsers.add(new SagaParser(sagaFile, sourceLoader)); } if (parsers.isEmpty()) { throw new IOException("No coverage report files found"); } return Collections.unmodifiableList(parsers); }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static void deployProject(File dirJar, File dirWar, MavenProject project, boolean deployDep, HashSet<String> ignoreProjects) throws Exception { if (!dirJar.exists()) { System.out.println("The directory " + dirJar.getParent() + " does not exists !"); return;/*from w w w .j ava 2 s . c o m*/ } if (!dirWar.exists()) { System.out.println("The directory " + dirWar.getParent() + " does not exists !"); return; } int counter = 0; if (deployDep) { counter += deployedDependency(dirJar, dirWar, project, ignoreProjects).size(); } deleteFileOnExist(dirWar, project.getBuild().getFinalName()); if (project.getPackaging().equals("jar")) { counter++; File moduleFile = new File(project.getBasedir().toString() + "/target/" + project.getArtifactId() + "-" + project.getVersion() + "." + project.getPackaging()); copyFileToDirectory(moduleFile, dirJar); printMessage("deploy", " Deployed file '" + project.getArtifactId() + "' to " + dirJar.getPath()); } else { if (project.getPackaging().equals("war") || project.getPackaging().equals("exo-jcr") || project.getPackaging().equals("exo-portal") || project.getPackaging().equals("exo-portlet")) { File deployWar = new File( project.getBasedir().toString() + "/target/" + project.getBuild().getFinalName() + ".war"); copyFileToDirectory(deployWar, dirWar); printMessage("deploy", " Deployed file '" + project.getArtifactId() + "' to " + dirWar.getPath()); counter++; } } printMessage("deploy", " TOTAL DEPLOY : " + counter + " project"); }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static void createManifest(File mf, MavenProject project, HashSet ignoredProjects) throws IOException { StringBuilder b = new StringBuilder(); b.append("Manifest-Version: 1.0\n"); b.append("Ant-Version: Apache Ant 1.5.3\n"); b.append("Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)\n"); b.append("Class-Path: "); if (checkTypes(project)) { for (Artifact da : allDependencies(project, ignoredProjects)) { if (da.getType().equals("jar")) { b.append(da.getArtifactId() + "-" + da.getVersion() + ".jar "); }//from w w w .j a v a 2 s .com } } b.append("\n"); b.append("Built-By: exo\n"); b.append("Specification-Title: " + project.getArtifactId() + "\n"); b.append("Specification-Version: " + project.getVersion() + "\n"); b.append("Specification-Vendor: eXo Platform SARL\n"); b.append("Implementation-Title: " + project.getBuild().getFinalName() + "\n"); b.append("Implementation-Version: " + project.getVersion() + "\n"); b.append("Implementation-Vendor: eXo Platform SARL\n"); FileOutputStream out = new FileOutputStream(mf); out.write(b.toString().getBytes()); out.close(); }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static void createManifest2(File mf, MavenProject project, HashSet includes) throws IOException { StringBuilder b = new StringBuilder(); b.append("Manifest-Version: 1.0\n"); b.append("Ant-Version: Apache Ant 1.5.3\n"); b.append("Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)\n"); if (includes != null) { b.append("Class-Path: "); for (Artifact da : allDependencies(project, null)) { if (da.getType().equals("jar") && includes.contains(da.getArtifactId())) { b.append(da.getArtifactId() + "-" + da.getVersion() + ".jar "); }/*from www . jav a2 s. c o m*/ } b.append("\n"); } b.append("Built-By: exo\n"); b.append("Specification-Title: " + project.getArtifactId() + "\n"); b.append("Specification-Version: " + project.getVersion() + "\n"); b.append("Specification-Vendor: eXo Platform SARL\n"); b.append("Implementation-Title: " + project.getBuild().getFinalName() + "\n"); b.append("Implementation-Version: " + project.getVersion() + "\n"); b.append("Implementation-Vendor: eXo Platform SARL\n"); FileOutputStream out = new FileOutputStream(mf); out.write(b.toString().getBytes()); out.close(); }
From source file:org.fusesource.ide.server.karaf.core.server.subsystems.publish.ModuleBundleVersionUtility.java
License:Open Source License
private BundleDetails findBuildArtifactInProjectsOutputFolder(IModule[] module) { BundleDetails bd = null;//w ww. j a v a2 s. c o m IProject prj = module[0].getProject(); IMavenProjectFacade m2prjFacade = MavenPlugin.getMavenProjectRegistry().create(prj, new NullProgressMonitor()); MavenProject m2Project = m2prjFacade.getMavenProject(); if (m2Project != null) { String path = m2Project.getBuild().getOutputDirectory(); String file = m2Project.getBuild().getFinalName(); File out = new File(path, file); if (out.exists() && out.isFile()) { try (JarFile jf = new JarFile(out)) { bd = createBundleDetails(jf.getManifest()); } catch (IOException ex) { Activator.getLogger().error(ex); } } } return bd; }
From source file:org.geotools.maven.JarCollector.java
License:Open Source License
/** * Copies the {@code .jar} files to the collect directory. * * @throws MojoExecutionException if the plugin execution failed. *//*from w ww .jav a 2 s .com*/ public void execute() throws MojoExecutionException { /* * Gets the parent "target" directory. */ MavenProject parent = project; while (parent.hasParent()) { parent = parent.getParent(); } collectDirectory = parent.getBuild().getDirectory(); /* * Now collects the JARs. */ try { collect(); } catch (IOException e) { throw new MojoExecutionException("Error collecting the JAR file.", e); } }
From source file:org.grails.maven.plugin.tools.DefaultGrailsServices.java
License:Apache License
public MavenProject createPOM(final String groupId, final GrailsProject grailsProjectDescriptor, final String mtgGroupId, final String grailsPluginArtifactId, final String mtgVersion, final boolean addEclipseSettings) { final MavenProject pom = new MavenProject(); if (pom.getBuild().getPluginManagement() == null) { pom.getBuild().setPluginManagement(new PluginManagement()); }/*from w w w . j av a 2s. c o m*/ final PluginManagement pluginMgt = pom.getPluginManagement(); // Those four properties are needed. pom.setModelVersion("4.0.0"); pom.setPackaging("grails-app"); // Specific for GRAILS pom.getModel().getProperties().setProperty("grailsHome", "${env.GRAILS_HOME}"); pom.getModel().getProperties().setProperty("grailsVersion", grailsProjectDescriptor.getAppGrailsVersion()); // Add our own plugin final Plugin grailsPlugin = new Plugin(); grailsPlugin.setGroupId(mtgGroupId); grailsPlugin.setArtifactId(grailsPluginArtifactId); grailsPlugin.setVersion(mtgVersion); grailsPlugin.setExtensions(true); pom.addPlugin(grailsPlugin); // Add compiler plugin settings final Plugin compilerPlugin = new Plugin(); compilerPlugin.setGroupId("org.apache.maven.plugins"); compilerPlugin.setArtifactId("maven-compiler-plugin"); final Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); final Xpp3Dom source = new Xpp3Dom("source"); source.setValue("1.5"); compilerConfig.addChild(source); final Xpp3Dom target = new Xpp3Dom("target"); target.setValue("1.5"); compilerConfig.addChild(target); compilerPlugin.setConfiguration(compilerConfig); pom.addPlugin(compilerPlugin); // Add eclipse plugin settings if (addEclipseSettings) { final Plugin warPlugin = new Plugin(); warPlugin.setGroupId("org.apache.maven.plugins"); warPlugin.setArtifactId("maven-war-plugin"); final Xpp3Dom warConfig = new Xpp3Dom("configuration"); final Xpp3Dom warSourceDirectory = new Xpp3Dom("warSourceDirectory"); warSourceDirectory.setValue("web-app"); warConfig.addChild(warSourceDirectory); warPlugin.setConfiguration(warConfig); pluginMgt.addPlugin(warPlugin); final Plugin eclipsePlugin = new Plugin(); eclipsePlugin.setGroupId("org.apache.maven.plugins"); eclipsePlugin.setArtifactId("maven-eclipse-plugin"); final Xpp3Dom configuration = new Xpp3Dom("configuration"); final Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); final Xpp3Dom projectnature = new Xpp3Dom("projectnature"); projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); projectnatures.addChild(projectnature); configuration.addChild(projectnatures); final Xpp3Dom additionalBuildcommands = new Xpp3Dom("additionalBuildcommands"); final Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); additionalBuildcommands.addChild(buildcommand); configuration.addChild(additionalBuildcommands); // Xpp3Dom additionalProjectFacets = new Xpp3Dom( // "additionalProjectFacets"); // Xpp3Dom jstWeb = new Xpp3Dom("jst.web"); // jstWeb.setValue("2.5"); // additionalProjectFacets.addChild(jstWeb); // configuration.addChild(additionalProjectFacets); final Xpp3Dom packaging = new Xpp3Dom("packaging"); packaging.setValue("war"); configuration.addChild(packaging); eclipsePlugin.setConfiguration(configuration); pluginMgt.addPlugin(eclipsePlugin); } // Change the default output directory to generate classes pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); pom.setArtifactId(grailsProjectDescriptor.getAppName()); pom.setName(grailsProjectDescriptor.getAppName()); pom.setGroupId(groupId); pom.setVersion(grailsProjectDescriptor.getAppVersion()); if (!grailsProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { getLogger().warn("====================================================================="); getLogger().warn("If your project is currently in development, in accordance with maven "); getLogger().warn("standards, its version must be " + grailsProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + grailsProjectDescriptor.getAppVersion() + "."); getLogger().warn("Please, change your version in the application.properties descriptor"); getLogger().warn("and regenerate your pom."); getLogger().warn("====================================================================="); } return pom; }
From source file:org.hardisonbrewing.maven.core.TargetDirectoryService.java
License:Open Source License
public static final String getTempPackagePath() { MavenProject project = ProjectService.getProject(); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(getTargetDirectoryPath()); stringBuffer.append(File.separator); stringBuffer.append(project.getBuild().getFinalName()); return stringBuffer.toString(); }