List of usage examples for org.apache.maven.project MavenProject getModel
public Model getModel()
From source file:org.eclipse.m2e.editor.xml.PomHyperlinkDetector.java
License:Open Source License
static InputLocation findLocationForManagedArtifact(final ManagedArtifactRegion region, MavenProject mavprj) { Model mdl = mavprj.getModel(); InputLocation openLocation = null;/*w w w . j a v a 2 s . c o m*/ if (region.isDependency) { DependencyManagement dm = mdl.getDependencyManagement(); if (dm != null) { List<Dependency> list = dm.getDependencies(); String id = region.groupId + ":" + region.artifactId + ":"; //$NON-NLS-1$ //$NON-NLS-2$ if (list != null) { for (Dependency dep : list) { if (dep.getManagementKey().startsWith(id)) { InputLocation location = dep.getLocation(ARTIFACT_ID); //$NON-NLS-1$ //when would this be null? if (location != null) { openLocation = location; break; } } } } } } if (region.isPlugin) { Build build = mdl.getBuild(); if (build != null) { PluginManagement pm = build.getPluginManagement(); if (pm != null) { List<Plugin> list = pm.getPlugins(); String id = Plugin.constructKey(region.groupId, region.artifactId); if (list != null) { for (Plugin plg : list) { if (id.equals(plg.getKey())) { InputLocation location = plg.getLocation(ARTIFACT_ID); //$NON-NLS-1$ //when would this be null? if (location != null) { openLocation = location; break; } } } } } } } return openLocation; }
From source file:org.eclipse.m2e.editor.xml.PomHyperlinkDetector.java
License:Open Source License
public static IHyperlink createHyperlink(final ExpressionRegion region) { return new IHyperlink() { public IRegion getHyperlinkRegion() { return region; }/* www . ja v a 2 s .c o m*/ public String getHyperlinkText() { return NLS.bind(Messages.PomHyperlinkDetector_open_property, region.property); } public String getTypeLabel() { return "pom-property-expression"; //$NON-NLS-1$ } public void open() { //see if we can find the plugin in plugin management of resolved project. MavenProject mavprj = region.project; if (mavprj != null) { //TODO get rid of InputLocation here and use the dom tree to find the property Model mdl = mavprj.getModel(); InputLocation location = null; if (mdl.getProperties().containsKey(region.property)) { location = mdl.getLocation(PROPERTIES).getLocation(region.property); } else if (region.property != null && region.property.startsWith("project.")) {//$NON-NLS-1$ if ("project.version".equals(region.property)) { location = mdl.getLocation(VERSION); } else if ("project.name".equals(region.property)) { location = mdl.getLocation(NAME); } } if (location != null) { File file = XmlUtils.fileForInputLocation(location, mavprj); if (file != null) { IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI()); openXmlEditor(fileStore, location.getLineNumber(), location.getColumnNumber(), location.getSource().getModelId()); } } } } }; }
From source file:org.eclipse.m2e.editor.xml.PomTemplateContext.java
License:Open Source License
static String simpleInterpolate(MavenProject project, String text) { if (text != null && text.contains("${")) { //$NON-NLS-1$ //when expression is in the version but no project instance around // just give up. if (project == null) { return null; }/*from www . ja v a 2s . c om*/ Properties props = project.getProperties(); RegexBasedInterpolator inter = new RegexBasedInterpolator(); if (props != null) { inter.addValueSource(new PropertiesBasedValueSource(props)); } inter.addValueSource(new PrefixedObjectValueSource(Arrays.asList(new String[] { "pom.", "project." }), //$NON-NLS-1$//$NON-NLS-2$ project.getModel(), false)); try { text = inter.interpolate(text); } catch (InterpolationException e) { text = null; } } return text; }
From source file:org.eclipse.m2e.editor.xml.PomTextHover.java
License:Open Source License
/** * @param hoverRegion/* w w w .j av a2 s .c o m*/ */ public static StyledString getLabelForRegion(ExpressionRegion region) { MavenProject mavprj = region.project; if (mavprj != null) { String value = PomTemplateContext.simpleInterpolate(region.project, "${" + region.property + "}"); //$NON-NLS-1$ //$NON-NLS-2$ String loc = null; Model mdl = mavprj.getModel(); if (mdl.getProperties() != null && mdl.getProperties().containsKey(region.property)) { if (mdl.getLocation(PomEdits.PROPERTIES) != null) { //$NON-NLS-1$ InputLocation location = mdl.getLocation(PomEdits.PROPERTIES).getLocation(region.property); //$NON-NLS-1$ if (location != null) { //MNGECLIPSE-2539 apparently you can have an InputLocation with null input source. // check! InputSource source = location.getSource(); if (source != null) { loc = source.getModelId(); } } } } StyledString ret = new StyledString(); ret.append(Messages.PomTextHover_eval1); ret.append(value, StyledString.DECORATIONS_STYLER); //not happy with decorations but how to just do bold text if (loc != null) { ret.append(" "); //$NON-NLS-1$ ret.append(NLS.bind(Messages.PomTextHover_eval2, loc)); } return ret; } return new StyledString(""); //$NON-NLS-1$ }
From source file:org.eclipse.m2e.profiles.core.internal.management.ProfileManager.java
License:Open Source License
public List<ProfileData> getProfileDatas(IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException { if (facade == null) { return Collections.emptyList(); }//from w w w . j a v a 2 s . co m ResolverConfiguration resolverConfiguration = MavenPlugin.getProjectConfigurationManager() .getResolverConfiguration(facade.getProject()); List<String> configuredProfiles = toList(resolverConfiguration.getSelectedProfiles()); MavenProject mavenProject = facade.getMavenProject(monitor); List<Model> modelHierarchy = new ArrayList<>(); getModelHierarchy(modelHierarchy, mavenProject.getModel(), monitor); List<Profile> availableProfiles = collectAvailableProfiles(modelHierarchy, monitor); final Map<Profile, Boolean> availableSettingsProfiles = getAvailableSettingsProfiles(); availableProfiles.addAll(availableSettingsProfiles.keySet()); List<ProfileData> statuses = new ArrayList<ProfileData>(); Map<String, List<String>> allActiveProfiles = mavenProject.getInjectedProfileIds(); for (Profile p : availableProfiles) { String pId = p.getId(); ProfileData status = new ProfileData(pId); boolean isDisabled = configuredProfiles.contains("!" + pId); if (isActive(pId, allActiveProfiles)) { status.setActivationState(ProfileState.Active); } else if (isDisabled) { status.setActivationState(ProfileState.Disabled); } boolean isUserSelected = isDisabled || configuredProfiles.contains(pId); status.setUserSelected(isUserSelected); Boolean isAutoActiveSettingProfile = availableSettingsProfiles.get(p); boolean isAutoActive = (isAutoActiveSettingProfile != null && isAutoActiveSettingProfile) || (status.getActivationState().isActive() && !isUserSelected); status.setAutoActive(isAutoActive); status.setSource(findSource(p, modelHierarchy)); statuses.add(status); } return Collections.unmodifiableList(statuses); }
From source file:org.eclipse.m2e.wtp.internal.filtering.ResourceFilteringBuildParticipant.java
License:Open Source License
/** * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=356725. * Loads the parent project hierarchy if needed. * @param facade// w ww .j a v a 2 s . c om * @param monitor * @return true if parent projects had to be loaded. * @throws CoreException */ private boolean loadParentHierarchy(IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException { boolean loadedParent = false; MavenProject mavenProject = facade.getMavenProject(); try { if (mavenProject.getModel().getParent() == null || mavenProject.getParent() != null) { //If the method is called without error, we can assume the project has been fully loaded //No need to continue. return false; } } catch (IllegalStateException e) { //The parent can not be loaded properly } MavenExecutionRequest request = null; while (mavenProject != null && mavenProject.getModel().getParent() != null) { if (monitor.isCanceled()) { break; } if (request == null) { request = MavenPlugin.getMavenProjectRegistry().createExecutionRequest(facade, monitor); } MavenProject parentProject = MavenPlugin.getMaven().resolveParentProject(request, mavenProject, monitor); if (parentProject != null) { mavenProject.setParent(parentProject); loadedParent = true; } mavenProject = parentProject; } return loadedParent; }
From source file:org.eclipse.scada.build.helper.AbstractSetQualifierMojo.java
License:Open Source License
private void checkNonRelativeParent(final MavenProject project) { if (project.getModel().getParent() == null) { // no parent return;/*ww w. j a v a 2s .co m*/ } if (project.getParentFile() != null) { // is a local parent return; } final Parent parent = project.getModel().getParent(); final String prefix = String.format("%s:%s:", parent.getGroupId(), parent.getArtifactId()); for (final String entry : this.forceUpdateParentQualifiers) { if (entry.startsWith(prefix)) { final String qualifier = entry.substring(prefix.length()); final String newVersion = makeVersion(parent.getVersion(), qualifier); getLog().info(String.format("Force update parent of %s to %s -> %s", project.getId(), parent.getId(), newVersion)); addChange(project.getFile(), new ModelModifier() { @Override public boolean apply(final Model model) { model.getParent().setVersion(newVersion); return true; } }); } } }
From source file:org.eclipse.scada.build.helper.DefaultPomHelper.java
License:Open Source License
protected List<String> getModules(final MavenProject project) { final List<String> result = new LinkedList<String>(); result.addAll(project.getModules()); for (final Profile profile : project.getModel().getProfiles()) { result.addAll(profile.getModules()); }/*from www . j ava 2 s . co m*/ return result; }
From source file:org.eluder.coveralls.maven.plugin.util.CoverageParsersFactory.java
License:Open Source License
public List<CoverageParser> createParsers() throws IOException { List<CoverageParser> parsers = new ArrayList<CoverageParser>(); List<MavenProject> projects = new MavenProjectCollector(project).collect(); ExistingFiles jacocoFiles = ExistingFiles.create(jacocoReports); ExistingFiles coberturaFiles = ExistingFiles.create(coberturaReports); ExistingFiles sagaFiles = ExistingFiles.create(sagaReports); for (MavenProject p : projects) { File reportingDirectory = new File(p.getModel().getReporting().getOutputDirectory()); File buildDirectory = new File(p.getBuild().getDirectory()); jacocoFiles.add(new File(reportingDirectory, JACOCO_FILE)); coberturaFiles.add(new File(reportingDirectory, COBERTURA_FILE)); sagaFiles.add(new File(buildDirectory, SAGA_FILE)); }//from w w w . j a va2s. c o m for (File jacocoFile : jacocoFiles) { parsers.add(new JaCoCoParser(jacocoFile, sourceLoader)); } for (File coberturaFile : coberturaFiles) { parsers.add(new CoberturaParser(coberturaFile, sourceLoader)); } for (File sagaFile : sagaFiles) { parsers.add(new SagaParser(sagaFile, sourceLoader)); } if (parsers.isEmpty()) { throw new IOException("No coverage report files found"); } return Collections.unmodifiableList(parsers); }
From source file:org.fluidity.foundation.impl.BundleJarManifest.java
License:Apache License
public SecurityPolicy processManifest(final MavenProject project, final Attributes attributes, final SecurityPolicy policy, final Logger log, final Dependencies dependencies) throws MojoExecutionException { dependencies.attribute(BUNDLE_CLASSPATH, ","); addEntry(attributes, BUNDLE_MANIFESTVERSION, "2"); addEntry(attributes, BUNDLE_NAME, project::getName); addEntry(attributes, BUNDLE_SYMBOLICNAME, project::getArtifactId); addEntry(attributes, BUNDLE_VERSION, project::getVersion); addEntry(attributes, BUNDLE_DESCRIPTION, project::getDescription); addEntry(attributes, BUNDLE_DOCURL, project::getUrl); addEntry(attributes, BUNDLE_VENDOR, () -> { return project.getOrganization().getName(); });// w ww . ja va 2 s .c o m addEntry(attributes, BUNDLE_COPYRIGHT, () -> { final String year = project.getInceptionYear(); return year == null ? null : String.format("Copyright %s (c) %s. All rights reserved.", project.getOrganization().getName(), year); }); addEntry(attributes, REQUIRE_CAPABILITY, () -> { // https://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html final String[] version = System.getProperty("java.version").split("\\."); return String.format("osgi.ee;filter:=(&(osgi.ee=JavaSE)(version>=%s.%s))", version[0], version[1]); }); final String version = attributes.getValue(BUNDLE_VERSION); if (version != null) { attributes.putValue(BUNDLE_VERSION, verify(version)); } else { addEntry(attributes, BUNDLE_VERSION, DEFAULT_BUNDLE_VERSION); } final RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); final List<String> prefixes = Collections.singletonList("project."); interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties())); interpolator.addValueSource(new PrefixedPropertiesValueSource(prefixes, project.getProperties(), true)); interpolator.addValueSource(new PrefixedObjectValueSource(prefixes, project.getModel(), true)); final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(prefixes, true); interpolator.setCacheAnswers(true); interpolator.setReusePatterns(true); interpolator.addPostProcessor((ignored, value) -> verify((String) value)); try { interpolateHeaders(attributes, interpolator, interceptor, EXPORT_PACKAGE, IMPORT_PACKAGE, DYNAMICIMPORT_PACKAGE, FRAGMENT_HOST, REQUIRE_BUNDLE, BUNDLE_NATIVECODE); } catch (final InterpolationException e) { throw new IllegalStateException(e); } final Collection<Artifact> artifacts = dependencies.compiler(); // if embedding project dependencies, see if Fluid Tools composition is included and if so, add a bundle activator to bootstrap the system. if (!artifacts.isEmpty()) { try { // create a class loader that sees the project's compile-time dependencies final Set<URL> urls = new HashSet<>(); final String skippedId = project.getArtifact().getId(); for (final Artifact dependency : artifacts) { // we don't need the project artifact and don't want to prevent the caller from overwriting it by locking the file... if (!skippedId.equals(dependency.getId())) { urls.add(dependency.getFile().toURI().toURL()); } } final Method method = Methods.get(BootstrapDiscovery.class, BootstrapDiscovery::activator)[0]; urls.add((Archives.containing(BootstrapDiscovery.class))); urls.add((Archives.containing(BootstrapDiscoveryImpl.class))); urls.add((Archives.containing(ComponentContainer.class))); final String activator = isolate(null, urls, BootstrapDiscoveryImpl.class, method); if (activator != null) { addEntry(attributes, BUNDLE_ACTIVATOR, activator); } if (log.active()) { final String value = attributes.getValue(BUNDLE_ACTIVATOR); log.detail("Bundle activator: %s", value == null ? "none" : value.equals(BundleBootstrap.class.getName()) ? "built in" : value); } } catch (final ClassNotFoundException e) { // that's OK } catch (final Exception e) { throw new IllegalStateException(e); } } return new OsgiLocalPermissions(policy, artifacts, attributes.getValue(DYNAMICIMPORT_PACKAGE), attributes.getValue(IMPORT_PACKAGE), attributes.getValue(EXPORT_PACKAGE)); }