List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:com.sun.enterprise.module.maven.MavenProjectRepository.java
License:Open Source License
/** * When creating {@link MavenProjectRepository} from the current project (which is used * to launch mvn), and if the compile phase has run yet, then the main artifact is * still null.//from w w w .j a va2s . c o m * * <p> * However, it's often convenient to pick up the files that were left in the file system * from the previous execution. This method checks this situation and updates {@link MavenProject} * accordingly, so that it can be then passed to the constructor of {@link MavenProjectRepository}. * * <p> * Think of this as a pre-processing phase to compensate for the lack of the compile phase * invocation. */ public static void prepareProject(MavenProject project) throws IOException { Artifact ma = project.getArtifact(); if (!project.getPackaging().equals("pom") && ma.getFile() == null) { File outdir = new File(project.getBuild().getOutputDirectory()); if (!outdir.exists()) logger.warning("No output directory " + outdir); else ma.setFile(outdir); } if (ma.getFile() != null) { // if the 'ma' is the distribution module, it won't have its own output. if (ma.getFile().isDirectory()) { // if the main artifact is from target/classes, create META-INF.MF new Packager().writeManifest(project, ma.getFile()); } } }
From source file:com.tenderowls.opensource.haxemojos.components.HaxeCompiler.java
License:Apache License
private void addHars(List<String> argumentsList, MavenProject project, Set<CompileTarget> targets, ArtifactFilter artifactFilter) { Map<String, MavenProject> projectReferences = project.getProjectReferences(); for (Artifact artifact : project.getArtifacts()) { boolean filtered = artifactFilter != null && !artifactFilter.include(artifact); if (!filtered && artifact.getType().equals(HaxeFileExtensions.HAR)) { String artifactKey = getProjectReferenceKey(artifact, ":"); MavenProject reference = projectReferences.get(artifactKey); if (reference == null) { File harUnpackDirectory = new File(getDependenciesDirectory(), getProjectReferenceKey(artifact, "-")); unpackHar(artifact, harUnpackDirectory); validateHarMetadata(targets, artifact, new File(harUnpackDirectory, HarMetadata.METADATA_FILE_NAME)); addSourcePath(argumentsList, harUnpackDirectory.getAbsolutePath()); } else { String dirName = OutputNamesHelper.getHarValidationOutput(artifact); File validationDirectory = new File(reference.getBuild().getDirectory(), dirName); validateHarMetadata(targets, artifact, new File(validationDirectory, HarMetadata.METADATA_FILE_NAME)); for (String cp : reference.getCompileSourceRoots()) { addSourcePath(argumentsList, cp); }//from ww w . ja v a2s . c om } } } }
From source file:com.tenderowls.opensource.haxemojos.components.NativeBootstrap.java
License:Apache License
public void initialize(MavenProject project, ArtifactRepository localRepository) throws Exception { this.project = project; this.localRepository = localRepository; Map<String, Plugin> pluginMap = project.getBuild().getPluginsAsMap(); Plugin plugin = pluginMap.get("com.tenderowls.opensource:haxemojos-maven-plugin"); Artifact pluginArtifact = resolveArtifact(repositorySystem.createPluginArtifact(plugin), project.getPluginArtifactRepositories()); String pluginHomeName = plugin.getArtifactId() + "-" + plugin.getVersion(); File pluginHome = new File(pluginArtifact.getFile().getParentFile(), pluginHomeName); if (!pluginHome.exists()) pluginHome.mkdirs();// w ww . j a v a 2 s . com initializePrograms(pluginHome, plugin.getDependencies()); initializeHaxelib(pluginHome); }
From source file:com.tenderowls.opensource.haxemojos.utils.OutputNamesHelper.java
License:Apache License
public static String getTestOutput(MavenProject project) { return project.getBuild().getFinalName() + "-test.n"; }
From source file:com.totsp.mavenplugin.gwt.util.BuildClasspathUtil.java
License:Open Source License
/** * Build classpath list using either gwtHome (if present) or using *project* dependencies. Note * that this is ONLY used for the script/cmd writers (so the scopes are not for the compiler, or * war plugins, etc).//from w w w.j a v a 2s .co m * * This is required so that the script writers can get the dependencies they need regardless of * the Maven scopes (still want to use the Maven scopes for everything else Maven, but for * GWT-Maven we need to access deps differently - directly at times). * * * @param mojo * @param scope * @return file collection for classpath * @throws DependencyResolutionRequiredException */ public static Collection<File> buildClasspathList(final AbstractGWTMojo mojo, final DependencyScope scope) throws DependencyResolutionRequiredException, MojoExecutionException { mojo.getLog().info("establishing classpath list (buildClaspathList - scope = " + scope + ")"); File gwtHome = mojo.getGwtHome(); MavenProject project = mojo.getProject(); Set<File> items = new LinkedHashSet<File>(); // inject GWT jars and relative native libs for all scopes // (gwt-user and gwt-dev should be scoped provided to keep them out of // other maven stuff - not end up in war, etc - this util is only used for GWT-Maven // scripts) // TODO filter the rest of the stuff so we don't double add these if (gwtHome != null) { mojo.getLog().info("google.webtoolkit.home (gwtHome) set, using it for GWT dependencies - " + gwtHome.getAbsolutePath()); items.addAll(BuildClasspathUtil.injectGwtDepsFromGwtHome(gwtHome, mojo)); } else { mojo.getLog() .info("google.webtoolkit.home (gwtHome) *not* set, using project POM for GWT dependencies"); items.addAll(BuildClasspathUtil.injectGwtDepsFromRepo(mojo)); } // add sources if (mojo.getSourcesOnPath()) { BuildClasspathUtil.addSourcesWithActiveProjects(project, items, DependencyScope.COMPILE); } // add resources if (mojo.getResourcesOnPath()) { BuildClasspathUtil.addResourcesWithActiveProjects(project, items, DependencyScope.COMPILE); } // add classes dir items.add(new File(project.getBuild().getDirectory() + File.separator + "classes")); // if runtime add runtime if (scope == DependencyScope.RUNTIME) { // use Collection<Artifact> because sometimes it's LinkedHashSet, sometimes it's List, and NO TIMES is it documented for (Artifact a : (Collection<Artifact>) project.getRuntimeArtifacts()) { items.add(a.getFile()); } } // if test add test if (scope == DependencyScope.TEST) { for (Artifact a : (Collection<Artifact>) project.getTestArtifacts()) { items.add(a.getFile()); } // add test classes dir items.add(new File(project.getBuild().getDirectory() + File.separator + "test-classes")); // add test sources and resources BuildClasspathUtil.addSourcesWithActiveProjects(project, items, scope); BuildClasspathUtil.addResourcesWithActiveProjects(project, items, scope); } // add compile (even when scope is other than) for (Artifact a : (Collection<Artifact>) project.getCompileArtifacts()) { items.add(a.getFile()); } // add all source artifacts for (Artifact a : (Collection<Artifact>) project.getArtifacts()) { if ("sources".equals(a.getClassifier())) { items.add(a.getFile()); } } mojo.getLog().debug("SCRIPT INJECTION CLASSPATH LIST"); for (File f : items) { mojo.getLog().debug(" " + f.getAbsolutePath()); } return items; }
From source file:com.webguys.maven.plugin.st.Controller.java
License:Open Source License
private Class loadController(MavenProject project, MavenSession session, ProjectDependenciesResolver dependenciesResolver) throws MalformedURLException, ClassNotFoundException, ArtifactResolutionException, ArtifactNotFoundException { ArrayList<String> scopes = new ArrayList<String>(1); scopes.add(JavaScopes.RUNTIME);// w w w .j av a 2s . c om Set<Artifact> artifacts = dependenciesResolver.resolve(project, scopes, session); ArrayList<URL> urls = new ArrayList<URL>(); urls.add(new File(project.getBuild().getOutputDirectory()).getAbsoluteFile().toURI().toURL()); for (Artifact artifact : artifacts) { urls.add(artifact.getFile().getAbsoluteFile().toURI().toURL()); } ClassLoader loader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), this.getClass().getClassLoader()); return loader.loadClass(this.className); }
From source file:com.xebia.mojo.dashboard.reports.XmlFileXpathReport.java
License:Apache License
/** {@inheritDoc} */ protected File getReportingPath(MavenProject project) { return new File(project.getBuild().getDirectory()); }
From source file:de.andrena.tools.macker.plugin.it.AbstractMackerPluginITCase.java
License:Apache License
/** * Execute the plugin./*from w w w . j a v a 2 s .c o m*/ * @param baseDir Execute the plugin goal on a test project and verify generated files. * @param properties additional properties * @param goalList comma separated list of goals to execute * @throws Exception any exception generated during test */ protected void testProject(File baseDir, Properties properties, String goalList) throws Exception { File pom = new File(baseDir, "pom.xml"); String[] goal = goalList.split(","); List<String> goals = new ArrayList<String>(); for (int i = 0; i < goal.length; i++) { goals.add(goal[i]); } executeMaven(pom, properties, goals, true); MavenProject project = readProject(pom); File projectOutputDir = new File(project.getBuild().getDirectory()); compareMackerOutput(baseDir, projectOutputDir); }
From source file:de.lightful.maven.plugins.drools.impl.OutputFileWriter.java
License:Apache License
public void writeOutputFile(Collection<KnowledgePackage> knowledgePackages, PluginLogger logger, MavenProjectDecorator mavenProjectDecorator, MavenProjectHelper projectHelper, String classifier) throws MojoFailureException { MavenProject mavenProject = mavenProjectDecorator.getProject(); ensureCorrectPackaging(mavenProject); Build build = mavenProject.getBuild(); File buildDirectory = new File(build.getDirectory()); File outputFile = new File(buildDirectory, build.getFinalName() + "." + WellKnownNames.FILE_EXTENSION_DROOLS_KNOWLEDGE_MODULE); final String absoluteOutputFileName = outputFile.getAbsolutePath(); logger.info().write("Writing " + knowledgePackages.size() + " knowledge packages into output file " + mavenProjectDecorator.relativeToBasedir(outputFile)).nl(); int counter = 1; for (KnowledgePackage knowledgePackage : knowledgePackages) { String declaredTypesCount = "(unknown)"; String globalsCount = "(unknown)"; String rulesCount = "(unknown)"; if (knowledgePackage instanceof KnowledgePackageImp) { final KnowledgePackageImp packageImp = (KnowledgePackageImp) knowledgePackage; rulesCount = String.valueOf(knowledgePackage.getRules().size()); declaredTypesCount = String.valueOf(packageImp.pkg.getTypeDeclarations().size()); globalsCount = String.valueOf(packageImp.pkg.getGlobals().size()); }/*from w w w . ja va 2s . c om*/ logger.info().write(" #" + counter + ": " + knowledgePackage.getName()).write(" (" + rulesCount + " rules, " + declaredTypesCount + " type declarations, " + globalsCount + " globals)").nl(); counter++; } ensureTargetDirectoryExists(buildDirectory); prepareOutputFileForWriting(outputFile, absoluteOutputFileName); KnowledgeIoFactory factory = new KnowledgeIoFactory(); try { final KnowledgeModuleWriter writer = factory .createKnowledgeModuleWriter(new FileOutputStream(outputFile)); writer.writeKnowledgePackages(knowledgePackages); } catch (IOException e) { throw new MojoFailureException("Unable to write compiled knowledge into output file!", e); } if (classifier != null && !"".equals(classifier)) { debug.write("Attaching file " + outputFile.getAbsolutePath() + " as artifact with classifier '" + classifier + "'."); projectHelper.attachArtifact(mavenProject, outputFile, classifier); } else { debug.write(("Setting project main artifact to " + outputFile.getAbsolutePath())).nl(); final Artifact artifact = mavenProject.getArtifact(); artifact.setFile(outputFile); } }
From source file:edu.umd.mith.util.tei.OddSpec.java
License:Apache License
public File getOutputDir(MavenProject project) { return this.outputDir == null ? new File(project.getBuild().getDirectory(), "generated-resources/schemas") : this.outputDir; }