use of org.eclipse.m2e.core.project.IMavenProjectRegistry in project liferay-ide by liferay.
the class MavenGoalAction method _runMavenGoal.
private void _runMavenGoal(IFile pomFile, String goal, IProgressMonitor monitor) throws CoreException {
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
IMavenProjectFacade projectFacade = projectManager.create(pomFile, false, new NullProgressMonitor());
MavenUIProjectBuilder builder = new MavenUIProjectBuilder(pomFile.getProject());
builder.runMavenGoal(projectFacade, goal, "run", monitor);
}
use of org.eclipse.m2e.core.project.IMavenProjectRegistry in project m2e-nar by maven-nar.
the class AbstractDependencyMojo method resolveEclipseProject.
private EclipseNarLayout resolveEclipseProject(final Artifact artifact, final ConfiguratorContext context, IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
final IMavenProjectRegistry projectManager = context.getProjectManager();
if (!Artifact.SCOPE_COMPILE.equals(artifact.getScope()) && !Artifact.SCOPE_TEST.equals(artifact.getScope())) {
return null;
}
IMavenProjectFacade dependency = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
if (dependency == null || dependency.getFullPath(artifact.getFile()) == null) {
return null;
}
if (dependency.getProject().equals(facade.getProject())) {
return null;
}
getLog().debug("Found dependency project " + dependency.getProject().getName());
EclipseNarLayout layout = new EclipseNarLayout(getLog());
layout.setProject(dependency);
List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, dependency, monitor);
getLog().debug("Found " + narExecutions.size() + " compile executions");
com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact artifactSettings = null;
for (NarExecution narSettings : narExecutions) {
for (com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact settings : narSettings.getArtifactSettings()) {
layout.addArtifactName(settings.getType(), settings.getArtifactName());
artifactSettings = settings;
}
}
if (artifactSettings != null) {
for (String includePath : artifactSettings.getCSettings().getIncludePaths()) {
layout.addIncludeDirectory(new File(includePath));
}
for (String includePath : artifactSettings.getCppSettings().getIncludePaths()) {
layout.addIncludeDirectory(new File(includePath));
}
return layout;
}
return null;
}
use of org.eclipse.m2e.core.project.IMavenProjectRegistry in project liferay-ide by liferay.
the class MavenUtil method getProjectFacade.
public static IMavenProjectFacade getProjectFacade(IProject project, IProgressMonitor monitor) {
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
IFile pomResource = project.getFile(IMavenConstants.POM_FILE_NAME);
if (FileUtil.exists(pomResource)) {
return projectManager.create(pomResource, true, monitor);
}
return null;
}
use of org.eclipse.m2e.core.project.IMavenProjectRegistry in project liferay-ide by liferay.
the class NewMavenPluginProjectProvider method createNewProject.
@Override
public IStatus createNewProject(NewLiferayPluginProjectOp op, IProgressMonitor monitor) throws CoreException {
ElementList<ProjectName> projectNames = op.getProjectNames();
IStatus retval = null;
IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration();
IMavenProjectRegistry mavenProjectRegistry = MavenPlugin.getMavenProjectRegistry();
IProjectConfigurationManager projectConfigurationManager = MavenPlugin.getProjectConfigurationManager();
String groupId = op.getGroupId().content();
String artifactId = op.getProjectName().content();
String version = op.getArtifactVersion().content();
String javaPackage = op.getGroupId().content();
String activeProfilesValue = op.getActiveProfilesValue().content();
IPortletFramework portletFramework = op.getPortletFramework().content(true);
String frameworkName = NewLiferayPluginProjectOpMethods.getFrameworkName(op);
IPath location = PathBridge.create(op.getLocation().content());
if (location.lastSegment().equals(artifactId)) {
// use parent dir since maven archetype will generate new dir under this
// location
location = location.removeLastSegments(1);
}
String archetypeArtifactId = op.getArchetype().content(true);
Archetype archetype = new Archetype();
String[] gav = archetypeArtifactId.split(":");
String archetypeVersion = gav[gav.length - 1];
archetype.setGroupId(gav[0]);
archetype.setArtifactId(gav[1]);
archetype.setVersion(archetypeVersion);
ArchetypeManager archetypeManager = MavenPluginActivator.getDefault().getArchetypeManager();
ArtifactRepository remoteArchetypeRepository = archetypeManager.getArchetypeRepository(archetype);
Properties properties = new Properties();
try {
List<?> archProps = archetypeManager.getRequiredProperties(archetype, remoteArchetypeRepository, monitor);
if (ListUtil.isNotEmpty(archProps)) {
for (Object prop : archProps) {
if (prop instanceof RequiredProperty) {
RequiredProperty rProp = (RequiredProperty) prop;
Value<PluginType> pluginType = op.getPluginType();
if (pluginType.content().equals(PluginType.theme)) {
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);
}
ResolverConfiguration resolverConfig = new ResolverConfiguration();
if (!CoreUtil.isNullOrEmpty(activeProfilesValue)) {
resolverConfig.setSelectedProfiles(activeProfilesValue);
}
ProjectImportConfiguration configuration = new ProjectImportConfiguration(resolverConfig);
List<IProject> newProjects = projectConfigurationManager.createArchetypeProjects(location, archetype, groupId, artifactId, version, javaPackage, properties, configuration, monitor);
if (ListUtil.isNotEmpty(newProjects)) {
op.setImportProjectStatus(true);
for (IProject project : newProjects) {
projectNames.insert().setName(project.getName());
}
}
if (ListUtil.isEmpty(newProjects)) {
retval = LiferayMavenCore.createErrorStatus("New project was not created due to unknown error");
} else {
IProject firstProject = newProjects.get(0);
if (!CoreUtil.isNullOrEmpty(activeProfilesValue)) {
String[] activeProfiles = activeProfilesValue.split(",");
// find all profiles that should go in user settings file
List<NewLiferayProfile> newUserSettingsProfiles = getNewProfilesToSave(activeProfiles, op.getNewLiferayProfiles(), ProfileLocation.userSettings);
if (ListUtil.isNotEmpty(newUserSettingsProfiles)) {
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
File settingsXmlFile = new File(userSettingsPath);
File backupFile = _getBackupFile(settingsXmlFile);
FileUtils.copyFile(settingsXmlFile, backupFile);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
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
List<NewLiferayProfile> newProjectPomProfiles = getNewProfilesToSave(activeProfiles, op.getNewLiferayProfiles(), ProfileLocation.projectPom);
// only need to set the first project as nested projects should pickup the
// parent setting
IMavenProjectFacade newMavenProject = mavenProjectRegistry.getProject(firstProject);
IFile pomFile = newMavenProject.getPom();
IDOMModel domModel = null;
try {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(pomFile);
for (NewLiferayProfile newProfile : newProjectPomProfiles) {
MavenUtil.createNewLiferayProfileNode(domModel.getDocument(), newProfile);
}
domModel.save();
} catch (IOException ioe) {
LiferayMavenCore.logError("Unable to save new Liferay profiles to project pom.", ioe);
} finally {
if (domModel != null) {
domModel.releaseFromEdit();
}
}
for (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);
}
}
String pluginVersion = getNewLiferayProfilesPluginVersion(activeProfiles, op.getNewLiferayProfiles(), archetypeVersion);
String archVersion = MavenUtil.getMajorMinorVersionOnly(archetypeVersion);
updateDtdVersion(firstProject, pluginVersion, archVersion);
}
Value<PluginType> pluginType = op.getPluginType();
if (pluginType.content().equals(PluginType.portlet)) {
String portletName = op.getPortletName().content(false);
retval = portletFramework.postProjectCreated(firstProject, frameworkName, portletName, monitor);
}
}
if (retval == null) {
retval = Status.OK_STATUS;
}
return retval;
}
Aggregations