List of usage examples for org.apache.maven.project MavenProject getModel
public Model getModel()
From source file:org.codehaus.mojo.webstart.generator.AbstractGenerator.java
License:Apache License
/** * Creates a Velocity context and populates it with replacement values * for our pre-defined placeholders.//from w w w. j a v a 2 s. co m * * @return Returns a velocity context with system and maven properties added */ protected VelocityContext createAndPopulateContext() { VelocityContext context = new VelocityContext(); context.put("dependencies", getDependenciesText()); // Note: properties that contain dots will not be properly parsed by Velocity. // Should we replace dots with underscores ? addPropertiesToContext(System.getProperties(), context); MavenProject mavenProject = config.getMavenProject(); String encoding = config.getEncoding(); addPropertiesToContext(mavenProject.getProperties(), context); addPropertiesToContext(extraConfig.getProperties(), context); context.put("project", mavenProject.getModel()); context.put("jnlpCodebase", extraConfig.getJnlpCodeBase()); // aliases named after the JNLP file structure context.put("informationTitle", mavenProject.getModel().getName()); context.put("informationDescription", mavenProject.getModel().getDescription()); if (mavenProject.getModel().getOrganization() != null) { context.put("informationVendor", mavenProject.getModel().getOrganization().getName()); context.put("informationHomepage", mavenProject.getModel().getOrganization().getUrl()); } // explicit timestamps in local and and UTC time zones Date timestamp = new Date(); context.put("explicitTimestamp", dateToExplicitTimestamp(timestamp)); context.put("explicitTimestampUTC", dateToExplicitTimestampUTC(timestamp)); context.put("outputFile", config.getOutputFile().getName()); context.put("mainClass", config.getMainClass()); context.put("encoding", encoding); context.put("input.encoding", encoding); context.put("output.encoding", encoding); // TODO make this more extensible context.put("allPermissions", BooleanUtils.toBoolean(extraConfig.getAllPermissions())); context.put("offlineAllowed", BooleanUtils.toBoolean(extraConfig.getOfflineAllowed())); context.put("jnlpspec", extraConfig.getJnlpSpec()); context.put("j2seVersion", extraConfig.getJ2seVersion()); return context; }
From source file:org.deegree.maven.ModuleListRenderer.java
License:Open Source License
private String getModuleStatus(MavenProject p) { Properties props = p.getModel().getProperties(); String st = props.getProperty("deegree.module.status"); if (st == null) { return "not specified in pom"; }//from w ww. ja v a 2s .co m return st; }
From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java
License:Open Source License
private static MavenProjectInfo getIntfProjectInfoFromProperties(final String projectName, final MavenProject mProject) throws Exception { if (SOALogger.DEBUG) logger.entering(projectName, mProject); MavenProjectInfo result = null;/* w ww .jav a 2 s. com*/ // try to load from the project if available final IProject project = WorkspaceUtil.getProject(projectName); if (project != null && project.isAccessible()) { if (SOALogger.DEBUG) logger.debug("Project is accessible->", project); result = getInterfaceProjectInfo(project); } else { // the service only exist in the repository if (SOALogger.DEBUG) logger.debug("Project is NOT accessible, reading from the local repository->", mProject); final Properties props = mProject.getProperties(); // the service name should be same as the interface project name final String serviceName = projectName; final String implProjectName = props.getProperty(SOAMavenConstants.POM_PROP_KEY_IMPL_PROJECT_NAME); Properties metadataProps = null; InputStream io = null; try { final String jarEntryPath = StringUtil.toString(SOAProjectConstants.FOLDER_META_INF, SOAIntfProject.FOLDER_SOA_COMMON_CONFIG, WorkspaceUtil.PATH_SEPERATOR, serviceName, WorkspaceUtil.PATH_SEPERATOR, SOAProjectConstants.PROPS_FILE_SERVICE_METADATA); io = getInputStreamFromJar(mProject, jarEntryPath); metadataProps = new Properties(); metadataProps.load(io); } finally { IOUtils.closeQuietly(io); } result = createProjectInfoFromMetadataProps(serviceName, metadataProps); if (result != null) { result.setImplementationProjectName(implProjectName); /* * if (StringUtils.isNotBlank(implProjectName)) * result.setImplementationProjectName(implProjectName); else { * //TODO the impl project name might not be available for those * project created in the old SOA plugin * result.setImplementationProjectName(serviceName + * SOAProjectConstants.IMPL_PROJECT_SUFFIX); logger.warning( * "Could not load the impl project name from the pom.xml of service->" * , projectName, * ", using the default logic with \"Impl\" as suffix ->", * result.getImplementationProjectName()); } */ processDependencies(mProject.getModel(), result); } } if (SOALogger.DEBUG) logger.exiting(result); return result; }
From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java
License:Open Source License
/** * Gets the project info./*from w w w . j a v a2s. c om*/ * * @param groupID the group id * @param projectName the project name * @param version the version * @return the project info * @throws Exception the exception */ public static MavenProjectInfo getProjectInfo(final String groupID, final String projectName, final String version) throws Exception { final String libVersion = version != null ? version : MavenCoreUtils.getLibraryVersion(groupID, projectName, SOAProjectConstants.DEFAULT_SERVICE_VERSION); final String fullLibName = MavenCoreUtils.translateLibraryName(groupID, projectName, libVersion); final ArtifactMetadata artifact = getLibraryIdentifier(fullLibName); if (artifact != null) { final MavenProject mProject = MavenCoreUtils.getLibrary(artifact); if (getMavenOrgProviderInstance().getProjectGroupId(SupportedProjectType.INTERFACE).equals(groupID)) { return MavenCoreUtils.getIntfProjectInfoFromProperties(projectName, mProject); } else if (getMavenOrgProviderInstance().getProjectGroupId(SupportedProjectType.IMPL).equals(groupID)) { return MavenCoreUtils.getImplProjectInfoFromProperties(projectName, mProject.getProperties(), mProject.getModel()); } else if (getMavenOrgProviderInstance().getProjectGroupId(SupportedProjectType.CONSUMER) .equals(groupID)) { return MavenCoreUtils.getConsumerProjectInfoFromProperties(projectName, mProject.getProperties(), mProject.getModel()); } else if (getMavenOrgProviderInstance().getProjectGroupId(SupportedProjectType.TYPE_LIBRARY) .equals(groupID)) { // TODO return type library project info // return MavenUtil.getTypeLibraryInfo(mProject); } else if (SOAMavenConstants.SOA_FRAMEWORK_GROUPID.equals(groupID)) { // this could be either the soa framework jars or the client // projects // return MavenUtil.get(projectName, mProject.getProperties(), // mProject.getModel()); } } return null; }
From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java
License:Open Source License
/** * Gets the dependencies.//from w w w .j a v a 2 s.c o m * * @param projectName the project name * @return the dependencies * @throws CoreException the core exception * @throws MavenEclipseApiException the maven eclipse api exception */ public static List<AssetInfo> getDependencies(final String projectName) throws CoreException, MavenEclipseApiException { final List<AssetInfo> result = new ArrayList<AssetInfo>(); final IProject project = WorkspaceUtil.getProject(projectName); if (project != null && project.isAccessible()) { final Model pom = MavenEclipseUtil.readPOM(project); if (pom != null) result.addAll(processDependencies(pom, null)); } else { // the project does not exist, let's find it from the repository final MavenProject mProject = MavenCoreUtils.getLibrary(getLibraryIdentifier(projectName)); final Model pom = mProject.getModel(); if (pom != null) result.addAll(processDependencies(pom, null)); } return result; }
From source file:org.eclipse.che.maven.server.EffectivePomWriter.java
License:Apache License
/** * method from org.apache.maven.plugins.help.EffectivePomMojo * Method for writing the effective pom informations of the current build. * * @param project the project of the current build, not null. * @param writer the XML writer , not null, not null. * @throws MojoExecutionException if any */// www .ja v a2 s . c o m private static void writeEffectivePom(MavenProject project, XMLWriter writer) throws MojoExecutionException { Model pom = project.getModel(); cleanModel(pom); String effectivePom; StringWriter sWriter = new StringWriter(); MavenXpp3Writer pomWriter = new MavenXpp3Writer(); try { pomWriter.write(sWriter, pom); } catch (IOException e) { throw new MojoExecutionException("Cannot serialize POM to XML.", e); } effectivePom = addMavenNamespace(sWriter.toString(), true); writeComment(writer, "Effective POM for project \'" + project.getId() + "\'"); writer.writeMarkup(effectivePom); }
From source file:org.eclipse.che.maven.server.MavenModelUtil.java
License:Open Source License
public static MavenModel convertProjectToModel(MavenProject project, List<DependencyNode> dependencyNodes, File localRepository) {//from ww w . j a va2 s . co m Model model = project.getModel(); return convertModel(model, project.getCompileSourceRoots(), project.getTestCompileSourceRoots(), project.getArtifacts(), project.getExtensionArtifacts(), localRepository); }
From source file:org.eclipse.m2e.core.internal.lifecyclemapping.AnnotationMappingMetadataSource.java
License:Open Source License
private AnnotationMappingMetadataSource(MavenProject project, List<PI> pis) { this.project = project; this.pis = pis; projectId = project.getModel().getLocation(SELF).getSource().getModelId(); }
From source file:org.eclipse.m2e.core.internal.lifecyclemapping.AnnotationMappingMetadataSource.java
License:Open Source License
private static List<PI> parsePIs(MavenProject project) { File pom = project.getFile(); InputSource source = project.getModel().getLocation(SELF).getSource(); List<PI> pis = new ArrayList<>(); XmlPullParser parser = new MXParser(); try (InputStream in = new FileInputStream(pom)) { parser.setInput(ReaderFactory.newXmlReader(in)); Deque<State> stack = new LinkedList<>(); int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { stack.push(new State(parser.getLineNumber(), parser.getColumnNumber())); } else if (eventType == XmlPullParser.END_TAG) { stack.pop();/*from ww w . jav a 2 s. c o m*/ } else if (eventType == XmlPullParser.PROCESSING_INSTRUCTION && !stack.isEmpty()) { String text = parser.getText(); if (text.startsWith("m2e ")) { //$NON-NLS-1$ // found it Xpp3Dom dom = parse(text.substring(4)); if (dom == null) { SourceLocation location = new SourceLocation(source.getLocation(), source.getModelId(), parser.getLineNumber(), parser.getColumnNumber(), text.length() + 4); throw new LifecycleMappingConfigurationException( Messages.AnnotationMappingMetadataSource_UnsupportedInstructionFormat, location); } State s = stack.peek(); PI pi = new PI(s.l, s.c, dom); pis.add(pi); } } eventType = parser.nextToken(); } } catch (XmlPullParserException | IOException ex) { SourceLocation location = new SourceLocation(source.getLocation(), source.getModelId(), parser.getLineNumber(), parser.getColumnNumber(), 1); throw new LifecycleMappingConfigurationException( Messages.AnnotationMappingMetadataSource_ErrorParsingInstruction, location); } return pis; }
From source file:org.eclipse.m2e.core.internal.markers.SourceLocationHelper.java
License:Open Source License
public static SourceLocation findPackagingLocation(MavenProject mavenProject) { InputLocation inputLocation = mavenProject.getModel().getLocation(PACKAGING); if (inputLocation != null) { return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PACKAGING.length() - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); }/*w w w .j a v a 2 s . c o m*/ inputLocation = mavenProject.getModel().getLocation(SELF); return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PROJECT.length() - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); }