List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.sonar.updatecenter.deprecated.UpdateCenter.java
License:Open Source License
private History<Plugin> resolvePluginHistory(String id) throws Exception { String groupId = StringUtils.substringBefore(id, ":"); String artifactId = StringUtils.substringAfter(id, ":"); Artifact artifact = artifactFactory.createArtifact(groupId, artifactId, Artifact.LATEST_VERSION, Artifact.SCOPE_COMPILE, ARTIFACT_JAR_TYPE); List<ArtifactVersion> versions = filterSnapshots( metadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories)); History<Plugin> history = new History<Plugin>(); for (ArtifactVersion version : versions) { Plugin plugin = org.sonar.updatecenter.deprecated.Plugin .extractMetadata(resolve(artifact.getGroupId(), artifact.getArtifactId(), version.toString())); history.addArtifact(version, plugin); MavenProject project = mavenProjectBuilder .buildFromRepository(/* w w w. j a v a2 s. c o m*/ artifactFactory.createArtifact(groupId, artifactId, version.toString(), Artifact.SCOPE_COMPILE, ARTIFACT_POM_TYPE), remoteRepositories, localRepository); if (plugin.getVersion() == null) { // Legacy plugin - set default values plugin.setKey(project.getArtifactId()); plugin.setName(project.getName()); plugin.setVersion(project.getVersion()); String sonarVersion = "1.10"; // TODO Is it minimal version for all extension points ? for (Dependency dependency : project.getDependencies()) { if ("sonar-plugin-api".equals(dependency.getArtifactId())) { // TODO dirty hack sonarVersion = dependency.getVersion(); } } plugin.setRequiredSonarVersion(sonarVersion); plugin.setHomepage(project.getUrl()); } plugin.setDownloadUrl(getPluginDownloadUrl(groupId, artifactId, plugin.getVersion())); // There is no equivalent for following properties in MANIFEST.MF if (project.getIssueManagement() != null) { plugin.setIssueTracker(project.getIssueManagement().getUrl()); } else { System.out.println("Unknown Issue Management for " + plugin.getKey() + ":" + plugin.getVersion()); } if (project.getScm() != null) { String scmUrl = project.getScm().getUrl(); if (StringUtils.startsWith(scmUrl, "scm:")) { scmUrl = StringUtils.substringAfter(StringUtils.substringAfter(scmUrl, ":"), ":"); } plugin.setSources(scmUrl); } else { System.out.println("Unknown SCM for " + plugin.getKey() + ":" + plugin.getVersion()); } if (project.getLicenses() != null && project.getLicenses().size() > 0) { plugin.setLicense(project.getLicenses().get(0).getName()); } else { System.out.println("Unknown License for " + plugin.getKey() + ":" + plugin.getVersion()); } if (project.getDevelopers().size() > 0) { plugin.setDevelopers(project.getDevelopers()); } else { System.out.println("Unknown Developers for " + plugin.getKey() + ":" + plugin.getVersion()); } } return history; }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static void rebuildModuleHierarchy(Properties properties, Map<MavenProject, Properties> propsByModule, MavenProject current, String prefix) throws IOException { Properties currentProps = propsByModule.get(current); if (currentProps == null) { throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); }/*from www. ja v a 2s . c o m*/ for (Map.Entry<Object, Object> prop : currentProps.entrySet()) { properties.put(prefix + prop.getKey(), prop.getValue()); } propsByModule.remove(current); List<String> moduleIds = new ArrayList<>(); for (String modulePathStr : current.getModules()) { File modulePath = new File(current.getBasedir(), modulePathStr); MavenProject module = findMavenProject(modulePath, propsByModule.keySet()); if (module != null) { String moduleId = module.getGroupId() + ":" + module.getArtifactId(); rebuildModuleHierarchy(properties, propsByModule, module, prefix + moduleId + "."); moduleIds.add(moduleId); } } if (!moduleIds.isEmpty()) { properties.put(prefix + "sonar.modules", StringUtils.join(moduleIds, SEPARATOR)); } }
From source file:org.sonatype.flexmojos.htmlwrapper.HtmlWrapperMojo.java
License:Apache License
private void init() { /*/* ww w . ja v a 2 s .c o m*/ * If sourceProject is defined, then parameters are from an external project and that project (sourceProject) * should be used as reference for default values rather than this project. */ MavenProject project = this.project; if (sourceProject != null) { project = sourceProject; } if (parameters == null) { parameters = new HashMap<String, String>(); } if (!parameters.containsKey("title")) { parameters.put("title", project.getName()); } String[] nodes = targetPlayer != null ? targetPlayer.split("\\.") : new String[] { "9", "0", "0" }; if (!parameters.containsKey("version_major")) { parameters.put("version_major", nodes[0]); } if (!parameters.containsKey("version_minor")) { parameters.put("version_minor", nodes[1]); } if (!parameters.containsKey("version_revision")) { parameters.put("version_revision", nodes[2]); } if (!parameters.containsKey("swf")) { parameters.put("swf", project.getBuild().getFinalName()); } if (!parameters.containsKey("width")) { parameters.put("width", "100%"); } if (!parameters.containsKey("height")) { parameters.put("height", "100%"); } if (!parameters.containsKey("application")) { parameters.put("application", project.getArtifactId()); } if (!parameters.containsKey("bgcolor")) { parameters.put("bgcolor", "#869ca7"); } }
From source file:org.sonatype.flexmojos.war.CopyMojo.java
License:Apache License
private List<Artifact> getRuntimeLocalesDependencies(MavenProject artifactProject) { String[] runtimeLocales = CompileConfigurationLoader.getCompilerPluginSettings(artifactProject, "runtimeLocales"); if (runtimeLocales == null || runtimeLocales.length == 0) { return Collections.emptyList(); }//www . ja va 2 s . c o m List<Artifact> artifacts = new ArrayList<Artifact>(); for (String locale : runtimeLocales) { artifacts.add(artifactFactory.createArtifactWithClassifier(artifactProject.getGroupId(), artifactProject.getArtifactId(), artifactProject.getVersion(), SWF, locale)); } return artifacts; }
From source file:org.sonatype.m2e.webby.internal.build.WebbyBuildParticipant.java
License:Open Source License
private void addConfigurationError(MavenProject mvnProject, String msg) { File pomFile = mvnProject.getFile(); int line = 0; int column = 0; InputLocation location = new WarConfigurationExtractor().getConfigurationLocation(mvnProject); if (location != null && location.getSource() != null) { String modelId = mvnProject.getGroupId() + ":" + mvnProject.getArtifactId() + ':' + mvnProject.getVersion(); if (location.getSource().getModelId().equals(modelId)) { line = location.getLineNumber(); column = location.getColumnNumber(); }// w w w.j ava 2 s.co m } BuildContext buildContext = getBuildContext(); buildContext.addMessage(pomFile, line, column, msg, BuildContext.SEVERITY_ERROR, null); }
From source file:org.sonatype.m2e.webby.internal.launch.WebbyLaunchDelegate.java
License:Open Source License
@Override public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { SubMonitor pm = SubMonitor.convert(monitor, 100); try {//from w ww . ja va2 s. c o m IJavaProject javaProject = verifyJavaProject(configuration); IMavenProjectFacade mvnFacade = MavenUtils.getFacade(javaProject.getProject()); MavenProject mvnProject = mvnFacade.getMavenProject(pm.newChild(10)); IMaven mvn = MavenPlugin.getMaven(); MavenExecutionRequest mvnRequest = mvn.createExecutionRequest(pm.newChild(10)); MavenSession mvnSession = mvn.createSession(mvnRequest, mvnProject); WarConfiguration warConfig = new WarConfigurationExtractor().getConfiguration(mvnFacade, mvnProject, mvnSession, pm.newChild(10)); WarClasspath warClasspath = new WarClasspath(); new WarClasspathPopulator().populate(warClasspath, mvnProject, warConfig, true, pm.newChild(30)); File workDir = new File(warConfig.getWorkDirectory()); CargoConfiguration cargo = new CargoConfiguration(); cargo.setWorkDirectory(workDir); cargo.setWarDirectory(new File(warConfig.getWarDirectory())); cargo.setRuntimeClasspath(toClasspath(warClasspath.getRuntimeClasspath())); cargo.setProvidedClasspath(toClasspath(warClasspath.getProvidedClasspath())); cargo.setContextName(configuration.getAttribute(WebbyLaunchConstants.ATTR_CONTEXT_NAME, "")); if (cargo.getContextName().length() <= 0) { cargo.setContextName(mvnProject.getArtifactId()); } cargo.setContainerId(configuration.getAttribute(WebbyLaunchConstants.ATTR_CONTAINER_ID, "jetty7x")); cargo.setContainerType(ContainerType .toType(configuration.getAttribute(WebbyLaunchConstants.ATTR_CONTAINER_TYPE, "embedded"))); cargo.setContainerHome(configuration.getAttribute(WebbyLaunchConstants.ATTR_CONTAINER_HOME, "")); cargo.setContainerHome(expandVariables(cargo.getContainerHome())); cargo.setConfigHome(new File(workDir, "container").getAbsolutePath()); cargo.setConfigType(ConfigurationType.STANDALONE); cargo.setLogLevel(configuration.getAttribute(WebbyLaunchConstants.ATTR_LOG_LEVEL, "medium")); try { cargo.setPort(Integer .toString(configuration.getAttribute(WebbyLaunchConstants.ATTR_CONTAINER_PORT, 8080))); } catch (CoreException e) { cargo.setPort(configuration.getAttribute(WebbyLaunchConstants.ATTR_CONTAINER_PORT, "8080")); } cargo.setTimeout(configuration.getAttribute(WebbyLaunchConstants.ATTR_CONTAINER_TIMEOUT, 60) * 1000); if (!cargo.getWarDirectory().exists()) { throw WebbyPlugin.newError( "WAR base directory " + cargo.getWarDirectory() + " does not exist, please ensure your workspace is refreshed and has been built", null); } MessageConsole console = ConsoleManager.getConsole(); console.clearConsole(); MessageConsoleStream mcs = console.newMessageStream(); mcs.println("Runtime classpath:"); for (File file : warClasspath.getRuntimeClasspath()) { mcs.println(" " + file); } mcs.println("Provided classpath:"); for (File file : warClasspath.getProvidedClasspath()) { mcs.println(" " + file); } try { mcs.close(); } catch (IOException e) { WebbyPlugin.log(e); } IWebApp webApp; if (ContainerType.EMBEDDED.equals(cargo.getContainerType())) { webApp = launchEmbedded(cargo, configuration, mode, launch, pm.newChild(40)); } else { webApp = launchInstalled(cargo, configuration, mode, launch, pm.newChild(40)); } WebbyPlugin.getDefault().getWebAppRegistry().addWebApp(webApp); } finally { if (monitor != null) { monitor.done(); } } }
From source file:org.sonatype.nexus.maven.staging.AbstractStagingMojo.java
License:Open Source License
protected String getRootProjectGav() { final MavenProject rootProject = getFirstProjectWithThisPluginDefined(); if (rootProject != null) { return rootProject.getGroupId() + ":" + rootProject.getArtifactId() + ":" + rootProject.getVersion(); } else {//from w w w.ja v a 2 s . com return "unknown"; } }
From source file:org.sonatype.nexus.plugin.deploy.AbstractDeployMojo.java
License:Open Source License
protected String beforeUpload() throws ArtifactDeploymentException { if (deployUrl != null) { getLog().info("Performing normal upload against URL: " + deployUrl); return deployUrl; } else if (nexusUrl != null) { try {//from w ww . j a va 2 s . c om getLog().info("Initiating staging against Nexus on URL " + nexusUrl); createStageClient(); final MavenProject currentProject = mavenSession.getCurrentProject(); // if profile is not "targeted", perform a match and save the result if (StringUtils.isBlank(stagingProfileId)) { stagingProfileId = stageClient.getStageProfileForUser(currentProject.getGroupId(), currentProject.getArtifactId(), currentProject.getVersion()); getLog().info("Using staging profile ID \"" + stagingProfileId + "\" (matched by Nexus)."); } else { getLog().info("Using staging profile ID \"" + stagingProfileId + "\" (configured by user)."); } if (StringUtils.isBlank(stagingRepositoryId)) { stagingRepositoryId = stageClient.startRepository(stagingProfileId, "Started by nexus-maven-plugin", tags); // store the one just created for us, as it means we need to "babysit" it (close or drop, depending // on outcome) createdStagingRepositoryId = stagingRepositoryId; if (tags != null && !tags.isEmpty()) { getLog().info("Created staging repository with ID \"" + stagingRepositoryId + "\", applied tags: " + tags); } else { getLog().info("Created staging repository with ID \"" + stagingRepositoryId + "\"."); } } else { createdStagingRepositoryId = null; getLog().info("Using preconfigured staging repository with ID \"" + stagingRepositoryId + "\" (we are NOT managing it)."); // we will not close it! This might be created by some // other automated component } return concat(nexusUrl, "/service/local/staging/deployByRepositoryId", stagingRepositoryId); } catch (RESTLightClientException e) { throw new ArtifactDeploymentException("Error before upload while managing staging repository!", e); } } else { throw new ArtifactDeploymentException("No deploy URL set, nor Nexus BaseURL given!"); } }
From source file:org.sourcepit.b2.maven.core.B2MavenBridge.java
License:Apache License
public static URI toArtifactURI(MavenProject project, String type, String classifier) { final StringBuilder sb = new StringBuilder(); sb.append(project.getGroupId());/* www . j a v a2s . com*/ sb.append("/"); sb.append(project.getArtifactId()); sb.append("/"); sb.append(type); if (classifier != null && classifier.length() > 0) { sb.append("/"); sb.append(classifier); } sb.append("/"); sb.append(project.getVersion()); return URI.createURI("gav:/" + sb.toString()); }
From source file:org.sourcepit.b2.p2.MavenDependenciesSiteGenerator.java
License:Apache License
public void preInterpolation(AbstractModule module, final PropertiesSource moduleProperties) { final MavenSession session = legacySupport.getSession(); final MavenProject project = session.getCurrentProject(); final List<Dependency> dependencies = new ArrayList<Dependency>(filter(project.getDependencies(), JARS)); if (!dependencies.isEmpty()) { final IInterpolationLayout layout = layoutManager.getLayout(module.getLayoutId()); final File siteDir = new File(layout.pathOfMetaDataFile(module, "maven-dependencies")); final String repositoryName = "maven-dependencies@" + project.getArtifactId(); final List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories(); final ArtifactRepository localRepository = session.getLocalRepository(); final Date startTime = session.getStartTime(); final String pattern = moduleProperties.get("osgifier.updateSiteBundles"); final PathMatcher bundleMatcher = pattern == null ? null : PathMatcher.parsePackagePatterns(pattern); BundleSelector bundleSelector = new AbstractBundleTreeSelector() { @Override/*w w w . j a va2s . c om*/ public Collection<BundleCandidate> selectRootBundles(OsgifierContext bundleContext) { final DependencyModel dependencyModel = bundleContext.getExtension(DependencyModel.class); final Map<ArtifactKey, BundleCandidate> artifactKeyToBundle = new HashMap<ArtifactKey, BundleCandidate>(); for (BundleCandidate bundle : bundleContext.getBundles()) { artifactKeyToBundle.put(getArtifactKey(bundle), bundle); } final List<BundleCandidate> rootBundles = new ArrayList<BundleCandidate>(); for (MavenArtifact artifact : dependencyModel.getRootArtifacts()) { final BundleCandidate rootBundle = artifactKeyToBundle.get(artifact.getArtifactKey()); if (rootBundle != null && select(rootBundle)) { rootBundles.add(rootBundle); } } return rootBundles; } private ArtifactKey getArtifactKey(BundleCandidate bundle) { return bundle.getExtension(MavenArtifact.class).getArtifactKey(); } @Override public boolean select(Stack<BundleCandidate> path, BundleReference reference) { return !reference.isOptional() && super.select(path, reference); } @Override protected boolean select(BundleCandidate bundle) { return bundleMatcher == null || bundleMatcher.isMatch(bundle.getSymbolicName()); } }; final OsgifierContext bundleContext = updateSiteGenerator.generateUpdateSite(siteDir, dependencies, true, remoteRepositories, localRepository, repositoryName, moduleProperties, startTime, bundleSelector); try { module.setAnnotationData("b2.mavenDependencies", "repositoryURL", siteDir.toURI().toURL().toExternalForm()); } catch (MalformedURLException e) { throw pipe(e); } module.setAnnotationData("b2.mavenDependencies", "repositoryName", repositoryName); final Collection<BundleCandidate> selectedBundles = new LinkedHashSet<BundleCandidate>(); selectBundles(selectedBundles, bundleContext, bundleSelector); interpolatePlugins(module, moduleProperties, selectedBundles); } }