List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
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 www.ja v a 2 s. c o 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"); } } ; }
From source file:io.fabric8.maven.HelmPushMojo.java
License:Apache License
protected static boolean projectsEqual(MavenProject project1, MavenProject project2) { return Objects.equal(project1.getGroupId(), project2.getGroupId()) && Objects.equal(project1.getArtifactId(), project2.getArtifactId()) && Objects.equal(project1.getVersion(), project2.getVersion()); }
From source file:io.fabric8.maven.JsonMojo.java
License:Apache License
public String getKubernetesContainerName() { if (Strings.isNullOrBlank(kubernetesContainerName)) { // lets generate it from the docker user and the camelCase artifactId String groupPrefix = null; MavenProject project = getProject(); String imageName = getDockerImage(); if (Strings.isNotBlank(imageName)) { String[] paths = imageName.split("/"); if (paths != null) { if (paths.length == 2) { groupPrefix = paths[0]; } else if (paths.length == 3) { groupPrefix = paths[1]; }/*from www. j a v a 2 s . c om*/ } } if (Strings.isNullOrBlank(groupPrefix)) { groupPrefix = project.getGroupId(); } kubernetesContainerName = groupPrefix + "-" + project.getArtifactId(); } return kubernetesContainerName; }
From source file:io.fabric8.maven.JsonMojo.java
License:Apache License
public Template getTemplate() throws MojoExecutionException { List<io.fabric8.openshift.api.model.Parameter> parameters = new ArrayList<>(); MavenProject project = getProject(); Properties projectProperties = getProjectAndFabric8Properties(getProject()); Set<String> paramNames = new HashSet<>(); if (templateParametersPropertiesFile != null && templateParametersPropertiesFile.isFile() && templateParametersPropertiesFile.exists()) { final String valuePostfix = ".value"; final String descriptionPostfix = ".description"; try {//from w ww.jav a 2 s . co m Properties properties = new Properties(); properties.load(new FileInputStream(templateParametersPropertiesFile)); // lets append the prefix Set<Object> keys = properties.keySet(); Properties prefixedProperties = new Properties(); for (Object key : keys) { if (key != null) { String name = key.toString(); String value = properties.getProperty(name); prefixedProperties.put(PARAMETER_PREFIX + "." + name, value); } } loadParametersFromProperties(prefixedProperties, parameters, paramNames); } catch (IOException e) { throw new MojoExecutionException("Failed to load templateParameters properties file " + templateParametersPropertiesFile + ". " + e, e); } } loadParametersFromProperties(projectProperties, parameters, paramNames); String templateName = projectProperties.containsKey(TEMPLATE_NAME) ? String.valueOf(projectProperties.getProperty(TEMPLATE_NAME)) : project.getArtifactId(); return new TemplateBuilder().withNewMetadata().withName(templateName) .withAnnotations(getTemplateAnnotations()).endMetadata().withParameters(parameters).build(); }
From source file:io.fabric8.maven.MigrateMojo.java
License:Apache License
private void migrateLabels(Map<String, String> labels) { if (labels != null) { MavenProject project = getProject(); // TODO there is a currently a bug when using values other than ${project.artifactId} in fabric8-maven-plugin 3.x // where it overrides the value of the sepc.selector.matchLabels to the artifactId which then breaks // as the template.metadata.labels.project will differ boolean alwaysUseArtifactIdForProject = true; if (alwaysUseArtifactIdForProject) { if (labels.containsKey("project")) { labels.put("project", "${project.artifactId}"); }//from w w w . jav a 2s. com } else { replaceKeyValueWith(labels, "project", project.getArtifactId(), "${project.artifactId}"); } replaceKeyValueWith(labels, "version", project.getVersion(), "${project.version}"); } }
From source file:io.fabric8.maven.ZipMojo.java
License:Apache License
protected void generateZip() throws DependencyTreeBuilderException, MojoExecutionException, IOException, MojoFailureException { File appBuildDir = buildDir;/*from www .j av a2 s. co m*/ if (Strings.isNotBlank(pathInZip)) { appBuildDir = new File(buildDir, pathInZip); } appBuildDir.mkdirs(); if (hasConfigDir()) { copyAppConfigFiles(appBuildDir, appConfigDir); } else { getLog().info("The app configuration files directory " + appConfigDir + " doesn't exist, so not copying any additional project documentation or configuration files"); } MavenProject project = getProject(); if (!ignoreProject) { File kubernetesJson = getKubernetesJson(); if (kubernetesJson != null && kubernetesJson.isFile() && kubernetesJson.exists()) { File jsonFile = new File(appBuildDir, "kubernetes.json"); jsonFile.getParentFile().mkdirs(); Files.copy(kubernetesJson, jsonFile); } // TODO if no iconRef is specified we could try guess based on the project? // lets check if we can use an icon reference copyIconToFolder(appBuildDir); } // lets only generate a app zip if we have a requirement (e.g. we're not a parent pom packaging project) and // we have defined some configuration files or dependencies // to avoid generating dummy apps for parent poms if (hasConfigDir() || !ignoreProject) { if (includeReadMe) { copyReadMe(appBuildDir); } if (generateSummaryFile) { copySummaryText(appBuildDir); } if (generateAppPropertiesFile) { String name = project.getName(); if (Strings.isNullOrBlank(name)) { name = project.getArtifactId(); } String description = project.getDescription(); Properties appProperties = new Properties(); appProperties.put("name", name); if (Strings.isNotBlank(description)) { appProperties.put("description", description); } appProperties.put("groupId", project.getGroupId()); appProperties.put("artifactId", project.getArtifactId()); appProperties.put("version", project.getVersion()); File appPropertiesFile = new File(appBuildDir, "fabric8.properties"); appPropertiesFile.getParentFile().mkdirs(); if (!appPropertiesFile.exists()) { appProperties.store(new FileWriter(appPropertiesFile), "Fabric8 Properties"); } } File outputZipFile = getZipFile(); File legalDir = null; if (includeLegal) { legalDir = new File(project.getBuild().getOutputDirectory(), "META-INF"); } Zips.createZipFile(getLog(), buildDir, outputZipFile, legalDir); projectHelper.attachArtifact(project, artifactType, artifactClassifier, outputZipFile); getLog().info("Created app zip file: " + outputZipFile); } }
From source file:io.fabric8.maven.ZipMojo.java
License:Apache License
private List<MavenProject> fabricZipGoalProjects() { List<MavenProject> answer = new ArrayList<>(); if (reactorProjects != null) { List<MavenProject> pomZipProjects = new ArrayList<>(); for (MavenProject reactorProject : reactorProjects) { if (isPom(reactorProject)) { pomZipProjects.add(reactorProject); }/*from www. j a v a 2s. c om*/ List<Plugin> buildPlugins = reactorProject.getBuildPlugins(); for (Plugin buildPlugin : buildPlugins) { String artifactId = buildPlugin.getArtifactId(); if ("fabric8-maven-plugin".equals(artifactId)) { Object goals = buildPlugin.getGoals(); boolean hasZipGoal = goals != null && goals.toString().contains("zip"); List<PluginExecution> executions = buildPlugin.getExecutions(); for (PluginExecution execution : executions) { List<String> execGoals = execution.getGoals(); if (execGoals.contains("zip")) { hasZipGoal = true; } } getLog().debug( "Project " + reactorProject.getArtifactId() + " has zip goal: " + hasZipGoal); if (hasZipGoal) { answer.add(reactorProject); } } } } } return answer; }
From source file:io.fabric8.maven.ZipMojo.java
License:Apache License
protected void generateAggregatedZip(MavenProject rootProject, List<MavenProject> reactorProjects, Set<MavenProject> pomZipProjects) throws IOException, MojoExecutionException { File projectBaseDir = rootProject.getBasedir(); String rootProjectGroupId = rootProject.getGroupId(); String rootProjectArtifactId = rootProject.getArtifactId(); String rootProjectVersion = rootProject.getVersion(); String aggregatedZipFileName = "target/" + rootProjectArtifactId + "-" + rootProjectVersion + "-app.zip"; File projectOutputFile = new File(projectBaseDir, aggregatedZipFileName); getLog().info("Generating " + projectOutputFile.getAbsolutePath() + " from root project " + rootProjectArtifactId);/*from w ww. j ava 2 s.c o m*/ File projectBuildDir = new File(projectBaseDir, reactorProjectOutputPath); if (projectOutputFile.exists()) { projectOutputFile.delete(); } createAggregatedZip(projectBaseDir, projectBuildDir, reactorProjectOutputPath, projectOutputFile, includeReadMe, pomZipProjects); if (rootProject.getAttachedArtifacts() != null) { // need to remove existing as otherwise we get a WARN Artifact found = null; 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 List<String> activeProfileIds = new ArrayList<>(); List<Profile> activeProfiles = rootProject.getActiveProfiles(); if (activeProfiles != null) { for (Profile profile : activeProfiles) { String id = profile.getId(); if (Strings.isNotBlank(id)) { activeProfileIds.add(id); } } } 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); request.setProfiles(activeProfileIds); Properties props = new Properties(); props.setProperty("file", aggregatedZipFileName); props.setProperty("groupId", rootProjectGroupId); props.setProperty("artifactId", rootProjectArtifactId); props.setProperty("version", rootProjectVersion); props.setProperty("classifier", "app"); props.setProperty("packaging", "zip"); props.setProperty("generatePom", "false"); 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); } } if (rootProject.hasLifecyclePhase("deploy")) { if (deploymentRepository == null && Strings.isNullOrBlank(altDeploymentRepository)) { String msg = "Cannot run deploy phase as Maven project has no <distributionManagement> with the maven url to use for deploying the aggregated zip file, neither an altDeploymentRepository property."; getLog().warn(msg); throw new MojoExecutionException(msg); } getLog().info("Deploying aggregated zip " + projectOutputFile + " to root project " + rootProject.getArtifactId()); getLog().info("Using deploy goal: " + deployFileGoal + " with active profiles: " + activeProfileIds); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory(rootProject.getBasedir()); request.setPomFile(new File("./pom.xml")); request.setGoals(Collections.singletonList(deployFileGoal)); request.setRecursive(false); request.setInteractive(false); request.setProfiles(activeProfileIds); request.setProperties(getProjectAndFabric8Properties(getProject())); Properties props = new Properties(); props.setProperty("file", aggregatedZipFileName); props.setProperty("groupId", rootProjectGroupId); props.setProperty("artifactId", rootProjectArtifactId); props.setProperty("version", rootProjectVersion); props.setProperty("classifier", "app"); props.setProperty("packaging", "zip"); String deployUrl = null; if (!Strings.isNullOrBlank(deployFileUrl)) { deployUrl = deployFileUrl; } else if (altDeploymentRepository != null && altDeploymentRepository.contains("::")) { deployUrl = altDeploymentRepository.substring(altDeploymentRepository.lastIndexOf("::") + 2); } else { deployUrl = deploymentRepository.getUrl(); } props.setProperty("url", deployUrl); props.setProperty("repositoryId", deploymentRepository.getId()); props.setProperty("generatePom", "false"); request.setProperties(props); getLog().info("Deploying aggregated zip using: mvn deploy:deploy-file" + serializeMvnProperties(props)); Invoker invoker = new DefaultInvoker(); try { InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new IllegalStateException("Error invoking Maven goal deploy:deploy-file"); } } catch (MavenInvocationException e) { throw new MojoExecutionException("Error invoking Maven goal deploy:deploy-file", e); } } }
From source file:io.github.wanghuayao.maven.plugin.oaktree.CreateTreeMojo.java
License:Apache License
public void execute() throws MojoExecutionException { log = getLog();/*from ww w. j a v a2 s . c om*/ try { OakProperties properties = new OakProperties(); dependencyArtifacts = "io.github.wanghuayao:maven-plugin-oaktree:" + properties.getVersion() + ":dependency-artifacts"; filter = new ProcessingFilter(likePatten, hitePatten, deep); MavenProject mp = (MavenProject) this.getPluginContext().get("project"); String mavenHomeStr = removeUnusedCharInPath(mavenHome.getPath()); File mvnExecFile = new File(mavenHomeStr + "/bin/mvn"); mvnExec = mvnExecFile.getPath(); String os = System.getProperty("os.name"); if (os.toLowerCase().startsWith("win")) { mvnExec = mvnExec + ".cmd"; isWindwos = true; } File okaBaseDir = new File(outputDirectory, "oaktree"); File okadependencyDir = new File(okaBaseDir, "dependency"); if (!okadependencyDir.exists()) { okadependencyDir.mkdirs(); } okadependencyOutputDir = okadependencyDir.getPath(); ArtifactItem rootItem = new ArtifactItem(mp.getGroupId(), mp.getArtifactId(), mp.getPackaging(), mp.getVersion()); File rootPom = mp.getFile(); int startDeep = 2; for (Object obj : mp.getDependencyArtifacts()) { DefaultArtifact artifact = (DefaultArtifact) obj; ArtifactItem chieldern = ArtifactItem.valueOf(artifact); if (filter.isGoOnProcessing(chieldern, startDeep)) { calcDependancy(chieldern, startDeep); rootItem.addChildren(chieldern); } } FileWriter w = null; try { File okaFile = new File(okaBaseDir, "okatree.txt"); if (okaFile.exists()) { okaFile.delete(); } w = new FileWriter(okaFile); log.info("writing file : " + okaFile.getPath()); printArtifactItem(w, rootItem, ""); log.info("writing complete."); } finally { StreamUtils.quiteClose(w); } } catch (Exception ex) { getLog().error(ex.getMessage(), ex); throw new MojoExecutionException(ex.getMessage(), ex); } }
From source file:io.github.wanghuayao.maven.plugin.oaktree.DependencyArtifactsMojo.java
License:Apache License
public void execute() throws MojoExecutionException { try {// w w w. j a v a 2 s. c om MavenProject mp = (MavenProject) this.getPluginContext().get("project"); if (outputFile == null) { outputFile = new File(outputDirectory, mp.getGroupId() + "." + mp.getArtifactId() + "." + mp.getVersion() + ".txt"); } // delete old file if (outputFile.exists()) { return; } FileWriter w = null; try { w = new FileWriter(outputFile); for (Object obj : mp.getDependencyArtifacts()) { DefaultArtifact artifact = (DefaultArtifact) obj; ArtifactWriter.artifactToWriter(artifact, w); w.write('\n'); } } catch (IOException e) { throw new MojoExecutionException("Error writing file " + outputFile, e); } finally { StreamUtils.quiteClose(w); } } catch (Exception ex) { ex.printStackTrace(); throw new MojoExecutionException(ex.getMessage(), ex); } }