Example usage for org.apache.maven.project MavenProject getArtifactId

List of usage examples for org.apache.maven.project MavenProject getArtifactId

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getArtifactId.

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:ms.dew.devops.kernel.config.ConfigBuilder.java

License:Apache License

private static FinalProjectConfig doBuildProject(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 {
    FinalProjectConfig finalProjectConfig = new FinalProjectConfig();
    if (inputProfile.equalsIgnoreCase(FLAG_DEW_DEVOPS_DEFAULT_PROFILE)) {
        $.bean.copyProperties(finalProjectConfig, dewConfig);
    } else {/*from   w ww .  j a  v a2  s. c  o m*/
        $.bean.copyProperties(finalProjectConfig, dewConfig.getProfiles().get(inputProfile));
    }
    // setting basic
    finalProjectConfig.setId(mavenProject.getId());
    finalProjectConfig.setAppKindPlugin(appKindPlugin);
    finalProjectConfig.setDeployPlugin(deployPlugin);
    finalProjectConfig.setProfile(inputProfile);
    finalProjectConfig.setAppGroup(mavenProject.getGroupId());
    finalProjectConfig.setAppName(mavenProject.getArtifactId());
    finalProjectConfig.setSkip(false);
    if (mavenProject.getName() != null && !mavenProject.getName().trim().isEmpty()) {
        finalProjectConfig.setAppShowName(mavenProject.getName());
    } else {
        finalProjectConfig.setAppShowName(mavenProject.getArtifactId());
    }
    // ?
    if (inputDockerHost != null && !inputDockerHost.trim().isEmpty()) {
        finalProjectConfig.getDocker().setHost(inputDockerHost.trim());
    }
    if (inputDockerRegistryUrl != null && !inputDockerRegistryUrl.trim().isEmpty()) {
        finalProjectConfig.getDocker().setRegistryUrl(inputDockerRegistryUrl.trim());
    }
    if (inputDockerRegistryUserName != null && !inputDockerRegistryUserName.trim().isEmpty()) {
        finalProjectConfig.getDocker().setRegistryUserName(inputDockerRegistryUserName.trim());
    }
    if (inputDockerRegistryPassword != null && !inputDockerRegistryPassword.trim().isEmpty()) {
        finalProjectConfig.getDocker().setRegistryPassword(inputDockerRegistryPassword.trim());
    }
    if (inputKubeBase64Config != null && !inputKubeBase64Config.trim().isEmpty()) {
        finalProjectConfig.getKube().setBase64Config(inputKubeBase64Config.trim());
    }

    // setting path
    finalProjectConfig.setDirectory(mavenProject.getBasedir().getPath() + File.separator);
    finalProjectConfig.setTargetDirectory(finalProjectConfig.getDirectory() + "target" + File.separator);

    // setting git info
    finalProjectConfig.setScmUrl(GitHelper.inst().getScmUrl());
    finalProjectConfig.setGitCommit(GitHelper.inst().getCurrentCommit());
    finalProjectConfig.setImageVersion(finalProjectConfig.getGitCommit());
    finalProjectConfig.setAppVersion(finalProjectConfig.getGitCommit());

    // setting custom config by app kind
    finalProjectConfig.getAppKindPlugin().customConfig(finalProjectConfig);
    // setting reuse version
    fillReuseVersionInfo(finalProjectConfig, dewConfig, dockerHostAppendOpt, dockerRegistryUrlAppendOpt,
            dockerRegistryUserNameAppendOpt, dockerRegistryPasswordAppendOpt, kubeBase64ConfigAppendOpt);
    return finalProjectConfig;
}

From source file:ms.dew.devops.kernel.plugin.deploy.maven.MavenDeployPlugin.java

License:Apache License

@Override
public Resp<String> deployAble(FinalProjectConfig projectConfig) {
    MavenProject mavenProject = projectConfig.getMavenProject();
    String version = mavenProject.getVersion();
    if (version.trim().toLowerCase().endsWith("snapshot")) {
        // /*from w  w w  .ja va  2  s . c  om*/
        if (mavenProject.getDistributionManagement() == null
                || mavenProject.getDistributionManagement().getSnapshotRepository() == null
                || mavenProject.getDistributionManagement().getSnapshotRepository().getUrl() == null
                || mavenProject.getDistributionManagement().getSnapshotRepository().getUrl().trim().isEmpty()) {
            return Resp.forbidden("Maven distribution snapshot repository not found");
        }
    } else if (mavenProject.getDistributionManagement() == null
            || mavenProject.getDistributionManagement().getRepository() == null
            || mavenProject.getDistributionManagement().getRepository().getUrl() == null
            || mavenProject.getDistributionManagement().getRepository().getUrl().trim().isEmpty()) {
        // ??
        return Resp.forbidden("Maven distribution repository not found");
    }
    String repoUrl = mavenProject.getDistributionManagement().getRepository().getUrl().trim();
    // TBD auth
    repoUrl = repoUrl.endsWith("/") ? repoUrl : repoUrl + "/";
    repoUrl += mavenProject.getGroupId().replaceAll("\\.", "/") + "/" + mavenProject.getArtifactId() + "/"
            + version;
    try {
        if ($.http.getWrap(repoUrl).statusCode == 200) {
            return Resp.forbidden("The current version already exists");
        }
    } catch (IOException e) {
        throw new ProjectProcessException(e.getMessage(), e);
    }
    return Resp.success("");
}

From source file:net.erdfelt.maven.graphing.MultimoduleGraphMojo.java

License:Apache License

private boolean isMultiModuleDependency(Dependency dep) {
    boolean ret = false;

    Iterator it = projects.iterator();
    while (it.hasNext()) {
        MavenProject project = (MavenProject) it.next();
        if (StringUtils.equals(project.getGroupId(), dep.getGroupId())
                && StringUtils.equals(project.getArtifactId(), dep.getArtifactId())
                && StringUtils.equals(project.getPackaging(), dep.getType())) {
            // Found dep that matches on groupId / artifactId / type only.
            if (ignoreVersions) {
                // No test of version.
                ret = true;//from   w w  w . ja  v a  2s.  c o  m
                break;
            } else if (StringUtils.equals(project.getVersion(), dep.getVersion())) {
                // Found dep that matches on version too.
                ret = true;
                break;
            }
        }
    }

    return ret;
}

From source file:net.erdfelt.maven.graphing.MultimoduleGraphMojo.java

License:Apache License

private Node toNode(MavenProject project) {
    return toNode(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging());
}

From source file:net.flexmojos.oss.plugin.war.CopyMojo.java

License:Open Source License

private List<Artifact> getRuntimeLocalesDependencies(MavenProject artifactProject) {
    String[] runtimeLocales = CompileConfigurationLoader.getCompilerPluginSettings(artifactProject,
            "runtimeLocales");
    if (runtimeLocales == null || runtimeLocales.length == 0) {
        return Collections.emptyList();
    }/*from w  ww.  ja  va 2s. c o m*/

    List<Artifact> artifacts = new ArrayList<Artifact>();
    for (String locale : runtimeLocales) {
        artifacts.add(repositorySystem.createArtifactWithClassifier(artifactProject.getGroupId(),
                artifactProject.getArtifactId(), artifactProject.getVersion(), SWF, locale));
    }
    return artifacts;
}

From source file:net.java.jpatch.maven.common.AbstractPatchMojo.java

License:Apache License

/**
 * Check the SCM status of the project.// w  ww  .  j  a va2s  .c o  m
 *
 * @param project the MAVEN project.
 * @param begin the SCM ID.
 * @param end the SCM ID.
 *
 * @return
 *
 * @throws MojoExecutionException if the method fails.
 */
private boolean checkSCM(MavenProject project, String revision, File diffDirectory)
        throws MojoExecutionException {

    getLog().info("Check SCM for the project " + project.getId());

    boolean result = false;
    boolean ignoreUnknown = true;

    DiffScmResult scmResult = null;
    try {
        ScmRepository repository = scmManager.makeScmRepository(project.getScm().getConnection());
        scmResult = scmManager.diff(repository, new ScmFileSet(project.getBasedir()), new ScmRevision(revision),
                null);
    } catch (Exception e) {
        getLog().error("Error check SCM status for project " + project.getId());
        throw new MojoExecutionException("Couldn't configure SCM repository: " + e.getLocalizedMessage(), e);
    }

    if (scmResult != null && scmResult.getChangedFiles() != null) {
        List<ScmFile> changedFiles = scmResult.getChangedFiles();
        for (ScmFile changedScmFile : changedFiles) {
            ScmFileStatus status = changedScmFile.getStatus();
            if (!status.isStatus()) {
                getLog().debug("Not a diff: " + status);
                continue;
            }
            if (ignoreUnknown && ScmFileStatus.UNKNOWN.equals(status)) {
                getLog().debug("Ignoring unknown");
                continue;
            }

            getLog().info(changedScmFile.getStatus().toString() + " " + changedScmFile.getPath());
            result = true;
        }

        if (result) {
            File diffFile = new File(diffDirectory, project.getArtifactId() + project.getVersion() + ".diff");
            try {
                getLog().info("Create new diff file: " + diffFile.getAbsolutePath());
                diffFile.createNewFile();
                FileUtils.fileWrite(diffFile.getAbsolutePath(), scmResult.getPatch());
            } catch (IOException ex) {
                Logger.getLogger(AbstractPatchMojo.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    getLog().info("");
    return result;
}

From source file:net.kozelka.contentcheck.mojo.LicenseShowMojo.java

License:Open Source License

/**
 * Artifact resolving and the rest of Maven repo magic taken from <a href="http://maven.apache.org/plugins/maven-project-info-reports-plugin/index.html">Maven Project Info Reports Plugin</a>.
 *///  ww  w.ja  va 2 s  .com
public void execute() throws MojoExecutionException, MojoFailureException {
    final File src = sourceFile.exists() ? sourceFile : defaultBundleForPOMPacking;
    if (!src.exists()) {
        getLog().warn("Skipping project since there is no archive to check.");
        return;
    }

    final List<MavenProject> mavenProjectForDependencies = getMavenProjectForDependencies();

    try {
        final ContentIntrospector introspector = VendorFilter.createIntrospector(
                new MyIntrospectionListener(getLog()), ignoreVendorArchives, vendorId, manifestVendorEntry,
                checkFilesPattern);
        final Set<ActualEntry> archiveEntries = new LinkedHashSet<ActualEntry>();
        introspector.setSourceFile(src);
        //TODO: instead of collecting, put the dependency comparison right inside
        final ContentCollector collector = new ContentCollector(archiveEntries);
        introspector.getEvents().addListener(collector);
        introspector.walk();
        introspector.getEvents().removeListener(collector);

        final Map<String, List<License>> entries = new LinkedHashMap<String, List<License>>();

        final Map<String, List<License>> additionalLicenseInformation = new LinkedHashMap<String, List<License>>();
        if (licenseMappingFile != null && licenseMappingFile.exists()) {
            //read additional license information
            getLog().info(
                    String.format("Reading license mapping file %s", licenseMappingFile.getAbsolutePath()));
            try {
                additionalLicenseInformation.putAll(LicenseShow.parseLicenseMappingFile(licenseMappingFile));
            } catch (JsonParseException e) {
                throw new MojoFailureException(String.format(
                        "Cannot parse JSON from file %s the content of the file is not well formed JSON.",
                        licenseMappingFile), e);
            } catch (JsonMappingException e) {
                throw new MojoFailureException(
                        String.format("Cannot deserialize JSON from file %s", licenseMappingFile), e);
            } catch (IOException e) {
                throw new MojoFailureException(e.getMessage(), e);
            }

        }

        getLog().info("Comparing the archive content with Maven project artifacts");
        for (ActualEntry archiveEntry : archiveEntries) {
            List<License> licenses = null; //these licenses will be associated with the given archive entry

            for (MavenProject mavenProject : mavenProjectForDependencies) {
                mavenProject.getGroupId();
                final String artifactId = mavenProject.getArtifactId();
                final String version = mavenProject.getVersion();
                final String jarName = artifactId + "-" + version + ".jar"; //guess jar name
                if (archiveEntry.getUri().endsWith(jarName)) {
                    @SuppressWarnings("unchecked")
                    final List<License> _licenses = mavenProject.getLicenses();
                    licenses = _licenses == null || _licenses.size() == 0 ? null : _licenses;
                    break;
                }
            }

            final List<License> licensesMappingFile = additionalLicenseInformation
                    .get(FileUtils.filename(archiveEntry.getUri()));

            if (licenses == null && licensesMappingFile == null) {//misising license information
                getLog().debug(String.format(
                        "Cannot resolve license information for archive entry %s neither from the POM file nor the file for license mapping",
                        archiveEntry));
                //archive entry must be present even if there is no a matching Maven Project
                entries.put(archiveEntry.getUri(), Collections.<License>emptyList());
            } else if (licenses != null && licensesMappingFile != null) {//licenses specified in both - POM and license mapping file
                getLog().warn(String.format(
                        "The license information for file %s are defined in the POM file and also in the file for license mapping. Using license information from the the file for license mapping.",
                        archiveEntry));
                entries.put(archiveEntry.getUri(), licensesMappingFile); //mapping manually specified licenses precedes licenses from POM
            } else if (licenses != null) {//license information in POM
                entries.put(archiveEntry.getUri(), licenses);//license
            } else {
                //license information in mapping file
                //put additional license information to the object that holds this information
                entries.put(archiveEntry.getUri(), licensesMappingFile);
            }
        }

        final LicenseShow.LicenseOutput logOutput = new MavenLogOutput(getLog());
        logOutput.output(entries);

        if (csvOutput) {
            final LicenseShow.CsvOutput csvOutput = new LicenseShow.CsvOutput(csvOutputFile);
            getLog().info(String.format("Creating license output to CSV file %s", csvOutputFile.getPath()));
            csvOutput.output(entries);
        }
    } catch (IOException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
}

From source file:net.oneandone.maven.plugins.billofmaterials.CreateBillOfMaterialsMojo.java

License:Apache License

/**
 * Adds the hash entry for the POM./*from  w w  w.  j  a v  a 2s .  c o m*/
 * @param hashBaseNames to add the entry to.
 * @throws IOException when the POM could not be read.
 */
void addHashEntryForPom(final List<String> hashBaseNames) throws IOException {
    final MavenProject project = getProject();
    final HashCode sha1OfPom = Files.hash(project.getFile(), sha1);
    final String pomLine = String.format(Locale.ENGLISH, "%s  %s-%s.pom", sha1OfPom, project.getArtifactId(),
            project.getVersion());
    hashBaseNames.add(pomLine);
}

From source file:net.oneandone.maven.plugins.billofmaterials.CreateBillOfMaterialsMojo.java

License:Apache License

/**
 * Returns a string representation for the comment.
 *
 * @param userName current user//from   w  ww .  ja v a 2  s. c o  m
 * @return string representation for the comment.
 */
String projectCommentToString(final String userName) {
    final MavenProject project = getProject();
    return String.format(Locale.ENGLISH, "# %s:%s:%s user=%s\n", project.getGroupId(), project.getArtifactId(),
            project.getVersion(), userName);
}

From source file:net.oneandone.maven.plugins.prerelease.core.Archive.java

License:Apache License

public static List<FileNode> directories(List<FileNode> storages, MavenProject project) {
    List<FileNode> directories;

    directories = new ArrayList<>(storages.size());
    for (FileNode storage : storages) {
        directories.add(storage.join(project.getGroupId(), project.getArtifactId()));
    }/*from  w w  w .  ja  v a 2s  . c o  m*/
    return directories;
}