List of usage examples for org.apache.maven.project MavenProject getAttachedArtifacts
public List<Artifact> getAttachedArtifacts()
From source file:hudson.plugins.deploy.MuleApplicationTracker.java
License:Apache License
@Override public boolean postBuild(final MavenBuildProxy build, final MavenProject project, final BuildListener listener) throws InterruptedException, IOException { if (project.getArtifact() == null || !"mule".equals(project.getArtifact().getType())) { return true; }//from w w w. j av a 2 s .c om if (project.getAttachedArtifacts() != null && !project.getAttachedArtifacts().isEmpty()) { //Record the mule application File as an Action final String filePath = project.getAttachedArtifacts().get(0).getFile().getPath(); build.execute(new MavenBuildProxy.BuildCallable<Void, IOException>() { @Override public Void call(final MavenBuild build) throws IOException, InterruptedException { //Mule packaging type attach mule application file first build.addAction(new MuleApplicationAction(filePath)); build.save(); return null; } }); } return true; }
From source file:io.fabric8.maven.CreateProfileZipMojo.java
License:Apache License
protected void generateAggregatedZip(MavenProject rootProject, List<MavenProject> reactorProjects, List<MavenProject> pomZipProjects) throws IOException, MojoExecutionException { File projectBaseDir = rootProject.getBasedir(); File projectOutputFile = new File(projectBaseDir, "target/profile.zip"); getLog().info("Generating " + projectOutputFile.getAbsolutePath() + " from root project " + rootProject.getArtifactId()); File projectBuildDir = new File(projectBaseDir, reactorProjectOutputPath); createAggregatedZip(reactorProjects, projectBaseDir, projectBuildDir, reactorProjectOutputPath, projectOutputFile, includeReadMe, pomZipProjects); if (rootProject.getAttachedArtifacts() != null) { // need to remove existing as otherwise we get a WARN Artifact found = null;// w w w .ja v a 2 s .c o m for (Artifact artifact : rootProject.getAttachedArtifacts()) { if (artifactClassifier != null && artifact.hasClassifier() && artifact.getClassifier().equals(artifactClassifier)) { found = artifact; break; } } if (found != null) { rootProject.getAttachedArtifacts().remove(found); } } getLog().info("Attaching aggregated zip " + projectOutputFile + " to root project " + rootProject.getArtifactId()); projectHelper.attachArtifact(rootProject, artifactType, artifactClassifier, projectOutputFile); // if we are doing an install goal, then also install the aggregated zip manually // as maven will install the root project first, and then build the reactor projects, and at this point // it does not help to attach artifact to root project, as those artifacts will not be installed // so we need to install manually if (rootProject.hasLifecyclePhase("install")) { getLog().info("Installing aggregated zip " + projectOutputFile); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory(rootProject.getBasedir()); request.setPomFile(new File("./pom.xml")); request.setGoals(Collections.singletonList("install:install-file")); request.setRecursive(false); request.setInteractive(false); Properties props = new Properties(); props.setProperty("file", "target/profile.zip"); props.setProperty("groupId", rootProject.getGroupId()); props.setProperty("artifactId", rootProject.getArtifactId()); props.setProperty("version", rootProject.getVersion()); props.setProperty("classifier", "profile"); props.setProperty("packaging", "zip"); request.setProperties(props); getLog().info( "Installing aggregated zip using: mvn install:install-file" + serializeMvnProperties(props)); Invoker invoker = new DefaultInvoker(); try { InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new IllegalStateException("Error invoking Maven goal install:install-file"); } } catch (MavenInvocationException e) { throw new MojoExecutionException("Error invoking Maven goal install:install-file", e); } } }
From source file:io.fabric8.maven.ZipMojo.java
License:Apache License
protected void generateAggregatedZip(MavenProject rootProject, List<MavenProject> reactorProjects, Set<MavenProject> pomZipProjects) throws IOException, MojoExecutionException { File projectBaseDir = rootProject.getBasedir(); String rootProjectGroupId = rootProject.getGroupId(); String rootProjectArtifactId = rootProject.getArtifactId(); String rootProjectVersion = rootProject.getVersion(); String aggregatedZipFileName = "target/" + rootProjectArtifactId + "-" + rootProjectVersion + "-app.zip"; File projectOutputFile = new File(projectBaseDir, aggregatedZipFileName); getLog().info("Generating " + projectOutputFile.getAbsolutePath() + " from root project " + rootProjectArtifactId);/*from w w w . ja v a2s .c o m*/ File projectBuildDir = new File(projectBaseDir, reactorProjectOutputPath); if (projectOutputFile.exists()) { projectOutputFile.delete(); } createAggregatedZip(projectBaseDir, projectBuildDir, reactorProjectOutputPath, projectOutputFile, includeReadMe, pomZipProjects); if (rootProject.getAttachedArtifacts() != null) { // need to remove existing as otherwise we get a WARN Artifact found = null; for (Artifact artifact : rootProject.getAttachedArtifacts()) { if (artifactClassifier != null && artifact.hasClassifier() && artifact.getClassifier().equals(artifactClassifier)) { found = artifact; break; } } if (found != null) { rootProject.getAttachedArtifacts().remove(found); } } getLog().info("Attaching aggregated zip " + projectOutputFile + " to root project " + rootProject.getArtifactId()); projectHelper.attachArtifact(rootProject, artifactType, artifactClassifier, projectOutputFile); // if we are doing an install goal, then also install the aggregated zip manually // as maven will install the root project first, and then build the reactor projects, and at this point // it does not help to attach artifact to root project, as those artifacts will not be installed // so we need to install manually List<String> activeProfileIds = new ArrayList<>(); List<Profile> activeProfiles = rootProject.getActiveProfiles(); if (activeProfiles != null) { for (Profile profile : activeProfiles) { String id = profile.getId(); if (Strings.isNotBlank(id)) { activeProfileIds.add(id); } } } if (rootProject.hasLifecyclePhase("install")) { getLog().info("Installing aggregated zip " + projectOutputFile); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory(rootProject.getBasedir()); request.setPomFile(new File("./pom.xml")); request.setGoals(Collections.singletonList("install:install-file")); request.setRecursive(false); request.setInteractive(false); request.setProfiles(activeProfileIds); Properties props = new Properties(); props.setProperty("file", aggregatedZipFileName); props.setProperty("groupId", rootProjectGroupId); props.setProperty("artifactId", rootProjectArtifactId); props.setProperty("version", rootProjectVersion); props.setProperty("classifier", "app"); props.setProperty("packaging", "zip"); props.setProperty("generatePom", "false"); request.setProperties(props); getLog().info( "Installing aggregated zip using: mvn install:install-file" + serializeMvnProperties(props)); Invoker invoker = new DefaultInvoker(); try { InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new IllegalStateException("Error invoking Maven goal install:install-file"); } } catch (MavenInvocationException e) { throw new MojoExecutionException("Error invoking Maven goal install:install-file", e); } } if (rootProject.hasLifecyclePhase("deploy")) { if (deploymentRepository == null && Strings.isNullOrBlank(altDeploymentRepository)) { String msg = "Cannot run deploy phase as Maven project has no <distributionManagement> with the maven url to use for deploying the aggregated zip file, neither an altDeploymentRepository property."; getLog().warn(msg); throw new MojoExecutionException(msg); } getLog().info("Deploying aggregated zip " + projectOutputFile + " to root project " + rootProject.getArtifactId()); getLog().info("Using deploy goal: " + deployFileGoal + " with active profiles: " + activeProfileIds); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory(rootProject.getBasedir()); request.setPomFile(new File("./pom.xml")); request.setGoals(Collections.singletonList(deployFileGoal)); request.setRecursive(false); request.setInteractive(false); request.setProfiles(activeProfileIds); request.setProperties(getProjectAndFabric8Properties(getProject())); Properties props = new Properties(); props.setProperty("file", aggregatedZipFileName); props.setProperty("groupId", rootProjectGroupId); props.setProperty("artifactId", rootProjectArtifactId); props.setProperty("version", rootProjectVersion); props.setProperty("classifier", "app"); props.setProperty("packaging", "zip"); String deployUrl = null; if (!Strings.isNullOrBlank(deployFileUrl)) { deployUrl = deployFileUrl; } else if (altDeploymentRepository != null && altDeploymentRepository.contains("::")) { deployUrl = altDeploymentRepository.substring(altDeploymentRepository.lastIndexOf("::") + 2); } else { deployUrl = deploymentRepository.getUrl(); } props.setProperty("url", deployUrl); props.setProperty("repositoryId", deploymentRepository.getId()); props.setProperty("generatePom", "false"); request.setProperties(props); getLog().info("Deploying aggregated zip using: mvn deploy:deploy-file" + serializeMvnProperties(props)); Invoker invoker = new DefaultInvoker(); try { InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new IllegalStateException("Error invoking Maven goal deploy:deploy-file"); } } catch (MavenInvocationException e) { throw new MojoExecutionException("Error invoking Maven goal deploy:deploy-file", e); } } }
From source file:io.takari.maven.plugins.Deploy.java
License:Open Source License
private void installProject(MavenProject project) throws MojoExecutionException { DeployRequest deployRequest = new DeployRequest(); if ("pom".equals(project.getPackaging())) { //// w ww . j av a 2 s.co m // POM-project primary artifact // Artifact artifact = AetherUtils.toArtifact(project.getArtifact()); artifact = artifact.setFile(project.getFile()); deployRequest.addArtifact(artifact); } else { // // Primary artifact // Artifact artifact = AetherUtils.toArtifact(project.getArtifact()); deployRequest.addArtifact(artifact); // // POM // Artifact pomArtifact = new SubArtifact(artifact, "", "pom"); pomArtifact = pomArtifact.setFile(project.getFile()); deployRequest.addArtifact(pomArtifact); } // // Attached artifacts // for (org.apache.maven.artifact.Artifact attachedArtifact : project.getAttachedArtifacts()) { deployRequest.addArtifact(AetherUtils.toArtifact(attachedArtifact)); } deployRequest.setRepository(remoteRepository(project)); try { repositorySystem.deploy(repositorySystemSession, deployRequest); } catch (DeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:io.takari.maven.plugins.Install.java
License:Open Source License
private void installProject(MavenProject project) throws MojoExecutionException { InstallRequest installRequest = new InstallRequest(); if ("pom".equals(project.getPackaging())) { ///*from www .java2s . c om*/ // POM-project primary artifact // Artifact artifact = AetherUtils.toArtifact(project.getArtifact()); artifact = artifact.setFile(project.getFile()); installRequest.addArtifact(artifact); } else { // // Primary artifact // Artifact artifact = AetherUtils.toArtifact(project.getArtifact()); installRequest.addArtifact(artifact); // // POM // Artifact pomArtifact = new SubArtifact(artifact, "", "pom"); pomArtifact = pomArtifact.setFile(project.getFile()); installRequest.addArtifact(pomArtifact); } // // Attached artifacts // for (org.apache.maven.artifact.Artifact attachedArtifact : project.getAttachedArtifacts()) { installRequest.addArtifact(AetherUtils.toArtifact(attachedArtifact)); } try { repositorySystem.install(repositorySystemSession, installRequest); } catch (InstallationException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:io.takari.maven.workspace.GenerationsWorkspaceReader.java
License:Apache License
private Artifact findMatchingArtifact(MavenProject project, Artifact requestedArtifact) { String versionlessId = ArtifactIdUtils.toVersionlessId(requestedArtifact); Artifact mainArtifact = RepositoryUtils.toArtifact(project.getArtifact()); if (versionlessId.equals(ArtifactIdUtils.toVersionlessId(mainArtifact))) { return mainArtifact; }/*from w ww . j a v a 2 s. c o m*/ for (Artifact attachedArtifact : RepositoryUtils.toArtifacts(project.getAttachedArtifacts())) { if (attachedArtifactComparison(requestedArtifact, attachedArtifact)) { return attachedArtifact; } } return null; }
From source file:net.oneandone.maven.plugins.billofmaterials.CreateBillOfMaterialsMojo.java
License:Apache License
/** * Creates a list of all artifacts for the build. * @return a list of all artifacts for the build including the attached ones. *//*www. ja v a 2 s. c o m*/ final List<File> getListOfArtifactsAsFiles() { final MavenProject project = getProject(); final List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); // We need a copy here as otherwise install and deploy will choke later on because // we attach the POM as well. final List<File> files = new ArrayList<>( Collections2.filter(Lists.transform(attachedArtifacts, toFileFunction), Files.isFile())); final String packaging = project.getPackaging(); // POMs return null as their artifact, which will crash the transformation lateron. if (!"pom".equals(packaging)) { files.add(project.getArtifact().getFile()); } return files; }
From source file:org.apache.axis2.maven2.repo.AbstractCreateRepositoryMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { Set<Artifact> artifacts = new HashSet<Artifact>(); if (useDependencies) { artifacts.addAll(projectArtifacts); }//from w ww . j a va2 s . co m if (useModules) { for (MavenProject project : collectedProjects) { artifacts.add(project.getArtifact()); artifacts.addAll(project.getAttachedArtifacts()); } } File outputDirectory = getOutputDirectory(); if (includeModules || includeServices) { FilterArtifacts filter = new FilterArtifacts(); filter.addFilter(new ScopeFilter(getScope(), null)); if (includeModules && includeServices) { filter.addFilter(new TypeFilter("aar,mar", null)); } else if (includeModules) { filter.addFilter(new TypeFilter("mar", null)); } try { artifacts = filter.filter(artifacts); } catch (ArtifactFilterException ex) { throw new MojoExecutionException(ex.getMessage(), ex); } selectArtifacts(artifacts, modules, "mar"); selectArtifacts(artifacts, services, "aar"); artifacts = replaceIncompleteArtifacts(artifacts); Map<String, ArchiveDeployer> deployers = new HashMap<String, ArchiveDeployer>(); deployers.put("aar", new ArchiveDeployer(outputDirectory, servicesDirectory, "services.list", generateFileLists, stripServiceVersion)); deployers.put("mar", new ArchiveDeployer(outputDirectory, modulesDirectory, "modules.list", generateFileLists, stripModuleVersion)); for (Artifact artifact : artifacts) { String type = artifact.getType(); ArchiveDeployer deployer = deployers.get(type); if (deployer == null) { throw new MojoExecutionException("No deployer found for artifact type " + type); } deployer.deploy(getLog(), artifact); } for (ArchiveDeployer deployer : deployers.values()) { deployer.finish(getLog()); } } if (axis2xml != null) { getLog().info("Copying axis2.xml"); File targetDirectory = configurationDirectory == null ? outputDirectory : new File(outputDirectory, configurationDirectory); try { FileUtils.copyFile(axis2xml, new File(targetDirectory, "axis2.xml")); } catch (IOException ex) { throw new MojoExecutionException("Error copying axis2.xml file: " + ex.getMessage(), ex); } } }
From source file:org.apache.cxf.maven_plugin.AbstractCodegenMoho.java
License:Apache License
private Artifact resolveAttachedWsdl(Artifact artifact) { List<MavenProject> rProjects = mavenSession.getProjects(); List<Artifact> artifactList = new ArrayList<>(); for (MavenProject rProject : rProjects) { List<Artifact> list = CastUtils.cast(rProject.getAttachedArtifacts()); if (list != null) { artifactList.addAll(list);//from w w w . j a v a 2 s . c o m } } return findWsdlArtifact(artifact, artifactList); }
From source file:org.apache.karaf.tooling.RunMojo.java
License:Apache License
private File getAttachedFeatureFile(MavenProject project) { List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); for (Artifact artifact : attachedArtifacts) { if ("features".equals(artifact.getClassifier()) && "xml".equals(artifact.getType())) { return artifact.getFile(); }//from ww w . j av a2 s .c om } return null; }