Example usage for org.apache.maven.project DefaultMavenProjectHelper DefaultMavenProjectHelper

List of usage examples for org.apache.maven.project DefaultMavenProjectHelper DefaultMavenProjectHelper

Introduction

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

Prototype

DefaultMavenProjectHelper

Source Link

Usage

From source file:com.ericsson.tools.cpp.car.AbstractCarMojo.java

License:Apache License

private void attach(final File archiveFile, final String classifier) {
    new DefaultMavenProjectHelper().attachArtifact(project, archiveFile, classifier);
}

From source file:com.inetpsa.seed.plugin.PackageMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    MavenProjectHelper helper = new DefaultMavenProjectHelper();

    if (capsuleVersion == null) {
        capsuleVersion = artifactResolver.getHighestVersion(mavenProject, CAPSULE_GROUP_ID, CAPSULE_ARTIFACT_ID,
                false);/*from w w w. jav  a  2 s .  c  o m*/
    }

    if (!outputDirectory.exists()) {
        boolean success = outputDirectory.mkdirs();
        if (!success)
            throw new MojoFailureException("Unable to create output directory");
    }

    getLog().info("Packaging SeedStack application using Capsule version " + capsuleVersion);

    File capsuleFile;
    if (standalone != null) {
        try {
            capsuleFile = buildStandalone();
        } catch (Exception e) {
            throw new MojoExecutionException("Unable to build standalone Capsule", e);
        }
    } else {
        try {
            capsuleFile = buildLight();
        } catch (Exception e) {
            throw new MojoExecutionException("Unable to build lightweight Capsule", e);
        }
    }

    helper.attachArtifact(mavenProject, capsuleFile, "capsule");
}

From source file:de.smartics.maven.plugin.projectmetadata.ArchiveMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (!skip) {/*from   www.  ja v a 2 s .co m*/
        init();

        final File jarFile = createArtifact();
        if (this.attach) {
            final MavenProjectHelper helper = new DefaultMavenProjectHelper();
            helper.attachArtifact(project, jarFile, classifier);
        }
    } else {
        getLog().info("Skipping projectmetadata plugin since skip=true.");
    }
}

From source file:org.apache.usergrid.chop.plugin.RunnerMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException {
    String gitConfigDirectory = Utils.getGitConfigFolder(getProjectBaseDirectory());
    String commitId = Utils.getLastCommitUuid(gitConfigDirectory);

    if (failIfCommitNecessary && Utils.isCommitNecessary(gitConfigDirectory)) {
        String failMsg = "There are modified sources, commit changes before calling the plugin or set "
                + "failIfCommitNecessary parameter as false in your plugin configuration field inside the pom.xml";

        throw new MojoExecutionException(failMsg);
    }/*from   ww  w . j  ava2 s  .c o  m*/

    try {
        String timeStamp = Utils.getTimestamp(new Date());

        // Extract the original chop-runner.jar file which should be in the local repository
        String runnerJarPath = getRunnerInLocalRepo();
        String extractedRunnerPath = getExtractedRunnerPath();
        if (FileUtils.fileExists(extractedRunnerPath)) {
            FileUtils.cleanDirectory(extractedRunnerPath);
        } else {
            FileUtils.mkdir(extractedRunnerPath);
        }
        Utils.extractJar(new File(runnerJarPath), extractedRunnerPath);

        // Copy caller project jar and its dependency jars to topmost runner folder
        File libPathFile = new File(extractedRunnerPath);
        String projectTestOutputJar = getProjectTestOutputJarPath();
        if (!FileUtils.fileExists(projectTestOutputJar)) {
            throw new MojoExecutionException("Project Test Jar could not be found. Make sure you use 'test-jar'"
                    + " goal of the 'maven-jar-plugin' in your project's pom");
        }
        FileUtils.copyFileToDirectory(new File(getProjectOutputJarPath()), libPathFile);
        FileUtils.copyFileToDirectory(new File(projectTestOutputJar), libPathFile);

        Utils.copyArtifactsTo(this.project, extractedRunnerPath);
        boolean successfullyCopiedResourceFiles = Utils.copyResourcesTo(this.project, extractedRunnerPath);
        if (successfullyCopiedResourceFiles) {
            // Create project.properties file
            InputStream inputStream;
            Properties prop = new Properties();
            String configPropertiesFilePath = extractedRunnerPath + "project.properties";
            if (FileUtils.fileExists(configPropertiesFilePath)) {
                // Existing project.properties of chop-runner
                inputStream = new FileInputStream(configPropertiesFilePath);
                prop.load(inputStream);
                inputStream.close();
            }

            // If exists, properties in this file can overwrite the ones from chop-runner
            if (getClass().getResource("project.properties") != null) {
                inputStream = getClass().getResourceAsStream("project.properties");
                Properties propCurrent = new Properties();
                propCurrent.load(inputStream);
                inputStream.close();

                String key;
                while (propCurrent.propertyNames().hasMoreElements()) {
                    key = propCurrent.propertyNames().nextElement().toString();
                    prop.setProperty(key, propCurrent.getProperty(key));
                }
            }

            // Insert all properties acquired in runtime and overwrite existing ones
            String gitUrl = Utils.getGitRemoteUrl(gitConfigDirectory);
            String md5 = Utils.getMD5(timeStamp, commitId);
            prop.setProperty(Project.GIT_UUID_KEY, commitId);
            prop.setProperty(Project.GIT_URL_KEY, gitUrl);
            prop.setProperty(Project.CREATE_TIMESTAMP_KEY, timeStamp);
            prop.setProperty(Project.GROUP_ID_KEY, this.project.getGroupId());
            prop.setProperty(Project.ARTIFACT_ID_KEY, this.project.getArtifactId());
            prop.setProperty(Project.PROJECT_VERSION_KEY, this.project.getVersion());
            prop.setProperty(Project.TEST_PACKAGE_BASE, testPackageBase);
            prop.setProperty(Project.MD5_KEY, md5);
            prop.setProperty(CoordinatorFig.USERNAME, username);
            prop.setProperty(CoordinatorFig.PASSWORD, password);
            prop.setProperty(CoordinatorFig.ENDPOINT, endpoint);

            String uuid = commitId.substring(0, CHARS_OF_UUID / 2)
                    + commitId.substring(commitId.length() - CHARS_OF_UUID / 2);

            prop.setProperty(Project.LOAD_KEY, TESTS_PATH + '/' + uuid + '/' + RUNNER_JAR);
            prop.setProperty(Project.LOAD_TIME_KEY, String.valueOf(System.currentTimeMillis()));
            prop.setProperty(Project.CHOP_VERSION_KEY, plugin.getVersion());

            // Save the newly formed properties file under project.properties
            FileUtils.mkdir(configPropertiesFilePath.substring(0, configPropertiesFilePath.lastIndexOf('/')));
            FileWriter writer = new FileWriter(configPropertiesFilePath);
            prop.store(writer, "Generated with chop:runner");

            // Create the final runner file
            String finalPath = getRunnerFile().getAbsolutePath();
            File finalFile = new File(finalPath);
            Utils.archiveWar(finalFile, extractedRunnerPath);

            // Attempt to attach the runner file with the chop classifier
            if (projectHelper == null) {
                projectHelper = new DefaultMavenProjectHelper();
            }
            projectHelper.attachArtifact(project, finalFile, "chop");
        } else {
            throw new MojoExecutionException("There is no resource folder inside the project");
        }
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error while executing plugin", e);
    }
}