List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.commonjava.maven.plugins.betterdep.AbstractDepgraphGoal.java
License:Open Source License
protected void readFromReactorProjects() throws MojoExecutionException { getLog().info("Initializing direct graph relationships from reactor projects: " + projects); for (final MavenProject project : projects) { final List<Profile> activeProfiles = project.getActiveProfiles(); if (activeProfiles != null) { for (final Profile profile : activeProfiles) { profiles.add(RelationshipUtils.profileLocation(profile.getId())); }/*from w w w . jav a2 s . com*/ } final ProjectVersionRef projectRef = new SimpleProjectVersionRef(project.getGroupId(), project.getArtifactId(), project.getVersion()); roots.add(projectRef); final List<Dependency> deps = project.getDependencies(); // final List<ProjectVersionRef> roots = new ArrayList<ProjectVersionRef>( deps.size() ); URI localUri; try { localUri = new URI(MavenLocationExpander.LOCAL_URI); } catch (final URISyntaxException e) { throw new MojoExecutionException( "Failed to construct dummy local URI to use as the source of the current project in the depgraph: " + e.getMessage(), e); } final int index = 0; for (final Dependency dep : deps) { final ProjectVersionRef depRef = new SimpleProjectVersionRef(dep.getGroupId(), dep.getArtifactId(), dep.getVersion()); // roots.add( depRef ); final List<Exclusion> exclusions = dep.getExclusions(); final List<ProjectRef> excludes = new ArrayList<ProjectRef>(); if (exclusions != null && !exclusions.isEmpty()) { for (final Exclusion exclusion : exclusions) { excludes.add(new SimpleProjectRef(exclusion.getGroupId(), exclusion.getArtifactId())); } } rootRels.add(new SimpleDependencyRelationship(localUri, projectRef, new SimpleArtifactRef(depRef, dep.getType(), dep.getClassifier(), dep.isOptional()), DependencyScope.getScope(dep.getScope()), index, false, excludes.toArray(new ProjectRef[excludes.size()]))); } final DependencyManagement dm = project.getDependencyManagement(); if (dm != null) { final List<Dependency> managed = dm.getDependencies(); int i = 0; for (final Dependency dep : managed) { if ("pom".equals(dep.getType()) && "import".equals(dep.getScope())) { final ProjectVersionRef depRef = new SimpleProjectVersionRef(dep.getGroupId(), dep.getArtifactId(), dep.getVersion()); rootRels.add(new SimpleBomRelationship(localUri, projectRef, depRef, i++)); } } } ProjectVersionRef lastParent = projectRef; MavenProject parent = project.getParent(); while (parent != null) { final ProjectVersionRef parentRef = new SimpleProjectVersionRef(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); rootRels.add(new SimpleParentRelationship(localUri, projectRef, parentRef)); lastParent = parentRef; parent = parent.getParent(); } rootRels.add(new SimpleParentRelationship(lastParent)); } }
From source file:org.commonjava.maven.plugins.execroot.ProjectRef.java
License:Apache License
public boolean matches(final MavenProject project) { return project.getGroupId().equals(groupId) && project.getArtifactId().equals(artifactId); }
From source file:org.commonjava.poc.ral.AppLauncher.java
License:Open Source License
public AppLauncher(final Options options) throws AppLauncherException { setupLogging(Level.INFO);/*w ww . ja v a 2s. c o m*/ this.options = options; try { load(); } catch (MAEException e) { throw new AppLauncherException("Failed to initialize MAE subsystem: %s", e, e.getMessage()); } SimpleProjectToolsSession session = new SimpleProjectToolsSession(); session.setPomValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); session.setDependencySelector( new FlexibleScopeDependencySelector(org.apache.maven.artifact.Artifact.SCOPE_TEST, org.apache.maven.artifact.Artifact.SCOPE_PROVIDED).setTransitive(true)); MavenProject project = loadProject(options.coordinate, session); DependencyGraph depGraph = resolveDependencies(project, session); List<URL> urls = new ArrayList<URL>(); try { ArtifactResult result = repositorySystem.resolveArtifact(session.getRepositorySystemSession(), new ArtifactRequest(RepositoryUtils.toArtifact(project.getArtifact()), session.getRemoteRepositoriesForResolution(), null)); mainJar = result.getArtifact().getFile().toURI().normalize().toURL(); urls.add(mainJar); } catch (ArtifactResolutionException e) { throw new AppLauncherException("Failed to resolve main project artifact: %s. Reason: %s", e, project.getId(), e.getMessage()); } catch (MalformedURLException e) { throw new AppLauncherException("Cannot format classpath URL from: %s. Reason: %s", e, project.getId(), e.getMessage()); } for (DepGraphNode node : depGraph) { try { ArtifactResult result = node.getLatestResult(); if (result == null) { if (node.getKey() .equals(key(project.getGroupId(), project.getArtifactId(), project.getVersion()))) { continue; } else { throw new AppLauncherException("Failed to resolve: %s", node.getKey()); } } Artifact artifact = result.getArtifact(); File file = artifact.getFile(); URL url = file.toURI().normalize().toURL(); urls.add(url); } catch (MalformedURLException e) { throw new AppLauncherException("Cannot format classpath URL from: %s. Reason: %s", e, node.getKey(), e.getMessage()); } } classLoader = new URLClassLoader(urls.toArray(new URL[] {}), ClassLoader.getSystemClassLoader()); }
From source file:org.commonjava.sjbi.maven3.builder.M3BuildResult.java
License:Open Source License
M3BuildResult(final MavenExecutionResult mavenResult) { if (mavenResult.hasExceptions()) { setErrors(mavenResult.getExceptions()); }/*from w ww. jav a2 s .c o m*/ final List<ArtifactSetRef> ars = new ArrayList<ArtifactSetRef>(); for (final MavenProject project : mavenResult.getTopologicallySortedProjects()) { final ProjectRef pr = new ProjectRef(project.getGroupId(), project.getArtifactId(), project.getVersion()); pr.setPomFile(project.getFile()); final ArtifactSetRef ar = new ArtifactSetRef(pr); final Artifact mainArtifact = project.getArtifact(); ar.addArtifactRef(mainArtifact.getType(), mainArtifact.getClassifier(), mainArtifact.getFile()); for (final Artifact a : project.getAttachedArtifacts()) { ar.addArtifactRef(a.getType(), a.getClassifier(), a.getFile()); } ars.add(ar); } setArtifactSets(ars); }
From source file:org.commonjava.tensor.maven.plugin.LogProjectBuildroot.java
License:Apache License
@Override public void execute() throws MojoExecutionException { if (isThisTheExecutionRoot()) { final ModuleAssociations moduleAssoc = new ModuleAssociations( new ProjectVersionRef(project.getGroupId(), project.getArtifactId(), project.getVersion())); for (final MavenProject p : projects) { moduleAssoc.addModule(new ProjectVersionRef(p.getGroupId(), p.getArtifactId(), p.getVersion())); }/*from ww w . j a v a 2 s. co m*/ final TensorSerializerProvider prov = new TensorSerializerProvider( new EGraphManager(new JungEGraphDriver()), new GraphWorkspaceHolder()); final JsonSerializer serializer = prov.getTensorSerializer(); final String json = serializer.toString(moduleAssoc); final DefaultHttpClient client = new DefaultHttpClient(); try { final HttpPut request = new HttpPut(getUrl()); request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); request.setEntity(new StringEntity(json)); final HttpResponse response = client.execute(request); final StatusLine sl = response.getStatusLine(); if (sl.getStatusCode() != HttpStatus.SC_CREATED) { throw new MojoExecutionException("Failed to publish module-artifact association data: " + sl.getStatusCode() + " " + sl.getReasonPhrase()); } } catch (final UnsupportedEncodingException e) { throw new MojoExecutionException( "Failed to publish module-artifact association data; invalid encoding for JSON: " + e.getMessage(), e); } catch (final ClientProtocolException e) { throw new MojoExecutionException( "Failed to publish module-artifact association data; http request failed: " + e.getMessage(), e); } catch (final IOException e) { throw new MojoExecutionException( "Failed to publish module-artifact association data; http request failed: " + e.getMessage(), e); } } }
From source file:org.debian.dependency.ProjectArtifactSpy.java
License:Apache License
@Override public void onEvent(final Object event) { if (!(event instanceof ExecutionEvent)) { return;// w w w . ja v a 2 s. com } ExecutionEvent execEvent = (ExecutionEvent) event; if (!Type.ProjectSucceeded.equals(execEvent.getType()) && !Type.ForkedProjectSucceeded.equals(execEvent.getType())) { return; } MavenProject project = execEvent.getProject(); Artifact pomArtifact = repoSystem.createProjectArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion()); pomArtifact.setFile(project.getFile()); // the first project should always be the top-level project if (outputFile == null) { outputFile = new File(project.getBuild().getDirectory(), ServicePackage.PROJECT_ARTIFACT_REPORT_NAME); } recordArtifact(pomArtifact); recordArtifact(project.getArtifact()); for (Artifact artifact : project.getAttachedArtifacts()) { recordArtifact(artifact); } }
From source file:org.debian.maven.packager.GenerateDebianFilesMojo.java
License:Apache License
private void setupArtifactLocation(ListOfPOMs listOfPOMs, ListOfPOMs listOfJavadocPOMs, MavenProject mavenProject) { String dirRelPath = new WrappedProject(project, mavenProject).getBaseDir(); if (!"pom".equals(mavenProject.getPackaging())) { String pomFile = dirRelPath + "pom.xml"; listOfPOMs.getOrCreatePOMOptions(pomFile).setJavaLib(true); String extension = mavenProject.getPackaging(); if (extension.equals("bundle")) { extension = "jar"; }/*from ww w. j a va 2 s.c o m*/ if (extension.equals("webapp")) { extension = "war"; } if (mavenProject.getArtifact() != null && mavenProject.getArtifact().getFile() != null) { extension = mavenProject.getArtifact().getFile().toString(); extension = extension.substring(extension.lastIndexOf('.') + 1); } POMOptions pomOptions = listOfPOMs.getOrCreatePOMOptions(pomFile); pomOptions.setArtifact(dirRelPath + "target/" + mavenProject.getArtifactId() + "-*." + extension); if ("jar".equals(extension) && generateJavadoc && "ant".equals(packageType) && listOfJavadocPOMs != null) { String artifactId = mavenProject.getArtifact().getArtifactId(); POMOptions javadocPomOptions = listOfJavadocPOMs.getOrCreatePOMOptions(pomFile); javadocPomOptions.setIgnorePOM(true); javadocPomOptions.setArtifact(dirRelPath + "target/" + artifactId + ".javadoc.jar"); javadocPomOptions.setClassifier("javadoc"); javadocPomOptions.setHasPackageVersion(pomOptions.getHasPackageVersion()); } pomOptions.setJavaLib(true); if (mavenProject.getArtifactId().matches(packageName + "\\d")) { pomOptions.setUsjName(packageName); } } }
From source file:org.deegree.maven.EclipseWorkingSetMojo.java
License:Open Source License
private Map<String, String> findModules() { List<MavenProject> modules = project.getCollectedProjects(); List<String> modList = new ArrayList<String>(); for (MavenProject p : modules) { if (p.getPackaging().equals("pom")) { continue; }//from w ww. j av a 2s . c om modList.add(p.getArtifactId()); } Collections.sort(modList); List<String> workingsets = new ArrayList<String>(); Map<String, String> moduleToWorkingSet = new HashMap<String, String>(); for (String mod : modList) { int idx1 = mod.indexOf("-"); if (idx1 == -1) { continue; } int idx2 = mod.indexOf("-", idx1 + 1); if (idx2 != -1) { String ws = mod.substring(idx1 + 1, idx2); if (!workingsets.contains(ws)) { workingsets.add(ws); } moduleToWorkingSet.put(mod, ws); } } return moduleToWorkingSet; }
From source file:org.deegree.maven.ModuleListRenderer.java
License:Open Source License
@Override protected void renderBody() { List<MavenProject> modules = project.getCollectedProjects(); SortedMap<String, String> byModuleName = new TreeMap<String, String>(); HashSet<String> status = new HashSet<String>(); for (MavenProject p : modules) { if (p.getPackaging().equals("pom")) { continue; }/* www . j ava 2s. c o m*/ String st = getModuleStatus(p); status.add(st); byModuleName.put(p.getArtifactId(), st); } generateReport(byModuleName, status); }
From source file:org.devacfr.maven.skins.reflow.SkinConfigTool.java
License:Apache License
/** * {@inheritDoc}/*from www. j ava 2 s. co m*/ * * @see SafeConfig#configure(ValueParser) */ @Override protected void configure(final ValueParser values) { final String altkey = values.getString("key"); if (altkey != null) { setKey(altkey); } // allow changing skin key in the configuration final String altSkinKey = values.getString("skinKey"); if (altSkinKey != null) { this.skinKey = altSkinKey; } // retrieve the decoration model from Velocity context final Object velocityContext = values.get("velocityContext"); if (!(velocityContext instanceof ToolContext)) { return; } final ToolContext ctxt = (ToolContext) velocityContext; final Object projectObj = ctxt.get("project"); if (projectObj instanceof MavenProject) { final MavenProject project = (MavenProject) projectObj; final String artifactId = project.getArtifactId(); // use artifactId "sluggified" as the projectId projectId = HtmlTool.slug(artifactId); } // calculate the page ID from the current file name final Object currentFileObj = ctxt.get("currentFileName"); if (currentFileObj instanceof String) { String currentFile = (String) currentFileObj; // drop the extension final int lastDot = currentFile.lastIndexOf("."); if (lastDot >= 0) { currentFile = currentFile.substring(0, lastDot); } // get the short ID (in case of nested files) // String fileName = new File(currentFile).getName(); // fileShortId = HtmlTool.slug(fileName); // full file ID includes the nested dirs // replace nesting "/" with "-" fileId = HtmlTool.slug(currentFile.replace("/", "-").replace("\\", "-")); } final Object decorationObj = ctxt.get("decoration"); if (!(decorationObj instanceof DecorationModel)) { return; } final DecorationModel decoration = (DecorationModel) decorationObj; final Object customObj = decoration.getCustom(); if (!(customObj instanceof Xpp3Dom)) { return; } // Now that we have the custom node, get the global properties // under the skin tag final Xpp3Dom customNode = (Xpp3Dom) customObj; Xpp3Dom skinNode = customNode.getChild(skinKey); final String namespaceKey = ":" + skinKey; if (skinNode == null) { // try searching with any namespace for (final Xpp3Dom child : customNode.getChildren()) { if (child.getName().endsWith(namespaceKey)) { skinNode = child; break; } } } if (skinNode != null) { globalProperties = skinNode; if (skinNode.getName().endsWith(namespaceKey)) { // extract the namespace (including the colon) namespace = skinNode.getName().substring(0, skinNode.getName().length() - namespaceKey.length() + 1); } // for page properties, retrieve the file name and drop the `.html` // extension - this will be used, i.e. `index` instead of `index.html` final Xpp3Dom pagesNode = getChild(skinNode, "pages"); if (pagesNode != null) { // Get the page for the file // TODO try fileShortId as well? Xpp3Dom page = getChild(pagesNode, fileId); // Now check if the project artifact ID is set, and if so, if it matches the // current project. This allows preventing accidental reuse of parent page // configs in children modules if (page != null && projectId != null) { final String pageProject = page.getAttribute("project"); if (pageProject != null && !projectId.equals(pageProject)) { // project ID indicated, and is different - do not use the config page = null; } } if (page != null) { pageProperties = page; } } } }