本文整理汇总了Java中org.eclipse.m2e.core.MavenPlugin类的典型用法代码示例。如果您正苦于以下问题:Java MavenPlugin类的具体用法?Java MavenPlugin怎么用?Java MavenPlugin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MavenPlugin类属于org.eclipse.m2e.core包,在下文中一共展示了MavenPlugin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isArtifactAvailableLocally
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
/**
* Checks if an artifact is available in the local repository. The artifact <code>version</code>
* must be a specific value, cannot be "LATEST".
*/
public static boolean isArtifactAvailableLocally(String groupId, String artifactId,
String version, String type,
String classifier) {
try {
Preconditions.checkArgument(!MAVEN_LATEST_VERSION.equals(version));
String artifactPath =
MavenPlugin.getMaven().getLocalRepository()
.pathOf(new DefaultArtifact(groupId, artifactId, version, null /* scope */, type,
classifier, new DefaultArtifactHandler(type)));
return new File(artifactPath).exists();
} catch (CoreException ex) {
logger.log(Level.SEVERE, "Could not lookup local repository", ex);
return false;
}
}
示例2: enableMavenNature
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
private static void enableMavenNature(IProject newProject, IProgressMonitor monitor)
throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 30);
// Workaround deadlock bug described in Eclipse bug (https://bugs.eclipse.org/511793).
try {
IDependencyGraph.INSTANCE.preUpdate();
try {
Job.getJobManager().join(DependencyGraphImpl.GRAPH_UPDATE_JOB_FAMILY,
subMonitor.newChild(8));
} catch (OperationCanceledException | InterruptedException ex) {
logger.log(Level.WARNING, "Exception waiting for WTP Graph Update job", ex);
}
ResolverConfiguration resolverConfiguration = new ResolverConfiguration();
MavenPlugin.getProjectConfigurationManager().enableMavenNature(newProject,
resolverConfiguration, subMonitor.newChild(20));
} finally {
IDependencyGraph.INSTANCE.postUpdate();
}
// M2E will cleverly set "target/<artifact ID>-<version>/WEB-INF/classes" as a new Java output
// folder; delete the default old folder.
newProject.getFolder("build").delete(true /* force */, subMonitor.newChild(2));
}
示例3: execute
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IProject project = getSelectedProject(event);
if (project == null) {
return null;
}
final Shell shell = HandlerUtil.getActiveShell(event);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(project, new NullProgressMonitor());
if (facade == null) {
return;
}
PolyglotTranslaterWizard wizard = new PolyglotTranslaterWizard(facade);
WizardDialog wizardDialog = new WizardDialog(shell, wizard);
wizardDialog.setPageSize(150, 100);
wizardDialog.open();
}
});
return null;
}
示例4: getLatestVersion
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
public static String getLatestVersion(Artifact artifact, IProgressMonitor monitor) throws CoreException {
monitor.beginTask("Getting latest version for " + artifact.getGroupId() + ":" + artifact.getArtifactId(), 1);
try {
final IMaven maven = MavenPlugin.getMaven();
final ArtifactMetadataSource source = ((MavenImpl) maven).getPlexusContainer().lookup(
ArtifactMetadataSource.class, "org.apache.maven.artifact.metadata.ArtifactMetadataSource", "maven"); //$NON-NLS-1$ $NON-NLS-2$
List<ArtifactVersion> versions = source.retrieveAvailableVersions(artifact, maven.getLocalRepository(),
maven.getArtifactRepositories());
Collections.reverse(versions);
for (ArtifactVersion artifactVersion : versions) {
String version = artifactVersion.toString();
if (!version.endsWith("-SNAPSHOT")) {
return version;
}
}
} catch (Exception e) {
throw new CoreException(
new Status(Status.ERROR, PolyglotSupportActivator.PLUGIN_ID, "Error resolving version range", e)); //$NON-NLS-1$
}
return null;
}
示例5: getMavenProperty
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
/**
* Get the current maven project version.
*
* @param project is the {@link IProject}.
* @return the maven project version excluding a potential "-SNAPSHOT" suffix.
*/
private String getMavenProperty(IProject project) {
if (project == null) {
throw new IllegalArgumentException("Missing project");
}
String result = "";
try {
// IMavenConstants.NATURE_ID
if (project.hasNature("org.eclipse.m2e.core.maven2Nature")) {
final IMavenProjectRegistry projectRegistry = MavenPlugin.getMavenProjectRegistry();
final IMavenProjectFacade projectFacade = projectRegistry.create(project, new NullProgressMonitor());
if (projectFacade != null) {
result = getMavenProperty(projectFacade);
}
}
} catch (CoreException ex) {
throw new IllegalStateException(ex);
}
return result;
}
示例6: updateBuildPaths
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
private void updateBuildPaths(IProject project, IProgressMonitor monitor) throws CoreException {
final IMavenProjectFacade facade = projectManager.getProject(project);
if (facade != null) {
final ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
final ICProjectDescription des = mngr.getProjectDescription(project, true);
if (des != null) {
boolean changed = false;
logger.debug("updateBuildPaths: project=" + project.getName());
final ConfiguratorContext context = new ConfiguratorContext(MavenPlugin.getMaven(), projectManager);
List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor);
narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor));
for (NarExecution narSettings : narExecutions) {
if (!narSettings.isSkip()) {
final String os = narSettings.getOS();
final String linkerName = narSettings.getLinkerName();
final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName);
changed = updateCdtBuildPaths(des, synchro, narSettings);
}
}
if (changed) {
mngr.setProjectDescription(project, des);
}
}
}
}
示例7: doFinish
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
/**
* The worker method. It will find the container, create the file if missing
* or just replace its contents, and open the editor on the newly created
* file.
*/
private void doFinish(String containerName, IPath location, IProgressMonitor monitor) throws CoreException {
// create a sample file
monitor.beginTask("Creating " + containerName, 2);
monitor.worked(1);
final Archetype archetype = new Archetype();
archetype.setGroupId("org.glassmaker");
archetype.setArtifactId("org.glassmaker.archetype.basic");
archetype.setVersion("0.0.1");
ProjectParameters params = parametersPage.getParams();
final String groupId = params.getGroupId();
final String artifactId = params.getArtifactId();
final String version = params.getVersion();
final String javaPackage = params.getPackageName();
final Properties properties = params.getProperties();
properties.setProperty("oauth2callbackurl", properties.getProperty(ProjectWizardParametersPage.O_AUTH_CALLBACK));
properties.setProperty("clientid", properties.getProperty(ProjectWizardParametersPage.CLIENT_ID));
properties.setProperty("clientsecret", properties.getProperty(ProjectWizardParametersPage.CLIENT_SECRET));
List<IProject> projects = MavenPlugin.getProjectConfigurationManager().createArchetypeProjects(location, archetype, groupId, artifactId, version, javaPackage, properties, importConfiguration, monitor);
}
示例8: fixParentProject
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
private void fixParentProject(IProject p, IProject parentProject)
throws CoreException {
IFile existingPom = p.getFile("pom.xml");
Model model = MavenPlugin.getMavenModelManager().readMavenModel(existingPom);
Model parent = MavenPlugin.getMavenModelManager().readMavenModel(parentProject.getFile("pom.xml"));
//Parent oldParent = model.getParent();
Parent newParent = new Parent();
newParent.setGroupId(parent.getGroupId());
newParent.setArtifactId(parent.getArtifactId());
newParent.setRelativePath(calculateRelativePath(p, parentProject));
newParent.setVersion(parent.getVersion());
model.setParent(newParent);
// outright deletion doesn't work on windows as the process has a ref to the file itself
// so creating a temp '_newpom_.xml'
final IFile newPom = p.getFile("_newpom_.xml");
MavenPlugin.getMavenModelManager().createMavenModel(newPom, model);
// then copying that content over to the pom.xml
existingPom.setContents(newPom.getContents(), true, true, new NullProgressMonitor());
// and deleting the temp pom
newPom.delete(true, false, new NullProgressMonitor());
}
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-eclipse-developer-tools,代码行数:23,代码来源:NewGraniteProjectWizard.java
示例9: updateMavenConfiguration
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
private static void updateMavenConfiguration(IFile pomFile, Model mavenModel) {
try {
IProgressMonitor monitor = new NullProgressMonitor();
IFile backupFile = pomFile.getParent().getFile(new Path("pom.xml." + System.currentTimeMillis() + ".bak"));
pomFile.move(backupFile.getFullPath(), true, monitor);
MavenPlugin.getMavenModelManager().createMavenModel(pomFile, mavenModel);
backupFile.delete(true, monitor);
} catch (CoreException e) {
Activator.getDefault().getLog()
.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, UserMessages.EXCEPTION_POMUPDATE.value(), e));
}
}
示例10: updateMavenConfiguration
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
private static void updateMavenConfiguration(IFile pomFile, Model mavenModel) {
try {
IProgressMonitor monitor = new NullProgressMonitor();
IFile backupFile = pomFile.getParent().getFile(new Path("pom.xml." + System.currentTimeMillis() + ".bak"));
pomFile.move(backupFile.getFullPath(), true, monitor);
MavenPlugin.getMavenModelManager().createMavenModel(pomFile, mavenModel);
backupFile.delete(true, monitor);
} catch (CoreException e) {
AsciidocBuilderLogger.warn(e.getMessage(), e);
}
}
示例11: resolveArtifact
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
public static Artifact resolveArtifact(IProgressMonitor monitor, String groupId,
String artifactId, String type, String version, String classifier,
List<ArtifactRepository> repositories) throws CoreException {
Artifact artifact = MavenPlugin.getMaven().resolve(groupId, artifactId, version, type,
classifier, repositories, monitor);
return artifact;
}
示例12: getFinalArtifactPath
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
private static IPath getFinalArtifactPath(IProject project) throws CoreException {
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
IMavenProjectFacade projectFacade = projectManager.create(project, new NullProgressMonitor());
MavenProject mavenProject = projectFacade.getMavenProject(new NullProgressMonitor());
String buildDirectory = mavenProject.getBuild().getDirectory();
String finalName = mavenProject.getBuild().getFinalName();
String finalArtifactPath = buildDirectory + "/" + finalName + "." + mavenProject.getPackaging();
return new Path(finalArtifactPath);
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:11,代码来源:FlexMavenPackagedProjectStagingDelegate.java
示例13: update
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
@Override
public void update(IProject project, IProgressMonitor monitor) throws CoreException {
if (!applies(project)) {
return;
}
JavaLanguageServerPlugin.logInfo("Starting Maven update for "+project.getName());
//TODO collect dependent projects and update them as well? i.e in case a parent project was modified
IProjectConfigurationManager configurationManager = MavenPlugin.getProjectConfigurationManager();
MavenUpdateRequest request = new MavenUpdateRequest(project, MavenPlugin.getMavenConfiguration().isOffline(), true);
configurationManager.updateProjectConfiguration(request, monitor);
}
示例14: importToWorkspace
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
@Override
@SuppressWarnings("restriction")
public void importToWorkspace(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
JavaLanguageServerPlugin.logInfo("Importing Maven project(s)");
MavenConfigurationImpl configurationImpl = (MavenConfigurationImpl)MavenPlugin.getMavenConfiguration();
configurationImpl.setDownloadSources(true);
configurationImpl.setNotCoveredMojoExecutionSeverity(ProblemSeverity.ignore.toString());
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
Set<MavenProjectInfo> files = getMavenProjectInfo(subMonitor.split(5));
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Collection<IProject> projects = new LinkedHashSet<>();
Collection<MavenProjectInfo> toImport = new LinkedHashSet<>();
//Separate existing projects from new ones
for (MavenProjectInfo projectInfo : files) {
File pom = projectInfo.getPomFile();
IContainer container = root.getContainerForLocation(new Path(pom.getAbsolutePath()));
if (container == null) {
toImport.add(projectInfo);
} else {
IProject project = container.getProject();
if (ProjectUtils.isMavenProject(project)) {
projects.add(container.getProject());
} else if (project != null) {
//Project doesn't have the Maven nature, so we (re)import it
toImport.add(projectInfo);
}
}
}
if (!toImport.isEmpty()) {
ProjectImportConfiguration importConfig = new ProjectImportConfiguration();
configurationManager.importProjects(toImport, importConfig, subMonitor.split(95));
}
updateProjects(projects, monitor);
}
示例15: getPossibleAdditions0
import org.eclipse.m2e.core.MavenPlugin; //导入依赖的package包/类
private static List<IJavaProject> getPossibleAdditions0(final ISourceLookupDirector director) {
final List<IProject> mavenProjects = new ArrayList<IProject>();
for (final IMavenProjectFacade mavenProject : MavenPlugin.getMavenProjectRegistry().getProjects()) {
mavenProjects.add(mavenProject.getProject());
}
final List<IJavaProject> javaProjects = new ArrayList<IJavaProject>();
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
try {
for (final IJavaProject javaProject : JavaCore.create(root).getJavaProjects()) {
if (mavenProjects.contains(javaProject.getProject())) {
javaProjects.add(javaProject);
}
}
} catch (final JavaModelException e) {
final IStatus status = new Status(IStatus.ERROR, SourceLookupPlugin.getInstance().getBundle().getSymbolicName(),
"Can't retrieve Java projects.", e);
SourceLookupPlugin.getInstance().getLog().log(status);
}
for (final ISourceContainer container : director.getSourceContainers()) {
if (container.getType().getId().equals(MyMvnSourceContainerTypeDelegate.TYPE_ID)) {
javaProjects.remove(((MyMvnSourceContainer) container).getJavaProject());
}
}
return javaProjects;
}