List of usage examples for org.apache.maven.project MavenProject getDescription
public String getDescription()
From source file:org.sonar.plugins.maven.MavenProjectConverter.java
License:Open Source License
@VisibleForTesting static void merge(MavenProject pom, ProjectDefinition definition) { String key = getSonarKey(pom); // IMPORTANT NOTE : reference on properties from POM model must not be saved, // instead they should be copied explicitly - see SONAR-2896 definition.setProperties(pom.getModel().getProperties()).setKey(key).setVersion(pom.getVersion()) .setName(pom.getName()).setDescription(pom.getDescription()).addContainerExtension(pom); guessJavaVersion(pom, definition);/*from ww w.ja v a2 s . c om*/ guessEncoding(pom, definition); convertMavenLinksToProperties(definition, pom); synchronizeFileSystem(pom, definition); }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
void merge(MavenProject pom, Properties props) throws MojoExecutionException { defineProjectKey(pom, props);//w w w . j a v a 2 s .c om props.setProperty(ScanProperties.PROJECT_VERSION, pom.getVersion()); props.setProperty(ScanProperties.PROJECT_NAME, pom.getName()); String description = pom.getDescription(); if (description != null) { props.setProperty(ScanProperties.PROJECT_DESCRIPTION, description); } guessJavaVersion(pom, props); guessEncoding(pom, props); convertMavenLinksToProperties(props, pom); props.setProperty("sonar.maven.projectDependencies", dependencyCollector.toJson(pom)); synchronizeFileSystemAndOtherProps(pom, props); findBugsExcludeFileMaven(pom, props); }
From source file:org.wildfly.swarm.plugin.bom.BomBuilder.java
License:Apache License
static String generateBOM(final MavenProject rootProject, final String template, final Collection<DependencyMetadata> bomItems) { return template .replace("#{dependencies}", String.join("\n", bomItems.stream().map(BomBuilder::pomGav).collect(Collectors.toList()))) .replace("#{bom-artifactId}", rootProject.getArtifactId()) .replace("#{bom-name}", rootProject.getName()) .replace("#{bom-description}", rootProject.getDescription()); }
From source file:org.wisdom.maven.utils.MavenUtils.java
License:Apache License
/** * Gets the default set of properties for the given project. * * @param currentProject the project/*from w ww. jav a 2 s . c o m*/ * @return the set of properties, containing default bundle packaging instructions. */ public static Properties getDefaultProperties(MavenProject currentProject) { Properties properties = new Properties(); String bsn = DefaultMaven2OsgiConverter.getBundleSymbolicName(currentProject.getArtifact()); // Setup defaults properties.put(MAVEN_SYMBOLICNAME, bsn); properties.put("bundle.file.name", DefaultMaven2OsgiConverter.getBundleFileName(currentProject.getArtifact())); properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn); properties.put(Analyzer.IMPORT_PACKAGE, "*"); properties.put(Analyzer.BUNDLE_VERSION, DefaultMaven2OsgiConverter.getVersion(currentProject.getVersion())); header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription()); StringBuilder licenseText = printLicenses(currentProject.getLicenses()); if (licenseText != null) { header(properties, Analyzer.BUNDLE_LICENSE, licenseText); } header(properties, Analyzer.BUNDLE_NAME, currentProject.getName()); if (currentProject.getOrganization() != null) { if (currentProject.getOrganization().getName() != null) { String organizationName = currentProject.getOrganization().getName(); header(properties, Analyzer.BUNDLE_VENDOR, organizationName); properties.put("project.organization.name", organizationName); properties.put("pom.organization.name", organizationName); } if (currentProject.getOrganization().getUrl() != null) { String organizationUrl = currentProject.getOrganization().getUrl(); header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl); properties.put("project.organization.url", organizationUrl); properties.put("pom.organization.url", organizationUrl); } } properties.putAll(currentProject.getModel().getProperties()); for (String s : currentProject.getFilters()) { File filterFile = new File(s); if (filterFile.isFile()) { properties.putAll(PropertyUtils.loadProperties(filterFile)); } } properties.putAll(getProperties(currentProject.getModel(), "project.build.")); properties.putAll(getProperties(currentProject.getModel(), "pom.")); properties.putAll(getProperties(currentProject.getModel(), "project.")); properties.put("project.baseDir", currentProject.getBasedir().getAbsolutePath()); properties.put("project.build.directory", currentProject.getBuild().getDirectory()); properties.put("project.build.outputdirectory", currentProject.getBuild().getOutputDirectory()); properties.put("project.source.roots", getArray(currentProject.getCompileSourceRoots())); properties.put("project.testSource.roots", getArray(currentProject.getTestCompileSourceRoots())); properties.put("project.resources", toString(currentProject.getResources())); properties.put("project.testResources", toString(currentProject.getTestResources())); return properties; }
From source file:org.wso2.developerstudio.eclipse.artifact.library.project.export.LibraryArtifactHandler.java
License:Open Source License
public List<IResource> exportArtifact(IProject project) throws Exception { List<IResource> exportResources = new ArrayList<IResource>(); List<String> exportedPackageList = new ArrayList<String>(); List<String> importededPackageList = new ArrayList<String>(); ArchiveManipulator archiveManipulator = new ArchiveManipulator(); NullProgressMonitor nullProgressMonitor = new NullProgressMonitor(); BundlesDataInfo bundleData = new BundlesDataInfo(); IFile bundleDataFile = project.getFile("bundles-data.xml"); File tempProject = createTempProject(); File libResources = createTempDir(tempProject, "lib_resources"); MavenProject mavenProject = MavenUtils.getMavenProject(project.getFile("pom.xml").getLocation().toFile()); if (bundleDataFile.exists()) { bundleData.deserialize(bundleDataFile); for (String lib : bundleData.getExportedPackageListsFromJar().keySet()) { IFile JarFile = project.getFile(lib); if (JarFile.exists()) { archiveManipulator.extract(JarFile.getLocation().toFile(), libResources); exportedPackageList.addAll(bundleData.getExportedPackageListsFromJar().get(lib)); }//from www .j a v a 2 s .c o m } for (IProject lib : bundleData.getExportedPackageListsFromProject().keySet()) { if (lib.isOpen()) { lib.build(IncrementalProjectBuilder.FULL_BUILD, nullProgressMonitor); IJavaProject javaLibProject = JavaCore.create(lib); for (IPackageFragment pkg : javaLibProject.getPackageFragments()) { if (pkg.getKind() == IPackageFragmentRoot.K_SOURCE) { if (pkg.hasChildren()) { exportedPackageList.add(pkg.getElementName()); } } } IPath outPutPath = getOutputPath(javaLibProject); // get resource location IPath resources = getResourcePath(lib); FileUtils.copyDirectoryContents(outPutPath.toFile(), libResources); if (resources.toFile().exists()) { FileUtils.copyDirectoryContents(resources.toFile(), libResources); } } } getPackages(exportedPackageList, mavenProject, "Export-Package"); getPackages(importededPackageList, mavenProject, "Import-Package"); BundleManifest manifest = new BundleManifest(); manifest.setBundleName(project.getName()); manifest.setBundleSymbolicName(project.getName()); if (null != mavenProject.getModel().getDescription() && !"".equals(mavenProject.getModel().getDescription())) { manifest.setBundleDescription(mavenProject.getModel().getDescription()); } else { manifest.setBundleDescription(project.getName()); } if (null != mavenProject.getModel().getVersion() && !"".equals(mavenProject.getDescription())) { manifest.setBundleVersion(mavenProject.getModel().getVersion()); } else { manifest.setBundleVersion("1.0.0"); } if (null != bundleData.getFragmentHost() && !"".equals(bundleData.getFragmentHost())) { manifest.setFragmentHost(bundleData.getFragmentHost()); } manifest.setExportPackagesList(exportedPackageList); if (importededPackageList.size() > 0) { manifest.setImportPackagesList(importededPackageList); manifest.setDynamicImports(false); } File metaInfDir = new File(libResources, "META-INF"); if (!metaInfDir.exists()) metaInfDir.mkdir(); File manifestFile = new File(metaInfDir, "MANIFEST.MF"); FileUtils.createFile(manifestFile, manifest.toString()); File tmpArchive = new File(tempProject, project.getName().concat(".jar")); archiveManipulator.archiveDir(tmpArchive.toString(), libResources.toString()); IFile libArchive = getTargetArchive(project, "jar"); FileUtils.copy(tmpArchive, libArchive.getLocation().toFile()); exportResources.add((IResource) libArchive); // cleaning temp project // if(!org.apache.commons.io.FileUtils.deleteQuietly(tempProject.getLocation().toFile())){ // tempProject.delete(true, getProgressMonitor()); } TempFileUtils.cleanUp(); return exportResources; }
From source file:org.wso2.developerstudio.eclipse.artifact.registry.filter.project.export.RegistryFilterArtifactHandler.java
License:Open Source License
public List<IResource> exportArtifact(IProject project) { List<IResource> exportResources = new ArrayList<IResource>(); List<String> exportedPackageList = new ArrayList<String>(); if (!project.isOpen()) { return exportResources; }/* w w w . j a v a2 s.co m*/ try { ArchiveManipulator archiveManipulator = new ArchiveManipulator(); NullProgressMonitor nullProgressMonitor = new NullProgressMonitor(); //cleaning target directory clearTarget(project); //getting maven details MavenProject mavenProject = MavenUtils .getMavenProject(project.getFile("pom.xml").getLocation().toFile()); // First compile the code project.build(IncrementalProjectBuilder.FULL_BUILD, nullProgressMonitor); // Get the output location IJavaProject javaProject = JavaCore.create(project); IPath outPutPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(javaProject.getOutputLocation()) .getLocation(); // get resource location IPath resources = project.getFolder("src" + File.separator + "main" + File.separator + "resources") .getLocation(); // getting export packages for (IPackageFragment pkg : javaProject.getPackageFragments()) { if (pkg.getKind() == IPackageFragmentRoot.K_SOURCE) { if (pkg.hasChildren()) { exportedPackageList.add(pkg.getElementName()); } } } IProject tempProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(".temp" + System.currentTimeMillis()); tempProject.create(nullProgressMonitor); tempProject.open(nullProgressMonitor); tempProject.setHidden(true); org.eclipse.osgi.storagemanager.StorageManager manager = new StorageManager( tempProject.getLocation().toFile(), "false"); File filterResources = manager.createTempFile("filter_resources"); filterResources.delete(); filterResources.mkdir(); FileUtils.copyDirectoryContents(outPutPath.toFile(), filterResources); // copy binaries if (resources.toFile().exists()) { FileUtils.copyDirectoryContents(resources.toFile(), filterResources); // copy resources } /* writing manifest */ BundleManifest manifest = new BundleManifest(); manifest.setBundleName(project.getName()); manifest.setBundleSymbolicName(project.getName()); if (null != mavenProject.getModel().getDescription() && !"".equals(mavenProject.getModel().getDescription())) { manifest.setBundleDescription(mavenProject.getModel().getDescription()); } else { manifest.setBundleDescription(project.getName()); } if (null != mavenProject.getModel().getVersion() && !"".equals(mavenProject.getDescription())) { manifest.setBundleVersion(mavenProject.getModel().getVersion()); } else { manifest.setBundleVersion("1.0.0"); } manifest.setExportPackagesList(exportedPackageList); File metaInfDir = new File(filterResources, "META-INF"); if (!metaInfDir.exists()) metaInfDir.mkdir(); File manifestFile = new File(metaInfDir, "MANIFEST.MF"); FileUtils.createFile(manifestFile, manifest.toString()); File tmpArchive = new File(tempProject.getLocation().toFile(), project.getName().concat(".jar")); archiveManipulator.archiveDir(tmpArchive.toString(), filterResources.toString()); IFolder binaries = project.getFolder("target"); if (!binaries.exists()) { binaries.create(true, false, nullProgressMonitor); binaries.setHidden(true); } IFile bundleArchive = project.getFile("target/" + project.getName().concat(".jar")); FileUtils.copy(tmpArchive, bundleArchive.getLocation().toFile()); exportResources.add((IResource) bundleArchive); // cleaning temp project tempProject.delete(true, nullProgressMonitor); } catch (Exception e) { e.printStackTrace(); } return exportResources; }
From source file:org.wso2.developerstudio.eclipse.artifact.registry.handler.project.export.RegistryHandlerArtifactHandler.java
License:Open Source License
public List<IResource> exportArtifact(IProject project) throws Exception { List<IResource> exportResources = new ArrayList<IResource>(); List<String> exportedPackageList = new ArrayList<String>(); String activatorClass = new String(); String existingActivatorClass = new String(); ArchiveManipulator archiveManipulator = new ArchiveManipulator(); // getting maven details MavenProject mavenProject = MavenUtils.getMavenProject(project.getFile("pom.xml").getLocation().toFile()); // Get the output location IJavaProject javaProject = JavaCore.create(project); clearTarget(project);//ww w . j a va2s . co m IPath outPutPath = buildJavaProject(project); // get resource location IPath resources = getResourcePath(project); // getting export packages for (IPackageFragment pkg : javaProject.getPackageFragments()) { if (pkg.getKind() == IPackageFragmentRoot.K_SOURCE) { if (pkg.hasChildren()) { exportedPackageList.add(pkg.getElementName()); for (ICompilationUnit compilationUnit : pkg.getCompilationUnits()) { IType[] types = compilationUnit.getTypes(); for (IType type : types) { if (type.getSuperInterfaceNames().length > 0 && Arrays.asList(type.getSuperInterfaceNames()).contains("BundleActivator")) { activatorClass = type.getFullyQualifiedName(); } } } } } } List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if ("maven-bundle-plugin".equalsIgnoreCase(plugin.getArtifactId())) { Xpp3Dom configurationNode = (Xpp3Dom) plugin.getConfiguration(); Xpp3Dom[] instructions = configurationNode.getChildren("instructions"); if (instructions.length == 1) { Xpp3Dom[] exportPackage = instructions[0].getChildren("Export-Package"); if (exportPackage.length == 1) { exportedPackageList.clear(); //clear default configuration (All packages by default) String packages = exportPackage[0].getValue(); if (packages != null) { exportedPackageList.addAll(Arrays.asList(packages.split(","))); } } else { log.warn("Invalid configuration for <Export-Package> entry" + " using default configuration for <Export-Package>"); } } else { log.warn("Invalid instructions configuration for plugin : maven-bundle-plugin" + " using default configuration for <Export-Package>"); } break; //not considering multiple versions of the maven-bundle-plugin } } File tempProject = createTempProject(); File bundleResources = createTempDir(tempProject, "bundle_resources"); if (exportedPackageList.size() > 0) { FileUtils.copyDirectoryContents(outPutPath.toFile(), bundleResources); // copy // binaries } if (resources.toFile().exists()) { FileUtils.copyDirectoryContents(resources.toFile(), bundleResources); // copy // resources } @SuppressWarnings("unchecked") List<Dependency> dependencies = mavenProject.getDependencies(); Iterator<Dependency> iterator = dependencies.iterator(); while (iterator.hasNext()) { Dependency dependency = iterator.next(); if ("system".equals(dependency.getScope())) { String systemPath = dependency.getSystemPath(); if (systemPath != null && !systemPath.trim().isEmpty()) { systemPath = systemPath.replaceAll("^".concat(Pattern.quote("${basedir}/")), ""); IFile jarFile = project.getFile(systemPath); if (jarFile.exists()) { archiveManipulator.extract(jarFile.getLocation().toFile(), bundleResources); // getting export packages IPackageFragmentRoot rootPkg = JavaCore.createJarPackageFragmentRootFrom(jarFile); for (IJavaElement item : rootPkg.getChildren()) { if (item instanceof IPackageFragment) { IPackageFragment pkg = (IPackageFragment) item; if (pkg.hasChildren()) { exportedPackageList.add(pkg.getElementName()); for (IClassFile clazz : pkg.getClassFiles()) { IType type = clazz.getType(); if (type.getSuperInterfaceNames().length > 0 && Arrays .asList(type.getSuperInterfaceNames()).contains(ACTIVATOR_FQN)) { existingActivatorClass = type.getFullyQualifiedName(); } } } } } } } } } if (activatorClass.trim().isEmpty()) { activatorClass = existingActivatorClass; } /* writing manifest */ BundleManifest manifest = new BundleManifest(); manifest.setBundleName(project.getName()); manifest.setBundleSymbolicName(project.getName()); if (null != mavenProject.getModel().getDescription() && !"".equals(mavenProject.getModel().getDescription())) { manifest.setBundleDescription(mavenProject.getModel().getDescription()); } else { manifest.setBundleDescription(project.getName()); } if (null != mavenProject.getModel().getVersion() && !"".equals(mavenProject.getDescription())) { manifest.setBundleVersion(mavenProject.getModel().getVersion()); } else { manifest.setBundleVersion("1.0.0"); } manifest.setBundleActivatorName(activatorClass); manifest.setExportPackagesList(exportedPackageList); File metaInfDir = new File(bundleResources, "META-INF"); if (!metaInfDir.exists()) metaInfDir.mkdir(); File manifestFile = new File(metaInfDir, "MANIFEST.MF"); FileUtils.createFile(manifestFile, manifest.toString()); File tmpArchive = new File(tempProject, project.getName().concat(".jar")); archiveManipulator.archiveDir(tmpArchive.toString(), bundleResources.toString()); IFile bundleArchive = getTargetArchive(project, "jar"); FileUtils.copy(tmpArchive, bundleArchive.getLocation().toFile()); exportResources.add((IResource) bundleArchive); TempFileUtils.cleanUp(); return exportResources; }
From source file:se.natusoft.tools.codelicmgr.MojoUtils.java
License:Open Source License
/** * This will take config values that are not specified or specified as blank and * look for that information elsewhere in the maven project and if found, update * the configuration with that information. * <p>/*from w w w .ja v a 2 s.c om*/ * The reason for this is to minimize duplication of information in the pom. Some * of the information managed by CodeLicenseManager is also available as standard * information in a pom and is used by site:site to generate documentation. * * @param project The CLM project config. * @param mavenProject Maven project info from pom. */ public static ProjectConfig updateConfigFromMavenProject(ProjectConfig project, MavenProject mavenProject) { // Project if (project == null) { // Will be null if no <project> tag is specified! project = new ProjectConfig(); } if (isEmpty(project.getName())) { project.setName(getFirstNonEmpty(mavenProject.getName(), mavenProject.getArtifactId())); } if (isEmpty(project.getDescription())) { project.setDescription(mavenProject.getDescription()); } // License LicenseConfig licenseConf = project.getLicense(); if (licenseConf == null) { licenseConf = new LicenseConfig(); project.setLicense(licenseConf); } if (licenseConf.getType() == null) { List<org.apache.maven.model.License> lics = mavenProject.getLicenses(); if (lics != null && lics.size() >= 1) { org.apache.maven.model.License lic = lics.get(0); String licName = getLicenseName(lic.getName().replaceAll("-", " ")); if (licName.trim().length() > 0) { licenseConf.setType(licName); } String licVer = getLicenseVersion(lic.getName().replaceAll("-", " ")); if (licVer.trim().length() > 0) { licenseConf.setVersion(licVer); } } } // Copyright if (project.getCopyrights().getCopyrights().size() == 0) { CopyrightConfig copyrightConf = new CopyrightConfig(); copyrightConf.setHolder(mavenProject.getOrganization().getName()); copyrightConf.setYear(mavenProject.getInceptionYear()); project.getCopyrights().addCopyright(copyrightConf); } return project; }