List of usage examples for org.apache.maven.cli.configuration SettingsXmlConfigurationProcessor DEFAULT_USER_SETTINGS_FILE
File DEFAULT_USER_SETTINGS_FILE
To view the source code for org.apache.maven.cli.configuration SettingsXmlConfigurationProcessor DEFAULT_USER_SETTINGS_FILE.
Click Source Link
From source file:com.liferay.ide.maven.core.NewMavenPluginProjectProvider.java
License:Open Source License
@Override public IStatus createNewProject(NewLiferayPluginProjectOp op, IProgressMonitor monitor) throws CoreException { ElementList<ProjectName> projectNames = op.getProjectNames(); IStatus retval = null;//from w w w . j a v a2 s. c o m final IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration(); final IMavenProjectRegistry mavenProjectRegistry = MavenPlugin.getMavenProjectRegistry(); final IProjectConfigurationManager projectConfigurationManager = MavenPlugin .getProjectConfigurationManager(); final String groupId = op.getGroupId().content(); final String artifactId = op.getProjectName().content(); final String version = op.getArtifactVersion().content(); final String javaPackage = op.getGroupId().content(); final String activeProfilesValue = op.getActiveProfilesValue().content(); final IPortletFramework portletFramework = op.getPortletFramework().content(true); final String frameworkName = NewLiferayPluginProjectOpMethods.getFrameworkName(op); IPath location = PathBridge.create(op.getLocation().content()); // for location we should use the parent location if (location.lastSegment().equals(artifactId)) { // use parent dir since maven archetype will generate new dir under this location location = location.removeLastSegments(1); } final String archetypeArtifactId = op.getArchetype().content(true); final Archetype archetype = new Archetype(); final String[] gav = archetypeArtifactId.split(":"); final String archetypeVersion = gav[gav.length - 1]; archetype.setGroupId(gav[0]); archetype.setArtifactId(gav[1]); archetype.setVersion(archetypeVersion); final ArchetypeManager archetypeManager = MavenPluginActivator.getDefault().getArchetypeManager(); final ArtifactRepository remoteArchetypeRepository = archetypeManager.getArchetypeRepository(archetype); final Properties properties = new Properties(); try { final List<?> archProps = archetypeManager.getRequiredProperties(archetype, remoteArchetypeRepository, monitor); if (!CoreUtil.isNullOrEmpty(archProps)) { for (Object prop : archProps) { if (prop instanceof RequiredProperty) { final RequiredProperty rProp = (RequiredProperty) prop; if (op.getPluginType().content().equals(PluginType.theme)) { final String key = rProp.getKey(); if (key.equals("themeParent")) { properties.put(key, op.getThemeParent().content(true)); } else if (key.equals("themeType")) { properties.put(key, ThemeUtil.getTemplateExtension(op.getThemeFramework().content(true))); } } else { properties.put(rProp.getKey(), rProp.getDefaultValue()); } } } } } catch (UnknownArchetype e1) { LiferayMavenCore.logError("Unable to find archetype required properties", e1); } final ResolverConfiguration resolverConfig = new ResolverConfiguration(); if (!CoreUtil.isNullOrEmpty(activeProfilesValue)) { resolverConfig.setSelectedProfiles(activeProfilesValue); } final ProjectImportConfiguration configuration = new ProjectImportConfiguration(resolverConfig); final List<IProject> newProjects = projectConfigurationManager.createArchetypeProjects(location, archetype, groupId, artifactId, version, javaPackage, properties, configuration, monitor); if (!CoreUtil.isNullOrEmpty(newProjects)) { op.setImportProjectStatus(true); for (IProject project : newProjects) { projectNames.insert().setName(project.getName()); } } if (CoreUtil.isNullOrEmpty(newProjects)) { retval = LiferayMavenCore.createErrorStatus("New project was not created due to unknown error"); } else { final IProject firstProject = newProjects.get(0); // add new profiles if it was specified to add to project or parent poms if (!CoreUtil.isNullOrEmpty(activeProfilesValue)) { final String[] activeProfiles = activeProfilesValue.split(","); // find all profiles that should go in user settings file final List<NewLiferayProfile> newUserSettingsProfiles = getNewProfilesToSave(activeProfiles, op.getNewLiferayProfiles(), ProfileLocation.userSettings); if (newUserSettingsProfiles.size() > 0) { final String userSettingsFile = mavenConfiguration.getUserSettingsFile(); String userSettingsPath = null; if (CoreUtil.isNullOrEmpty(userSettingsFile)) { userSettingsPath = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE .getAbsolutePath(); } else { userSettingsPath = userSettingsFile; } try { // backup user's settings.xml file final File settingsXmlFile = new File(userSettingsPath); final File backupFile = getBackupFile(settingsXmlFile); FileUtils.copyFile(settingsXmlFile, backupFile); final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); final Document pomDocument = docBuilder.parse(settingsXmlFile.getCanonicalPath()); for (NewLiferayProfile newProfile : newUserSettingsProfiles) { MavenUtil.createNewLiferayProfileNode(pomDocument, newProfile); } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(pomDocument); StreamResult result = new StreamResult(settingsXmlFile); transformer.transform(source, result); } catch (Exception e) { LiferayMavenCore.logError("Unable to save new Liferay profile to user settings.xml.", e); } } // find all profiles that should go in the project pom final List<NewLiferayProfile> newProjectPomProfiles = getNewProfilesToSave(activeProfiles, op.getNewLiferayProfiles(), ProfileLocation.projectPom); // only need to set the first project as nested projects should pickup the parent setting final IMavenProjectFacade newMavenProject = mavenProjectRegistry.getProject(firstProject); final IFile pomFile = newMavenProject.getPom(); IDOMModel domModel = null; try { domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(pomFile); for (final NewLiferayProfile newProfile : newProjectPomProfiles) { MavenUtil.createNewLiferayProfileNode(domModel.getDocument(), newProfile); } domModel.save(); } catch (IOException e) { LiferayMavenCore.logError("Unable to save new Liferay profiles to project pom.", e); } finally { if (domModel != null) { domModel.releaseFromEdit(); } } for (final IProject project : newProjects) { try { projectConfigurationManager.updateProjectConfiguration( new MavenUpdateRequest(project, mavenConfiguration.isOffline(), true), monitor); } catch (Exception e) { LiferayMavenCore.logError("Unable to update configuration for " + project.getName(), e); } } final String pluginVersion = getNewLiferayProfilesPluginVersion(activeProfiles, op.getNewLiferayProfiles(), archetypeVersion); final String archVersion = MavenUtil.getMajorMinorVersionOnly(archetypeVersion); updateDtdVersion(firstProject, pluginVersion, archVersion); } if (op.getPluginType().content().equals(PluginType.portlet)) { final String portletName = op.getPortletName().content(false); retval = portletFramework.postProjectCreated(firstProject, frameworkName, portletName, monitor); } } if (retval == null) { retval = Status.OK_STATUS; } return retval; }
From source file:org.eclipse.m2e.ui.internal.launch.MavenLaunchMainTab.java
License:Open Source License
public void initializeFrom(ILaunchConfiguration configuration) { String pomDirName = getAttribute(configuration, ATTR_POM_DIR, ""); //$NON-NLS-1$ this.pomDirNameText.setText(pomDirName); this.goalsText.setText(getAttribute(configuration, ATTR_GOALS, "")); //$NON-NLS-1$ this.profilesText.setText(getAttribute(configuration, ATTR_PROFILES, "")); //$NON-NLS-1$ try {/*from w w w . j a va2s . co m*/ IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration(); this.offlineButton .setSelection(getAttribute(configuration, ATTR_OFFLINE, mavenConfiguration.isOffline())); this.debugOutputButton.setSelection( getAttribute(configuration, ATTR_DEBUG_OUTPUT, mavenConfiguration.isDebugOutput())); this.updateSnapshotsButton.setSelection(getAttribute(configuration, ATTR_UPDATE_SNAPSHOTS, false)); this.skipTestsButton.setSelection(getAttribute(configuration, ATTR_SKIP_TESTS, false)); this.nonRecursiveButton.setSelection(getAttribute(configuration, ATTR_NON_RECURSIVE, false)); this.enableWorkspaceResolution .setSelection(getAttribute(configuration, ATTR_WORKSPACE_RESOLUTION, false)); this.threadsCombo.select(getAttribute(configuration, ATTR_THREADS, 1) - 1); this.runtimeSelector.initializeFrom(configuration); this.userSettings.setText(getAttribute(configuration, ATTR_USER_SETTINGS, "")); this.userSettings.setMessage(nvl(mavenConfiguration.getUserSettingsFile(), SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath())); this.propsTable.removeAll(); @SuppressWarnings("unchecked") List<String> properties = configuration.getAttribute(ATTR_PROPERTIES, Collections.EMPTY_LIST); for (String property : properties) { int n = property.indexOf('='); String name = property; String value = ""; //$NON-NLS-1$ if (n > -1) { name = property.substring(0, n); if (n > 1) { value = property.substring(n + 1); } } TableItem item = new TableItem(propsTable, SWT.NONE); item.setText(0, name); item.setText(1, value); } } catch (CoreException ex) { // XXX should we at least log something here? } setDirty(false); }
From source file:org.springframework.ide.vscode.commons.maven.MavenBridge.java
License:Open Source License
@SuppressWarnings("deprecation") MavenExecutionRequest createExecutionRequest() throws MavenException { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); // this causes problems with unexpected "stale project configuration" // error markers // need to think how to manage ${maven.build.timestamp} properly inside // workspace//from ww w .ja v a 2s .c o m // request.setStartTime( new Date() ); if (mavenConfiguration.getGlobalSettingsFile() != null) { request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile())); } File userSettingsFile = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE; if (mavenConfiguration.getUserSettingsFile() != null) { userSettingsFile = new File(mavenConfiguration.getUserSettingsFile()); } request.setUserSettingsFile(userSettingsFile); try { lookup(MavenExecutionRequestPopulator.class).populateFromSettings(request, getSettings()); } catch (MavenExecutionRequestPopulationException ex) { throw new MavenException(ex); } ArtifactRepository localRepository = getLocalRepository(); request.setLocalRepository(localRepository); request.setLocalRepositoryPath(localRepository.getBasedir()); // request.setOffline(mavenConfiguration.isOffline()); // request.getUserProperties().put("m2e.version", // MavenPluginActivator.getVersion()); //$NON-NLS-1$ // request.getUserProperties().put(ConfigurationProperties.USER_AGENT, // MavenPluginActivator.getUserAgent()); EnvironmentUtils.addEnvVars(request.getSystemProperties()); copyProperties(request.getSystemProperties(), System.getProperties()); request.setCacheNotFound(true); request.setCacheTransferError(true); // request.setGlobalChecksumPolicy(mavenConfiguration.getGlobalChecksumPolicy()); // the right way to disable snapshot update // request.setUpdateSnapshots(false); return request; }
From source file:org.springframework.ide.vscode.commons.maven.MavenBridge.java
License:Open Source License
public synchronized Settings getSettings(final boolean force_reload) throws MavenException { // MUST NOT use createRequest! File userSettingsFile = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE; if (mavenConfiguration.getUserSettingsFile() != null) { userSettingsFile = new File(mavenConfiguration.getUserSettingsFile()); }// ww w . java 2 s. c o m boolean reload = force_reload || settings == null; if (!reload && userSettingsFile != null) { reload = userSettingsFile.lastModified() != settings_timestamp || userSettingsFile.length() != settings_length; } if (reload) { // TODO: Can't that delegate to buildSettings()? SettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); // 440696 guard against ConcurrentModificationException Properties systemProperties = new Properties(); copyProperties(systemProperties, System.getProperties()); request.setSystemProperties(systemProperties); if (mavenConfiguration.getGlobalSettingsFile() != null) { request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile())); } if (userSettingsFile != null) { request.setUserSettingsFile(userSettingsFile); } try { settings = lookup(SettingsBuilder.class).build(request).getEffectiveSettings(); } catch (SettingsBuildingException ex) { String msg = "Could not read settings.xml, assuming default values"; log.error(msg, ex); /* * NOTE: This method provides input for various other core * functions, just bailing out would make m2e highly unusuable. * Instead, we fail gracefully and just ignore the broken * settings, using defaults. */ settings = new Settings(); } if (userSettingsFile != null) { settings_length = userSettingsFile.length(); settings_timestamp = userSettingsFile.lastModified(); } } return settings; }
From source file:org.springframework.ide.vscode.commons.maven.MavenBridge.java
License:Open Source License
public Settings buildSettings(String globalSettings, String userSettings) throws MavenException { SettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); request.setGlobalSettingsFile(globalSettings != null ? new File(globalSettings) : null); request.setUserSettingsFile(userSettings != null ? new File(userSettings) : SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE); try {/*from w ww. ja v a2 s . c o m*/ return lookup(SettingsBuilder.class).build(request).getEffectiveSettings(); } catch (SettingsBuildingException ex) { throw new MavenException(ex); } }