List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:io.reactiverse.vertx.maven.plugin.mojos.PackageMojo.java
License:Apache License
public static String computeOutputName(MavenProject project, String classifier) { String finalName = project.getBuild().getFinalName(); if (finalName != null) { if (finalName.endsWith(".jar")) { finalName = finalName.substring(0, finalName.length() - 4); }//w w w. j a v a2s . c o m if (classifier != null && !classifier.isEmpty()) { finalName += "-" + classifier; } finalName += ".jar"; return finalName; } else { finalName = project.getArtifactId() + "-" + project.getVersion(); if (classifier != null && !classifier.isEmpty()) { finalName += "-" + classifier; } finalName += ".jar"; return finalName; } }
From source file:io.sarl.maven.compiler.AbstractSarlBatchCompilerMojo.java
License:Apache License
/** Replies the current classpath. * * @return the current classpath./*from w ww .ja v a2s. c o m*/ * @throws MojoExecutionException on failure. */ protected List<File> getClassPath() throws MojoExecutionException { final Set<String> classPath = new LinkedHashSet<>(); final MavenProject project = getProject(); classPath.add(project.getBuild().getSourceDirectory()); try { classPath.addAll(project.getCompileClasspathElements()); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } for (final Artifact dep : project.getArtifacts()) { classPath.add(dep.getFile().getAbsolutePath()); } classPath.remove(project.getBuild().getOutputDirectory()); final List<File> files = new ArrayList<>(); for (final String filename : classPath) { final File file = new File(filename); if (file.exists()) { files.add(file); } else { getLog().warn(Locale.getString(AbstractSarlBatchCompilerMojo.class, "ERROR_3", filename)); //$NON-NLS-1$ } } return files; }
From source file:io.sundr.maven.GenerateBomMojo.java
License:Apache License
/** * Returns the generated {@link org.apache.maven.project.MavenProject} to build. * This version of the project contains all the stuff needed for building (parents, profiles, properties etc). * * @param project The source {@link org.apache.maven.project.MavenProject}. * @param config The {@link io.sundr.maven.BomConfig}. * @return The build {@link org.apache.maven.project.MavenProject}. *//*from ww w. j a v a 2 s .com*/ private static MavenProject toBuild(MavenProject project, BomConfig config) { File outputDir = new File(project.getBuild().getOutputDirectory()); File bomDir = new File(outputDir, config.getArtifactId()); File generatedBom = new File(bomDir, BOM_NAME); MavenProject toBuild = project.clone(); //we want to avoid recursive "generate-bom". toBuild.setExecutionRoot(false); toBuild.setFile(generatedBom); toBuild.getModel().setPomFile(generatedBom); toBuild.setModelVersion(project.getModelVersion()); toBuild.setArtifact(new DefaultArtifact(project.getGroupId(), config.getArtifactId(), project.getVersion(), project.getArtifact().getScope(), project.getArtifact().getType(), project.getArtifact().getClassifier(), project.getArtifact().getArtifactHandler())); toBuild.setParent(project.getParent()); toBuild.getModel().setParent(project.getModel().getParent()); toBuild.setGroupId(project.getGroupId()); toBuild.setArtifactId(config.getArtifactId()); toBuild.setVersion(project.getVersion()); toBuild.setPackaging("pom"); toBuild.setName(config.getName()); toBuild.setDescription(config.getDescription()); toBuild.setUrl(project.getUrl()); toBuild.setLicenses(project.getLicenses()); toBuild.setScm(project.getScm()); toBuild.setDevelopers(project.getDevelopers()); toBuild.setDistributionManagement(project.getDistributionManagement()); toBuild.getModel().setProfiles(project.getModel().getProfiles()); //We want to avoid having the generated stuff wiped. toBuild.getProperties().put("clean.skip", "true"); toBuild.getModel().getBuild().setDirectory(bomDir.getAbsolutePath()); toBuild.getModel().getBuild().setOutputDirectory(new File(bomDir, "target").getAbsolutePath()); for (String key : config.getProperties().stringPropertyNames()) { toBuild.getProperties().put(key, config.getProperties().getProperty(key)); } return toBuild; }
From source file:io.takari.maven.plugins.compile.jdt.ClasspathDigester.java
License:Open Source License
@Inject public ClasspathDigester(MavenProject project, MavenSession session, ClassfileDigester digester) { this.digester = digester; // this is only needed for unit tests, but won't hurt in general CACHE.remove(new File(project.getBuild().getOutputDirectory())); CACHE.remove(new File(project.getBuild().getTestOutputDirectory())); }
From source file:io.takari.maven.plugins.compile.jdt.ClasspathEntryCache.java
License:Open Source License
@Inject public ClasspathEntryCache(MavenProject project) { synchronized (CACHE) { // this is only needed for unit tests, but won't hurt in general CACHE.remove(normalize(new File(project.getBuild().getOutputDirectory()))); CACHE.remove(normalize(new File(project.getBuild().getTestOutputDirectory()))); }// w ww. j av a 2 s . co m }
From source file:io.takari.maven.plugins.jar.Jar.java
License:Open Source License
private Iterable<Entry> jarManifestSource(MavenProject project) throws IOException { Manifest manifest = new Manifest(); Attributes main = manifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Archiver-Version", "Provisio Archiver"); main.putValue("Created-By", "Takari Inc."); main.putValue("Built-By", System.getProperty("user.name")); main.putValue("Build-Jdk", System.getProperty("java.version")); main.putValue("Specification-Title", project.getArtifactId()); main.putValue("Specification-Version", project.getVersion()); main.putValue("Implementation-Title", project.getArtifactId()); main.putValue("Implementation-Version", project.getVersion()); main.putValue("Implementation-Vendor-Id", project.getGroupId()); File manifestFile = new File(project.getBuild().getDirectory(), "MANIFEST.MF"); if (!manifestFile.getParentFile().exists()) { manifestFile.getParentFile().mkdirs(); }//from w w w. java 2 s.c om ByteArrayOutputStream buf = new ByteArrayOutputStream(); manifest.write(buf); return singleton((Entry) new BytesEntry(MANIFEST_PATH, buf.toByteArray())); }
From source file:io.takari.maven.workspace.GenerationsWorkspaceReader.java
License:Apache License
private File find(MavenProject project, Artifact artifact) { File file = null;/* www .j a v a 2 s .com*/ if ("pom".equals(artifact.getExtension())) { return project.getFile(); } // // project = project where we will find artifact, this may be the primary artifact or any of the // secondary artifacts // Artifact projectArtifact = findMatchingArtifact(project, artifact); if (hasArtifactFileFromPackagePhase(projectArtifact)) { // // We have gone far enough in the lifecycle to produce a JAR, WAR, or other file-based artifact // if (isTestArtifact(artifact)) { // // We are looking for a test JAR foo-1.0-test.jar // file = new File(project.getBuild().getDirectory(), String.format("%s-%s-tests.jar", project.getArtifactId(), project.getVersion())); } else { // // We are looking for an application JAR foo-1.0.jar // file = projectArtifact.getFile(); } } else if (!hasBeenPackaged(project)) { // // Here no file has been produced so we fallback to loose class files only if artifacts haven't been packaged yet // and only for plain old jars. Not war files, not ear files, not anything else. // String type = artifact.getProperty("type", ""); if (isTestArtifact(artifact)) { if (project.hasLifecyclePhase("test-compile")) { file = new File(project.getBuild().getTestOutputDirectory()); } } else if (project.hasLifecyclePhase("compile") && COMPILE_PHASE_TYPES.contains(type)) { file = new File(project.getBuild().getOutputDirectory()); } if (file == null && allowArtifactsWithoutAFileToBeResolvedInTheReactor) { // // There is no elegant way to signal that the Artifact's representation is actually present in the // reactor but that it has no file-based representation during this execution and may, in fact, not // require one. The case this accounts for something I am doing with Eclipse project file // generation where I can perform dependency resolution, but cannot run any lifecycle phases. // I need the in-reactor references to work correctly. The WorkspaceReader interface needs // to be changed to account for this. This is not exactly elegant, but it's turned on // with a property and should not interfere. // // We have made a slight change in that we don't want to return "." because it confuses the // compiler plugin for special cases that we have where we are running the compiler in the // process-resources phase. // file = new File(project.getBuild().getOutputDirectory()); //if (file.exists() == false) { // file = new File("."); //} } } // // The fall-through indicates that the artifact cannot be found; // for instance if package produced nothing or classifier problems. // return file; }
From source file:io.takari.maven.workspace.GenerationsWorkspaceReader.java
License:Apache License
private File findWorkspaceArtifact(MavenProject project, Artifact artifact) { File file = null;/*from w w w . ja v a2 s.c o m*/ if ("pom".equals(artifact.getExtension())) { return project.getFile(); } // // project = project where we will find artifact, this may be the primary artifact or any of the // secondary artifacts // Artifact projectArtifact = findMatchingArtifact(project, artifact); if (hasArtifactFileFromPackagePhase(projectArtifact)) { // // We have gone far enough in the lifecycle to produce a JAR, WAR, or other file-based artifact // if (isTestArtifact(artifact)) { // // We are looking for a test JAR foo-1.0-test.jar // file = new File(project.getBuild().getDirectory(), String.format("%s-%s-tests.jar", project.getArtifactId(), project.getVersion())); } else { // // We are looking for an application JAR foo-1.0.jar // file = projectArtifact.getFile(); } } else if (!hasBeenPackaged(project)) { // // Here no file has been produced so we fallback to loose class files only if artifacts haven't been packaged yet // and only for plain old jars. Not war files, not ear files, not anything else. // String type = artifact.getProperty("type", ""); if (isTestArtifact(artifact)) { if (project.hasLifecyclePhase("test-compile")) { file = new File(project.getBuild().getTestOutputDirectory()); } } else if (project.hasLifecyclePhase("compile") && COMPILE_PHASE_TYPES.contains(type)) { file = new File(project.getBuild().getOutputDirectory()); } if (file == null && allowArtifactsWithoutAFileToBeResolvedInTheReactor) { // // There is no elegant way to signal that the Artifact's representation is actually present in the // reactor but that it has no file-based representation during this execution and may, in fact, not // require one. The case this accounts for something I am doing with Eclipse project file // generation where I can perform dependency resolution, but cannot run any lifecycle phases. // I need the in-reactor references to work correctly. The WorkspaceReader interface needs // to be changed to account for this. This is not exactly elegant, but it's turned on // with a property and should not interfere. // /* Turn off resolving for now file = new File(project.getBuild().getOutputDirectory()); if (file.exists() == false) { file = new File("."); } */ } } // // The fall-through indicates that the artifact cannot be found; // for instance if package produced nothing or classifier problems. // return file; }
From source file:io.teecube.t3.GenericReplacerMojo.java
License:Apache License
private void signGPG(MavenProject p) throws MojoExecutionException, MavenInvocationException, MojoFailureException, IOException { InvocationRequest request = getInvocationRequest(p); Invoker invoker = getInvoker(); InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { CommandLineException executionException = result.getExecutionException(); if (executionException != null) { throw new MojoFailureException("Error during project build: " + executionException.getMessage(), executionException); } else {/*from ww w . j a v a 2 s. c o m*/ throw new MojoFailureException("Error during project build: " + result.getExitCode()); } } if (!p.isExecutionRoot() || p.getModel().getModules().isEmpty()) { File gpgTempDirectory = null; try { URL gpgTempDirectoryURL = new URL(request.getProperties().get("url").toString()); gpgTempDirectory = new File(gpgTempDirectoryURL.getFile()); File pomGpgSignature = new File(gpgTempDirectory, p.getGroupId().replaceAll("\\.", "/") + "/" + p.getArtifactId() + "/" + p.getVersion() + "/" + p.getArtifactId() + "-" + p.getVersion() + ".pom.asc"); File gpgSignatureDest = new File(p.getBuild().getDirectory(), pomGpgSignature.getName()); pomGpgSignature = new File(p.getFile().getParentFile(), "pom.xml.asc"); org.apache.commons.io.FileUtils.copyFile(pomGpgSignature, gpgSignatureDest); } finally { if (gpgTempDirectory != null && gpgTempDirectory.exists()) { org.apache.commons.io.FileUtils.deleteDirectory(gpgTempDirectory); } File ascFile = new File(p.getFile().getParentFile(), "pom.xml.asc"); if (ascFile.exists()) { ascFile.delete(); } } } }
From source file:io.treefarm.plugins.haxe.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("io.treefarm.plugins:haxebuildr-maven-plugin"); File pluginHome = initializePluginHome(project, plugin); if (!pluginHome.exists()) pluginHome.mkdirs();//from ww w . j a v a2 s .c o m initializePrograms(project, pluginHome, plugin.getDependencies()); initializeHaxelib(pluginHome); }