List of usage examples for org.apache.maven.project MavenProject getActiveProfiles
public List<Profile> getActiveProfiles()
From source file:com.exentes.maven.versions.VersionMojoUtils.java
License:Apache License
private static Iterable<Dependency> allActiveProfilesDependencyManagement(MavenProject project) { Iterable<Dependency> allDependencies = emptyList(); for (Profile profile : project.getActiveProfiles()) { if (profile.getDependencyManagement() != null) { allDependencies = concat(emptyIfNull(profile.getDependencyManagement().getDependencies()), allDependencies);/*from w w w. j av a 2 s . c om*/ } } return allDependencies; }
From source file:com.exentes.maven.versions.VersionMojoUtils.java
License:Apache License
private static Iterable<Dependency> allActiveProfilesDependencies(MavenProject project) { Iterable<Dependency> allDependencies = emptyList(); for (Profile profile : project.getActiveProfiles()) { allDependencies = concat(emptyIfNull(profile.getDependencies()), allDependencies); }/* w w w .jav a2s. c o m*/ return allDependencies; }
From source file:com.exentes.maven.versions.VersionMojoUtils.java
License:Apache License
public static Map<Object, MavenProject> origins(MavenSession session) { Map<Object, MavenProject> origins = new IdentityHashMap<Object, MavenProject>(); for (MavenProject project : session.getProjects()) { if (project.getOriginalModel().getProperties() != null) { origins.put(project.getOriginalModel().getProperties(), project); }//from w w w .ja v a 2s . co m for (Profile profile : project.getActiveProfiles()) { if (profile.getProperties() != null) { origins.put(profile.getProperties(), project); } } for (Dependency dependency : concat(emptyIfNull(project.getOriginalModel().getDependencies()), dependencyManagement(project), allActiveProfilesDependencies(project), allActiveProfilesDependencyManagement(project))) { origins.put(dependency, project); } } return origins; }
From source file:com.github.maven_nar.NarUtil.java
License:Apache License
/** * (Darren) this code lifted from mvn help:active-profiles plugin Recurses * into the project's parent poms to find the active profiles of the * specified project and all its parents. * //from w ww . ja v a 2 s. com * @param project * The project to start with * @return A list of active profiles */ static List collectActiveProfiles(final MavenProject project) { final List profiles = project.getActiveProfiles(); if (project.hasParent()) { profiles.addAll(collectActiveProfiles(project.getParent())); } return profiles; }
From source file:com.igormaznitsa.jcp.maven.MavenPropertiesImporter.java
License:Apache License
public MavenPropertiesImporter(@Nonnull final PreprocessorContext context, @Nonnull final MavenProject project, final boolean logAddedProperties) { this.project = project; for (final String paramName : TO_IMPORT) { final String varName = "mvn." + paramName.toLowerCase(Locale.ENGLISH); final String value = getProperty(this.project, paramName); addVariableIntoInsideMap(context, varName, Value.valueOf(value), logAddedProperties); }/*from w ww . j a va 2s. c o m*/ // add active profile ids final StringBuilder profileIds = new StringBuilder(); for (final Profile profile : project.getActiveProfiles()) { if (profileIds.length() > 0) { profileIds.append(';'); } profileIds.append(profile.getId()); } addVariableIntoInsideMap(context, "mvn.project.activeprofiles", Value.valueOf(profileIds.toString()), logAddedProperties); // add properties for (final String propertyName : this.project.getProperties().stringPropertyNames()) { final String varName = "mvn.project.property." + propertyName.toLowerCase(Locale.ENGLISH).replace(' ', '_'); final String value = this.project.getProperties().getProperty(propertyName); addVariableIntoInsideMap(context, varName, Value.valueOf(value), logAddedProperties); } }
From source file:com.slim.service.DeployService.java
License:Apache License
/** * /*from w w w . j ava 2s.c om*/ * @param project * @param hostServer * @param hostUser * @param hostPassword * @param tibcoDomain * @param tibcoUser * @param tibcoPassword * @param outputDirectory * @param remoteDirectory * @throws MojoExecutionException */ public void deploy(MavenProject project, String hostServer, String hostUser, String hostPassword, String tibcoDomain, String tibcoUser, String tibcoPassword, String outputDirectory, String remoteDirectory, String appLocation, Log logger) throws MojoExecutionException { // TODO Check parameter try { String appTibco = appLocation == null || appLocation.trim().length() == 0 ? project.getArtifact().getArtifactId() : appLocation; String remotePath = remoteDirectory + "/" + appTibco; // Extrait le profil maven actuel String environnement = null; if (project.getActiveProfiles().size() > 0) { environnement = ((Profile) project.getActiveProfiles().get(0)).getId(); } else { environnement = CommandUtils.DFT; ; } String localEarFile = project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_EAR; String localXmlFile = project.getBasedir().toString() + "\\" + outputDirectory + "\\" + environnement + "\\" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_XML; String remoteEarFile = remotePath + "/" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_EAR; String remoteXmlFile = remotePath + "/" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_XML; SSHClientUtils sshclient = new SSHClientUtils(hostServer, hostUser, hostPassword, logger); logger.info("Creating directory " + remotePath + " ..."); sshclient.sendShell("mkdir -p " + remotePath, remoteDirectory); logger.info("Moving " + localEarFile + " to " + remoteEarFile + " ..."); sshclient.sendFile(localEarFile, remoteEarFile); logger.info("Moving " + localXmlFile + " to " + remoteXmlFile + " ..."); sshclient.sendFile(localXmlFile, remoteXmlFile); StringBuilder commandDeploy = new StringBuilder(); commandDeploy.append(CommandUtils.getRemoteAppManageBin()).append(" -deploy"); commandDeploy.append(" -ear ").append(remoteEarFile); commandDeploy.append(" -deployconfig ").append(remoteXmlFile); commandDeploy.append(" -app ").append(appTibco); commandDeploy.append(" -domain ").append(tibcoDomain); commandDeploy.append(" -user ").append(tibcoUser); commandDeploy.append(" -pw ").append(tibcoPassword); logger.info("Executing " + commandDeploy.toString() + " ..."); sshclient.sendShell(commandDeploy.toString(), remoteDirectory); } catch (Exception e) { e.printStackTrace(); throw new MojoExecutionException("Error in deploying ear ..." + e.getMessage()); } }
From source file:com.slim.service.ReplaceService.java
License:Apache License
/** * //from w w w.j av a 2 s. c o m * @param doc * @throws TransformerFactoryConfigurationError * @throws TransformerConfigurationException * @throws TransformerException */ private void createFile(Document doc, String outputDirectory, MavenProject project, Log logger) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException { // Extrait le profil maven actuel String environnement = null; if (project.getActiveProfiles().size() > 0) { environnement = ((Profile) project.getActiveProfiles().get(0)).getId(); } else { environnement = CommandUtils.DFT; } // Write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); CommandUtils.createDirectoryIfNeeded( project.getBasedir().toString() + "\\" + outputDirectory + "\\" + environnement, logger); StreamResult result = new StreamResult(new File(project.getBasedir().toString() + "\\" + outputDirectory + "\\" + environnement + "\\" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_XML)); transformer.transform(source, result); }
From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.pom.GenerateRootDeploymentPOM.java
License:Apache License
@SuppressWarnings("unchecked") private List<Profile> getActiveProfiles(List<MavenProject> projects) { List<Profile> result = new ArrayList<Profile>(); for (MavenProject project : projects) { result.addAll(project.getActiveProfiles()); }/*from w ww. j a v a 2s . c o m*/ return result; }
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 ww. java 2 s . 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:kr.motd.maven.os.DetectExtension.java
License:Apache License
private void interpolate(Map<String, String> dict, MavenProject p) { if (p == null) { return;//from w ww. ja v a2s.c o m } interpolate(dict, p.getParent()); interpolate(dict, p.getModel()); for (ModelBase model : p.getActiveProfiles()) { interpolate(dict, model); } }