List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:io.takari.maven.workspace.GenerationsWorkspaceReader.java
License:Apache License
private File find(MavenProject project, Artifact artifact) { File file = null;/*from w ww . j a v a2 s.c om*/ if ("pom".equals(artifact.getExtension())) { return project.getFile(); } // // project = project where we will find artifact, this may be the primary artifact or any of the // secondary artifacts // Artifact projectArtifact = findMatchingArtifact(project, artifact); if (hasArtifactFileFromPackagePhase(projectArtifact)) { // // We have gone far enough in the lifecycle to produce a JAR, WAR, or other file-based artifact // if (isTestArtifact(artifact)) { // // We are looking for a test JAR foo-1.0-test.jar // file = new File(project.getBuild().getDirectory(), String.format("%s-%s-tests.jar", project.getArtifactId(), project.getVersion())); } else { // // We are looking for an application JAR foo-1.0.jar // file = projectArtifact.getFile(); } } else if (!hasBeenPackaged(project)) { // // Here no file has been produced so we fallback to loose class files only if artifacts haven't been packaged yet // and only for plain old jars. Not war files, not ear files, not anything else. // String type = artifact.getProperty("type", ""); if (isTestArtifact(artifact)) { if (project.hasLifecyclePhase("test-compile")) { file = new File(project.getBuild().getTestOutputDirectory()); } } else if (project.hasLifecyclePhase("compile") && COMPILE_PHASE_TYPES.contains(type)) { file = new File(project.getBuild().getOutputDirectory()); } if (file == null && allowArtifactsWithoutAFileToBeResolvedInTheReactor) { // // There is no elegant way to signal that the Artifact's representation is actually present in the // reactor but that it has no file-based representation during this execution and may, in fact, not // require one. The case this accounts for something I am doing with Eclipse project file // generation where I can perform dependency resolution, but cannot run any lifecycle phases. // I need the in-reactor references to work correctly. The WorkspaceReader interface needs // to be changed to account for this. This is not exactly elegant, but it's turned on // with a property and should not interfere. // // We have made a slight change in that we don't want to return "." because it confuses the // compiler plugin for special cases that we have where we are running the compiler in the // process-resources phase. // file = new File(project.getBuild().getOutputDirectory()); //if (file.exists() == false) { // file = new File("."); //} } } // // The fall-through indicates that the artifact cannot be found; // for instance if package produced nothing or classifier problems. // return file; }
From source file:io.takari.maven.workspace.GenerationsWorkspaceReader.java
License:Apache License
private File findWorkspaceArtifact(MavenProject project, Artifact artifact) { File file = null;// www . j av a2s . c o m if ("pom".equals(artifact.getExtension())) { return project.getFile(); } // // project = project where we will find artifact, this may be the primary artifact or any of the // secondary artifacts // Artifact projectArtifact = findMatchingArtifact(project, artifact); if (hasArtifactFileFromPackagePhase(projectArtifact)) { // // We have gone far enough in the lifecycle to produce a JAR, WAR, or other file-based artifact // if (isTestArtifact(artifact)) { // // We are looking for a test JAR foo-1.0-test.jar // file = new File(project.getBuild().getDirectory(), String.format("%s-%s-tests.jar", project.getArtifactId(), project.getVersion())); } else { // // We are looking for an application JAR foo-1.0.jar // file = projectArtifact.getFile(); } } else if (!hasBeenPackaged(project)) { // // Here no file has been produced so we fallback to loose class files only if artifacts haven't been packaged yet // and only for plain old jars. Not war files, not ear files, not anything else. // String type = artifact.getProperty("type", ""); if (isTestArtifact(artifact)) { if (project.hasLifecyclePhase("test-compile")) { file = new File(project.getBuild().getTestOutputDirectory()); } } else if (project.hasLifecyclePhase("compile") && COMPILE_PHASE_TYPES.contains(type)) { file = new File(project.getBuild().getOutputDirectory()); } if (file == null && allowArtifactsWithoutAFileToBeResolvedInTheReactor) { // // There is no elegant way to signal that the Artifact's representation is actually present in the // reactor but that it has no file-based representation during this execution and may, in fact, not // require one. The case this accounts for something I am doing with Eclipse project file // generation where I can perform dependency resolution, but cannot run any lifecycle phases. // I need the in-reactor references to work correctly. The WorkspaceReader interface needs // to be changed to account for this. This is not exactly elegant, but it's turned on // with a property and should not interfere. // /* Turn off resolving for now file = new File(project.getBuild().getOutputDirectory()); if (file.exists() == false) { file = new File("."); } */ } } // // The fall-through indicates that the artifact cannot be found; // for instance if package produced nothing or classifier problems. // return file; }
From source file:io.takari.maven.workspace.GenerationsWorkspaceReader.java
License:Apache License
private Map<String, MavenProject> getProjectMap(Collection<MavenProject> projects) { Map<String, MavenProject> index = new LinkedHashMap<String, MavenProject>(); Map<String, List<File>> collisions = new LinkedHashMap<String, List<File>>(); for (MavenProject project : projects) { String projectId = ArtifactUtils.key(project.getGroupId(), project.getArtifactId(), project.getVersion());/*from ww w .ja v a2 s . co m*/ MavenProject collision = index.get(projectId); if (collision == null) { index.put(projectId, project); } else { List<File> pomFiles = collisions.get(projectId); if (pomFiles == null) { pomFiles = new ArrayList<File>(Arrays.asList(collision.getFile(), project.getFile())); collisions.put(projectId, pomFiles); } else { pomFiles.add(project.getFile()); } } } /* * * We'll assume there is no collisions * * if (!collisions.isEmpty()) { throw new DuplicateProjectException("Two or more projects in the reactor" + " have the same identifier, please make sure that <groupId>:<artifactId>:<version>" + * " is unique for each project: " + collisions, collisions); } */ return index; }
From source file:io.teecube.t3.GenericReplacerMojo.java
License:Apache License
private void signGPG(MavenProject p) throws MojoExecutionException, MavenInvocationException, MojoFailureException, IOException { InvocationRequest request = getInvocationRequest(p); Invoker invoker = getInvoker(); InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { CommandLineException executionException = result.getExecutionException(); if (executionException != null) { throw new MojoFailureException("Error during project build: " + executionException.getMessage(), executionException); } else {//from w w w . j a va2 s .co m throw new MojoFailureException("Error during project build: " + result.getExitCode()); } } if (!p.isExecutionRoot() || p.getModel().getModules().isEmpty()) { File gpgTempDirectory = null; try { URL gpgTempDirectoryURL = new URL(request.getProperties().get("url").toString()); gpgTempDirectory = new File(gpgTempDirectoryURL.getFile()); File pomGpgSignature = new File(gpgTempDirectory, p.getGroupId().replaceAll("\\.", "/") + "/" + p.getArtifactId() + "/" + p.getVersion() + "/" + p.getArtifactId() + "-" + p.getVersion() + ".pom.asc"); File gpgSignatureDest = new File(p.getBuild().getDirectory(), pomGpgSignature.getName()); pomGpgSignature = new File(p.getFile().getParentFile(), "pom.xml.asc"); org.apache.commons.io.FileUtils.copyFile(pomGpgSignature, gpgSignatureDest); } finally { if (gpgTempDirectory != null && gpgTempDirectory.exists()) { org.apache.commons.io.FileUtils.deleteDirectory(gpgTempDirectory); } File ascFile = new File(p.getFile().getParentFile(), "pom.xml.asc"); if (ascFile.exists()) { ascFile.delete(); } } } }
From source file:io.teecube.t3.GenericReplacerMojo.java
License:Apache License
private InvocationRequest getInvocationRequest(MavenProject p) throws MojoExecutionException, IOException { InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(p.getFile());/*www . j ava 2 s . c o m*/ if (p.isExecutionRoot() && !p.getModel().getModules().isEmpty()) { request.setGoals(Lists.newArrayList("gpg:sign")); } else { File gpgDirectory = Files.createTempDir(); request.setGoals(Lists.newArrayList("gpg:sign-and-deploy-file")); Properties properties = new Properties(); properties.put("file", p.getFile().getAbsolutePath()); // properties.put("pomFile", p.getFile().getAbsolutePath()); properties.put("groupId", p.getGroupId()); properties.put("artifactId", p.getArtifactId()); properties.put("version", p.getVersion()); properties.put("repositoryId", "null"); properties.put("url", gpgDirectory.toURI().toURL().toString()); request.setProperties(properties); } request.setRecursive(false); this.tempSettingsFile = createAndSetTempSettings(request); return request; }
From source file:licenseUtil.LicenseUtil.java
License:Apache License
public static LicensingList processProjectsInFolder(File directory, String currentVersion, Boolean mavenProjectsOnly) throws IOException { LicensingList result = new LicensingList(); File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); File gitDir = new File(directory.getPath() + File.separator + ".git"); File pomFile = new File(directory.getPath() + File.separator + "pom.xml"); if (mavenProjectsOnly) { // check pom.xml if (!pomFile.exists()) { return result; }//from w w w . ja v a2 s .c om } else { // check git and update if (gitDir.exists()) { logger.info("update local repository"); Utils.updateRepository(directory.getPath()); } for (File dir : subdirs) { result.addAll(processProjectsInFolder(dir, currentVersion, true)); } //return result; } logger.info("process directory: " + directory.getName()); // check git and update if (gitDir.exists()) { logger.info("update local repository"); Utils.updateRepository(directory.getPath()); } if (pomFile.exists()) { logger.info("build effective-pom"); File pom = new File(directory.getPath() + File.separator + EFFECTIVE_POM_FN); Utils.writeEffectivePom(new File(directory.getPath()), pom.getAbsolutePath()); MavenProject project = null; try { project = Utils.readPom(pom); } catch (Exception e) { logger.warn("Could not read from pom file: \"" + pom.getPath() + "\" because of " + e.getMessage()); return result; } FileUtils.delete(pom); // death first for (String module : project.getModules()) { File subdirectory = new File(directory + File.separator + module); result.addAll(processProjectsInFolder(subdirectory, currentVersion, true)); } // add all licence objects of child modules for (LicensingObject licensingObject : result) { licensingObject.put(project.getArtifactId(), currentVersion); } result.addMavenProject(project, currentVersion); } return result; }
From source file:licenseUtil.LicensingList.java
License:Apache License
public void addMavenProject(MavenProject project, String version) { logger.debug("add pom content to current list"); List<Dependency> dependencies = project.getDependencies(); for (Dependency dependency : dependencies) { if (dependency.getScope() == null || !dependency.getScope().equals(excludedScope)) { LicensingObject licensingObject; Artifact depArtifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), "pom", dependency.getVersion()); try { MavenProject depProject = Utils.resolveArtifact(project, depArtifact); licensingObject = new LicensingObject(depProject, project.getArtifactId(), version, licenseUrlMappings); } catch (ArtifactResolutionException | IOException | XmlPullParserException e) { logger.error("Could not resolve Artifact; " + depArtifact.toString()); licensingObject = new LicensingObject(dependency, project.getArtifactId(), version); }/*w w w . ja va 2s .co m*/ add(licensingObject); } } List<Plugin> plugins = project.getBuild().getPlugins(); for (Plugin plugin : plugins) { //LicensingObject licensingObject = new LicensingObject(plugin, project.getArtifactId(), version); LicensingObject licensingObject; Artifact depArtifact = new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), "pom", plugin.getVersion()); try { MavenProject depProject = Utils.resolveArtifact(project, depArtifact); licensingObject = new LicensingObject(depProject, project.getArtifactId(), version, licenseUrlMappings); } catch (ArtifactResolutionException | IOException | XmlPullParserException e) { logger.error("Could not resolve Artifact; " + depArtifact.toString()); licensingObject = new LicensingObject(plugin, project.getArtifactId(), version); } add(licensingObject); } }
From source file:licenseUtil.LicensingObject.java
License:Apache License
LicensingObject(MavenProject project, String includingProject, String version, Map<String, String> licenseUrlFileMappings) { super();/*from www . j a va 2 s .com*/ put(ColumnHeader.ARTIFACT_ID.value(), project.getArtifactId()); put(ColumnHeader.GROUP_ID.value(), project.getGroupId()); put(ColumnHeader.VERSION.value(), project.getVersion()); if (project.getLicenses() != null && !project.getLicenses().isEmpty()) { String licenseNames = ""; String licenseUrls = ""; String licenseComments = ""; String licenseFN = null; int i = 0; for (License license : project.getLicenses()) { if (license.getUrl() != null && licenseFN == null) // remove protocol and lookup license url licenseFN = Utils.getValue(licenseUrlFileMappings, license.getUrl().replaceFirst("^[^:]+://", "")); if (i++ > 0) { licenseNames += multiEntriesSeparator; licenseUrls += multiEntriesSeparator; licenseComments += multiEntriesSeparator; } licenseNames += license.getName(); if (!Strings.isNullOrEmpty(license.getUrl())) licenseUrls += license.getUrl(); if (!Strings.isNullOrEmpty(license.getComments())) licenseComments += license.getComments(); } if (!Strings.isNullOrEmpty(licenseFN)) put(ColumnHeader.LICENSE_TEMPLATE.value(), licenseFN); if (!Strings.isNullOrEmpty(licenseNames)) put(ColumnHeader.LICENSE_NAMES.value(), licenseNames); if (!Strings.isNullOrEmpty(licenseUrls)) put(ColumnHeader.LICENSE_URLS.value(), licenseUrls); if (!Strings.isNullOrEmpty(licenseComments)) put(ColumnHeader.LICENSE_COMMENTS.value(), licenseComments); } put(includingProject, version); //clean(); }
From source file:lt.velykis.maven.skins.reflow.SkinConfigTool.java
License:Apache License
/** * {@inheritDoc}//from w w w. ja v a2s . c om * * @see SafeConfig#configure(ValueParser) */ @Override protected void configure(ValueParser values) { String altkey = values.getString("key"); if (altkey != null) { setKey(altkey); } // allow changing skin key in the configuration String altSkinKey = values.getString("skinKey"); if (altSkinKey != null) { this.skinKey = altSkinKey; } // retrieve the decoration model from Velocity context Object velocityContext = values.get("velocityContext"); if (!(velocityContext instanceof ToolContext)) { return; } ToolContext ctxt = (ToolContext) velocityContext; Object projectObj = ctxt.get("project"); if (projectObj instanceof MavenProject) { MavenProject project = (MavenProject) projectObj; String artifactId = project.getArtifactId(); // use artifactId "sluggified" as the projectId projectId = HtmlTool.slug(artifactId); } // calculate the page ID from the current file name Object currentFileObj = ctxt.get("currentFileName"); if (currentFileObj instanceof String) { String currentFile = (String) currentFileObj; // drop the extension 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("\\", "-")); } Object decorationObj = ctxt.get("decoration"); if (!(decorationObj instanceof DecorationModel)) { return; } DecorationModel decoration = (DecorationModel) decorationObj; Object customObj = decoration.getCustom(); if (!(customObj instanceof Xpp3Dom)) { return; } // Now that we have the custom node, get the global properties // under the skin tag Xpp3Dom customNode = (Xpp3Dom) customObj; Xpp3Dom skinNode = customNode.getChild(skinKey); String namespaceKey = ":" + skinKey; if (skinNode == null) { // try searching with any namespace for (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` 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) { 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; } } } }
From source file:ms.dew.devops.kernel.config.ConfigBuilder.java
License:Apache License
/** * Build project optional.//w w w . j av a 2s.co m * * @param dewConfig the dew config * @param appKindPlugin the app kind plugin * @param deployPlugin the deploy plugin * @param mavenProject the maven project * @param inputProfile the input profile * @param inputDockerHost the input docker host * @param inputDockerRegistryUrl the input docker registry url * @param inputDockerRegistryUserName the input docker registry user name * @param inputDockerRegistryPassword the input docker registry password * @param inputKubeBase64Config the input kube base 64 config * @param dockerHostAppendOpt the docker host append opt * @param dockerRegistryUrlAppendOpt the docker registry url append opt * @param dockerRegistryUserNameAppendOpt the docker registry user name append opt * @param dockerRegistryPasswordAppendOpt the docker registry password append opt * @param kubeBase64ConfigAppendOpt the kube base 64 config append opt * @return the optional * @throws InvocationTargetException the invocation target exception * @throws IllegalAccessException the illegal access exception */ public static Optional<FinalProjectConfig> buildProject(DewConfig dewConfig, AppKindPlugin appKindPlugin, DeployPlugin deployPlugin, MavenProject mavenProject, String inputProfile, String inputDockerHost, String inputDockerRegistryUrl, String inputDockerRegistryUserName, String inputDockerRegistryPassword, String inputKubeBase64Config, Optional<String> dockerHostAppendOpt, Optional<String> dockerRegistryUrlAppendOpt, Optional<String> dockerRegistryUserNameAppendOpt, Optional<String> dockerRegistryPasswordAppendOpt, Optional<String> kubeBase64ConfigAppendOpt) throws InvocationTargetException, IllegalAccessException { // ? inputProfile = inputProfile.toLowerCase(); dewConfig.setProfiles(dewConfig.getProfiles().entrySet().stream() .collect(Collectors.toMap(profile -> profile.getKey().toLowerCase(), Map.Entry::getValue))); // ??Kubernetes????????????Kubernetes Set<String> envChecker = dewConfig.getProfiles().values().stream() .map(prof -> prof.getNamespace() + prof.getKube().getBase64Config()).collect(Collectors.toSet()); if (!dewConfig.getNamespace().isEmpty() && !dewConfig.getKube().getBase64Config().isEmpty()) { envChecker.add(dewConfig.getNamespace() + dewConfig.getKube().getBase64Config()); } else { envChecker.add(""); } if (envChecker.size() != dewConfig.getProfiles().size() + 1) { throw new ConfigException("[" + mavenProject.getArtifactId() + "] " + "Namespace and kubernetes cluster between different environments cannot be the same"); } // ? if (!inputProfile.equals(FLAG_DEW_DEVOPS_DEFAULT_PROFILE) && !dewConfig.getProfiles().containsKey(inputProfile)) { throw new ConfigException( "[" + mavenProject.getArtifactId() + "] Can't be found [" + inputProfile + "] profile"); } // ??skip if (inputProfile.equals(FLAG_DEW_DEVOPS_DEFAULT_PROFILE) && dewConfig.getSkip() != null && dewConfig.getSkip() || !inputProfile.equals(FLAG_DEW_DEVOPS_DEFAULT_PROFILE) && dewConfig.getProfiles().get(inputProfile).getSkip() != null && dewConfig.getProfiles().get(inputProfile).getSkip()) { return Optional.empty(); } FinalProjectConfig finalProjectConfig = doBuildProject(dewConfig, appKindPlugin, deployPlugin, mavenProject, inputProfile, inputDockerHost, inputDockerRegistryUrl, inputDockerRegistryUserName, inputDockerRegistryPassword, inputKubeBase64Config, dockerHostAppendOpt, dockerRegistryUrlAppendOpt, dockerRegistryUserNameAppendOpt, dockerRegistryPasswordAppendOpt, kubeBase64ConfigAppendOpt); if (finalProjectConfig.getKube().getBase64Config().isEmpty()) { throw new ConfigException("[" + mavenProject.getArtifactId() + "] Kubernetes config can't be empty"); } return Optional.of(finalProjectConfig); }