List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
From source file:hudson.gridmaven.reporters.MavenFingerprinter.java
License:Open Source License
private void recordParents(MavenBuildProxy build, MavenProject pom) throws IOException, InterruptedException { MavenProject parent = pom.getParent(); while (parent != null) { File parentFile = parent.getFile(); if (parentFile == null) { // Parent artifact contains no actual file, so we resolve against // the local repository ArtifactRepository localRepository = getLocalRepository(build.getMavenBuildInformation(), parent, pom);/*from w w w .j av a2 s.co m*/ if (localRepository != null) { Artifact parentArtifact = getArtifact(parent); // Don't use ArtifactRepository.find(), for compatibility with Maven 2.x if (parentArtifact != null) { parentFile = new File(localRepository.getBasedir(), localRepository.pathOf(parentArtifact)); } } } if (parentFile != null) { // we need to include the artifact Id for poms as well, otherwise a // project with the same groupId would override its parent's // fingerprint record(parent.getGroupId() + ":" + parent.getArtifactId(), parentFile, used); } parent = parent.getParent(); } }
From source file:hudson.gridmaven.reporters.MavenFingerprinter.java
License:Open Source License
private Artifact getArtifact(MavenProject parent) { Artifact art = parent.getArtifact(); if (art == null) { // happens for Maven 2.x DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler("pom"); art = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), VersionRange.createFromVersion(parent.getVersion()), null, "pom", "", artifactHandler); }//from ww w.j a va 2s . c om return art; }
From source file:hudson.maven.ReactorReader.java
License:Apache License
public ReactorReader(Map<String, MavenProject> reactorProjects, File workspaceRoot) { projectsByGAV = reactorProjects;/*from ww w . j ava2 s. com*/ this.workspaceRoot = workspaceRoot; projectsByGA = new HashMap<String, List<MavenProject>>(reactorProjects.size() * 2); for (MavenProject project : reactorProjects.values()) { String key = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()); List<MavenProject> projects = projectsByGA.get(key); if (projects == null) { projects = new ArrayList<MavenProject>(1); projectsByGA.put(key, projects); } projects.add(project); } repository = new WorkspaceRepository("reactor", new HashSet<String>(projectsByGAV.keySet())); }
From source file:hudson.maven.ReactorReader.java
License:Apache License
public void addProject(MavenProject mavenProject) { String key = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId(); this.projectsByGA.put(key, Arrays.asList(mavenProject)); String projectKey = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId() + ':' + mavenProject.getVersion(); this.projectsByGAV.put(projectKey, mavenProject); }
From source file:hudson.maven.reporters.MavenArtifactArchiver.java
License:Open Source License
public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildListener listener) throws InterruptedException, IOException { // artifacts that are known to Maven. Set<File> mavenArtifacts = new HashSet<File>(); if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently. // record POM final MavenArtifact pomArtifact = new MavenArtifact(pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, "pom", pom.getFile().getName(), Util.getDigestOf(pom.getFile())); final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl()); final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId()); mavenArtifacts.add(pom.getFile()); pomArtifact.archive(build, pom.getFile(), listener); // record main artifact (if packaging is POM, this doesn't exist) final MavenArtifact mainArtifact = MavenArtifact.create(pom.getArtifact()); if (mainArtifact != null) { File f = pom.getArtifact().getFile(); mavenArtifacts.add(f);/*from w w w. j a v a2 s. c o m*/ mainArtifact.archive(build, f, listener); } // record attached artifacts final List<MavenArtifact> attachedArtifacts = new ArrayList<MavenArtifact>(); for (Artifact a : pom.getAttachedArtifacts()) { MavenArtifact ma = MavenArtifact.create(a); if (ma != null) { mavenArtifacts.add(a.getFile()); ma.archive(build, a.getFile(), listener); attachedArtifacts.add(ma); } } // record the action build.executeAsync(new MavenBuildProxy.BuildCallable<Void, IOException>() { private static final long serialVersionUID = -7955474564875700905L; public Void call(MavenBuild build) throws IOException, InterruptedException { // if a build forks lifecycles, this method can be called multiple times List<MavenArtifactRecord> old = build.getActions(MavenArtifactRecord.class); if (!old.isEmpty()) build.getActions().removeAll(old); MavenArtifactRecord mar = new MavenArtifactRecord(build, pomArtifact, mainArtifact, attachedArtifacts, repositoryUrl, repositoryId); build.addAction(mar); // TODO kutzi: why are the fingerprints recorded here? // I thought that is the job of MavenFingerprinter mar.recordFingerprints(); return null; } }); } // do we have any assembly artifacts? // System.out.println("Considering "+assemblies+" at "+MavenArtifactArchiver.this); // new Exception().fillInStackTrace().printStackTrace(); if (build.isArchivingDisabled()) { listener.getLogger().println("[JENKINS] Archiving disabled"); } else if (assemblies != null) { for (File assembly : assemblies) { if (mavenArtifacts.contains(assembly)) continue; // looks like this is already archived FilePath target = build.getArtifactsDir().child(assembly.getName()); listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target); new FilePath(assembly).copyTo(target); // TODO: fingerprint } } return true; }
From source file:io.fabric8.maven.core.util.kubernetes.KubernetesResourceUtil.java
License:Apache License
private static String extractImageUser(String image, MavenProject project) { ImageName name = new ImageName(image); String imageUser = name.getUser(); String projectGroupId = project.getGroupId(); if (imageUser != null) { return imageUser; } else {/*from w w w. j a v a 2 s.com*/ if (projectGroupId == null || projectGroupId.matches(CONTAINER_NAME_REGEX)) { return projectGroupId; } else { return projectGroupId.replaceAll("[^a-zA-Z0-9-]", "").replaceFirst("^-*(.*?)-*$", "$1"); } } }
From source file:io.fabric8.maven.core.util.KubernetesResourceUtil.java
License:Apache License
private static String extractImageUser(String image, MavenProject project) { ImageName name = new ImageName(image); String imageUser = name.getUser(); return imageUser != null ? imageUser : project.getGroupId(); }
From source file:io.fabric8.maven.CreateProfileZipMojo.java
License:Apache License
protected void generateAggregatedZip(MavenProject rootProject, List<MavenProject> reactorProjects, List<MavenProject> pomZipProjects) throws IOException, MojoExecutionException { File projectBaseDir = rootProject.getBasedir(); File projectOutputFile = new File(projectBaseDir, "target/profile.zip"); getLog().info("Generating " + projectOutputFile.getAbsolutePath() + " from root project " + rootProject.getArtifactId()); File projectBuildDir = new File(projectBaseDir, reactorProjectOutputPath); createAggregatedZip(reactorProjects, projectBaseDir, projectBuildDir, reactorProjectOutputPath, projectOutputFile, includeReadMe, pomZipProjects); if (rootProject.getAttachedArtifacts() != null) { // need to remove existing as otherwise we get a WARN Artifact found = null;/* w w w . j av a 2 s . co m*/ for (Artifact artifact : rootProject.getAttachedArtifacts()) { if (artifactClassifier != null && artifact.hasClassifier() && artifact.getClassifier().equals(artifactClassifier)) { found = artifact; break; } } if (found != null) { rootProject.getAttachedArtifacts().remove(found); } } getLog().info("Attaching aggregated zip " + projectOutputFile + " to root project " + rootProject.getArtifactId()); projectHelper.attachArtifact(rootProject, artifactType, artifactClassifier, projectOutputFile); // if we are doing an install goal, then also install the aggregated zip manually // as maven will install the root project first, and then build the reactor projects, and at this point // it does not help to attach artifact to root project, as those artifacts will not be installed // so we need to install manually if (rootProject.hasLifecyclePhase("install")) { getLog().info("Installing aggregated zip " + projectOutputFile); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory(rootProject.getBasedir()); request.setPomFile(new File("./pom.xml")); request.setGoals(Collections.singletonList("install:install-file")); request.setRecursive(false); request.setInteractive(false); Properties props = new Properties(); props.setProperty("file", "target/profile.zip"); props.setProperty("groupId", rootProject.getGroupId()); props.setProperty("artifactId", rootProject.getArtifactId()); props.setProperty("version", rootProject.getVersion()); props.setProperty("classifier", "profile"); props.setProperty("packaging", "zip"); request.setProperties(props); getLog().info( "Installing aggregated zip using: mvn install:install-file" + serializeMvnProperties(props)); Invoker invoker = new DefaultInvoker(); try { InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new IllegalStateException("Error invoking Maven goal install:install-file"); } } catch (MavenInvocationException e) { throw new MojoExecutionException("Error invoking Maven goal install:install-file", e); } } }
From source file:io.fabric8.maven.enricher.standard.ProjectEnricher.java
License:Apache License
private Map<String, String> createLabels(boolean withoutVersion) { MavenProject project = getProject(); Map<String, String> ret = new HashMap<>(); ret.put("project", project.getArtifactId()); ret.put("group", project.getGroupId()); ret.put("provider", "fabric8"); if (!withoutVersion) { ret.put("version", project.getVersion()); }/*from ww w . j a v a 2s. com*/ return ret; }
From source file:io.fabric8.maven.generator.javaexec.JavaExecGenerator.java
License:Apache License
protected void addAssembly(AssemblyConfiguration.Builder builder) throws MojoExecutionException { String assemblyRef = getConfig(Config.assemblyRef); if (assemblyRef != null) { builder.descriptorRef(assemblyRef); } else {/*from ww w . j a v a2 s . co m*/ if (isFatJar()) { FatJarDetector.Result fatJar = detectFatJar(); Assembly assembly = new Assembly(); MavenProject project = getProject(); if (fatJar == null) { DependencySet dependencySet = new DependencySet(); dependencySet.addInclude(project.getGroupId() + ":" + project.getArtifactId()); assembly.addDependencySet(dependencySet); } else { FileSet fileSet = new FileSet(); File buildDir = new File(project.getBuild().getDirectory()); fileSet.setDirectory(toRelativePath(buildDir, project.getBasedir())); fileSet.addInclude(toRelativePath(fatJar.getArchiveFile(), buildDir)); fileSet.setOutputDirectory("."); assembly.addFileSet(fileSet); } assembly.addFileSet(createFileSet("src/main/fabric8-includes/bin", "bin", "0755", "0755")); assembly.addFileSet(createFileSet("src/main/fabric8-includes", ".", "0644", "0755")); builder.assemblyDef(assembly); } else { builder.descriptorRef("artifact-with-dependencies"); } } ; }