本文整理汇总了Java中org.eclipse.m2e.core.internal.IMavenConstants类的典型用法代码示例。如果您正苦于以下问题:Java IMavenConstants类的具体用法?Java IMavenConstants怎么用?Java IMavenConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMavenConstants类属于org.eclipse.m2e.core.internal包,在下文中一共展示了IMavenConstants类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMavenProject
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
private boolean isMavenProject(IProject project) {
IProjectDescription description;
try {
description = project.getDescription();
if (description == null) {
return false;
}
} catch (CoreException e) {
return false;
}
List<String> natures = new ArrayList<>();
natures.addAll(Arrays.asList(description.getNatureIds()));
return natures.contains(IMavenConstants.NATURE_ID);
}
示例2: updatePOM
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
public static void updatePOM(Document pomDocument,
IProgressMonitor monitor, IProject project) throws CoreException,
TransformerException {
IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME);
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(pomDocument);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
StreamResult result = new StreamResult(bytes);
transformer.transform(source, result);
pom.setContents(new ByteArrayInputStream(bytes.toByteArray()),
IFile.FORCE, monitor);
}
示例3: getArtifactScope
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
protected int getArtifactScope(ILaunchConfiguration configuration) throws CoreException {
String typeid = configuration.getType().getAttribute("id"); //$NON-NLS-1$
if(JDT_JAVA_APPLICATION.equals(typeid) || "org.jboss.tools.servers.wildfly.swarm.core.serverLaunchConfig".equals(typeid)) {
IResource[] resources = configuration.getMappedResources();
// MNGECLIPSE-530: NPE starting openarchitecture workflow
if(resources == null || resources.length == 0) {
return IClasspathManager.CLASSPATH_RUNTIME;
}
// ECLIPSE-33: applications from test sources should use test scope
final Set<IPath> testSources = new HashSet<>();
IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
IMavenProjectFacade facade = projectManager.create(javaProject.getProject(), new NullProgressMonitor());
if(facade == null) {
return IClasspathManager.CLASSPATH_RUNTIME;
}
testSources.addAll(Arrays.asList(facade.getTestCompileSourceLocations()));
for(int i = 0; i < resources.length; i++ ) {
for(IPath testPath : testSources) {
if(testPath.isPrefixOf(resources[i].getProjectRelativePath())) {
return IClasspathManager.CLASSPATH_TEST;
}
}
}
return IClasspathManager.CLASSPATH_RUNTIME;
} else if(JDT_JUNIT_TEST.equals(typeid) || JDT_TESTNG_TEST.equals(typeid)) {
return IClasspathManager.CLASSPATH_TEST;
} else {
throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0, NLS.bind(
Messages.MavenRuntimeClasspathProvider_error_unsupported, typeid), null));
}
}
示例4: convertRange
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
/**
* @param marker
* @return
*/
private static Range convertRange(IDocument document, IMarker marker) {
int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1;
int cStart = 0;
int cEnd = 0;
try {
//Buildship doesn't provide markers for gradle files, Maven does
if (marker.isSubtypeOf(IMavenConstants.MARKER_ID)) {
cStart = marker.getAttribute(IMavenConstants.MARKER_COLUMN_START, -1);
cEnd = marker.getAttribute(IMavenConstants.MARKER_COLUMN_END, -1);
} else {
int lineOffset = 0;
try {
lineOffset = document.getLineOffset(line);
} catch (BadLocationException unlikelyException) {
JavaLanguageServerPlugin.logException(unlikelyException.getMessage(), unlikelyException);
return new Range(new Position(line, 0), new Position(line, 0));
}
cEnd = marker.getAttribute(IMarker.CHAR_END, -1) - lineOffset;
cStart = marker.getAttribute(IMarker.CHAR_START, -1) - lineOffset;
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
cStart = Math.max(0, cStart);
cEnd = Math.max(0, cEnd);
return new Range(new Position(line, cStart), new Position(line, cEnd));
}
示例5: createMavenMarker
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
private IMarker createMavenMarker(int severity, String msg, int line, int start, int end) throws Exception {
IMarker m = createMarker(severity, msg, line, start, end);
when(m.isSubtypeOf(IMavenConstants.MARKER_ID)).thenReturn(true);
when(m.getAttribute(IMarker.MESSAGE, "")).thenReturn(msg);
when(m.getAttribute(IMavenConstants.MARKER_COLUMN_START, -1)).thenReturn(start);
when(m.getAttribute(IMavenConstants.MARKER_COLUMN_END, -1)).thenReturn(end);
return m;
}
示例6: translatePom
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
private void translatePom(IFile input, IProgressMonitor monitor) throws CoreException {
markerManager.deleteMarkers(input, TRANSLATION_PROBLEM_TYPE);
IProject project = input.getProject();
IFile pomXml = project.getFile(IMavenConstants.POM_FILE_NAME);
IPath buildFolder;
if (pomXml.exists()) {
IMavenProjectFacade facade = projectManager.create(pomXml, true, monitor);
MavenProject mavenProject = facade.getMavenProject(monitor);
buildFolder = facade.getProjectRelativePath(mavenProject.getBuild().getDirectory());
} else {
//In case where pom.xml doesn't exist, fall back to default target folder
buildFolder = project.getFolder("target").getProjectRelativePath();
}
IPath polyglotFolder = buildFolder.append("polyglot");
IFile output = project.getFolder(polyglotFolder).getFile(IMavenConstants.POM_FILE_NAME);
MavenExecutionResult result = translate(pomXml, input, output, monitor);
if (result.hasExceptions()) {
addErrorMarkers(input, result.getExceptions());
return;
}
if (output.exists()) {
try (InputStream content = output.getContents()) {
if (pomXml.exists()) {
pomXml.setContents(content, true, true, monitor);
} else {
pomXml.create(content, true, monitor);
}
if (!pomXml.isDerived()) {
pomXml.setDerived(true, monitor);
}
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, PolyglotSupportActivator.PLUGIN_ID, "Unable to write to pom.xml", e));
}
}
}
示例7: setUp
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
workspace = ResourcesPlugin.getWorkspace();
// Turn off auto building
IWorkspaceDescription description = workspace.getDescription();
description.setAutoBuilding(false);
workspace.setDescription(description);
// Turn off index updating
IEclipsePreferences store = new DefaultScope().getNode(IMavenConstants.PLUGIN_ID);
store.putBoolean(MavenPreferenceConstants.P_UPDATE_INDEXES, false);
mavenConfiguration = MavenPlugin.getMavenConfiguration();
if (settingsFile != null) {
oldUserSettingsFile = mavenConfiguration.getUserSettingsFile();
File settings = new File(settingsFile).getCanonicalFile();
if (settings.canRead()) {
String userSettingsFile = settings.getAbsolutePath();
System.out.println("Setting user settings file: " + userSettingsFile);
mavenConfiguration.setUserSettingsFile(userSettingsFile);
} else {
fail("User settings file cannot be read: " + settings);
}
}
cleanWorkspace();
waitForJobs();
}
示例8: findPomXmlBasedir
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
private IContainer findPomXmlBasedir(IContainer dir) {
if (dir == null) {
return null;
}
try {
// loop upwards through the parents as long as we do not cross the project boundary
while (dir.exists() && dir.getProject() != null && dir.getProject() != dir) {
// see if pom.xml exists
if (dir.getType() == IResource.FOLDER) {
IFolder folder = (IFolder) dir;
if (folder.findMember(IMavenConstants.POM_FILE_NAME) != null) {
return folder;
}
}
else if (dir.getType() == IResource.FILE) {
if (((IFile) dir).getName().equals(IMavenConstants.POM_FILE_NAME)) {
return dir.getParent();
}
}
dir = dir.getParent();
}
}
catch (Exception e) {
return dir;
}
return dir;
}
示例9: checkoutProject
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
public void checkoutProject(MavenProjectScmInfo info, File dest, IProgressMonitor monitor) throws CoreException,
InterruptedException {
ISVNRemoteFolder folder = getRemoteFolder(info);
ISVNClientAdapter svnClient = folder.getRepository().getSVNClient();
try {
OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor));
svnClient.checkout(folder.getUrl(), dest, //
SVNRevision.getRevision(info.getRevision()), true);
// RepositoryProvider.map(project, SVNProviderPlugin.getTypeId());
// RepositoryProvider.getProvider(project, SVNProviderPlugin.getTypeId());
} catch(ParseException ex) {
throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0, //
"Invalid revision " + info.getRevision(), ex));
} catch (SVNClientException e) {
String msg = null;
Throwable cause = e.getCause();
if(cause!=null) {
msg = cause.getMessage();
}
if(msg==null) {
msg = e.getMessage();
}
if(msg==null) {
msg = e.toString();
}
throw new SVNException("Checkout error; " + msg);
} finally {
OperationManager.getInstance().endOperation();
}
// CheckoutAsProjectOperation operation = new CheckoutAsProjectOperation(null, //
// new ISVNRemoteFolder[] {folder}, //
// new IProject[] {project}, locationPath);
// try {
// operation.setSvnRevision(SVNRevision.getRevision(info.getRevision()));
// operation.run(monitor);
//
// } catch(ParseException ex) {
// throw new CoreException(new Status(IStatus.ERROR, MavenPlugin.PLUGIN_ID, 0, "Invalid revision " + info.getRevision(), ex));
//
// } catch(InvocationTargetException ex) {
// Throwable t = ex.getTargetException()==null ? ex : ex.getTargetException();
// if(t instanceof CoreException) {
// throw (CoreException) t;
// }
// throw new CoreException(new Status(IStatus.ERROR, MavenPlugin.PLUGIN_ID, 0, "Invalid revision " + info.getRevision(), t));
//
// }
}
示例10: isMavenProject
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
public static boolean isMavenProject(IProject project) {
return hasNature(project, IMavenConstants.NATURE_ID);
}
示例11: configure
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
final ConfiguratorContext context = new ConfiguratorContext(maven, projectManager);
IProject project = request.getProject();
monitor.setTaskName(Messages.CProjectConfigurator_task_name + project.getName());
logger.info("configure");
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
// Set the first created configuration as active.
boolean setActive = true;
final IMavenProjectFacade facade = request.getMavenProjectFacade();
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);
final String toolchain = synchro.getToolchain();
for (NarBuildArtifact artifactSettings : narSettings.getArtifactSettings()) {
final String configName = artifactSettings.getConfigName();
final String cdtArtefactType = CdtUtils.convertArtefactType(artifactSettings.getType());
IToolChain tc = getToolChain(toolchain, cdtArtefactType);
ICProjectDescription desc = getCdtProject(project, tc, cdtArtefactType, monitor);
ICConfigurationDescription cfg = getCdtMavenConfig(project, desc, tc, cdtArtefactType, configName, setActive, monitor);
setActive = false;
synchro.fullSync(cfg, artifactSettings);
mngr.setProjectDescription(project, desc);
}
}
}
AbstractProjectConfigurator jConfig = LifecycleMappingFactory.createProjectConfigurator(JAVA_CONFIGURATOR_ID);
jConfig.configure(request, monitor);
// ensure CDT builder is after the Maven one
boolean changed = false;
IProjectDescription description = project.getDescription();
ICommand cdtBuilder = null;
ICommand mavenBuilder = null;
ArrayList<ICommand> newSpec = new ArrayList<ICommand>();
for (ICommand command : description.getBuildSpec()) {
if (ManagedCProjectNature.getBuilderID().equals(command.getBuilderName()) && mavenBuilder == null) {
cdtBuilder = command;
} else {
newSpec.add(command);
}
if (IMavenConstants.BUILDER_ID.equals(command.getBuilderName())) {
mavenBuilder = command;
if (cdtBuilder != null) {
newSpec.add(cdtBuilder);
changed = true;
}
}
}
if (changed) {
description.setBuildSpec(newSpec.toArray(new ICommand[newSpec.size()]));
project.setDescription(description, monitor);
}
}
示例12: convertToMavenProject
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
private void convertToMavenProject() throws Exception {
Model model = MavenPlugin.getMavenModelManager().readMavenModel(loadPomFileWithSettings());
final IFile file = getContainer().getFile(new Path(IMavenConstants.POM_FILE_NAME));
if(file.exists()) {
throw new Exception("Error occurred during maven-project generation.");
}
MavenPlugin.getProjectConversionManager().convert(this.project, model, null);
MavenModelManager modelManager = MavenPlugin.getMavenModelManager();
modelManager.createMavenModel(file, model);
}
示例13: addNatureTo
import org.eclipse.m2e.core.internal.IMavenConstants; //导入依赖的package包/类
private IProjectDescription addNatureTo(IProjectDescription description) {
String[] natureIds = (String[]) Arrays.asList(JavaCore.NATURE_ID, IMavenConstants.NATURE_ID).toArray();
description.setNatureIds(natureIds);
return description;
}