List of usage examples for org.apache.maven.execution MavenSession getSettings
public Settings getSettings()
From source file:com.github.shyiko.sme.ServersExtension.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { MojoExecution mojoExecution = new MojoExecution(new MojoDescriptor()); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); Properties userProperties = session.getUserProperties(); boolean exportAsSysProp = isExtensionProperty(session, "servers.exportAsSysProp"); Map<String, String> properties = new HashMap<String, String>(); try {//from ww w.ja v a2s. co m for (Server server : session.getSettings().getServers()) { String serverId = server.getId(); for (String field : FIELDS) { String[] aliases = getAliases(serverId, field); String fieldNameWithFirstLetterCapitalized = upperCaseFirstLetter(field); String fieldValue = (String) Server.class.getMethod("get" + fieldNameWithFirstLetterCapitalized) .invoke(server); if (fieldValue != null) { fieldValue = decryptInlinePasswords(fieldValue); } for (String alias : aliases) { String userPropertyValue = userProperties.getProperty(alias); if (userPropertyValue != null) { fieldValue = userPropertyValue; break; } } String resolvedValue = (String) expressionEvaluator.evaluate(fieldValue); Server.class .getMethod("set" + fieldNameWithFirstLetterCapitalized, new Class[] { String.class }) .invoke(server, resolvedValue); if (resolvedValue != null) { for (String alias : aliases) { properties.put(alias, resolvedValue); } } } } if (exportAsSysProp) { System.getProperties().putAll(properties); } else { for (MavenProject project : session.getProjects()) { Properties projectProperties = project.getProperties(); projectProperties.putAll(properties); } } } catch (Exception e) { throw new MavenExecutionException("Failed to expose settings.servers.*", e); } }
From source file:fr.fastconnect.factory.tibco.bw.maven.AbstractBWMojo.java
License:Apache License
/** * <p>/*from ww w. jav a 2 s. co m*/ * Instantiate a minimalistic {@link AbstractCommonMojo} to use properties * management as a standalone object. * </p> * * @param session * @param mavenProject * @return */ public static AbstractBWMojo propertiesManager(MavenSession session, MavenProject mavenProject) { AbstractBWMojo mojo = new AbstractBWMojo(); mojo.setProject(mavenProject); mojo.setSession(session); mojo.setSettings(session.getSettings()); return mojo; }
From source file:info.ronjenkins.maven.rtr.steps.release.AbstractSmartReactorReleaseStep.java
License:Apache License
/** * Step logic that is executed if a release was requested. * * @param session/*from www .j a v a2 s .com*/ * the session to which this step applies. Not null. * @param components * that this step may need. May be null. * @throws MavenExecutionException * if any unrecoverable error occurs. */ protected void releaseExecute(final MavenSession session, final RTRComponents components) throws MavenExecutionException { this.releaseEnvironment.setSettings(session.getSettings()); final List<MavenProject> reactor = session.getProjects(); // Execute the release steps. try { this.runPhases(reactor, this.getReleasePhases()); } catch (final MavenExecutionException | RuntimeException e) { // Rollback if ANY exception occurred, then rethrow. this.logger.error("Rolling back release due to error..."); try { this.runPhases(reactor, this.getRollbackPhases()); } catch (final MavenExecutionException | RuntimeException e2) { // Suppress this exception. e.addSuppressed(e2); this.logger.error( "Rollback unsuccessful. Check project filesystem for POM backups and other resources that must be rolled back manually."); } throw e; } }
From source file:io.wcm.devops.conga.plugins.aem.maven.ProxySupport.java
License:Apache License
static List<io.wcm.tooling.commons.packmgr.Proxy> getMavenProxies(MavenSession mavenSession, SettingsDecrypter decrypter) {//from w w w. j a v a 2s .c o m if (mavenSession == null || mavenSession.getSettings() == null || mavenSession.getSettings().getProxies() == null || mavenSession.getSettings().getProxies().isEmpty()) { return Collections.emptyList(); } else { final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies(); final List<io.wcm.tooling.commons.packmgr.Proxy> proxies = new ArrayList<>(mavenProxies.size()); for (Proxy mavenProxy : mavenProxies) { if (mavenProxy.isActive()) { Proxy decryptedMavenProxy = decryptProxy(mavenProxy, decrypter); proxies.add(new io.wcm.tooling.commons.packmgr.Proxy(decryptedMavenProxy.getId(), decryptedMavenProxy.getProtocol(), decryptedMavenProxy.getHost(), decryptedMavenProxy.getPort(), decryptedMavenProxy.getUsername(), decryptedMavenProxy.getPassword(), decryptedMavenProxy.getNonProxyHosts())); } } return proxies; } }
From source file:org.apache.sling.maven.projectsupport.BundleListUtils.java
License:Apache License
public static Interpolator createInterpolator(MavenProject project, MavenSession mavenSession) { StringSearchInterpolator interpolator = new StringSearchInterpolator(); final Properties props = new Properties(); props.putAll(project.getProperties()); props.putAll(mavenSession.getSystemProperties()); props.putAll(mavenSession.getUserProperties()); interpolator.addValueSource(new PropertiesBasedValueSource(props)); // add ${project.foo} interpolator.addValueSource(new PrefixedObjectValueSource(Arrays.asList("project", "pom"), project, true)); // add ${session.foo} interpolator.addValueSource(new PrefixedObjectValueSource("session", mavenSession)); // add ${settings.foo} final Settings settings = mavenSession.getSettings(); if (settings != null) { interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings)); }/*w w w . j a va 2s . c om*/ return interpolator; }
From source file:org.debian.dependency.DefaultDependencyCollection.java
License:Apache License
private Artifact resolveArtifact(final Artifact toResolve, final MavenSession session) throws DependencyResolutionException { // otherwise resolve through the normal means ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setLocalRepository(session.getLocalRepository()) .setRemoteRepositories(session.getRequest().getRemoteRepositories()) .setMirrors(session.getSettings().getMirrors()).setServers(session.getRequest().getServers()) .setProxies(session.getRequest().getProxies()).setOffline(session.isOffline()) .setForceUpdate(session.getRequest().isUpdateSnapshots()).setResolveRoot(true) .setArtifact(toResolve);/*from w ww . j av a 2 s . c o m*/ ArtifactResolutionResult result = repositorySystem.resolve(request); if (!result.isSuccess()) { if (result.getExceptions() != null) { for (Exception exception : result.getExceptions()) { getLogger().error("Error resolving artifact " + toResolve, exception); } } throw new DependencyResolutionException("Unable to resolve artifact " + toResolve); } return result.getArtifacts().iterator().next(); }
From source file:org.debian.dependency.sources.SCMSourceRetrieval.java
License:Apache License
@Override public String retrieveSource(final Artifact artifact, final File directory, final MavenSession session) throws SourceRetrievalException { MavenProject project = findProjectRoot(constructProject(artifact, session)); Scm scm = project.getScm();//w w w. j a v a 2 s. c o m if (scm == null) { return null; } SettingsDecryptionResult decryptionResult = settingsDecrypter .decrypt(new DefaultSettingsDecryptionRequest(session.getSettings())); for (SettingsProblem problem : decryptionResult.getProblems()) { getLogger().warn("Error decrypting settings (" + problem.getLocation() + ") : " + problem.getMessage(), problem.getException()); } try { // first we check developer connection CheckOutScmResult checkoutResult = null; String connection = scm.getDeveloperConnection(); try { checkoutResult = performCheckout(connection, determineVersion(scm), directory, decryptionResult.getServers()); } catch (ScmException e) { // we don't really care about the exception here because we will try the regular connection next getLogger().debug( "Unable to checkout sources using developer connection, trying standard connection", e); } // now the regular connection if it wasn't successful if (checkoutResult == null || !checkoutResult.isSuccess()) { connection = scm.getConnection(); checkoutResult = performCheckout(connection, determineVersion(scm), directory, decryptionResult.getServers()); } if (checkoutResult == null) { throw new SourceRetrievalException("No scm information available"); } else if (!checkoutResult.isSuccess()) { getLogger().error("Provider Message:"); getLogger().error(StringUtils.defaultString(checkoutResult.getProviderMessage())); getLogger().error("Commandline:"); getLogger().error(StringUtils.defaultString(checkoutResult.getCommandOutput())); throw new SourceRetrievalException("Unable to checkout files: " + StringUtils.defaultString(checkoutResult.getProviderMessage())); } return connection; } catch (ScmException e) { throw new SourceRetrievalException("Unable to checkout project", e); } }
From source file:org.eclipse.tycho.core.maven.TychoInterpolator.java
License:Open Source License
public TychoInterpolator(MavenSession mavenSession, MavenProject mavenProject) { final Properties baseProps = new Properties(); // The order how the properties been added is important! // It defines which properties win over others // (session user properties overwrite system properties overwrite project properties) baseProps.putAll(mavenProject.getProperties()); baseProps.putAll(mavenSession.getSystemProperties()); baseProps.putAll(mavenSession.getUserProperties()); final Settings settings = mavenSession.getSettings(); // roughly match resources plugin behaviour // Using the project and settings as object value source to get things replaces like // ${project.artifactId}...; // Simple string replacement for ${localRepository}, ${version}, ${basedir}; // An and string replacement for all property values // (session user properties, system properties, project properties). interpolator = new StringSearchInterpolator(); interpolator.addValueSource(new PrefixedObjectValueSource("project", mavenProject)); interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings)); interpolator/*from w w w. ja va 2s .c o m*/ .addValueSource(new SingleResponseValueSource("localRepository", settings.getLocalRepository())); interpolator.addValueSource(new SingleResponseValueSource("version", mavenProject.getVersion())); interpolator.addValueSource( new SingleResponseValueSource("basedir", mavenProject.getBasedir().getAbsolutePath())); interpolator.addValueSource(new ValueSource() { @Override public Object getValue(String expression) { return baseProps.getProperty(expression); } @Override public void clearFeedback() { } @Override @SuppressWarnings("rawtypes") public List getFeedback() { return Collections.EMPTY_LIST; } }); }
From source file:org.eclipse.tycho.osgi.configuration.OSGiProxyConfigurator.java
License:Open Source License
@Override public void afterFrameworkStarted(EmbeddedEquinox framework) { MavenSession session = context.getSession(); ProxyServiceFacade proxyService = framework.getServiceFactory().getService(ProxyServiceFacade.class); // make sure there is no old state from previous aborted builds clearProxyConfiguration(proxyService); for (Proxy proxy : session.getSettings().getProxies()) { if (proxy.isActive()) { setProxy(proxyService, proxy); }/*from www. j a va2s .c o m*/ } }
From source file:org.eclipse.tycho.osgi.configuration.P2ProxyConfigurator.java
License:Open Source License
@Override public void afterFrameworkStarted(EmbeddedEquinox framework) { MavenSession session = context.getSession(); final List<Proxy> activeProxies = new ArrayList<Proxy>(); for (Proxy proxy : session.getSettings().getProxies()) { if (proxy.isActive()) { activeProxies.add(proxy);//from w w w .j a v a 2 s .co m } } ProxyServiceFacade proxyService = framework.getServiceFactory().getService(ProxyServiceFacade.class); // make sure there is no old state from previous aborted builds logger.debug("clear OSGi proxy settings"); proxyService.clearPersistentProxySettings(); for (Proxy proxy : activeProxies) { logger.debug("Configure OSGi proxy for protocol " + proxy.getProtocol() + ", host: " + proxy.getHost() + ", port: " + proxy.getPort() + ", nonProxyHosts: " + proxy.getNonProxyHosts()); proxyService.configureProxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts()); } }