List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.codehaus.mojo.xml.TransformMojo.java
License:Apache License
private File getOutputDir(File pOutputDir) { if (pOutputDir == null) { MavenProject project = getProject(); String dir = project.getBuild().getDirectory(); if (dir == null) { throw new IllegalStateException("The projects build directory is null."); }/*from www. j a va2 s. com*/ dir += "/generated-resources/xml/xslt"; return asAbsoluteFile(new File(dir)); } return asAbsoluteFile(pOutputDir); }
From source file:org.codehaus.tycho.eclipsepackaging.ProductExportMojo.java
static File getTarget(TargetEnvironment environment, boolean separateEnvironments, MavenProject project) { File target;/*from w ww.j av a2s .com*/ if (separateEnvironments) { target = new File(project.getBuild().getDirectory(), toString(environment)); } else { target = new File(project.getBuild().getDirectory(), "product"); } target.mkdirs(); return target; }
From source file:org.commonjava.emb.artifact.resolver.SimpleResolutionListener.java
License:Open Source License
private void logProjectResolution(final ProjectDependencyResolutionEvent event) { final Collection<? extends MavenProject> projects = event.getProjects(); final Set<Artifact> resolvedArtifacts = event.getResolvedArtifacts(); final StringBuilder sb = new StringBuilder(); sb.append("Projects Resolved:\n---------------------\n\n"); for (final MavenProject mavenProject : projects) { sb.append(" ").append(mavenProject.getId()).append("\n"); }/* ww w. j a v a 2 s .c om*/ appendArtifactInfo(resolvedArtifacts, sb); for (final MavenProject project : projects) { writeFile(sb, new File(project.getBuild().getDirectory(), "project-" + project.getId().replace(':', '_') + ".resolver.log")); } }
From source file:org.commonjava.emb.example.resolution.logger.SimpleProjectResolutionListener.java
License:Open Source License
public void handle(final EMBEvent evt) { if (evt instanceof ProjectDependencyResolutionEvent) { final ProjectDependencyResolutionEvent event = (ProjectDependencyResolutionEvent) evt; final Collection<? extends MavenProject> projects = event.getProjects(); final Set<org.apache.maven.artifact.Artifact> resolvedArtifacts = event.getResolvedArtifacts(); final StringBuilder sb = new StringBuilder(); sb.append("Projects Resolved:\n---------------------\n\n"); for (final MavenProject mavenProject : projects) { sb.append(" ").append(mavenProject.getId()).append("\n"); }// ww w. j ava 2 s .c om appendArtifactInfo(resolvedArtifacts, sb); for (final MavenProject project : projects) { writeFile(sb, new File(project.getBuild().getDirectory(), "project-" + project.getId().replace(':', '_') + ".resolver.log")); } } }
From source file:org.cruxframework.crux.plugin.maven.ClasspathBuilder.java
License:Apache 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). 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 project The maven project the Mojo is running for * @param artifacts the project artifacts (all scopes) * @param scope artifact scope to use// w ww .ja va2 s.c o m * @param isGenerator whether to use processed resources and compiled classes (false), or raw resources (true). * @return file collection for classpath * @throws MojoExecutionException */ public Collection<File> buildClasspathList(final MavenProject project, final String scope, Set<Artifact> artifacts, boolean isGenerator, boolean addSources) throws ClasspathBuilderException { getLogger().debug("establishing classpath list (scope = " + scope + ")"); Set<File> items = new LinkedHashSet<File>(); // Note : Don't call addSourceWithActiveProject as a GWT dependency MUST be a valid GWT library module : // * include java sources in the JAR as resources // * define a gwt.xml module file to declare the required inherits // addSourceWithActiveProject would make some java sources available to GWT compiler that should not be accessible in // a non-reactor build, making the build less deterministic and encouraging bad design. if (!isGenerator) { items.add(new File(project.getBuild().getOutputDirectory())); } if (addSources) { addSources(items, project.getCompileSourceRoots()); if (isGenerator) { addResources(items, project.getResources()); } } // Use our own ClasspathElements fitering, as for RUNTIME we need to include PROVIDED artifacts, // that is not the default Maven policy, as RUNTIME is used here to build the GWTShell execution classpath if (scope.equals(SCOPE_TEST)) { addSources(items, project.getTestCompileSourceRoots()); addResources(items, project.getTestResources()); items.add(new File(project.getBuild().getTestOutputDirectory())); // Add all project dependencies in classpath for (Artifact artifact : artifacts) { items.add(artifact.getFile()); } } else if (scope.equals(SCOPE_COMPILE)) { // Add all project dependencies in classpath getLogger().debug("candidate artifacts : " + artifacts.size()); for (Artifact artifact : artifacts) { String artifactScope = artifact.getScope(); if (SCOPE_COMPILE.equals(artifactScope) || SCOPE_PROVIDED.equals(artifactScope) || SCOPE_SYSTEM.equals(artifactScope)) { items.add(artifact.getFile()); } } } else if (scope.equals(SCOPE_RUNTIME)) { // Add all dependencies BUT "TEST" as we need PROVIDED ones to setup the execution // GWTShell that is NOT a full JEE server for (Artifact artifact : artifacts) { getLogger().debug("candidate artifact : " + artifact); if (!artifact.getScope().equals(SCOPE_TEST) && artifact.getArtifactHandler().isAddedToClasspath()) { items.add(artifact.getFile()); } } } else { throw new ClasspathBuilderException("unsupported scope " + scope); } return items; }
From source file:org.debian.dependency.ProjectArtifactSpy.java
License:Apache License
@Override public void onEvent(final Object event) { if (!(event instanceof ExecutionEvent)) { return;/* w w w . j a v a 2 s . c o m*/ } ExecutionEvent execEvent = (ExecutionEvent) event; if (!Type.ProjectSucceeded.equals(execEvent.getType()) && !Type.ForkedProjectSucceeded.equals(execEvent.getType())) { return; } MavenProject project = execEvent.getProject(); Artifact pomArtifact = repoSystem.createProjectArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion()); pomArtifact.setFile(project.getFile()); // the first project should always be the top-level project if (outputFile == null) { outputFile = new File(project.getBuild().getDirectory(), ServicePackage.PROJECT_ARTIFACT_REPORT_NAME); } recordArtifact(pomArtifact); recordArtifact(project.getArtifact()); for (Artifact artifact : project.getAttachedArtifacts()) { recordArtifact(artifact); } }
From source file:org.dugilos.m2e.nar.internal.NarPluginConfiguration.java
License:Open Source License
public NarPluginConfiguration(IProject project, MavenProject mavenProject, String pluginId, Log log) throws CoreException { this.mavenProject = mavenProject; this.pluginId = pluginId; // extract local repository (containing nar files dependencies) ProjectBuildingRequest buildingRequest = mavenProject.getProjectBuildingRequest(); ArtifactRepository artifactRepository = buildingRequest.getLocalRepository(); // extract project directories absoluteProjectBaseDir = project.getLocation().toFile(); projectBuildDirectory = mavenProject.getBuild().getDirectory(); // extract com.github.maven-nar:nar-maven-plugin plugin narMavenPlugin = getNarMavenPlugin(mavenProject); MgtNarMavenPlugin = getMgtNarMavenPlugin(mavenProject); // If the plugin isn't used in the project, it's useless to go further if (narMavenPlugin == null) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, "Plugin " + NAR_MAVEN_PLUGIN_GROUPID + ":" + NAR_MAVEN_PLUGIN_ARTIFACTID + " not found"); throw new CoreException(status); }//from w w w . ja v a 2s . c o m String arch = NarUtil.getArchitecture(null); String os = NarUtil.getOS(null); String aolPrefix = arch + "." + os + "."; NarProperties narProperties = null; try { narProperties = NarProperties.getInstance(mavenProject); } catch (MojoFailureException e) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, e.getMessage(), e); throw new CoreException(status); } String configLinkerName = getConfigurationLinkerName(); linker = new Linker(configLinkerName, log); // if configLinkerName is null we call getName(NarProperties properties, String prefix) to initialise the name from AOL if (configLinkerName == null) { try { linker.getName(narProperties, aolPrefix); } catch (MojoFailureException e) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, e.getMessage(), e); throw new CoreException(status); } catch (MojoExecutionException e) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, e.getMessage(), e); throw new CoreException(status); } } try { narManager = new NarManager(log, artifactRepository, mavenProject, arch, os, linker); } catch (MojoFailureException e) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, e.getMessage(), e); throw new CoreException(status); } catch (MojoExecutionException e) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, e.getMessage(), e); throw new CoreException(status); } try { aol = NarUtil.getAOL(mavenProject, arch, os, linker, null, log); } catch (MojoFailureException e) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, e.getMessage(), e); throw new CoreException(status); } catch (MojoExecutionException e) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, e.getMessage(), e); throw new CoreException(status); } String layoutName = getLayoutName(); try { narLayout = AbstractNarLayout.getLayout(layoutName, log); } catch (MojoExecutionException e) { int severity = IStatus.ERROR; Status status = new Status(severity, pluginId, e.getMessage(), e); throw new CoreException(status); } }
From source file:org.dugilos.m2e.nar.internal.NarPluginConfiguration.java
License:Open Source License
private Plugin getNarMavenPlugin(MavenProject mavenProject) { // extract com.github.maven-nar:nar-maven-plugin plugin Plugin narMavenPlugin = null;//from w ww .j av a 2 s .c o m List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Iterator<Plugin> it = plugins.iterator(); it.hasNext();) { Plugin plugin = it.next(); if (NAR_MAVEN_PLUGIN_GROUPID.equals(plugin.getGroupId()) && NAR_MAVEN_PLUGIN_ARTIFACTID.equals(plugin.getArtifactId())) { narMavenPlugin = plugin; break; } } return narMavenPlugin; }
From source file:org.dugilos.m2e.nar.internal.NarPluginConfiguration.java
License:Open Source License
private Plugin getMgtNarMavenPlugin(MavenProject mavenProject) { // extract com.github.maven-nar:nar-maven-plugin management plugin Plugin MgtNarMavenPlugin = null;//w ww.ja v a2 s . com List<Plugin> plugins = mavenProject.getBuild().getPluginManagement().getPlugins(); for (Iterator<Plugin> it = plugins.iterator(); it.hasNext();) { Plugin plugin = it.next(); if (NAR_MAVEN_PLUGIN_GROUPID.equals(plugin.getGroupId()) && NAR_MAVEN_PLUGIN_ARTIFACTID.equals(plugin.getArtifactId())) { MgtNarMavenPlugin = plugin; break; } } return MgtNarMavenPlugin; }
From source file:org.ebayopensource.turmeric.plugins.maven.util.ProjectClassLoader.java
License:Open Source License
private static URL[] getMavenProjectClassLoaderURLS(MavenProject project) throws MalformedURLException { List<File> searchPaths = new ArrayList<File>(); // Project Compile Artifacts @SuppressWarnings("unchecked") final List<Artifact> arts = project.getCompileArtifacts(); if (arts != null) { for (Artifact arti : arts) { File artiFile = arti.getFile(); if ((artiFile != null) && (artiFile.exists())) { searchPaths.add(artiFile); }/*from www .j a v a2 s. c om*/ } } // Project Resources @SuppressWarnings("unchecked") final List<Resource> resources = project.getBuild().getResources(); for (Resource resource : resources) { String resDir = resource.getDirectory(); File dir = new File(resDir); if (!dir.isAbsolute()) { dir = new File(project.getBasedir(), resDir); } searchPaths.add(dir); } // The Classes Dir File classesDir = new File(project.getBuild().getOutputDirectory()); if (!classesDir.isAbsolute()) { classesDir = new File(project.getBasedir(), project.getBuild().getOutputDirectory()); } searchPaths.add(classesDir); // Compile Source Roots - (needed for codegen javac) @SuppressWarnings("unchecked") List<String> sourceRoots = project.getCompileSourceRoots(); if (sourceRoots != null) { for (String srcRoot : sourceRoots) { if (StringUtils.isBlank(srcRoot)) { // skip continue; } File src = new File(srcRoot); if (src.exists()) { searchPaths.add(new File(srcRoot)); } } } int count = searchPaths.size(); URL urls[] = new URL[count]; for (int i = 0; i < count; i++) { urls[i] = searchPaths.get(i).toURI().toURL(); System.out.printf("### ProjectClassLoader[%d]: %s%n", i, urls[i].toExternalForm()); } return urls; }